From patchwork Mon Oct 30 05:10:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 44435 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dd83:b0:15d:8365:d4b8 with SMTP id kw3csp1216408pzb; Sun, 29 Oct 2023 22:10:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEcUVzMppNcfdQANt77vh4uiVi6dJiQPX40Uk/zKjW+4dxmEhDCD5yKdYRjZ7/jfnMdoaUc X-Received: by 2002:a17:907:9492:b0:9ae:54c3:c627 with SMTP id dm18-20020a170907949200b009ae54c3c627mr7310769ejc.71.1698642630354; Sun, 29 Oct 2023 22:10:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698642630; cv=none; d=google.com; s=arc-20160816; b=YF+smDEbLYyBVpwPshTTUMQKfNPcwmsnrT9BL1K0631GNLEW0hRP02SZupyBrUUNOw 8gAIA7PiZpNdDjGLGl6KO/DmZnzk7XnkNuEkmsWzDnDuw6zdgvCo7QBAMYFriv0uhQ2Z rugZcgD1J3mgE8naH9LiS9oTBuFtaFMA1sBYAEU5TUEFMFc/kiTfZGEVktpyfIs2lvQG PvORNrrVTWpoYiZTqMKYTE7M2sDEPmAbXs3TBlz9FFtapr+vCbTT562kiTey+vCoRLRX dPJJFV4xbS5gXawnybhfu/dGm6Ba44CmfEGEPBELb31MHsdBFJSgztL0vKG+3dbbPzYP MhaA== 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=a8+3SbU3y17eCF1vzhbPolUVVpNRDFki4jkRNEBjM7o=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=Q19KyKqMpDyTWwkQrJ3tY58Bj8vQs1hGLtbru6fOpe0LlQaVxOkZDU/2ulYjDo+054 IqpQyx5RjeqNXR8CTfiU55duF4FnUJIBjDdPZ4xtNmzAwvGUQA9C9P/DDCZ3/wfjblai y99vIjKBmXkBbdVoil+kGpTLba/FBlhEtBjeruxUdpnD5v+GTU9aQdyJ/hgraRaNzXcQ iD88d4viwVff2VhxfxVVwveeq0FSmW6tGJsFl3zi6lw58EbxQZt/RD5Dg4B1DgxEClOc mmc5BK5YYnwB3LIlfvxA0+xAwdzdJadNEnGhOGwOwrSdcWRaeddYoDYrGGODdDsSW3x7 ILvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=jbgER6Zi; 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 v17-20020a17090610d100b00992abdccff6si3022203ejv.576.2023.10.29.22.10.29; Sun, 29 Oct 2023 22:10:30 -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=jbgER6Zi; 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 EE9B568CCB5; Mon, 30 Oct 2023 07:10:27 +0200 (EET) 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 D543C68CBAB for ; Mon, 30 Oct 2023 07:10:21 +0200 (EET) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id 8C1AC1060136 for ; Mon, 30 Oct 2023 05:10:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1698642621; 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=e/KqR42nebwWkGHIpAhpQcIQUoq86r89vlWsGdr9h90=; b=jbgER6ZiI+TnSQuCrjR4nu3TlwmGiVCG8O8Jjux4farDD2AmaXuQKreAenoIT+OW KMfJ8KA4eLVZVD5o2H4LXNveK/03rVBbQRE/RUcyNZiTOyeKKZjFNnSxLCesyz0cTTp jZNi2AIjjKl9M3QNFei/Oi2HJulR26tmYF1AtPlBShturqlZW9Qlh4MFiQACETLxJHK bQ+uvOL2MWTmK4BZ68c5yhGfVXgdhOEOL4T9Kjp8zFu51D0ukK1pxyrBLd+i1rJqRyA WjDmaAHJnA6rRPkQzti4LSofcIRUyz2FFGb/3JTW+4KjDKyAzXggIJmO2DLzKs+Ykqs 37UrKsSanA== Date: Mon, 30 Oct 2023 06:10:21 +0100 (CET) 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: correctly skip padding at the start of frames and during seeking 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: hLwArtnkrnF0 Presently, our AAC decoder didn't skip any samples, unless the side data contained skip information. This uses the newly added ff_decoder_skip_samples function to skip samples on two levels: base, and additional. Base is the inherent decoder delay. Most containers already specify it, hence it is overwritten in that case. Additional is any extra samples that have to be skipped, in AAC's case, it's the delay introduced by SBR. Patch attached. From 82120460459cf90c330ff11fe0ccf4b954736b5c Mon Sep 17 00:00:00 2001 From: Lynne Date: Mon, 30 Oct 2023 05:40:22 +0100 Subject: [PATCH 2/2] aacdec: correctly skip padding at the start of frames and during seeking Presently, our AAC decoder didn't skip any samples, unless the side data contained skip information. This uses the newly added ff_decoder_skip_samples function to skip samples on two levels: base, and additional. Base is the inherent decoder delay. Most containers already specify it, hence it is overwritten in that case. Additional is any extra samples that have to be skipped, in AAC's case, it's the delay introduced by SBR. --- libavcodec/aac.h | 1 + libavcodec/aacdec_template.c | 24 +++++++++++++++++++----- 2 files changed, 20 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 954399f86b..ab3037c0d5 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -532,6 +532,8 @@ static void flush(AVCodecContext *avctx) } } } + + ac->skip_samples = 1; } /** @@ -1251,6 +1253,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) \ @@ -2419,7 +2422,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; @@ -2433,10 +2436,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); @@ -3403,6 +3402,21 @@ static int aac_decode_frame(AVCodecContext *avctx, AVFrame *frame, if (buf[buf_offset]) break; + if (ac->skip_samples) { + int additional = 0; + + if (ac->oc[1].m4ac.sbr) + additional = 3010; + + err = ff_decode_skip_samples(avctx, frame, + ac->oc[1].m4ac.frame_length_short ? 960 : 1024, + additional); + if (err < 0) + return err; + + ac->skip_samples = 0; + } + return buf_size > buf_offset ? buf_consumed : buf_size; } -- 2.42.0