From: Paul B Mahol <onemda@gmail.com>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: Jyrki Vesterinen <jyrkive@nekonyansoft.com>
Subject: Re: [FFmpeg-devel] [PATCH] avcodec: Vorbis decode: don't use a flag to determine if frames have been output
Date: Thu, 8 Sep 2022 14:11:50 +0200
Message-ID: <CAPYw7P6rSv+6eB32nUsjsxrS1O9z92u_=THvJQbpZovs-Z_JDA@mail.gmail.com> (raw)
In-Reply-To: <20220908113632.1056-2-jyrkive@nekonyansoft.com>
On 9/8/22, jyrkive@nekonyansoft.com <jyrkive@nekonyansoft.com> wrote:
> From: Jyrki Vesterinen <jyrkive@nekonyansoft.com>
>
> 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.
> ---
> libavcodec/vorbisdec.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c
> index 4d03947c49..38a5367be3 100644
> --- a/libavcodec/vorbisdec.c
> +++ b/libavcodec/vorbisdec.c
> @@ -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 = {
> --
> 2.37.2.windows.2
>
LGTM
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-09-08 12:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-08 8:25 jyrkive
2022-09-08 8:40 ` Paul B Mahol
2022-09-08 11:36 ` jyrkive
2022-09-08 11:36 ` jyrkive
2022-09-08 12:11 ` Paul B Mahol [this message]
2022-10-17 8:15 ` Hendrik Leppkes
2022-10-17 8:18 ` Paul B Mahol
2022-10-17 8:23 ` Hendrik Leppkes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAPYw7P6rSv+6eB32nUsjsxrS1O9z92u_=THvJQbpZovs-Z_JDA@mail.gmail.com' \
--to=onemda@gmail.com \
--cc=ffmpeg-devel@ffmpeg.org \
--cc=jyrkive@nekonyansoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git