[gstreamermm] fixed create_writable in caps



commit 3a08f1be77fc89d5b8fcc9b354bec1113f378380
Author: Tomasz Lakota <tomasz lakota flytronic pl>
Date:   Wed Mar 26 19:56:05 2014 +0100

    fixed create_writable in caps
    
    Conflicts:
        gstreamer/gstreamermm/caps.cc

 gstreamer/src/caps.ccg |   28 +++++++++++++++++++++++++++-
 1 files changed, 27 insertions(+), 1 deletions(-)
---
diff --git a/gstreamer/src/caps.ccg b/gstreamer/src/caps.ccg
index 778c876..d3a7e5d 100644
--- a/gstreamer/src/caps.ccg
+++ b/gstreamer/src/caps.ccg
@@ -54,7 +54,33 @@ Glib::RefPtr<Gst::Caps> Caps::create_simple(const Glib::ustring& media_type)
 
 Glib::RefPtr<Gst::Caps> Caps::create_writable()
 {
-    return Glib::RefPtr<Gst::Caps>(Glib::wrap(gst_caps_make_writable(gobj())));
+  /*
+   * This function is generally used in the following pattern:
+   * RefPtr<Caps> p = (...);
+   * p = p->create_writable();
+   *
+   * There are two cases:
+   * 1. object is not writable, therefore:
+   *   - somebody else may have another reference to the object (but it this might change in the meantime)
+   *   - gst_caps_make_writable may return a new copy of object
+   *   - we have to make additional ref, that will be unreffed in gst_caps_make_writable
+   * 2. object is_writable, then:
+   *   - our caller has the only one reference to object (therefore nobody can increase refcount in the 
meantime)
+   *   - gst_caps_make_writable will return the same object and will not do any reffing/unreffing
+   *   - we cannot make any additional refs before calling gst_caps_make_writable, since it would enforce 
unnecessary
+   *     copying of the object
+   *   - we are supposed to create a new RefPtr with is own reference to the object, therefore we need to 
"take copy"
+   *   - however when caller release the pointer (implicitly, during assignment) the refcount will be 1 again
+   */
+  if(gst_caps_is_writable(gobj()))
+  {
+    return Glib::wrap(gst_caps_make_writable(gobj()), true); // take copy so original object is left to the 
current owner (and hopefully will be released soon)
+  }
+  else
+  {
+    reference(); // gst_caps_make_writable(buf) will unref the old caps, but our caller is still holding 
RefPtr to it
+    return Glib::wrap(gst_caps_make_writable(gobj()));
+  }
 }
 
 Glib::RefPtr<Gst::Caps> Caps::create(const Structure& structure)


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