From patchwork Tue Jul 9 20:19:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jai Luthra X-Patchwork-Id: 13879 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 F21874483BB for ; Tue, 9 Jul 2019 23:19:33 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D51A868AB99; Tue, 9 Jul 2019 23:19:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AFA6168AB34 for ; Tue, 9 Jul 2019 23:19:26 +0300 (EEST) Received: by mail-pf1-f196.google.com with SMTP id q10so9830223pff.9 for ; Tue, 09 Jul 2019 13:19:26 -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=3zsl7giTPpj3yKWvcKRz1upNKXxBA/0oa0Ihm74UeKg=; b=Su+0NAa5MgHqO3s8wL1ZZe4IoDLNfOEM+Otg6P49QCIj8X2wZyhwHrp6Vw4UudcddO xE+Ep5LNdy/J3jehN7+THtmO0UIvu1/pk8cLqnHoUFXE1maQQVLBystI/NhkzL/RwS3D 2u6uGZ7T0Z94CmvFVHcGu2k/M/+aC702gRbj2FZcbItVEdQqxCVOJBX/swXFsXeN8VPa KQlinjJgSw2rWHuPlfPmvXnKUpohS8Z9E3I6VfgLSEnwlbQrzZFZnwalSMm6Y2v5bJ/W 6jD5rY/Gh/9lEzn8MI5EbzpDbOirFFKyhy5OzlMuW0Y0X+D2JHRoPjl2hJ1ms6EX4i3R dOtQ== 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=3zsl7giTPpj3yKWvcKRz1upNKXxBA/0oa0Ihm74UeKg=; b=HjKfXhmrOzzsVVIJiWYyRrSjzyYxMBRCI530LoyE7yjtFrzzvvrW4MkLiITsmPn1IF UEvP9kG4PeRPh7cqeu1/jjyW7HgTF/DIXRBcw4L7SAovlfApHXCz69I2azawWKSdeAWq hG0fxEGeZhxKzu3RbDtjFAhfD7llsz9flabVzNpcIQS6doLmb92ZcoUSoIMds89m+gIY JgMPigAJjhCaNbFHaOUmE+3pV9uptvQ2BayReacVm7PHHE5ZooOE4DbUx6kWO3Fs9s22 XOChq3NQZMeoJTKV1DiRg/OpChQ1Cw3x9EjaJPHw6Es5N6KbHjDErsz7l1NtQYsVaR65 RGBQ== X-Gm-Message-State: APjAAAXNEJHXFTvsW1vTDNDUmV+uGxwSnkHgbx9d91Jz8KJpXX6eJoYa FEI6pJ8WWC32T4W6/AQaZKYZLrESaUo= X-Google-Smtp-Source: APXvYqxK8/eKLUdwuY//ecBBHwwPU7F/zXhr+PCdTqAiad+m08vlkRyhyXqdjskDr+6eU8mdsd96kg== X-Received: by 2002:a17:90a:8a15:: with SMTP id w21mr2155057pjn.134.1562703564869; Tue, 09 Jul 2019 13:19:24 -0700 (PDT) Received: from localhost.localdomain ([122.180.207.198]) by smtp.googlemail.com with ESMTPSA id b126sm26212575pfa.126.2019.07.09.13.19.23 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 09 Jul 2019 13:19:24 -0700 (PDT) From: Jai Luthra To: ffmpeg-devel@ffmpeg.org Date: Wed, 10 Jul 2019 01:49:00 +0530 Message-Id: <20190709201901.26693-4-me@jailuthra.in> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190709201901.26693-1-me@jailuthra.in> References: <20190709201901.26693-1-me@jailuthra.in> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/5] 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 --- libavcodec/mlpenc.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c index 41030f6f07..9805e7ff23 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) @@ -2209,8 +2212,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); } }