Skip to content

Commit

Permalink
codec_ffmpeg_audio: closer flush to documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
courville committed Aug 24, 2024
1 parent 73735f8 commit 228f13c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Source/codec_ffmpeg_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 228f13c

Please sign in to comment.