From patchwork Tue Oct 6 00:17:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 22732 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 4C86F44AE80 for ; Tue, 6 Oct 2020 03:25:17 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 321BF68B57F; Tue, 6 Oct 2020 03:25:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 78B9A68B4FA for ; Tue, 6 Oct 2020 03:25:10 +0300 (EEST) Received: by mail-ed1-f65.google.com with SMTP id t21so8750139eds.6 for ; Mon, 05 Oct 2020 17:25:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=n6EyzLpD4o//VKmVgSELGGcnfQBjwH1a9Sv4BJDxL3E=; b=CyE0iaZrFHCWMcOW9+U3ZRpsiyj3kNl2e1bi9dBmqPrm0L8SsU5snL9tVxYoY7ujHx 43SyRov7ciHJLzp0SS2iBr9z5FRawtW8uJ4bcSSU4+otMdk0PQOGOO/DoVH6SBC6PRKt sHXDX9kGBEIUzHexAaEMnRmRsDy0R3fQxF0/eld/ybr+vAFBSPbxC4b9i++N7At7y4HX inFzvqEbJPtJT+zRNlUvUDP7MEKGHcGBvneC4JzDg/emnqLw9vuQK/EXY6rJdLfjliep Z2r8brQ9z6H8S/Kzs4awxzBqtEJRC7l1uYv81wBJL7PtBRGWtkcfiwY6I61BS1bnA4m1 3fiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=n6EyzLpD4o//VKmVgSELGGcnfQBjwH1a9Sv4BJDxL3E=; b=KxzrD+b/qaK+TdAQh57d9iH8LWhhCxVZqjPUF37mLMZBmg+5is/KnGfF4vfwuE80w5 r5Xr0Ai+2vFzh5oCSjKRkAUCAmJVT2y9Ip41kcclHTa3OUDpWgTVLAxD758AFF7DcVrl fq9DPe4gwORDzSmtpPi8TVrc8sfNF+UHzqRyHtvB7pkniWDh835oiftobrXIkr6DgQw6 bCIg+ECoNPO8ntTVXVakYN9UrknitrXIqGeT/A3xe5/UrcB/n6MjOldC5OATXuGrER+G Q5VDGE88h3WRGpkOh/TssvTWXkcDJ/tDG/rFV34wyEx73QjdczWL3c3XXEr5bTs9L3R7 P+tA== X-Gm-Message-State: AOAM531H92Betm83lct+zleRe/VLdqp0NsFSb11HgcElCKqQowDw7eHU HKzZqLibxbajPdIbJBc3BfL4d5ctwvVWFQ== X-Google-Smtp-Source: ABdhPJzBymDJAoD/xGnDXczWGJJIRLEXE63oUENE+ah5v2AmXUaYNQ2j97/gMvk8j2SOIA2HlOkfCg== X-Received: by 2002:a05:6402:2055:: with SMTP id bc21mr2392413edb.67.1601943445242; Mon, 05 Oct 2020 17:17:25 -0700 (PDT) Received: from localhost.localdomain ([109.227.55.37]) by smtp.gmail.com with ESMTPSA id q12sm1017137edj.19.2020.10.05.17.17.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Oct 2020 17:17:23 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Tue, 6 Oct 2020 02:17:11 +0200 Message-Id: <20201006001714.19577-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/4] avcodec/apedec: fix decoding insane files with recent versions 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- libavcodec/apedec.c | 59 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c index c76c0509df..273abe2490 100644 --- a/libavcodec/apedec.c +++ b/libavcodec/apedec.c @@ -133,6 +133,21 @@ 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 @@ -152,6 +167,7 @@ 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; @@ -789,13 +805,20 @@ 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) { @@ -813,8 +836,11 @@ 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)); @@ -826,7 +852,13 @@ 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) */ @@ -1132,16 +1164,17 @@ static void predictor_decode_mono_3930(APEContext *ctx, int count) } } -static av_always_inline int predictor_update_filter(APEPredictor *p, +static av_always_inline int predictor_update_filter(APEPredictor64 *p, const int decoded, const int filter, const int delayA, const int delayB, const int adaptA, const int adaptB) { - int32_t predictionA, predictionB, sign; + int64_t predictionA, predictionB; + int32_t sign; p->buf[delayA] = p->lastA[filter]; p->buf[adaptA] = APESIGN(p->buf[delayA]); - p->buf[delayA - 1] = p->buf[delayA] - (unsigned)p->buf[delayA - 1]; + p->buf[delayA - 1] = p->buf[delayA] - (uint64_t)p->buf[delayA - 1]; p->buf[adaptA - 1] = APESIGN(p->buf[delayA - 1]); predictionA = p->buf[delayA ] * p->coeffsA[filter][0] + @@ -1150,9 +1183,9 @@ static av_always_inline int predictor_update_filter(APEPredictor *p, p->buf[delayA - 3] * p->coeffsA[filter][3]; /* Apply a scaled first-order filter compression */ - p->buf[delayB] = p->filterA[filter ^ 1] - ((int)(p->filterB[filter] * 31U) >> 5); + p->buf[delayB] = p->filterA[filter ^ 1] - ((int64_t)(p->filterB[filter] * 31ULL) >> 5); p->buf[adaptB] = APESIGN(p->buf[delayB]); - p->buf[delayB - 1] = p->buf[delayB] - (unsigned)p->buf[delayB - 1]; + p->buf[delayB - 1] = p->buf[delayB] - (uint64_t)p->buf[delayB - 1]; p->buf[adaptB - 1] = APESIGN(p->buf[delayB - 1]); p->filterB[filter] = p->filterA[filter ^ 1]; @@ -1162,8 +1195,8 @@ static av_always_inline int predictor_update_filter(APEPredictor *p, p->buf[delayB - 3] * p->coeffsB[filter][3] + p->buf[delayB - 4] * p->coeffsB[filter][4]; - p->lastA[filter] = decoded + ((int)((unsigned)predictionA + (predictionB >> 1)) >> 10); - p->filterA[filter] = p->lastA[filter] + ((int)(p->filterA[filter] * 31U) >> 5); + 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); sign = APESIGN(decoded); p->coeffsA[filter][0] += p->buf[adaptA ] * sign; @@ -1181,7 +1214,7 @@ static av_always_inline int predictor_update_filter(APEPredictor *p, static void predictor_decode_stereo_3950(APEContext *ctx, int count) { - APEPredictor *p = &ctx->predictor; + APEPredictor64 *p = &ctx->predictor64; int32_t *decoded0 = ctx->decoded[0]; int32_t *decoded1 = ctx->decoded[1]; @@ -1210,7 +1243,7 @@ static void predictor_decode_stereo_3950(APEContext *ctx, int count) static void predictor_decode_mono_3950(APEContext *ctx, int count) { - APEPredictor *p = &ctx->predictor; + APEPredictor64 *p = &ctx->predictor64; int32_t *decoded0 = ctx->decoded[0]; int32_t predictionA, currentA, A, sign; @@ -1222,14 +1255,14 @@ static void predictor_decode_mono_3950(APEContext *ctx, int count) A = *decoded0; p->buf[YDELAYA] = currentA; - p->buf[YDELAYA - 1] = p->buf[YDELAYA] - (unsigned)p->buf[YDELAYA - 1]; + p->buf[YDELAYA - 1] = p->buf[YDELAYA] - (uint64_t)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 + (unsigned)(predictionA >> 10); + currentA = A + (uint64_t)(predictionA >> 10); p->buf[YADAPTCOEFFSA] = APESIGN(p->buf[YDELAYA ]); p->buf[YADAPTCOEFFSA - 1] = APESIGN(p->buf[YDELAYA - 1]); @@ -1249,7 +1282,7 @@ static void predictor_decode_mono_3950(APEContext *ctx, int count) p->buf = p->historybuffer; } - p->filterA[0] = currentA + (unsigned)((int)(p->filterA[0] * 31U) >> 5); + p->filterA[0] = currentA + (uint64_t)((int64_t)(p->filterA[0] * 31U) >> 5); *(decoded0++) = p->filterA[0]; } @@ -1286,7 +1319,7 @@ static void do_apply_filter(APEContext *ctx, int version, APEFilter *f, f->delay - order, f->adaptcoeffs - order, order, APESIGN(*data)); - res = (int)(res + (1U << (fracbits - 1))) >> fracbits; + res = (int64_t)(res + (1LL << (fracbits - 1))) >> fracbits; res += (unsigned)*data; *data++ = res; From patchwork Tue Oct 6 00:17:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 22734 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 4E0E944A987 for ; Tue, 6 Oct 2020 04:11:48 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2D10868B534; Tue, 6 Oct 2020 04:11:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f65.google.com (mail-lf1-f65.google.com [209.85.167.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4676C68A173 for ; Tue, 6 Oct 2020 04:11:42 +0300 (EEST) Received: by mail-lf1-f65.google.com with SMTP id h6so6346605lfj.3 for ; Mon, 05 Oct 2020 18:11:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=WQPv2+cWcli7wuZGVv5u/KMdgxfa//yozY24jnPeGhw=; b=EGPrTlRMumB0T682zFXDf80dSJVYgs/FFNBh2/MYeQqzH3O3e8HglDufWfz0nmOvwR qAh+3NRwRhQXzr3uBhnwX3DcasIu/qrECsP4cE5Q6EZcD/PM9jdUIjczOwlq6VaUrGJg o4jGEpD7iBjXh6GrekRxKBxusB3R4FXZfBMuea7rNeFrb7aQjN8md7epvika0Qs2Be2k rHI4TlnUB2RwYUlTmOrUXEVY/p9jAoRbT/D+5WHwWi8G7OqfxZJQLUuIKpLzE9whk9OR 43dWZAWL98stBMHTubetGADvJ9K1EtAOdRn/hTE5iFB4DyUghHCifS8MG1MRtWmalet/ OJYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=WQPv2+cWcli7wuZGVv5u/KMdgxfa//yozY24jnPeGhw=; b=jXV/ZOeMptugVMeP83CoMJLNAMmDRQyJX86iIylzmtOJD/GwdKxrlesds1/T6GTvxO 3HVozrI3IFM3ojtNmNdnrXdolBo31xvC3p/vrw+QFCpDP2E1opQ8ZCpU8kW4W7ulauzB 7f7Iwhh11Wpz0VTlMHlIY4o+y+feqBD8oEln+dxSj9yhroTqEBou7bYOGZZGZhD8mnUo HoKcY9K34TurIXHbcRIc2Zi8g3/sTAFNka0HoSCn7AeHT/4JRfbL7biRTVQjtSmFKrRM a+dIDYtLqF+sNqhZsAoj6z2B5ROtzuciKj3Cbbleyd0OQsBPu3TG2+yDqjTIa1Dl+q/Y +6Xw== X-Gm-Message-State: AOAM5328/zlRrkjEWtT2iLXlhTwkULdqlAgqigCXBwnlF8WlkIiH71Ir kwgXm1DmczR5qe1AtPjpCTOTDufZE6x8TA== X-Google-Smtp-Source: ABdhPJz8d/mQGhKlIgDVuE/LAfnKUaCA3DpEvEvH7gFxcy/c8xKWlhgiBvRHdeQUJkei7zUlpi2PDw== X-Received: by 2002:aa7:dac4:: with SMTP id x4mr2388395eds.165.1601943447054; Mon, 05 Oct 2020 17:17:27 -0700 (PDT) Received: from localhost.localdomain ([109.227.55.37]) by smtp.gmail.com with ESMTPSA id q12sm1017137edj.19.2020.10.05.17.17.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Oct 2020 17:17:25 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Tue, 6 Oct 2020 02:17:12 +0200 Message-Id: <20201006001714.19577-2-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201006001714.19577-1-onemda@gmail.com> References: <20201006001714.19577-1-onemda@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/4] avcodec/apedec: properly calculate and store absolute value 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- libavcodec/apedec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c index 273abe2490..aa4d8fa524 100644 --- a/libavcodec/apedec.c +++ b/libavcodec/apedec.c @@ -1311,7 +1311,7 @@ static void do_apply_filter(APEContext *ctx, int version, APEFilter *f, int32_t *data, int count, int order, int fracbits) { int res; - int absres; + unsigned absres; while (count--) { /* round fixedpoint scalar product */ @@ -1335,7 +1335,7 @@ static void do_apply_filter(APEContext *ctx, int version, APEFilter *f, /* Version 3.98 and later files */ /* Update the adaption coefficients */ - absres = res < 0 ? -(unsigned)res : res; + absres = FFABS(res); if (absres) *f->adaptcoeffs = APESIGN(res) * (8 << ((absres > f->avg * 3) + (absres > f->avg * 4 / 3))); From patchwork Tue Oct 6 00:17:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 22731 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 64191440240 for ; Tue, 6 Oct 2020 03:25:03 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 39BD268B368; Tue, 6 Oct 2020 03:25:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C75A768B368 for ; Tue, 6 Oct 2020 03:24:56 +0300 (EEST) Received: by mail-ed1-f67.google.com with SMTP id k14so11511048edo.1 for ; Mon, 05 Oct 2020 17:24:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=YJdSqtxUEX4WxNoWoyLp6I9uAAHcD14+ofW7HRXg2yU=; b=vaLueIwSkmEUUMEWY6zD9UoyC8XlS7vv6adfhQZDNZ6C6C4yY9kyqP2XhdqlAcIRF/ NlEZFeiTF8P3cDlpTURHQOelFbbxABn8h+fCrX5Tss6AGTdKcg5OpBMQzOV4OfFsAFtA EsTxq05Nj9iis5VMAE94f6ruWPHa64NIRkKIgdoISVKaIULsJXQIPOl6al37/ElSO2ID SnhTYysRuI4ME445DrjYoisTsfo2kFS8LmyOIm0Atx/W5n6Q7WKQx0PNBdxuZOTVj6au dRW5ZMJfOi3H3qd1LGr9UOqMJyVMDxEiPRUkhivnsU8zlmv1rqqCxb2JeG+MeBj5KEaD 8kDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=YJdSqtxUEX4WxNoWoyLp6I9uAAHcD14+ofW7HRXg2yU=; b=MUlMOfUT0DXm6Hk/mOQzv93/8Cb1O1+zBtvBEh/ndyE3rDPVPW39CLuRRzGPSa5nnA NW9dAg5AXtPeKyOSQIgDtglDx9kAmCEvB0pqtKVfbQAWl7uvXoEnA8y8aOWefIRF6SqA hNNAmK1PT3eC03T9Z1ihJ8+LiE3fnKAnhM/Qx0r9RvnjZaLLNhFRpVO6iey75P1sjrqr 1YmqbCRz79FCy3leyubxmUjuu4Nt/xil//dYv7OjXlKVTo+zdF65jVKnttAe00FLd0In wnGpKYukG9CeBlbZR2ncRa5UtJQxT0/2HYjovN/5NS6/Z1TdEOiJBdYSHVS9EZY0S9RN J9PA== X-Gm-Message-State: AOAM5334DWg8g3wvM4C5RGML1/poGRj7Cx4xQAWU7dBrv2CDLH2pmcQ2 IIbtJiZEdJJho0x0drk7lURB0GvZ3D6BDw== X-Google-Smtp-Source: ABdhPJxoMv156RduYn+/OC0eaSp3/PdXvYmZ8mjUH8AKAJ4VO/AJJkUflfkrIKGw0Fwt5q28ZR4/UQ== X-Received: by 2002:a05:6402:b64:: with SMTP id cb4mr2462608edb.25.1601943448942; Mon, 05 Oct 2020 17:17:28 -0700 (PDT) Received: from localhost.localdomain ([109.227.55.37]) by smtp.gmail.com with ESMTPSA id q12sm1017137edj.19.2020.10.05.17.17.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Oct 2020 17:17:27 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Tue, 6 Oct 2020 02:17:13 +0200 Message-Id: <20201006001714.19577-3-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201006001714.19577-1-onemda@gmail.com> References: <20201006001714.19577-1-onemda@gmail.com> Subject: [FFmpeg-devel] [PATCH 3/4] avcodec/apedec: use proper macro and type for pivot variable 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- libavcodec/apedec.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c index aa4d8fa524..8fe7b5ee86 100644 --- a/libavcodec/apedec.c +++ b/libavcodec/apedec.c @@ -559,12 +559,10 @@ static inline int ape_decode_value_3900(APEContext *ctx, APERice *rice) static inline int ape_decode_value_3990(APEContext *ctx, APERice *rice) { - unsigned int x, overflow; - int base, pivot; + unsigned int x, overflow, pivot; + int base; - pivot = rice->ksum >> 5; - if (pivot == 0) - pivot = 1; + pivot = FFMAX(rice->ksum >> 5, 1); overflow = range_get_symbol(ctx, counts_3980, counts_diff_3980); From patchwork Tue Oct 6 00:17:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 22733 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 051C244AFB4 for ; Tue, 6 Oct 2020 03:45:47 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D622968B4FA; Tue, 6 Oct 2020 03:45:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f66.google.com (mail-ej1-f66.google.com [209.85.218.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2A0256880CA for ; Tue, 6 Oct 2020 03:45:40 +0300 (EEST) Received: by mail-ej1-f66.google.com with SMTP id ly6so13622436ejb.8 for ; Mon, 05 Oct 2020 17:45:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=tSx3NaWBugiWH0vNshnPN0ogttOXydpAht5PG3TJtr8=; b=kHz+AIVzQNaZ8lTwbw3zNwrUD00T6ThG7JHPnZ3Ti8ryfw2Cluc45dBwRQMmuk3378 HJlVT+cuS6jaXenjPj+KLzooEB5FC303UOjjzpEbWCg5dTXs/Hjo+zwbFyijuCWNAsHL 0QGRQ1NP+e/zyqSXMM+HPRRhODraN8L5Y54Y91UP1N6SHcJrjWKve/YrUZ9D432/9C54 UWhyfdsmp35sjsKmoRA5B1AeyoQC2+so7PCz9xcIhWSj69sX66inJq7t+pV4ekE3XWsF DVApqQ2l03JMGzNkxguNAs2Q3VSwZ1SECJSZOnx+/6mIe5blw3UEeD3VPqNwbc56DBXD KC5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=tSx3NaWBugiWH0vNshnPN0ogttOXydpAht5PG3TJtr8=; b=OeSLeKGn7zCxG0hehVQaXAj/nvdqrbgIUDXO+m75tMTHZpJSe1KVPnaLnAHkqCl6bo fQqgynw9P6H4hfnxRERbOjX7Ihl1GWOXnfuDXZeBBIsE4Yk/SmqIGz26eUHQmx87yq9M Ym1vbtkv3AJax8wJ+1dWeCB+ApVaEFFYktA23CupBJ+W5iD6lnTpR77hhISas7Nn8zLV 3ubCiIpreUXXaPUiiyB/uf9G7Ik5A0cvMmDrw89TbB4HtLCboBKang/GrncdGBFxagkh WYLAorILXppPS3t32Q4B5n6z+6CepkN94Sm2c6ng3byDNDjBS84sJEI11i+Jqj+WL2M0 g5ig== X-Gm-Message-State: AOAM533AEd4BBzLM4Akk9eKvOK4sacrC4DpC+xBPtdyC5yw+C7V6hDWt JIoLeozkAFnveRrdz9Lg2kJ+3kz3hZsx8w== X-Google-Smtp-Source: ABdhPJywKwdatP7vKpJydN8tJCsWvA0ssSr/mlQ/BRctEud1gaO4wn4Q2UTjNzv0mEjVxYconPUjkw== X-Received: by 2002:a05:6402:31b3:: with SMTP id dj19mr389275edb.210.1601943450955; Mon, 05 Oct 2020 17:17:30 -0700 (PDT) Received: from localhost.localdomain ([109.227.55.37]) by smtp.gmail.com with ESMTPSA id q12sm1017137edj.19.2020.10.05.17.17.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Oct 2020 17:17:29 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Tue, 6 Oct 2020 02:17:14 +0200 Message-Id: <20201006001714.19577-4-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201006001714.19577-1-onemda@gmail.com> References: <20201006001714.19577-1-onemda@gmail.com> Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/apedec: use ff_clz() instead of while loop 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- libavcodec/apedec.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c index 8fe7b5ee86..ea36247eb9 100644 --- a/libavcodec/apedec.c +++ b/libavcodec/apedec.c @@ -575,14 +575,10 @@ static inline int ape_decode_value_3990(APEContext *ctx, APERice *rice) base = range_decode_culfreq(ctx, pivot); range_decode_update(ctx, 1, base); } else { - int base_hi = pivot, base_lo; - int bbits = 0; + int base_hi, base_lo; + int bbits = 16 - ff_clz(pivot); - while (base_hi & ~0xFFFF) { - base_hi >>= 1; - bbits++; - } - base_hi = range_decode_culfreq(ctx, base_hi + 1); + base_hi = range_decode_culfreq(ctx, (pivot >> bbits) + 1); range_decode_update(ctx, 1, base_hi); base_lo = range_decode_culfreq(ctx, 1 << bbits); range_decode_update(ctx, 1, base_lo);