Debian Codegraph @

examples/tee_request_pad/main.cc

raw symbols SCIP
1 /* gstreamermm - a C++ wrapper for gstreamer
2 *
3 * Copyright 2009-2016 The gstreamermm Development Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 #include <gstreamermm.h>cxx . . $ `<file>/gstreamer/gstreamermm.h`/
20 #include <glibmm/main.h>
21
22 #include <regex>
23 #include <iostream>
24
25 Glibcxx . . $ Glib/::RefPtrcxx . . $ Glib/RefPtr#<Glibcxx . . $ Glib/::MainLoopcxx . . $ Glib/MainLoop#> mainloopcxx . . $ mainloop.;
26
27 // Message watch function
28 bool bus_message_watchcxx . . $ bus_message_watch(f80753751e77bf04).(const Glibcxx . . $ Glib/::RefPtrcxx . . $ Glib/RefPtr#<Gstcxx . . $ Gst/::Buscxx . . $ Gst/Bus#>& /* bus */, const Glibcxx . . $ Glib/::RefPtrcxx . . $ Glib/RefPtr#<Gstcxx . . $ Gst/::Messagecxx . . $ Gst/Message#>& message)
29 {
30 switch (message->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_message_typecxx . . $ Gst/Message#get_message_type(97914d44a9bd21bb).())
31 {
32 case Gstcxx . . $ Gst/::MESSAGE_ERRORcxx . . $ Gst/MESSAGE_ERROR.:
33 case Gstcxx . . $ Gst/::MESSAGE_EOScxx . . $ Gst/MESSAGE_EOS.:
34 mainloopcxx . . $ mainloop.->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).quitcxx . . $ Glib/MainLoop#quit(49f6e7a06ebc5aa8).();
35 default:
36 break;
37 }
38
39 return true;
40 }
41
42 int maincxx . . $ main(afcd3168fc1188a4).(int argc, char** argv)
43 {
44 // Initialize Gstreamermm:
45 Gstcxx . . $ Gst/::initcxx . . $ Gst/init(22930d6ef54703eb).(argc, argv);
46
47 //Check input arguments:
48 if(argc < 2)
49 {
50 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Usage: " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). argv[0] <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " <filename>" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
51 return 1;
52 }
53
54 const stdcxx . . $ std/::stringcxx . . $ std/string# filenamecxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). = argvcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).[1];
55
56 // Create pipeline:
57 Glibcxx . . $ Glib/::RefPtrcxx . . $ Glib/RefPtr#<Gstcxx . . $ Gst/::Pipelinecxx . . $ Gst/Pipeline#> pipeline = Gstcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).::Pipelinecxx . . $ Gst/Pipeline#::createcxx . . $ Gst/Pipeline#create(4db98da4abd65927).("my-pipeline"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).);
58
59 // Create elements:
60 Glibcxx . . $ Glib/::RefPtrcxx . . $ Glib/RefPtr#<Gstcxx . . $ Gst/::Elementcxx . . $ Gst/Element#> source = Gstcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).::ElementFactorycxx . . $ Gst/ElementFactory#::create_elementcxx . . $ Gst/ElementFactory#create_element(1ef5e1ee31814ad5).("filesrc"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).),
61 decoder = Gstcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).::ElementFactorycxx . . $ Gst/ElementFactory#::create_elementcxx . . $ Gst/ElementFactory#create_element(1ef5e1ee31814ad5).("decodebin"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).),
62 tee = Gstcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).::ElementFactorycxx . . $ Gst/ElementFactory#::create_elementcxx . . $ Gst/ElementFactory#create_element(1ef5e1ee31814ad5).("tee"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).),
63 audio_queue = Gstcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).::ElementFactorycxx . . $ Gst/ElementFactory#::create_elementcxx . . $ Gst/ElementFactory#create_element(1ef5e1ee31814ad5).("queue"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).),
64 video_queue = Gstcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).::ElementFactorycxx . . $ Gst/ElementFactory#::create_elementcxx . . $ Gst/ElementFactory#create_element(1ef5e1ee31814ad5).("queue"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).),
65 audio_convert = Gstcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).::ElementFactorycxx . . $ Gst/ElementFactory#::create_elementcxx . . $ Gst/ElementFactory#create_element(1ef5e1ee31814ad5).("audioconvert"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).),
66 audio_convert_4v = Gstcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).::ElementFactorycxx . . $ Gst/ElementFactory#::create_elementcxx . . $ Gst/ElementFactory#create_element(1ef5e1ee31814ad5).("audioconvert"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).),
67 video_convert = Gstcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).::ElementFactorycxx . . $ Gst/ElementFactory#::create_elementcxx . . $ Gst/ElementFactory#create_element(1ef5e1ee31814ad5).("videoconvert"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).),
68 goom = Gstcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).::ElementFactorycxx . . $ Gst/ElementFactory#::create_elementcxx . . $ Gst/ElementFactory#create_element(1ef5e1ee31814ad5).("goom"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).),
69 resample = Gstcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).::ElementFactorycxx . . $ Gst/ElementFactory#::create_elementcxx . . $ Gst/ElementFactory#create_element(1ef5e1ee31814ad5).("audioresample"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).),
70 audio_sink = Gstcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).::ElementFactorycxx . . $ Gst/ElementFactory#::create_elementcxx . . $ Gst/ElementFactory#create_element(1ef5e1ee31814ad5).("autoaudiosink"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).),
71 video_sink = Gstcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).::ElementFactorycxx . . $ Gst/ElementFactory#::create_elementcxx . . $ Gst/ElementFactory#create_element(1ef5e1ee31814ad5).("autovideosink"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).);
72
73 if (!source || !decoder || !tee || !audio_queue || !video_queue || !goom || !audio_convert_4v
74 || !audio_convert || !video_convert || !resample || !audio_sink || !video_sink)
75 stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "One of the elements could not be created." <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
76
77 // Set location property of filesrc element
78 source->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).set_propertycxx . . $ Glib/ObjectBase#set_property(29831774a8731cb).<Glibcxx . . $ Glib/::ustringcxx . . $ Glib/ustring#>("location"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9)., argvcxx . . $ Glib/ustring#ustring(85c52e162fed56f9).[1]);
79
80 // We must add the elements to the pipeline before linking them:
81 try
82 {
83 pipeline->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).addcxx . . $ Gst/Bin#add(25e1dc1b4b432bb3).(source)->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).addcxx . . $ Gst/Bin#add(25e1dc1b4b432bb3).(decoder)->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).addcxx . . $ Gst/Bin#add(25e1dc1b4b432bb3).(tee)->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).addcxx . . $ Gst/Bin#add(25e1dc1b4b432bb3).(audio_queue)->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).addcxx . . $ Gst/Bin#add(25e1dc1b4b432bb3).(video_queue)
84 ->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).addcxx . . $ Gst/Bin#add(25e1dc1b4b432bb3).(goom)->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).addcxx . . $ Gst/Bin#add(25e1dc1b4b432bb3).(audio_convert_4v)->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).addcxx . . $ Gst/Bin#add(25e1dc1b4b432bb3).(audio_convert)->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).addcxx . . $ Gst/Bin#add(25e1dc1b4b432bb3).(video_convert)
85 ->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).addcxx . . $ Gst/Bin#add(25e1dc1b4b432bb3).(resample)->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).addcxx . . $ Gst/Bin#add(25e1dc1b4b432bb3).(audio_sink)->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).addcxx . . $ Gst/Bin#add(25e1dc1b4b432bb3).(video_sink);
86 }
87 catch (stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#& ex)
88 {
89 stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Exception while adding: " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ex.whatcxx . . $ std/runtime_error#what(a9f41ea0e82d88cf).() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
90 return 1;
91 }
92
93 // Lik tee with queues
94 Glibcxx . . $ Glib/::RefPtrcxx . . $ Glib/RefPtr#<Gstcxx . . $ Gst/::PadTemplatecxx . . $ Gst/PadTemplate#> tee_src_tpl = teecxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_pad_templatecxx . . $ Gst/Element#get_pad_template(c9217be5c367a067).("src_%u"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).);
95 if (tee->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).request_padcxx . . $ Gst/Element#request_pad(9128074496de6b9e).(tee_src_tpl)->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).linkcxx . . $ Gst/Pad#link(ca9408873a0c7209).(audio_queue->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_static_padcxx . . $ Gst/Element#get_static_pad(d41a58e7b5052139).("sink"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).)) != Gstcxx . . $ Gst/::PAD_LINK_OKcxx . . $ Gst/PAD_LINK_OK.)
96 {
97 stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Cannot link tee pad with audio queue" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
98 return 1;
99 }
100 if (tee->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).request_padcxx . . $ Gst/Element#request_pad(9128074496de6b9e).(tee_src_tpl)->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).linkcxx . . $ Gst/Pad#link(ca9408873a0c7209).(video_queue->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_static_padcxx . . $ Gst/Element#get_static_pad(d41a58e7b5052139).("sink"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).)) != Gstcxx . . $ Gst/::PAD_LINK_OKcxx . . $ Gst/PAD_LINK_OK.)
101 {
102 stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Cannot link tee pad with video queue" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
103 return 1;
104 }
105
106 // Link other elements together:
107 try
108 {
109 source->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).linkcxx . . $ Gst/Element#link(52e71ea9673343b3).(decoder);
110 audio_queue->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).linkcxx . . $ Gst/Element#link(52e71ea9673343b3).(audio_convert)->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).linkcxx . . $ Gst/Element#link(52e71ea9673343b3).(resample)->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).linkcxx . . $ Gst/Element#link(52e71ea9673343b3).(audio_sink);
111 video_queue->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).linkcxx . . $ Gst/Element#link(52e71ea9673343b3).(audio_convert_4v)->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).linkcxx . . $ Gst/Element#link(52e71ea9673343b3).(goom)->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).linkcxx . . $ Gst/Element#link(52e71ea9673343b3).(video_convert)->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).linkcxx . . $ Gst/Element#link(52e71ea9673343b3).(video_sink);
112 }
113 catch(const stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#& error)
114 {
115 stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Exception while linking: " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). error.whatcxx . . $ std/runtime_error#what(a9f41ea0e82d88cf).() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
116 return 1;
117 }
118
119 // Signal handler for on-pad-added signal of decoder element
120 decoder->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).signal_pad_addedcxx . . $ Gst/Element#signal_pad_added(b8ac1dfc5db9f846).().connectcxx . . $ Glib/SignalProxy#connect(23e07d4a2c0735e0).([cxx . . $ sigc/slot#slot(edcd8b2679e9bd1a).teecxx . . $ Glib/RefPtr#RefPtr(73f8e0eb4f2c32).] (const Glibcxx . . $ Glib/::RefPtrcxx . . $ Glib/RefPtr#<Gstcxx . . $ Gst/::Padcxx . . $ Gst/Pad#> &pad) {
121 Glibcxx . . $ Glib/::RefPtrcxx . . $ Glib/RefPtr#<Gstcxx . . $ Gst/::Capscxx . . $ Gst/Caps#> caps = padcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_current_capscxx . . $ Gst/Pad#get_current_caps(22811ab509ec2061).();
122 stdcxx . . $ std/::stringcxx . . $ std/string# media_typecxx . . $ std/__cxx11/basic_string#basic_string(3bc0f77cdfbaa67f). = caps->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_structurecxx . . $ Gst/Caps#get_structure(1c73294166a8b10b).(0).get_namecxx . . $ Gst/Structure#get_name(fff0f585954e56f3).();
123
124 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "New pad: " <<cxx . . $ Glib/`operator<<`(d3a65685b7328161). pad->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_namecxx . . $ Gst/Object#get_name(fff0f585954e56f3).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ", media type: " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). media_type <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
125
126 if (stdcxx . . $ std/::regex_searchcxx . . $ std/regex_search(dbfa5bd607d7b136).(media_type, stdcxx . . $ std/::regexcxx . . $ std/__cxx11/regex#("^audio")))
127 {
128 if (pad->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).linkcxx . . $ Gst/Pad#link(ca9408873a0c7209).(tee->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_static_padcxx . . $ Gst/Element#get_static_pad(d41a58e7b5052139).("sink"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).)) != Gstcxx . . $ Gst/::PAD_LINK_OKcxx . . $ Gst/PAD_LINK_OK.)
129 {
130 stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Cannot link pad with queue" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
131 }
132 }
133 else
134 stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Unsupported media type" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
135 });
136
137 // Add watch to pipeline's bus.
138 pipeline->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_buscxx . . $ Gst/Pipeline#get_bus(ada66d6ded80d30d).()->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).add_watchcxx . . $ Gst/Bus#add_watch(125cf56d22b1e63d).(sigccxx . . $ sigc/slot#slot(edcd8b2679e9bd1a).::ptr_funcxx . . $ sigc/ptr_fun(1a86a404afb7766).(&bus_message_watchcxx . . $ bus_message_watch(f80753751e77bf04).));
139
140
141 // Now set the whole pipeline to playing and start the main loop:
142 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Setting pipeline to PLAYING." <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
143 mainloopcxx . . $ mainloop. =cxx . . $ Glib/RefPtr#`operator=`(b66de19e2ab7ce1f). Glibcxx . . $ Glib/::MainLoopcxx . . $ Glib/MainLoop#::createcxx . . $ Glib/MainLoop#create(748caac81bf5da26).();
144 pipeline->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).set_statecxx . . $ Gst/Element#set_state(17bf573d41f9253f).(Gstcxx . . $ Gst/::STATE_PLAYINGcxx . . $ Gst/STATE_PLAYING.);
145 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Pipeline is playing." <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
146 mainloopcxx . . $ mainloop.->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).runcxx . . $ Glib/MainLoop#run(49f6e7a06ebc5aa8).();
147
148 stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Returned. Stopping pipeline." <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
149 pipeline->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).set_statecxx . . $ Gst/Element#set_state(17bf573d41f9253f).(Gstcxx . . $ Gst/::STATE_NULLcxx . . $ Gst/STATE_NULL.);
150
151 return 0;
152 }