[vlc-devel] [PATCH] decoder: add an assert to make sure decoders serialize calls in a single thread

Thomas Guillem thomas at gllm.fr
Wed Sep 4 12:41:19 CEST 2019


This will fail with avcodec. Nothing prevent the output callback to be called from many threads inside a plugin. In that case, the plugin should handle the thread safety. That is what avcodec is doing.

On Wed, Sep 4, 2019, at 12:24, Steve Lhomme wrote:
> ---
>  src/input/decoder.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
> 
> diff --git a/src/input/decoder.c b/src/input/decoder.c
> index aa7d45dde6c..5f37d5f8e5d 100644
> --- a/src/input/decoder.c
> +++ b/src/input/decoder.c
> @@ -105,6 +105,10 @@ struct decoder_owner
>      audio_output_t *p_aout;
>  
>      vout_thread_t   *p_vout;
> +#ifndef NDEBUG
> +    unsigned long  aout_thread_id;
> +    unsigned long  vout_thread_id;
> +#endif
>  
>      /* -- Theses variables need locking on read *and* write -- */
>      /* Preroll */
> @@ -215,6 +219,10 @@ static int ReloadDecoder( struct decoder_owner 
> *p_owner, bool b_packetizer,
>  
>      /* Restart the decoder module */
>      decoder_Clean( p_dec );
> +#ifndef NDEBUG
> +    p_owner->aout_thread_id = -1;
> +    p_owner->vout_thread_id = -1;
> +#endif
>      p_owner->error = false;
>  
>      if( reload == RELOAD_DECODER_AOUT )
> @@ -234,6 +242,10 @@ static int ReloadDecoder( struct decoder_owner 
> *p_owner, bool b_packetizer,
>  
>      if( LoadDecoder( p_dec, b_packetizer, &fmt_in ) )
>      {
> +#ifndef NDEBUG
> +        p_owner->aout_thread_id = -1;
> +        p_owner->vout_thread_id = -1;
> +#endif
>          p_owner->error = true;
>          es_format_Clean( &fmt_in );
>          return VLC_EGENERIC;
> @@ -296,6 +308,13 @@ static int aout_update_format( decoder_t *p_dec )
>  {
>      struct decoder_owner *p_owner = dec_get_owner( p_dec );
>  
> +#ifndef NDEBUG
> +    if (p_owner->aout_thread_id == -1)
> +        p_owner->aout_thread_id = vlc_thread_id();
> +    else
> +        assert(p_owner->aout_thread_id == vlc_thread_id());
> +#endif
> +
>      if( p_owner->p_aout &&
>         ( !AOUT_FMTS_IDENTICAL(&p_dec->fmt_out.audio, &p_owner->fmt.audio) ||
>           p_dec->fmt_out.i_codec != p_dec->fmt_out.audio.i_format ||
> @@ -390,6 +409,13 @@ static int vout_update_format( decoder_t *p_dec )
>      bool need_vout = false;
>      bool need_format_update = false;
>  
> +#ifndef NDEBUG
> +    if (p_owner->vout_thread_id == -1)
> +        p_owner->vout_thread_id = vlc_thread_id();
> +    else
> +        assert(p_owner->vout_thread_id == vlc_thread_id());
> +#endif
> +
>      if( p_owner->p_vout == NULL )
>      {
>          msg_Dbg(p_dec, "vout: none found");
> @@ -1760,6 +1786,10 @@ static struct decoder_owner * CreateDecoder( 
> vlc_object_t *p_parent,
>      p_owner->cbs_userdata = cbs_userdata;
>      p_owner->p_aout = NULL;
>      p_owner->p_vout = NULL;
> +#ifndef NDEBUG
> +    p_owner->aout_thread_id = -1;
> +    p_owner->vout_thread_id = -1;
> +#endif
>      p_owner->i_spu_channel = VOUT_SPU_CHANNEL_INVALID;
>      p_owner->i_spu_order = 0;
>      p_owner->p_sout = p_sout;
> @@ -1901,6 +1931,11 @@ static void DeleteDecoder( decoder_t * p_dec )
>      const enum es_format_category_e i_cat =p_dec->fmt_in.i_cat;
>      decoder_Clean( p_dec );
>  
> +#ifndef NDEBUG
> +    p_owner->vout_thread_id = -1;
> +    p_owner->aout_thread_id = -1;
> +#endif
> +
>      /* Free all packets still in the decoder fifo. */
>      block_FifoRelease( p_owner->p_fifo );
>  
> -- 
> 2.17.1
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list