[vlc-devel] [PATCH] decoder: drop audio block and picture during flushing

Zhao Zhili quinkblack at foxmail.com
Tue Jan 2 11:00:22 CET 2018



On 2018年01月02日 17:43, Zhao Zhili wrote:
> If input_DecoderStartWait() is executed before DecoderThread() do flushing,
> an old picture can be treated as the first picture.
> ---
>   src/input/decoder.c | 20 ++++++++++++++++++++
>   1 file changed, 20 insertions(+)
>
> diff --git a/src/input/decoder.c b/src/input/decoder.c
> index b94d6da..7a0106a 100644
> --- a/src/input/decoder.c
> +++ b/src/input/decoder.c
> @@ -987,8 +987,18 @@ static int DecoderPlayVideo( decoder_t *p_dec, picture_t *p_picture,
>   {
>       decoder_owner_sys_t *p_owner = p_dec->p_owner;
>       vout_thread_t  *p_vout = p_owner->p_vout;
> +    bool flushing;
>       bool prerolled;
>   
> +    vlc_fifo_Lock( p_owner->p_fifo );
> +    flushing = p_owner->flushing;
> +    vlc_fifo_Unlock( p_owner->p_fifo );
> +    if( flushing )
> +    {
> +        picture_Release( p_picture );
> +        return -1;
> +    }
> +
>       vlc_mutex_lock( &p_owner->lock );
>       if( p_owner->i_preroll_end > p_picture->date )
>       {
> @@ -1127,10 +1137,20 @@ static int DecoderPlayAudio( decoder_t *p_dec, block_t *p_audio,
>                                unsigned *restrict pi_lost_sum )
>   {
>       decoder_owner_sys_t *p_owner = p_dec->p_owner;
> +    bool flushing;
>       bool prerolled;
>   
>       assert( p_audio != NULL );
>   
> +    vlc_fifo_Lock( p_owner->p_fifo );
> +    flushing = p_owner->flushing;
> +    vlc_fifo_Unlock( p_owner->p_fifo );
> +    if( flushing )
> +    {
> +        block_Release( p_audio );
> +        return -1;
> +    }
> +
>       vlc_mutex_lock( &p_owner->lock );
>       if( p_owner->i_preroll_end > p_audio->i_pts )
>       {

It's easy to reproduce. Here is my patch for debug (make sure set 
file-caching
large enough to prevent the code path of "buffer deadlock prevented").

diff --git a/src/input/decoder.c b/src/input/decoder.c
index b94d6da..c579045 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -1022,6 +1022,7 @@ static int DecoderPlayVideo( decoder_t *p_dec, 
picture_t *p_picture,
      {
          p_owner->b_has_data = true;
          vlc_cond_signal( &p_owner->wait_acknowledge );
+        msg_Warn( p_dec, "signal wait_acknowledge, picture date %" 
PRId64, p_picture->date );
      }
      bool b_first_after_wait = p_owner->b_waiting && p_owner->b_has_data;

@@ -1030,10 +1031,11 @@ static int DecoderPlayVideo( decoder_t *p_dec, 
picture_t *p_picture,
      if( p_owner->b_waiting )
      {
          assert( p_owner->b_first );
-        msg_Dbg( p_dec, "Received first picture" );
+        msg_Warn( p_dec, "Received first picture %" PRId64, 
p_picture->date );
          p_owner->b_first = false;
          p_picture->b_force = true;
      }
+    msg_Warn( p_dec, "picture date %" PRId64, p_picture->date );

      const bool b_dated = p_picture->date > VLC_TS_INVALID;
      int i_rate = INPUT_RATE_DEFAULT;
@@ -1557,6 +1559,8 @@ static void *DecoderThread( void *p_data )
               * harmless). */
              p_owner->flushing = false;

+            if( p_owner->p_vout != NULL )
+                msg_Warn( p_dec, "now flushing" );
              continue;
          }

The log before and after seek:
...
main decoder warning: picture date 3240001
main decoder warning: picture date 3280001
main decoder warning: picture date 3320001
main decoder warning: picture date 3360001
main decoder warning: picture date 3400001
main decoder warning: picture date 3440001
main decoder warning: picture date 3480001
main decoder warning: picture date 3520001
main decoder debug: discarded audio buffer
main decoder debug: end of audio preroll
main decoder warning: Received first picture 3560001
main decoder warning: picture date 3560001
main decoder warning: now flushing
main decoder warning: signal wait_acknowledge, picture date 2248640001
main decoder warning: picture date 2248640001
main decoder warning: picture date 2248680001
main decoder warning: picture date 2248720001
main decoder warning: picture date 2248760001
main decoder warning: picture date 2248800001
...




More information about the vlc-devel mailing list