gnomemm r1542 - in gstreamermm/trunk: gstreamer/gstreamermm gstreamer/src tests



Author: jaalburqu
Date: Fri May 30 04:05:36 2008
New Revision: 1542
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1542&view=rev

Log:
2008-05-29  Josà Alburquerque  <jaalburqu svn gnome org>

	* gstreamer/src/caps.ccg:
	* gstreamer/src/caps.hg: Added set_simple() method which in
	conjunction with newly added Gst::StructureValue<> allows setting of
	fields w/o the need to use Glib::ValueBase (as Gtk::TreeRow does).
	* gstreamer/gstreamermm/Makefile.am:
	* gstreamer/gstreamermm/structurevalue.cc:
	* gstreamer/gstreamermm/structurevalue.h: Added to allow setting of
	simple Gst::Caps fields w/o need to use Glib::Value<>.
	* tests/test-caps.cc: Modified to test Gst::Caps::set_simple() with
	regular C++ types.
	* gstreamer/src/elementfactory.hg: Did not rename find() to create()
	because in theory ElementFactories "pre-exist" so find() seems to make
	more sense. gst_element_factory_create() creates elements from a
	specified factory.

Added:
   gstreamermm/trunk/gstreamer/gstreamermm/structurevalue.cc
   gstreamermm/trunk/gstreamer/gstreamermm/structurevalue.h
Modified:
   gstreamermm/trunk/gstreamer/gstreamermm/Makefile.am
   gstreamermm/trunk/gstreamer/src/caps.ccg
   gstreamermm/trunk/gstreamer/src/caps.hg
   gstreamermm/trunk/gstreamer/src/elementfactory.hg
   gstreamermm/trunk/tests/test-caps.cc

Modified: gstreamermm/trunk/gstreamer/gstreamermm/Makefile.am
==============================================================================
--- gstreamermm/trunk/gstreamer/gstreamermm/Makefile.am	(original)
+++ gstreamermm/trunk/gstreamer/gstreamermm/Makefile.am	Fri May 30 04:05:36 2008
@@ -13,12 +13,12 @@
 
 sublib_files_extra_posix_cc = 
 sublib_files_extra_win32_cc =
-sublib_files_extra_general_cc = init.cc miniobject.cc object.cc version.cc wrap.cc gst_wrap_init.cc taglist.cc
+sublib_files_extra_general_cc = init.cc miniobject.cc object.cc version.cc wrap.cc gst_wrap_init.cc taglist.cc structurevalue.cc
 sublib_files_extra_general_deprecated_cc = 
 
 sublib_files_extra_posix_h = 
 sublib_files_extra_win32_h =
-sublib_files_extra_general_h = init.h miniobject.h object.h version.h wrap.h gst_wrap_init.h taglist.h
+sublib_files_extra_general_h = init.h miniobject.h object.h version.h wrap.h gst_wrap_init.h taglist.h structurevalue.h
 sublib_files_extra_general_deprecated_h = 
 
 include $(top_srcdir)/build_shared/Makefile_build.am_fragment

Added: gstreamermm/trunk/gstreamer/gstreamermm/structurevalue.cc
==============================================================================
--- (empty file)
+++ gstreamermm/trunk/gstreamer/gstreamermm/structurevalue.cc	Fri May 30 04:05:36 2008
@@ -0,0 +1,35 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* gstreamermm - a C++ wrapper for gstreamer
+ *
+ * Copyright 2008 The gstreamermm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gstreamermm/structurevalue.h>
+
+namespace Gst
+{
+
+/**** Gst::StructureValueBase *****************************************/
+
+StructureValueBase::StructureValueBase(GType type)
+:
+  type_  (type)
+{}
+
+} // namespace Gst
+

Added: gstreamermm/trunk/gstreamer/gstreamermm/structurevalue.h
==============================================================================
--- (empty file)
+++ gstreamermm/trunk/gstreamer/gstreamermm/structurevalue.h	Fri May 30 04:05:36 2008
@@ -0,0 +1,64 @@
+#ifndef _GSTREAMERMM_STRUCTUREVALUE_H
+#define _GSTREAMERMM_STRUCTUREVALUE_H
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+
+/* gstreamermm - a C++ wrapper for gstreamer
+ *
+ * Copyright 2008 The gstreamermm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+
+#include <glib-object.h>
+#include <glibmm/value.h>
+
+namespace Gst
+{
+
+/** Base class of Gst::StructureValue templates.
+ */
+class StructureValueBase
+{
+public:
+  GType type()  const { return type_;  }
+
+protected:
+  explicit StructureValueBase(GType type);
+
+private:
+  GType type_;
+};
+
+
+/** Template class used to convert simple C++ types to usable Gst::Structure
+ * Glib::Value<> types. It is used for setting/getting fields in
+ * Gst::Structures.
+ */
+template <class T>
+class StructureValue : public StructureValueBase
+{
+public:
+  typedef T               ElementType;
+  typedef Glib::Value<T>  ValueType;
+
+  StructureValue() : StructureValueBase(ValueType::value_type()) {}
+};
+
+} // namespace Gst
+
+
+#endif /* _GSTREAMERMM_STRUCTUREVALUE_H */
+

Modified: gstreamermm/trunk/gstreamer/src/caps.ccg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/caps.ccg	(original)
+++ gstreamermm/trunk/gstreamer/src/caps.ccg	Fri May 30 04:05:36 2008
@@ -49,7 +49,7 @@
 {
   //We take a copy because gst_caps_append_structure() wants to take ownership:
   GstStructure* copy = gst_structure_copy(structure.gobj());
-  return Glib::wrap(gst_caps_new_full(copy));
+  return Glib::wrap(gst_caps_new_full(copy, NULL));
 }
 
 void Caps::append_structure(const Structure& structure)

Modified: gstreamermm/trunk/gstreamer/src/caps.hg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/caps.hg	(original)
+++ gstreamermm/trunk/gstreamer/src/caps.hg	Fri May 30 04:05:36 2008
@@ -21,6 +21,7 @@
 
 #include <gst/gstcaps.h>
 #include <gstreamermm/structure.h>
+#include <gstreamermm/structurevalue.h>
 
 _DEFS(gstreamermm,gst)
 
@@ -48,12 +49,11 @@
  *
  * @code
  * Glib::RefPtr<Gst::Caps> caps = Gst::Caps::create_simple("video/x-raw-yuv");
- * //TODO: Add method overloads so we don't need to specify the type, and so we don't need to use Glib::Value:
- * caps->set_simple("format", GST_TYPE_FOURCC, GST_MAKE_FOURCC ('I', '4', '2', '0'));
- * caps->set_simple("framerate", GST_TYPE_FRACTION, 25, 1,
- * caps->set_simple("pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
- * caps->set_simple("width", G_TYPE_INT, 320,
- * caps->set_simple("height", G_TYPE_INT, 240)
+ * caps->set_simple("format", Gst::Fourcc('I', '4', '2', '0'));
+ * caps->set_simple("framerate", Gst::Fraction(25, 1));
+ * caps->set_simple("pixel-aspect-ratio", Gst::Fraction(1, 1));
+ * caps->set_simple("width", 320);
+ * caps->set_simple("height", 240);
  * @endcode
  */
 class Caps 
@@ -115,15 +115,28 @@
   _WRAP_METHOD(void remove_structure(guint idx), gst_caps_remove_structure)
   _WRAP_METHOD(guint size() const, gst_caps_get_size)
 
-  //TODO: Avoid forcing applications to use Glib::Value<>. See what TreeModel does.
-
   /** Sets fields in a simple Gst::Caps. A simple Gst::Caps is one that only
-   * has one structure.
+   * has one structure. This method, like the Gst::Structure::set_field()
+   * methods, translates certain GTypes to GStreamer specific GTypes for
+   * functional compatibility.
    *
-   * @param field Field to set.
+   * @param name Field to set.
    * @param value The value which the field should be set to.
    */
   void set_simple(const Glib::ustring& name, const Glib::ValueBase& value);
+
+  /** Sets fields in a simple Gst::Caps. A simple Gst::Caps is one that only
+   * has one structure. This method, like the Gst::Structure::set_field()
+   * methods, translates certain GTypes to GStreamer specific GTypes for
+   * functional compatibility.
+   *
+   * @param name Field to set.
+   * @param data A value which the field should be set to (this can be any C++
+   * type).
+   */
+  template <class DataType>
+  void set_simple(const Glib::ustring& name, const DataType& data);
+
   _IGNORE(gst_caps_set_simple)
 
   //This does not seem useful: _WRAP_METHOD(void set_simple_valist(char* field, const va_list& varargs), gst_caps_set_simple_valist)
@@ -162,4 +175,22 @@
   _IGNORE(gst_caps_copy, gst_caps_set_simple, gst_caps_make_writable, gst_caps_append_structure, gst_caps_merge_structure, gst_caps_get_structure)
 };
 
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+
+/******************************* Gst::Caps *******************************/
+
+template <class DataType>
+void Caps::set_simple(const Glib::ustring& name, const DataType& data)
+{
+  typedef typename Gst::StructureValue<DataType> type_cppdata;
+  typedef typename type_cppdata::ValueType ValueType;
+
+  ValueType value;
+  value.init(ValueType::value_type());
+  value.set(data);
+  this->set_simple(name, (Glib::ValueBase)(value));
+}
+
+#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+
 } //namespace Gst

Modified: gstreamermm/trunk/gstreamer/src/elementfactory.hg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/elementfactory.hg	(original)
+++ gstreamermm/trunk/gstreamer/src/elementfactory.hg	Fri May 30 04:05:36 2008
@@ -77,8 +77,6 @@
   _CLASS_GOBJECT(ElementFactory, GstElementFactory, GST_ELEMENT_FACTORY, PluginFeature, GstPluginFeature)
 
 public:
-
-  //TODO: Rename as create_*()? How is this different to gst_element_factory_create()?
   _WRAP_METHOD(static Glib::RefPtr<ElementFactory> find(const Glib::ustring& name), gst_element_factory_find)
 
   //Note that name can't be NULL here, though it seems like gstreamer should allow that as for gst_element_factory_make().

Modified: gstreamermm/trunk/tests/test-caps.cc
==============================================================================
--- gstreamermm/trunk/tests/test-caps.cc	(original)
+++ gstreamermm/trunk/tests/test-caps.cc	Fri May 30 04:05:36 2008
@@ -43,6 +43,32 @@
   return e1->link_filtered(e2, caps);
 }
 
+void test_simple()
+{
+  int width;
+  Gst::Fraction rate;
+
+  Glib::RefPtr<Gst::Caps> caps = Gst::Caps::create_simple("video/x-raw-yuv");
+  caps->set_simple("width", 500);
+  caps->set_simple("framerate", Gst::Fraction(25, 1));
+
+  if (caps->get_structure(0).get_field("width", width))
+  {
+    std::cout << "Simple caps width after setting = " << width << "." <<
+      std::endl;
+  }
+  else
+    std::cout << "Getting of simple caps width field failed." << std::endl;
+
+  if (caps->get_structure(0).get_field("framerate", rate))
+  {
+    std::cout << "Simple caps rate after setting = " << rate.num << "/" <<
+      rate.denom << "." << std::endl;
+  }
+  else
+    std::cout << "Getting of simple caps framerate field failed." << std::endl;
+}
+
 int main (int argc, char* argv[])
 {
   Glib::RefPtr<Gst::Pipeline> pipeline;
@@ -50,6 +76,8 @@
 
   Gst::init(argc, argv);
 
+  test_simple();
+
   pipeline = Gst::Pipeline::create("pipeline");
 
   e1 = Gst::ElementFactory::create_element("fakesrc", "source");



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