Debian Codegraph @

examples/basics/dynamic_pads.cc

raw symbols SCIP
1 /*
2 * This example presents basic usage of dynamics Gst::Pad objects.
3 */
4 #include <gstreamermm.h>
5 #include <glibmm/main.h>
6
7 #include <iostream>
8
9 int main(int argc, char *argv[])
10 {
11 Gst::init(argc, argv);
12
13 Glib::RefPtr<Glib::MainLoop> main_loop = Glib::MainLoop::create();
14
15 // Create pipeline
16 Glib::RefPtr<Gst::Pipeline> pipeline = Gst::Pipeline::create("my_pipeline");
17
18 // Create elements
19 Glib::RefPtr<Gst::Element> source = Gst::ElementFactory::create_element("videotestsrc", "source"),
20 decodebin = Gst::ElementFactory::create_element("decodebin", "decoder"),
21 sink = Gst::ElementFactory::create_element("autovideosink", "videosink");
22
23 // Add elements to a pipeline
24 try
25 {
26 pipeline->add(source)->add(decodebin)->add(sink);
27 }
28 catch (const std::runtime_error& ex)
29 {
30 std::cerr << "Exception while adding: " << ex.what() << std::endl;
31 return 1;
32 }
33
34 // Link elements
35 try
36 {
37 // We can't link decodebin with sink, because decodebin
38 // doesn't have any src pad on start up.
39 source->link(decodebin);
40 }
41 catch (const std::runtime_error& ex)
42 {
43 std::cerr << "Exception while linking: " << ex.what() << std::endl;
44 }
45
46 // Handle messages posted on bus
47 pipeline->get_bus()->add_watch([main_loop] (const Glib::RefPtr<Gst::Bus>&,
48 const Glib::RefPtr<Gst::Message>& message) {
49 switch (message->get_message_type())
50 {
51 case Gst::MESSAGE_EOS:
52 case Gst::MESSAGE_ERROR:
53 main_loop->quit();
54 break;
55 default:
56 break;
57 }
58 return true;
59 });
60
61 // Listen for newly created pads
62 decodebin->signal_pad_added().connect([decodebin, sink] (const Glib::RefPtr<Gst::Pad>& pad) {
63 std::cout << "New pad added to " << decodebin->get_name() << std::endl;
64 std::cout << "Pad name: " << pad->get_name() << std::endl;
65
66 Gst::PadLinkReturn ret = pad->link(sink->get_static_pad("sink"));
67
68 if (ret != Gst::PAD_LINK_OK)
69 {
70 std::cout << "Cannot link pads. Error: " << ret << std::endl;
71 }
72 else
73 {
74 std::cout << "Pads linked correctly!" << std::endl;
75 }
76 });
77
78 // Start the pipeline
79 pipeline->set_state(Gst::STATE_PLAYING);
80 main_loop->run();
81 pipeline->set_state(Gst::STATE_NULL);
82
83 return 0;
84 }