From patchwork Tue Nov 3 17:57:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23359 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 D92C044B2DE for ; Tue, 3 Nov 2020 19:57:50 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B62F068B5C5; Tue, 3 Nov 2020 19:57:50 +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 F348D68A7F4 for ; Tue, 3 Nov 2020 19:57:43 +0200 (EET) Received: by mail-wr1-f68.google.com with SMTP id n18so19457838wrs.5 for ; Tue, 03 Nov 2020 09:57:43 -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:mime-version :content-transfer-encoding; bh=Sy5OMDDdK/EC70QdMREV6AxxGIstDJm1Pz0cT7ak6jY=; b=gA73MtnKajTpKdKx5MdwVzsNQX/vpYV2Rb/SZhQJmIEJpum+27U2awCEp7FQYxg5Ad E9+oCoKPToNPkuai7xjzJecaMCjrUqMH6jiB54hfwdBKEAX4bCzvlDY1+JnICwZ7z1v2 hswMyWjWbFBdH/Io0aNVPVaUFtI9U2feK8GY9IVG1oUbUpXnl7BQjmCogiGs2f5XpAd+ XEJkWTMBEF3SFS+TAGeU3agwY79VB0eF03YgxO+9jqyN4W29OIiTzeUpLdhFfzaqZJ6I t/QxQSypriipWV6AbOKzne+Kdj5Q2c1geyMEavSWznwl/4cOHFQ38lRnR3WmX2vfKrlJ CaAA== 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:mime-version :content-transfer-encoding; bh=Sy5OMDDdK/EC70QdMREV6AxxGIstDJm1Pz0cT7ak6jY=; b=TfNU1kP/jLr3bgxKuHHtvJVSu6DPG3onUyYWapWwLXQZxqM2wQ6DIeLpzL+KNBmJb9 PhvB22/ywvGYMM69E9KfqLDHxwxcjVrurqNmWGxDDONNYgmUihSVr8E45dL4sidOSMRh qXE5LEyIpXMt6mQkcplE5+GfLCzFFos+TCJ6dhCjYuhUgMMDfFW6CW1jQFPaAy9mi4rt PhmoonRB4WOQ1bOz49VSUzbq4ndGp0C/ezK/fUNz13oY+/lv1suluDm73agO4QDdPKSl cTz51Ww/iOjIdFNUSoteGYzI4L0ksrE3NQWjD1OVkglXTqfHP8Aod5QsKCoAxV93Tb2+ u9gg== X-Gm-Message-State: AOAM530z1PQKr0Byq/S/OFltBu1ToXOWmmtbNby1cas8TULEv6Zhy8jX n3eQeO64Y0WkzQvtuudlrbu4E4CEkD8= X-Google-Smtp-Source: ABdhPJwf62b+qVgIKioJ4feqr1Daa0/5HTEOeUNp0gD64MGDRL3daAD4n1ITOKYotBgVNb7qpHeu0Q== X-Received: by 2002:a5d:4148:: with SMTP id c8mr27246013wrq.261.1604426263165; Tue, 03 Nov 2020 09:57:43 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 09:57:42 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Nov 2020 18:57:29 +0100 Message-Id: <20201103175735.170080-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/7] avcodec/sonic: Allocate several buffers together 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" It simplifies freeing them and reduces the amount of allocations. Signed-off-by: Andreas Rheinhardt --- libavcodec/sonic.c | 48 ++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/libavcodec/sonic.c b/libavcodec/sonic.c index 0d4891ebf4..bca1eca27a 100644 --- a/libavcodec/sonic.c +++ b/libavcodec/sonic.c @@ -596,6 +596,7 @@ static inline int code_samplerate(int samplerate) static av_cold int sonic_encode_init(AVCodecContext *avctx) { SonicContext *s = avctx->priv_data; + int *coded_samples; PutBitContext pb; int i; @@ -655,12 +656,11 @@ static av_cold int sonic_encode_init(AVCodecContext *avctx) if (!s->predictor_k) return AVERROR(ENOMEM); - for (i = 0; i < s->channels; i++) - { - s->coded_samples[i] = av_calloc(s->block_align, sizeof(**s->coded_samples)); - if (!s->coded_samples[i]) - return AVERROR(ENOMEM); - } + coded_samples = av_calloc(s->block_align, s->channels * sizeof(**s->coded_samples)); + if (!coded_samples) + return AVERROR(ENOMEM); + for (i = 0; i < s->channels; i++, coded_samples += s->block_align) + s->coded_samples[i] = coded_samples; s->int_samples = av_calloc(s->frame_size, sizeof(*s->int_samples)); @@ -706,11 +706,8 @@ static av_cold int sonic_encode_init(AVCodecContext *avctx) static av_cold int sonic_encode_close(AVCodecContext *avctx) { SonicContext *s = avctx->priv_data; - int i; - - for (i = 0; i < s->channels; i++) - av_freep(&s->coded_samples[i]); + av_freep(&s->coded_samples[0]); av_freep(&s->predictor_k); av_freep(&s->tail); av_freep(&s->tap_quant); @@ -859,6 +856,7 @@ static const int samplerate_table[] = static av_cold int sonic_decode_init(AVCodecContext *avctx) { SonicContext *s = avctx->priv_data; + int *tmp; GetBitContext gb; int i; int ret; @@ -951,19 +949,18 @@ static av_cold int sonic_decode_init(AVCodecContext *avctx) s->predictor_k = av_calloc(s->num_taps, sizeof(*s->predictor_k)); - for (i = 0; i < s->channels; i++) - { - s->predictor_state[i] = av_calloc(s->num_taps, sizeof(**s->predictor_state)); - if (!s->predictor_state[i]) - return AVERROR(ENOMEM); - } + tmp = av_calloc(s->num_taps, s->channels * sizeof(**s->predictor_state)); + if (!tmp) + return AVERROR(ENOMEM); + for (i = 0; i < s->channels; i++, tmp += s->num_taps) + s->predictor_state[i] = tmp; + + tmp = av_calloc(s->block_align, s->channels * sizeof(**s->coded_samples)); + if (!tmp) + return AVERROR(ENOMEM); + for (i = 0; i < s->channels; i++, tmp += s->block_align) + s->coded_samples[i] = tmp; - for (i = 0; i < s->channels; i++) - { - s->coded_samples[i] = av_calloc(s->block_align, sizeof(**s->coded_samples)); - if (!s->coded_samples[i]) - return AVERROR(ENOMEM); - } s->int_samples = av_calloc(s->frame_size, sizeof(*s->int_samples)); if (!s->int_samples) return AVERROR(ENOMEM); @@ -975,15 +972,12 @@ static av_cold int sonic_decode_init(AVCodecContext *avctx) static av_cold int sonic_decode_close(AVCodecContext *avctx) { SonicContext *s = avctx->priv_data; - int i; av_freep(&s->int_samples); av_freep(&s->tap_quant); av_freep(&s->predictor_k); - for (i = 0; i < MAX_CHANNELS; i++) { - av_freep(&s->predictor_state[i]); - av_freep(&s->coded_samples[i]); - } + av_freep(&s->predictor_state[0]); + av_freep(&s->coded_samples[0]); return 0; } 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; From patchwork Tue Nov 3 17:57:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23361 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 B212F44B434 for ; Tue, 3 Nov 2020 19:58:07 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 970D268B636; Tue, 3 Nov 2020 19:58:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DE28668B615 for ; Tue, 3 Nov 2020 19:57:59 +0200 (EET) Received: by mail-wm1-f66.google.com with SMTP id e2so184763wme.1 for ; Tue, 03 Nov 2020 09:57:59 -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=ufa1U/mZtqdWPDV1ROEzycmExnjYa0iB+TDGvsWBF3U=; b=UFMsb85TYpTpuoqOgHUaNvnKzuKvfJTQ7oJohXGxMngbI83xMAaiIDtZ6OcgIl/a82 jojh2SMYyk26fZLKrkVGH0y4uQXkCnCLtZwNH+T1H/EbhW4JF5uyyrFey/yRVot704Ez bQ+hme6gKIJOujp5Dhuu1m55GUuB/77lX2A1kG3DLY6zcMGhIjgo/hlNQC+9ZQ7YdcJ7 dpT4BSvA115isHa12e33WfmBv3t9DvTQCjWN2TpTsub5JhmuidYakaIVYRP9bCBLXcNZ KnOKxcRmmT3UL1nwrgn9U/ikdyrbV1q2Ma7CZW3gsu/OBey6F0awg6nFCcAL6n9cdPJw mmaw== 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=ufa1U/mZtqdWPDV1ROEzycmExnjYa0iB+TDGvsWBF3U=; b=pSTnUdkPat3phjjva7jHtqj6chZ0UeXqKe8gYTwwjP/xLEeiQvF+XuRj/aGTraRbSx o8AZbEARNtfUMSroafrS28+YOzrL9gqdi9AvDxrRZ/0f4JgrHg+dz/hCPKBW39BWPUmk EE1XGtEOmLxJj0bo41wDo4mSqz0ztf8E+8sM7ZcSm2Ccge7l1/FrpxMvFj7vB0uoAgCL 7k00VP7/ssIQOc57SFQoVxZ5bL1I77HE5cuXPqBJpNASlPkWh9ZbrJLUY/D95nFPbCGB ibB4qxZxJ5USCASyrNIjgWYsTOlLjqtMvPw2DFE513RPPY2ClnGoAeFJVBVf+bPbFAlt vD7A== X-Gm-Message-State: AOAM531fc0J4gScwrEWhdnKOWeXpQkgpa6EuRSv/BZ5eLLu2Zw8QCSPv /+glBr+Y6hP2m9kTgSlx87gIe/+5OW4= X-Google-Smtp-Source: ABdhPJz9pfOaAhNbwDXVuVcc8AEFNBgc3NkJ+DO7FNEMJvvPCpqOAUYvo1HUpfUc6Aec/xmnvVbE9g== X-Received: by 2002:a7b:c387:: with SMTP id s7mr366601wmj.52.1604426279090; Tue, 03 Nov 2020 09:57:59 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 09:57:58 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Nov 2020 18:57:31 +0100 Message-Id: <20201103175735.170080-3-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 3/7] avcodec/sonic: Don't hardcode sizeof(int) == 4 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" Signed-off-by: Andreas Rheinhardt --- libavcodec/sonic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/sonic.c b/libavcodec/sonic.c index db2c4339a3..a285228bbc 100644 --- a/libavcodec/sonic.c +++ b/libavcodec/sonic.c @@ -506,7 +506,7 @@ static void modified_levinson_durbin(int *window, int window_entries, int i; int *state = window + window_entries; - memcpy(state, window, 4* window_entries); + memcpy(state, window, window_entries * sizeof(*state)); for (i = 0; i < out_entries; i++) { @@ -755,7 +755,7 @@ static int sonic_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, break; } - memset(s->window, 0, 4* s->window_size); + memset(s->window, 0, s->window_size * sizeof(*s->window)); for (i = 0; i < s->tail_size; i++) s->window[x++] = s->tail[i]; From patchwork Tue Nov 3 17:57:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23362 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 AA2D044B434 for ; Tue, 3 Nov 2020 19:58:08 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 90DD268B682; Tue, 3 Nov 2020 19:58:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C5DF168B638 for ; Tue, 3 Nov 2020 19:58:00 +0200 (EET) Received: by mail-wr1-f65.google.com with SMTP id b8so19487912wrn.0 for ; Tue, 03 Nov 2020 09:58:00 -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=LFAulhDEheeiLv1ZkinLWZ0ltW6bEfjpddmdG15PtIg=; b=S+tL9CVmWGaCKXojh/sUjW4oO+LfjZj56bqxXpvaDjdUlcrLwyN/Q5wKbe3dTdR8Dk Aw5qSQnOi5Q5vfasKrAHP/0sIEoWdy8CtgCAjSAKVlKq0LwmiBbTVSGP1CUCuO8dp92W eYlW8NnTg3lP1TU8U0thoNaGmDnU8ZX5zdIiP7YOkDXtyb+L4jATvmYROjK64eA/jlAF xjzBBrTMl+cHc532isCp2xpot6lHzoyDezLO47BYIQXIjBvC+5Z8Zx0SWZD2n6XJAtBi cwK9ifSWmT15JiI5VZ7mN0vA9/HHZ5HLm++EfwtpVTBiCTjC8T1QFYw+Uf0e3Qpj2bH7 gWHw== 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=LFAulhDEheeiLv1ZkinLWZ0ltW6bEfjpddmdG15PtIg=; b=gkfEK6T5yGwe4pPfjOQ/vqIoEFYASTLD7++9Hyfm7IAvBoC8iUSS8MpaPvB8Zdnxxv Hoh0+jpJfx1n9oy7LSwOE+rqlI39cGC3oLTta/2ioJ72FjXDEBAQSogAvKlPgervzEeS eoZCrhqlgvtT+5/EWvinkgOvjbmb2gteCVqzzuBJEPZ07/F3cGWsPf19wRNYo7iZwAd2 mqXEwFnBCv5rLiuV1VSljd7yBSfgXRIhcFNbQKNMwitBsVrwhCsSQvOTcHbP2GlN8Ba0 eDYnYK6PNO9UwHrl6MqhNf3OgKek+05ImjVdByNdGSP9EMoWc+Rq/6xLHiWlFInjfCQ2 o+Hg== X-Gm-Message-State: AOAM530at4FB4AWE2NtoHAfPqt8MT7nXjO3UZieIq9ZfOaCJ7U/lqj1w 5V5e22DL94gCg7TFI0mLSazE9Qu8/7s= X-Google-Smtp-Source: ABdhPJwJxNjCv33iQAHOdwgclrCEKb1idn7B08S27FKT0kY8p6Q7su+le4/zGre5lGkLtiwEPNY5XQ== X-Received: by 2002:adf:f142:: with SMTP id y2mr27078523wro.160.1604426280064; Tue, 03 Nov 2020 09:58:00 -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.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 09:57:59 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Nov 2020 18:57:32 +0100 Message-Id: <20201103175735.170080-4-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 4/7] avcodec/truemotion2: Replace av_free() by av_freep() in AVCodec.close 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" Signed-off-by: Andreas Rheinhardt --- libavcodec/truemotion2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/truemotion2.c b/libavcodec/truemotion2.c index a1d4eea340..51266e5744 100644 --- a/libavcodec/truemotion2.c +++ b/libavcodec/truemotion2.c @@ -1016,8 +1016,8 @@ static av_cold int decode_end(AVCodecContext *avctx) TM2Context * const l = avctx->priv_data; int i; - av_free(l->last); - av_free(l->clast); + av_freep(&l->last); + av_freep(&l->clast); for (i = 0; i < TM2_NUM_STREAMS; i++) av_freep(&l->tokens[i]); if (l->Y1) { From patchwork Tue Nov 3 17:57:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23363 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 AA87B44B434 for ; Tue, 3 Nov 2020 19:58:09 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9655368B688; Tue, 3 Nov 2020 19:58:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D105F68B607 for ; Tue, 3 Nov 2020 19:58:01 +0200 (EET) Received: by mail-wm1-f68.google.com with SMTP id c9so175833wml.5 for ; Tue, 03 Nov 2020 09:58:01 -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=VlmNo6A6+D9sZy4BNsCQrcFzbrXUZBnIYnvUfwzgELo=; b=fVE3rkmvHgFGHOUdNwpuTPkPocKoJAj8kuhEMjpnxVF+ef/uPP6GPazLN/lyClJOMX hIZdjgLW/bmo7W0Lab07Zn8fjkKlSJYfH0b9z3LvVPnZtBxafP8BRMesDH5cI380EdCh 2HySj3Lx8+7ZHLvZ0by5zQcCsXriVnoiHcvFDq5RR+N0FDxHvIFdzwmTRhVKQUH8FwzH 8r6EYQ1ogYM7cq0PWUxi/pzzuaqS/I0CuCF//XNGaSGMB5rM3h1qfQM2O45RVvx2eFJj JC8zu9/81oF9YCKHy5usegJxWdOpJTALAm/G2BwQUPiKUsWvmjHVeEY/BZpHl7Ld5fgO Ru9Q== 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=VlmNo6A6+D9sZy4BNsCQrcFzbrXUZBnIYnvUfwzgELo=; b=QflttiIq/QwCBo99h5Y/TCinsUld9b5p/fRfOJ8mAj5AE4thtCTg2JVUfgr4lHoXPB o20cpmMJwUq54mLEX2STSr/oW4oc6w8oqkvXe+Wu6MZQX7UzOKsRlDfkkdIDJ/vWZKnb eif8hFCzvif85IMDIvYvG100DznlWMMuHGf1OhThLvOeO7QhjaX8EqmPh8wl62HCvXt7 XO5pIduw7CGHfoqOAhc718jfhXowejpe+1AxuJ2Y6+VqzzguB2Yj6cjEV6QWhBkGRYV6 LwuNXByeSNuDxIkdpsHQhTyVrXJxqo8HVS5abnGAZ25s9uzcnDPsklOhu5BZrpxLvGGE zHXw== X-Gm-Message-State: AOAM532vE/IucaYXwrG0vrvc81zhDKmZibEehG080dCewCCaovRo0Sj7 WGzTrvVakQR6XeXsmDWiB9ehHHPcBfs= X-Google-Smtp-Source: ABdhPJzbQPAADB9yddytW7hy41qpsvfI/RX+sfrwoEv62+KC8EeC5/0VPCQaPE8T62L2na6fCh7F5Q== X-Received: by 2002:a7b:cf31:: with SMTP id m17mr361747wmg.62.1604426280987; Tue, 03 Nov 2020 09:58:00 -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.58.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 09:58:00 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Nov 2020 18:57:33 +0100 Message-Id: <20201103175735.170080-5-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 5/7] avcodec/truemotion2: Remove redundant initializations 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" The codec's private context has already been zeroed generically. Signed-off-by: Andreas Rheinhardt --- libavcodec/truemotion2.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/libavcodec/truemotion2.c b/libavcodec/truemotion2.c index 51266e5744..1ae13bbf06 100644 --- a/libavcodec/truemotion2.c +++ b/libavcodec/truemotion2.c @@ -950,7 +950,7 @@ static int decode_frame(AVCodecContext *avctx, static av_cold int decode_init(AVCodecContext *avctx) { TM2Context * const l = avctx->priv_data; - int i, w = avctx->width, h = avctx->height; + int w = avctx->width, h = avctx->height; if ((avctx->width & 3) || (avctx->height & 3)) { av_log(avctx, AV_LOG_ERROR, "Width and height must be multiple of 4\n"); @@ -969,11 +969,6 @@ static av_cold int decode_init(AVCodecContext *avctx) l->last = av_malloc_array(w >> 2, 4 * sizeof(*l->last) ); l->clast = av_malloc_array(w >> 2, 4 * sizeof(*l->clast)); - for (i = 0; i < TM2_NUM_STREAMS; i++) { - l->tokens[i] = NULL; - l->tok_lens[i] = 0; - } - w += 8; h += 8; l->Y1_base = av_calloc(w * h, sizeof(*l->Y1_base)); @@ -986,7 +981,6 @@ static av_cold int decode_init(AVCodecContext *avctx) l->U2_base = av_calloc(w * h, sizeof(*l->U2_base)); l->V2_base = av_calloc(w * h, sizeof(*l->V1_base)); l->uv_stride = w; - l->cur = 0; if (!l->Y1_base || !l->Y2_base || !l->U1_base || !l->V1_base || !l->U2_base || !l->V2_base || !l->last || !l->clast) { From patchwork Tue Nov 3 17:57:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23364 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 E619D44B434 for ; Tue, 3 Nov 2020 19:58:10 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CF31468B67A; Tue, 3 Nov 2020 19:58:10 +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 E019168B666 for ; Tue, 3 Nov 2020 19:58:02 +0200 (EET) Received: by mail-wr1-f68.google.com with SMTP id c17so95725wrc.11 for ; Tue, 03 Nov 2020 09:58:02 -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=DKDI7UcNMYROYQXHB6liuQS3gHtwlsDag9QQowpuiBI=; b=RePtFaAdRqMMK1d6KwExe/AhUBLyeP7AVDZ6wH2OKx0DA+jZMt1haN+T/MkE8/W3i8 61Zk1Ryz+DYqeyl2xmMfV8REB9e8owtc+/Xn2NGUIfsoA3YnsV70e/lYxx/rk7TAlRIR ruR7AAR+duQ475xxOx9CPXR9bIXbsYax6oZQ1IT2aArSPZCr87dXK/P8RscoIy26+H9T RuAKq1BKDS8QHrSmYlLO1e96p7QY1RoyvGR1QaQ39A6bkiVjI63Gh3q2azjcjicrQhPF V0bPEaSAJYvwJK93CTeuh3feUpeLUZ5Z6H41CR3ojU8AjJ6qNPJj90Z5T8642MK439Ce kNfQ== 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=DKDI7UcNMYROYQXHB6liuQS3gHtwlsDag9QQowpuiBI=; b=dp6A9E/yEWaua9ThSPtWEmQLCnpmFnaR7LVYwVu8iGcKyIS4jLhHHEqOctw0w/ylRX iXqhGhUeAOZfK5o69TGhOCyeNemlt0xy4HhW14fND70eGzQrB37atlHGqInciqlUZb4v SKR6w43qXwZ4mGLDpwqiWay86zvL2DL2osCLXwV4apsOPbT1iX5zaquLbUm0j8aLIla3 Ew1HZOVJsX6vt8JuGVykmXS9rPfE2mwWu7zsbblSz6aILa+GEjZRN+h3jLZSOFDm5+JR xMf4bUOgE48pl6UHn/M6Hqc5ndbgqrpJy2SD1VlOOlpj2GV/Ypiokx8tMuAUWDC3W0/B +vRg== X-Gm-Message-State: AOAM531wclZ0KK6xPa51LZFdIbO/srarYm/OtHCKqg4O7PoLbQvkb2d5 defv1ICG5l9yYZCVGee6gpj1s/UDFbA= X-Google-Smtp-Source: ABdhPJxHBfFx7dThJNu9pNFqKffJd2DFG+Z9CrFxoPLWUr6DTRIZHyxSiAPsXJbtfTpz3hRnRYjMaw== X-Received: by 2002:adf:ea84:: with SMTP id s4mr26272517wrm.311.1604426282078; Tue, 03 Nov 2020 09:58:02 -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.58.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 09:58:01 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Nov 2020 18:57:34 +0100 Message-Id: <20201103175735.170080-6-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 6/7] avcodec/truemotion2: Cleanup generically on init failure 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" Signed-off-by: Andreas Rheinhardt --- libavcodec/truemotion2.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/libavcodec/truemotion2.c b/libavcodec/truemotion2.c index 1ae13bbf06..a90ff8cf01 100644 --- a/libavcodec/truemotion2.c +++ b/libavcodec/truemotion2.c @@ -984,15 +984,6 @@ static av_cold int decode_init(AVCodecContext *avctx) if (!l->Y1_base || !l->Y2_base || !l->U1_base || !l->V1_base || !l->U2_base || !l->V2_base || !l->last || !l->clast) { - av_freep(&l->Y1_base); - av_freep(&l->Y2_base); - av_freep(&l->U1_base); - av_freep(&l->U2_base); - av_freep(&l->V1_base); - av_freep(&l->V2_base); - av_freep(&l->last); - av_freep(&l->clast); - av_frame_free(&l->pic); return AVERROR(ENOMEM); } l->Y1 = l->Y1_base + l->y_stride * 4 + 4; @@ -1014,14 +1005,13 @@ static av_cold int decode_end(AVCodecContext *avctx) av_freep(&l->clast); for (i = 0; i < TM2_NUM_STREAMS; i++) av_freep(&l->tokens[i]); - if (l->Y1) { + av_freep(&l->Y1_base); av_freep(&l->U1_base); av_freep(&l->V1_base); av_freep(&l->Y2_base); av_freep(&l->U2_base); av_freep(&l->V2_base); - } av_freep(&l->buffer); l->buffer_size = 0; @@ -1040,4 +1030,5 @@ AVCodec ff_truemotion2_decoder = { .close = decode_end, .decode = decode_frame, .capabilities = AV_CODEC_CAP_DR1, + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, }; From patchwork Tue Nov 3 17:57:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23365 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 1E01D44B434 for ; Tue, 3 Nov 2020 19:58:12 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EF47C68B6CB; Tue, 3 Nov 2020 19:58:11 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DB4B668B66C for ; Tue, 3 Nov 2020 19:58:03 +0200 (EET) Received: by mail-wr1-f67.google.com with SMTP id g12so19438073wrp.10 for ; Tue, 03 Nov 2020 09:58:03 -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=5QG8RPeuqV3wZR4UWy3Aot7wMPR+AUpNnGo/4nJd25A=; b=LE+RELXQ7dlxdX419O49BfEAe6/XIym+IDXyA+LjPujfDsJHaC5Z8hQuINycBLB+Io 2kX6KKgmjN1Ji0CeXo6ffY4Cat8GH5kc6B+4wTVu7vgpqVsLqbVdqUTgkuERyaJQ18SJ A/9RDGRqiIFdNdtr/Bs6Q4R8nY4+5E8ih4lPe0bxMJS1SDO9YgNCvNrnHIwgj59v07aE IQzHwntebXeC0nwbKN7GqCIitYSvIV4xkFBKTM8ra6TZWwBhvyNOSmrPAyHeDhZCX5NY woGff7KPvDbPlox+eMfBSPW1vYlMFaJvPE24wNLwnSXgzIA7gvUHMh7PeZM/Yp/JT+Gz UYdg== 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=5QG8RPeuqV3wZR4UWy3Aot7wMPR+AUpNnGo/4nJd25A=; b=T6IZ8E0BoPpJw7UR4dBDbTdxTbxb/kBK+sAsHEj5bbX60BOGHSPVwezCk9UM3jY0Fx mq3Fc8LRwlcvO8yyahowhBn8iz6lN33guaaBN2sP0eSv9JTNx7UksP7wjZDGwo+D4xnp GRTjeOPuk2Pm5XrjhlnuMQVCtMn6OmbA7YQUdls3TZwxZ80R6Fw/dAfwexSf/krE5HWt Aq6c1Be1MRvoW//Bynr3Dl25Za6Axg9ZoTsuj3xWOTSVNFFFV3q9TO4mWMKowIwe68eM Vs7LxB72rMkN1UrYYEVcthBUAzYNHXz/R+WUSaA/mZwPgvn0EPK37ss8OZY63xnQamCH tLzA== X-Gm-Message-State: AOAM5320e63GPU5vdYogvVEG09AWLsLv46eAc0HcFbSXngDcAdDtY97I 1RNOjvJDaQCQEHJe4fnsNs9x+k94MWk= X-Google-Smtp-Source: ABdhPJw4Orayt2UkzhaPeSDPpDmeEHqr3RWYI1bznKe+nP8fg61KejXFsylNc1D0al1UHBOmAiFMrQ== X-Received: by 2002:adf:cd01:: with SMTP id w1mr27591149wrm.298.1604426283067; Tue, 03 Nov 2020 09:58:03 -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.58.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 09:58:02 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Nov 2020 18:57:35 +0100 Message-Id: <20201103175735.170080-7-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 7/7] avcodec/truemotion2: Allocate buffers together 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" Reduces the number of allocations and frees. Signed-off-by: Andreas Rheinhardt --- libavcodec/truemotion2.c | 46 +++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/libavcodec/truemotion2.c b/libavcodec/truemotion2.c index a90ff8cf01..0f4f345a6c 100644 --- a/libavcodec/truemotion2.c +++ b/libavcodec/truemotion2.c @@ -81,7 +81,7 @@ typedef struct TM2Context { int *clast; /* data for current and previous frame */ - int *Y1_base, *U1_base, *V1_base, *Y2_base, *U2_base, *V2_base; + int *Y_base, *UV_base; int *Y1, *U1, *V1, *Y2, *U2, *V2; int y_stride, uv_stride; int cur; @@ -966,32 +966,29 @@ static av_cold int decode_init(AVCodecContext *avctx) ff_bswapdsp_init(&l->bdsp); - l->last = av_malloc_array(w >> 2, 4 * sizeof(*l->last) ); - l->clast = av_malloc_array(w >> 2, 4 * sizeof(*l->clast)); + l->last = av_malloc_array(w, 2 * sizeof(*l->last)); + if (!l->last) + return AVERROR(ENOMEM); + l->clast = l->last + w; w += 8; h += 8; - l->Y1_base = av_calloc(w * h, sizeof(*l->Y1_base)); - l->Y2_base = av_calloc(w * h, sizeof(*l->Y2_base)); + l->Y_base = av_calloc(w * h, 2 * sizeof(*l->Y_base)); + if (!l->Y_base) + return AVERROR(ENOMEM); l->y_stride = w; + l->Y1 = l->Y_base + l->y_stride * 4 + 4; + l->Y2 = l->Y1 + w * h; w = (w + 1) >> 1; h = (h + 1) >> 1; - l->U1_base = av_calloc(w * h, sizeof(*l->U1_base)); - l->V1_base = av_calloc(w * h, sizeof(*l->V1_base)); - l->U2_base = av_calloc(w * h, sizeof(*l->U2_base)); - l->V2_base = av_calloc(w * h, sizeof(*l->V1_base)); - l->uv_stride = w; - if (!l->Y1_base || !l->Y2_base || !l->U1_base || - !l->V1_base || !l->U2_base || !l->V2_base || - !l->last || !l->clast) { + l->UV_base = av_calloc(w * h, 4 * sizeof(*l->UV_base)); + if (!l->UV_base) return AVERROR(ENOMEM); - } - l->Y1 = l->Y1_base + l->y_stride * 4 + 4; - l->Y2 = l->Y2_base + l->y_stride * 4 + 4; - l->U1 = l->U1_base + l->uv_stride * 2 + 2; - l->U2 = l->U2_base + l->uv_stride * 2 + 2; - l->V1 = l->V1_base + l->uv_stride * 2 + 2; - l->V2 = l->V2_base + l->uv_stride * 2 + 2; + l->uv_stride = w; + l->U1 = l->UV_base + l->uv_stride * 2 + 2; + l->U2 = l->U1 + w * h; + l->V1 = l->U2 + w * h; + l->V2 = l->V1 + w * h; return 0; } @@ -1002,16 +999,11 @@ static av_cold int decode_end(AVCodecContext *avctx) int i; av_freep(&l->last); - av_freep(&l->clast); for (i = 0; i < TM2_NUM_STREAMS; i++) av_freep(&l->tokens[i]); - av_freep(&l->Y1_base); - av_freep(&l->U1_base); - av_freep(&l->V1_base); - av_freep(&l->Y2_base); - av_freep(&l->U2_base); - av_freep(&l->V2_base); + av_freep(&l->Y_base); + av_freep(&l->UV_base); av_freep(&l->buffer); l->buffer_size = 0;