[vlc-devel] [PATCH 06/17] decoder: reload module if aout changed or failed

Thomas Guillem thomas at gllm.fr
Wed Jul 27 17:27:22 CEST 2016


Mainly in order to be able to change from S/PDIF to PCM since there is no S/PDIF
converter anymore. This is also possible to change from PCM to S/PDIF.

We can't reload directly from DecoderPlayAudio since this function may be
called from a running asynchronous decoder.
---
 src/input/decoder.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/input/decoder.c b/src/input/decoder.c
index 21f822a..eafc065 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -215,6 +215,23 @@ static int ReloadDecoder( decoder_t *p_dec, bool b_packetizer,
 
     /* Restart the decoder module */
     UnloadDecoder( p_dec );
+
+    if( reload == RELOAD_DECODER_AOUT )
+    {
+        decoder_owner_sys_t *p_owner = p_dec->p_owner;
+        assert( p_owner->fmt.i_cat == AUDIO_ES );
+        audio_output_t *p_aout = p_owner->p_aout;
+
+        vlc_mutex_lock( &p_owner->lock );
+        p_owner->p_aout = NULL;
+        vlc_mutex_unlock( &p_owner->lock );
+        if( p_aout )
+        {
+            aout_DecDelete( p_aout );
+            input_resource_PutAout( p_owner->p_resource, p_aout );
+        }
+    }
+
     if( LoadDecoder( p_dec, b_packetizer, &fmt_in ) )
     {
         p_dec->b_error = true;
@@ -1146,7 +1163,19 @@ static int DecoderPlayAudio( decoder_t *p_dec, block_t *p_audio,
      && i_rate <= INPUT_RATE_DEFAULT*AOUT_MAX_INPUT_RATE
      && !DecoderTimedWait( p_dec, p_audio->i_pts - AOUT_MAX_PREPARE_TIME ) )
     {
-        aout_DecPlay( p_aout, p_audio, i_rate );
+        int status = aout_DecPlay( p_aout, p_audio, i_rate );
+        if( status == AOUT_DEC_CHANGED )
+        {
+            /* Only reload the decoder */
+            decoder_RequestReload( p_dec );
+        }
+        else if( status == AOUT_DEC_FAILED )
+        {
+            /* If we reload because the aout failed, we should release it. That
+             * way, a next call to aout_update_format() won't re-use the
+             * previous (failing) aout but will try to create a new one. */
+            atomic_store( &p_owner->reload, RELOAD_DECODER_AOUT );
+        }
     }
     else
     {
-- 
2.8.1



More information about the vlc-devel mailing list