mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-24 09:34:25 +00:00
ringbuffer: allow for custom commit functions
Allow subclasses to override the commit method.
This commit is contained in:
parent
cae2981f83
commit
e6798c5cce
2 changed files with 69 additions and 42 deletions
|
@ -52,6 +52,8 @@ static void gst_ring_buffer_dispose (GObject * object);
|
||||||
static void gst_ring_buffer_finalize (GObject * object);
|
static void gst_ring_buffer_finalize (GObject * object);
|
||||||
|
|
||||||
static gboolean gst_ring_buffer_pause_unlocked (GstRingBuffer * buf);
|
static gboolean gst_ring_buffer_pause_unlocked (GstRingBuffer * buf);
|
||||||
|
static guint default_commit (GstRingBuffer * buf, guint64 * sample,
|
||||||
|
guchar * data, gint in_samples, gint out_samples, gint * accum);
|
||||||
|
|
||||||
static GstObjectClass *parent_class = NULL;
|
static GstObjectClass *parent_class = NULL;
|
||||||
|
|
||||||
|
@ -89,14 +91,18 @@ gst_ring_buffer_class_init (GstRingBufferClass * klass)
|
||||||
{
|
{
|
||||||
GObjectClass *gobject_class;
|
GObjectClass *gobject_class;
|
||||||
GstObjectClass *gstobject_class;
|
GstObjectClass *gstobject_class;
|
||||||
|
GstRingBufferClass *gstringbuffer_class;
|
||||||
|
|
||||||
gobject_class = (GObjectClass *) klass;
|
gobject_class = (GObjectClass *) klass;
|
||||||
gstobject_class = (GstObjectClass *) klass;
|
gstobject_class = (GstObjectClass *) klass;
|
||||||
|
gstringbuffer_class = (GstRingBufferClass *) klass;
|
||||||
|
|
||||||
parent_class = g_type_class_peek_parent (klass);
|
parent_class = g_type_class_peek_parent (klass);
|
||||||
|
|
||||||
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_ring_buffer_dispose);
|
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_ring_buffer_dispose);
|
||||||
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_ring_buffer_finalize);
|
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_ring_buffer_finalize);
|
||||||
|
|
||||||
|
gstringbuffer_class->commit = GST_DEBUG_FUNCPTR (default_commit);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1525,43 +1531,8 @@ G_STMT_START { \
|
||||||
GST_DEBUG ("rev_down end %d/%d",*accum,*toprocess); \
|
GST_DEBUG ("rev_down end %d/%d",*accum,*toprocess); \
|
||||||
} G_STMT_END
|
} G_STMT_END
|
||||||
|
|
||||||
/**
|
static guint
|
||||||
* gst_ring_buffer_commit_full:
|
default_commit (GstRingBuffer * buf, guint64 * sample,
|
||||||
* @buf: the #GstRingBuffer to commit
|
|
||||||
* @sample: the sample position of the data
|
|
||||||
* @data: the data to commit
|
|
||||||
* @in_samples: the number of samples in the data to commit
|
|
||||||
* @out_samples: the number of samples to write to the ringbuffer
|
|
||||||
* @accum: accumulator for rate conversion.
|
|
||||||
*
|
|
||||||
* Commit @in_samples samples pointed to by @data to the ringbuffer @buf.
|
|
||||||
*
|
|
||||||
* @in_samples and @out_samples define the rate conversion to perform on the the
|
|
||||||
* samples in @data. For negative rates, @out_samples must be negative and
|
|
||||||
* @in_samples positive.
|
|
||||||
*
|
|
||||||
* When @out_samples is positive, the first sample will be written at position @sample
|
|
||||||
* in the ringbuffer. When @out_samples is negative, the last sample will be written to
|
|
||||||
* @sample in reverse order.
|
|
||||||
*
|
|
||||||
* @out_samples does not need to be a multiple of the segment size of the ringbuffer
|
|
||||||
* although it is recommended for optimal performance.
|
|
||||||
*
|
|
||||||
* @accum will hold a temporary accumulator used in rate conversion and should be
|
|
||||||
* set to 0 when this function is first called. In case the commit operation is
|
|
||||||
* interrupted, one can resume the processing by passing the previously returned
|
|
||||||
* @accum value back to this function.
|
|
||||||
*
|
|
||||||
* MT safe.
|
|
||||||
*
|
|
||||||
* Returns: The number of samples written to the ringbuffer or -1 on error. The
|
|
||||||
* number of samples written can be less than @out_samples when @buf was interrupted
|
|
||||||
* with a flush or stop.
|
|
||||||
*
|
|
||||||
* Since: 0.10.11.
|
|
||||||
*/
|
|
||||||
guint
|
|
||||||
gst_ring_buffer_commit_full (GstRingBuffer * buf, guint64 * sample,
|
|
||||||
guchar * data, gint in_samples, gint out_samples, gint * accum)
|
guchar * data, gint in_samples, gint out_samples, gint * accum)
|
||||||
{
|
{
|
||||||
gint segdone;
|
gint segdone;
|
||||||
|
@ -1572,10 +1543,6 @@ gst_ring_buffer_commit_full (GstRingBuffer * buf, guint64 * sample,
|
||||||
gint inr, outr;
|
gint inr, outr;
|
||||||
gboolean reverse;
|
gboolean reverse;
|
||||||
|
|
||||||
if (G_UNLIKELY (in_samples == 0 || out_samples == 0))
|
|
||||||
return in_samples;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GST_IS_RING_BUFFER (buf), -1);
|
|
||||||
g_return_val_if_fail (buf->data != NULL, -1);
|
g_return_val_if_fail (buf->data != NULL, -1);
|
||||||
g_return_val_if_fail (data != NULL, -1);
|
g_return_val_if_fail (data != NULL, -1);
|
||||||
|
|
||||||
|
@ -1693,6 +1660,61 @@ not_started:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_ring_buffer_commit_full:
|
||||||
|
* @buf: the #GstRingBuffer to commit
|
||||||
|
* @sample: the sample position of the data
|
||||||
|
* @data: the data to commit
|
||||||
|
* @in_samples: the number of samples in the data to commit
|
||||||
|
* @out_samples: the number of samples to write to the ringbuffer
|
||||||
|
* @accum: accumulator for rate conversion.
|
||||||
|
*
|
||||||
|
* Commit @in_samples samples pointed to by @data to the ringbuffer @buf.
|
||||||
|
*
|
||||||
|
* @in_samples and @out_samples define the rate conversion to perform on the the
|
||||||
|
* samples in @data. For negative rates, @out_samples must be negative and
|
||||||
|
* @in_samples positive.
|
||||||
|
*
|
||||||
|
* When @out_samples is positive, the first sample will be written at position @sample
|
||||||
|
* in the ringbuffer. When @out_samples is negative, the last sample will be written to
|
||||||
|
* @sample in reverse order.
|
||||||
|
*
|
||||||
|
* @out_samples does not need to be a multiple of the segment size of the ringbuffer
|
||||||
|
* although it is recommended for optimal performance.
|
||||||
|
*
|
||||||
|
* @accum will hold a temporary accumulator used in rate conversion and should be
|
||||||
|
* set to 0 when this function is first called. In case the commit operation is
|
||||||
|
* interrupted, one can resume the processing by passing the previously returned
|
||||||
|
* @accum value back to this function.
|
||||||
|
*
|
||||||
|
* MT safe.
|
||||||
|
*
|
||||||
|
* Returns: The number of samples written to the ringbuffer or -1 on error. The
|
||||||
|
* number of samples written can be less than @out_samples when @buf was interrupted
|
||||||
|
* with a flush or stop.
|
||||||
|
*
|
||||||
|
* Since: 0.10.11.
|
||||||
|
*/
|
||||||
|
guint
|
||||||
|
gst_ring_buffer_commit_full (GstRingBuffer * buf, guint64 * sample,
|
||||||
|
guchar * data, gint in_samples, gint out_samples, gint * accum)
|
||||||
|
{
|
||||||
|
GstRingBufferClass *rclass;
|
||||||
|
guint res = -1;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GST_IS_RING_BUFFER (buf), -1);
|
||||||
|
|
||||||
|
if (G_UNLIKELY (in_samples == 0 || out_samples == 0))
|
||||||
|
return in_samples;
|
||||||
|
|
||||||
|
rclass = GST_RING_BUFFER_GET_CLASS (buf);
|
||||||
|
|
||||||
|
if (G_LIKELY (rclass->commit))
|
||||||
|
res = rclass->commit (buf, sample, data, in_samples, out_samples, accum);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_ring_buffer_commit:
|
* gst_ring_buffer_commit:
|
||||||
* @buf: the #GstRingBuffer to commit
|
* @buf: the #GstRingBuffer to commit
|
||||||
|
|
|
@ -300,6 +300,7 @@ struct _GstRingBuffer {
|
||||||
* @delay: get number of samples queued in device
|
* @delay: get number of samples queued in device
|
||||||
* @activate: activate the thread that starts pulling and monitoring the
|
* @activate: activate the thread that starts pulling and monitoring the
|
||||||
* consumed segments in the device. Since 0.10.22
|
* consumed segments in the device. Since 0.10.22
|
||||||
|
* @commit: write samples into the ringbuffer
|
||||||
*
|
*
|
||||||
* The vmethods that subclasses can override to implement the ringbuffer.
|
* The vmethods that subclasses can override to implement the ringbuffer.
|
||||||
*/
|
*/
|
||||||
|
@ -322,8 +323,12 @@ struct _GstRingBufferClass {
|
||||||
/* ABI added */
|
/* ABI added */
|
||||||
gboolean (*activate) (GstRingBuffer *buf, gboolean active);
|
gboolean (*activate) (GstRingBuffer *buf, gboolean active);
|
||||||
|
|
||||||
|
guint (*commit) (GstRingBuffer * buf, guint64 *sample,
|
||||||
|
guchar * data, gint in_samples,
|
||||||
|
gint out_samples, gint * accum);
|
||||||
|
|
||||||
/*< private >*/
|
/*< private >*/
|
||||||
gpointer _gst_reserved[GST_PADDING - 1];
|
gpointer _gst_reserved[GST_PADDING - 2];
|
||||||
};
|
};
|
||||||
|
|
||||||
GType gst_ring_buffer_get_type(void);
|
GType gst_ring_buffer_get_type(void);
|
||||||
|
|
Loading…
Reference in a new issue