| 1 | /* gstreamermm - a C++ wrapper for gstreamer |
| 2 | * |
| 3 | * Copyright 2011 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 | #include <glibmm/convert.h> |
| 22 | #include <iostream> |
| 23 | #include <stdlib.h> |
| 24 | #include <gstreamermm/playbin.h>cxx . . $ `<file>/gstreamer/gstreamermm/playbin.h`/ |
| 25 | |
| 26 | namespacecxx . . $ `$anonymous_namespace_examples/hello_world/main.cc`/ |
| 27 | { |
| 28 | |
| 29 | Glibcxx . . $ Glib/::RefPtrcxx . . $ Glib/RefPtr#<Glibcxx . . $ Glib/::MainLoopcxx . . $ Glib/MainLoop#> mainloopcxx . . $ `$anonymous_namespace_examples/hello_world/main.cc`/mainloop.; |
| 30 | |
| 31 | // This function is used to receive asynchronous messages in the main loop. |
| 32 | bool on_bus_messagecxx . . $ `$anonymous_namespace_examples/hello_world/main.cc`/on_bus_message(f80753751e77bf04).(const Glibcxx . . $ Glib/::RefPtrcxx . . $ Glib/RefPtr#<Gstcxx . . $ Gst/::Buscxx . . $ Gst/Bus#>& /* bus */, |
| 33 | const Glibcxx . . $ Glib/::RefPtrcxx . . $ Glib/RefPtr#<Gstcxx . . $ Gst/::Messagecxx . . $ Gst/Message#>& message) |
| 34 | { |
| 35 | switch(message->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_message_typecxx . . $ Gst/Message#get_message_type(97914d44a9bd21bb).()) { |
| 36 | case Gstcxx . . $ Gst/::MESSAGE_EOScxx . . $ Gst/MESSAGE_EOS.: |
| 37 | 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).; |
| 38 | mainloopcxx . . $ `$anonymous_namespace_examples/hello_world/main.cc`/mainloop.->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).quitcxx . . $ Glib/MainLoop#quit(49f6e7a06ebc5aa8).(); |
| 39 | return false; |
| 40 | case Gstcxx . . $ Gst/::MESSAGE_ERRORcxx . . $ Gst/MESSAGE_ERROR.: |
| 41 | { |
| 42 | Glibcxx . . $ Glib/::RefPtrcxx . . $ Glib/RefPtr#<Gstcxx . . $ Gst/::MessageErrorcxx . . $ Gst/MessageError#> msgError = |
| 43 | Glibcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).::RefPtrcxx . . $ Glib/RefPtr#<Gst::MessageError>::cast_staticcxx . . $ Glib/RefPtr#cast_static(18212fa50966cf79).(message); |
| 44 | |
| 45 | if(msgError) |
| 46 | { |
| 47 | Glibcxx . . $ Glib/::Errorcxx . . $ Glib/Error# errcxx . . $ Glib/Error#Error(49f6e7a06ebc5aa8).; |
| 48 | err =cxx . . $ Glib/Error#`operator=`(43eb97e7ea8857bc). msgError->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).parse_errorcxx . . $ Gst/MessageError#parse_error(565d2be64918d679).(); |
| 49 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Error: " <<cxx . . $ Glib/`operator<<`(d3a65685b7328161). err.whatcxx . . $ Glib/Error#what(fff0f585954e56f3).() <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 50 | } |
| 51 | else |
| 52 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Error." <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 53 | |
| 54 | mainloopcxx . . $ `$anonymous_namespace_examples/hello_world/main.cc`/mainloop.->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).quitcxx . . $ Glib/MainLoop#quit(49f6e7a06ebc5aa8).(); |
| 55 | return false; |
| 56 | } |
| 57 | default: |
| 58 | break; |
| 59 | } |
| 60 | |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | } // anonymous namespace |
| 65 | |
| 66 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char** argv) |
| 67 | { |
| 68 | // Initialize gstreamermm: |
| 69 | Gstcxx . . $ Gst/::initcxx . . $ Gst/init(22930d6ef54703eb).(argc, argv); |
| 70 | |
| 71 | // Check input arguments: |
| 72 | if(argc < 2) |
| 73 | { |
| 74 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Usage: " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). argv[0] <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " <media file or uri>" <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 75 | return EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!; |
| 76 | } |
| 77 | |
| 78 | // Create a playbin element. |
| 79 | #ifndef GSTREAMERMM_DISABLE_DEPRECATED |
| 80 | Glibcxx . . $ Glib/::RefPtrcxx . . $ Glib/RefPtr#<Gstcxx . . $ Gst/::PlayBincxx . . $ Gst/PlayBin#> playbin = Gstcxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).::PlayBincxx . . $ Gst/PlayBin#::createcxx . . $ Gst/PlayBin#create(c8f10ae5e361d455).(); |
| 81 | #else |
| 82 | Glib::RefPtr<Gst::Element> playbin = Gst::ElementFactory::create_element("playbin"); |
| 83 | #endif |
| 84 | |
| 85 | if(!playbin) |
| 86 | { |
| 87 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "The playbin2 element could not be created." <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 88 | return EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!; |
| 89 | } |
| 90 | |
| 91 | // Take the commandline argument and ensure that it is a uri: |
| 92 | Glibcxx . . $ Glib/::ustringcxx . . $ Glib/ustring# uricxx . . $ Glib/ustring#ustring(49f6e7a06ebc5aa8).; |
| 93 | |
| 94 | if(gst_uri_is_valid(argv[1])) |
| 95 | uri =cxx . . $ Glib/ustring#`operator=`(6082a55360a9226). argv[1]; |
| 96 | else |
| 97 | uri =cxx . . $ Glib/ustring#`operator=`(277b37d9861608cd). Glibcxx . . $ Glib/::filename_to_uricxx . . $ Glib/filename_to_uri(c7e6347fcccd7bf7).(argvcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).[1]); |
| 98 | |
| 99 | // Set the playbyin2's uri property. |
| 100 | playbin->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).set_propertycxx . . $ Glib/ObjectBase#set_property(29831774a8731cb).("uri"cxx . . $ Glib/ustring#ustring(85c52e162fed56f9)., uri); |
| 101 | |
| 102 | // Create the main loop. |
| 103 | mainloopcxx . . $ `$anonymous_namespace_examples/hello_world/main.cc`/mainloop. =cxx . . $ Glib/RefPtr#`operator=`(b66de19e2ab7ce1f). Glibcxx . . $ Glib/::MainLoopcxx . . $ Glib/MainLoop#::createcxx . . $ Glib/MainLoop#create(748caac81bf5da26).(); |
| 104 | |
| 105 | // Get the bus from the playbin, and add a bus watch to the default main |
| 106 | // context with the default priority: |
| 107 | Glibcxx . . $ Glib/::RefPtrcxx . . $ Glib/RefPtr#<Gstcxx . . $ Gst/::Buscxx . . $ Gst/Bus#> bus = playbincxx . . $ Glib/RefPtr#RefPtr(b50b0f543100b439).->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).get_buscxx . . $ Gst/Pipeline#get_bus(ada66d6ded80d30d).(); |
| 108 | bus->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).add_watchcxx . . $ Gst/Bus#add_watch(125cf56d22b1e63d).(sigccxx . . $ sigc/slot#slot(edcd8b2679e9bd1a).::ptr_funcxx . . $ sigc/ptr_fun(1a86a404afb7766).(&on_bus_messagecxx . . $ `$anonymous_namespace_examples/hello_world/main.cc`/on_bus_message(f80753751e77bf04).)); |
| 109 | |
| 110 | // Now set the playbin to the PLAYING state and start the main loop: |
| 111 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Setting to PLAYING." <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 112 | playbin->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).set_statecxx . . $ Gst/Element#set_state(17bf573d41f9253f).(Gstcxx . . $ Gst/::STATE_PLAYINGcxx . . $ Gst/STATE_PLAYING.); |
| 113 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Running." <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 114 | mainloopcxx . . $ `$anonymous_namespace_examples/hello_world/main.cc`/mainloop.->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).runcxx . . $ Glib/MainLoop#run(49f6e7a06ebc5aa8).(); |
| 115 | |
| 116 | // Clean up nicely: |
| 117 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Returned. Setting state to NULL." <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 118 | playbin->cxx . . $ Glib/RefPtr#`operator->`(5a2a78a048fb49a8).set_statecxx . . $ Gst/Element#set_state(17bf573d41f9253f).(Gstcxx . . $ Gst/::STATE_NULLcxx . . $ Gst/STATE_NULL.); |
| 119 | |
| 120 | return EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`!; |
| 121 | } |