我正在 Ubuntu 10.04/12.04 上测试以下代码。我收到一个错误
#include <gtkmm.h>
#include <gstreamermm.h>
#include <iostream>
using namespace std;
class Sound
{
public:
Sound();
void start_playing(double frequency);
bool stop_playing();
private:
Glib::RefPtr<Gst::Pipeline> m_pipeline;
Glib::RefPtr<Gst::Element> m_source;
Glib::RefPtr<Gst::Element> m_sink;
};
Sound::Sound()
{
m_pipeline = Gst::Pipeline::create("note");
m_source = Gst::ElementFactory::create_element("audiotestsrc",
"source");
m_sink = Gst::ElementFactory::create_element("autoaudiosink",
"output");
m_pipeline->add(m_source);
m_pipeline->add(m_sink);
m_source->link(m_sink);
}
void Sound::start_playing (double frequency)
{
m_source->set_property("freq", frequency);
m_pipeline->set_state(Gst::STATE_PLAYING);
/* stop it after 200ms */
Glib::signal_timeout().connect(sigc::mem_fun(*this, &Sound::stop_playing),
200);
}
bool Sound::stop_playing()
{
m_pipeline->set_state(Gst::STATE_NULL);
return false;
}
class Buttons : public Gtk::Window
{
public:
Buttons();
virtual ~Buttons();
protected:
//Signal handlers:
//void on_button_clicked();
Sound sound;
//void on_button_clicked(double frequency, Sound& sound);
void on_button_clicked(double frequency, Sound* sound);
//Child widgets:
Gtk::Button m_button;
};
Buttons::Buttons()
{
m_button.add_pixlabel("info.xpm", "cool button");
set_title("Pixmap'd buttons!");
set_border_width(10);
//m_button.signal_clicked().connect( sigc::mem_fun(*this,
// &Buttons::on_button_clicked) );
//m_button.signal_clicked().connect (sigc::bind<double, Sound*>(sigc::ptr_fun(&Buttons::on_button_clicked),
// 369.23, &sound));
//m_button.signal_clicked().connect( sigc::bind<double, Sound&>( sigc::mem_fun(*this, &Buttons::on_button_clicked), 369.23, sound) );
m_button.signal_clicked().connect( sigc::bind<double, Sound*>( sigc::mem_fun(*this, &Buttons::on_button_clicked), 369.23, &sound) );
add(m_button);
show_all_children();
}
Buttons::~Buttons()
{
}
/*
void Buttons::on_button_clicked()
{
std::cout << "The Button was clicked." << std::endl;
}
*/
/*
void
Buttons::on_button_clicked(double frequency, Sound& sound)
{
sound.start_playing (frequency);
}
*/
void
Buttons::on_button_clicked(double frequency, Sound* sound)
{
sound->start_playing (frequency);
}
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Buttons buttons;
//Shows the window and returns when it is closed.
Gtk::Main::run(buttons);
return 0;
}
我编译使用g++ gstmm1.cc -o gstmm1 ``pkg-config --cflags --libs gstreamermm-0.10 gtkmm-2.4
terminate called after throwing an instance of 'std::runtime_error'
what(): Failed to add null element.
Aborted
任何想法可能有什么问题?几乎看起来这可能与以下帖子有关 http://old.nabble.com/gstmm-add-element-to-pipeline-test-td14042055.html