[gstreamermm: 159/167] added sample with dynamic changing pipeline



commit ecb086aa4d4a51c5b8443bdaafa08da1f2319b1b
Author: Marcin Kolny at Flytronic.pl <marcin kolny flytronic pl>
Date:   Wed Aug 14 13:20:14 2013 +0200

    added sample with dynamic changing pipeline

 examples/Makefile.am                      |   50 +++++++------
 examples/dynamic_changing_element/main.cc |  113 +++++++++++++++++++++++++++++
 2 files changed, 139 insertions(+), 24 deletions(-)
---
diff --git a/examples/Makefile.am b/examples/Makefile.am
index ec15725..7384ddc 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -23,35 +23,37 @@ optional_examples =
 examples_cppflags = $(GSTREAMERMM_CFLAGS)
 endif
 
-noinst_PROGRAMS =                              \
-       audio_video_muxer/example       \
-       element_link/example            \
-       hello_world/example                     \
-       ogg_player/example                      \
-       ogg_rewriter/example            \
-       typefind/example                        \
-       optiongroup/example                     \
+noinst_PROGRAMS =                                              \
+       audio_video_muxer/example                       \
+       dynamic_changing_element/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)
 local_libgstreamermm = $(top_builddir)/gstreamer/gstreamermm/libgstreamermm-$(GSTREAMERMM_API_VERSION).la
 
 AM_CPPFLAGS = -I$(top_builddir) $(gstreamermm_includes) $(examples_cppflags)
-AM_CXXFLAGS = $(GSTREAMERMM_WXXFLAGS)
+AM_CXXFLAGS = $(GSTREAMERMM_WXXFLAGS) -std=c++0x
 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
-media_player_gtkmm_example_SOURCES     = media_player_gtkmm/main.cc \
-                                         media_player_gtkmm/player_window.cc \
-                                         media_player_gtkmm/player_window.h
-media_player_gtkmm_example_LDADD       = $(GUI_EXAMPLES_LIBS) $(local_libgstreamermm)
-ogg_player_example_SOURCES             = ogg_player/main.cc
-ogg_player_gtkmm_example_SOURCES       = ogg_player_gtkmm/main.cc \
-                                         ogg_player_gtkmm/player_window.cc \
-                                         ogg_player_gtkmm/player_window.h
-ogg_player_gtkmm_example_LDADD         = $(GUI_EXAMPLES_LIBS) $(local_libgstreamermm)
-optiongroup_example_SOURCES            = optiongroup/main.cc
-typefind_example_SOURCES               = typefind/main.cc
+audio_video_muxer_example_SOURCES                      = audio_video_muxer/main.cc
+dynamic_changing_element_example_SOURCES       = dynamic_changing_element/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
+media_player_gtkmm_example_SOURCES                     = media_player_gtkmm/main.cc \
+                                                                                               
media_player_gtkmm/player_window.cc \
+                                                                                               
media_player_gtkmm/player_window.h
+media_player_gtkmm_example_LDADD                       = $(GUI_EXAMPLES_LIBS) $(local_libgstreamermm)
+ogg_player_example_SOURCES                                     = ogg_player/main.cc
+ogg_player_gtkmm_example_SOURCES                       = ogg_player_gtkmm/main.cc \
+                                                                                               
ogg_player_gtkmm/player_window.cc \
+                                                                                               
ogg_player_gtkmm/player_window.h
+ogg_player_gtkmm_example_LDADD                         = $(GUI_EXAMPLES_LIBS) $(local_libgstreamermm)
+optiongroup_example_SOURCES                                    = optiongroup/main.cc
+typefind_example_SOURCES                                       = typefind/main.cc
diff --git a/examples/dynamic_changing_element/main.cc b/examples/dynamic_changing_element/main.cc
new file mode 100644
index 0000000..0690631
--- /dev/null
+++ b/examples/dynamic_changing_element/main.cc
@@ -0,0 +1,113 @@
+/*
+ * main.cc
+ *
+ *  Created on: Aug 14, 2013
+ *      Author: m.kolny
+ *
+ *      based on sample described here: 
http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/section-dynamic-pipelines.html
+ */
+
+#include <gstreamermm.h>
+#include <glibmm.h>
+#include <iostream>
+#include <vector>
+
+using namespace Gst;
+using Glib::RefPtr;
+
+RefPtr<Pad> blockpad;
+RefPtr<Element> conv_before,
+conv_after,
+curr_effect;
+RefPtr<Pipeline> pipeline;
+std::vector<Glib::ustring> effects = {"identity", "exclusion",
+               "navigationtest", "agingtv", "videoflip", "vertigotv",
+               "gaussianblur", "shagadelictv", "edgetv"};
+int curr_position = 0;
+
+RefPtr<Glib::MainLoop> main_loop;
+
+PadProbeReturn event_probe_cb (const RefPtr<Pad>& pad, const PadProbeInfo& info)
+{
+       RefPtr<Event> event = info.get_event();
+       if (event->get_event_type()!= EVENT_EOS)
+               return PAD_PROBE_OK;
+
+       pad->remove_probe(info.get_id());
+
+       curr_effect->set_state(STATE_NULL);
+       pipeline->remove(curr_effect);
+       curr_effect = ElementFactory::create_element(effects[curr_position++ % effects.size()]);
+       pipeline->add(curr_effect);
+       conv_before->link(curr_effect)->link(conv_after);
+       curr_effect->set_state(STATE_PLAYING);
+
+       return PAD_PROBE_DROP;
+}
+
+PadProbeReturn pad_probe_cb(const RefPtr<Pad>& pad, const PadProbeInfo& info)
+{
+       pad->remove_probe(info.get_id());
+
+       RefPtr<Pad> srcpad = curr_effect->get_static_pad("src");
+       srcpad->add_probe(PAD_PROBE_TYPE_BLOCK | PAD_PROBE_TYPE_EVENT_DOWNSTREAM, 
sigc::ptr_fun(event_probe_cb));
+       RefPtr<Pad> sinkpad = curr_effect->get_static_pad("sink");
+       sinkpad->send_event(EventEos::create());
+       return PAD_PROBE_OK;
+}
+
+bool on_bus_message(const Glib::RefPtr<Gst::Bus>& bus,
+                    const Glib::RefPtr<Gst::Message>& message)
+{
+       switch (message->get_message_type())
+       {
+               case MESSAGE_ERROR:
+                       std::cerr << "Error." << std::endl;
+                       main_loop->quit();
+                       return false;
+               default:
+                       break;
+       }
+
+       return true;
+}
+bool on_timeout()
+{
+       blockpad->add_probe(PAD_PROBE_TYPE_BLOCK_DOWNSTREAM, sigc::ptr_fun(&pad_probe_cb));
+       return true;
+}
+
+int main(int argc, char** argv)
+{
+       init(argc, argv);
+       main_loop = Glib::MainLoop::create();
+
+       pipeline = Pipeline::create("effects-pipeline");
+
+       RefPtr<Element> src = ElementFactory::create_element("videotestsrc"),
+                       sink = ElementFactory::create_element("xvimagesink");
+
+       conv_before = ElementFactory::create_element("videoconvert");
+       curr_effect = ElementFactory::create_element(effects[curr_position++]);
+       conv_after = ElementFactory::create_element("videoconvert");
+
+       blockpad = src->get_static_pad("src");
+       src->property("is-live", true);
+
+       pipeline->add(src)->add(conv_before)->add(curr_effect)->add(conv_after)->add(sink);
+       src->link(conv_before)->link(curr_effect)->link(conv_after)->link(sink);
+
+       RefPtr<Bus> bus = pipeline->get_bus();
+       bus->add_watch(sigc::ptr_fun(on_bus_message));
+
+       pipeline->set_state(STATE_PLAYING);
+
+       Glib::signal_timeout().connect(sigc::ptr_fun(&on_timeout), 1000);
+       main_loop->run();
+
+       pipeline->set_state(STATE_NULL);
+
+       return 0;
+}
+
+


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