[gstreamermm] BufferList: Wrap the iterate() method.



commit 36b9a033cc3fa4331f159be73cda03c7321f200b
Author: José Alburquerque <jaalburqu svn gnome org>
Date:   Fri Oct 15 13:15:35 2010 -0400

    	BufferList: Wrap the iterate() method.
    
    	* gstreamer/src/bufferlist.ccg:
    	* gstreamer/src/bufferlist.hg: Wrap the BufferList::iterate() method.
    	Also correct the logic of the foreach callback.
    	* gstreamer/gstreamermm.h: Include the buffer list header file in the
    	main includes.

 ChangeLog                    |   10 ++++++++++
 gstreamer/gstreamermm.h      |    1 +
 gstreamer/src/bufferlist.ccg |   34 +++++++++++++++++++++++++++++++++-
 gstreamer/src/bufferlist.hg  |   13 ++++++++++++-
 4 files changed, 56 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c6e8c27..a91e458 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2010-10-15  José Alburquerque  <jaalburqu svn gnome org>
+
+	BufferList: Wrap the iterate() method.
+
+	* gstreamer/src/bufferlist.ccg:
+	* gstreamer/src/bufferlist.hg: Wrap the BufferList::iterate() method.
+	Also correct the logic of the foreach callback.
+	* gstreamer/gstreamermm.h: Include the buffer list header file in the
+	main includes.
+
 2010-10-14  José Alburquerque  <jaalburqu svn gnome org>
 
 	Regenerate the docs.
diff --git a/gstreamer/gstreamermm.h b/gstreamer/gstreamermm.h
index e7e1691..a5edcdd 100644
--- a/gstreamer/gstreamermm.h
+++ b/gstreamer/gstreamermm.h
@@ -64,6 +64,7 @@
 // Core includes
 #include <gstreamermm/bin.h>
 #include <gstreamermm/buffer.h>
+#include <gstreamermm/bufferlist.h>
 #include <gstreamermm/bus.h>
 #include <gstreamermm/caps.h>
 #include <gstreamermm/childproxy.h>
diff --git a/gstreamer/src/bufferlist.ccg b/gstreamer/src/bufferlist.ccg
index 75adc18..64f0f07 100644
--- a/gstreamer/src/bufferlist.ccg
+++ b/gstreamer/src/bufferlist.ccg
@@ -30,12 +30,29 @@ static GstBufferListItem BufferList_Foreach_gstreamermm_callback(GstBuffer** buf
 
   try
   {
+    // First wrap the original buffer.
     Glib::RefPtr<Gst::Buffer> temp = Gst::wrap(*buffer, true);
 
+    // Call the slot which can modify the buffer (ie. set it to a new one or
+    // clear it altogether).
     GstBufferListItem const result =
       static_cast<GstBufferListItem>((*the_slot)(temp, group, idx));
 
-    *buffer = temp->gobj_copy();
+    // Set the reference to the buffer according to how the temp buffer has
+    // been altered.
+    if(!temp)
+    {
+      // Clear the reference to the original buffer also.
+      *buffer = 0;
+    }
+    else if(*buffer != temp->gobj())
+    {
+      // The temp buffer has been set to a new one so make the reference point
+      // to it and take an extra reference for when the temp wrapper is
+      // destroyed (I think that's right).
+      *buffer = temp->gobj();
+      temp->reference();
+    }
 
     return result;
   }
@@ -96,6 +113,11 @@ void BufferList::foreach(const SlotForeach& slot)
     const_cast<SlotForeach*>(&slot));
 }
 
+void BufferList::iterate(BufferListIterator& result)
+{
+  result.set_gobject(gst_buffer_list_iterate(gobj()));
+}
+
 BufferListIterator::BufferListIterator()
 : gobject_(0),
   take_ownership(false)
@@ -109,6 +131,16 @@ BufferListIterator::BufferListIterator(GstBufferListIterator* castitem,
 {
 }
 
+void BufferListIterator::set_gobject(GstBufferListIterator* castitem,
+  bool take_ownership)
+{
+  if(gobject_ && take_ownership)
+    gst_buffer_list_iterator_free(gobject_);
+
+  gobject_ = castitem;
+  this->take_ownership = take_ownership;
+}
+
 BufferListIterator::~BufferListIterator()
 {
   if(take_ownership && gobject_)
diff --git a/gstreamer/src/bufferlist.hg b/gstreamer/src/bufferlist.hg
index f4e722d..fb5e5d0 100644
--- a/gstreamer/src/bufferlist.hg
+++ b/gstreamer/src/bufferlist.hg
@@ -29,6 +29,7 @@ namespace Gst
 _WRAP_ENUM(BufferListItem, GstBufferListItem, NO_GTYPE)
 
 class Buffer;
+class BufferListIterator;
 
 /** A grouped scatter data buffer type for data-passing.
  * Buffer lists are units of grouped scatter/gather data transfer in GStreamer.
@@ -110,7 +111,11 @@ public:
   _WRAP_METHOD(Glib::RefPtr<Gst::Buffer> get(guint group, guint idx), gst_buffer_list_get)
   _WRAP_METHOD(Glib::RefPtr<const Gst::Buffer> get(guint group, guint idx) const, gst_buffer_list_get, constversion)
 
-  //TODO: _WRAP_METHOD(BufferListIterator& iterate(), gst_buffer_list_iterate)
+  /** Iterate the buffers in the buffer list.
+   * @param result A place in which to store the iterator.
+   * Sine 0.10.24.
+   */
+  void iterate(BufferListIterator& result);
 };
 
 /** An opaque iterator for a Gst::BufferList.
@@ -147,6 +152,8 @@ private:
   BufferListIterator(const BufferListIterator& other);
   BufferListIterator& operator=(const BufferListIterator& other);
 
+  friend class BufferList;
+
 public:
   /** For example,
    * Glib::RefPtr<Gst::Buffer> on_process(const Glib::RefPtr<Gst::Buffer>&
@@ -194,6 +201,10 @@ public:
 protected:
   GstBufferListIterator* gobject_;      // The C object.
   bool take_ownership;                  // Bool signaling ownership.
+
+protected:
+  // So that Gst::BufferList::iterate() can set the C object.
+  void set_gobject(GstBufferListIterator* castitem, bool take_ownership = true);
 };
 
 } // namespace Gst



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