[gstreamermm] Added Gst::RingBuffer base class.



commit fd3d309d7ed4bf98950a288ae65b85b17e3673d4
Author: José Alburquerque <jaalburqu svn gnome org>
Date:   Tue May 5 16:29:12 2009 -0400

    Added Gst::RingBuffer base class.
---
 ChangeLog                                     |   11 ++
 gstreamer/gstreamermm.h                       |    1 +
 gstreamer/src/Makefile_list_of_hg.am_fragment |    2 +-
 gstreamer/src/element.hg                      |    2 +-
 gstreamer/src/plugin.hg                       |    1 +
 gstreamer/src/ringbuffer.ccg                  |  133 ++++++++++++++++
 gstreamer/src/ringbuffer.hg                   |  210 +++++++++++++++++++++++++
 tools/m4/convert_gst.m4                       |    2 +
 8 files changed, 360 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6768919..5206803 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-05-05  José Alburquerque  <jaalburqu svn gnome org>
+
+	* gstreamer/gstreamermm.h:
+	* gstreamer/src/Makefile_list_of_hg.am_fragment:
+	* gstreamer/src/ringbuffer.ccg:
+	* gstreamer/src/ringbuffer.hg:
+	* tools/m4/convert_gst.m4: Added Gst::RingBuffer base class.
+
+	* gstreamer/src/element.hg:
+	* gstreamer/src/plugin.hg: Typos.
+
 2009-05-01  José Alburquerque  <jaalburqu svn gnome org>
 
 	* README: Also changed svn links to git links for future releases.
diff --git a/gstreamer/gstreamermm.h b/gstreamer/gstreamermm.h
index 3aa6caf..bc64863 100644
--- a/gstreamer/gstreamermm.h
+++ b/gstreamer/gstreamermm.h
@@ -59,6 +59,7 @@
 #include <gstreamermm/baseaudiosink.h>
 #include <gstreamermm/baseaudiosrc.h>
 #include <gstreamermm/cddabasesrc.h>
+#include <gstreamermm/ringbuffer.h>
 
 // Base inteface includes
 #include <gstreamermm/colorbalance.h>
diff --git a/gstreamer/src/Makefile_list_of_hg.am_fragment b/gstreamer/src/Makefile_list_of_hg.am_fragment
index 055315b..47ec63e 100644
--- a/gstreamer/src/Makefile_list_of_hg.am_fragment
+++ b/gstreamer/src/Makefile_list_of_hg.am_fragment
@@ -13,7 +13,7 @@ files_general_hg = bin.hg buffer.hg bus.hg caps.hg childproxy.hg clock.hg \
 	tagsetter.hg task.hg urihandler.hg value.hg xml.hg \
 	basesrc.hg basesink.hg basetransform.hg pushsrc.hg audioclock.hg \
 	audiofilter.hg audiosink.hg audiosrc.hg baseaudiosink.hg \
-	baseaudiosrc.hg cddabasesrc.hg videosink.hg \
+	baseaudiosrc.hg cddabasesrc.hg ringbuffer.hg videosink.hg \
    	colorbalance.hg colorbalancechannel.hg mixer.hg mixeroptions.hg \
 	mixertrack.hg navigation.hg propertyprobe.hg tuner.hg \
 	tunerchannel.hg tunernorm.hg videoorientation.hg xoverlay.hg
diff --git a/gstreamer/src/element.hg b/gstreamer/src/element.hg
index c65e38f..9aa7d7b 100644
--- a/gstreamer/src/element.hg
+++ b/gstreamer/src/element.hg
@@ -132,7 +132,7 @@ Glib::ustring get_name(StateChangeReturn state_ret);
  * toplevel Gst::Pipeline so the clock functions are only to be used in very
  * specific situations.
  *
- * Last reviewed on 2006-03-12 (0.10.5)
+ * Last reviewed on 2006-03-12 (0.10.5).
  * @ingroup GstBaseClasses
  */
 class Element : public Gst::Object
diff --git a/gstreamer/src/plugin.hg b/gstreamer/src/plugin.hg
index c43b774..8bc60ab 100644
--- a/gstreamer/src/plugin.hg
+++ b/gstreamer/src/plugin.hg
@@ -40,6 +40,7 @@ _WRAP_GERROR(PluginError, GstPluginError, GST_PLUGIN_ERROR)
  * Gst::PluginFeature subclasses.
  *
  * TODO: Edit following paragraph to use gstreamermm classes/methods:
+ *
  * A plugin should export a symbol gst_plugin_desc that is a struct of type
  * PluginDesc. the plugin loader will check the version of the core library
  * the plugin was linked against and will create a new Gst::Plugin. It will
diff --git a/gstreamer/src/ringbuffer.ccg b/gstreamer/src/ringbuffer.ccg
new file mode 100644
index 0000000..27a594e
--- /dev/null
+++ b/gstreamer/src/ringbuffer.ccg
@@ -0,0 +1,133 @@
+/* gstreamermm - a C++ wrapper for gstreamer
+ *
+ * Copyright 2008-2009 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gst/audio/audio-enumtypes.h>
+#include <gstreamermm/caps.h>
+#include <string.h>
+_PINCLUDE(gstreamermm/private/object_p.h)
+
+static void RingBuffer_Fill_gstreamermm_callback(GstRingBuffer* rbuf, guint8* data, guint len, gpointer user_data)
+{
+  Gst::RingBuffer::SlotFill* the_slot = static_cast<Gst::RingBuffer::SlotFill*>(user_data);
+
+  #ifdef GLIBMM_EXCEPTIONS_ENABLED
+  try
+  {
+  #endif //GLIBMM_EXCEPTIONS_ENABLED
+    (*the_slot)(data, len);
+  #ifdef GLIBMM_EXCEPTIONS_ENABLED
+  }
+  catch(...)
+  {
+    Glib::exception_handlers_invoke();
+  }
+  #endif //GLIBMM_EXCEPTIONS_ENABLED
+}
+
+namespace Gst
+{
+
+void RingBufferSpec::set_fields(GstRingBufferSpec& spec)
+{
+  type = (Gst::BufferFormatType)(spec.type);
+  format = (Gst::BufferFormat)(spec.format);
+  sign = spec.sign;
+  bigend = spec.bigend;
+  width = spec.width;
+  depth = spec.depth;
+  rate = spec.rate;
+  channels = spec.channels;
+  latency_time = spec.latency_time;
+  buffer_time = spec.buffer_time;
+  segsize = spec.segsize;
+  segtotal = spec.segtotal;
+  bytes_per_sample = spec.bytes_per_sample;
+  seglatency = spec.seglatency;
+
+  memcpy(silence_sample, spec.silence_sample, sizeof(silence_sample));
+}
+
+void RingBuffer::set_fill_slot(const SlotFill& slot)
+{
+  if (_slot_set())
+    delete this->slot;
+
+  this->slot = new SlotFill(slot);
+  _slot_set(true);
+
+  gst_ring_buffer_set_callback(gobj(), &RingBuffer_Fill_gstreamermm_callback,
+    this->slot);
+}
+
+bool RingBuffer::_slot_set(bool mark_set) const
+{
+  static bool slot_set = false;
+
+  if (mark_set)
+    slot_set = true;
+
+  return slot_set;
+}
+
+bool RingBuffer::acquire(Gst::RingBufferSpec& spec)
+{
+  GstRingBufferSpec gst_spec =
+  {
+    spec.caps->gobj(), (GstBufferFormatType)(spec.type),
+    (GstBufferFormat)(spec.format), spec.sign, spec.bigend, spec.width,
+    spec.depth, spec.rate, spec.channels, spec.latency_time, spec.buffer_time,
+    spec.segsize, spec.segtotal, spec.bytes_per_sample, {0,},
+    spec.seglatency
+  };
+
+  memcpy(gst_spec.silence_sample, spec.silence_sample,
+    sizeof(gst_spec.silence_sample));
+
+  gboolean const result = gst_ring_buffer_acquire(gobj(), &gst_spec);
+  spec.set_fields(gst_spec);
+  return result;
+}
+
+bool RingBuffer::parse_caps(Gst::RingBufferSpec& spec, const Glib::RefPtr<Gst::Caps>& caps)
+{
+  GstRingBufferSpec gst_spec =
+  {
+    spec.caps->gobj(), (GstBufferFormatType)(spec.type),
+    (GstBufferFormat)(spec.format), spec.sign, spec.bigend, spec.width,
+    spec.depth, spec.rate, spec.channels, spec.latency_time, spec.buffer_time,
+    spec.segsize, spec.segtotal, spec.bytes_per_sample, {0,},
+    spec.seglatency
+  };
+
+  memcpy(gst_spec.silence_sample, spec.silence_sample,
+    sizeof(gst_spec.silence_sample));
+
+  gboolean const result = gst_ring_buffer_parse_caps(&gst_spec, caps->gobj());
+  spec.set_fields(gst_spec);
+  return result;
+}
+
+RingBuffer::~RingBuffer()
+{
+    // Delete task's slot upon destruction
+  if (_slot_set())
+    delete slot;
+}
+
+} // namespace Gst
diff --git a/gstreamer/src/ringbuffer.hg b/gstreamer/src/ringbuffer.hg
new file mode 100644
index 0000000..2104ef1
--- /dev/null
+++ b/gstreamer/src/ringbuffer.hg
@@ -0,0 +1,210 @@
+/* gstreamermm - a C++ wrapper for gstreamer
+ *
+ * Copyright 2008-2009 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gst/audio/gstringbuffer.h>
+#include <gstreamermm/object.h>
+#include <gstreamermm/format.h>
+
+_DEFS(gstreamermm,gst)
+
+namespace Gst
+{
+
+class Caps;
+
+_WRAP_ENUM(RingBufferSegState, GstRingBufferSegState)
+_WRAP_ENUM(RingBufferState, GstRingBufferState)
+_WRAP_ENUM(BufferFormat, GstBufferFormat)
+_WRAP_ENUM(BufferFormatType, GstBufferFormatType)
+
+/** The structure containing the format specification of a Gst::RingBuffer.
+ * see Gst::RingBuffer::acquire().
+ */
+class RingBufferSpec
+{
+  _CLASS_GENERIC(RingBufferSpec, GstRingBufferSpec)
+public:
+  /** Copy the Gst::RingBufferSpec to a C object GstRingBufferSpec.  The C
+   * object should be freed when no longer needed.  A gobj() method is not
+   * implemented because there is no underlying C object to a
+   * Gst::RingBufferSpec.
+   */
+  GstRingBufferSpec* gobj_copy();
+
+  /** The caps that generated the Spec. */
+  Glib::RefPtr<Gst::Caps> caps;
+
+  /** The sample type.
+   */
+  Gst::BufferFormatType type;
+
+  /** The sample format.
+   */
+  Gst::BufferFormat format;
+
+  /** The sample sign.
+   */
+  bool          sign;
+
+  /** The endianness of the samples.
+   */
+  bool          bigend;
+
+  /** The width of the samples.
+   */
+  int           width;
+
+  /** The depth of the samples.
+   */
+  int           depth;
+
+  /** The samplerate.
+   */
+  int           rate;
+
+  /** The number of channels.
+   */
+  int           channels;
+
+  /** The latency in microseconds.
+   */
+  guint64       latency_time;
+
+  /**  The total buffer size in microseconds.
+   */
+  guint64       buffer_time;
+
+  /** The size of one segment in bytes.
+   */
+  int           segsize;
+
+  /** The total number of segments.
+   */
+  int           segtotal;
+
+  /** Number of bytes of one sample.
+  */
+  int           bytes_per_sample;
+
+  /** Bytes representing one sample of silence.
+  */
+  guint8        silence_sample[32];
+
+  /** Number of segments queued in the lower level device, defaults to
+   * segtotal.
+   */
+  int           seglatency;
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+protected:
+  friend class RingBuffer;
+  void set_fields(GstRingBufferSpec& spec);
+#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+};
+
+/** Gst::RingBuffer â?? Base class for audio ringbuffer implementations.
+ * This object is the base class for audio ringbuffers used by the base audio
+ * source and sink classes.
+ *
+ * The ringbuffer abstracts a circular buffer of data. One reader and one
+ * writer can operate on the data from different threads in a lockfree manner.
+ * The base class is sufficiently flexible to be used as an abstraction for DMA
+ * based ringbuffers as well as a pure software implementations.
+ *
+ * Last reviewed on 2006-02-02 (0.10.4).
+ * @ingroup GstBaseClasses
+ */
+class RingBuffer : public Gst::Object 
+{
+  _CLASS_GOBJECT(RingBuffer, GstRingBuffer, GST_RING_BUFFER, Gst::Object, GstObject)
+  _CUSTOM_DTOR()
+
+public:
+  /** For example,
+   * bool on_fill(const Glib::RefPtr<Gst::RingBuffer>& rbuf, guint8* data,
+   * guint len);.
+   * This slot is set with set_fill_slot() and is called to fill the memory at
+   * data with len bytes of samples.
+   */
+  typedef sigc::slot<void, guint8*, guint> SlotFill;
+
+  //TODO: _MEMBER_GET(cond, cond, Glib::Cond, GCond*)
+
+  /** Sets the given fill slot on the buffer. The slot will be called every
+   * time a segment has been written to a device.
+   *
+   * MT safe.
+   *
+   * @param slot The fill slot to set.
+   */
+  void set_fill_slot(const SlotFill& slot);
+
+  /** Allocate the resources for the ringbuffer. This function fills in the
+   * data pointer of the ring buffer with a valid Gst::Buffer to which samples
+   * can be written.
+   *
+   * @param spec The specs of the buffer.
+   *
+   * @return true if the device could be acquired, false on error. MT safe. 
+   */
+  bool acquire(Gst::RingBufferSpec& spec);
+
+  _WRAP_METHOD(bool release(), gst_ring_buffer_release)
+  _WRAP_METHOD(bool is_acquired() const, gst_ring_buffer_is_acquired)
+  _WRAP_METHOD(bool activate(bool active), gst_ring_buffer_activate)
+  _WRAP_METHOD(bool is_active() const, gst_ring_buffer_is_active)
+  _WRAP_METHOD(bool start(), gst_ring_buffer_start)
+  _WRAP_METHOD(bool pause(), gst_ring_buffer_pause)
+  _WRAP_METHOD(bool stop(), gst_ring_buffer_stop)
+  _WRAP_METHOD(guint get_delay() const, gst_ring_buffer_delay)
+  _WRAP_METHOD(guint64 get_samples_done() const, gst_ring_buffer_samples_done)
+  _WRAP_METHOD(void set_sample(guint64 sample), gst_ring_buffer_set_sample)
+  _WRAP_METHOD(guint commit(guint64 sample, guchar* data, guint len), gst_ring_buffer_commit)
+  _WRAP_METHOD(guint commit(guint64& sample, guchar* data, int in_samples, int out_samples, int& accum), gst_ring_buffer_commit_full)
+  _WRAP_METHOD(bool convert(Gst::Format src_fmt, gint64 src_val, Gst::Format dest_fmt, gint64& dest_val) const, gst_ring_buffer_convert)
+  _WRAP_METHOD(bool prepare_read(int& segment, guint8*& readptr, int& len), gst_ring_buffer_prepare_read)
+  _WRAP_METHOD(guint read(guint64 sample, guchar* data, guint len), gst_ring_buffer_read)
+  _WRAP_METHOD(void clear(int segment), gst_ring_buffer_clear)
+  _WRAP_METHOD(void clear_all(), gst_ring_buffer_clear_all)
+  _WRAP_METHOD(void advance(guint advance), gst_ring_buffer_advance)
+  _WRAP_METHOD(bool close_device(), gst_ring_buffer_close_device)
+  _WRAP_METHOD(bool open_device(), gst_ring_buffer_open_device)
+  _WRAP_METHOD(bool device_is_open() const, gst_ring_buffer_device_is_open)
+  _WRAP_METHOD(void set_may_start(bool allowed), gst_ring_buffer_may_start)
+
+  /** Parse caps into a Gst::RingBufferSpec.
+   *
+   * @param spec A Gst::RingBufferSpec.
+   * @param caps the Gst::Caps to parse.
+   * @return true if the caps could be parsed.
+   */
+  static bool parse_caps(Gst::RingBufferSpec& spec, const Glib::RefPtr<Gst::Caps>& caps);
+
+  _WRAP_METHOD(void set_flushing(bool flushing), gst_ring_buffer_set_flushing)
+
+  //TODO: Wrap vfuncs.
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+private:
+  SlotFill* slot;
+  bool _slot_set(bool mark_set = false) const;
+#endif
+};
+
+} // namespace Gst
diff --git a/tools/m4/convert_gst.m4 b/tools/m4/convert_gst.m4
index a3643be..d53c212 100644
--- a/tools/m4/convert_gst.m4
+++ b/tools/m4/convert_gst.m4
@@ -173,9 +173,11 @@ _CONVERSION(`const Glib::RefPtr<Gst::URIHandler>&',`GstURIHandler*',`($3)->gobj(
 
 #Basic General Conversions
 _CONVERSION(`gint64&',`gint64*',`&($3)')
+_CONVERSION(`guint64&',`guint64*',`&($3)')
 _CONVERSION(`guint*',`guint&',`*($3)')
 _CONVERSION(`const guint&',`guint',`$3')
 _CONVERSION(`const guint32&',`guint32',`($3)')
+_CONVERSION(`guint8*&',`guint8**',`&($3)')
 
 #Basic Gstreamermm Conversions
 _CONVERSION(`ClockTime&',`GstClockTime*',`(GstClockTime*)(&($3))')



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