From patchwork Tue Oct 3 04:07:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 44110 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1204:b0:15d:8365:d4b8 with SMTP id v4csp1812376pzf; Mon, 2 Oct 2023 21:07:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG6+wBqn8pwmqp8l2wIqCwcN/AJ6ZYKsRZY1fEeW0iDIlU5CwySR4e8xbMeKOaSEgeS3HDg X-Received: by 2002:aa7:d1c3:0:b0:532:c690:92bf with SMTP id g3-20020aa7d1c3000000b00532c69092bfmr12193335edp.28.1696306066794; Mon, 02 Oct 2023 21:07:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696306066; cv=none; d=google.com; s=arc-20160816; b=hRBvC/V2ZR5Tb+JGx+5AkxpMD8QMA95NcfujTG4zXz937I3HoMeBhwg+JSDzJN/B5O pNXjoS0m8Qg+WXR+8ImBMpfGcAmXqKNp/s+eZR4Pu1aGdi7DX97bBauM3XfYxUXy4KDn MRg1OHqUAWlQeYkH9hBvwY5+76mQKoqGvFvZdl4/4ZG2wtwuVhKkENmQLcbMhqyaEsKx qQG5Be99xQTKMKWmbo8Ul7zcMEF8kcqrCxl+Y36ctIQ4ezxb3BgzDByH/D0OFikpfj5n kFtlnT8vK0JjYFDiiq7iws1SMfiirM1Qb1dtcueCMh2jNnDu2rPfMU0xGDr7hUpeH4Hv 85Dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:message-id:to:from:date:dkim-signature:delivered-to; bh=yNrMcBIeVxr+KOH/aLp6GKKQioEAbC4Qpp8N/tKyt1s=; fh=Q46kXK7oI5D1Jhi90JBr53c7NIaTxGaU4KPeRZyM/hI=; b=LUkO2KdNft+kTGt7ELJn91+Cf1gFkeDkBSSupHLFuHDQtY8EAV1rVjxNxDDbDHAqvk 6ymYDma0xXrNfi6w+/fJP9wXxK+dBqWHFv1UCnJovp6qXrBpjJcrisyCFxXt+6LYpyDW 41KUtfftDg+ryuO8fcWjKeYVyNbeNIs3Dff/poksa/t/VjezsN1latUwnZ6tYiS4Xywu zhyR7r0yjx1B1RzxFzTFlGu10wC/qj2E02+pWpz2JhCQMkRqAcBoCnpyydY1LZMbQsFD xT40v5ilmjfr9zeTRDY644c4s+ByimknDOqbTHg+N3cGCAoYJTfczW9266lHUz63zxtP 64eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=Xj1D3xHc; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=lynne.ee Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e7-20020a50fb87000000b00533f1c4dac6si166405edq.497.2023.10.02.21.07.42; Mon, 02 Oct 2023 21:07:46 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=Xj1D3xHc; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=lynne.ee Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DC16168CB38; Tue, 3 Oct 2023 07:07:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A9B5568CAA7 for ; Tue, 3 Oct 2023 07:07:30 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id 23C8E1060148 for ; Tue, 3 Oct 2023 04:07:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1696306049; s=s1; d=lynne.ee; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:Sender; bh=pt+6C0UbmYyK93zGGDbsmBt6hYJH4bBM77cWndlgKBc=; b=Xj1D3xHcnAj89dudKPBIGIdafZpmxDJVr4NnoruMU5b5Lz2inNQckX5QRsn0oiV6 wXxbwIAZlH5wQpndToC7MkTYBcZbGv66gb6BuVIo7+FxqC7erkEHhujpac2ABSAZoJD SbzSVXqVISbm+uEx7G0QKZo/bXmuj3xAxMHEcTmyfxqYkxOyVOBxCkBE+HsTbD4+isi Z+DgmU8+g0SM1ahmFgnqIaN1jB7z2MKMShIGwCJNg0DiYDCuNprr1Lg1i8pcasjhXBX Gnk5xhAgbuSLAZjIOtYY0gsG5kTovFYDg8Glf/KTeBUxMI9pNQBJOQGCZaUdnf7LySZ 2uYUQ9mjSg== Date: Tue, 3 Oct 2023 06:07:29 +0200 (CEST) From: Lynne To: Ffmpeg Devel Message-ID: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] aacdec: padding skip improvements X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: wGga9/LyWAVE For some reason, this was never set, which meant all **raw** AAC in ADTS streams, except faac, had extra samples at the start. Despite this being a standard MDCT-based codec with a frame size of 1024, hence a delay of 1024 samples at the start, all major encoders, excluding faac and FFmpeg, use 2048 samples of padding. Because this is also such a mess, make it an option to allow for users to configure the amount of padding. The FFmpeg encoder will be modified to also output 2048 samples of padding at the start, to make it in line with other encoders. Yes, this leaves FATE pretty sad. Will be fixed by another patch once the discussions have completed as to what should be the default. From dca29a894a60cdca1682fa6d0d3ee56c552b3d49 Mon Sep 17 00:00:00 2001 From: Lynne Date: Tue, 3 Oct 2023 05:57:50 +0200 Subject: [PATCH] aacdec: padding skip improvements For some reason, this was never set, which meant all **raw** AAC in ADTS streams, except faac, had extra samples at the start. Despite this being a standard MDCT-based codec with a frame size of 1024, hence a delay of 1024 samples at the start, all major encoders, excluding faac and FFmpeg, use 2048 samples of padding. The FFmpeg encoder will be modified to also output 2048 samples of padding at the start, to make it in line with other encoders. Yes, this leaves FATE pretty sad. Will fix it with the real version of the patch. --- libavcodec/aac.h | 1 + libavcodec/aacdec_template.c | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/libavcodec/aac.h b/libavcodec/aac.h index 285d3b7482..79bbb3cce5 100644 --- a/libavcodec/aac.h +++ b/libavcodec/aac.h @@ -298,6 +298,7 @@ struct AACContext { AVCodecContext *avctx; AVFrame *frame; + int override_padding; 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 51a4cb2b66..70c5c6ab4c 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -1273,6 +1273,9 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) if (ret < 0) return ret; + /* Usually overridden by side data */ + avctx->internal->skip_samples = ac->override_padding; + return 0; } @@ -2417,14 +2420,16 @@ static int decode_dynamic_range(DynamicRangeControl *che_drc, return n; } -static int decode_fill(AACContext *ac, GetBitContext *gb, int len) { - uint8_t buf[256]; - int i, major, minor; +static int decode_fill(AACContext *ac, GetBitContext *gb, int len) +{ + uint8_t buf[256] = { 0 }; + int i, major, minor, micro; if (len < 13+7*8) goto unknown; - get_bits(gb, 13); len -= 13; + get_bits(gb, 13); + len -= 13; for(i=0; i+1=8; i++, len-=8) buf[i] = get_bits(gb, 8); @@ -2434,7 +2439,9 @@ static int decode_fill(AACContext *ac, GetBitContext *gb, int len) { 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; + ac->avctx->internal->skip_samples -= 1024; + } else if ((sscanf(buf, "avc %d.%d.%d", &major, &minor, µ) == 3)) { + ac->avctx->internal->skip_samples -= 1024; } unknown: @@ -3471,6 +3478,9 @@ static const AVOption options[] = { { "coded", "order in which the channels are coded in the bitstream", 0, AV_OPT_TYPE_CONST, { .i64 = CHANNEL_ORDER_CODED }, .flags = AACDEC_FLAGS, "channel_order" }, + { "padding", "Override the padding at the start of a stream.\n", + offsetof(AACContext, override_padding), AV_OPT_TYPE_INT, { .i64 = 2048 }, 1024, 8192, AACDEC_FLAGS }, + {NULL}, }; -- 2.42.0