| 1 | /* |
| 2 | * This example presents basic usage of the Gst::Bus class. |
| 3 | */ |
| 4 | #include <gstreamermm.h>cxx . . $ `<file>/gstreamer/gstreamermm.h`/ |
| 5 | #include <glibmm/main.h> |
| 6 | |
| 7 | #include <iostream> |
| 8 | |
| 9 | Glibcxx . . $ Glib/::RefPtrcxx . . $ Glib/RefPtr#<Glibcxx . . $ Glib/::MainLoopcxx . . $ Glib/MainLoop#> main_loopcxx . . $ main_loop.; |
| 10 | |
| 11 | // Message watch function |
| 12 | 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) |
| 13 | { |
| 14 | // Print type of the message posted on the bus, and the source object name. |
| 15 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Got message of type " <<cxx . . $ Glib/`operator<<`(d3a65685b7328161). Gstcxx . . $ Gst/::Enumscxx . . $ Gst/Enums/::get_namecxx . . $ Gst/Enums/get_name(c0fae451ba8947aa).(message->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_message_typecxx . . $ Gst/Message#get_message_type(97914d44a9bd21bb).()) <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 16 | |
| 17 | if (message->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_sourcecxx . . $ Gst/Message#get_source(9952950db3828d1a).()) |
| 18 | { |
| 19 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Source object: " <<cxx . . $ Glib/`operator<<`(d3a65685b7328161). message->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_sourcecxx . . $ Gst/Message#get_source(9952950db3828d1a).()->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_namecxx . . $ Gst/Object#get_name(fff0f585954e56f3).() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 20 | } |
| 21 | |
| 22 | switch (message->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_message_typecxx . . $ Gst/Message#get_message_type(97914d44a9bd21bb).()) |
| 23 | { |
| 24 | // Handle ERROR message - print error and debug information |
| 25 | case Gstcxx . . $ Gst/::MESSAGE_ERRORcxx . . $ Gst/MESSAGE_ERROR.: |
| 26 | { |
| 27 | auto error_msg = Glibcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).::RefPtrcxx . . $ Glib/RefPtr#<Gst::MessageError>::cast_staticcxx . . $ Glib/RefPtr#cast_static(18212fa50966cf79).(message); |
| 28 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Error: " <<cxx . . $ Glib/`operator<<`(d3a65685b7328161). error_msg->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).parse_errorcxx . . $ Gst/MessageError#parse_error(565d2be64918d679).().whatcxx . . $ Glib/Error#what(fff0f585954e56f3).() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 29 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Debug: " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). error_msg->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).parse_debugcxx . . $ Gst/MessageError#parse_debug(219584694fe2b248).() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 30 | break; |
| 31 | } |
| 32 | // Handle EOS message - quit the loop |
| 33 | case Gstcxx . . $ Gst/::MESSAGE_EOScxx . . $ Gst/MESSAGE_EOS.: |
| 34 | main_loopcxx . . $ main_loop.->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).quitcxx . . $ Glib/MainLoop#quit(49f6e7a06ebc5aa8).(); |
| 35 | break; |
| 36 | // Handle state changed message - print details |
| 37 | case Gstcxx . . $ Gst/::MESSAGE_STATE_CHANGEDcxx . . $ Gst/MESSAGE_STATE_CHANGED.: |
| 38 | { |
| 39 | auto state_changed_msg = Glibcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).::RefPtrcxx . . $ Glib/RefPtr#<Gst::MessageStateChanged>::cast_staticcxx . . $ Glib/RefPtr#cast_static(5cfbc7b574b06143).(message); |
| 40 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Old state: " <<cxx . . $ Glib/`operator<<`(d3a65685b7328161). Gstcxx . . $ Gst/::Enumscxx . . $ Gst/Enums/::get_namecxx . . $ Gst/Enums/get_name(47fa988766e80c0c).(state_changed_msg->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).parse_old_statecxx . . $ Gst/MessageStateChanged#parse_old_state(e9887b553a311197).()) <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 41 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "New state: " <<cxx . . $ Glib/`operator<<`(d3a65685b7328161). Gstcxx . . $ Gst/::Enumscxx . . $ Gst/Enums/::get_namecxx . . $ Gst/Enums/get_name(47fa988766e80c0c).(state_changed_msg->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).parse_new_statecxx . . $ Gst/MessageStateChanged#parse_new_state(e9887b553a311197).()) <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 42 | break; |
| 43 | } |
| 44 | // Unhanlded messages |
| 45 | default: |
| 46 | break; |
| 47 | } |
| 48 | |
| 49 | return true; |
| 50 | } |
| 51 | |
| 52 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[]) |
| 53 | { |
| 54 | Gstcxx . . $ Gst/::initcxx . . $ Gst/init(22930d6ef54703eb).(argc, argv); |
| 55 | |
| 56 | // Create some elements |
| 57 | 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(bde311d80d2d00e5).("videotestsrc"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9)., "source"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).); |
| 58 | Glibcxx . . $ Glib/::RefPtrcxx . . $ Glib/RefPtr#<Gstcxx . . $ Gst/::Elementcxx . . $ Gst/Element#> sink = Gstcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).::ElementFactorycxx . . $ Gst/ElementFactory#::create_elementcxx . . $ Gst/ElementFactory#create_element(bde311d80d2d00e5).("autovideosink"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9)., "sink"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9).); |
| 59 | |
| 60 | // Create pipeline |
| 61 | 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).); |
| 62 | |
| 63 | // Add elements to a pipeline |
| 64 | try |
| 65 | { |
| 66 | pipeline->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).addcxx . . $ Gst/Bin#add(25e1dc1b4b432bb3).(source)->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).addcxx . . $ Gst/Bin#add(25e1dc1b4b432bb3).(sink); |
| 67 | } |
| 68 | catch (const stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#& ex) |
| 69 | { |
| 70 | 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).; |
| 71 | return 1; |
| 72 | } |
| 73 | |
| 74 | // Link elements |
| 75 | try |
| 76 | { |
| 77 | source->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).linkcxx . . $ Gst/Element#link(52e71ea9673343b3).(sink); |
| 78 | } |
| 79 | catch (const stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#& ex) |
| 80 | { |
| 81 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Exception while linking: " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ex.whatcxx . . $ std/runtime_error#what(a9f41ea0e82d88cf).() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 82 | } |
| 83 | |
| 84 | // Get a bus object of the pipeline |
| 85 | Glibcxx . . $ Glib/::RefPtrcxx . . $ Glib/RefPtr#<Gstcxx . . $ Gst/::Buscxx . . $ Gst/Bus#> bus = pipelinecxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_buscxx . . $ Gst/Pipeline#get_bus(ada66d6ded80d30d).(); |
| 86 | |
| 87 | // Add watch to the bus |
| 88 | bus->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).)); |
| 89 | |
| 90 | // Start pipeline |
| 91 | pipeline->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).set_statecxx . . $ Gst/Element#set_state(17bf573d41f9253f).(Gstcxx . . $ Gst/::STATE_PLAYINGcxx . . $ Gst/STATE_PLAYING.); |
| 92 | |
| 93 | main_loopcxx . . $ main_loop. =cxx . . $ Glib/RefPtr#`operator=`(b66de19e2ab7ce1f). Glibcxx . . $ Glib/::MainLoopcxx . . $ Glib/MainLoop#::createcxx . . $ Glib/MainLoop#create(748caac81bf5da26).(); |
| 94 | main_loopcxx . . $ main_loop.->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).runcxx . . $ Glib/MainLoop#run(49f6e7a06ebc5aa8).(); |
| 95 | |
| 96 | // Stop playing the pipeline |
| 97 | pipeline->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).set_statecxx . . $ Gst/Element#set_state(17bf573d41f9253f).(Gstcxx . . $ Gst/::STATE_NULLcxx . . $ Gst/STATE_NULL.); |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 |