From patchwork Sun May 19 16:54:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 49032 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:3a48:b0:1af:fc2d:ff5a with SMTP id zu8csp4001460pzb; Sun, 19 May 2024 09:55:32 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV1tyKdOZxCAhDRwbuYCwejEL7LodPI0p+eMw8bDg4rvyAhy2JJ5IkDETqSLc33bZpUp3cSFyEMoA7tUGSmpSARrnSrFqW2LPidsw== X-Google-Smtp-Source: AGHT+IEiu9GWTR92bM8juNoHvwfp22mIRuLYit+hVJ+BDoCFKHvhlPfLLyK0rIGd3R7RXqDKaWPc X-Received: by 2002:a50:8711:0:b0:572:7015:f303 with SMTP id 4fb4d7f45d1cf-5734d6f00d7mr22627779a12.35.1716137732327; Sun, 19 May 2024 09:55:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716137732; cv=none; d=google.com; s=arc-20160816; b=WeZ0LywDUmq+wg9QRvxE2rGlWKruv1gPZrY4O85BpYMwh3dPF/P4qlVt04mVByWHc+ lP4c/Y3o8BtzWY2jwON4wqd0F7r09CMGy2a8ep5j6o+AAZCwt7+i+kL54hQ9numE4Ptu +AySeWtF6+Ko4xAv8jM3O+qUcHy2DvmUpFSW2hJdbq157NPGpPfzcUT6hTSMkRX6NRkq wqnkjjgTCK7DuV9xGkB3P01nvFb1fThRrzOWIejadmZ9wknDXhqqzouIMqm4FKzPfiO8 A4b33CY7pnYmJWMQ+gOGNZ80sVzLlrBSNnQIRdS0dfL/Sv2LWoLyJXXw+aFxwZ44iin2 4HEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to:from :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:delivered-to; bh=Y6Xh7HevtYbVRCN7hkxbwwVTSGR08q0jr1TmPy0ODBc=; fh=nenT92/WZoU6unXd3J6UhGUdod4piddKfVtctNBOh6k=; b=BgbLVKBBH6F3O9nD5rcVwTZB7ChpVUfx7OJD8LyyS/QdqjRfeIE/SJ3xsu+hcw+OYg mZ0eaAT3PDJInn1rwXBCBGtX9Sc9Ziquej/RdVFPNRXCgkgBCZU2QrxciVuujgN1XyBv 4FZGt6VBQISIA7+nqeNRhMgh+a8+2TeOn2WBklQf0Z3aFTIBZu7rY+1XleP2tFy+aUGf rLUyUPc4h5m5/BRlbqhaH2f7LS09OPw+afMFJ35chD3FRrf+W5NV/+2oFvoEn467Pcue YYaOaBgwfxEN9nw3rB1Jv5fPrxaWEz0lr9MFKSwTv8jvgvJ+sllGPcaw1GKA6Cf/GXf5 7d5A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-5751aefad10si3220143a12.207.2024.05.19.09.55.31; Sun, 19 May 2024 09:55:32 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C11F968CF47; Sun, 19 May 2024 19:55:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vidala.lynne.ee (vidala.pars.ee [116.203.72.101]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0680968CEED for ; Sun, 19 May 2024 19:55:10 +0300 (EEST) To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 May 2024 18:54:38 +0200 Message-ID: <20240519165444.829271-3-dev@lynne.ee> X-Mailer: git-send-email 2.43.0.381.gb435a96ce8 In-Reply-To: <20240519165444.829271-1-dev@lynne.ee> References: <20240519165444.829271-1-dev@lynne.ee> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/8] aacdec: expose channel layout related functions X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Lynne via ffmpeg-devel From: Lynne Reply-To: FFmpeg development discussions and patches Cc: Lynne Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: IwQjC/ID83+M --- libavcodec/aac/aacdec.c | 73 ++++++++++++++++++++--------------------- libavcodec/aac/aacdec.h | 19 +++++++++-- 2 files changed, 51 insertions(+), 41 deletions(-) diff --git a/libavcodec/aac/aacdec.c b/libavcodec/aac/aacdec.c index 35722f9b9b..40554ff9e4 100644 --- a/libavcodec/aac/aacdec.c +++ b/libavcodec/aac/aacdec.c @@ -111,10 +111,6 @@ Parametric Stereo. */ -static int output_configure(AACDecContext *ac, - uint8_t layout_map[MAX_ELEM_ID*4][3], int tags, - enum OCStatus oc_type, int get_new_frame); - #define overread_err "Input buffer exhausted before END element found\n" static int count_channels(uint8_t (*layout)[3], int tags) @@ -447,8 +443,8 @@ static void pop_output_configuration(AACDecContext *ac) if (ac->oc[1].status != OC_LOCKED && ac->oc[0].status != OC_NONE) { ac->oc[1] = ac->oc[0]; ac->avctx->ch_layout = ac->oc[1].ch_layout; - output_configure(ac, ac->oc[1].layout_map, ac->oc[1].layout_map_tags, - ac->oc[1].status, 0); + ff_aac_output_configure(ac, ac->oc[1].layout_map, ac->oc[1].layout_map_tags, + ac->oc[1].status, 0); } } @@ -458,7 +454,7 @@ static void pop_output_configuration(AACDecContext *ac) * * @return Returns error status. 0 - OK, !0 - error */ -static int output_configure(AACDecContext *ac, +int ff_aac_output_configure(AACDecContext *ac, uint8_t layout_map[MAX_ELEM_ID * 4][3], int tags, enum OCStatus oc_type, int get_new_frame) { @@ -547,7 +543,7 @@ static av_cold void flush(AVCodecContext *avctx) * * @return Returns error status. 0 - OK, !0 - error */ -static int set_default_channel_config(AACDecContext *ac, AVCodecContext *avctx, +int ff_aac_set_default_channel_config(AACDecContext *ac, AVCodecContext *avctx, uint8_t (*layout_map)[3], int *tags, int channel_config) @@ -587,7 +583,7 @@ static int set_default_channel_config(AACDecContext *ac, AVCodecContext *avctx, return 0; } -static ChannelElement *get_che(AACDecContext *ac, int type, int elem_id) +ChannelElement *ff_aac_get_che(AACDecContext *ac, int type, int elem_id) { /* For PCE based channel configurations map the channels solely based * on tags. */ @@ -603,11 +599,11 @@ static ChannelElement *get_che(AACDecContext *ac, int type, int elem_id) av_log(ac->avctx, AV_LOG_DEBUG, "mono with CPE\n"); - if (set_default_channel_config(ac, ac->avctx, layout_map, - &layout_map_tags, 2) < 0) + if (ff_aac_set_default_channel_config(ac, ac->avctx, layout_map, + &layout_map_tags, 2) < 0) return NULL; - if (output_configure(ac, layout_map, layout_map_tags, - OC_TRIAL_FRAME, 1) < 0) + if (ff_aac_output_configure(ac, layout_map, layout_map_tags, + OC_TRIAL_FRAME, 1) < 0) return NULL; ac->oc[1].m4ac.chan_config = 2; @@ -627,8 +623,8 @@ static ChannelElement *get_che(AACDecContext *ac, int type, int elem_id) layout_map[0][2] = layout_map[1][2] = AAC_CHANNEL_FRONT; layout_map[0][1] = 0; layout_map[1][1] = 1; - if (output_configure(ac, layout_map, layout_map_tags, - OC_TRIAL_FRAME, 1) < 0) + if (ff_aac_output_configure(ac, layout_map, layout_map_tags, + OC_TRIAL_FRAME, 1) < 0) return NULL; if (ac->oc[1].m4ac.sbr) @@ -877,8 +873,8 @@ static int decode_ga_specific_config(AACDecContext *ac, AVCodecContext *avctx, if (tags < 0) return tags; } else { - if ((ret = set_default_channel_config(ac, avctx, layout_map, - &tags, channel_config))) + if ((ret = ff_aac_set_default_channel_config(ac, avctx, layout_map, + &tags, channel_config))) return ret; } @@ -887,7 +883,7 @@ static int decode_ga_specific_config(AACDecContext *ac, AVCodecContext *avctx, } else if (m4ac->sbr == 1 && m4ac->ps == -1) m4ac->ps = 1; - if (ac && (ret = output_configure(ac, layout_map, tags, OC_GLOBAL_HDR, 0))) + if (ac && (ret = ff_aac_output_configure(ac, layout_map, tags, OC_GLOBAL_HDR, 0))) return ret; if (extension_flag) { @@ -967,11 +963,11 @@ static int decode_eld_specific_config(AACDecContext *ac, AVCodecContext *avctx, skip_bits_long(gb, 8 * len); } - if ((ret = set_default_channel_config(ac, avctx, layout_map, - &tags, channel_config))) + if ((ret = ff_aac_set_default_channel_config(ac, avctx, layout_map, + &tags, channel_config))) return ret; - if (ac && (ret = output_configure(ac, layout_map, tags, OC_GLOBAL_HDR, 0))) + if (ac && (ret = ff_aac_output_configure(ac, layout_map, tags, OC_GLOBAL_HDR, 0))) return ret; ep_config = get_bits(gb, 2); @@ -1206,11 +1202,12 @@ av_cold int ff_aac_decode_init(AVCodecContext *avctx) ac->oc[1].m4ac.chan_config = i; if (ac->oc[1].m4ac.chan_config) { - int ret = set_default_channel_config(ac, avctx, layout_map, - &layout_map_tags, ac->oc[1].m4ac.chan_config); + int ret = ff_aac_set_default_channel_config(ac, avctx, layout_map, + &layout_map_tags, + ac->oc[1].m4ac.chan_config); if (!ret) - output_configure(ac, layout_map, layout_map_tags, - OC_GLOBAL_HDR, 0); + ff_aac_output_configure(ac, layout_map, layout_map_tags, + OC_GLOBAL_HDR, 0); else if (avctx->err_recognition & AV_EF_EXPLODE) return AVERROR_INVALIDDATA; } @@ -1915,8 +1912,8 @@ static int decode_extension_payload(AACDecContext *ac, GetBitContext *gb, int cn ac->oc[1].m4ac.sbr = 1; ac->oc[1].m4ac.ps = 1; ac->avctx->profile = AV_PROFILE_AAC_HE_V2; - output_configure(ac, ac->oc[1].layout_map, ac->oc[1].layout_map_tags, - ac->oc[1].status, 1); + ff_aac_output_configure(ac, ac->oc[1].layout_map, ac->oc[1].layout_map_tags, + ac->oc[1].status, 1); } else { ac->oc[1].m4ac.sbr = 1; ac->avctx->profile = AV_PROFILE_AAC_HE; @@ -2066,13 +2063,13 @@ static int parse_adts_frame_header(AACDecContext *ac, GetBitContext *gb) push_output_configuration(ac); if (hdr_info.chan_config) { ac->oc[1].m4ac.chan_config = hdr_info.chan_config; - if ((ret = set_default_channel_config(ac, ac->avctx, - layout_map, - &layout_map_tags, - hdr_info.chan_config)) < 0) + if ((ret = ff_aac_set_default_channel_config(ac, ac->avctx, + layout_map, + &layout_map_tags, + hdr_info.chan_config)) < 0) return ret; - if ((ret = output_configure(ac, layout_map, layout_map_tags, - FFMAX(ac->oc[1].status, + if ((ret = ff_aac_output_configure(ac, layout_map, layout_map_tags, + FFMAX(ac->oc[1].status, OC_TRIAL_FRAME), 0)) < 0) return ret; } else { @@ -2088,8 +2085,8 @@ static int parse_adts_frame_header(AACDecContext *ac, GetBitContext *gb) layout_map[0][2] = layout_map[1][2] = AAC_CHANNEL_FRONT; layout_map[0][1] = 0; layout_map[1][1] = 1; - if (output_configure(ac, layout_map, layout_map_tags, - OC_TRIAL_FRAME, 0)) + if (ff_aac_output_configure(ac, layout_map, layout_map_tags, + OC_TRIAL_FRAME, 0)) return -7; } } @@ -2142,7 +2139,7 @@ static int aac_decode_er_frame(AVCodecContext *avctx, AVFrame *frame, for (i = 0; i < ff_tags_per_config[chan_config]; i++) { const int elem_type = ff_aac_channel_layout_map[chan_config-1][i][0]; const int elem_id = ff_aac_channel_layout_map[chan_config-1][i][1]; - if (!(che=get_che(ac, elem_type, elem_id))) { + if (!(che=ff_aac_get_che(ac, elem_type, elem_id))) { av_log(ac->avctx, AV_LOG_ERROR, "channel element %d.%d is not allocated\n", elem_type, elem_id); @@ -2241,7 +2238,7 @@ static int aac_decode_frame_int(AVCodecContext *avctx, AVFrame *frame, } che_presence[elem_type][elem_id]++; - if (!(che=get_che(ac, elem_type, elem_id))) { + if (!(che=ff_aac_get_che(ac, elem_type, elem_id))) { av_log(ac->avctx, AV_LOG_ERROR, "channel element %d.%d is not allocated\n", elem_type, elem_id); err = AVERROR_INVALIDDATA; @@ -2298,7 +2295,7 @@ static int aac_decode_frame_int(AVCodecContext *avctx, AVFrame *frame, "Not evaluating a further program_config_element as this construct is dubious at best.\n"); pop_output_configuration(ac); } else { - err = output_configure(ac, layout_map, tags, OC_TRIAL_PCE, 1); + err = ff_aac_output_configure(ac, layout_map, tags, OC_TRIAL_PCE, 1); if (!err) ac->oc[1].m4ac.chan_config = 0; pce_found = 1; diff --git a/libavcodec/aac/aacdec.h b/libavcodec/aac/aacdec.h index bbb7ea358f..bea0578e92 100644 --- a/libavcodec/aac/aacdec.h +++ b/libavcodec/aac/aacdec.h @@ -39,6 +39,7 @@ #include "libavutil/tx.h" #include "libavcodec/aac.h" +#include "libavcodec/avcodec.h" #include "libavcodec/mpeg4audio.h" typedef struct AACDecContext AACDecContext; @@ -343,10 +344,22 @@ struct AACDecContext { #define fdsp RENAME_FIXED(fdsp) #endif -int ff_aac_decode_init(struct AVCodecContext *avctx); -int ff_aac_decode_init_float(struct AVCodecContext *avctx); -int ff_aac_decode_init_fixed(struct AVCodecContext *avctx); +int ff_aac_decode_init(AVCodecContext *avctx); +int ff_aac_decode_init_float(AVCodecContext *avctx); +int ff_aac_decode_init_fixed(AVCodecContext *avctx); + int ff_aac_decode_ics(AACDecContext *ac, SingleChannelElement *sce, GetBitContext *gb, int common_window, int scale_flag); +int ff_aac_set_default_channel_config(AACDecContext *ac, AVCodecContext *avctx, + uint8_t (*layout_map)[3], + int *tags, + int channel_config); + +int ff_aac_output_configure(AACDecContext *ac, + uint8_t layout_map[MAX_ELEM_ID * 4][3], int tags, + enum OCStatus oc_type, int get_new_frame); + +ChannelElement *ff_aac_get_che(AACDecContext *ac, int type, int elem_id); + #endif /* AVCODEC_AAC_AACDEC_H */