gnomemm r2154 - in gstreamermm/trunk: . gstreamer/src



Author: jaalburqu
Date: Mon Apr 13 03:49:20 2009
New Revision: 2154
URL: http://svn.gnome.org/viewvc/gnomemm?rev=2154&view=rev

Log:
2009-04-12  Josà Alburquerque  <jaalburqu svn gnome org>

	* gstreamer/src/basesrc.ccg:
	* gstreamer/src/basesrc.hg: Wrapped all of Gst::BaseSrc vfuncs.
	Handwrote some.  In particular, create_vfunc() was difficult because
	of the (un-constant) Glib::RefPtr<Gst::Buffer> which should be empty
	initially but should have the created buffer after the vfunc is
	called.

Modified:
   gstreamermm/trunk/ChangeLog
   gstreamermm/trunk/gstreamer/src/basesrc.ccg
   gstreamermm/trunk/gstreamer/src/basesrc.hg

Modified: gstreamermm/trunk/gstreamer/src/basesrc.ccg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/basesrc.ccg	(original)
+++ gstreamermm/trunk/gstreamer/src/basesrc.ccg	Mon Apr 13 03:49:20 2009
@@ -21,3 +21,188 @@
 #include <gstreamermm/buffer.h>
 
 _PINCLUDE(gstreamermm/private/element_p.h)
+
+namespace Gst
+{
+
+#ifdef GLIBMM_VFUNCS_ENABLED
+gboolean BaseSrc_Class::do_seek_vfunc_callback(GstBaseSrc* self, GstSegment* segment)
+{
+  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
+      Gst::Segment gstmm_segment(segment, true);
+        // Call the virtual member method, which derived classes might override.
+        return static_cast<int>(obj->do_seek_vfunc(gstmm_segment));
+      #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->do_seek)
+    return (*base->do_seek)(self, segment);
+
+
+  typedef gboolean RType;
+  return RType();
+}
+bool Gst::BaseSrc::do_seek_vfunc(Gst::Segment& segment) 
+{
+  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->do_seek)
+    return (*base->do_seek)(gobj(),(segment).gobj());
+
+  typedef bool RType;
+  return RType();
+}
+gboolean BaseSrc_Class::prepare_seek_segment_vfunc_callback(GstBaseSrc* self, GstEvent* seek, GstSegment* segment)
+{
+  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
+        // Call the virtual member method, which derived classes might override.
+        Gst::Segment gstmm_segment(segment, true);
+        return static_cast<int>(obj->prepare_seek_segment_vfunc(Gst::wrap(seek, true) , gstmm_segment));
+      #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_seek_segment)
+    return (*base->prepare_seek_segment)(self, seek, segment);
+
+
+  typedef gboolean RType;
+  return RType();
+}
+bool Gst::BaseSrc::prepare_seek_segment_vfunc(const Glib::RefPtr<Gst::Event>& seek, Gst::Segment& segment) 
+{
+  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_seek_segment)
+    return (*base->prepare_seek_segment)(gobj(),Gst::unwrap(seek),(segment).gobj());
+
+  typedef bool RType;
+  return RType();
+}
+GstFlowReturn BaseSrc_Class::create_vfunc_callback(GstBaseSrc* self, guint64 offset, guint size, 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.
+        GstFlowReturn const result = (GstFlowReturn)(obj->create_vfunc(offset,
+          size, 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->create)
+    return (*base->create)(self, offset, size, buf);
+
+
+  typedef GstFlowReturn RType;
+  return RType();
+}
+FlowReturn Gst::BaseSrc::create_vfunc(guint64 offset, guint size, 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->create)
+  {
+    GstBuffer* gst_buffer;
+    Gst::FlowReturn const result = (FlowReturn)((*base->create)(gobj(),offset,
+      size,&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

Modified: gstreamermm/trunk/gstreamer/src/basesrc.hg
==============================================================================
--- gstreamermm/trunk/gstreamer/src/basesrc.hg	(original)
+++ gstreamermm/trunk/gstreamer/src/basesrc.hg	Mon Apr 13 03:49:20 2009
@@ -161,40 +161,32 @@
   _WRAP_PROPERTY("num-buffers", int)
   _WRAP_PROPERTY("typefind", 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()')
   /** Called to get the caps to report.
    */
   _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 output caps.
-   //*/
-  //_WRAP_VFUNC(bool set_caps(const Glib::RefPtr<Gst::Caps>& caps), "set_caps")
-
-  ///** Negotiated the caps with the peer.
-   //*/
-  //_WRAP_VFUNC(bool negotiate(), "negotiate")
-
-  ///** Generate and send a new_segment event (UNUSED).
-   //*/
-  //_WRAP_VFUNC(bool new_segment(), "newsegment")
-
-  ///** Start processing. Subclasses should open resources and prepare to produce
-   //* data.
-   //*/
-  //_WRAP_VFUNC(bool start(), "start")
-
-  ///** Stop processing. Subclasses should use this to close resources.
-   //*/
-  //_WRAP_VFUNC(bool stop(), "stop")
+  /** Notify subclass of changed output caps.
+   */
+  _WRAP_VFUNC(bool set_caps(const Glib::RefPtr<Gst::Caps>& caps), "set_caps")
+
+  /** Negotiated the caps with the peer.
+   */
+  _WRAP_VFUNC(bool negotiate(), "negotiate")
+
+  /** Generate and send a new_segment event (UNUSED).
+   */
+  _WRAP_VFUNC(bool new_segment(), "newsegment")
+
+  /** Start processing. Subclasses should open resources and prepare to produce
+   * data.
+   */
+  _WRAP_VFUNC(bool start(), "start")
+
+  /** Stop processing. Subclasses should use this to close resources.
+   */
+  _WRAP_VFUNC(bool stop(), "stop")
 
 #m4 _CONVERSION(`GstBuffer*', `const Glib::RefPtr<Gst::Buffer>&', `Gst::wrap($3, true)')
 #m4 _CONVERSION(`GstClockTime*', `ClockTime&', `*($3)')
@@ -205,60 +197,79 @@
 
 #m4 _CONVERSION(`guint64&', `guint64*', `&($3)')
 #m4 _CONVERSION(`guint64*', `guint64&', `*($3)')
-  ///** Return the total size of the resource, in the configured format.
-   //*/
-  //_WRAP_VFUNC(bool get_size(guint64& size) const, "get_size")
-
-  ///** Check if the source can seek.
-   //*/
-  //_WRAP_VFUNC(bool is_seekable() const, "is_seekable")
-
-  ///** Unlock any pending access to the resource. Subclasses should unblock any
-   //* blocked function ASAP.
-   //*/
-  //_WRAP_VFUNC(bool unlock(), "unlock")
-
-  ///** Override this to implement custom event handling.
-   //*/
-  //_WRAP_VFUNC(bool event(const Glib::RefPtr<Gst::Event>& event), "event")
-
-//TODO: #m4 _CONVERSION(`Glib::RefPtr<Gst::Buffer>&', `GstBuffer**', `*($3)')
-  //_WRAP_VFUNC(FlowReturn create(guint64 offset, guint size, Glib::RefPtr<Gst::Buffer>& buffer), "create")
-
-#m4 _CONVERSION(`Segment&', `GstSegment*', `($3).gobj()')
-  ///** Perform seeking on the resource to the indicated segment.
-   //*/
-  //_WRAP_VFUNC(bool do_seek(Segment& segment), "do_seek")
-
-  ///** Handle a requested query.
-   //*/
-  //_WRAP_VFUNC(bool query(const Glib::RefPtr<Gst::Query>& query), "query")
-
-  ///** Check whether the source would support pull-based operation if it were to
-   //* be opened now. This vfunc is optional, but should be implemented if
-   //* possible to avoid unnecessary start/stop cycles. The default
-   //* implementation will open and close the resource to find out whether
-   //* get_range() is supported, and that is usually undesirable.
-   //*/
-  //_WRAP_VFUNC(bool check_get_range(), "check_get_range")
+  /** Return the total size of the resource, in the configured format.
+   */
+  _WRAP_VFUNC(bool get_size(guint64& size) const, "get_size")
+
+  /** Check if the source can seek.
+   */
+  _WRAP_VFUNC(bool is_seekable() const, "is_seekable")
+
+  /** Unlock any pending access to the resource. Subclasses should unblock any
+   * blocked function ASAP.
+   */
+  _WRAP_VFUNC(bool unlock(), "unlock")
+
+#m4 _CONVERSION(`GstEvent*', `const Glib::RefPtr<Gst::Event>&', `Gst::wrap($3, true)')
+  /** Override this to implement custom event handling.
+   */
+  _WRAP_VFUNC(bool event(const Glib::RefPtr<Gst::Event>& event), "event")
+
+#ifdef GLIBMM_VFUNCS_ENABLED
+  virtual FlowReturn create_vfunc(guint64 offset, guint size, Glib::RefPtr<Gst::Buffer>& buffer);
+#endif //GLIBMM_VFUNCS_ENABLED
+
+#ifdef GLIBMM_VFUNCS_ENABLED
+  /** Perform seeking on the resource to the indicated segment.
+   */
+  virtual bool do_seek_vfunc(Gst::Segment& segment); 
+#endif //GLIBMM_VFUNCS_ENABLED
+
+#m4 _CONVERSION(`GstQuery*', `const Glib::RefPtr<Gst::Query>&', `Gst::wrap($3, true)')
+  /** Handle a requested query.
+   */
+  _WRAP_VFUNC(bool query(const Glib::RefPtr<Gst::Query>& query) const, "query")
+
+  /** Check whether the source would support pull-based operation if it were to
+   * be opened now. This vfunc is optional, but should be implemented if
+   * possible to avoid unnecessary start/stop cycles. The default
+   * implementation will open and close the resource to find out whether
+   * get_range() is supported, and that is usually undesirable.
+   */
+  _WRAP_VFUNC(bool check_get_range(), "check_get_range")
 
   /** Called during negotiation if caps need fixating. Implement instead of
    * setting a fixate function on the source pad.
    */
   _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")
-
-  ///** Prepare the Gst::Segment that will be passed to the do_seek_vfunc() vmethod
-   //* for executing a seek request. Sub-classes should override this if they
-   //* support seeking in formats other than the configured native format. By
-   //* default, it tries to convert the seek arguments to the configured native
-   //* format and prepare a segment in that format.
-   //*/
-  //_WRAP_VFUNC(bool prepare_seek_segment(const Glib::RefPtr<Gst::Event>& seek, Segment& segment), "prepare_seek_segment")
+  /** 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")
+
+#ifdef GLIBMM_VFUNCS_ENABLED
+  /** Prepare the Gst::Segment that will be passed to the do_seek_vfunc()
+   * vmethod for executing a seek request. Sub-classes should override this if
+   * they support seeking in formats other than the configured native format.
+   * By default, it tries to convert the seek arguments to the configured
+   * native format and prepare a segment in that format.
+   */
+   virtual bool prepare_seek_segment_vfunc(const Glib::RefPtr<Gst::Event>& seek, Gst::Segment& segment);
+#endif //GLIBMM_VFUNCS_ENABLED
+
+protected:
+#m4begin
+  _PUSH(SECTION_PCC_CLASS_INIT_VFUNCS)
+  klass->do_seek = &do_seek_vfunc_callback;
+  klass->prepare_seek_segment = &prepare_seek_segment_vfunc_callback;
+  klass->create = &create_vfunc_callback;
+  _SECTION(SECTION_PH_VFUNCS)
+  static gboolean do_seek_vfunc_callback(GstBaseSrc* self, GstSegment* segment);
+  static gboolean prepare_seek_segment_vfunc_callback(GstBaseSrc* self, GstEvent* seek, GstSegment* segment);
+  static GstFlowReturn create_vfunc_callback(GstBaseSrc* self, guint64 offset, guint size, GstBuffer** buf);
+  _POP()
+#m4end
 };
 
 } //namespace Gst



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