From patchwork Wed Feb 21 00:56:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dale Curtis X-Patchwork-Id: 7686 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.150.33 with SMTP id c30csp200773jai; Tue, 20 Feb 2018 17:02:54 -0800 (PST) X-Google-Smtp-Source: AH8x226HA0xXDrEK3+ajn43DCRCPBmyqgu3/Ysv0Ygroxvoov+8YUE+n0/8OnevFHYYxMsVkHRax X-Received: by 10.223.166.135 with SMTP id t7mr1289703wrc.260.1519174974096; Tue, 20 Feb 2018 17:02:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519174974; cv=none; d=google.com; s=arc-20160816; b=lOz+oVx4u97ygfuCKAfXrDiukNaG0LbSIYJrUZuWoPC9ZvC8Re3MTe3KhB+lAHXOdd I0gVei9gwSDtmVhrL20i1wA8kahkQqYKOndgM0u85hsurSzzx4We4gINS6cvHKoFSmWE WjePp36GiKhjDUEJ78M77aB1iqRunAyui60zgaYHReaVebO3DPJWJyUr1nOtLTpmT286 NEb55iktEK89I36AvLhEoGjU4m9jRCjWNHyV53Ur67P9X5l40un2EfczVveMtU0ihHJT 8LpW9T47Zeru5mGQVRnjYAtEkqmeTfJws73XgDNWepMzsSfvm+aSPFTYDBsjbEa43XDl Ax+Q== 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:to :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:dkim-signature:delivered-to :arc-authentication-results; bh=MVNp9R2qdfNSvH4bKoCrJ27cRqPSWk+zrb9wDh8hylg=; b=Ysn7ORqId/36e81fgkegTDyDsxFptq+raZC0wK2jkiHIpkAaSvVzvPaCvBbI93ReDD 5SXa+SOEg7zCzKgPSke+3tJOYobH0DcYphVlxlq8e9ZCEMOWcNs4818JqVPSPl5LadHa hLBqo7mpV81+ZyOYfoCp0M6nacqltafLq9yDrad1eraR206Hu8+1wwXrlsYXR515P7tM bKxJbuoZdMpFCEeGHQ89GHc7WU31SsqzgvQWr3Gc7spwvZ4xjammdf5aIyfrAS1eHUgK 68FPc75wVpWIxSH+7JHtzEVKoyRPqEXHjItzEvGC7rJ17mNH/0x5FCPLR+maQYE86KEb T76A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b=V/w6zNup; dkim=neutral (body hash did not verify) header.i=@chromium.org header.s=google header.b=X2YddauB; 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=chromium.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b11si13921936wrf.21.2018.02.20.17.02.53; Tue, 20 Feb 2018 17:02:54 -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=@google.com header.s=20161025 header.b=V/w6zNup; dkim=neutral (body hash did not verify) header.i=@chromium.org header.s=google header.b=X2YddauB; 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=chromium.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 180FE68A31C; Wed, 21 Feb 2018 03:02:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yb0-f177.google.com (mail-yb0-f177.google.com [209.85.213.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C1AC3689CB5 for ; Wed, 21 Feb 2018 03:02:43 +0200 (EET) Received: by mail-yb0-f177.google.com with SMTP id v135-v6so5971ybe.2 for ; Tue, 20 Feb 2018 17:02:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to; bh=FLUqmR62OXnz1LYOFKuApeDWfe9Pp3PWKlgzG411ZyY=; b=V/w6zNup6cSa8TMnBA/h+Ix8UTu4AP9X3fwNTRD3NHs8dabEYo4cRlDPYHg0VIngRY JOXTOkGiWCG6xPkaVI6UWd6QmDY5qepUcHNXhY5AhMH3/2S8srSw3ukH4x/51rutw2LM Fcu0K09gBj6wnw/LJ1WO9xei1pHdyPSgqjmKiOZfxDmzxdcxaLS6RmIvPJp1VpzZGDKj u3GL9FLPCDBBugle5zJhoMr7wKVSfjayNeDKWvgsSPx9Ut2XRuw0TGHY+4zDaZU7zFJm MsGaBYo3CQUh5ydhu8Dn1JgkywKejT9X6qJPja5oX08son/vFxwl4BfYay5SJgYVzqsB aDkA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to; bh=FLUqmR62OXnz1LYOFKuApeDWfe9Pp3PWKlgzG411ZyY=; b=X2YddauBEh1eZm8UsV/7wIglODZFL2BALYmoQaocf/oDtjHcGWb6qF8RY5FznFkZmR MsuEMMWzLg/yFZtYTXSQzjxI/TYJyxnZu6DVGTys8qEGfDCZ+v27R2QLhexzH/G6xDrV dLFm8hZcqk/HrFqJaZnwLiqBXEIu52CeVwNTA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to; bh=FLUqmR62OXnz1LYOFKuApeDWfe9Pp3PWKlgzG411ZyY=; b=ldobvIkTPh5c72svc92DHQV0LZZMgx/5EW7aMRxa0PhOA1zHESGtakc3VvHv8Q4wAB qJsIaZsCrtsWumy//AmctjoEIfbMH5C16RO+JkmaQ2vaDayZ0OueRRONpA4m7UUaRDmH rt1uHZUkjWA2AOSNddf0QUeBGx5PKmVYA0UEJiqaWGeb3d2us6p8ZtuSTMv6lrEsSQsA 598DtjAo61jcuNxGYZsdtA0NDNNal+btw7HzW92IOeTMEO43q0vTYujsc+MrMMS0LLDF cJd2Pvs0LPBcICDFflerhKh/G/flJFKZELmpCjPgrjyw8bn+z6l1XHJjay3MLY4EI18E RLfQ== X-Gm-Message-State: APf1xPD/uYCernCHaxWgx5ay12+x+LzrnVejuaWgCCtD9b0nxAMyMKPF IZUuJJNUtGT/cFYtv7Z80+XVEQg5no+yk1S81UGOvb5ikU0= X-Received: by 2002:a25:a063:: with SMTP id x90-v6mr1180306ybh.356.1519174636429; Tue, 20 Feb 2018 16:57:16 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a25:5f52:0:0:0:0:0 with HTTP; Tue, 20 Feb 2018 16:56:55 -0800 (PST) In-Reply-To: References: From: Dale Curtis Date: Tue, 20 Feb 2018 16:56:55 -0800 X-Google-Sender-Auth: cdzMBTpsaaHXL8dWGeFCsNP-cm4 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: Re: [FFmpeg-devel] [aacdec] Parse and drop gain control data, so that SSR packets decode. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" On Tue, Feb 20, 2018 at 4:18 PM, Alex Converse wrote: > > I would make this uint8_t > Done. > I would drop this stack struck and replace the leaf get_bits() with > skip bits. It makes the code that much harder to exploit and there is > no point in storing data we don't plan on decoding > Done. > This block seems funny. decode_gain_control() always returns zero. > Maybe make this warn once per stream when present like some of the > other AAC warn > cases. > Done. I've added an AACContext::warn_gain_control member to do this. This patch set also changes the attribution from Robert Swain to Maxim Gavrilov based on svn blame of the SoC repository after discussion at https://trac.ffmpeg.org/ticket/1693#comment:34 From 8e5a3cc04400a1186df0714524ccb24dbe3f627d Mon Sep 17 00:00:00 2001 From: Dale Curtis Date: Thu, 15 Feb 2018 16:22:55 -0800 Subject: [PATCH] [aacdec] Parse and drop gain control data, so that SSR packets decode. This will result in poor quality audio for SSR streams, but they will at least demux and decode without error; partially fixing ticket #1693. This pulls in the decode_gain_control() function from the ffmpeg summer-of-code repo (original author Maxim Gavrilov) at svn://svn.mplayerhq.hu/soc/aac/aac.c with some minor modifications and adds AOT_AAC_SSR to decode_audio_specific_config_gb(). Signed-off-by: Dale Curtis Co-authored-by: Maxim Gavrilov --- libavcodec/aac.h | 2 ++ libavcodec/aacdec_template.c | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/libavcodec/aac.h b/libavcodec/aac.h index 4910c661d6..05bc95385f 100644 --- a/libavcodec/aac.h +++ b/libavcodec/aac.h @@ -357,6 +357,8 @@ struct AACContext { int warned_num_aac_frames; int warned_960_sbr; + int warned_gain_control; + /* aacdec functions pointers */ void (*imdct_and_windowing)(AACContext *ac, SingleChannelElement *sce); void (*apply_ltp)(AACContext *ac, SingleChannelElement *sce); diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c index c2d9802023..cf97181092 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -997,6 +997,7 @@ static int decode_audio_specific_config_gb(AACContext *ac, switch (m4ac->object_type) { case AOT_AAC_MAIN: case AOT_AAC_LC: + case AOT_AAC_SSR: case AOT_AAC_LTP: case AOT_ER_AAC_LC: case AOT_ER_AAC_LD: @@ -1967,6 +1968,33 @@ static void apply_prediction(AACContext *ac, SingleChannelElement *sce) reset_all_predictors(sce->predictor_state); } +static void decode_gain_control(SingleChannelElement * sce, GetBitContext * gb) +{ + // wd_num, wd_test, aloc_size + static const uint8_t gain_mode[4][3] = { + {1, 0, 5}, // ONLY_LONG_SEQUENCE = 0, + {2, 1, 2}, // LONG_START_SEQUENCE, + {8, 0, 2}, // EIGHT_SHORT_SEQUENCE, + {2, 1, 5}, // LONG_STOP_SEQUENCE + }; + + const int mode = sce->ics.window_sequence[0]; + uint8_t bd, wd, ad; + + // FIXME: Store the gain control data on |sce| and do something with it. + uint8_t max_band = get_bits(gb, 2); + for (bd = 0; bd < max_band; bd++) { + for (wd = 0; wd < gain_mode[mode][0]; wd++) { + uint8_t adjust_num = get_bits(gb, 3); + for (ad = 0; ad < adjust_num; ad++) { + skip_bits(gb, 4 + ((wd == 0 && gain_mode[mode][1]) + ? 4 + : gain_mode[mode][2])); + } + } + } +} + /** * Decode an individual_channel_stream payload; reference: table 4.44. * @@ -2034,9 +2062,11 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce, goto fail; } if (!eld_syntax && get_bits1(gb)) { - avpriv_request_sample(ac->avctx, "SSR"); - ret = AVERROR_PATCHWELCOME; - goto fail; + decode_gain_control(sce, gb); + if (!ac->warned_gain_control) { + avpriv_report_missing_feature(ac->avctx, "Gain control"); + ac->warned_gain_control = 1; + } } // I see no textual basis in the spec for this occurring after SSR gain // control, but this is what both reference and real implmentations do -- 2.16.1.291.g4437f3f132-goog