From patchwork Wed Jul 10 03:56:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jai Luthra X-Patchwork-Id: 13885 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 5977D447829 for ; Wed, 10 Jul 2019 06:57:57 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3A23A68A95D; Wed, 10 Jul 2019 06:57:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3754C68A77E for ; Wed, 10 Jul 2019 06:57:49 +0300 (EEST) Received: by mail-pg1-f196.google.com with SMTP id i18so504686pgl.11 for ; Tue, 09 Jul 2019 20:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jailuthra-in.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=6geX9Vzy7spDKWNieCKOXK3rOoI9apOPeYaJwRcJhWE=; b=mbGThTF/0cb3sMUY3tphwECJglmN6LJEFk6dhg5QVKOsO7+KJC0IjWQkmclwQrCQzK pASEmvN0VaIPM5F+9+YdI7UUGg34+WGc4HyQvAWpH1bLWbRTr04za1MZiTnFhWRMfwtR 7rYhF92JsumcDaysSY1eIuQYc3Bw0/p0DAnUXuPxSMQWQXsOkdhBlxbjkIQ+1qc7Wswk vbLj7zm6DbhO+17rI9gBJ+Hz18NKgpyvAbrysK136eTT5hV3mudIzXg9UpDOOYcZgXgf I8t4gWu5QAfs4at0W4fI/SFbvS7wFpFHYJDkJLMT5UAWKs9fY3WLga1Gs4c15gsLEUXu w5Ow== 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:mime-version:content-transfer-encoding; bh=6geX9Vzy7spDKWNieCKOXK3rOoI9apOPeYaJwRcJhWE=; b=awVhrd1qr9nniuJPZcKFHwvkKOTgklsto7Vk6mS+noJL8MR+BKGPcpTMGcaZsWx0pN kE+kHNPhEdnM60XHPcOZo6kHv/yerEatRW6wDlzET0+/T/3oa9VMjXwz869+R+GsgbfZ 7u1eEi2Pz+aBAv/7krIgCQGzo42HE1X6spb5xACLCXnjMemMsu3wo/iB5gkYP6d/r5of HxNzrzRwsGAmDdQF/uW9eJFBLUXC4YssH521JrNuZs7weMQ77RWnCc4BozJ80c8sBv0X wCSSrGKgpzGopPSeIL5XXl1qMYadtBbeIlQb3gPGG/QqlCVZgOuMxgb8kXru9aeNj49D zmCg== X-Gm-Message-State: APjAAAWnZvR+5Jfj9D/znxqlF0P3gMWhAfpgwhStoYKwSlYwnEERpCrw MwG8Zs8SGFU47Sou7WSG+D67tf0M2Rg= X-Google-Smtp-Source: APXvYqzMljUgnQQ0tw43C7CedOrLXNmUSBHjl1jMvYwLYobTk5IgkVYzorBs6p5pZj0eLuK0pRrhsA== X-Received: by 2002:a17:90b:8c8:: with SMTP id ds8mr4233303pjb.89.1562731066879; Tue, 09 Jul 2019 20:57:46 -0700 (PDT) Received: from localhost.localdomain ([122.180.207.198]) by smtp.googlemail.com with ESMTPSA id r9sm1906215pjq.3.2019.07.09.20.57.45 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 09 Jul 2019 20:57:46 -0700 (PDT) From: Jai Luthra To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Jul 2019 09:26:38 +0530 Message-Id: <20190710035638.30961-1-me@jailuthra.in> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190709201901.26693-4-me@jailuthra.in> References: <20190709201901.26693-4-me@jailuthra.in> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/5 v2] mlpenc: improve lpc filtering 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" * fix a possible memory leak (apply_filter returned before freeing) * use apply_filters in process_major_frame * revert back to checking bounds with 24 bitdepth, as huff offset takes care of it Signed-off-by: Jai Luthra --- v2: remove unused variables in process_major_frame --- libavcodec/mlpenc.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c index 41030f6f07..3c2a57d81a 100644 --- a/libavcodec/mlpenc.c +++ b/libavcodec/mlpenc.c @@ -1799,7 +1799,7 @@ static void determine_bits(MLPEncodeContext *ctx) /** Applies the filter to the current samples, and saves the residual back * into the samples buffer. If the filter is too bad and overflows the - * maximum amount of bits allowed (16 or 24), the samples buffer is left as is and + * maximum amount of bits allowed (24), the samples buffer is left as is and * the function returns -1. */ static int apply_filter(MLPEncodeContext *ctx, unsigned int channel) @@ -1812,7 +1812,7 @@ static int apply_filter(MLPEncodeContext *ctx, unsigned int channel) unsigned int number_of_samples = ctx->number_of_samples; unsigned int filter_shift = fp[FIR]->shift; int filter; - int i; + int i, ret = 0; for (i = 0; i < NUM_FILTERS; i++) { unsigned int size = ctx->number_of_samples; @@ -1835,7 +1835,7 @@ static int apply_filter(MLPEncodeContext *ctx, unsigned int channel) int32_t sample = *sample_buffer; unsigned int order; int64_t accum = 0; - int32_t residual; + int64_t residual; for (filter = 0; filter < NUM_FILTERS; filter++) { int32_t *fcoeff = ctx->cur_channel_params[channel].coeff[filter]; @@ -1847,11 +1847,13 @@ static int apply_filter(MLPEncodeContext *ctx, unsigned int channel) accum >>= filter_shift; residual = sample - (accum & mask); - if (residual < SAMPLE_MIN(ctx->wordlength) || residual > SAMPLE_MAX(ctx->wordlength)) - return -1; + if (residual < SAMPLE_MIN(24) || residual > SAMPLE_MAX(24)) { + ret = -1; + goto free_and_return; + } filter_state_buffer[FIR][i] = sample; - filter_state_buffer[IIR][i] = residual; + filter_state_buffer[IIR][i] = (int32_t) residual; sample_buffer += ctx->num_channels; } @@ -1863,11 +1865,12 @@ static int apply_filter(MLPEncodeContext *ctx, unsigned int channel) sample_buffer += ctx->num_channels; } +free_and_return: for (i = 0; i < NUM_FILTERS; i++) { av_freep(&filter_state_buffer[i]); } - return 0; + return ret; } static void apply_filters(MLPEncodeContext *ctx) @@ -2198,9 +2201,6 @@ static void process_major_frame(MLPEncodeContext *ctx) ctx->number_of_samples = ctx->major_frame_size; for (substr = 0; substr < ctx->num_substreams; substr++) { - RestartHeader *rh = ctx->cur_restart_header; - unsigned int channel; - ctx->cur_restart_header = &ctx->restart_header[substr]; ctx->cur_decoding_params = &ctx->major_decoding_params[1][substr]; @@ -2209,8 +2209,7 @@ static void process_major_frame(MLPEncodeContext *ctx) generate_2_noise_channels(ctx); rematrix_channels (ctx); - for (channel = rh->min_channel; channel <= rh->max_channel; channel++) - apply_filter(ctx, channel); + apply_filters(ctx); } }