From b296c96169bb5f5f2f09ea336b757e4547738700 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 4 Aug 2010 15:18:37 +0200 Subject: [PATCH] baseaudiosink/baseaudiosrc: Post CLOCK-LOST/CLOCK-PROVIDE when going to/from READY Otherwise the clocks are redistributed every time the pipeline goes to PAUSED, which is quite expensive. --- gst-libs/gst/audio/gstbaseaudiosink.c | 38 +++++++++++++++++------------------ gst-libs/gst/audio/gstbaseaudiosrc.c | 20 +++++++++--------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/gst-libs/gst/audio/gstbaseaudiosink.c b/gst-libs/gst/audio/gstbaseaudiosink.c index 76efba9..4b40a5e 100644 --- a/gst-libs/gst/audio/gstbaseaudiosink.c +++ b/gst-libs/gst/audio/gstbaseaudiosink.c @@ -1835,6 +1835,16 @@ gst_base_audio_sink_change_state (GstElement * element, sink->priv->eos_rendering = 0; gst_ring_buffer_set_flushing (sink->ringbuffer, FALSE); gst_ring_buffer_may_start (sink->ringbuffer, FALSE); + + /* Only post clock-provide messages if this is the clock that + * we've created. If the subclass has overriden it the subclass + * should post this messages whenever necessary */ + if (sink->provided_clock && GST_IS_AUDIO_CLOCK (sink->provided_clock) && + GST_AUDIO_CLOCK_CAST (sink->provided_clock)->func == + (GstAudioClockGetTimeFunc) gst_base_audio_sink_get_time) + gst_element_post_message (element, + gst_message_new_clock_provide (GST_OBJECT_CAST (element), + sink->provided_clock, TRUE)); break; case GST_STATE_CHANGE_PAUSED_TO_PLAYING: GST_OBJECT_LOCK (sink); @@ -1849,18 +1859,17 @@ gst_base_audio_sink_change_state (GstElement * element, /* sync rendering on eos needs running clock */ gst_ring_buffer_start (sink->ringbuffer); } - - /* Only post clock-provide messages if this is the clock that - * we've created. If the subclass has overriden it the subclass - * should post this messages whenever necessary */ - if (sink->provided_clock && GST_IS_AUDIO_CLOCK (sink->provided_clock) && - GST_AUDIO_CLOCK_CAST (sink->provided_clock)->func == - (GstAudioClockGetTimeFunc) gst_base_audio_sink_get_time) - gst_element_post_message (element, - gst_message_new_clock_provide (GST_OBJECT_CAST (element), - sink->provided_clock, TRUE)); break; case GST_STATE_CHANGE_PLAYING_TO_PAUSED: + /* ringbuffer cannot start anymore */ + gst_ring_buffer_may_start (sink->ringbuffer, FALSE); + gst_ring_buffer_pause (sink->ringbuffer); + + GST_OBJECT_LOCK (sink); + sink->priv->sync_latency = FALSE; + GST_OBJECT_UNLOCK (sink); + break; + case GST_STATE_CHANGE_PAUSED_TO_READY: /* Only post clock-lost messages if this is the clock that * we've created. If the subclass has overriden it the subclass * should post this messages whenever necessary */ @@ -1871,15 +1880,6 @@ gst_base_audio_sink_change_state (GstElement * element, gst_message_new_clock_lost (GST_OBJECT_CAST (element), sink->provided_clock)); - /* ringbuffer cannot start anymore */ - gst_ring_buffer_may_start (sink->ringbuffer, FALSE); - gst_ring_buffer_pause (sink->ringbuffer); - - GST_OBJECT_LOCK (sink); - sink->priv->sync_latency = FALSE; - GST_OBJECT_UNLOCK (sink); - break; - case GST_STATE_CHANGE_PAUSED_TO_READY: /* make sure we unblock before calling the parent state change * so it can grab the STREAM_LOCK */ gst_ring_buffer_set_flushing (sink->ringbuffer, TRUE); diff --git a/gst-libs/gst/audio/gstbaseaudiosrc.c b/gst-libs/gst/audio/gstbaseaudiosrc.c index 468402c..b870ff4 100644 --- a/gst-libs/gst/audio/gstbaseaudiosrc.c +++ b/gst-libs/gst/audio/gstbaseaudiosrc.c @@ -1076,11 +1076,6 @@ gst_base_audio_src_change_state (GstElement * element, src->next_sample = -1; gst_ring_buffer_set_flushing (src->ringbuffer, FALSE); gst_ring_buffer_may_start (src->ringbuffer, FALSE); - break; - case GST_STATE_CHANGE_PAUSED_TO_PLAYING: - GST_DEBUG_OBJECT (src, "PAUSED->PLAYING"); - gst_ring_buffer_may_start (src->ringbuffer, TRUE); - /* Only post clock-provide messages if this is the clock that * we've created. If the subclass has overriden it the subclass * should post this messages whenever necessary */ @@ -1091,8 +1086,17 @@ gst_base_audio_src_change_state (GstElement * element, gst_message_new_clock_provide (GST_OBJECT_CAST (element), src->clock, TRUE)); break; + case GST_STATE_CHANGE_PAUSED_TO_PLAYING: + GST_DEBUG_OBJECT (src, "PAUSED->PLAYING"); + gst_ring_buffer_may_start (src->ringbuffer, TRUE); + break; case GST_STATE_CHANGE_PLAYING_TO_PAUSED: GST_DEBUG_OBJECT (src, "PLAYING->PAUSED"); + gst_ring_buffer_may_start (src->ringbuffer, FALSE); + gst_ring_buffer_pause (src->ringbuffer); + break; + case GST_STATE_CHANGE_PAUSED_TO_READY: + GST_DEBUG_OBJECT (src, "PAUSED->READY"); /* Only post clock-lost messages if this is the clock that * we've created. If the subclass has overriden it the subclass * should post this messages whenever necessary */ @@ -1101,12 +1105,6 @@ gst_base_audio_src_change_state (GstElement * element, (GstAudioClockGetTimeFunc) gst_base_audio_src_get_time) gst_element_post_message (element, gst_message_new_clock_lost (GST_OBJECT_CAST (element), src->clock)); - - gst_ring_buffer_may_start (src->ringbuffer, FALSE); - gst_ring_buffer_pause (src->ringbuffer); - break; - case GST_STATE_CHANGE_PAUSED_TO_READY: - GST_DEBUG_OBJECT (src, "PAUSED->READY"); gst_ring_buffer_set_flushing (src->ringbuffer, TRUE); break; default: -- 2.7.4