[gstreamermm] Wrapped Gst::BaseTransform vfuncs.



commit a7f12c9c551b7c763ed5bfb40d99326fb4d3205c
Author: José Alburquerque <jaalburqu svn gnome org>
Date:   Thu Apr 30 22:06:45 2009 -0400

    Wrapped Gst::BaseTransform vfuncs.
---
 ChangeLog                       |    9 ++++
 gstreamer/src/basetransform.ccg |   70 ++++++++++++++++++++++++++
 gstreamer/src/basetransform.hg  |  102 ++++++++++++++++++++++-----------------
 gstreamer/src/gst_vfuncs.defs   |   10 ++++-
 tools/m4/convert_gst.m4         |    2 +
 5 files changed, 147 insertions(+), 46 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f1b862a..8873a68 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2009-04-30  José Alburquerque  <jaalburqu svn gnome org>
 
+	Wrapped Gst::BaseTransform vfuncs.
+
+	* gstreamer/src/basetransform.ccg:
+	* gstreamer/src/basetransform.hg:
+	* gstreamer/src/gst_vfuncs.defs:
+	* tools/m4/convert_gst.m4: Wrapped Gst::BaseTransform vfuncs.
+
+2009-04-30  José Alburquerque  <jaalburqu svn gnome org>
+
 	Wrapped Gst::BaseSink base class vfuncs.
 
 	* gstreamer/src/basesink.ccg:
diff --git a/gstreamer/src/basetransform.ccg b/gstreamer/src/basetransform.ccg
index 414b0c5..418dcbc 100644
--- a/gstreamer/src/basetransform.ccg
+++ b/gstreamer/src/basetransform.ccg
@@ -36,4 +36,74 @@ void BaseTransform::unlock()
   GST_BASE_TRANSFORM_UNLOCK(gobj());
 }
 
+#ifdef GLIBMM_VFUNCS_ENABLED
+GstFlowReturn BaseTransform_Class::prepare_output_buffer_vfunc_callback(GstBaseTransform* self, GstBuffer* input, gint size, GstCaps* caps, GstBuffer** buffer)
+{
+  Glib::ObjectBase *const 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_())
+  {
+    CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
+    if(obj) // This can be NULL during destruction.
+    {
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      try // Trap C++ exceptions which would normally be lost because this is a C callback.
+      {
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+        Glib::RefPtr<Gst::Buffer> cpp_buffer;
+        // Call the virtual member method, which derived classes might override.
+        const GstFlowReturn result =
+          ((GstFlowReturn)(obj->prepare_output_buffer_vfunc(
+          Gst::wrap(input, true) , size , Glib::wrap(caps, true), cpp_buffer)));
+        *buffer = cpp_buffer->gobj_copy();
+        return result;
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      }
+      catch(...)
+      {
+        Glib::exception_handlers_invoke();
+      }
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+    }
+  }
+  
+  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->prepare_output_buffer)
+    return (*base->prepare_output_buffer)(self, input, size, caps, buffer);
+
+
+  typedef GstFlowReturn RType;
+  return RType();
+}
+FlowReturn Gst::BaseTransform::prepare_output_buffer_vfunc(const Glib::RefPtr<Gst::Buffer>& input, int size, const Glib::RefPtr<Gst::Caps>& caps, Glib::RefPtr<Gst::Buffer>& buffer) 
+{
+  BaseClassType *const 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->prepare_output_buffer)
+  {
+    GstBuffer* gst_buffer;
+    const Gst::FlowReturn result =
+      ((FlowReturn)((*base->prepare_output_buffer)(gobj(),(input)->gobj(),
+      size,(caps)->gobj(),&gst_buffer)));
+    buffer = Gst::wrap(gst_buffer, false); // Don't take copy because callback returns a newly created copy.
+    return result;
+  }
+
+  typedef FlowReturn RType;
+  return RType();
+}
+#endif //GLIBMM_VFUNCS_ENABLED
+
 } //namespace Gst
diff --git a/gstreamer/src/basetransform.hg b/gstreamer/src/basetransform.hg
index 07469ce..38b4282 100644
--- a/gstreamer/src/basetransform.hg
+++ b/gstreamer/src/basetransform.hg
@@ -169,15 +169,6 @@ public:
 
   _WRAP_PROPERTY("qos", bool)
 
-  //TODO: bool vfuncs are a problem because if the base class does not
-  //implement one (which occurs often in GStreamer -- don't know why) the
-  //default generated callback returns false because of the "typedef RType;
-  //return RType()" statements (see discussion about bug #530416 in element.hg
-  //for more).  I've filed a patch for the bug which will allow a custom return
-  //to be specified for the callback, in which case the bool vfuncs can be made
-  //to return true which would then work.
-
-#m4 _CONVERSION(`Glib::RefPtr<Gst::Caps>', `GstCaps*', `($3)->gobj()')
 #m4 _CONVERSION(`GstCaps*', `const Glib::RefPtr<Gst::Caps>&', `Glib::wrap($3, true)')
   /** Optional. Given the pad in this direction and the given caps, what caps
    * are allowed on the other pad in this element ?
@@ -189,36 +180,37 @@ public:
    */
   _WRAP_VFUNC(void fixate_caps(PadDirection direction, const Glib::RefPtr<Gst::Caps>& caps, const Glib::RefPtr<Gst::Caps>& othercaps), "fixate_caps")
 
-  ///** Optional. Given the size of a buffer in the given direction with the
-   //* given caps, calculate the size in bytes of a buffer on the other pad with
-   //* the given other caps. The default implementation uses
-   //* get_unit_size_vfunc() and keeps the number of units the same.
-   //*/
-  //_WRAP_VFUNC(bool transform_size(PadDirection direction, const Glib::RefPtr<Gst::Caps>& caps, guint size, const Glib::RefPtr<Gst::Caps>& othercaps, guint& othersize), "transform_size")
-
-  ///** Required if the transform is not in-place. Get the size in bytes of one
-   //* unit for the given caps.
-   //*/
-  //_WRAP_VFUNC(bool get_unit_size(const Glib::RefPtr<Gst::Caps>& caps, guint& size) const, "get_unit_size")
-
-  ///** Allows the subclass to be notified of the actual caps set.
-   //*/
-  //_WRAP_VFUNC(bool set_caps(const Glib::RefPtr<Gst::Caps>& incaps, const Glib::RefPtr<Gst::Caps>& outcaps), "set_caps")
-
-  ///** Optional. Called when the element starts processing. Allows opening
-   //* external resources.
-   //*/
-  //_WRAP_VFUNC(bool start(), "start")
-
-  ///** Optional. Called when the element stops processing. Allows closing
-   //* external resources.
-   //*/
-  //_WRAP_VFUNC(bool stop(), "stop")
-
-  ///** Optional. Event handler on the sink pad. This function should return TRUE
-   //* if the base class should forward the event.
-   //*/
-  //_WRAP_VFUNC(bool event(const Glib::RefPtr<Gst::Event>& event), "event")
+  /** Optional. Given the size of a buffer in the given direction with the
+   * given caps, calculate the size in bytes of a buffer on the other pad with
+   * the given other caps. The default implementation uses
+   * get_unit_size_vfunc() and keeps the number of units the same.
+   */
+  _WRAP_VFUNC(bool transform_size(PadDirection direction, const Glib::RefPtr<Gst::Caps>& caps, guint size, const Glib::RefPtr<Gst::Caps>& othercaps, guint& othersize), "transform_size")
+
+  /** Required if the transform is not in-place. Get the size in bytes of one
+   * unit for the given caps.
+   */
+  _WRAP_VFUNC(bool get_unit_size(const Glib::RefPtr<Gst::Caps>& caps, guint& size) const, "get_unit_size")
+
+  /** Allows the subclass to be notified of the actual caps set.
+   */
+  _WRAP_VFUNC(bool set_caps(const Glib::RefPtr<Gst::Caps>& incaps, const Glib::RefPtr<Gst::Caps>& outcaps), "set_caps")
+
+  /** Optional. Called when the element starts processing. Allows opening
+   * external resources.
+   */
+  _WRAP_VFUNC(bool start(), "start")
+
+  /** Optional. Called when the element stops processing. Allows closing
+   * external resources.
+   */
+  _WRAP_VFUNC(bool stop(), "stop")
+
+#m4 _CONVERSION(`GstEvent*', `const Glib::RefPtr<Gst::Event>&', `Gst::wrap($3, true)')
+  /** Optional. Event handler on the sink pad. This function should return TRUE
+   * if the base class should forward the event.
+   */
+  _WRAP_VFUNC(bool event(const Glib::RefPtr<Gst::Event>& event), "event")
 
 #m4 _CONVERSION(`GstBuffer*', `const Glib::RefPtr<Gst::Buffer>&', `Gst::wrap($3, true)')
   /** Required if the element does not operate in-place. Transforms one
@@ -235,13 +227,33 @@ public:
   //TODO: Should "passthrough_on_same_caps" variable in GstBaseTransformClass
   //be wrapped?
 
-//TODO: #m4 _CONVERSION(`Glib::RefPtr<Gst::Buffer>&', `GstBuffer**', `&(($3)->gobj())')
-//#m4 _CONVERSION(`GstBuffer**', `Glib::RefPtr<Gst::Buffer>&', `Gst::wrap(*($3, true))')
-  //_WRAP_VFUNC(FlowReturn prepare_output_buffer(const Glib::RefPtr<Gst::Buffer>& input, int size, const Glib::RefPtr<Gst::Caps>& caps, Glib::RefPtr<Gst::Buffer>&), "prepare_output_buffer")
+#ifdef GLIBMM_VFUNCS_ENABLED
+  /** Optional. Subclasses can override this to do their own allocation of
+   * output buffers. Elements that only do analysis can return a subbuffer or
+   * even just increment the reference to the input buffer (if in passthrough
+   * mode).
+   */
+  virtual FlowReturn prepare_output_buffer_vfunc(const Glib::RefPtr<Gst::Buffer>& input, int size, const Glib::RefPtr<Gst::Caps>& caps, Glib::RefPtr<Gst::Buffer>& buffer);
+#endif //GLIBMM_VFUNCS_ENABLED
+
+  /** Optional. Event handler on the source pad.
+   */
+  _WRAP_VFUNC(bool src_event(const Glib::RefPtr<Gst::Event>& event), "src_event")
+
+  /** Optional. Since 0.10.22 This method is called right before the base class
+   * will start processing. Dynamic properties or other delayed configuration
+   * could be performed in this method.
+   */
+  _WRAP_VFUNC(void before_transform(const Glib::RefPtr<Gst::Buffer>& buffer), "before_transform")
 
-  ///** Optional. Event handler on the source pad.
-   //*/
-  //_WRAP_VFUNC(bool src_event(const Glib::RefPtr<Gst::Event>& event), "src_event")
+protected:
+#m4begin
+  _PUSH(SECTION_PCC_CLASS_INIT_VFUNCS)
+  klass->prepare_output_buffer = &prepare_output_buffer_vfunc_callback;
+  _SECTION(SECTION_PH_VFUNCS)
+  static GstFlowReturn prepare_output_buffer_vfunc_callback(GstBaseTransform* self, GstBuffer* input, gint size, GstCaps* caps, GstBuffer** buf);
+  _POP()
+#m4end
 };
 
 } //namespace Gst
diff --git a/gstreamer/src/gst_vfuncs.defs b/gstreamer/src/gst_vfuncs.defs
index 7b568b0..81c1b63 100644
--- a/gstreamer/src/gst_vfuncs.defs
+++ b/gstreamer/src/gst_vfuncs.defs
@@ -664,7 +664,7 @@
    '("GstBuffer*" "input")
    '("gint" "size")
    '("GstCaps*" "caps")
-   '("GstBuffer**" "buf")
+   '("GstBuffer**" "buffer")
   )
 )
 
@@ -676,6 +676,14 @@
   )
 )
 
+(define-vfunc before_transform
+  (of-object "GstBaseTransform")
+  (return-type "void")
+  (parameters
+   '("GstBuffer*" "buffer")
+  )
+)
+
 ; GstColorBalance
 
 (define-vfunc list_channels
diff --git a/tools/m4/convert_gst.m4 b/tools/m4/convert_gst.m4
index d1c24f9..a3643be 100644
--- a/tools/m4/convert_gst.m4
+++ b/tools/m4/convert_gst.m4
@@ -52,6 +52,7 @@ _CONVERSION(`GstBus*',`Glib::RefPtr<Gst::Bus>',`Glib::wrap($3)')
 
 #Caps
 _CONVERSION(`GstCaps*',`Glib::RefPtr<Gst::Caps>',`Glib::wrap($3)')
+_CONVERSION(`Glib::RefPtr<Gst::Caps>',`GstCaps*',`($3)->gobj()')
 _CONVERSION(`const Glib::RefPtr<Gst::Caps>&',`GstCaps*', `($3)->gobj()')
 _CONVERSION(`const Glib::RefPtr<const Gst::Caps>&',`GstCaps*', `const_cast<$2>(($3)->gobj())')
 _CONVERSION(`const Glib::RefPtr<Gst::Caps>&',`const GstCaps*', `($3)->gobj()')
@@ -172,6 +173,7 @@ _CONVERSION(`const Glib::RefPtr<Gst::URIHandler>&',`GstURIHandler*',`($3)->gobj(
 
 #Basic General Conversions
 _CONVERSION(`gint64&',`gint64*',`&($3)')
+_CONVERSION(`guint*',`guint&',`*($3)')
 _CONVERSION(`const guint&',`guint',`$3')
 _CONVERSION(`const guint32&',`guint32',`($3)')
 



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