[FFmpeg-devel] [PATCH] pthread_frame: don't return stale error codes after flush

Ronald S. Bultje rsbultje at gmail.com
Thu Apr 6 18:38:55 EEST 2017


Hi,

On Thu, Apr 6, 2017 at 11:36 AM, wm4 <nfxjfg at googlemail.com> wrote:

> Consider the following sequence of events:
>
> - open a codec without AV_CODEC_CAP_DELAY
> - decode call fails with an error
> - ff_thread_flush() is called
> - drain packet is sent
>
> Then the last step would make ff_thread_decode_frame() return an error,
> because p->result can still be set to an error value. This is because
> submit_packet returns immediately if AV_CODEC_CAP_DELAY is not set, and
> no worker thread gets the chance to reset p->result, yet its value is
> trusted by ff_thread_decode_frame().
>
> Fix this by clearing the error fields on flush.
> ---
>  libavcodec/pthread_frame.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
> index 9a6b83ac45..7586f00bec 100644
> --- a/libavcodec/pthread_frame.c
> +++ b/libavcodec/pthread_frame.c
> @@ -859,6 +859,7 @@ void ff_thread_flush(AVCodecContext *avctx)
>          // Make sure decode flush calls with size=0 won't return old
> frames
>          p->got_frame = 0;
>          av_frame_unref(p->frame);
> +        p->result = 0;
>
>          release_delayed_buffers(p);
>
> --
> 2.11.0


Nice catch - I think that looks good.

Ronald


More information about the ffmpeg-devel mailing list