From patchwork Thu Oct 19 02:38:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 44297 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:2a09:b0:15d:8365:d4b8 with SMTP id e9csp279013pzh; Wed, 18 Oct 2023 19:39:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgdAssoRpFx4840OO1lhHfG06c513RMN/mgtN29swTRtC/80Q1IfsdT7U8gfMuooqxuHH4 X-Received: by 2002:a2e:a781:0:b0:2c5:409a:a901 with SMTP id c1-20020a2ea781000000b002c5409aa901mr457556ljf.49.1697683141863; Wed, 18 Oct 2023 19:39:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697683141; cv=none; d=google.com; s=arc-20160816; b=iqsIsBj8NuJz8KWjUaVdUdW8aa3tBD8W4VE9lDYkDFy+bDuBGrjS4VB3p8m8/3/89d hgViKpE64SaKLY0uvbeVmLbWpAZvLwU7eH72d5/6ntohxsz3KRrwod6w5iJT9aO/a510 Dhv7/MoT7fPBz3KHn3DcpUMqgUAlV30chaplPNry/+UQ3/gSTBllZ64D8bBlcIrcTxP5 aqhpDGlRerRD0eB0tESTSLZgdowcSJstRcfVCpQnYrzJDdyG3kHTdKgCThFNSviOQejf g1am2PjTiZmkf0ClBTqe+jD/w8MojNEmL1eu/a5smgKBYrNYYvaDrg9IGwYyFKJlUuGq +5Ew== 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:references:in-reply-to:message-id:to:from:date :dkim-signature:delivered-to; bh=Pdy15ATzNPv2CH/jA2dXKgUuKBnjqFtGI7mXMnQqKOY=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=cjeLSl+Juj0Jm4WsMRruZh5CaykmOb86TpFAwqIzBD79mN/TId/ZQdQ5po8CqA2EFQ JwgY90JjBAU4LYeRguaBYTizE9CgmqFTcM6AZ8ghUxBqYJVhPIlqHARaL6zdCCkRJWzD OqOu1JOvd6TfnNZ1GvuXyStixGWtcnzXfGWdEDyqZRl7KCw9pK6IaNpzaYCijt+PUoVX 7mJWjXkAiKpRu2kzdEy8gPtSMDzJHl5BvPQO454z9u/i9hgsuj9EtbukbEIA8KDwIavg YxjDwoIxA1MYmAL9Fl39TFuR2kY18rCnIAzDew/k1z3aAJJfDSVoDydvjB31XGW5X3Uw eWYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=LOy31h4e; 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 qb20-20020a1709077e9400b009874409d1e9si1543196ejc.200.2023.10.18.19.39.00; Wed, 18 Oct 2023 19:39:01 -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=LOy31h4e; 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 2A2EB68CABE; Thu, 19 Oct 2023 05:38:58 +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 D80A668CA5B for ; Thu, 19 Oct 2023 05:38:51 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id 8E4AD106015A for ; Thu, 19 Oct 2023 02:38:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1697683131; 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:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:References:Sender; bh=TVX/WYaoEb6RYHGeJcp5Z5/nx0vL+bk7ym88BqKujG8=; b=LOy31h4exzQv1cHe5avvcSHIjB4rosDrThxUuOBNJ5JCLybtYRLspS1lvBtwKlrM bkLvP6YastV0iZn0SWtOzaHLCI3v+UQrfsIDMGH6cXBGclMZxx1NeFDQvPUxuOqoOd6 7MbGjJ4l2lkUKPhpkUMoT/eYKOUjZgG57sKnkY1qM7ITXzpntPRMlf178m1JXEj3Glb AwVql9nYN+JWg58zzVn4aLbLgL1uz3rmiVd+e89UBkjzVk1z8vMUdwtlsCbpepUwKTL NgZuheXrKy6AeGl91E+6bVgbQsor1+00pZNfN793kE60xwP6B2CdCj3YehNGXk9OVNy TsI7CUuO3w== Date: Thu, 19 Oct 2023 04:38:51 +0200 (CEST) From: Lynne To: FFmpeg development discussions and patches Message-ID: In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] 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: KXrMyhjFrXxU Change from the previous version: by default, the current behaviour of the decoder is preserved. Samples to skip are zero by default. We can improve this later. 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 different amounts of padding. Patch attached. From 691fdb2952707fffd6975ca7a555e198236e9168 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. --- 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 954399f86b..a5b46b09e3 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 = 1024 }, 1024, 8192, AACDEC_FLAGS }, + {NULL}, }; -- 2.42.0