[vlc-devel] [PATCH 3/3] decoder: delay controls when output is not started

Thomas Guillem thomas at gllm.fr
Thu Dec 17 09:52:05 UTC 2020


This fixes rate and delay ignored if the command is sent before the
output is started.

The "continue" is removed from the loop in order to avoid
DecoderThread_Change*() busy loop.

We don't need to delay the pause control since an output can't start
paused. Indeed, if paused, the decoder thread won't process any inputs
and the output won't be started.
---
 src/input/decoder.c | 37 +++++++++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 8 deletions(-)

diff --git a/src/input/decoder.c b/src/input/decoder.c
index 0b90d3e5ae6..ecf8face777 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -1535,21 +1535,29 @@ static void DecoderThread_ChangePause( vlc_input_decoder_t *p_owner, bool paused
     }
 }
 
-static void DecoderThread_ChangeRate( vlc_input_decoder_t *p_owner, float rate )
+static int DecoderThread_ChangeRate( vlc_input_decoder_t *p_owner, float rate )
 {
     decoder_t *p_dec = &p_owner->dec;
 
+    int ret = VLC_EGENERIC;
+
     msg_Dbg( p_dec, "changing rate: %f", rate );
     vlc_mutex_lock( &p_owner->lock );
     switch( p_dec->fmt_out.i_cat )
     {
         case VIDEO_ES:
             if( p_owner->p_vout != NULL && p_owner->vout_started )
+            {
                 vout_ChangeRate( p_owner->p_vout, rate );
+                ret = VLC_SUCCESS;
+            }
             break;
         case AUDIO_ES:
             if( p_owner->p_aout != NULL )
+            {
                 aout_DecChangeRate( p_owner->p_aout, rate );
+                ret = VLC_SUCCESS;
+            }
             break;
         case SPU_ES:
             if( p_owner->p_vout != NULL )
@@ -1557,6 +1565,7 @@ static void DecoderThread_ChangeRate( vlc_input_decoder_t *p_owner, float rate )
                 assert(p_owner->i_spu_channel != VOUT_SPU_CHANNEL_INVALID);
                 vout_ChangeSpuRate(p_owner->p_vout, p_owner->i_spu_channel,
                                    rate );
+                ret = VLC_SUCCESS;
             }
             break;
         default:
@@ -1564,26 +1573,35 @@ static void DecoderThread_ChangeRate( vlc_input_decoder_t *p_owner, float rate )
     }
     p_owner->output_rate = rate;
     vlc_mutex_unlock( &p_owner->lock );
+
+    return ret;
 }
 
-static void DecoderThread_ChangeDelay( vlc_input_decoder_t *p_owner, vlc_tick_t delay )
+static int DecoderThread_ChangeDelay( vlc_input_decoder_t *p_owner, vlc_tick_t delay )
 {
     decoder_t *p_dec = &p_owner->dec;
 
     msg_Dbg( p_dec, "changing delay: %"PRId64, delay );
 
+    int ret = VLC_EGENERIC;
     switch( p_dec->fmt_out.i_cat )
     {
         case VIDEO_ES:
             vlc_mutex_lock( &p_owner->lock );
             if( p_owner->p_vout != NULL && p_owner->vout_started )
+            {
                 vout_ChangeDelay( p_owner->p_vout, delay );
+                ret = VLC_SUCCESS;
+            }
             vlc_mutex_unlock( &p_owner->lock );
             break;
         case AUDIO_ES:
             vlc_mutex_lock( &p_owner->lock );
             if( p_owner->p_aout != NULL )
+            {
                 aout_DecChangeDelay( p_owner->p_aout, delay );
+                ret = VLC_SUCCESS;
+            }
             vlc_mutex_unlock( &p_owner->lock );
             break;
         case SPU_ES:
@@ -1593,12 +1611,15 @@ static void DecoderThread_ChangeDelay( vlc_input_decoder_t *p_owner, vlc_tick_t
                 assert(p_owner->i_spu_channel != VOUT_SPU_CHANNEL_INVALID);
                 vout_ChangeSpuDelay(p_owner->p_vout, p_owner->i_spu_channel,
                                     delay);
+                ret = VLC_SUCCESS;
             }
             vlc_mutex_unlock( &p_owner->lock );
             break;
         default:
             vlc_assert_unreachable();
     }
+
+    return ret;
 }
 
 /**
@@ -1662,24 +1683,24 @@ static void *DecoderThread( void *p_data )
 
         if( rate != p_owner->request_rate )
         {
-            rate = p_owner->request_rate;
+            float request_rate = p_owner->request_rate;
             vlc_fifo_Unlock( p_owner->p_fifo );
 
-            DecoderThread_ChangeRate( p_owner, rate );
+            if( DecoderThread_ChangeRate( p_owner, request_rate ) == VLC_SUCCESS)
+                rate = request_rate;
 
             vlc_fifo_Lock( p_owner->p_fifo );
-            continue;
         }
 
         if( delay != p_owner->delay )
         {
-            delay = p_owner->delay;
+            float request_delay = p_owner->delay;
             vlc_fifo_Unlock( p_owner->p_fifo );
 
-            DecoderThread_ChangeDelay( p_owner, delay );
+            if( DecoderThread_ChangeDelay( p_owner, request_delay ) == VLC_SUCCESS )
+                delay = request_delay;
 
             vlc_fifo_Lock( p_owner->p_fifo );
-            continue;
         }
 
         if( p_owner->paused && p_owner->frames_countdown == 0 )
-- 
2.29.2



More information about the vlc-devel mailing list