gst-libs/gst/audio/gstbaseaudiosink.c: Use gobject_class instead of G_OBJECT_CLASS (klass)

Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_class_init),
(gst_base_audio_sink_provide_clock):
Use gobject_class instead of G_OBJECT_CLASS (klass)
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_class_init), (gst_base_audio_src_init),
(gst_base_audio_src_set_clock), (gst_base_audio_src_provide_clock),
(gst_base_audio_src_get_time),
(gst_base_audio_src_check_get_range), (gst_base_audio_src_create),
(gst_base_audio_src_create_ringbuffer):
Fix latency and buffer-time constants and properties ala basesink.
Implement pull based scheduling. Fixes #346527.
Set default blocksize in GstBaseSrc to 0, we default to pushing out
one segment.
Refuse slaving to another clock instead of silently not working.
Only provide a clock when we are actually able to do so.
Various small cleanups and compiler hints.
This commit is contained in:
Wim Taymans 2006-07-06 15:54:50 +00:00
parent 9585862055
commit fa5dacc998
3 changed files with 147 additions and 46 deletions

View file

@ -1,3 +1,24 @@
2006-07-06 Wim Taymans <wim@fluendo.com>
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_class_init),
(gst_base_audio_sink_provide_clock):
Use gobject_class instead of G_OBJECT_CLASS (klass)
* gst-libs/gst/audio/gstbaseaudiosrc.c:
(gst_base_audio_src_class_init), (gst_base_audio_src_init),
(gst_base_audio_src_set_clock), (gst_base_audio_src_provide_clock),
(gst_base_audio_src_get_time),
(gst_base_audio_src_check_get_range), (gst_base_audio_src_create),
(gst_base_audio_src_create_ringbuffer):
Fix latency and buffer-time constants and properties ala basesink.
Implement pull based scheduling. Fixes #346527.
Set default blocksize in GstBaseSrc to 0, we default to pushing out
one segment.
Refuse slaving to another clock instead of silently not working.
Only provide a clock when we are actually able to do so.
Various small cleanups and compiler hints.
2006-07-06 Tim-Philipp Müller <tim at centricular dot net> 2006-07-06 Tim-Philipp Müller <tim at centricular dot net>
Patch by: Lutz Mueller <lutz at topfrose de> Patch by: Lutz Mueller <lutz at topfrose de>

View file

@ -115,17 +115,17 @@ gst_base_audio_sink_class_init (GstBaseAudioSinkClass * klass)
GST_DEBUG_FUNCPTR (gst_base_audio_sink_get_property); GST_DEBUG_FUNCPTR (gst_base_audio_sink_get_property);
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_base_audio_sink_dispose); gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_base_audio_sink_dispose);
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BUFFER_TIME, g_object_class_install_property (gobject_class, PROP_BUFFER_TIME,
g_param_spec_int64 ("buffer-time", "Buffer Time", g_param_spec_int64 ("buffer-time", "Buffer Time",
"Size of audio buffer in microseconds", 1, "Size of audio buffer in microseconds", 1,
G_MAXINT64, DEFAULT_BUFFER_TIME, G_PARAM_READWRITE)); G_MAXINT64, DEFAULT_BUFFER_TIME, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_LATENCY_TIME, g_object_class_install_property (gobject_class, PROP_LATENCY_TIME,
g_param_spec_int64 ("latency-time", "Latency Time", g_param_spec_int64 ("latency-time", "Latency Time",
"Audio latency in microseconds", 1, "Audio latency in microseconds", 1,
G_MAXINT64, DEFAULT_LATENCY_TIME, G_PARAM_READWRITE)); G_MAXINT64, DEFAULT_LATENCY_TIME, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PROVIDE_CLOCK, g_object_class_install_property (gobject_class, PROP_PROVIDE_CLOCK,
g_param_spec_boolean ("provide-clock", "Provide Clock", g_param_spec_boolean ("provide-clock", "Provide Clock",
"Provide a clock to be used as the global pipeline clock", "Provide a clock to be used as the global pipeline clock",
DEFAULT_PROVIDE_CLOCK, G_PARAM_READWRITE)); DEFAULT_PROVIDE_CLOCK, G_PARAM_READWRITE));
@ -184,7 +184,7 @@ gst_base_audio_sink_provide_clock (GstElement * elem)
sink = GST_BASE_AUDIO_SINK (elem); sink = GST_BASE_AUDIO_SINK (elem);
/* we have no ringbuffer (must be NULL state */ /* we have no ringbuffer (must be NULL state) */
if (sink->ringbuffer == NULL) if (sink->ringbuffer == NULL)
goto wrong_state; goto wrong_state;

View file

@ -34,8 +34,9 @@ enum
LAST_SIGNAL LAST_SIGNAL
}; };
#define DEFAULT_BUFFER_TIME 500 * GST_USECOND #define DEFAULT_BUFFER_TIME ((200 * GST_MSECOND) / GST_USECOND)
#define DEFAULT_LATENCY_TIME 10 * GST_USECOND #define DEFAULT_LATENCY_TIME ((10 * GST_MSECOND) / GST_USECOND)
enum enum
{ {
PROP_0, PROP_0,
@ -60,11 +61,14 @@ static GstStateChangeReturn gst_base_audio_src_change_state (GstElement *
element, GstStateChange transition); element, GstStateChange transition);
static GstClock *gst_base_audio_src_provide_clock (GstElement * elem); static GstClock *gst_base_audio_src_provide_clock (GstElement * elem);
static gboolean gst_base_audio_src_set_clock (GstElement * elem,
GstClock * clock);
static GstClockTime gst_base_audio_src_get_time (GstClock * clock, static GstClockTime gst_base_audio_src_get_time (GstClock * clock,
GstBaseAudioSrc * src); GstBaseAudioSrc * src);
static GstFlowReturn gst_base_audio_src_create (GstPushSrc * psrc, static GstFlowReturn gst_base_audio_src_create (GstBaseSrc * bsrc,
GstBuffer ** buf); guint64 offset, guint length, GstBuffer ** buf);
static gboolean gst_base_audio_src_check_get_range (GstBaseSrc * bsrc);
static gboolean gst_base_audio_src_event (GstBaseSrc * bsrc, GstEvent * event); static gboolean gst_base_audio_src_event (GstBaseSrc * bsrc, GstEvent * event);
static void gst_base_audio_src_get_times (GstBaseSrc * bsrc, static void gst_base_audio_src_get_times (GstBaseSrc * bsrc,
@ -81,7 +85,6 @@ gst_base_audio_src_base_init (gpointer g_class)
static void static void
gst_base_audio_src_class_init (GstBaseAudioSrcClass * klass) gst_base_audio_src_class_init (GstBaseAudioSrcClass * klass)
{ {
gchar *longdesc;
GObjectClass *gobject_class; GObjectClass *gobject_class;
GstElementClass *gstelement_class; GstElementClass *gstelement_class;
GstBaseSrcClass *gstbasesrc_class; GstBaseSrcClass *gstbasesrc_class;
@ -97,33 +100,30 @@ gst_base_audio_src_class_init (GstBaseAudioSrcClass * klass)
gobject_class->get_property = gobject_class->get_property =
GST_DEBUG_FUNCPTR (gst_base_audio_src_get_property); GST_DEBUG_FUNCPTR (gst_base_audio_src_get_property);
longdesc = g_object_class_install_property (gobject_class, PROP_BUFFER_TIME,
g_strdup_printf g_param_spec_int64 ("buffer-time", "Buffer Time",
("Size of audio buffer in microseconds (use -1 for default of %" "Size of audio buffer in microseconds", 1,
G_GUINT64_FORMAT " us)", DEFAULT_BUFFER_TIME / GST_USECOND);
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BUFFER_TIME,
g_param_spec_int64 ("buffer-time", "Buffer Time", longdesc, -1,
G_MAXINT64, DEFAULT_BUFFER_TIME, G_PARAM_READWRITE)); G_MAXINT64, DEFAULT_BUFFER_TIME, G_PARAM_READWRITE));
g_free (longdesc);
longdesc = g_object_class_install_property (gobject_class, PROP_LATENCY_TIME,
g_strdup_printf ("Audio latency in microseconds (use -1 for default of %" g_param_spec_int64 ("latency-time", "Latency Time",
G_GUINT64_FORMAT " us)", DEFAULT_LATENCY_TIME / GST_USECOND); "Audio latency in microseconds", 1,
g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_LATENCY_TIME,
g_param_spec_int64 ("latency-time", "Latency Time", longdesc, -1,
G_MAXINT64, DEFAULT_LATENCY_TIME, G_PARAM_READWRITE)); G_MAXINT64, DEFAULT_LATENCY_TIME, G_PARAM_READWRITE));
g_free (longdesc);
gstelement_class->change_state = gstelement_class->change_state =
GST_DEBUG_FUNCPTR (gst_base_audio_src_change_state); GST_DEBUG_FUNCPTR (gst_base_audio_src_change_state);
gstelement_class->provide_clock = gstelement_class->provide_clock =
GST_DEBUG_FUNCPTR (gst_base_audio_src_provide_clock); GST_DEBUG_FUNCPTR (gst_base_audio_src_provide_clock);
gstelement_class->set_clock =
GST_DEBUG_FUNCPTR (gst_base_audio_src_set_clock);
gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_base_audio_src_setcaps); gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_base_audio_src_setcaps);
gstbasesrc_class->event = GST_DEBUG_FUNCPTR (gst_base_audio_src_event); gstbasesrc_class->event = GST_DEBUG_FUNCPTR (gst_base_audio_src_event);
gstbasesrc_class->get_times = gstbasesrc_class->get_times =
GST_DEBUG_FUNCPTR (gst_base_audio_src_get_times); GST_DEBUG_FUNCPTR (gst_base_audio_src_get_times);
gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_base_audio_src_create);
gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_base_audio_src_create); gstbasesrc_class->check_get_range =
GST_DEBUG_FUNCPTR (gst_base_audio_src_check_get_range);
} }
static void static void
@ -132,6 +132,9 @@ gst_base_audio_src_init (GstBaseAudioSrc * baseaudiosrc,
{ {
baseaudiosrc->buffer_time = DEFAULT_BUFFER_TIME; baseaudiosrc->buffer_time = DEFAULT_BUFFER_TIME;
baseaudiosrc->latency_time = DEFAULT_LATENCY_TIME; baseaudiosrc->latency_time = DEFAULT_LATENCY_TIME;
/* reset blocksize we use latency time to calculate a more useful
* value based on negotiated format. */
GST_BASE_SRC (baseaudiosrc)->blocksize = 0;
baseaudiosrc->clock = gst_audio_clock_new ("clock", baseaudiosrc->clock = gst_audio_clock_new ("clock",
(GstAudioClockGetTimeFunc) gst_base_audio_src_get_time, baseaudiosrc); (GstAudioClockGetTimeFunc) gst_base_audio_src_get_time, baseaudiosrc);
@ -139,18 +142,59 @@ gst_base_audio_src_init (GstBaseAudioSrc * baseaudiosrc,
gst_pad_set_fixatecaps_function (GST_BASE_SRC_PAD (baseaudiosrc), gst_pad_set_fixatecaps_function (GST_BASE_SRC_PAD (baseaudiosrc),
gst_base_audio_src_fixate); gst_base_audio_src_fixate);
/* we are always a live source */
gst_base_src_set_live (GST_BASE_SRC (baseaudiosrc), TRUE); gst_base_src_set_live (GST_BASE_SRC (baseaudiosrc), TRUE);
gst_base_src_set_format (GST_BASE_SRC (baseaudiosrc), GST_FORMAT_TIME); gst_base_src_set_format (GST_BASE_SRC (baseaudiosrc), GST_FORMAT_TIME);
} }
static gboolean
gst_base_audio_src_set_clock (GstElement * elem, GstClock * clock)
{
GstBaseAudioSrc *src;
src = GST_BASE_AUDIO_SRC (elem);
/* FIXME, we cannot slave to another clock yet, better fail
* than to give a bad user experience (tm). */
if (clock && clock != src->clock)
goto wrong_clock;
return TRUE;
/* ERRORS */
wrong_clock:
{
GST_ELEMENT_ERROR (src, CORE, CLOCK,
(NULL), ("Cannot operate with this clock."));
return FALSE;
}
}
static GstClock * static GstClock *
gst_base_audio_src_provide_clock (GstElement * elem) gst_base_audio_src_provide_clock (GstElement * elem)
{ {
GstBaseAudioSrc *src; GstBaseAudioSrc *src;
GstClock *clock;
src = GST_BASE_AUDIO_SRC (elem); src = GST_BASE_AUDIO_SRC (elem);
return GST_CLOCK (gst_object_ref (GST_OBJECT (src->clock))); /* we have no ringbuffer (must be NULL state) */
if (src->ringbuffer == NULL)
goto wrong_state;
if (!gst_ring_buffer_is_acquired (src->ringbuffer))
goto wrong_state;
clock = GST_CLOCK_CAST (gst_object_ref (src->clock));
return clock;
/* ERRORS */
wrong_state:
{
GST_DEBUG_OBJECT (src, "ringbuffer not acquired");
return NULL;
}
} }
static GstClockTime static GstClockTime
@ -159,8 +203,8 @@ gst_base_audio_src_get_time (GstClock * clock, GstBaseAudioSrc * src)
guint64 samples; guint64 samples;
GstClockTime result; GstClockTime result;
if (src->ringbuffer == NULL || src->ringbuffer->spec.rate == 0) if (G_UNLIKELY (src->ringbuffer == NULL || src->ringbuffer->spec.rate == 0))
return 0; return GST_CLOCK_TIME_NONE;
samples = gst_ring_buffer_samples_done (src->ringbuffer); samples = gst_ring_buffer_samples_done (src->ringbuffer);
@ -170,6 +214,16 @@ gst_base_audio_src_get_time (GstClock * clock, GstBaseAudioSrc * src)
return result; return result;
} }
static gboolean
gst_base_audio_src_check_get_range (GstBaseSrc * bsrc)
{
/* we allow limited pull base operation of which the details
* will eventually exposed in an as of yet non-existing query.
* Basically pulling can be done on any number of bytes as long
* as the offset is -1 or sequentially increasing. */
return TRUE;
}
static void static void
gst_base_audio_src_set_property (GObject * object, guint prop_id, gst_base_audio_src_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec) const GValue * value, GParamSpec * pspec)
@ -315,59 +369,86 @@ gst_base_audio_src_event (GstBaseSrc * bsrc, GstEvent * event)
} }
static GstFlowReturn static GstFlowReturn
gst_base_audio_src_create (GstPushSrc * psrc, GstBuffer ** outbuf) gst_base_audio_src_create (GstBaseSrc * bsrc, guint64 offset, guint length,
GstBuffer ** outbuf)
{ {
GstBaseAudioSrc *src = GST_BASE_AUDIO_SRC (psrc); GstBaseAudioSrc *src = GST_BASE_AUDIO_SRC (bsrc);
GstBuffer *buf; GstBuffer *buf;
guchar *data; guchar *data;
guint len, samples; guint samples;
guint res; guint res;
guint64 sample; guint64 sample;
gint bps;
GstRingBuffer *ringbuffer; GstRingBuffer *ringbuffer;
ringbuffer = src->ringbuffer; ringbuffer = src->ringbuffer;
if (!gst_ring_buffer_is_acquired (ringbuffer)) if (G_UNLIKELY (!gst_ring_buffer_is_acquired (ringbuffer)))
goto wrong_state; goto wrong_state;
buf = gst_buffer_new_and_alloc (ringbuffer->spec.segsize); bps = ringbuffer->spec.bytes_per_sample;
data = GST_BUFFER_DATA (buf); if ((length == 0 && bsrc->blocksize == 0) || length == -1)
len = GST_BUFFER_SIZE (buf); /* no length given, use the default segment size */
length = ringbuffer->spec.segsize;
else
/* make sure we round down to an integral number of samples */
length -= length % bps;
if (src->next_sample != -1) { /* calculate the sequentially next sample we need to read */
sample = src->next_sample; sample = (src->next_sample != -1 ? src->next_sample : 0);
} else {
sample = 0; if (G_UNLIKELY (offset != -1)) {
/* if a specific offset was given it must be the next
* sequential offset we expect or we fail. */
if (offset / bps != sample)
goto wrong_offset;
} }
samples = len / ringbuffer->spec.bytes_per_sample; /* get the number of samples to read */
samples = length / bps;
/* FIXME, using a bufferpool would be nice here */
buf = gst_buffer_new_and_alloc (length);
data = GST_BUFFER_DATA (buf);
res = gst_ring_buffer_read (ringbuffer, sample, data, samples); res = gst_ring_buffer_read (ringbuffer, sample, data, samples);
if (res == -1) if (G_UNLIKELY (res == -1))
goto stopped; goto stopped;
/* FIXME, we timestamp against our own clock, also handle the case
* where we are slaved to another clock. We currently refuse to accept
* any other clock than the one we provide, so this code is fine for
* now. */
GST_BUFFER_TIMESTAMP (buf) = gst_util_uint64_scale_int (sample, GST_BUFFER_TIMESTAMP (buf) = gst_util_uint64_scale_int (sample,
GST_SECOND, ringbuffer->spec.rate); GST_SECOND, ringbuffer->spec.rate);
src->next_sample = sample + samples; src->next_sample = sample + samples;
GST_BUFFER_DURATION (buf) = gst_util_uint64_scale_int (src->next_sample, GST_BUFFER_DURATION (buf) = gst_util_uint64_scale_int (src->next_sample,
GST_SECOND, ringbuffer->spec.rate) - GST_BUFFER_TIMESTAMP (buf); GST_SECOND, ringbuffer->spec.rate) - GST_BUFFER_TIMESTAMP (buf);
gst_buffer_set_caps (buf, GST_PAD_CAPS (GST_BASE_SRC_PAD (psrc))); gst_buffer_set_caps (buf, GST_PAD_CAPS (GST_BASE_SRC_PAD (bsrc)));
*outbuf = buf; *outbuf = buf;
return GST_FLOW_OK; return GST_FLOW_OK;
/* ERRORS */
wrong_state: wrong_state:
{ {
GST_DEBUG ("ringbuffer in wrong state"); GST_DEBUG_OBJECT (src, "ringbuffer in wrong state");
return GST_FLOW_WRONG_STATE; return GST_FLOW_WRONG_STATE;
} }
wrong_offset:
{
GST_ELEMENT_ERROR (src, RESOURCE, SEEK,
(NULL), ("resource can only be operated on sequentially but offset %"
G_GUINT64_FORMAT " was given", offset));
return GST_FLOW_ERROR;
}
stopped: stopped:
{ {
gst_buffer_unref (buf); gst_buffer_unref (buf);
GST_DEBUG ("ringbuffer stopped"); GST_DEBUG_OBJECT (src, "ringbuffer stopped");
return GST_FLOW_WRONG_STATE; return GST_FLOW_WRONG_STATE;
} }
} }
@ -382,9 +463,8 @@ gst_base_audio_src_create_ringbuffer (GstBaseAudioSrc * src)
if (bclass->create_ringbuffer) if (bclass->create_ringbuffer)
buffer = bclass->create_ringbuffer (src); buffer = bclass->create_ringbuffer (src);
if (buffer) { if (G_LIKELY (buffer))
gst_object_set_parent (GST_OBJECT (buffer), GST_OBJECT (src)); gst_object_set_parent (GST_OBJECT_CAST (buffer), GST_OBJECT_CAST (src));
}
return buffer; return buffer;
} }