| 1 | /* |
| 2 | * main.cc |
| 3 | * |
| 4 | * Created on: Sep 12, 2014 |
| 5 | * Author: m.kolny |
| 6 | */ |
| 7 | |
| 8 | #include <gstreamermm.h>cxx . . $ `<file>/gstreamer/gstreamermm.h`/ |
| 9 | #include <iostream> |
| 10 | #include <glibmm/main.h> |
| 11 | |
| 12 | using namespace Gst; |
| 13 | using Glibcxx . . $ Glib/::RefPtrcxx . . $ RefPtr#; |
| 14 | |
| 15 | |
| 16 | class AllMediaPlayercxx . . $ AllMediaPlayer# |
| 17 | { |
| 18 | private: |
| 19 | RefPtrcxx . . $ RefPtr#<Glibcxx . . $ Glib/::MainLoopcxx . . $ Glib/MainLoop#> main_loopcxx . . $ AllMediaPlayer#main_loop.; |
| 20 | RefPtrcxx . . $ RefPtr#<Pipelinecxx . . $ Gst/Pipeline#> pipelinecxx . . $ AllMediaPlayer#pipeline.; |
| 21 | |
| 22 | #ifndef GSTREAMERMM_DISABLE_DEPRECATED |
| 23 | RefPtrcxx . . $ RefPtr#<FileSrccxx . . $ Gst/FileSrc#> sourcecxx . . $ AllMediaPlayer#source.; |
| 24 | #else |
| 25 | RefPtr<Gst::Element> source; |
| 26 | #endif |
| 27 | |
| 28 | RefPtrcxx . . $ RefPtr#<Elementcxx . . $ Gst/Element#> decodercxx . . $ AllMediaPlayer#decoder.; |
| 29 | |
| 30 | bool on_bus_messagecxx . . $ AllMediaPlayer#on_bus_message(f80753751e77bf04).(const RefPtrcxx . . $ RefPtr#<Buscxx . . $ Gst/Bus#>&, const RefPtrcxx . . $ RefPtr#<Messagecxx . . $ Gst/Message#>& message); |
| 31 | void on_decoder_pad_addedcxx . . $ AllMediaPlayer#on_decoder_pad_added(6d8541f3277dd441).(const RefPtrcxx . . $ RefPtr#<Padcxx . . $ Gst/Pad#>& pad); |
| 32 | |
| 33 | void initcxx . . $ AllMediaPlayer#init(49f6e7a06ebc5aa8).() |
| 34 | { |
| 35 | #ifndef GSTREAMERMM_DISABLE_DEPRECATED |
| 36 | sourcecxx . . $ AllMediaPlayer#source. =cxx . . $ Glib/RefPtr#`operator=`(b66de19e2ab7ce1f). FileSrccxx . . $ Gst/FileSrc#::createcxx . . $ Gst/FileSrc#create(c38e35eb3f591174).(); |
| 37 | #else |
| 38 | source = ElementFactory::create_element("filesrc"); |
| 39 | #endif |
| 40 | |
| 41 | decodercxx . . $ AllMediaPlayer#decoder. =cxx . . $ Glib/RefPtr#`operator=`(b66de19e2ab7ce1f). ElementFactorycxx . . $ Gst/ElementFactory#::create_elementcxx . . $ Gst/ElementFactory#create_element(1ef5e1ee31814ad5).("decodebin"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).); |
| 42 | |
| 43 | if (!decodercxx . . $ AllMediaPlayer#decoder. || !sourcecxx . . $ AllMediaPlayer#source.) |
| 44 | { |
| 45 | throw stdcxx . . $ std/runtime_error#runtime_error(6be18eeaba0abf21).::runtime_errorcxx . . $ std/runtime_error#("One element could not be created."); |
| 46 | } |
| 47 | |
| 48 | pipelinecxx . . $ AllMediaPlayer#pipeline.->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).addcxx . . $ Gst/Bin#add(25e1dc1b4b432bb3).(sourcecxx . . $ Glib/RefPtr#RefPtr(11a1ac667024f826).)->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).addcxx . . $ Gst/Bin#add(25e1dc1b4b432bb3).(decodercxx . . $ AllMediaPlayer#decoder.); |
| 49 | decodercxx . . $ AllMediaPlayer#decoder.->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).signal_pad_addedcxx . . $ Gst/Element#signal_pad_added(b8ac1dfc5db9f846).().connectcxx . . $ Glib/SignalProxy#connect(23e07d4a2c0735e0).(sigccxx . . $ sigc/slot#slot(edcd8b2679e9bd1a).::mem_funcxx . . $ sigc/mem_fun(5a1f7901f4fc005e).(*this, &AllMediaPlayercxx . . $ AllMediaPlayer#::on_decoder_pad_addedcxx . . $ AllMediaPlayer#on_decoder_pad_added(6d8541f3277dd441).)); |
| 50 | |
| 51 | sourcecxx . . $ AllMediaPlayer#source.->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).linkcxx . . $ Gst/Element#link(52e71ea9673343b3).(decodercxx . . $ AllMediaPlayer#decoder.); |
| 52 | } |
| 53 | |
| 54 | public: |
| 55 | AllMediaPlayercxx . . $ AllMediaPlayer#AllMediaPlayer(49f6e7a06ebc5aa8).() |
| 56 | { |
| 57 | main_loopcxx . . $ AllMediaPlayer#main_loop. =cxx . . $ Glib/RefPtr#`operator=`(b66de19e2ab7ce1f). Glibcxx . . $ Glib/::MainLoopcxx . . $ Glib/MainLoop#::createcxx . . $ Glib/MainLoop#create(748caac81bf5da26).(); |
| 58 | pipelinecxx . . $ AllMediaPlayer#pipeline. =cxx . . $ Glib/RefPtr#`operator=`(b66de19e2ab7ce1f). Pipelinecxx . . $ Gst/Pipeline#::createcxx . . $ Gst/Pipeline#create(5502e112d2933258).(); |
| 59 | pipelinecxx . . $ AllMediaPlayer#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).::mem_funcxx . . $ sigc/mem_fun(d04a425b0ef7d1a0).(*this, &AllMediaPlayercxx . . $ AllMediaPlayer#::on_bus_messagecxx . . $ AllMediaPlayer#on_bus_message(f80753751e77bf04).)); |
| 60 | } |
| 61 | |
| 62 | void play_until_eoscxx . . $ AllMediaPlayer#play_until_eos(9c546c94e5fcce4e).(const stdcxx . . $ std/::stringcxx . . $ std/string#& filename) |
| 63 | { |
| 64 | initcxx . . $ AllMediaPlayer#init(49f6e7a06ebc5aa8).(); |
| 65 | |
| 66 | #ifndef GSTREAMERMM_DISABLE_DEPRECATED |
| 67 | sourcecxx . . $ AllMediaPlayer#source.->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).property_locationcxx . . $ Gst/FileSrc#property_location(ee255b09b2ef680a).() =cxx . . $ Glib/PropertyProxy#`operator=`(96d6f65396a143d8). filenamecxx . . $ Glib/ustring#ustring(9c546c94e5fcce4e).; |
| 68 | #else |
| 69 | source->set_property("location", filename); |
| 70 | #endif |
| 71 | |
| 72 | pipelinecxx . . $ AllMediaPlayer#pipeline.->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).set_statecxx . . $ Gst/Element#set_state(17bf573d41f9253f).(STATE_PLAYINGcxx . . $ Gst/STATE_PLAYING.); |
| 73 | main_loopcxx . . $ AllMediaPlayer#main_loop.->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).runcxx . . $ Glib/MainLoop#run(49f6e7a06ebc5aa8).(); |
| 74 | pipelinecxx . . $ AllMediaPlayer#pipeline.->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).set_statecxx . . $ Gst/Element#set_state(17bf573d41f9253f).(STATE_NULLcxx . . $ Gst/STATE_NULL.); |
| 75 | } |
| 76 | }; |
| 77 | |
| 78 | bool AllMediaPlayercxx . . $ AllMediaPlayer#::on_bus_messagecxx . . $ AllMediaPlayer#on_bus_message(f80753751e77bf04).(const RefPtrcxx . . $ RefPtr#<Buscxx . . $ Gst/Bus#>&, const RefPtrcxx . . $ RefPtr#<Messagecxx . . $ Gst/Message#>& message) |
| 79 | { |
| 80 | switch(message->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_message_typecxx . . $ Gst/Message#get_message_type(97914d44a9bd21bb).()) |
| 81 | { |
| 82 | case Gstcxx . . $ Gst/::MESSAGE_EOScxx . . $ Gst/MESSAGE_EOS.: |
| 83 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9). <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "End of stream" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 84 | main_loopcxx . . $ AllMediaPlayer#main_loop.->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).quitcxx . . $ Glib/MainLoop#quit(49f6e7a06ebc5aa8).(); |
| 85 | return false; |
| 86 | case Gstcxx . . $ Gst/::MESSAGE_ERRORcxx . . $ Gst/MESSAGE_ERROR.: |
| 87 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Error." <<cxx . . $ std/`operator<<`(88df5bef833f7f83). RefPtrcxx . . $ Glib/RefPtr#<MessageError>::cast_staticcxx . . $ Glib/RefPtr#cast_static(18212fa50966cf79).(message)->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).parse_debugcxx . . $ Gst/MessageError#parse_debug(219584694fe2b248).() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 88 | main_loopcxx . . $ AllMediaPlayer#main_loop.->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).quitcxx . . $ Glib/MainLoop#quit(49f6e7a06ebc5aa8).(); |
| 89 | return false; |
| 90 | default: |
| 91 | break; |
| 92 | } |
| 93 | |
| 94 | return true; |
| 95 | } |
| 96 | |
| 97 | void AllMediaPlayercxx . . $ AllMediaPlayer#::on_decoder_pad_addedcxx . . $ AllMediaPlayer#on_decoder_pad_added(6d8541f3277dd441).(const RefPtrcxx . . $ RefPtr#<Padcxx . . $ Gst/Pad#>& pad) |
| 98 | { |
| 99 | Glibcxx . . $ Glib/::ustringcxx . . $ Glib/ustring# caps_format = padcxx . . $ Glib/ustring#ustring(9ff8f5cb794dfdbf).->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_current_capscxx . . $ Gst/Pad#get_current_caps(22811ab509ec2061).()->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).to_stringcxx . . $ Gst/Caps#to_string(fff0f585954e56f3).().substrcxx . . $ Glib/ustring#substr(d35f79e9a633722d).(0, 5); |
| 100 | RefPtrcxx . . $ RefPtr#<Bincxx . . $ Gst/Bin#> parent = parentcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439)..cast_dynamiccxx . . $ Glib/RefPtr#cast_dynamic(9d87394f87ca1249).(pad->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_parentcxx . . $ Gst/Object#get_parent(9952950db3828d1a).()->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_parentcxx . . $ Gst/Object#get_parent(9952950db3828d1a).()); |
| 101 | |
| 102 | if (!parent) |
| 103 | { |
| 104 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "cannot get parent bin" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | Glibcxx . . $ Glib/::ustringcxx . . $ Glib/ustring# factory_namecxx . . $ Glib/ustring#ustring(49f6e7a06ebc5aa8).; |
| 109 | |
| 110 | if (caps_format ==cxx . . $ Glib/`operator==`(c236aab782da112f). "video") |
| 111 | { |
| 112 | factory_name =cxx . . $ Glib/ustring#`operator=`(6082a55360a9226). "autovideosink"; |
| 113 | } |
| 114 | else if (caps_format ==cxx . . $ Glib/`operator==`(c236aab782da112f). "audio") |
| 115 | { |
| 116 | factory_name =cxx . . $ Glib/ustring#`operator=`(6082a55360a9226). "autoaudiosink"; |
| 117 | } |
| 118 | else |
| 119 | { |
| 120 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "unsupported media type: " <<cxx . . $ Glib/`operator<<`(d3a65685b7328161). pad->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_current_capscxx . . $ Gst/Pad#get_current_caps(22811ab509ec2061).()->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).to_stringcxx . . $ Gst/Caps#to_string(fff0f585954e56f3).() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | RefPtrcxx . . $ RefPtr#<Elementcxx . . $ Gst/Element#> element = ElementFactorycxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).::create_elementcxx . . $ Gst/ElementFactory#create_element(1ef5e1ee31814ad5).(factory_name); |
| 125 | |
| 126 | if (!element) |
| 127 | { |
| 128 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "cannot create element " <<cxx . . $ Glib/`operator<<`(d3a65685b7328161). factory_name <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | try |
| 133 | { |
| 134 | parent->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).addcxx . . $ Gst/Bin#add(25e1dc1b4b432bb3).(element); |
| 135 | element->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).set_statecxx . . $ Gst/Element#set_state(17bf573d41f9253f).(STATE_PLAYINGcxx . . $ Gst/STATE_PLAYING.); |
| 136 | pad->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).linkcxx . . $ Gst/Pad#link(ca9408873a0c7209).(element->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_static_padcxx . . $ Gst/Element#get_static_pad(d41a58e7b5052139).("sink"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).)); |
| 137 | } |
| 138 | catch (const stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#& err) |
| 139 | { |
| 140 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "cannot add element to a bin: " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). err.whatcxx . . $ std/runtime_error#what(a9f41ea0e82d88cf).() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char** argv) |
| 145 | { |
| 146 | if (argc < 2) |
| 147 | { |
| 148 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Usage: " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). argv[0] <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " <multimedia filename>" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 149 | return 1; |
| 150 | } |
| 151 | |
| 152 | initcxx . . $ Gst/init(22930d6ef54703eb).(argc, argv); |
| 153 | AllMediaPlayercxx . . $ AllMediaPlayer# playercxx . . $ AllMediaPlayer#AllMediaPlayer(49f6e7a06ebc5aa8).; |
| 154 | |
| 155 | try |
| 156 | { |
| 157 | player.play_until_eoscxx . . $ AllMediaPlayer#play_until_eos(9c546c94e5fcce4e).(argvcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).[1]); |
| 158 | } |
| 159 | catch (const stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#& err) |
| 160 | { |
| 161 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "runtime error: " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). err.whatcxx . . $ std/runtime_error#what(a9f41ea0e82d88cf).() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 162 | } |
| 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | |
| 168 |