[gstreamermm] Added typefind example.



commit f0ba310448018ee80a9ebe5a9179e896571ef157
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Aug 2 12:07:29 2009 +0200

    Added typefind example.
    
    * configure.ac:
    * examples/typefind/Makefile.am:
    * examples/typefind/main.cc: Added example of the use of the typefind
    element, to detect the mime-type of a media file.

 ChangeLog                     |    9 +++
 configure.ac                  |    1 +
 examples/Makefile.am          |    2 +-
 examples/typefind/Makefile.am |    6 ++
 examples/typefind/main.cc     |  115 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 132 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 313db8b..af6439c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-08-02  Murray Cumming  <murrayc murrayc com>
+
+	Added typefind example.
+
+	* configure.ac:
+	* examples/typefind/Makefile.am:
+	* examples/typefind/main.cc: Added example of the use of the typefind 
+	element, to detect the mime-type of a media file.
+
 2009-07-31  Murray Cumming  <murrayc murrayc com>
 
 	Tiny comment additions.
diff --git a/configure.ac b/configure.ac
index 911ee5b..8dd01e0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -316,6 +316,7 @@ AC_CONFIG_FILES([
     examples/ogg_player/Makefile
     examples/ogg_player_gtkmm/Makefile
     examples/media_player_gtkmm/Makefile
+    examples/typefind/Makefile
     ])
 AC_SUBST(EXAMPLE_SUBDIR)
 else
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 91a097c..80b0aa5 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1,5 +1,5 @@
 example_dirs = element_link media_player_gtkmm ogg_player ogg_player_gtkmm \
-	       optiongroup
+	       optiongroup typefind
 
 SUBDIRS = $(example_dirs)
 EXTRA_DIST = README Makefile.am_fragment
diff --git a/examples/typefind/Makefile.am b/examples/typefind/Makefile.am
new file mode 100644
index 0000000..0c79f50
--- /dev/null
+++ b/examples/typefind/Makefile.am
@@ -0,0 +1,6 @@
+include $(top_srcdir)/examples/Makefile.am_fragment
+
+#Build the executable, but don't install it.
+noinst_PROGRAMS = example
+example_SOURCES = main.cc
+
diff --git a/examples/typefind/main.cc b/examples/typefind/main.cc
new file mode 100644
index 0000000..ffa2804
--- /dev/null
+++ b/examples/typefind/main.cc
@@ -0,0 +1,115 @@
+/* gstreamermm - a C++ wrapper for gstreamer
+ *
+ * Copyright 2009 The gstreamermm Development Team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <gstreamermm.h>
+#include <iostream>
+
+Glib::RefPtr<Glib::MainLoop> mainloop;
+bool have_type = false;
+
+static void on_typefind_have_type(guint probability, const Glib::RefPtr<Gst::Caps>& caps)
+{
+  have_type = true;
+
+  std::cout << "have-type: probability=" << probability << std::endl;
+
+  if(!caps)
+  {
+    std::cerr << "on_typefind_have_type(): caps is null" << std::endl;
+    return;
+  }
+
+  const Gst::Structure structure = caps->get_structure(0);
+  const Glib::ustring mime_type = structure.get_name();
+  std::cout << "have-type: mime_type=" << mime_type << std::endl;
+
+  if(mainloop)
+    mainloop->quit();
+  else
+    std::cerr << "on_typefind_have_type(): mainloop is null" << std::endl;
+}
+
+int main(int argc, char** argv)
+{
+  // Initialize Gstreamermm:
+  Gst::init(argc, argv);
+
+  //Check input arguments:
+  if(argc < 2)
+  {
+    std::cout << "Usage: " << argv[0] << " <filename>" << std::endl;
+    return -1;
+  }
+
+  const std::string filename = argv[1];
+
+  // Create pipeline:
+  Glib::RefPtr<Gst::Pipeline> pipeline = Gst::Pipeline::create("my-pipeline");
+
+  // Create elements:
+  Glib::RefPtr<Gst::FileSrc> element_source = Gst::FileSrc::create();
+  element_source->property_location() = filename;
+
+  Glib::RefPtr<Gst::TypeFindElement> element_typefind = Gst::TypeFindElement::create();
+  element_typefind->signal_have_type().connect(
+    sigc::ptr_fun(&on_typefind_have_type) );
+  Glib::RefPtr<Gst::Element> element_sink = Gst::FakeSink::create();
+
+  // We must add the elements to the pipeline before linking them:
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  try
+  {
+#endif
+    pipeline->add(element_source)->add(element_typefind)->add(element_sink);
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  }
+  catch (std::runtime_error& ex)
+  {
+    std::cerr << "Exception while adding: " << ex.what() << std::endl;
+    return 1;
+  }
+#endif
+
+  // Link the elements together:
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  try
+  {
+#endif
+    element_source->link(element_typefind)->link(element_sink);
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  }
+  catch(const std::runtime_error& error)
+  {
+    std::cerr << "Exception while linking: " << error.what() << std::endl;
+  }
+#endif
+
+  // Now set the whole pipeline to playing and start the main loop:
+  std::cout << "Setting pipeline to PLAYING." << std::endl;
+  mainloop = Glib::MainLoop::create();
+  pipeline->set_state(Gst::STATE_PLAYING);
+  std::cout << "Pipeline is playing." << std::endl;
+  if(!have_type)
+    mainloop->run();
+
+  // Clean up nicely:
+  std::cout << "Returned. Stopping pipeline." << std::endl;
+  pipeline->set_state(Gst::STATE_NULL);
+
+  return 0;
+}



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