audiobase{sink,src}: Don't hold the object lock while calling create_ringbuffer() vfunc

The implementation of that vfunc might want to use the object lock for
something too. It's generally not a good idea to keep the object lock while
calling any function implemented elsewhere.

Also the ringbuffer can only be NULL at this point, remove a useless if block.

And in the sink actually hold the object lock while setting the ringbuffer on
the instance. Code accessing this is expected to use the object lock, so do it
here ourselves too.
This commit is contained in:
Sebastian Dröge 2014-12-22 10:45:37 +01:00
parent c1776a9dd3
commit ceb9de6e55
2 changed files with 36 additions and 10 deletions

View file

@ -2187,14 +2187,22 @@ gst_audio_base_sink_change_state (GstElement * element,
GstAudioBaseSink *sink = GST_AUDIO_BASE_SINK (element);
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
if (sink->ringbuffer == NULL) {
case GST_STATE_CHANGE_NULL_TO_READY:{
GstAudioRingBuffer *rb;
gst_audio_clock_reset (GST_AUDIO_CLOCK (sink->provided_clock), 0);
sink->ringbuffer = gst_audio_base_sink_create_ringbuffer (sink);
}
rb = gst_audio_base_sink_create_ringbuffer (sink);
if (rb == NULL)
goto create_failed;
GST_OBJECT_LOCK (sink);
sink->ringbuffer = rb;
GST_OBJECT_UNLOCK (sink);
if (!gst_audio_ring_buffer_open_device (sink->ringbuffer))
goto open_failed;
break;
}
case GST_STATE_CHANGE_READY_TO_PAUSED:
gst_audio_base_sink_reset_sync (sink);
gst_audio_ring_buffer_set_flushing (sink->ringbuffer, FALSE);
@ -2289,6 +2297,12 @@ gst_audio_base_sink_change_state (GstElement * element,
return ret;
/* ERRORS */
create_failed:
{
/* subclass must post a meaningful error message */
GST_DEBUG_OBJECT (sink, "create failed");
return GST_STATE_CHANGE_FAILURE;
}
open_failed:
{
/* subclass must post a meaningful error message */

View file

@ -1124,17 +1124,23 @@ gst_audio_base_src_change_state (GstElement * element,
GstAudioBaseSrc *src = GST_AUDIO_BASE_SRC (element);
switch (transition) {
case GST_STATE_CHANGE_NULL_TO_READY:
case GST_STATE_CHANGE_NULL_TO_READY:{
GstAudioRingBuffer *rb;
GST_DEBUG_OBJECT (src, "NULL->READY");
GST_OBJECT_LOCK (src);
if (src->ringbuffer == NULL) {
gst_audio_clock_reset (GST_AUDIO_CLOCK (src->clock), 0);
src->ringbuffer = gst_audio_base_src_create_ringbuffer (src);
}
rb = gst_audio_base_src_create_ringbuffer (src);
if (rb == NULL)
goto create_failed;
GST_OBJECT_LOCK (src);
src->ringbuffer = rb;
GST_OBJECT_UNLOCK (src);
if (!gst_audio_ring_buffer_open_device (src->ringbuffer))
goto open_failed;
break;
}
case GST_STATE_CHANGE_READY_TO_PAUSED:
GST_DEBUG_OBJECT (src, "READY->PAUSED");
src->next_sample = -1;
@ -1197,6 +1203,12 @@ gst_audio_base_src_change_state (GstElement * element,
return ret;
/* ERRORS */
create_failed:
{
/* subclass must post a meaningful error message */
GST_DEBUG_OBJECT (src, "create failed");
return GST_STATE_CHANGE_FAILURE;
}
open_failed:
{
/* subclass must post a meaningful error message */