[gstreamermm] Caps: Add new methods.



commit ae8683aebdda8040c16d0d3ce4433ee92303e8e7
Author: José Alburquerque <jaalburqu svn gnome org>
Date:   Tue May 17 23:56:02 2011 -0400

    Caps: Add new methods.
    
    	* gstreamer/src/caps.{ccg,hg}: Add the steal_structure() method and
    	get_intersect() method accepting a Gst::CapsIntersectMode enum.  Wrap
    	the get_structure() method instead of handwriting it.
    	* tests/test-caps-structures.cc: Adapt the test to use the new
    	steal_structure() method.
    	* tools/m4/convert_gst.m4: Added a GstCapsIntersect enum conversion.

 ChangeLog                     |   11 +++++++++++
 gstreamer/src/caps.ccg        |    9 ---------
 gstreamer/src/caps.hg         |   14 ++++++++++++--
 tests/test-caps-structures.cc |   23 +++++++++++++++++++----
 tools/m4/convert_gst.m4       |    1 +
 5 files changed, 43 insertions(+), 15 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 37c3ce4..9a25054 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-05-17  José Alburquerque  <jaalburqu svn gnome org>
+
+	Caps: Add new methods.
+
+	* gstreamer/src/caps.{ccg,hg}: Add the steal_structure() method and
+	get_intersect() method accepting a Gst::CapsIntersectMode enum.  Wrap
+	the get_structure() method instead of handwriting it.
+	* tests/test-caps-structures.cc: Adapt the test to use the new
+	steal_structure() method.
+	* tools/m4/convert_gst.m4: Added a GstCapsIntersect enum conversion.
+
 2011-05-12  José Alburquerque  <jaalburqu svn gnome org>
 
 	BaseAudioSink, BaseSink, XOverlay: Add new methods.
diff --git a/gstreamer/src/caps.ccg b/gstreamer/src/caps.ccg
index e9a5e9e..c9c25c7 100644
--- a/gstreamer/src/caps.ccg
+++ b/gstreamer/src/caps.ccg
@@ -68,15 +68,6 @@ void Caps::merge_structure(Structure& structure)
   gst_caps_merge_structure(gobj(), copy);
 }
 
-const Structure Caps::get_structure(guint idx) const
-{
-  GstStructure* structure = gst_caps_get_structure(gobj(), idx);
-  if(structure)
-    return Structure(structure, true /* take_copy */);
-  else
-    return Structure(); //Use operator bool() to detect this.
-}
-
 //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
diff --git a/gstreamer/src/caps.hg b/gstreamer/src/caps.hg
index 4d45af8..7d68af0 100644
--- a/gstreamer/src/caps.hg
+++ b/gstreamer/src/caps.hg
@@ -26,6 +26,8 @@ _DEFS(gstreamermm,gst)
 namespace Gst
 {
 
+_WRAP_ENUM(CapsIntersectMode, GstCapsIntersectMode, NO_GTYPE)
+
 struct Structure;
 
 /** A class that describes sets of media formats.
@@ -109,17 +111,22 @@ public:
   void merge_structure(Structure& structure);
   _IGNORE(gst_caps_merge_structure)
 
+#m4 _CONVERSION(`GstStructure*', `const Structure', `Glib::wrap($3, true)')
   /** Finds the structure in caps that has the index @a idx, and returns it.
    *
    * @param index The index of the structure.
    * @return The Gst::Structure corresponding to index.
    */
-  const Structure get_structure(guint idx) const;
-  _IGNORE(gst_caps_get_structure)
+  _WRAP_METHOD(const Structure get_structure(guint idx) const, gst_caps_get_structure)
 
   _WRAP_METHOD(void remove_structure(guint idx), gst_caps_remove_structure)
   _WRAP_METHOD(guint size() const, gst_caps_get_size)
 
+// There's no need to take an extra reference because we are stealing the
+// structure.
+#m4 _CONVERSION(`GstStructure*', `Structure', `Glib::wrap($3)')
+  _WRAP_METHOD(Structure steal_structure(guint index), gst_caps_steal_structure)
+
   /** 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
@@ -177,6 +184,9 @@ public:
   _WRAP_METHOD(Glib::RefPtr<Gst::Caps> get_intersect(const Glib::RefPtr<const Gst::Caps>& other_caps) const, gst_caps_intersect)
 
   //This is const (returns a non const) because it always creates a new instance:
+  _WRAP_METHOD(Glib::RefPtr<Gst::Caps> get_intersect(const Glib::RefPtr<const Gst::Caps>& other_caps, CapsIntersectMode) const, gst_caps_intersect_full)
+
+  //This is const (returns a non const) because it always creates a new instance:
   _WRAP_METHOD(Glib::RefPtr<Gst::Caps> get_union(const Glib::RefPtr<const Gst::Caps>& other_caps) const, gst_caps_union)
 
   //This is const (returns a non const) because it always creates a new instance:
diff --git a/tests/test-caps-structures.cc b/tests/test-caps-structures.cc
index e1fba83..4a864c7 100644
--- a/tests/test-caps-structures.cc
+++ b/tests/test-caps-structures.cc
@@ -47,7 +47,7 @@ int main(int argc, char** argv)
   Glib::RefPtr<Gst::Caps> caps = Gst::Caps::create();
   add_structures(caps);
 
-  for(int i = 0; i < 2; i++) {
+  for(int i = 0; i < 3; i++) {
     Glib::ustring str;
     const Gst::Structure s = caps->get_structure(i);
     if(s)
@@ -57,11 +57,26 @@ int main(int argc, char** argv)
     }
   }
 
-  caps->remove_structure(1);
+  std::cout << "Removing cap's structure at index 0" << std::endl;
 
-  const Gst::Structure structure = caps->get_structure(1);
+  caps->remove_structure(0);
+
+  Gst::Structure structure = caps->get_structure(0);
+  if(structure)
+    std::cout << "Cap's structure at index 0 = " << structure.get_name() <<
+      std::endl;
+
+  std::cout << "Stealing cap's structure at index 0" << std::endl;
+
+  Gst::Structure stolen_struct = caps->steal_structure(0);
+  if(stolen_struct)
+    std::cout << "Cap's stolen structure at indext 0 = " <<
+      stolen_struct.get_name() << std::endl;
+
+  structure = caps->get_structure(0);
   if(structure)
-    std::cout << "Caps structure index 1 = " << structure.get_name() << std::endl;
+    std::cout << "Cap's structure at index 0 = " << structure.get_name() <<
+      std::endl;
 
   return 0;
 }
diff --git a/tools/m4/convert_gst.m4 b/tools/m4/convert_gst.m4
index f867db7..d00548b 100644
--- a/tools/m4/convert_gst.m4
+++ b/tools/m4/convert_gst.m4
@@ -9,6 +9,7 @@ _CONV_ENUM(Gst,BufferCopyFlags)
 _CONV_ENUM(Gst,BufferFlag)
 _CONV_ENUM(Gst,BufferFormat)
 _CONV_ENUM(Gst,BufferFormatType)
+_CONV_ENUM(Gst,CapsIntersectMode)
 _CONV_ENUM(Gst,ClockEntryType)
 _CONV_ENUM(Gst,ClockReturn)
 _CONV_ENUM(Gst,ClockTime)



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