From patchwork Thu Aug 24 23:21:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 43300 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:f07:b0:149:dfde:5c0a with SMTP id fl7csp74828pzb; Thu, 24 Aug 2023 16:21:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHzugHeuHAPnBRUP9Gztc+o1cOD2ugFRAyZC3dfklX17712US16+qD0RVD/bwy7STmCpoCb X-Received: by 2002:a17:906:7485:b0:9a1:c44d:7056 with SMTP id e5-20020a170906748500b009a1c44d7056mr6908658ejl.26.1692919308690; Thu, 24 Aug 2023 16:21:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692919308; cv=none; d=google.com; s=arc-20160816; b=gxlM+p3aUAnA4qlSsIqgiAhxG5GOuqxoiX/u4BSNAEs5f3pu+9hGeO3Slrw0m7+4TS 0A2gWjkChyB8B8YNvikBgh63jEXbtPZdhycGW3QSfyUBZChV8JTB0Z87EF9Tu30IhVFO oYumqUcNxB5F54JBsftq1MaHIiVBXsaRvfhEgRYV2V/kuqL51WGZdDh+vc3VENiPc9zt BPfe7EMg5njww1aaXexdp+LHKq9eUtBxUyhZGCBaoQQ9LERWSFT/wz6B7qPCSY4p6SpB ZAiGBKiZzm7bHCHPmCmEtHSmYQ9kP0m81lP/XaGahRbtmml4oJZmWKsS4V1Or4ZKEDqJ VBuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to; bh=lBVJFI4oeuFqyLL6BPq3nvFzZUfoR32+0aVgAGgHKfQ=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=BrO7HjjECMaGEY91o2JbqO5noiPehWqi4KHELXpXCzjT1GIP+rRL4mKB2mepiXOzA2 oXCXoFdfsScXX/Wz9cySyqRvTZfla3fOsNG+mTwUcJR7ZPMkJHD8YtXxibdLdZce4cvg dy8z/ZxNKxFhprM7aj6R0TvFDswg2B0sntJza1TDuSrL5f2evegb/KtVZT0oj4C5NaNZ oJFq6m59JThbHVUQyQWX1EdDHdeVSo5pNpq00bRYov1gifAF7tvGuOT95oVOIDC4luCI GiZ9uRsYBm+agGObCM5XXFXDnGBV55nNjVitoUJSZA1SMq9nSfR1EL0uwnvA1T+Mazj1 ddrA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id p26-20020a170906b21a00b00997eac101casi221422ejz.509.2023.08.24.16.21.47; Thu, 24 Aug 2023 16:21:48 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E866968C685; Fri, 25 Aug 2023 02:21:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0658768C53B for ; Fri, 25 Aug 2023 02:21:36 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 34D9540004 for ; Thu, 24 Aug 2023 23:21:35 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 25 Aug 2023 01:21:34 +0200 Message-Id: <20230824232135.26854-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 1/2] Revert "avcodec/apedec: fix decoding 24bit insane files with recent versions" 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: pRuIuHbAFzyl Fixes: Ticket9816 This reverts commit ed0001482a74b60f3d5bc5cd7e304c9d65b2fcd5. --- libavcodec/apedec.c | 59 ++++++++++----------------------------------- 1 file changed, 13 insertions(+), 46 deletions(-) diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c index 613c76df0b..cc0d7e2749 100644 --- a/libavcodec/apedec.c +++ b/libavcodec/apedec.c @@ -134,21 +134,6 @@ typedef struct APEPredictor { unsigned int sample_pos; } APEPredictor; -typedef struct APEPredictor64 { - int64_t *buf; - - int64_t lastA[2]; - - int64_t filterA[2]; - int64_t filterB[2]; - - uint64_t coeffsA[2][4]; ///< adaption coefficients - uint64_t coeffsB[2][5]; ///< adaption coefficients - int64_t historybuffer[HISTORY_SIZE + PREDICTOR_SIZE]; - - unsigned int sample_pos; -} APEPredictor64; - /** Decoder context */ typedef struct APEContext { AVClass *class; ///< class for AVOptions @@ -168,7 +153,6 @@ typedef struct APEContext { uint32_t CRC_state; ///< accumulated CRC int frameflags; ///< frame flags APEPredictor predictor; ///< predictor used for final reconstruction - APEPredictor64 predictor64; ///< 64bit predictor used for final reconstruction int32_t *decoded_buffer; int decoded_size; @@ -808,20 +792,13 @@ static const int32_t initial_coeffs_3930[4] = { 360, 317, -109, 98 }; -static const int64_t initial_coeffs_3930_64bit[4] = { - 360, 317, -109, 98 -}; - static void init_predictor_decoder(APEContext *ctx) { APEPredictor *p = &ctx->predictor; - APEPredictor64 *p64 = &ctx->predictor64; /* Zero the history buffers */ memset(p->historybuffer, 0, PREDICTOR_SIZE * sizeof(*p->historybuffer)); - memset(p64->historybuffer, 0, PREDICTOR_SIZE * sizeof(*p64->historybuffer)); p->buf = p->historybuffer; - p64->buf = p64->historybuffer; /* Initialize and zero the coefficients */ if (ctx->fileversion < 3930) { @@ -839,11 +816,8 @@ static void init_predictor_decoder(APEContext *ctx) } else { memcpy(p->coeffsA[0], initial_coeffs_3930, sizeof(initial_coeffs_3930)); memcpy(p->coeffsA[1], initial_coeffs_3930, sizeof(initial_coeffs_3930)); - memcpy(p64->coeffsA[0], initial_coeffs_3930_64bit, sizeof(initial_coeffs_3930_64bit)); - memcpy(p64->coeffsA[1], initial_coeffs_3930_64bit, sizeof(initial_coeffs_3930_64bit)); } memset(p->coeffsB, 0, sizeof(p->coeffsB)); - memset(p64->coeffsB, 0, sizeof(p64->coeffsB)); if (ctx->fileversion < 3930) { memcpy(p->coeffsB[0], initial_coeffs_b_3800, sizeof(initial_coeffs_b_3800)); @@ -855,13 +829,7 @@ static void init_predictor_decoder(APEContext *ctx) p->filterB[0] = p->filterB[1] = 0; p->lastA[0] = p->lastA[1] = 0; - p64->filterA[0] = p64->filterA[1] = 0; - p64->filterB[0] = p64->filterB[1] = 0; - p64->lastA[0] = p64->lastA[1] = 0; - p->sample_pos = 0; - - p64->sample_pos = 0; } /** Get inverse sign of integer (-1 for positive, 1 for negative and 0 for zero) */ @@ -1181,17 +1149,16 @@ static void predictor_decode_mono_3930(APEContext *ctx, int count) } } -static av_always_inline int predictor_update_filter(APEPredictor64 *p, +static av_always_inline int predictor_update_filter(APEPredictor *p, const int decoded, const int filter, const int delayA, const int delayB, const int adaptA, const int adaptB) { - int64_t predictionA, predictionB; - int32_t sign; + int32_t predictionA, predictionB, sign; p->buf[delayA] = p->lastA[filter]; p->buf[adaptA] = APESIGN(p->buf[delayA]); - p->buf[delayA - 1] = p->buf[delayA] - (uint64_t)p->buf[delayA - 1]; + p->buf[delayA - 1] = p->buf[delayA] - (unsigned)p->buf[delayA - 1]; p->buf[adaptA - 1] = APESIGN(p->buf[delayA - 1]); predictionA = p->buf[delayA ] * p->coeffsA[filter][0] + @@ -1200,9 +1167,9 @@ static av_always_inline int predictor_update_filter(APEPredictor64 *p, p->buf[delayA - 3] * p->coeffsA[filter][3]; /* Apply a scaled first-order filter compression */ - p->buf[delayB] = p->filterA[filter ^ 1] - ((int64_t)(p->filterB[filter] * 31ULL) >> 5); + p->buf[delayB] = p->filterA[filter ^ 1] - ((int)(p->filterB[filter] * 31U) >> 5); p->buf[adaptB] = APESIGN(p->buf[delayB]); - p->buf[delayB - 1] = p->buf[delayB] - (uint64_t)p->buf[delayB - 1]; + p->buf[delayB - 1] = p->buf[delayB] - (unsigned)p->buf[delayB - 1]; p->buf[adaptB - 1] = APESIGN(p->buf[delayB - 1]); p->filterB[filter] = p->filterA[filter ^ 1]; @@ -1212,8 +1179,8 @@ static av_always_inline int predictor_update_filter(APEPredictor64 *p, p->buf[delayB - 3] * p->coeffsB[filter][3] + p->buf[delayB - 4] * p->coeffsB[filter][4]; - p->lastA[filter] = decoded + ((int64_t)((uint64_t)predictionA + (predictionB >> 1)) >> 10); - p->filterA[filter] = p->lastA[filter] + ((int64_t)(p->filterA[filter] * 31ULL) >> 5); + p->lastA[filter] = decoded + ((int)((unsigned)predictionA + (predictionB >> 1)) >> 10); + p->filterA[filter] = p->lastA[filter] + ((int)(p->filterA[filter] * 31U) >> 5); sign = APESIGN(decoded); p->coeffsA[filter][0] += p->buf[adaptA ] * sign; @@ -1231,7 +1198,7 @@ static av_always_inline int predictor_update_filter(APEPredictor64 *p, static void predictor_decode_stereo_3950(APEContext *ctx, int count) { - APEPredictor64 *p = &ctx->predictor64; + APEPredictor *p = &ctx->predictor; int32_t *decoded0 = ctx->decoded[0]; int32_t *decoded1 = ctx->decoded[1]; @@ -1260,7 +1227,7 @@ static void predictor_decode_stereo_3950(APEContext *ctx, int count) static void predictor_decode_mono_3950(APEContext *ctx, int count) { - APEPredictor64 *p = &ctx->predictor64; + APEPredictor *p = &ctx->predictor; int32_t *decoded0 = ctx->decoded[0]; int32_t predictionA, currentA, A, sign; @@ -1272,14 +1239,14 @@ static void predictor_decode_mono_3950(APEContext *ctx, int count) A = *decoded0; p->buf[YDELAYA] = currentA; - p->buf[YDELAYA - 1] = p->buf[YDELAYA] - (uint64_t)p->buf[YDELAYA - 1]; + p->buf[YDELAYA - 1] = p->buf[YDELAYA] - (unsigned)p->buf[YDELAYA - 1]; predictionA = p->buf[YDELAYA ] * p->coeffsA[0][0] + p->buf[YDELAYA - 1] * p->coeffsA[0][1] + p->buf[YDELAYA - 2] * p->coeffsA[0][2] + p->buf[YDELAYA - 3] * p->coeffsA[0][3]; - currentA = A + (uint64_t)(predictionA >> 10); + currentA = A + (unsigned)(predictionA >> 10); p->buf[YADAPTCOEFFSA] = APESIGN(p->buf[YDELAYA ]); p->buf[YADAPTCOEFFSA - 1] = APESIGN(p->buf[YDELAYA - 1]); @@ -1299,7 +1266,7 @@ static void predictor_decode_mono_3950(APEContext *ctx, int count) p->buf = p->historybuffer; } - p->filterA[0] = currentA + (uint64_t)((int64_t)(p->filterA[0] * 31U) >> 5); + p->filterA[0] = currentA + (unsigned)((int)(p->filterA[0] * 31U) >> 5); *(decoded0++) = p->filterA[0]; } @@ -1336,7 +1303,7 @@ static void do_apply_filter(APEContext *ctx, int version, APEFilter *f, f->delay - order, f->adaptcoeffs - order, order, APESIGN(*data)); - res = (int64_t)(res + (1LL << (fracbits - 1))) >> fracbits; + res = (int)(res + (1U << (fracbits - 1))) >> fracbits; res += (unsigned)*data; *data++ = res; From patchwork Thu Aug 24 23:21:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 43301 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:f07:b0:149:dfde:5c0a with SMTP id fl7csp74893pzb; Thu, 24 Aug 2023 16:21:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGJkIlu6IxAE+QToUcT+PfgpaGcyxh+YTgGKoOvyZ6ZdJ588UHdbljNky+9uNqCa3rJEKom X-Received: by 2002:a17:906:3051:b0:99c:f47a:2354 with SMTP id d17-20020a170906305100b0099cf47a2354mr13425719ejd.70.1692919318393; Thu, 24 Aug 2023 16:21:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692919318; cv=none; d=google.com; s=arc-20160816; b=1JJUJABtcC0YTXrKgPShR0WGc+i3mhQPONT79bD9GAv/gZgLcjYEF6Ek3fkaXWtHIi WuXnONE/TUHCeNBD9Iogcmkkn/bOUiu0Ku0VRCQP4LM+V3UPLjpfH6BvGwuy2oRIi9QY W0/AgNGVP290u5CpsmU375RW72rDxWo+iHRvpLnY3oe9Y62Qjp7A/WG8YO8Piv/vQy9r kPZYOraktQWpOJEzmC3xhfl5Ap8xTDXFcuBjvg03P9P9+B3npPW0acxU/6n6IguCOAI1 VA1VNPwFBoC0xG2J5TyMf4QXyNSTGEi1dhgON2qQdwfHuGxzAi9FbiRtwssAtxbNcb5m f0AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=upK8pduE+ia8h/lm8Rkjir2XDzdl5NivB0w/oR3kB40=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=YJxmiMJN7NK/ELyc7AtIEDkiKxfmUChcYcpgfgfKHf/C4aZ3hfiFiCsQ2Ou79YA5uK BsKsy4E+SxI1Oxp+15Sx86sS7gnuy4wIA7PPVIy5RKwxCLZl/0BEuXzLbF6rPnrdFtyu lg6wzuj0dumwSoimniQ1mx+F3cRa4LeC8Fcb3jPpKv6tLXqZ0mPfNWM23f4ZKZTDx/wk Fx2hVI3K5aWYumYkwyv9qmX4brDp1hjbTpPVlBuF9cCNly5fM6oVzIFGnsrZwEvX5n3n 0mnyZUueVPy3PfbmnTXd+a7n8Fdt8RXIXkCP8RgK/ClDNXlaXZzBwjuoPKttRIcJ2y4k hkvw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id lc8-20020a170906dfe800b00993689daad0si242294ejc.269.2023.08.24.16.21.57; Thu, 24 Aug 2023 16:21:58 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DF55B68C683; Fri, 25 Aug 2023 02:21:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E614968C53B for ; Fri, 25 Aug 2023 02:21:37 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 26953FF803 for ; Thu, 24 Aug 2023 23:21:36 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 25 Aug 2023 01:21:35 +0200 Message-Id: <20230824232135.26854-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230824232135.26854-1-michael@niedermayer.cc> References: <20230824232135.26854-1-michael@niedermayer.cc> X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/apedec: Fix CRC for 24bps and bigendian 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: X/UtIegaMcQh Fixes CRC for vlc.ape and APE_48K_24bit_2CH_02_01.ape Signed-off-by: Michael Niedermayer --- libavcodec/apedec.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c index cc0d7e2749..d48d3a676d 100644 --- a/libavcodec/apedec.c +++ b/libavcodec/apedec.c @@ -1592,13 +1592,24 @@ static int ape_decode_frame(AVCodecContext *avctx, AVFrame *frame, s->samples -= blockstodecode; if (avctx->err_recognition & AV_EF_CRCCHECK && - s->fileversion >= 3900 && s->bps < 24) { + s->fileversion >= 3900) { uint32_t crc = s->CRC_state; const AVCRC *crc_tab = av_crc_get_table(AV_CRC_32_IEEE_LE); + int stride = s->bps == 24 ? 4 : (s->bps>>3); + int offset = s->bps == 24; + int bytes = s->bps >> 3; + for (i = 0; i < blockstodecode; i++) { for (ch = 0; ch < s->channels; ch++) { - uint8_t *smp = frame->data[ch] + (i*(s->bps >> 3)); - crc = av_crc(crc_tab, crc, smp, s->bps >> 3); +#if HAVE_BIGENDIAN + uint8_t *smp_native = frame->data[ch] + i*stride; + uint8_t smp[4]; + for(int j = 0; jdata[ch] + i*stride; +#endif + crc = av_crc(crc_tab, crc, smp+offset, bytes); } }