From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 4AFA04A5F1 for ; Mon, 1 Apr 2024 18:56:45 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E14D468CFFC; Mon, 1 Apr 2024 21:56:38 +0300 (EEST) 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 { -- 2.35.3 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".