From 228f13c7399f21bb5832bd5f352a2a27bceb449b Mon Sep 17 00:00:00 2001 From: Courville Software Date: Sat, 24 Aug 2024 23:20:44 +0200 Subject: [PATCH] codec_ffmpeg_audio: closer flush to documentation --- Source/codec_ffmpeg_audio.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Source/codec_ffmpeg_audio.c b/Source/codec_ffmpeg_audio.c index 8b45b62..2ba16bc 100644 --- a/Source/codec_ffmpeg_audio.c +++ b/Source/codec_ffmpeg_audio.c @@ -871,6 +871,26 @@ static int ffmpeg_audio_codec_decode( AUDIO_PROPERTIES *audio, UCHAR *data, int static int ffmpeg_audio_codec_flush( AUDIO_PROPERTIES *audio ) { PRIV *p = (PRIV*)audio->priv; + int ret; + + // enter draining mode by sending a NULL packet + ret = avcodec_send_packet(p->actx, NULL); + if (ret < 0) { +serprintf("Error sending NULL packet for flushing: %s\n", av_err2str(ret)); + } + + // receive all remaining frames + while (ret >= 0) { + ret = avcodec_receive_frame(p->actx, p->aframe); + if (ret == AVERROR_EOF) { + // end of stream, stop draining + break; + } else if (ret < 0) { +serprintf("Error receiving frame during flushing: %s\n", av_err2str(ret)); + break; + } + } + DBGCA serprintf("ffad flush\r\n" ); avcodec_flush_buffers( p->actx );