A gstreamermm dynamic Gst::Pad example.
#include <gstreamermm.h>
#include <glibmm/main.h>
int main(int argc, char *argv[])
{
Glib::RefPtr<Glib::MainLoop> main_loop = Glib::MainLoop::create();
try
{
pipeline->add(source)->add(decodebin)->add(sink);
}
{
std::cerr <<
"Exception while adding: " << ex.what() <<
std::endl;
return 1;
}
try
{
source->link(decodebin);
}
{
std::cerr <<
"Exception while linking: " << ex.what() <<
std::endl;
}
pipeline->get_bus()->add_watch([main_loop] (const Glib::RefPtr<Gst::Bus>&,
const Glib::RefPtr<Gst::Message>& message) {
switch (message->get_message_type())
{
main_loop->quit();
break;
default:
break;
}
return true;
});
decodebin->signal_pad_added().connect([decodebin, sink] (const Glib::RefPtr<Gst::Pad>& pad) {
std::cout <<
"New pad added to " << decodebin->get_name() <<
std::endl;
std::cout <<
"Pad name: " << pad->get_name() <<
std::endl;
{
std::cout <<
"Cannot link pads. Error: " << ret <<
std::endl;
}
else
{
std::cout <<
"Pads linked correctly!" <<
std::endl;
}
});
main_loop->run();
return 0;
}