* [FFmpeg-devel] [PATCH 1/2] decode: add ff_decode_skip_samples function @ 2023-12-04 7:51 Lynne [not found] ` <NknnrNO--3-9@lynne.ee-Nknnuzj----9> 0 siblings, 1 reply; 3+ messages in thread From: Lynne @ 2023-12-04 7:51 UTC (permalink / raw) To: Ffmpeg Devel [-- Attachment #1: Type: text/plain, Size: 300 bytes --] This is a convenience function, which is required to be called by decoders needing to skip samples every time. It automatically creates and increments side data. This function is a simplified version of an earlier patch. It is only able to add additional delay, rather than insert or override any. [-- Attachment #2: 0001-decode-add-ff_decode_skip_samples-function.patch --] [-- Type: text/x-diff, Size: 2132 bytes --] From 3045ac286538641076ce4547cda677c3b159877f Mon Sep 17 00:00:00 2001 From: Lynne <dev@lynne.ee> Date: Mon, 30 Oct 2023 05:38:17 +0100 Subject: [PATCH 1/2] decode: add ff_decode_skip_samples function This is a convenience function, which is required to be called by decoders needing to skip samples every time. It automatically creates and increments side data. This function is a simplified version of an earlier patch. It is only able to add additional delay, rather than insert or override any. --- libavcodec/decode.c | 17 +++++++++++++++++ libavcodec/decode.h | 8 ++++++++ 2 files changed, 25 insertions(+) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 2cfb3fcf97..450d63d947 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -299,6 +299,23 @@ static int64_t guess_correct_pts(AVCodecContext *ctx, return pts; } +int ff_decode_skip_samples(AVCodecContext *avctx, AVFrame *frame, uint32_t skip) +{ + uint32_t val = 0; + AVFrameSideData *side = av_frame_get_side_data(frame, AV_FRAME_DATA_SKIP_SAMPLES); + if (!side) { + side = av_frame_new_side_data(frame, AV_FRAME_DATA_SKIP_SAMPLES, 10); + if (!side) + return AVERROR(ENOMEM); + } + + val += AV_RL32(side->data); + val += skip; + AV_WL32(side->data, val); + + return 0; +} + static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples) { AVCodecInternal *avci = avctx->internal; diff --git a/libavcodec/decode.h b/libavcodec/decode.h index daf1a67444..c83476208c 100644 --- a/libavcodec/decode.h +++ b/libavcodec/decode.h @@ -155,4 +155,12 @@ int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_pr const AVPacketSideData *ff_get_coded_side_data(const AVCodecContext *avctx, enum AVPacketSideDataType type); +/** + * Skip samples in an AVFrame. + * + * @param skip amount of samples to skip unconditionally + */ +int ff_decode_skip_samples(AVCodecContext *avctx, AVFrame *frame, + uint32_t skip); + #endif /* AVCODEC_DECODE_H */ -- 2.43.0 [-- Attachment #3: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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". ^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <NknnrNO--3-9@lynne.ee-Nknnuzj----9>]
* [FFmpeg-devel] [PATCH 2/2] aacdec: fix single-sample delay for SBR streams [not found] ` <NknnrNO--3-9@lynne.ee-Nknnuzj----9> @ 2023-12-04 7:52 ` Lynne 2023-12-05 1:47 ` Michael Niedermayer 0 siblings, 1 reply; 3+ messages in thread From: Lynne @ 2023-12-04 7:52 UTC (permalink / raw) To: FFmpeg development discussions and patches [-- Attachment #1: Type: text/plain, Size: 268 bytes --] Our SBR implementation introduces a single sample of latency into the output, which is currently never skipped. This delay is separate from any container skip value and always present, as it is from an additional part of the decoding process. Fixes Trac issue #9667 [-- Attachment #2: 0002-aacdec-fix-single-sample-delay-for-SBR-streams.patch --] [-- Type: text/x-diff, Size: 2778 bytes --] From 5b9d971b108677d54bc3aac317669007462dbcc9 Mon Sep 17 00:00:00 2001 From: Lynne <dev@lynne.ee> Date: Mon, 30 Oct 2023 05:40:22 +0100 Subject: [PATCH 2/2] aacdec: fix single-sample delay for SBR streams Our SBR implementation introduces a single sample of latency into the output, which is currently never skipped. This delay is separate from any container skip value and always present, as it is from an additional part of the decoding process. Fixes Trac issue #9667 --- libavcodec/aac.h | 1 + libavcodec/aacdec_template.c | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/libavcodec/aac.h b/libavcodec/aac.h index 285d3b7482..06ae2222cf 100644 --- a/libavcodec/aac.h +++ b/libavcodec/aac.h @@ -298,6 +298,7 @@ struct AACContext { AVCodecContext *avctx; AVFrame *frame; + int skip_samples; int is_saved; ///< Set if elements have stored overlap from previous frame. DynamicRangeControl che_drc; diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c index 2b3509c85f..a82cd69a60 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -529,6 +529,8 @@ static void flush(AVCodecContext *avctx) } } } + + ac->skip_samples = 1; } /** @@ -1222,6 +1224,7 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) return AVERROR(ENOMEM); } + ac->skip_samples = 1; ac->random_state = 0x1f2e3d4c; #define MDCT_INIT(s, fn, len, sval) \ @@ -2390,7 +2393,7 @@ static int decode_dynamic_range(DynamicRangeControl *che_drc, static int decode_fill(AACContext *ac, GetBitContext *gb, int len) { uint8_t buf[256]; - int i, major, minor; + int i; if (len < 13+7*8) goto unknown; @@ -2404,10 +2407,6 @@ static int decode_fill(AACContext *ac, GetBitContext *gb, int len) { if (ac->avctx->debug & FF_DEBUG_PICT_INFO) av_log(ac->avctx, AV_LOG_DEBUG, "FILL:%s\n", buf); - if (sscanf(buf, "libfaac %d.%d", &major, &minor) == 2){ - ac->avctx->internal->skip_samples = 1024; - } - unknown: skip_bits_long(gb, len); @@ -3374,6 +3373,20 @@ static int aac_decode_frame(AVCodecContext *avctx, AVFrame *frame, if (buf[buf_offset]) break; + if (ac->skip_samples) { + int skip = 0; + + /* Our SBR implementation introduces a sample of delay into the output. */ + if (ac->oc[1].m4ac.sbr) + skip = 1; + + err = ff_decode_skip_samples(avctx, frame, skip); + if (err < 0) + return err; + + ac->skip_samples = 0; + } + return buf_size > buf_offset ? buf_consumed : buf_size; } -- 2.43.0 [-- Attachment #3: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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". ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [FFmpeg-devel] [PATCH 2/2] aacdec: fix single-sample delay for SBR streams 2023-12-04 7:52 ` [FFmpeg-devel] [PATCH 2/2] aacdec: fix single-sample delay for SBR streams Lynne @ 2023-12-05 1:47 ` Michael Niedermayer 0 siblings, 0 replies; 3+ messages in thread From: Michael Niedermayer @ 2023-12-05 1:47 UTC (permalink / raw) To: FFmpeg development discussions and patches [-- Attachment #1.1: Type: text/plain, Size: 1527 bytes --] On Mon, Dec 04, 2023 at 08:52:06AM +0100, Lynne wrote: > Our SBR implementation introduces a single sample of latency into the > output, which is currently never skipped. > This delay is separate from any container skip value and always present, > as it is from an additional part of the decoding process. > > Fixes Trac issue #9667 > > aac.h | 1 + > aacdec_template.c | 23 ++++++++++++++++++----- > 2 files changed, 19 insertions(+), 5 deletions(-) > 100f2e0512732bbf24f36e1524e07fb6c3fa0831 0002-aacdec-fix-single-sample-delay-for-SBR-streams.patch > From 5b9d971b108677d54bc3aac317669007462dbcc9 Mon Sep 17 00:00:00 2001 > From: Lynne <dev@lynne.ee> > Date: Mon, 30 Oct 2023 05:40:22 +0100 > Subject: [PATCH 2/2] aacdec: fix single-sample delay for SBR streams > > Our SBR implementation introduces a single sample of latency into the > output, which is currently never skipped. > This delay is separate from any container skip value and always present, > as it is from an additional part of the decoding process. > > Fixes Trac issue #9667 > --- > libavcodec/aac.h | 1 + > libavcodec/aacdec_template.c | 23 ++++++++++++++++++----- > 2 files changed, 19 insertions(+), 5 deletions(-) this affects many fate tests thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Does the universe only have a finite lifespan? No, its going to go on forever, its just that you wont like living in it. -- Hiranya Peiri [-- Attachment #1.2: signature.asc --] [-- Type: application/pgp-signature, Size: 195 bytes --] [-- Attachment #2: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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". ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-12-05 1:47 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-12-04 7:51 [FFmpeg-devel] [PATCH 1/2] decode: add ff_decode_skip_samples function Lynne [not found] ` <NknnrNO--3-9@lynne.ee-Nknnuzj----9> 2023-12-04 7:52 ` [FFmpeg-devel] [PATCH 2/2] aacdec: fix single-sample delay for SBR streams Lynne 2023-12-05 1:47 ` Michael Niedermayer
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