[gstreamermm] Wrapped Gst::BaseSink base class vfuncs.



commit 2143e01e8ab9a7a7fc7dee3ad1f48f0aba971219
Author: José Alburquerque <jaalburqu svn gnome org>
Date:   Thu Apr 30 18:10:07 2009 -0400

    Wrapped Gst::BaseSink base class vfuncs.
---
 ChangeLog                  |    7 ++++
 gstreamer/src/basesink.ccg |   68 +++++++++++++++++++++++++++++++++++++
 gstreamer/src/basesink.hg  |   80 +++++++++++++++++++++++---------------------
 3 files changed, 117 insertions(+), 38 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 58a12d5..f1b862a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2009-04-30  José Alburquerque  <jaalburqu svn gnome org>
 
+	Wrapped Gst::BaseSink base class vfuncs.
+
+	* gstreamer/src/basesink.ccg:
+	* gstreamer/src/basesink.hg: Wrapped Gst::BaseSink base class vfuncs.
+
+2009-04-30  José Alburquerque  <jaalburqu svn gnome org>
+
 	Wrapped Gst::VideoOrientation interface vfuncs.
 
 	* gstreamer/src/videoorientation.ccg:
diff --git a/gstreamer/src/basesink.ccg b/gstreamer/src/basesink.ccg
index 9f7f6ac..1cae324 100644
--- a/gstreamer/src/basesink.ccg
+++ b/gstreamer/src/basesink.ccg
@@ -50,4 +50,72 @@ FlowReturn BaseSink::wait_eos(ClockTime time)
   return (FlowReturn)(gst_base_sink_wait_eos(const_cast<GstBaseSink*>(gobj()), (GstClockTime)(time), 0));
 }
 
+#ifdef GLIBMM_VFUNCS_ENABLED
+GstFlowReturn BaseSink_Class::buffer_alloc_vfunc_callback(GstBaseSink* self, guint64 offset, guint size, GstCaps* caps, GstBuffer** buf)
+{
+  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->buffer_alloc_vfunc(offset, size,
+          Glib::wrap(caps, true) , cpp_buffer)));
+        *buf = 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->buffer_alloc)
+    return (*base->buffer_alloc)(self, offset, size, caps, buf);
+
+
+  typedef GstFlowReturn RType;
+  return RType();
+}
+FlowReturn Gst::BaseSink::buffer_alloc_vfunc(guint64 offset, guint 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->buffer_alloc)
+  {
+    GstBuffer* gst_buffer;
+    const Gst::FlowReturn result = ((FlowReturn)((*base->buffer_alloc)(gobj(),
+      offset,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/basesink.hg b/gstreamer/src/basesink.hg
index 444db16..b02f85d 100644
--- a/gstreamer/src/basesink.hg
+++ b/gstreamer/src/basesink.hg
@@ -211,26 +211,20 @@ public:
   _WRAP_PROPERTY("sync", bool)
   _WRAP_PROPERTY("ts-offset", gint64)
 
-  //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()')
   /** Called to get sink pad caps from the subclass.
    */
   _WRAP_VFUNC(Glib::RefPtr<Gst::Caps> get_caps() const, "get_caps")
 
 #m4 _CONVERSION(`GstCaps*', `const Glib::RefPtr<Gst::Caps>&', `Glib::wrap($3, true)')
-  ///** Notify subclass of changed caps.
-   //*/
-  //_WRAP_VFUNC(bool set_caps(const Glib::RefPtr<Gst::Caps>& caps), "set_caps")
+  /** Notify subclass of changed caps.
+   */
+  _WRAP_VFUNC(bool set_caps(const Glib::RefPtr<Gst::Caps>& caps), "set_caps")
 
-//TODO: #m4 _CONVERSION(`Glib::RefPtr<Gst::Buffer>&', `GstBuffer**', `*($3)')
-  //_WRAP_VFUNC(FlowReturn buffer_alloc(guint64 offset, guint size, Glib::RefPtr<Gst::Buffer>& buffer), "buffer_alloc")
+#ifdef GLIBMM_VFUNCS_ENABLED
+  /** Allocate a new buffer with given caps. */
+  virtual FlowReturn buffer_alloc_vfunc(guint64 offset, guint size, const Glib::RefPtr<Gst::Caps>& caps, Glib::RefPtr<Gst::Buffer>& buffer);
+#endif //GLIBMM_VFUNCS_ENABLED
 
 #m4 _CONVERSION(`GstBuffer*', `const Glib::RefPtr<Gst::Buffer>&', `Gst::wrap($3, true)')
 #m4 _CONVERSION(`GstClockTime*', `ClockTime&', `*($3)')
@@ -239,22 +233,23 @@ public:
    */
   _WRAP_VFUNC(void get_times(const Glib::RefPtr<Gst::Buffer>& buffer, ClockTime& start, ClockTime& end) const, "get_times")
 
-  ///** Start processing. Ideal for opening resources in the subclass.
-   //*/
-  //_WRAP_VFUNC(bool start(), "start")
+  /** Start processing. Ideal for opening resources in the subclass.
+   */
+  _WRAP_VFUNC(bool start(), "start")
 
-  ///** Stop processing. Subclasses should use this to close resources.
-   //*/
-  //_WRAP_VFUNC(bool stop(), "stop")
+  /** Stop processing. Subclasses should use this to close resources.
+   */
+  _WRAP_VFUNC(bool stop(), "stop")
 
-  ///** Unlock any pending access to the resource. Subclasses should unblock any
-   //* blocked function ASAP.
-   //*/
-  //_WRAP_VFUNC(bool unlock(), "unlock")
+  /** Unlock any pending access to the resource. Subclasses should unblock any
+   * blocked function ASAP.
+   */
+  _WRAP_VFUNC(bool unlock(), "unlock")
 
-  ///** Override this to handle events arriving on the sink pad.
-   //*/
-  //_WRAP_VFUNC(bool event(const Glib::RefPtr<Gst::Event>& event), "event")
+#m4 _CONVERSION(`GstEvent*', `const Glib::RefPtr<Gst::Event>&', `Gst::wrap($3, true)')
+  /** Override this to handle events arriving on the sink pad.
+   */
+  _WRAP_VFUNC(bool event(const Glib::RefPtr<Gst::Event>& event), "event")
 
   /** Called to present the preroll buffer if desired.
    */
@@ -271,13 +266,13 @@ public:
    */
   _WRAP_VFUNC(StateChangeReturn async_play(), "async_play")
 
-  ///** Subclasses should override this when they can provide an alternate method
-   //* of spawning a thread to drive the pipeline in pull mode. Should start or
-   //* stop the pulling thread, depending on the value of the "active" argument.
-   //* Called after actually activating the sink pad in pull mode. The default
-   //* implementation starts a task on the sink pad. 
-   //*/
-  //_WRAP_VFUNC(bool activate_pull(bool active), "activate_pull")
+  /** Subclasses should override this when they can provide an alternate method
+   * of spawning a thread to drive the pipeline in pull mode. Should start or
+   * stop the pulling thread, depending on the value of the "active" argument.
+   * Called after actually activating the sink pad in pull mode. The default
+   * implementation starts a task on the sink pad. 
+   */
+  _WRAP_VFUNC(bool activate_pull(bool active), "activate_pull")
 
   /** Only useful in pull mode, this vmethod will be called in response to
    * Gst::Pad::fixate_caps() being called on the sink pad. Implement if you
@@ -286,10 +281,19 @@ public:
    */
   _WRAP_VFUNC(void fixate(const Glib::RefPtr<Gst::Caps>& caps), "fixate")
 
-  ///** Clear the previous unlock request. Subclasses should clear any state they
-   //* set during unlock_vfunc(), such as clearing command queues.
-   //*/
-  //_WRAP_VFUNC(bool unlock_stop(), "unlock_stop")
+  /** Clear the previous unlock request. Subclasses should clear any state they
+   * set during unlock_vfunc(), such as clearing command queues.
+   */
+  _WRAP_VFUNC(bool unlock_stop(), "unlock_stop")
+protected:
+#m4begin
+  _PUSH(SECTION_PCC_CLASS_INIT_VFUNCS)
+  klass->buffer_alloc = &buffer_alloc_vfunc_callback;
+  _SECTION(SECTION_PH_VFUNCS)
+  static GstFlowReturn buffer_alloc_vfunc_callback(GstBaseSink* self,
+    guint64 offset, guint size, GstCaps* caps, GstBuffer** buf);
+  _POP()
+#m4end
 };
 
-} //namespace Gst
+} // namespace Gst



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