From patchwork Tue Sep 15 07:39:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22409 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 4A2A7449636 for ; Tue, 15 Sep 2020 10:44:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8F4EC68BB39; Tue, 15 Sep 2020 10:41:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5818068BC83 for ; Tue, 15 Sep 2020 10:40:56 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id y15so2385228wmi.0 for ; Tue, 15 Sep 2020 00:40:56 -0700 (PDT) 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=W2b0vsQ0oaKAFeJTU0JKHB7H3gXnNhRG4KJrbBwuIQU=; b=D8CYnqQcM5zm9U4HKjwvdNRTBmXNT4OxuMMfIjSZx/qKJXLyibuQxk9IDgwijmyHku XxRFWiXLOAF5GR1awJUy65yrvFEe8d5mMNt2TPRX1OJG3WdV1apygMQ9xzWeBgcUJkLM KZQ6ScXpzv8IDrM5UwQAtvtxvUwskwvaSCe1e3mYO7VaBAjhwPjxPZfdRlsWCGGD8TPK c+VCjUNcthfB8cZBhaIJ5Za/K2gUgNpVgAOH74jZJifXTFov7eoR+21LWz3q/VdGN3Vf O1/YwtnXcZVgPBRswadUyqDkEYu+s3t9Lne+D2OU9NIysnB7SE5KYU97gflBOmvvwUjq eV2g== 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=W2b0vsQ0oaKAFeJTU0JKHB7H3gXnNhRG4KJrbBwuIQU=; b=RdEj5hWrAyzCQn/xz7DvEGpg1KLuLVOYAB0J8jN5x/JEi3LzKOgzlVaow1MHNGRAdF leiCamrV08iEu2GRKrlgbeHVp5GW5NzAlME8siHQiZD0NCnsewUppOVloiNPH1RhgAGb UCl/2z5uzEd1zclHhypGn3MWhn5FKdbtFaWAhbJFK+Z9dprYah5X9PyisOPJTmVcHSEH qu/UZ3Kd2oVf38uwQVxXjheM97XvAYmq0HLYDqYQQbDBng2Wj1U+OWi5xNRy5/Ttke/q gcRYijsKtxKnBR+DitYR1jAzdKgK5xawXAqdheAqQ6qDV0Cg6RgiUk+EAshjLo/iwYbl h2Bg== X-Gm-Message-State: AOAM532vvYpg5oGumN7ZLBc4o7cOEMA6+s2+ELnDrnlaj22ckEm/Pj3I +TdZjnTXnyGyCiWCoNV/+NGgGVEAfxo= X-Google-Smtp-Source: ABdhPJxsFJGAbarBnLn85nh/Glc3zCpPEdcO76Xe7BqOu2EvIE8pBE2LMHcSd4JQFYYAS/YZrXQxpQ== X-Received: by 2002:a1c:6254:: with SMTP id w81mr3182436wmb.94.1600155655271; Tue, 15 Sep 2020 00:40:55 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id d23sm6112125wmb.6.2020.09.15.00.40.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2020 00:40:54 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 15 Sep 2020 09:39:59 +0200 Message-Id: <20200915074000.102622-29-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200915074000.102622-1-andreas.rheinhardt@gmail.com> References: <20200915074000.102622-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 29/30] avcodec/mpegaudiodec_template: Simplify creating mp3on4 child decoders 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" Allocating the child codec contexts in one piece simplifies both allocating as well as freeing. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegaudiodec_template.c | 33 +++++++++++++----------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/libavcodec/mpegaudiodec_template.c b/libavcodec/mpegaudiodec_template.c index d2b72497e1..8ed2f74eee 100644 --- a/libavcodec/mpegaudiodec_template.c +++ b/libavcodec/mpegaudiodec_template.c @@ -1827,7 +1827,7 @@ typedef struct MP3On4DecodeContext { int frames; ///< number of mp3 frames per block (number of mp3 decoder instances) int syncword; ///< syncword patch const uint8_t *coff; ///< channel offsets in output buffer - MPADecodeContext *mp3decctx[5]; ///< MPADecodeContext for every decoder instance + MPADecodeContext *mp3decctx; ///< MPADecodeContext for every decoder instance } MP3On4DecodeContext; #include "mpeg4audio.h" @@ -1864,10 +1864,8 @@ static const int16_t chan_layout[8] = { static av_cold int decode_close_mp3on4(AVCodecContext * avctx) { MP3On4DecodeContext *s = avctx->priv_data; - int i; - for (i = 0; i < s->frames; i++) - av_freep(&s->mp3decctx[i]); + av_freep(&s->mp3decctx); return 0; } @@ -1905,12 +1903,12 @@ static av_cold int decode_init_mp3on4(AVCodecContext * avctx) * decode_init() does not have to be changed. * Other decoders will be initialized here copying data from the first context */ - // Allocate zeroed memory for the first decoder context - s->mp3decctx[0] = av_mallocz(sizeof(MPADecodeContext)); - if (!s->mp3decctx[0]) + // Allocate zeroed memory for the decoder contexts + s->mp3decctx = av_mallocz_array(sizeof(MPADecodeContext), s->frames); + if (!s->mp3decctx) goto alloc_fail; // Put decoder context in place to make init_decode() happy - avctx->priv_data = s->mp3decctx[0]; + avctx->priv_data = s->mp3decctx; ret = decode_init(avctx); // Restore mp3on4 context pointer avctx->priv_data = s; @@ -1918,19 +1916,16 @@ static av_cold int decode_init_mp3on4(AVCodecContext * avctx) decode_close_mp3on4(avctx); return ret; } - s->mp3decctx[0]->adu_mode = 1; // Set adu mode + s->mp3decctx[0].adu_mode = 1; // Set adu mode /* Create a separate codec/context for each frame (first is already ok). * Each frame is 1 or 2 channels - up to 5 frames allowed */ for (i = 1; i < s->frames; i++) { - s->mp3decctx[i] = av_mallocz(sizeof(MPADecodeContext)); - if (!s->mp3decctx[i]) - goto alloc_fail; - s->mp3decctx[i]->adu_mode = 1; - s->mp3decctx[i]->avctx = avctx; - s->mp3decctx[i]->mpadsp = s->mp3decctx[0]->mpadsp; - s->mp3decctx[i]->butterflies_float = s->mp3decctx[0]->butterflies_float; + s->mp3decctx[i].adu_mode = 1; + s->mp3decctx[i].avctx = avctx; + s->mp3decctx[i].mpadsp = s->mp3decctx[0].mpadsp; + s->mp3decctx[i].butterflies_float = s->mp3decctx[0].butterflies_float; } return 0; @@ -1946,7 +1941,7 @@ static void flush_mp3on4(AVCodecContext *avctx) MP3On4DecodeContext *s = avctx->priv_data; for (i = 0; i < s->frames; i++) - mp_flush(s->mp3decctx[i]); + mp_flush(&s->mp3decctx[i]); } @@ -1980,7 +1975,7 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data, for (fr = 0; fr < s->frames; fr++) { fsize = AV_RB16(buf) >> 4; fsize = FFMIN3(fsize, len, MPA_MAX_CODED_FRAME_SIZE); - m = s->mp3decctx[fr]; + m = &s->mp3decctx[fr]; av_assert1(m); if (fsize < HEADER_SIZE) { @@ -2027,7 +2022,7 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data, } /* update codec info */ - avctx->sample_rate = s->mp3decctx[0]->sample_rate; + avctx->sample_rate = s->mp3decctx[0].sample_rate; frame->nb_samples = out_size / (avctx->channels * sizeof(OUT_INT)); *got_frame_ptr = 1;