From patchwork Fri Jan 24 10:33:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jai Luthra X-Patchwork-Id: 17504 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 DA3EC44B5D2 for ; Fri, 24 Jan 2020 12:41:30 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C1FEE68B0A5; Fri, 24 Jan 2020 12:41:30 +0200 (EET) 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 40B2368AF07 for ; Fri, 24 Jan 2020 12:41:23 +0200 (EET) Received: by mail-pg1-f196.google.com with SMTP id q127so819209pga.4 for ; Fri, 24 Jan 2020 02:41:23 -0800 (PST) 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=epmLjV/ELk5tNqXa8sLT+7ONW1xY14ldT6KpRlIUkIs=; b=PezV1oJPIpuXmJhySkhzevYsU6a7tshq1gY0GPstYJMzbruowIRkMrCxlxV/i7vRkk oxuxfD7EcMjFIuDSibx/Z3Z+thIVDQi3INFnk0Kt/UouL68eurPX1mMUxG/mXZV+F++c sRuK1fCsYdNkHouO8BUPx836oYxjwhVFvBsXudw3i6lh+hCP7aiWVY2TUfS/VZhFdr3t xQqo0tr6gc3cTJH8KrdyJGHIqBc42QoGKicTx/lJXQ6cCe0Du+fGDESWG7lz3LDbZoHu lSNaKUrBooRV5lAVHA2STYHXhlJUqCiZet8UdSSl7toZh7D0LTD2wqozhYuQ6RnR9QE4 mPYA== 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=epmLjV/ELk5tNqXa8sLT+7ONW1xY14ldT6KpRlIUkIs=; b=o5yQHMg7ZME9yKGxeHPaZ3/DDTyeIk4R2knRaLiHpJuR/jLZ5eN7fwj19/XLPa1Yhq gqmToTGt5DRodu+RdzEmmHyfDUHqf44c6QmLeouGh7aNg8jPyMBzROlcz5yEYFCn1g79 6IqJfo52eAg3NYIM6XDc9BGuViUSc9HGmtl1WaUQ4xddfAG7vRmXAIF2fYhzfp5++nK9 a6+zbG2iQIuEW0fGbRbGp4E9uqV7gEm/2XKCuOh4ReNLZ4FCmHyCy5eHLjmw8oVnY65U NMQOXRp6LdFetYK9QzPsDRmSjNA2aPU8fU7ZJNXVDzuwS/ITnki8XfhHqva8qSfaRdGN wvIA== X-Gm-Message-State: APjAAAUoMM0UlTU/ugsbccvNFf1I05d5Zb3DssF6XK6AbGTsqtZMUQQs hazU842eb2wVOumVGCsi5mMjVe/zi1M= X-Google-Smtp-Source: APXvYqxtPtKnJPXqd4OkMGPZ8/lJf9FX6DfmASdZS3iIVz3XnV/EteXeynNV3iyFI/id/ftGGALw4A== X-Received: by 2002:a63:484b:: with SMTP id x11mr3403095pgk.148.1579862030492; Fri, 24 Jan 2020 02:33:50 -0800 (PST) Received: from localhost.localdomain ([49.207.55.142]) by smtp.googlemail.com with ESMTPSA id j125sm5471274pfg.160.2020.01.24.02.33.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 02:33:50 -0800 (PST) From: Jai Luthra To: ffmpeg-devel@ffmpeg.org Date: Fri, 24 Jan 2020 16:03:33 +0530 Message-Id: <20200124103334.110855-5-me@jailuthra.in> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124103334.110855-1-me@jailuthra.in> References: <20200124103334.110855-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 | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c index 41030f6f07..0e7a9b7640 100644 --- a/libavcodec/mlpenc.c +++ b/libavcodec/mlpenc.c @@ -1799,20 +1799,20 @@ 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) { FilterParams *fp[NUM_FILTERS] = { &ctx->cur_channel_params[channel].filter_params[FIR], &ctx->cur_channel_params[channel].filter_params[IIR], }; - int32_t *filter_state_buffer[NUM_FILTERS]; + int32_t *filter_state_buffer[NUM_FILTERS] = { NULL }; int32_t mask = MSB_MASK(ctx->cur_decoding_params->quant_step_size[channel]); int32_t *sample_buffer = ctx->sample_buffer + 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); } }