From patchwork Sat Dec 5 20:33:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 24362 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 C364144B2FB for ; Sat, 5 Dec 2020 22:42:18 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A366D68A7E5; Sat, 5 Dec 2020 22:42:18 +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 33737689C54 for ; Sat, 5 Dec 2020 22:42:12 +0200 (EET) Received: by mail-wm1-f68.google.com with SMTP id a3so10048614wmb.5 for ; Sat, 05 Dec 2020 12:42:12 -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=Cy8PpIMdlTyYnfdlxHNrOVnLx81ib6y1Q9OnkOmE/rY=; b=E0nzl7/QPb22m8mq4biCDjCVK3TbeScZXgwH5nZmN/8Nvzk7hFPZcakQVR1NbC9gPS SlUtuDCBeuIjX2TX+Zd1AFcpK5+GF33zqlPZw5FiYGOafKxoUqw2Ap+r/g9rqTwBNRt7 HMiqO78v9oaFrBrCXeAJbN8YKp+tor68WbqUAn0sf8utbb4BCSQjay51llARX5CwMO2H Xi51FBDmTcjSH0B9WihYeromEkFxWUbAZ6TGmIPxOjDFYdhSDZYt0hQfTMJFb/pq07f/ kxnT/g1eTxV035PPx+rVy0+0LG8OMa36vtUkeQCBz10oxNPPx3syWTnMw01aDi0XAGGU lWKg== 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=Cy8PpIMdlTyYnfdlxHNrOVnLx81ib6y1Q9OnkOmE/rY=; b=pWbL0uCaNSBHm0vJ2FABJHLHWXsd9TjLNlQIEcVeyFOBrJtFYVHwpcgc4a0o9DkWyd aybg5fxmDm32hRiS3KBFqLb9PwtzbnWxCyZBCmQwN02lu+2TkzzTLWQ5rCgMTVK9/96m oY0n7cQlNsacdXvgn4CpSThk+bvzuSHxPgYQzGgTzM2VS0TsLfyW7RnyECkN0HOm3xBD ZkLUv2CsssbLsx2pXgHU3yKKKOUZsN+jwdcc2hFDg0Tedsp0xGlM0JkIzVeRml+8ejqZ 5fPn361SrO85z67typdYT3+2qxbWIdiMJ+8GdQ1yQYjM2rWozLNFrkE45CNAZj29dkft M6kQ== X-Gm-Message-State: AOAM531W1V1VbmOAbwR8X1rHn8sEjMuUydXs0ctiZ27p23pRtj22anGU 4+0MY6150ddGJOrATM9wE45pRH5rbsxAcA== X-Google-Smtp-Source: ABdhPJyvIoYO1fnseyytWJ35Gx3JosmlQq99grYj+ZGjozUhCwTrZka8MX9maKCkg/dIa2OceJHdkQ== X-Received: by 2002:a1c:2c4:: with SMTP id 187mr10929569wmc.187.1607200457620; Sat, 05 Dec 2020 12:34:17 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id e4sm8747079wrr.32.2020.12.05.12.34.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2020 12:34:17 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 5 Dec 2020 21:33:37 +0100 Message-Id: <20201205203340.19357-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201205203340.19357-1-andreas.rheinhardt@gmail.com> References: <20201205203340.19357-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/7] avcodec/ac3enc: Factor common end of float/fixed encode_frame out 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/ac3enc.c | 42 ++++++++++++++++++++++++++++++------ libavcodec/ac3enc.h | 14 ++---------- libavcodec/ac3enc_template.c | 24 +-------------------- 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 30f6ca9dce..8079b98b68 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -270,7 +270,7 @@ void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s) * * @param s AC-3 encoder private context */ -void ff_ac3_apply_rematrixing(AC3EncodeContext *s) +static void ac3_apply_rematrixing(AC3EncodeContext *s) { int nb_coefs; int blk, bnd, i; @@ -574,7 +574,7 @@ static int count_exponent_bits(AC3EncodeContext *s) * * @param s AC-3 encoder private context */ -void ff_ac3_group_exponents(AC3EncodeContext *s) +static void ac3_group_exponents(AC3EncodeContext *s) { int blk, ch, i, cpl; int group_size, nb_groups; @@ -632,7 +632,7 @@ void ff_ac3_group_exponents(AC3EncodeContext *s) * * @param s AC-3 encoder private context */ -void ff_ac3_process_exponents(AC3EncodeContext *s) +static void ac3_process_exponents(AC3EncodeContext *s) { extract_exponents(s); @@ -1141,7 +1141,7 @@ static int cbr_bit_allocation(AC3EncodeContext *s) * frame size. Output is the SNR offset and a set of bit allocation pointers * used to quantize the mantissas. */ -int ff_ac3_compute_bit_allocation(AC3EncodeContext *s) +static int ac3_compute_bit_allocation(AC3EncodeContext *s) { count_frame_bits(s); @@ -1295,7 +1295,7 @@ static void quantize_mantissas_blk_ch(AC3Mant *s, int32_t *fixed_coef, * * @param s AC-3 encoder private context */ -void ff_ac3_quantize_mantissas(AC3EncodeContext *s) +static void ac3_quantize_mantissas(AC3EncodeContext *s) { int blk, ch, ch0=0, got_cpl; @@ -1656,7 +1656,7 @@ static void output_frame_end(AC3EncodeContext *s) * @param s AC-3 encoder private context * @param frame output data buffer */ -void ff_ac3_output_frame(AC3EncodeContext *s, unsigned char *frame) +static void ac3_output_frame(AC3EncodeContext *s, unsigned char *frame) { int blk; @@ -1670,6 +1670,36 @@ void ff_ac3_output_frame(AC3EncodeContext *s, unsigned char *frame) output_frame_end(s); } +int ff_ac3_encode_frame_common_end(AVCodecContext *avctx, AVPacket *avpkt, + const AVFrame *frame, int *got_packet_ptr) +{ + AC3EncodeContext *const s = avctx->priv_data; + int ret; + + ac3_apply_rematrixing(s); + + ac3_process_exponents(s); + + ret = ac3_compute_bit_allocation(s); + if (ret) { + av_log(avctx, AV_LOG_ERROR, "Bit allocation failed. Try increasing the bitrate.\n"); + return ret; + } + + ac3_group_exponents(s); + + ac3_quantize_mantissas(s); + + if ((ret = ff_alloc_packet2(avctx, avpkt, s->frame_size, 0)) < 0) + return ret; + ac3_output_frame(s, avpkt->data); + + if (frame->pts != AV_NOPTS_VALUE) + avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->initial_padding); + + *got_packet_ptr = 1; + return 0; +} static void dprint_options(AC3EncodeContext *s) { diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h index 6d8f186a1a..044564ecb4 100644 --- a/libavcodec/ac3enc.h +++ b/libavcodec/ac3enc.h @@ -282,18 +282,8 @@ void ff_ac3_adjust_frame_size(AC3EncodeContext *s); void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s); -void ff_ac3_apply_rematrixing(AC3EncodeContext *s); - -void ff_ac3_process_exponents(AC3EncodeContext *s); - -int ff_ac3_compute_bit_allocation(AC3EncodeContext *s); - -void ff_ac3_group_exponents(AC3EncodeContext *s); - -void ff_ac3_quantize_mantissas(AC3EncodeContext *s); - -void ff_ac3_output_frame(AC3EncodeContext *s, unsigned char *frame); - +int ff_ac3_encode_frame_common_end(AVCodecContext *avctx, AVPacket *avpkt, + const AVFrame *frame, int *got_packet_ptr); /* prototypes for functions in ac3enc_template.c */ diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c index 974a3f9f74..f3274cf9eb 100644 --- a/libavcodec/ac3enc_template.c +++ b/libavcodec/ac3enc_template.c @@ -406,27 +406,5 @@ int AC3_NAME(encode_frame)(AVCodecContext *avctx, AVPacket *avpkt, if (AC3ENC_FLOAT) scale_coefficients(s); - ff_ac3_apply_rematrixing(s); - - ff_ac3_process_exponents(s); - - ret = ff_ac3_compute_bit_allocation(s); - if (ret) { - av_log(avctx, AV_LOG_ERROR, "Bit allocation failed. Try increasing the bitrate.\n"); - return ret; - } - - ff_ac3_group_exponents(s); - - ff_ac3_quantize_mantissas(s); - - if ((ret = ff_alloc_packet2(avctx, avpkt, s->frame_size, 0)) < 0) - return ret; - ff_ac3_output_frame(s, avpkt->data); - - if (frame->pts != AV_NOPTS_VALUE) - avpkt->pts = frame->pts - ff_samples_to_time_base(avctx, avctx->initial_padding); - - *got_packet_ptr = 1; - return 0; + return ff_ac3_encode_frame_common_end(avctx, avpkt, frame, got_packet_ptr); }