[gstreamermm] Gst::BaseSrc: update basesrc class



commit 50714491160b927ffb5d9b16bb338757c0330f6e
Author: Marcin Kolny <marcin kolny gmail com>
Date:   Sun May 8 16:25:53 2016 +0200

    Gst::BaseSrc: update basesrc class
    
        * gstreamer/src/basesrc.{ccg|hg}: wrap missing virtual functions.
        * gstreamer/src/gst_vfuncs.defs: add vfuncs definitions.
        * tools/m4/convert_gst.m4: add BaseSrcFlags conversion definition.

 gstreamer/src/basesrc.ccg     |  138 ++++++++++++++++++++++++++++++++++++----
 gstreamer/src/basesrc.hg      |   41 ++++++++++---
 gstreamer/src/gst_vfuncs.defs |   28 ++++++++
 tools/m4/convert_gst.m4       |    1 +
 4 files changed, 185 insertions(+), 23 deletions(-)
---
diff --git a/gstreamer/src/basesrc.ccg b/gstreamer/src/basesrc.ccg
index 37dfa00..06b198e 100644
--- a/gstreamer/src/basesrc.ccg
+++ b/gstreamer/src/basesrc.ccg
@@ -1,6 +1,6 @@
 /* gstreamermm - a C++ wrapper for gstreamer
  *
- * Copyright 2008 The gstreamermm Development Team
+ * Copyright 2008-2016 The gstreamermm Development Team
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -25,19 +25,6 @@ _PINCLUDE(gstreamermm/private/element_p.h)
 namespace Gst
 {
 
-bool BaseSrc::query_latency(bool& live, ClockTime& min_latency,
-  ClockTime& max_latency) const
-{
-  gboolean gst_live = 0;
-
-  const bool result =
-    gst_base_src_query_latency(const_cast<GstBaseSrc*>(gobj()),
-    &gst_live, static_cast<GstClockTime*>(&min_latency),
-    static_cast<GstClockTime*>(&max_latency));
-  live = gst_live;
-  return result;
-}
-
 gboolean BaseSrc_Class::do_seek_vfunc_callback(GstBaseSrc* self, GstSegment* segment)
 {
   Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
@@ -210,4 +197,127 @@ Glib::RefPtr<Allocator> BaseSrc::get_allocator(AllocationParams& params)
   return Glib::wrap(alloc, false);
 }
 
+gboolean BaseSrc_Class::query_vfunc_callback(GstBaseSrc* self, GstQuery* query)
+{
+  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.
+       auto query_cpp = Glib::wrap(query, false);
+        int ret = static_cast<int>(obj->base_src_query_vfunc(query_cpp));
+       query_cpp.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->query)
+  {
+    gboolean retval = (*base->query)(self, query);
+    return retval;
+  }
+
+  typedef gboolean RType;
+  return RType();
+}
+
+bool Gst::BaseSrc::base_src_query_vfunc(const Glib::RefPtr<Gst::Query>& query)
+{
+  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->query)
+  {
+    bool retval((*base->query)(const_cast<GstBaseSrc*>(gobj()),Glib::unwrap(query)));
+    return retval;
+  }
+
+  typedef bool RType;
+  return RType();
+}
+
+GstFlowReturn BaseSrc_Class::alloc_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.
+    {
+      try // Trap C++ exceptions which would normally be lost because this is a C callback.
+      {
+        Glib::RefPtr<Gst::Buffer> cpp_buffer;
+        // Call the virtual member method, which derived classes might override.
+        GstFlowReturn const result = static_cast<GstFlowReturn>(obj->alloc_vfunc(offset, size, cpp_buffer));
+        *buf = cpp_buffer ? cpp_buffer->gobj_copy() : 0;
+        return result;
+      }
+      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->alloc)
+    return (*base->alloc)(self, offset, size, buf);
+
+
+  typedef GstFlowReturn RType;
+  return RType();
+}
+FlowReturn Gst::BaseSrc::alloc_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->alloc)
+  {
+    GstBuffer* gst_buffer = NULL;
+    Gst::FlowReturn const result =
+      static_cast<FlowReturn>((*base->alloc)(gobj(),offset, size,&gst_buffer));
+    buffer = Glib::wrap(gst_buffer, false); // Don't take copy because callback returns a newly created copy.
+    return result;
+  }
+
+  typedef FlowReturn RType;
+  return RType();
+}
+
+
 } // namespace Gst
diff --git a/gstreamer/src/basesrc.hg b/gstreamer/src/basesrc.hg
index 992b3d9..52181d1 100644
--- a/gstreamer/src/basesrc.hg
+++ b/gstreamer/src/basesrc.hg
@@ -1,6 +1,6 @@
 /* gstreamermm - a C++ wrapper for gstreamer
  *
- * Copyright 2008 The gstreamermm Development Team
+ * Copyright 2008-2016 The gstreamermm Development Team
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -29,6 +29,8 @@ _DEFS(gstreamermm,gst)
 namespace Gst
 {
 
+_WRAP_ENUM(BaseSrcFlags, GstBaseSrcFlags, NO_GTYPE)
+
 /** A base class for getrange based source elements.
  * This is a generice base class for source elements. The following types of
  * sources are supported:
@@ -134,7 +136,7 @@ namespace Gst
  * The old behaviour for controlled shutdown introduced since GStreamer 0.10.3
  * is still available but deprecated as it is dangerous and less flexible.
  *
- * Last reviewed on 2007-12-19 (0.10.16).
+ * Last reviewed on 2016-05-05 (1.8.0).
  *
  * @ingroup GstBaseClasses
  */
@@ -148,11 +150,7 @@ public:
   _WRAP_METHOD(bool is_live() const, gst_base_src_is_live)
   _WRAP_METHOD(void set_live(bool live), gst_base_src_set_live)
   _WRAP_METHOD(void set_format(Format format), gst_base_src_set_format)
-
-  _WRAP_METHOD_DOCS_ONLY(gst_base_src_query_latency)
-  bool query_latency(bool& live, Gst::ClockTime& min_latency,
-    Gst::ClockTime& max_latency) const;
-
+  _WRAP_METHOD(bool query_latency(bool& live, Gst::ClockTime& min_latency, Gst::ClockTime& max_latency) 
const, gst_base_src_query_latency)
   _WRAP_METHOD(guint get_blocksize() const, gst_base_src_get_blocksize)
   _WRAP_METHOD(void set_blocksize(guint blocksize), gst_base_src_set_blocksize)
   _WRAP_METHOD(bool get_do_timestamp() const, gst_base_src_get_do_timestamp)
@@ -166,6 +164,11 @@ public:
   _WRAP_METHOD(void start_complete(Gst::FlowReturn ret), gst_base_src_start_complete)
   _WRAP_METHOD(void set_automatic_eos(bool automatic_eos), gst_base_src_set_automatic_eos)
 
+  /** Returns the memory @a allocator used by the base class and its @a params.
+   *
+   * @param params The Gst::AllocationParams of @a allocator.
+   * @return The Gst::Allocator used.
+   */
   Glib::RefPtr<Gst::Allocator> get_allocator(Gst::AllocationParams& params);
   _IGNORE(gst_base_src_get_allocator)
 
@@ -232,10 +235,12 @@ public:
    */
   virtual bool do_seek_vfunc(Gst::Segment& segment); 
 
-#m4 _CONVERSION(`GstQuery*', `const Glib::RefPtr<Gst::Query>&', `Glib::wrap($3, true)')
+  // Cannot use query_vfunc because the name has been used in the Gst::Element class.
+  // We have to provide custom implementation, because query vfunc expects writable
+  // query object.
   /** Handle a requested query.
    */
-  //_WRAP_VFUNC(bool query(const Glib::RefPtr<Gst::Query>& query) const, "query")
+  virtual bool base_src_query_vfunc(const Glib::RefPtr<Gst::Query>& query);
 
   /** Called during negotiation if caps need fixating. Implement instead of
    * setting a fixate function on the source pad.
@@ -255,16 +260,34 @@ public:
    */
    virtual bool prepare_seek_segment_vfunc(const Glib::RefPtr<Gst::Event>& seek, Gst::Segment& segment);
 
+#m4 _CONVERSION(`GstQuery*', `const Glib::RefPtr<Gst::Query>&', `Glib::wrap($3, true)')
+  /** Configure the allocation query.
+   */
+  _WRAP_VFUNC(bool decide_allocation(const Glib::RefPtr<Gst::Query>& query), "decide_allocation")
+
+  /** Ask the subclass to allocate a buffer with for offset and size. The default
+   * implementation will create a new buffer from the negotiated allocator.
+   */
+  Gst::FlowReturn alloc_vfunc(guint64 offset, guint size, Glib::RefPtr<Gst::Buffer>& buffer);
+
+  /** Ask the subclass to fill the buffer with data for offset and size. The passed
+   * buffer is guaranteed to hold the requested amount of bytes.
+   */
+  _WRAP_VFUNC(Gst::FlowReturn fill(guint64 offset, guint size, const Glib::RefPtr<Gst::Buffer>& buffer), 
"fill")
 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;
+  klass->query = &query_vfunc_callback;
+  klass->alloc = &alloc_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);
+  static gboolean query_vfunc_callback(GstBaseSrc* self, GstQuery* query);
+  static GstFlowReturn alloc_vfunc_callback(GstBaseSrc* self, guint64 offset, guint size, GstBuffer** buf);
   _POP()
 #m4end
 };
diff --git a/gstreamer/src/gst_vfuncs.defs b/gstreamer/src/gst_vfuncs.defs
index d76d323..3b5eb04 100644
--- a/gstreamer/src/gst_vfuncs.defs
+++ b/gstreamer/src/gst_vfuncs.defs
@@ -416,6 +416,34 @@
   )
 )
 
+(define-vfunc decide_allocation
+  (of-object "GstBaseSrc")
+  (return-type "gboolean")
+  (parameters
+   '("GstQuery*" "query")
+  )
+)
+
+(define-vfunc alloc
+  (of-object "GstBaseSrc")
+  (return-type "GstFlowReturn")
+  (parameters
+   '("guint64" "offset")
+   '("guint" "size")
+   '("GstBuffer**" "buf")
+  )
+)
+
+(define-vfunc fill
+  (of-object "GstBaseSrc")
+  (return-type "GstFlowReturn")
+  (parameters
+   '("guint64" "offset")
+   '("guint" "size")
+   '("GstBuffer*" "buf")
+  )
+)
+
 ; GstBaseTransform
 
 (define-vfunc transform_caps
diff --git a/tools/m4/convert_gst.m4 b/tools/m4/convert_gst.m4
index 31edc85..24431d0 100644
--- a/tools/m4/convert_gst.m4
+++ b/tools/m4/convert_gst.m4
@@ -13,6 +13,7 @@ _CONV_ENUM(Gst,BufferFlags)
 _CONV_ENUM(Gst,AudioFormat)
 _CONV_ENUM(Gst,AudioFormatFlags)
 _CONV_ENUM(Gst,AudioRingBufferFormatType)
+_CONV_ENUM(Gst,BaseSrcFlags)
 _CONV_ENUM(Gst,CapsIntersectMode)
 _CONV_ENUM(Gst,ClockEntryType)
 _CONV_ENUM(Gst,ClockReturn)


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