1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00

avcodec/vorbisdec: don't use a flag to determine if frames have been output

If a developer using FFmpeg libraries seeks into an earlier position and calls
avcodec_flush_buffers() afterwards as recommended, the Vorbis decoder will drop
the next frame, since buffer flushing clears the first_frame flag. As a result,
the audio samples the calling code receives may be ahead of the requested seek
position, which is unacceptable in some use cases such as playing a looping
sound effect.

This commit records the presentation timestamp of the first frame and
determines after that if the new frame is the first frame (possible after
seeking to the start) by comparing its pts to the stored pts.
This commit is contained in:
Jyrki Vesterinen 2022-09-08 14:36:32 +03:00 committed by Paul B Mahol
parent a5ce44f301
commit 8fc2dedfe6

View File

@ -131,6 +131,7 @@ typedef struct vorbis_context_s {
FFTContext mdct[2];
uint8_t first_frame;
int64_t initial_pts;
uint32_t version;
uint8_t audio_channels;
uint32_t audio_samplerate;
@ -1847,6 +1848,10 @@ static int vorbis_decode_frame(AVCodecContext *avctx, AVFrame *frame,
if (!vc->first_frame) {
vc->first_frame = 1;
vc->initial_pts = frame->pts;
}
if (frame->pts == vc->initial_pts) {
*got_frame_ptr = 0;
av_frame_unref(frame);
return buf_size;
@ -1881,7 +1886,6 @@ static av_cold void vorbis_decode_flush(AVCodecContext *avctx)
sizeof(*vc->saved));
}
vc->previous_window = -1;
vc->first_frame = 0;
}
const FFCodec ff_vorbis_decoder = {