[gstreamermm: 161/167] added example



commit 5a145d3632fd24abcfadae6a8f6a086d59ceebb2
Author: Marcin Kolny at Flytronic.pl <marcin kolny flytronic pl>
Date:   Mon Aug 19 09:14:04 2013 +0200

    added example

 examples/Makefile.am                     |    2 +
 examples/dynamic_changing_source/main.cc |   98 ++++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+), 0 deletions(-)
---
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 7384ddc..1836275 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -26,6 +26,7 @@ endif
 noinst_PROGRAMS =                                              \
        audio_video_muxer/example                       \
        dynamic_changing_element/example        \
+       dynamic_changing_source/example         \
        element_link/example                            \
        hello_world/example                                     \
        ogg_player/example                                      \
@@ -43,6 +44,7 @@ LDADD = $(GSTREAMERMM_LIBS) $(local_libgstreamermm)
 
 audio_video_muxer_example_SOURCES                      = audio_video_muxer/main.cc
 dynamic_changing_element_example_SOURCES       = dynamic_changing_element/main.cc
+dynamic_changing_source_example_SOURCES                = dynamic_changing_source/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/dynamic_changing_source/main.cc b/examples/dynamic_changing_source/main.cc
new file mode 100644
index 0000000..3f46d56
--- /dev/null
+++ b/examples/dynamic_changing_source/main.cc
@@ -0,0 +1,98 @@
+/*
+ * main.cc
+ *
+ *  Created on: Aug 19, 2013
+ *      Author: m.kolny
+ */
+#include <gstreamermm.h>
+#include <glibmm.h>
+#include <iostream>
+
+using namespace Gst;
+using Glib::RefPtr;
+
+RefPtr<Element> src;
+RefPtr<Element> convert;
+RefPtr<Pipeline> pipeline;
+RefPtr<Glib::MainLoop> main_loop;
+
+bool on_timeout()
+{
+       static int pattern = 0;
+       src->set_state(STATE_NULL);
+       pipeline->remove(src);
+       src = ElementFactory::create_element("videotestsrc");
+       pattern = (pattern == 0) ? 18 : 0;
+       src->property("pattern",  pattern);
+       pipeline->add(src);
+       src->link(convert);
+       src->set_state(STATE_PLAYING);
+
+       return true;
+}
+
+int main(int argc, char** argv)
+{
+       if (argc < 2)
+       {
+               std::cout << "Usage: " << argv[0] << " <avi output filename>" << std::endl;
+               return 1;
+       }
+
+       init(argc, argv);
+       main_loop = Glib::MainLoop::create();
+
+       pipeline = Pipeline::create("effects-pipeline");
+
+       if (!pipeline)
+       {
+               std::cout << "Cannot create pipeline element." << std::endl;
+               return 1;
+       }
+
+       RefPtr<Element> queue1 = ElementFactory::create_element("queue"),
+                       queue2 = ElementFactory::create_element("queue"),
+                       tee = ElementFactory::create_element("tee"),
+                       autosink = ElementFactory::create_element("autovideosink"),
+                       sink = ElementFactory::create_element("filesink"),
+                       muxer = ElementFactory::create_element("avimux");
+
+       src = ElementFactory::create_element("videotestsrc");
+       src->property<int>("num-buffers", 100);
+       sink->property<Glib::ustring>("location", argv[1]);
+       convert = ElementFactory::create_element("videoconvert");
+
+       if (!queue1 || !queue2 || !tee || !autosink ||
+                       !sink || !muxer || !src || !sink || !convert)
+       {
+               std::cout << "Cannot create one of the elements." << std::endl;
+               return 1;
+       }
+
+       try
+       {
+               pipeline->add(src)->add(convert)->add(tee)->add(queue1)
+                               ->add(autosink)->add(queue2)->add(muxer)->add(sink);
+
+               src->link(convert)->link(tee)->link(queue1)->link(autosink);
+               tee->link(queue2)->link(muxer)->link(sink);
+       }
+       catch (const std::exception& ex)
+       {
+               std::cout << "Exception occured during preparing pipeline. Message: " << ex.what() << 
std::endl;
+               return 1;
+       }
+
+       pipeline->set_state(STATE_PLAYING);
+
+       Glib::signal_timeout().connect(sigc::ptr_fun(&on_timeout), 2000);
+       main_loop->run();
+
+       pipeline->set_state(STATE_NULL);
+
+  return 0;
+}
+
+
+
+


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