gnomemm r1694 - in gstreamermm/trunk: . gstreamer/src tests tools/m4



Author: jaalburqu
Date: Fri Aug 29 19:59:45 2008
New Revision: 1694
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1694&view=rev

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

	* gstreamer/src/format.ccg:
	* gstreamer/src/format.hg: Added register_format(), formats_contain()
	and iterate_format_definitions().  Renamed get_details(Format f, ...)
	to get_format_details().  Made FormatDefinition a _CLASS_GENERIC to
	make it usable with Gst::IteratorBasic<> for return of
	iterate_format_definitions().

	* gstreamer/src/query.ccg:
	* gstreamer/src/query.hg: Added Gst;:Query class doc.  Renamed
	query_types_constains() to query_types_contain().  Added
	Gst::Query::iterate_definitions().  Made QueryTypeDefinition a
	_CLASS_GENERIC so that it can be used with Gst::IteratorBasic<> for
	return of Gst::Query::iterate_definitions().
	* tools/m4/convert_gst.m4: Added conversion from GstIterator* to
	Gst::IteratorBasic<const QueryTypeDefinition>.

	* gstreamer/src/iterator.hg: Added Gst::IteratorBasic<>::operator->().
	Used CppType() constructor in the Gst::IteratorBasic<>::operator*()
	return instead of Glib::wrap() which makes it usable with classes that
	don't have a Glib::wrap() method (like FormatDefinition and
	QueryTypeDefinition).

	* tests/test-iterator.cc: Modified to test
	iterate_format_definitions() and Gst::Query::iterate_definitions().

	* gstreamer/src/caps.ccg: Clarified TODO.

Modified:
   gstreamermm/trunk/ChangeLog
   gstreamermm/trunk/gstreamer/src/caps.ccg
   gstreamermm/trunk/gstreamer/src/format.ccg
   gstreamermm/trunk/gstreamer/src/format.hg
   gstreamermm/trunk/gstreamer/src/iterator.hg
   gstreamermm/trunk/gstreamer/src/query.ccg
   gstreamermm/trunk/gstreamer/src/query.hg
   gstreamermm/trunk/tests/test-iterator.cc
   gstreamermm/trunk/tools/m4/convert_gst.m4

Modified: gstreamermm/trunk/gstreamer/src/caps.ccg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/caps.ccg	(original)
+++ gstreamermm/trunk/gstreamer/src/caps.ccg	Fri Aug 29 19:59:45 2008
@@ -77,7 +77,7 @@
 //TODO: Want to return RefPtr to Caps but using RefPtr in expressions such
 // as 'caps->set_simple(name1, value1)->set_simple(name2, value2)' a
 // causes gstreamer Structure immutability warnings because the Caps is
-// referenced more than once in the expression
+// referenced more than once in the expression (see bug #510301).
 /*
   This method is implemented in place of gst_caps_set_simple which is a
   variable argument function and cannot be wrapped.  We don't call

Modified: gstreamermm/trunk/gstreamer/src/format.ccg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/format.ccg	(original)
+++ gstreamermm/trunk/gstreamer/src/format.ccg	Fri Aug 29 19:59:45 2008
@@ -20,10 +20,28 @@
  */
 
 #include <gst/gstenumtypes.h>
+#include <gstreamermm/iterator.h>
 
 namespace Gst
 {
 
+FormatDefinition::FormatDefinition()
+: value(Gst::FORMAT_UNDEFINED),
+  quark((GQuark)(0))
+{}
+
+FormatDefinition::FormatDefinition(GstFormatDefinition* castitem)
+: value(Gst::FORMAT_UNDEFINED),
+  quark((castitem) ? castitem->quark : 0)
+{
+  if (castitem)
+  {
+    value = (Format)(castitem->value);
+    nick = castitem->nick;
+    description = castitem->description;
+  }
+}
+
 namespace Enums
 {
 
@@ -41,10 +59,21 @@
 
 Format get_format(const Glib::ustring& nick)
 {
-  return Format(gst_format_get_by_nick(nick.c_str()));
+  return (Format)(gst_format_get_by_nick(nick.c_str()));
+}
+
+Format register_format(const Glib::ustring& nick, const Glib::ustring&
+description)
+{
+  return (Format)(gst_format_register(nick.c_str(), description.c_str()));
 }
 
-bool get_details(Format format, FormatDefinition &def)
+bool formats_contain(const Glib::ArrayHandle<Format>& formats, Format format)
+{
+  return gst_formats_contains((GstFormat*)((formats).data()), (GstFormat)(format));
+}
+
+bool get_format_details(Format format, FormatDefinition &def)
 {
   const GstFormatDefinition* gstdef = gst_format_get_details(GstFormat(format));
 
@@ -58,5 +87,10 @@
   return true;
 }
 
+IteratorBasic<const FormatDefinition> iterate_format_definitions()
+{
+  return IteratorBasic<const FormatDefinition>::IteratorBasic(gst_format_iterate_definitions());
+}
+
 } //namespace Gst
 

Modified: gstreamermm/trunk/gstreamer/src/format.hg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/format.hg	(original)
+++ gstreamermm/trunk/gstreamer/src/format.hg	Fri Aug 29 19:59:45 2008
@@ -26,13 +26,29 @@
 namespace Gst
 {
 
+//Gst::IteratorBasic<> forward declaration.
+template <class CppType>
+class IteratorBasic;
+
 _WRAP_ENUM(Format, GstFormat)
 
 /** A format definition is used to get details of a Gst::Format by
  * Gst::get_details().
  */
-struct FormatDefinition
+class FormatDefinition
 {
+  _CLASS_GENERIC(FormatDefinition, GstFormatDefinition)
+
+public:
+  /// Default constructor.
+  FormatDefinition();
+
+  /** Constructs a Gst::FormatDefinition from a C GstFormatDefinition type.
+   * The @a castitem is left unaffected; its contents are simply copied.
+   * @param castitem The GstFormatDefinition to copy contents from.
+   */
+  FormatDefinition(GstFormatDefinition* castitem);
+
   /// The unique id of this format.
   Gst::Format         value;
 
@@ -65,6 +81,17 @@
 
 } //namespace Enums
 
+/** Create a new Gst::Format based on the nick or return an already registered
+ * format with that nick.
+ *
+ * @param nick The nick of the new format.
+ * @param description The description of the new format.
+ * @return A new Gst::Format or an already registered format with the same
+ * nick. MT safe.
+ */
+Format register_format(const Glib::ustring& nick, const Glib::ustring&
+description);
+
 /** Return the format registered with the given nick.
  *
  * @param nick The nick of the format.
@@ -73,12 +100,26 @@
  */
 Format get_format(const Glib::ustring& nick);
 
+/** See if the given format is inside the array of formats.
+ *
+ * @param formats The array of formats to search.
+ * @param format The format to find.
+ * @return true If the format is found inside the array.
+ */
+bool formats_contain(const Glib::ArrayHandle<Format>& formats, Format format);
+
 /** Get details about the given format.
  *
  * @param format The format to get details of.
- * @param def The Gst::FormatDefinition in which to store details of format.
+ * @param def The Gst::FormatDefinition in which to store the details of
+ * the format.
  * @return true if successful, false otherwise. MT safe.
  */
-bool get_details(Format format, FormatDefinition& def);
+bool get_format_details(Format format, FormatDefinition& def);
+
+/** Iterate all the registered formats.  The format definitions are read only.
+ * @return a Gst::IteratorBasic of Gst::FormatDefinition.
+ */
+IteratorBasic<const FormatDefinition> iterate_format_definitions();
 
 } //namespace Gst

Modified: gstreamermm/trunk/gstreamer/src/iterator.hg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/iterator.hg	(original)
+++ gstreamermm/trunk/gstreamer/src/iterator.hg	Fri Aug 29 19:59:45 2008
@@ -135,10 +135,8 @@
 /**  Gst::IteratorBasic â Class that retrieves multiple elements in a thread
  * safe way.
  * Gst::IteratorBasic iterates specifically through elements that are not
- * reference counted.  Though it is mostly not used, it is included for
- * completeness.  Gst::Iterator, which iterates through reference counted
- * objects is mostly used for iterating through objects because the ones that
- * are iterated in GStreamer are mostly reference counted.
+ * reference counted.  Gst::Iterator is used for iterating through reference
+ * counted objects.
  */
 template <class CppType>
 class IteratorBasic : public IteratorBase<CppType>
@@ -169,6 +167,10 @@
    */
   CppType operator*() const;
 
+  /** Accesses underlying object member through the iterator.
+   */
+  CppType* operator->() const;
+
   /** Prefix auto-increment operator.  It advances to the next item in the
    * iterator.  It is faster than the postfix operator.
    * @throw std::runtime_error (if a Gst::ITERATOR_ERROR is encountered or if a
@@ -217,7 +219,6 @@
    */
   Glib::RefPtr<CppType> operator*() const;
 
-  //TODO: Should this operator be included?
   /** Accesses underlying object member through the RefPtr<>.
    */
   CppType* operator->() const;
@@ -366,11 +367,25 @@
   typedef typename CppType::BaseObjectType CType;
 
   if (this->current)
-    return Glib::wrap((CType*)(this->current));
+    return CppType((CType*)(this->current));
   else
     return CppType();
 }
 
+template <class CppType>
+CppType* IteratorBasic<CppType>::operator->() const
+{
+  static typename CppType::CppObjectType result;
+
+  if (this->current)
+  {
+    result = this->operator*();
+    return &result;
+  }
+  else
+    return (CppType*) 0;
+}
+
 template<class CppType>
 IteratorBasic<CppType>& IteratorBasic<CppType>::operator++()
 {

Modified: gstreamermm/trunk/gstreamer/src/query.ccg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/query.ccg	(original)
+++ gstreamermm/trunk/gstreamer/src/query.ccg	Fri Aug 29 19:59:45 2008
@@ -20,11 +20,30 @@
  */
 
 #include <gst/gstenumtypes.h>
+#include <gstreamermm/iterator.h>
+
 _PINCLUDE(gstreamermm/private/miniobject_p.h)
 
 namespace Gst
 {
 
+QueryTypeDefinition::QueryTypeDefinition()
+: value(Gst::QUERY_NONE),
+  quark((GQuark)(0))
+{}
+
+QueryTypeDefinition::QueryTypeDefinition(GstQueryTypeDefinition* castitem)
+: value(Gst::QUERY_NONE),
+  quark((castitem) ? castitem->quark : 0)
+{
+  if (castitem)
+  {
+    value = (QueryType)(castitem->value);
+    nick = castitem->nick;
+    description = castitem->description;
+  }
+}
+
 namespace Enums
 {
 

Modified: gstreamermm/trunk/gstreamer/src/query.hg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/query.hg	(original)
+++ gstreamermm/trunk/gstreamer/src/query.hg	Fri Aug 29 19:59:45 2008
@@ -30,9 +30,43 @@
 namespace Gst
 {
 
+//Gst::IteratorBasic<> forward declaration.
+template <class CppType>
+class IteratorBasic;
+
 _WRAP_ENUM(QueryType, GstQueryType)
 _WRAP_ENUM(BufferingMode, GstBufferingMode)
 
+/** A query type definition is used to get details of a Gst::Query by
+ * Gst::Query::get_details().
+ */
+class QueryTypeDefinition
+{
+  _CLASS_GENERIC(QueryTypeDefinition, GstQueryTypeDefinition)
+
+public:
+  /// Default constructor.
+  QueryTypeDefinition();
+
+  /** Constructs a Gst::QueryTypeDefinition from a C GstQueryTypeDefinition
+   * type.  The @a castitem is left unaffected; its contents are simply copied.
+   * @param castitem The GstQueryTypeDefinition to copy contents from.
+   */
+  QueryTypeDefinition(GstQueryTypeDefinition* castitem);
+
+  /// The unique id of the Query type.
+  QueryType             value;
+
+  /// A short nickname for the query type.
+  Glib::ustring         nick;
+
+  /// A longer description of the query type.
+  Glib::ustring         description;
+
+  /// The quark for the nick.
+  Glib::QueryQuark      quark;
+};
+
 namespace Enums
 {
 
@@ -54,14 +88,26 @@
 
 } //namespace Enums
 
-struct QueryTypeDefinition
-{
-  QueryType             value;
-  Glib::ustring         nick;
-  Glib::ustring         description;
-  Glib::QueryQuark      quark;
-};
+/** Gst::Query â Provide functions to create queries, and to set and parse
+ * values in them.  Dynamically register new query types. 
+ * Gst::Query methods are used to register new query types to the GStreamer
+ * core. Query types can be used to perform queries on pads and elements.
+ *
+ * Queries can be created using the derived Gst::Query classes create()
+ * methods. Query values can be set using derived classes set() methods, and
+ * parsed using derived classes parse() methods.
+ *
+ * The following example shows how to query the duration of a pipeline:
+ *
+ * TODO: Correct following to include duration query example:
 
+Glib::RefPtr<Gst::Query> query = Gst::QueryDuration::create(Gst::FORMAT_TIME);
+bool res = pipeline->query(query);
+if (res)
+{
+  gint64 duration;
+}
+ */
 class Query : public MiniObject
 {
 protected:
@@ -90,7 +136,7 @@
   _WRAP_METHOD(static QueryType get_query_type(const Glib::ustring& nick), gst_query_type_get_by_nick)
 
 #m4 _CONVERSION(`const Glib::ArrayHandle<QueryType>&',`GstQueryType*',`(GstQueryType*)(($3).data())')
-  _WRAP_METHOD(static bool query_types_contains(const Glib::ArrayHandle<QueryType>& types, QueryType type), gst_query_types_contains)
+  _WRAP_METHOD(static bool query_types_contain(const Glib::ArrayHandle<QueryType>& types, QueryType type), gst_query_types_contains)
 
   /** Get details about the given Gst::QueryType.
    *
@@ -100,6 +146,8 @@
    */
   bool get_details(QueryType type, QueryTypeDefinition& def);
   _IGNORE(gst_query_type_get_details)
+
+  _WRAP_METHOD(static IteratorBasic<const QueryTypeDefinition> iterate_definitions(), gst_query_type_iterate_definitions)
 };
 
 //TODO: Modify create methods of derived Query classes to return

Modified: gstreamermm/trunk/tests/test-iterator.cc
==============================================================================
--- gstreamermm/trunk/tests/test-iterator.cc	(original)
+++ gstreamermm/trunk/tests/test-iterator.cc	Fri Aug 29 19:59:45 2008
@@ -76,5 +76,43 @@
   std::cout << "The loop iterated " << iterations <<
     " time(s) to print bin '" << bin->get_name() << "' elements." << std::endl;
 
+  std::cout << std::endl <<
+    "The following are standard GStreamer query types:" << std::endl;
+
+  Gst::IteratorBasic<const Gst::QueryTypeDefinition> queryTypes =
+    Gst::Query::iterate_definitions();
+  try
+  {
+    for(++queryTypes; !queryTypes.is_end(); ++queryTypes)
+    {
+      std::cout << queryTypes->nick << " -- " << queryTypes->description <<
+        "." << std::endl;
+    }
+  }
+  catch (std::runtime_error& e)
+  {
+    std::cout << "Runtime error while iterating through query types." <<
+      std::endl << e.what() << std::endl;
+  }
+
+  std::cout << std::endl <<
+    "The following are standard GStreamer formats:" << std::endl;
+
+  Gst::IteratorBasic<const Gst::FormatDefinition> formats =
+    Gst::iterate_format_definitions();
+  try
+  {
+    for(++formats; !formats.is_end(); ++formats)
+    {
+      std::cout << formats->nick << " -- " << formats->description <<
+        "." << std::endl;
+    }
+  }
+  catch (std::runtime_error& e)
+  {
+    std::cout << "Runtime error while iterating through formats." <<
+      std::endl << e.what() << std::endl;
+  }
+
   return 0;
 }

Modified: gstreamermm/trunk/tools/m4/convert_gst.m4
==============================================================================
--- gstreamermm/trunk/tools/m4/convert_gst.m4	(original)
+++ gstreamermm/trunk/tools/m4/convert_gst.m4	Fri Aug 29 19:59:45 2008
@@ -99,6 +99,7 @@
 #Iterator
 _CONVERSION(`GstIterator*',`Iterator<Element>',`Iterator<Element>::Iterator($3)')
 _CONVERSION(`GstIterator*',`Iterator<Pad>',`Iterator<Pad>::Iterator($3)')
+_CONVERSION(`GstIterator*',`IteratorBasic<const QueryTypeDefinition>',`IteratorBasic<const QueryTypeDefinition>::IteratorBasic($3)')
 
 #Message
 _CONVERSION(`GstMessage*',`Glib::RefPtr<Message>',`Gst::Message::wrap($3)')



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