From patchwork Tue Nov 3 17:57:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23360 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 EC01744B434 for ; Tue, 3 Nov 2020 19:58:05 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D418D68B63E; Tue, 3 Nov 2020 19:58:05 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D042D68B615 for ; Tue, 3 Nov 2020 19:57:58 +0200 (EET) Received: by mail-wr1-f68.google.com with SMTP id x7so19486131wrl.3 for ; Tue, 03 Nov 2020 09:57:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+ZgoN8AMigyvmp310c3BPDkz+dwb8Mfx+ZKLReZjEOI=; b=sDATj/ub1D8GEzv9dJzXFYV0BE5w8zunQqhG0Ejq+YjBWuLXDQLXMtLr9NBNfQ4YKi Agqab5dha1HHe68/QqxJQn0raVUNwR+A7LETVt0pqETMJ3b8kiemsKCPvPHIYMbpiLfT jry4kdyuERNdgsDJzdRuZ1YUIzqybC0L/TLDojFwpF3ixCHlZ/VPQ62K5o0oa9H1n0F9 Yvvl1BpcIEep4Gp9M8l/ysvLmtOvY9b7qq90dUwHj4cqpZ/POHYEwkBSfDqwiNT+2+Ii WYhAFA+s8eto/1TQti9z7wQ2+UHm9MhtoXQ7jDK+r0DlSkobNXz6ZttpYMSNXGtG2NLG yZFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+ZgoN8AMigyvmp310c3BPDkz+dwb8Mfx+ZKLReZjEOI=; b=Qb3RaZ+QqlhJ8kBCXI9kyvWiRxKV+lWo2qjEI5GjZT7DBVK9mUUtwHlcIZFcnLrLtB f9pbiTdaz6Z/OSA8B1UznZaxu0BRdZfDmTl8d7lCgfam210154b8Le4HBKXUzRM4LML5 V4GvbbL3tq2qNzxNXqDRAbcNZw3XlG4KHTxVEZwnsX0EWg/HN0+N+k45ciH+YuKUHIUU pub/XhOIUSEa/ED2hPOmWhI7EyNouialeVqUR3yULwaZLsY4nob+DIEUMQZ5MZRR8XNm fs87sMWrTYBi+NLHihAt6U2ghlBCGFCNInTIJZDsM0FK1G8w56luqQOtwZdX/HXZLa1M GRQA== X-Gm-Message-State: AOAM5321RxfNDHOSLxuMvE6tDWKdeQRZueDZkyx4T7WeXJyd0FAGD0zU +yyUuhsq+xtuoo7IeU40G57qvIX3Nek= X-Google-Smtp-Source: ABdhPJy8j04fN/WYMS6uAs2FHdH1SgFEVSKZDr2w4AOfp4jCEL+MGUGS8a9b/q6xh3nYiBwW5gHLBQ== X-Received: by 2002:a5d:5748:: with SMTP id q8mr27513535wrw.299.1604426278171; Tue, 03 Nov 2020 09:57:58 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id n8sm3586453wmc.11.2020.11.03.09.57.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 09:57:57 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Nov 2020 18:57:30 +0100 Message-Id: <20201103175735.170080-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201103175735.170080-1-andreas.rheinhardt@gmail.com> References: <20201103175735.170080-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/7] avcodec/sonic: Don't allocate a temporary buffer for every frame 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Instead allocate it together with the buffer that it mirrors. Signed-off-by: Andreas Rheinhardt --- libavcodec/sonic.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/libavcodec/sonic.c b/libavcodec/sonic.c index bca1eca27a..db2c4339a3 100644 --- a/libavcodec/sonic.c +++ b/libavcodec/sonic.c @@ -500,14 +500,11 @@ static int predictor_calc_error(int *k, int *state, int order, int error) // copes better with quantization, and calculates the // actual whitened result as it goes. -static int modified_levinson_durbin(int *window, int window_entries, +static void modified_levinson_durbin(int *window, int window_entries, int *out, int out_entries, int channels, int *tap_quant) { int i; - int *state = av_calloc(window_entries, sizeof(*state)); - - if (!state) - return AVERROR(ENOMEM); + int *state = window + window_entries; memcpy(state, window, 4* window_entries); @@ -571,9 +568,6 @@ static int modified_levinson_durbin(int *window, int window_entries, } #endif } - - av_free(state); - return 0; } static inline int code_samplerate(int samplerate) @@ -665,7 +659,7 @@ static av_cold int sonic_encode_init(AVCodecContext *avctx) s->int_samples = av_calloc(s->frame_size, sizeof(*s->int_samples)); s->window_size = ((2*s->tail_size)+s->frame_size); - s->window = av_calloc(s->window_size, sizeof(*s->window)); + s->window = av_calloc(s->window_size, 2 * sizeof(*s->window)); if (!s->window || !s->int_samples) return AVERROR(ENOMEM); @@ -776,10 +770,8 @@ static int sonic_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, s->tail[i] = s->int_samples[s->frame_size - s->tail_size + i]; // generate taps - ret = modified_levinson_durbin(s->window, s->window_size, + modified_levinson_durbin(s->window, s->window_size, s->predictor_k, s->num_taps, s->channels, s->tap_quant); - if (ret < 0) - return ret; if ((ret = intlist_write(&c, state, s->predictor_k, s->num_taps, 0)) < 0) return ret;