[gstreamermm] Gst::BaseTransform: pass writable buffer to transform_ip function



commit 3f5fe44d45f4c2cefd0731bbd874a9bc9ae2dc5c
Author: Marcin Kolny <marcin kolny gmail com>
Date:   Sat Apr 14 16:31:39 2018 +0100

    Gst::BaseTransform: pass writable buffer to transform_ip function
    
    transform_ip_vfunc should get writable buffer as an argument. However,
    gstreamermm increases refcount (Glib::wrap(outbuf, true)), so the
    buffer was not writable anymore. This commit fixes this issue.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=794250

 gstreamer/src/basetransform.ccg |   58 +++++++++++++++++++++++++++++++++++++++
 gstreamer/src/basetransform.hg  |    4 ++-
 2 files changed, 61 insertions(+), 1 deletions(-)
---
diff --git a/gstreamer/src/basetransform.ccg b/gstreamer/src/basetransform.ccg
index 9ae7b68..04b01e6 100644
--- a/gstreamer/src/basetransform.ccg
+++ b/gstreamer/src/basetransform.ccg
@@ -147,6 +147,48 @@ GstFlowReturn BaseTransform_Class::transform_vfunc_callback(GstBaseTransform* se
   return RType();
 }
 
+GstFlowReturn BaseTransform_Class::transform_ip_vfunc_callback(GstBaseTransform* self, GstBuffer* buf)
+{
+  const auto obj_base = static_cast<Glib::ObjectBase*>(
+      Glib::ObjectBase::_get_current_wrapper((GObject*)self));
+
+  // Non-gtkmmproc-generated custom classes implicitly call the default
+  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
+  // generated classes can use this optimisation, which avoids the unnecessary
+  // parameter conversions if there is no possibility of the virtual function
+  // being overridden:
+  if(obj_base && obj_base->is_derived_())
+  {
+    const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
+    if(obj) // This can be NULL during destruction.
+    {
+      try // Trap C++ exceptions which would normally be lost because this is a C callback.
+      {
+        // Call the virtual member method, which derived classes might override.
+        Glib::RefPtr<Gst::Buffer> cpp_buf = Glib::wrap(buf, false);
+        GstFlowReturn ret = (GstFlowReturn)obj->transform_ip_vfunc(cpp_buf);
+        IGNORE_RESULT(cpp_buf.release());
+        return ret;
+      }
+      catch(...)
+      {
+        Glib::exception_handlers_invoke();
+      }
+    }
+  }
+
+  BaseClassType *const base = static_cast<BaseClassType*>(
+      g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The 
original underlying C class).
+  );
+
+  // Call the original underlying C function:
+  if(base && base->transform_ip)
+    return (*base->transform_ip)(self, buf);
+
+  using RType = GstFlowReturn;
+  return RType();
+}
+
 FlowReturn Gst::BaseTransform::transform_vfunc(const Glib::RefPtr<Gst::Buffer>& inbuf, const 
Glib::RefPtr<Gst::Buffer>& outbuf) 
 {
   BaseClassType *const base = static_cast<BaseClassType*>(
@@ -163,6 +205,22 @@ FlowReturn Gst::BaseTransform::transform_vfunc(const Glib::RefPtr<Gst::Buffer>&
   return RType();
 }
 
+FlowReturn Gst::BaseTransform::transform_ip_vfunc(const Glib::RefPtr<Gst::Buffer>& buf) 
+{
+  const auto base = static_cast<BaseClassType*>(
+      g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class 
(The original underlying C class).
+  );
+
+  if(base && base->transform_ip)
+  {
+    FlowReturn retval(((FlowReturn)((*base->transform_ip)(gobj(),Glib::unwrap(buf)))));
+    return retval;
+  }
+
+  using RType = FlowReturn;
+  return RType();
+}
+
 GstFlowReturn BaseTransform_Class::generate_output_vfunc_callback(GstBaseTransform* self, GstBuffer** outbuf)
 {
   Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
diff --git a/gstreamer/src/basetransform.hg b/gstreamer/src/basetransform.hg
index 46a9b52..6830bd1 100644
--- a/gstreamer/src/basetransform.hg
+++ b/gstreamer/src/basetransform.hg
@@ -217,7 +217,7 @@ public:
   /** Required if the element operates in-place. Transform the incoming buffer
    * in-place.
    */
-  _WRAP_VFUNC(FlowReturn transform_ip(const Glib::RefPtr<Gst::Buffer>& buf), "transform_ip")
+  virtual FlowReturn transform_ip_vfunc(const Glib::RefPtr<Gst::Buffer>& buf);
 
   /** Optional. Subclasses can override this to do their own allocation of
    * output buffers. Elements that only do analysis can return a subbuffer or
@@ -321,6 +321,7 @@ protected:
   _PUSH(SECTION_PCC_CLASS_INIT_VFUNCS)
   klass->prepare_output_buffer = &prepare_output_buffer_vfunc_callback;
   klass->transform = &transform_vfunc_callback;
+  klass->transform_ip = &transform_ip_vfunc_callback;
   klass->copy_metadata = &copy_metadata_vfunc_callback;
   klass->generate_output = &generate_output_vfunc_callback;
   klass->query = &query_vfunc_callback;
@@ -329,6 +330,7 @@ protected:
   _SECTION(SECTION_PH_VFUNCS)
   static GstFlowReturn prepare_output_buffer_vfunc_callback(GstBaseTransform* self, GstBuffer* input, 
GstBuffer** buf);
   static GstFlowReturn transform_vfunc_callback(GstBaseTransform* self, GstBuffer* inbuf, GstBuffer* outbuf);
+  static GstFlowReturn transform_ip_vfunc_callback(GstBaseTransform* self, GstBuffer* buf);
   static gboolean copy_metadata_vfunc_callback(GstBaseTransform* self, GstBuffer* input, GstBuffer* outbuf);
   static GstFlowReturn generate_output_vfunc_callback(GstBaseTransform* self, GstBuffer** outbuf);
   static gboolean query_vfunc_callback(GstBaseTransform* self, GstPadDirection direction, GstQuery* query);


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