From cd256acf03c40581933d7b875e10910515d34fcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 23 Dec 2014 12:24:48 +0100 Subject: [PATCH] audiomixer: If getting a timeout before having caps, just advance our position This can happen if this is a live pipeline and no source produced any buffer and sent no caps until the an output buffer should've been produced according to the latency. --- gst/audiomixer/gstaudiomixer.c | 38 +++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/gst/audiomixer/gstaudiomixer.c b/gst/audiomixer/gstaudiomixer.c index a12a3f1b31..35e6cc0ffb 100644 --- a/gst/audiomixer/gstaudiomixer.c +++ b/gst/audiomixer/gstaudiomixer.c @@ -707,7 +707,11 @@ gst_audiomixer_sink_event (GstAggregator * agg, GstAggregatorPad * aggpad, static void gst_audiomixer_reset (GstAudioMixer * audiomixer) { + GstAggregator *agg = GST_AGGREGATOR (audiomixer); + audiomixer->offset = 0; + agg->segment.position = -1; + gst_caps_replace (&audiomixer->current_caps, NULL); gst_buffer_replace (&audiomixer->current_buffer, NULL); } @@ -1375,9 +1379,32 @@ gst_audiomixer_aggregate (GstAggregator * agg, gboolean timeout) audiomixer = GST_AUDIO_MIXER (agg); - /* this is fatal */ - if (G_UNLIKELY (audiomixer->info.finfo->format == GST_AUDIO_FORMAT_UNKNOWN)) - goto not_negotiated; + /* Update position from the segment start/stop if needed */ + if (agg->segment.position == -1) { + if (agg->segment.rate > 0.0) + agg->segment.position = agg->segment.start; + else + agg->segment.position = agg->segment.stop; + } + + if (G_UNLIKELY (audiomixer->info.finfo->format == GST_AUDIO_FORMAT_UNKNOWN)) { + if (timeout) { + GST_DEBUG_OBJECT (audiomixer, + "Got timeout before receiving any caps, don't output anything"); + + /* Advance position */ + if (agg->segment.rate > 0.0) + agg->segment.position += audiomixer->output_buffer_duration; + else if (agg->segment.position > audiomixer->output_buffer_duration) + agg->segment.position -= audiomixer->output_buffer_duration; + else + agg->segment.position = 0; + + return GST_FLOW_OK; + } else { + goto not_negotiated; + } + } blocksize = gst_util_uint64_scale (audiomixer->output_buffer_duration, @@ -1387,11 +1414,6 @@ gst_audiomixer_aggregate (GstAggregator * agg, gboolean timeout) if (audiomixer->send_caps) { gst_aggregator_set_src_caps (agg, audiomixer->current_caps); - if (agg->segment.rate > 0.0) - agg->segment.position = agg->segment.start; - else - agg->segment.position = agg->segment.stop; - audiomixer->offset = gst_util_uint64_scale (agg->segment.position, GST_AUDIO_INFO_RATE (&audiomixer->info), GST_SECOND);