From patchwork Wed Jun 22 01:42:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 36375 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp2554713pzb; Tue, 21 Jun 2022 18:42:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tgYyZluxLURpxt/zdAdICpRlpapKOKigQAiEjRw46vaURpVwuxUDTOPfEEXXIrWrSbrXjk X-Received: by 2002:a17:907:e92:b0:722:efe6:90fc with SMTP id ho18-20020a1709070e9200b00722efe690fcmr897421ejc.44.1655862151904; Tue, 21 Jun 2022 18:42:31 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f26-20020a170906739a00b00709fed17d05si211052ejl.97.2022.06.21.18.42.30; Tue, 21 Jun 2022 18:42:31 -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=@outlook.com header.s=selector1 header.b=HNpDcD9E; arc=fail (body hash mismatch); 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=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AD49B68B6B0; Wed, 22 Jun 2022 04:42:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2102.outbound.protection.outlook.com [40.92.89.102]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B7A8768B4BF for ; Wed, 22 Jun 2022 04:42:20 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j/ifM5h4doShji01nY6oe0kLOnlVMbq57bGuvQRzJNOg43IVZvFtyx5uylk7X4QgjsNKu2EYX5Bdd8m5Uxj/9cgKS6bDdP5X3O5brnORKF0urFh2G8cpjnPmFlHTwiqXO+paDQo+SW2nD5PVWXNm7PMcH8FFtjapaPdAXYZ8Xoi3h8JNAYuNpCjtjPV2znmqAqQgVtwJF3pD42/MfDeG5NqIfyajuCagE/GYMM5Bg0Ayrn5FK9KvWB4NUrO237P3vmDjG0W3r+JYwL9UKuqhAaOydSMEy1jgIg2a2yJGtXObaDzj7Q+kpR9yDPy5GwYgWgnzAXd7xR1MvKPFwX1VAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=EzRkflmxxu5YIksroP84z1thddKu/VJm8f6PqPzEu6g=; b=VR4qVfp26d+dRNMSCroinPALFXRZ0PdnSUhEPfCZIekQlp1MHXdJOmQM0qKg5OGKZSJzHHZ28VWrw56B6MFTI/6V0cfVLnF5ZWId4vI3RnjMhw3eV6sqZmRmYimwOskKrZKC9gLJt40dVHzHmWJB+iCkNGzR1sqJw1Cx6u1lukvKsP2WU+p89+Sl3Ll/EFq47Af41JsRgYTymOuzbOEI3ecNFms3zj79QhramWHPjanI1CYNV2nezL8+sLu0FIWt5rRmHzRi02nP1TWt8ctvQymNjkBLQb74Gr9ESCkUHZ4R9inQMETELDv66pJ98lNTwGePQ/gQ6ITa920BJ2SHLQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EzRkflmxxu5YIksroP84z1thddKu/VJm8f6PqPzEu6g=; b=HNpDcD9E1xrmWwKBunWGd6FxniXoTTobKzWrSz3Sr1ctfYXTCNq31rEnwPMsGyTtOuQz0GOgH0YrLM/wJY1RIQlD4P05q9AgacnViZ7qcvJ67bOoBi3NaKsuTE6WcQXSiyLxowOcUsb8pSmBydeQ75EDYVfZ1UH+AJtyV5CXMORMXzx1UDm9sjNhLgVAu7VX4D0VYgxRXNe/KL5Alfj2NjGereMYBx9I7srw5MPBEixoLs5nOw25a5MpcofKSKlB0C8dpyNbvZorRswDS6syQUeOqDk1ysecYx44r+Tj2ZJuuvFqJg4TAVVttaVx1doqjWKrQuuXtOomGf0/f4kfog== Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) by GV1PR01MB8452.eurprd01.prod.exchangelabs.com (2603:10a6:150:1f::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5353.14; Wed, 22 Jun 2022 01:42:18 +0000 Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::60b9:9f29:40cc:f01c]) by DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::60b9:9f29:40cc:f01c%10]) with mapi id 15.20.5353.022; Wed, 22 Jun 2022 01:42:18 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 22 Jun 2022 03:42:08 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 X-TMN: [xgTsO7s7FioOICkBWWMjfmbmB2cq/7lM] X-ClientProxiedBy: ZR0P278CA0136.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::15) To DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) X-Microsoft-Original-Message-ID: <20220622014210.430917-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 81aec7d8-7f2f-4602-f4c9-08da53f070d6 X-MS-Exchange-SLBlob-MailProps: +LiGfBxqLEuS9uuI2GdeKg9Cxv13K+VOLxybiTZMoHuQKv8jSIX+y+UoqRUnpixRkpeyqg4yc0MjbvlFxzA51Zkg/hOpY4tnLyE9wtAHnZ/AXpQwfuRWRzg3C1rqydAlephMt/wlrf03TEQHOX3H/0g6Yt6hNczB8V8OQQ+TVVsc9+L4Vb8LP5EKZIbG6mOr9xNUyk7sguNpXgNkpHjLtTYy7tcjhf7aWu0m2vNtOygBMyLmlGaVq2C9F4FfudkXAUV1U+bZC8qZgdveGvJ0d+hR3vrIsPw2+RR4xfeJlRr6cOJcVT1EL/OxkTPEjvdrGLZlWgOftrcnJE0V4woOUMG1u22QAXTObFmjMvTFNiqo5iTFtbP8ytHRwuXxvYV2/F2sm9DF2OS5/TAIZ0Vc0kWYKtCzkP89H1f4SBqmMdW3SHXK85t2BdarRxZZN2keqdCykxHPBss/uzZ2RkNYcBL/73N3CMk8yLcN7jMtwa15BhAF45i409Xeo2IrFaF/U1CN6FNqWdziA+y3GX6caFf6XiQK64yq4xEVsE+t23Nfaeb8PERsVaTBehyahha6EBn8+7Sa7dHXREsUpeaOQAtBDg2ct6/DVqZzeDLJE1OeCPvSUUkafzMECcaMbjTEvgwkXdv1Hq4auUdJKHvgki+Ybgk3/YKbE5sK5YiQ1ea1xLn+kcrSSRi2i5nYuaovQ0+wqL3xd5wrKzAZPAgQmEpQJvD6tmMsEKbnYIg7ybpMa28vVHienU7YEy8vLYfBqsoDunuObKGmIV+alcNS+xuhpWd7fQ6q X-MS-TrafficTypeDiagnostic: GV1PR01MB8452:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uJ/kwRv5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-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 81aec7d8-7f2f-4602-f4c9-08da53f070d6 X-MS-Exchange-CrossTenant-AuthSource: DB6PR0101MB2214.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jun 2022 01:42:18.2519 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR01MB8452 Subject: [FFmpeg-devel] [PATCH 1/3] avcodec/hcadec: Don't use GetBit-API for byte-aligned reads 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 7n43JIbECbmP Signed-off-by: Andreas Rheinhardt --- libavcodec/hcadec.c | 80 ++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/libavcodec/hcadec.c b/libavcodec/hcadec.c index 4e84942bb9..73ff62139d 100644 --- a/libavcodec/hcadec.c +++ b/libavcodec/hcadec.c @@ -23,6 +23,7 @@ #include "libavutil/tx.h" #include "avcodec.h" +#include "bytestream.h" #include "codec_internal.h" #include "get_bits.h" #include "internal.h" @@ -106,7 +107,7 @@ static inline unsigned ceil2(unsigned a, unsigned b) static av_cold int decode_init(AVCodecContext *avctx) { HCAContext *c = avctx->priv_data; - GetBitContext *gb = &c->gb; + GetByteContext gb0, *const gb = &gb0; int8_t r[16] = { 0 }; float scale = 1.f / 8.f; unsigned b, chunk; @@ -118,41 +119,42 @@ static av_cold int decode_init(AVCodecContext *avctx) if (avctx->ch_layout.nb_channels <= 0 || avctx->ch_layout.nb_channels > 16) return AVERROR(EINVAL); - ret = init_get_bits8(gb, avctx->extradata, avctx->extradata_size); - if (ret < 0) - return ret; - skip_bits_long(gb, 32); - version = get_bits(gb, 16); - skip_bits_long(gb, 16); + if (avctx->extradata_size < 36) + return AVERROR_INVALIDDATA; + bytestream2_init(gb, avctx->extradata, avctx->extradata_size); + + bytestream2_skipu(gb, 4); + version = bytestream2_get_be16(gb); + bytestream2_skipu(gb, 2); c->ath_type = version >= 0x200 ? 0 : 1; - if (get_bits_long(gb, 32) != MKBETAG('f', 'm', 't', 0)) + if (bytestream2_get_be32u(gb) != MKBETAG('f', 'm', 't', 0)) return AVERROR_INVALIDDATA; - skip_bits_long(gb, 32); - skip_bits_long(gb, 32); - skip_bits_long(gb, 32); + bytestream2_skipu(gb, 4); + bytestream2_skipu(gb, 4); + bytestream2_skipu(gb, 4); - chunk = get_bits_long(gb, 32); + chunk = bytestream2_get_be32u(gb); if (chunk == MKBETAG('c', 'o', 'm', 'p')) { - skip_bits_long(gb, 16); - skip_bits_long(gb, 8); - skip_bits_long(gb, 8); - c->track_count = get_bits(gb, 8); - c->channel_config = get_bits(gb, 8); - c->total_band_count = get_bits(gb, 8); - c->base_band_count = get_bits(gb, 8); - c->stereo_band_count = get_bits(gb, 8); - c->bands_per_hfr_group = get_bits(gb, 8); + bytestream2_skipu(gb, 2); + bytestream2_skipu(gb, 1); + bytestream2_skipu(gb, 1); + c->track_count = bytestream2_get_byteu(gb); + c->channel_config = bytestream2_get_byteu(gb); + c->total_band_count = bytestream2_get_byteu(gb); + c->base_band_count = bytestream2_get_byteu(gb); + c->stereo_band_count = bytestream2_get_byte (gb); + c->bands_per_hfr_group = bytestream2_get_byte (gb); } else if (chunk == MKBETAG('d', 'e', 'c', 0)) { - skip_bits_long(gb, 16); - skip_bits_long(gb, 8); - skip_bits_long(gb, 8); - c->total_band_count = get_bits(gb, 8) + 1; - c->base_band_count = get_bits(gb, 8) + 1; - c->track_count = get_bits(gb, 4); - c->channel_config = get_bits(gb, 4); - if (!get_bits(gb, 8)) + bytestream2_skipu(gb, 2); + bytestream2_skipu(gb, 1); + bytestream2_skipu(gb, 1); + c->total_band_count = bytestream2_get_byteu(gb) + 1; + c->base_band_count = bytestream2_get_byteu(gb) + 1; + c->track_count = bytestream2_peek_byteu(gb) >> 4; + c->channel_config = bytestream2_get_byteu(gb) & 0xF; + if (!bytestream2_get_byteu(gb)) c->base_band_count = c->total_band_count; c->stereo_band_count = c->total_band_count - c->base_band_count; c->bands_per_hfr_group = 0; @@ -163,24 +165,20 @@ static av_cold int decode_init(AVCodecContext *avctx) return AVERROR_INVALIDDATA; - while (get_bits_left(gb) >= 32) { - chunk = get_bits_long(gb, 32); + while (bytestream2_get_bytes_left(gb) >= 4) { + chunk = bytestream2_get_be32u(gb); if (chunk == MKBETAG('v', 'b', 'r', 0)) { - skip_bits_long(gb, 16); - skip_bits_long(gb, 16); + bytestream2_skip(gb, 2 + 2); } else if (chunk == MKBETAG('a', 't', 'h', 0)) { - c->ath_type = get_bits(gb, 16); + c->ath_type = bytestream2_get_be16(gb); } else if (chunk == MKBETAG('r', 'v', 'a', 0)) { - skip_bits_long(gb, 32); + bytestream2_skip(gb, 4); } else if (chunk == MKBETAG('c', 'o', 'm', 'm')) { - skip_bits_long(gb, get_bits(gb, 8) * 8); + bytestream2_skip(gb, bytestream2_get_byte(gb) * 8); } else if (chunk == MKBETAG('c', 'i', 'p', 'h')) { - skip_bits_long(gb, 16); + bytestream2_skip(gb, 2); } else if (chunk == MKBETAG('l', 'o', 'o', 'p')) { - skip_bits_long(gb, 32); - skip_bits_long(gb, 32); - skip_bits_long(gb, 16); - skip_bits_long(gb, 16); + bytestream2_skip(gb, 4 + 4 + 2 + 2); } else if (chunk == MKBETAG('p', 'a', 'd', 0)) { break; } else {