Debian Codegraph @

examples/dynamic_changing_source/main.cc

raw symbols SCIP
1 /*
2 * main.cc
3 *
4 * Created on: Aug 19, 2013
5 * Author: m.kolny
6 */
7 #include <gstreamermm.h>
8 #include <glibmm/main.h>
9 #include <iostream>
10
11 using namespace Gst;
12 using Glib::RefPtr;
13
14 RefPtr<Element> src;
15 RefPtr<Element> convert;
16 RefPtr<Pipeline> pipeline;
17 RefPtr<Glib::MainLoop> main_loop;
18
19 bool on_timeout()
20 {
21 static int pattern = 0;
22 src->set_state(STATE_NULL);
23 pipeline->remove(src);
24 src = ElementFactory::create_element("videotestsrc");
25 pattern = (pattern == 0) ? 18 : 0;
26 src->property("pattern", pattern);
27 pipeline->add(src);
28 src->link(convert);
29 src->set_state(STATE_PLAYING);
30
31 return true;
32 }
33
34 int main(int argc, char** argv)
35 {
36 if (argc < 2)
37 {
38 std::cout << "Usage: " << argv[0] << " <avi output filename>" << std::endl;
39 return 1;
40 }
41
42 init(argc, argv);
43 main_loop = Glib::MainLoop::create();
44
45 pipeline = Pipeline::create("effects-pipeline");
46
47 if (!pipeline)
48 {
49 std::cout << "Cannot create pipeline element." << std::endl;
50 return 1;
51 }
52
53 RefPtr<Element> queue1 = ElementFactory::create_element("queue"),
54 queue2 = ElementFactory::create_element("queue"),
55 tee = ElementFactory::create_element("tee"),
56 autosink = ElementFactory::create_element("autovideosink"),
57 sink = ElementFactory::create_element("filesink"),
58 muxer = ElementFactory::create_element("avimux");
59
60 src = ElementFactory::create_element("videotestsrc");
61 src->property<int>("num-buffers", 100);
62 sink->property<Glib::ustring>("location", argv[1]);
63 convert = ElementFactory::create_element("videoconvert");
64
65 if (!queue1 || !queue2 || !tee || !autosink ||
66 !sink || !muxer || !src || !sink || !convert)
67 {
68 std::cout << "Cannot create one of the elements." << std::endl;
69 return 1;
70 }
71
72 try
73 {
74 pipeline->add(src)->add(convert)->add(tee)->add(queue1)
75 ->add(autosink)->add(queue2)->add(muxer)->add(sink);
76
77 src->link(convert)->link(tee)->link(queue1)->link(autosink);
78 tee->link(queue2)->link(muxer)->link(sink);
79 }
80 catch (const std::exception& ex)
81 {
82 std::cout << "Exception occured during preparing pipeline. Message: " << ex.what() << std::endl;
83 return 1;
84 }
85
86 pipeline->set_state(STATE_PLAYING);
87
88 Glib::signal_timeout().connect(sigc::ptr_fun(&on_timeout), 2000);
89 main_loop->run();
90
91 pipeline->set_state(STATE_NULL);
92
93 return 0;
94 }
95
96
97
98