[gstreamermm: 66/167] added simple example



commit 296d3d51ad3cb09a61b20987839b8453e995fe11
Author: Marcin Kolny at Flytronic <marcin kolny flytronic pl>
Date:   Mon Jul 29 14:13:06 2013 +0200

    added simple example

 examples/Makefile.am          |    2 +
 examples/ogg_rewriter/main.cc |   70 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 0 deletions(-)
---
diff --git a/examples/Makefile.am b/examples/Makefile.am
index ed834cc..211a094 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -24,6 +24,7 @@ examples_cppflags = $(GSTREAMERMM_CFLAGS)
 endif
 
 noinst_PROGRAMS =                      \
+       ogg_rewriter/example
        $(optional_examples)
 
 gstreamermm_includes = -I$(top_builddir)/gstreamer $(if $(srcdir:.=),-I$(top_srcdir)/gstreamer)
@@ -35,6 +36,7 @@ LDADD = $(GSTREAMERMM_LIBS) $(local_libgstreamermm)
 
 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
diff --git a/examples/ogg_rewriter/main.cc b/examples/ogg_rewriter/main.cc
new file mode 100644
index 0000000..6a18211
--- /dev/null
+++ b/examples/ogg_rewriter/main.cc
@@ -0,0 +1,70 @@
+#include <gstreamermm.h>
+#include <glibmm.h>
+#include <iostream>
+#include <stdlib.h>
+
+Glib::RefPtr<Glib::MainLoop> mainloop;
+
+bool on_bus_message(const Glib::RefPtr<Gst::Bus>& /* bus */,
+  const Glib::RefPtr<Gst::Message>& message)
+{
+  switch(message->get_message_type()) {
+    case Gst::MESSAGE_EOS:
+      std::cout << std::endl << "End of stream" << std::endl;
+      mainloop->quit();
+      return false;
+    case Gst::MESSAGE_ERROR:
+    {
+        std::cerr << "Error." << std::endl;
+        mainloop->quit();
+        return false;
+    }
+    default:
+      break;
+  }
+
+  return true;
+}
+
+int main(int argc, char** argv)
+{
+  Gst::init(argc, argv);
+  Glib::RefPtr<Gst::Pipeline> pipeline;
+
+  if(argc < 3)
+  {
+    std::cout << "Usage: " << argv[0] << " <input ogg file> <output ogg file>" << std::endl;
+    return EXIT_FAILURE;
+  }
+
+  Glib::RefPtr<Gst::FileSrc> filesrc = Gst::FileSrc::create();
+
+  if(!filesrc)
+  {
+    std::cerr << "The playbin2 element could not be created." << std::endl;
+    return EXIT_FAILURE;
+  }
+
+  filesrc->property_location() = argv[1];
+
+  mainloop = Glib::MainLoop::create();
+  pipeline = Gst::Pipeline::create("rewriter");
+  Glib::RefPtr<Gst::FileSink> filesink = Gst::FileSink::create();
+  filesink->property_location() = argv[2];
+
+  Glib::RefPtr<Gst::Bus> bus = pipeline->get_bus();
+  bus->add_watch(sigc::ptr_fun(&on_bus_message));
+
+  pipeline->add(filesrc)->add(filesink);
+
+  std::cout << "Setting to PLAYING." << std::endl;
+  pipeline->set_state(Gst::STATE_PLAYING);
+  filesrc->link(filesink);
+  std::cout << "Running." << std::endl;
+  mainloop->run();
+
+  std::cout << "Returned. Setting state to NULL." << std::endl;
+  pipeline->set_state(Gst::STATE_NULL);
+
+  return EXIT_SUCCESS;
+}


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