From e84c83ef982042b4441b517a8f23d8427f2b5494 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Mon, 11 Oct 2021 17:36:41 +0200 Subject: [PATCH] avcodec/binkaudio: Properly flush the decoder The packets delivered to this decoder are often decoded to more than one frame and if the internal buffer packet is not unreferenced, the decoder will still output frames derived from the old packet (from before the flush). Signed-off-by: Andreas Rheinhardt --- libavcodec/binkaudio.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libavcodec/binkaudio.c b/libavcodec/binkaudio.c index 5915ba6ffb..59ecab25c6 100644 --- a/libavcodec/binkaudio.c +++ b/libavcodec/binkaudio.c @@ -337,6 +337,14 @@ fail: return ret; } +static void decode_flush(AVCodecContext *avctx) +{ + BinkAudioContext *const s = avctx->priv_data; + + av_packet_unref(s->pkt); + s->first = 1; +} + const AVCodec ff_binkaudio_rdft_decoder = { .name = "binkaudio_rdft", .long_name = NULL_IF_CONFIG_SMALL("Bink Audio (RDFT)"), @@ -344,6 +352,7 @@ const AVCodec ff_binkaudio_rdft_decoder = { .id = AV_CODEC_ID_BINKAUDIO_RDFT, .priv_data_size = sizeof(BinkAudioContext), .init = decode_init, + .flush = decode_flush, .close = decode_end, .receive_frame = binkaudio_receive_frame, .capabilities = AV_CODEC_CAP_DR1, @@ -357,6 +366,7 @@ const AVCodec ff_binkaudio_dct_decoder = { .id = AV_CODEC_ID_BINKAUDIO_DCT, .priv_data_size = sizeof(BinkAudioContext), .init = decode_init, + .flush = decode_flush, .close = decode_end, .receive_frame = binkaudio_receive_frame, .capabilities = AV_CODEC_CAP_DR1,