From 31f0f163bd652a8d171b73ec545e7f9138c5bea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 9 Oct 2012 10:56:30 +0200 Subject: [PATCH] Try to handle format changes more gracefully And make stop() faster and more robust --- sys/androidmedia/gstamcaudiodec.c | 13 +++++++++++-- sys/androidmedia/gstamcvideodec.c | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/sys/androidmedia/gstamcaudiodec.c b/sys/androidmedia/gstamcaudiodec.c index 2725e0ff2e..31a8bf5f22 100644 --- a/sys/androidmedia/gstamcaudiodec.c +++ b/sys/androidmedia/gstamcaudiodec.c @@ -772,7 +772,7 @@ gst_amc_audio_dec_stop (GstAudioDecoder * decoder) self = GST_AMC_AUDIO_DEC (decoder); GST_DEBUG_OBJECT (self, "Stopping decoder"); - gst_pad_stop_task (GST_AUDIO_DECODER_SRC_PAD (decoder)); + self->flushing = TRUE; if (self->started) { gst_amc_codec_flush (self->codec); gst_amc_codec_stop (self->codec); @@ -784,6 +784,7 @@ gst_amc_audio_dec_stop (GstAudioDecoder * decoder) gst_amc_codec_free_buffers (self->output_buffers, self->n_output_buffers); self->output_buffers = NULL; } + gst_pad_stop_task (GST_AUDIO_DECODER_SRC_PAD (decoder)); g_free (self->positions); self->positions = NULL; @@ -799,7 +800,6 @@ gst_amc_audio_dec_stop (GstAudioDecoder * decoder) g_cond_broadcast (self->drain_cond); g_mutex_unlock (self->drain_lock); gst_buffer_replace (&self->codec_data, NULL); - self->flushing = TRUE; GST_DEBUG_OBJECT (self, "Stopped decoder"); return TRUE; } @@ -845,6 +845,15 @@ gst_amc_audio_dec_set_format (GstAudioDecoder * decoder, GstCaps * caps) GST_AUDIO_DECODER_STREAM_UNLOCK (self); gst_amc_audio_dec_stop (GST_AUDIO_DECODER (self)); GST_AUDIO_DECODER_STREAM_LOCK (self); + gst_amc_audio_dec_close (GST_AUDIO_DECODER (self)); + if (!gst_amc_audio_dec_open (GST_AUDIO_DECODER (self))) { + GST_ERROR_OBJECT (self, "Failed to open codec again"); + return FALSE; + } + + if (!gst_amc_audio_dec_start (GST_AUDIO_DECODER (self))) { + GST_ERROR_OBJECT (self, "Failed to start codec again"); + } } /* srcpad task is not running at this point */ diff --git a/sys/androidmedia/gstamcvideodec.c b/sys/androidmedia/gstamcvideodec.c index 4e6a33ca3f..dc3d7b2db6 100644 --- a/sys/androidmedia/gstamcvideodec.c +++ b/sys/androidmedia/gstamcvideodec.c @@ -1202,7 +1202,7 @@ gst_amc_video_dec_stop (GstVideoDecoder * decoder) self = GST_AMC_VIDEO_DEC (decoder); GST_DEBUG_OBJECT (self, "Stopping decoder"); - gst_pad_stop_task (GST_VIDEO_DECODER_SRC_PAD (decoder)); + self->flushing = TRUE; if (self->started) { gst_amc_codec_flush (self->codec); gst_amc_codec_stop (self->codec); @@ -1214,6 +1214,7 @@ gst_amc_video_dec_stop (GstVideoDecoder * decoder) gst_amc_codec_free_buffers (self->output_buffers, self->n_output_buffers); self->output_buffers = NULL; } + gst_pad_stop_task (GST_VIDEO_DECODER_SRC_PAD (decoder)); self->downstream_flow_ret = GST_FLOW_WRONG_STATE; self->eos = FALSE; @@ -1222,7 +1223,6 @@ gst_amc_video_dec_stop (GstVideoDecoder * decoder) g_cond_broadcast (self->drain_cond); g_mutex_unlock (self->drain_lock); gst_buffer_replace (&self->codec_data, NULL); - self->flushing = TRUE; GST_DEBUG_OBJECT (self, "Stopped decoder"); return TRUE; } @@ -1268,6 +1268,15 @@ gst_amc_video_dec_set_format (GstVideoDecoder * decoder, GST_VIDEO_DECODER_STREAM_UNLOCK (self); gst_amc_video_dec_stop (GST_VIDEO_DECODER (self)); GST_VIDEO_DECODER_STREAM_LOCK (self); + gst_amc_video_dec_close (GST_VIDEO_DECODER (self)); + if (!gst_amc_video_dec_open (GST_VIDEO_DECODER (self))) { + GST_ERROR_OBJECT (self, "Failed to open codec again"); + return FALSE; + } + + if (!gst_amc_video_dec_start (GST_VIDEO_DECODER (self))) { + GST_ERROR_OBJECT (self, "Failed to start codec again"); + } } /* srcpad task is not running at this point */