From patchwork Mon Apr 1 18:56:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 47699 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp922605pzb; Mon, 1 Apr 2024 11:56:47 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUahmmYmGkUQ6dnrKBR0MzPRDvTYRGOF79AJPxmAjwAphz/s06BFa2hK1gGznb0/6viZ5fh8IBclBRjyIZFUI7jjr3Ch8/t1uXIyw== X-Google-Smtp-Source: AGHT+IF95UKmJEwazMdtnnJ0ucNRWWUiDpej9yg3wDVfbGiWCgCNYq2GJBq5A2tfsz2OnuA6GF4O X-Received: by 2002:a17:907:da5:b0:a4e:3956:6ad8 with SMTP id go37-20020a1709070da500b00a4e39566ad8mr7307869ejc.44.1711997807697; Mon, 01 Apr 2024 11:56:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711997807; cv=none; d=google.com; s=arc-20160816; b=Km0jQ2h8RnwB2kH2JRVrBtjAqqYhJAwJ/5snnE1VF/VVp38+/d/VezJW7954KXcuv4 LkOYSZ2diea3jeF3wTiEMbacxt6uXIZYJfG+0InSWp/9AKnHDYuOznhK4FeD0ci8Hwn5 oPuIOv+PcodD1taq5Lethx9Z3QFXfWbbV5ZHFCPCLV7tTf2zOMWoKMkUQpsqlIUC+KAo ubddWuLN7BxbcsuKvy4Mer3ay2VcCq4rWBqEd6z/La/9LyAeoxgetvABlL5bJGjstoy/ qijpkHd+MloKGb5LB28kha95RwyHE+uWrKH4NcmLRhPyJ//DFv0PNMtz1UAFPONtDMDl BUkA== 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 :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=tGcqenNrgU/S442McEXbzd6KanuERAaToGrgp2k5Abk=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=laTRCSnyVg7MCIDXJeiOh3vMeRm9JVIaVovP8bS3bLbMfYCTpVjdn2vxHfXcV5DNsg whGwaXUz8YfcCN4Mls3q3/j7QVUtbui5XhXrRy/fG2tVpyXE7vyn+sA+S72NzYLuZgQG E00ePDNYSM2UuaZav0Iuce68xmW1XQQd/10XZVEUJO+Lj43E+/47kgkHBew2v6ozDUSb srMqioiiEfsvpMtadX+VFH5i2ZMnG8/ArNgXmHAygFamnT6KIT+y+sBIUCbsltZR64Pg XLWPnKjO4hwsHZYgwHjSSasepr2FeD4jXvvMR27NaETux6Xy30s291R9cE+dZrewg/LT WO2A==; 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 dv3-20020a170906b80300b00a4e71323169si940806ejb.0.2024.04.01.11.56.47; Mon, 01 Apr 2024 11:56:47 -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 2C2C368D00E; Mon, 1 Apr 2024 21:56:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 64AD368CF55 for ; Mon, 1 Apr 2024 21:56:32 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 42058EA31B; Mon, 1 Apr 2024 20:56:32 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OhZMj5VhwQEQ; Mon, 1 Apr 2024 20:56:29 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 8ACD5EA33E; Mon, 1 Apr 2024 20:56:29 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Mon, 1 Apr 2024 20:56:19 +0200 Message-Id: <20240401185621.15297-2-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240401185621.15297-1-cus@passwd.hu> References: <20240401185621.15297-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/4] avformat/mov_chan: factorize some layout map search 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: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: u8Lav3ZqmAu2 Signed-off-by: Marton Balint --- libavformat/mov_chan.c | 62 ++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index 6ccc26b3f1..9ee896f229 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -187,6 +187,7 @@ static const struct MovChannelLayoutMap mov_ch_layout_map[] = { CHLIST09( MOV_CH_LAYOUT_DTS_8_1_B, Lc, C, Rc, L, R, Ls, Cs, Rs, LFE ), CHLIST16( MOV_CH_LAYOUT_TMH_10_2_STD, L, R, C, Vhc, Lsd, Rsd, Ls, Rs, Vhl, Vhr, Lw, Rw, Csd, Cs, LFE1, LFE2), CHLIST21( MOV_CH_LAYOUT_TMH_10_2_FULL, L, R, C, Vhc, Lsd, Rsd, Ls, Rs, Vhl, Vhr, Lw, Rw, Csd, Cs, LFE1, LFE2, Lc, Rc, HI, VI, Haptic), + { {0} }, }; static const enum MovChannelLayoutTag mov_ch_layouts_aac[] = { @@ -283,11 +284,11 @@ static const struct { { AV_CODEC_ID_NONE, NULL }, }; -static const struct MovChannelLayoutMap* find_layout_map(uint32_t tag) +static const struct MovChannelLayoutMap* find_layout_map(uint32_t tag, const struct MovChannelLayoutMap *map) { - for (int i = 0; i < FF_ARRAY_ELEMS(mov_ch_layout_map); i += 1 + (mov_ch_layout_map[i].tag & 0xffff)) - if (mov_ch_layout_map[i].tag == tag) - return &mov_ch_layout_map[i + 1]; + for (int i = 0; map[i].tag & 0xffff; i += 1 + (map[i].tag & 0xffff)) + if (map[i].tag == tag) + return &map[i + 1]; return NULL; } @@ -299,7 +300,7 @@ static const struct MovChannelLayoutMap* find_layout_map(uint32_t tag) * @param[in] tag channel layout tag * @return <0 on error */ -static int mov_get_channel_layout(AVChannelLayout *ch_layout, uint32_t tag) +static int mov_get_channel_layout(AVChannelLayout *ch_layout, uint32_t tag, const struct MovChannelLayoutMap *map) { int i, channels; const struct MovChannelLayoutMap *layout_map; @@ -307,7 +308,7 @@ static int mov_get_channel_layout(AVChannelLayout *ch_layout, uint32_t tag) channels = tag & 0xFFFF; /* find the channel layout for the specified layout tag */ - layout_map = find_layout_map(tag); + layout_map = find_layout_map(tag, map); if (layout_map) { int ret; av_channel_layout_uninit(ch_layout); @@ -361,12 +362,34 @@ static uint32_t mov_get_channel_label(enum AVChannel channel) return 0; } +static int is_layout_valid_for_tag(const AVChannelLayout *ch_layout, uint32_t tag, const struct MovChannelLayoutMap *map) +{ + const struct MovChannelLayoutMap *layout_map; + int channels = ch_layout->nb_channels; + + /* get the layout map based on the channel count */ + if ((tag & 0xFFFF) != channels) + return 0; + + layout_map = find_layout_map(tag, map); + if (layout_map) { + int i; + for (i = 0; i < channels; i++) { + if (av_channel_layout_channel_from_index(ch_layout, i) != layout_map[i].id) + break; + } + if (i == channels) + return 1; + } + return 0; +} + int ff_mov_get_channel_layout_tag(const AVCodecParameters *par, uint32_t *layout, uint32_t *bitmap, uint32_t **pchannel_desc) { - int i, j; + int i; uint32_t tag = 0; const enum MovChannelLayoutTag *layouts = NULL; @@ -379,26 +402,11 @@ int ff_mov_get_channel_layout_tag(const AVCodecParameters *par, layouts = mov_codec_ch_layouts[i].layouts; if (layouts) { - int channels; - const struct MovChannelLayoutMap *layout_map; - - /* get the layout map based on the channel count */ - channels = par->ch_layout.nb_channels; - /* find the layout tag for the specified channel layout */ - for (i = 0; layouts[i] != 0; i++) { - if ((layouts[i] & 0xFFFF) != channels) - continue; - layout_map = find_layout_map(layouts[i]); - if (layout_map) { - for (j = 0; j < channels; j++) { - if (av_channel_layout_channel_from_index(&par->ch_layout, j) != layout_map[j].id) - break; - } - if (j == channels) - break; - } - } + for (i = 0; layouts[i] != 0; i++) + if (is_layout_valid_for_tag(&par->ch_layout, layouts[i], mov_ch_layout_map)) + break; + tag = layouts[i]; } @@ -505,7 +513,7 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st, if (!ch_layout->nb_channels) ch_layout->nb_channels = nb_channels; if (nb_channels == ch_layout->nb_channels) { - ret = mov_get_channel_layout(ch_layout, layout_tag); + ret = mov_get_channel_layout(ch_layout, layout_tag, mov_ch_layout_map); if (ret < 0) return ret; } else {