[gstreamermm: 157/167] added example with matroska, minor fix in Pad class



commit 87b6860cb8b2c95f0d1b87cbd7cb19c35fffe33a
Author: Marcin Kolny at Flytronic.pl <marcin kolny flytronic pl>
Date:   Wed Aug 14 09:33:23 2013 +0200

    added example with matroska, minor fix in Pad class

 examples/Makefile.am               |   16 +++--
 examples/audio_video_muxer/main.cc |  118 ++++++++++++++++++++++++++++++++++++
 gstreamer/src/pad.hg               |    2 +-
 3 files changed, 128 insertions(+), 8 deletions(-)
---
diff --git a/examples/Makefile.am b/examples/Makefile.am
index bd9e04d..ec15725 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -23,13 +23,14 @@ optional_examples =
 examples_cppflags = $(GSTREAMERMM_CFLAGS)
 endif
 
-noinst_PROGRAMS =                      \
-       element_link/example    \
-       hello_world/example             \
-       ogg_player/example              \
-       ogg_rewriter/example    \
-       typefind/example        \
-       optiongroup/example     \
+noinst_PROGRAMS =                              \
+       audio_video_muxer/example       \
+       element_link/example            \
+       hello_world/example                     \
+       ogg_player/example                      \
+       ogg_rewriter/example            \
+       typefind/example                        \
+       optiongroup/example                     \
        $(optional_examples)
 
 gstreamermm_includes = -I$(top_builddir)/gstreamer $(if $(srcdir:.=),-I$(top_srcdir)/gstreamer)
@@ -39,6 +40,7 @@ AM_CPPFLAGS = -I$(top_builddir) $(gstreamermm_includes) $(examples_cppflags)
 AM_CXXFLAGS = $(GSTREAMERMM_WXXFLAGS)
 LDADD = $(GSTREAMERMM_LIBS) $(local_libgstreamermm)
 
+audio_video_muxer_example_SOURCES      = audio_video_muxer/main.cc
 element_link_example_SOURCES           = element_link/element_link.cc
 hello_world_example_SOURCES            = hello_world/main.cc
 ogg_rewriter_example_SOURCES           = ogg_rewriter/main.cc
diff --git a/examples/audio_video_muxer/main.cc b/examples/audio_video_muxer/main.cc
new file mode 100644
index 0000000..61b3377
--- /dev/null
+++ b/examples/audio_video_muxer/main.cc
@@ -0,0 +1,118 @@
+/*
+ * main.cc
+ *
+ *  Created on: Aug 14, 2013
+ *      Author: m.kolny
+ */
+
+#include <gstreamermm.h>
+#include <iostream>
+#include <glibmm.h>
+
+using namespace Gst;
+using Glib::RefPtr;
+
+RefPtr<Element> video_parser, audio_parser;
+RefPtr<Glib::MainLoop> main_loop;
+
+bool on_bus_message(const RefPtr<Gst::Bus>& bus,
+                    const RefPtr<Message>& message)
+{
+       switch(message->get_message_type())
+       {
+               case Gst::MESSAGE_EOS:
+                       std::cout << std::endl << "End of stream" << std::endl;
+                       main_loop->quit();
+                       return false;
+               case Gst::MESSAGE_ERROR:
+               {
+                       std::cerr << "Error." << std::endl;
+                       main_loop->quit();
+                       return false;
+               }
+               default:
+                       break;
+       }
+
+       return true;
+}
+
+void on_demux_pad_added(const RefPtr<Pad>& newPad)
+{
+       std::cout << "Dynamic pad created. Linking demuxer/decoder." << std::endl;
+       RefPtr<Pad> sinkPad = video_parser->get_static_pad("sink");
+       PadLinkReturn ret = newPad->link(sinkPad);
+
+       if (ret != PAD_LINK_OK && ret != PAD_LINK_WAS_LINKED)
+       {
+               std::cerr << "Linking of pads " << newPad->get_name() << " and " <<
+                               sinkPad->get_name() << " failed." << std::endl;
+       }
+}
+
+int main(int argc, char** argv)
+{
+       if (argc < 3)
+       {
+               std::cout << "Usage: " << argv[0] << " <Ogg/Vorbis filename>"
+                               " <mp3 filename> <mkv output filename>" << std::endl;
+               return 1;
+       }
+
+       init(argc, argv);
+
+       RefPtr<Pipeline> pipeline = Pipeline::create("play-pipeline");
+       main_loop = Glib::MainLoop::create();
+       RefPtr<Bus> bus = pipeline->get_bus();
+       bus->add_watch(sigc::ptr_fun(&on_bus_message));
+
+       RefPtr<FileSrc> video_source = FileSrc::create(),
+                       audio_source = FileSrc::create();
+
+       RefPtr<Element> ogg_demuxer = ElementFactory::create_element("oggdemux");
+       audio_parser = ElementFactory::create_element("mad");
+
+       RefPtr<Element> audiosink = ElementFactory::create_element("autoaudiosink"),
+                       videosink = ElementFactory::create_element("autovideosink");
+
+       RefPtr<Element> muxer = ElementFactory::create_element("matroskamux");
+       RefPtr<FileSink> filesink = FileSink::create();
+
+       video_parser = ElementFactory::create_element("theoraparse");
+
+       if (!video_source || !ogg_demuxer || !video_parser || !videosink || !pipeline || !audio_parser || 
!audio_source)
+       {
+               std::cout << "One element could not be created." << std::endl;
+               return 1;
+       }
+
+       video_source->property_location() = argv[1];
+       audio_source->property_location() = argv[2];
+       filesink->property_location() = argv[3];
+
+       pipeline->add(video_source)->
+                       add(ogg_demuxer)->
+                       add(video_parser)->
+                       add(audio_source)->
+                       add(audio_parser)->
+                       add(muxer)->
+                       add(filesink);
+
+       ogg_demuxer->signal_pad_added().connect(sigc::ptr_fun(&on_demux_pad_added));
+
+       video_source->link(ogg_demuxer);
+       video_parser->link(muxer);
+       audio_source->link(audio_parser)->link(muxer);
+       muxer->link(filesink);
+
+       pipeline->set_state(STATE_PLAYING);
+
+       main_loop->run();
+
+       pipeline->set_state(STATE_NULL);
+
+       return 0;
+}
+
+
+
diff --git a/gstreamer/src/pad.hg b/gstreamer/src/pad.hg
index 03a0b85..b606e9d 100644
--- a/gstreamer/src/pad.hg
+++ b/gstreamer/src/pad.hg
@@ -444,7 +444,7 @@ public:
 
   _WRAP_METHOD(Glib::RefPtr<Gst::Event> get_event(), gst_pad_probe_info_get_event)
   _WRAP_METHOD(Glib::RefPtr<Gst::Query> get_query(), gst_pad_probe_info_get_query)
-  _WRAP_METHOD(Glib::RefPtr<Gst::Buffer> get_buffer(), gst_pad_probe_info_get_buffer)
+  _WRAP_METHOD(Glib::RefPtr<Gst::Buffer> get_buffer(), gst_pad_probe_info_get_buffer, refreturn)
   _WRAP_METHOD(Glib::RefPtr<Gst::BufferList> get_buffer_list(), gst_pad_probe_info_get_buffer_list)
 protected:
 #ifndef DOXYGEN_SHOULD_SKIP_THIS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]