From patchwork Mon Dec 4 07:52:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 44899 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a301:b0:181:818d:5e7f with SMTP id x1csp2609863pzk; Sun, 3 Dec 2023 23:52:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IFekWabqWqaasZB1k6anhtTykufHe9W3jbE1R06FhoE4lSle9c2DX/1Ipd+tvAU7FR4qwvE X-Received: by 2002:ac2:494a:0:b0:50b:f873:3197 with SMTP id o10-20020ac2494a000000b0050bf8733197mr476740lfi.131.1701676338075; Sun, 03 Dec 2023 23:52:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701676338; cv=none; d=google.com; s=arc-20160816; b=ddlulaBN0YIUKABhkuU9u3zqBSWpW2fDt2Zp1K2tBmkhb4CzyMOEO8UCKbmU0/Qou6 +APXb5sWzs18TnBLqwee+rOA7B3o1H9/J+F7tZ1QtqqyLapZk0wOe+THLpynvd9IyNsm s2NW2pzgybhP0vtd0IrEqjGu+uc4t1GWgKcm8xtdvfYDcgq2vwems/7jJ9eV803jPmA9 RcA9s0t2ZmFKjYoz4MJMDQnRY7aUwgMe5Fkeftk6eDAbhdnunAeT92GUrUv7+lFRlWxm rLkomu0rskMKXnX0GXxVVnwmjJXxdCGdtTrDMd30f4DDgjNbixpAc/+55OsD7AL52FMz ojEQ== 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=+lRnG2PTRymY/yXUZuddr65mkUnfnpn3oh2qhEkLbEk=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=1AtRGNPuq0/5UZtbjTuD9rTu8C6oDC5EoDyVjR5JoZIXmWixbPOA6xNlWLRXWKr0ez Xm8c5ZEw1GjsCXoBQwTl9TS5yFvgs9JNYOv9JYakQLS3bVg55dBp2eYvdLkW2I/vxOiB VpygyPpn4+NVoxw1WUvmx1Wago+KTozp4kwrFKSwcTKw49AWb5yEY2pC1tBQF8ILhFtM yVWwASDCTU9m0YMzSc9vHLUcbNcpj08SwUETXiDkHw71GjQK1BKsqeQNCb64k7OaS1MM wXPyAsMqLNtHWx+RBeDkNuJdjxn+uoKT21F5XZHLJR5Irhb6Zm7Wk0k8aQSkFRLGuxmc P/kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=wOZlr0M6; 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 lt26-20020a170906fa9a00b00a0e3b388058si4213866ejb.338.2023.12.03.23.52.16; Sun, 03 Dec 2023 23:52:18 -0800 (PST) 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=wOZlr0M6; 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 5365D68B416; Mon, 4 Dec 2023 09:52:14 +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 3E48368B416 for ; Mon, 4 Dec 2023 09:52:07 +0200 (EET) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id EAE8910602EC for ; Mon, 4 Dec 2023 07:52:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1701676326; 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=WSVK9Zy577tdBOWTVZQkI3T/F8z7sltaHiDBC19Wxco=; b=wOZlr0M6VdrCNGKCyATCbHNz5M0B/kPji1Vau52+B64piUq3XkvA1OyxAmKjNlVR ST3E5yT3TjD5ruoeTWHM5rphH0l9BSy6tRg3E2Av4SiP5hyRGXHqRg4VYE7haZaH79l WipSgtvusQy7hfrInB+RmxGys9chXQ/lKnhVovW5j6E3urSHa4puuZ48zJUDvTq+euA JyJCixhKRMLNSrCAIs+ywZZcWAK+i0DB2VAf4R9/8QegyTuxckVO0UeotPaF4x8RT5a 8OjPGDaPphUUdjTS4IO95vp6QdH7kBRRk8R39Sep4lsg1XLo6831nhZPlk9wVRctFBv qdO55nUzdQ== Date: Mon, 4 Dec 2023 08:52:06 +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: fix single-sample delay for SBR streams 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: ih+i77XBG4IX 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 From 5b9d971b108677d54bc3aac317669007462dbcc9 Mon Sep 17 00:00:00 2001 From: Lynne 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