From patchwork Mon Apr 1 18:56:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 47698 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp922552pzb; Mon, 1 Apr 2024 11:56:38 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU3lAHHZdeZof0jzRbckSohDkGzMMXDvH3Eef28Q9mzk+BdthsLzSidV2zTRhdDOosjGCFrpDaWllZZTdZMd4WTQtgQhWO5TxtyVw== X-Google-Smtp-Source: AGHT+IErToytDh9lWshXgWt7nX+tWihptvhYhpmHrbzgPRopwxgcOLWLz3XRkSl/+uu8byuZzE77 X-Received: by 2002:a05:6402:27cb:b0:56d:206d:a6e with SMTP id c11-20020a05640227cb00b0056d206d0a6emr6599880ede.0.1711997798627; Mon, 01 Apr 2024 11:56:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711997798; cv=none; d=google.com; s=arc-20160816; b=KQvi1ciIArvn9G/jS3Z+/zAKmCK1v9hSwvi7kQ0rlIau+p387nIy6IIXjh/rwNv0Fr FvrcYyOEeDXXlXP2aG/A7T9hyExrnUjPmQWtUHK+8SNFfFjCq2gYrep1fnngWrtYO/HZ sGzeQV3QLrJkvyMsMMjvHaa7gGbJ9wy8TiBEounPk8BBM1vtMzBVssvaYVtEs+Cmt6Uy elJFBqaWlKh+w0AVfmj8mnNPfrSu4rSc8HP7k2RQSPz3ZEMrkIyjG0N2nqDW1RK+t455 3pyvLXrObCLohp2zggpeKqcwvYf2guE9WGwxKF9Ykm/ytshA0Kc3i92rYg72P+aWcne9 g9Jw== 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:message-id:date:to:from :delivered-to; bh=YgnycRGKiYH+ByQQL77Y2dvBFnQlzQJcjv8qb8b/SKk=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=BhDi1FJXiZmerMDNXzNLS4CYeFTumTNcrNS7bdXFu08c9Ccc0dZ5iZwXxvuvW5IqjJ TFR0zXdNAIVl/RUc3CmLuLvaP2JzGhfCv2VZYjy1PblpwVSCOej7i56PeEpr2coAKO2K 93oqe2zVa0mQfBjMLq+1CdH0HwDoecP1Pj5z6bUxBHjm3TJv/Wohh+rDeMCElWvYoO1T OLsxFQ+yhJxLXSPw9XZ+5LNDynUM6UooGwFoPjfc5ZijH0Tneyb3vep3vARDeaZWJnoE UJj+0wOC6eBZJF2LH5e1oD+ANOhOb7icIvRxyeeD2bvdgvlYudb+C8zzK3AZZlKM2Wq/ 5K+Q==; 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 b10-20020a056402350a00b0056c06f5b037si5100463edd.315.2024.04.01.11.56.38; Mon, 01 Apr 2024 11:56:38 -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 0B78F68CFD1; Mon, 1 Apr 2024 21:56:36 +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 DCCC868CC1C for ; Mon, 1 Apr 2024 21:56:29 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id C3DCBEA2A1; Mon, 1 Apr 2024 20:56:29 +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 k4s3wwOdKfqc; Mon, 1 Apr 2024 20:56:27 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 9C3F7EA292; Mon, 1 Apr 2024 20:56:27 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Mon, 1 Apr 2024 20:56:18 +0200 Message-Id: <20240401185621.15297-1-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] avformat/mov_chan: check channel count at compile time by using a nonconst expression 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: +Uh5zKpZbws8 If the channel tag does not match the number of channels, the constant expression evaluation should fail. Signed-off-by: Marton Balint --- libavformat/mov_chan.c | 48 +++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index e7d181d71f..6ccc26b3f1 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -81,24 +81,28 @@ struct MovChannelLayoutMap { }; }; -#define TAG(_0) {.tag = _0} -#define ID(_0) {.id = c_##_0} -#define CHLIST(_0, ...) TAG(_0), __VA_ARGS__ -#define CHLIST01(_0, _1) CHLIST(_0, ID(_1)) -#define CHLIST02(_0, _1, _2) CHLIST(_0, ID(_1), ID(_2)) -#define CHLIST03(_0, _1, _2, _3) CHLIST(_0, ID(_1), ID(_2), ID(_3)) -#define CHLIST04(_0, _1, _2, _3, _4) CHLIST(_0, ID(_1), ID(_2), ID(_3), ID(_4)) -#define CHLIST05(_0, _1, _2, _3, _4, _5) CHLIST(_0, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5)) -#define CHLIST06(_0, _1, _2, _3, _4, _5, _6) CHLIST(_0, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6)) -#define CHLIST07(_0, _1, _2, _3, _4, _5, _6, _7) CHLIST(_0, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7)) -#define CHLIST08(_0, _1, _2, _3, _4, _5, _6, _7, _8) CHLIST(_0, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7), ID(_8)) -#define CHLIST09(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) CHLIST(_0, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7), ID(_8), ID(_9)) -#define CHLIST16(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16) \ - CHLIST(_0, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7), ID(_8), ID(_9), ID(_10), \ - ID(_11), ID(_12), ID(_13), ID(_14), ID(_15), ID(_16)) -#define CHLIST21(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21) \ - CHLIST(_0, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7), ID(_8), ID(_9), ID(_10), \ - ID(_11), ID(_12), ID(_13), ID(_14), ID(_15), ID(_16), ID(_17), ID(_18), ID(_19), ID(_20), ID(_21)) +static int nonconst_expr(void) { + return 0; +} + +#define TAG(_tag, _cnt) {.tag = (_tag & 0xffff) == _cnt ? _tag : nonconst_expr()} +#define ID(_0) {.id = c_##_0} +#define CHLIST(_tag, _cnt, ...) TAG(_tag, _cnt), __VA_ARGS__ +#define CHLIST01(_tag, _1) CHLIST(_tag, 1, ID(_1)) +#define CHLIST02(_tag, _1, _2) CHLIST(_tag, 2, ID(_1), ID(_2)) +#define CHLIST03(_tag, _1, _2, _3) CHLIST(_tag, 3, ID(_1), ID(_2), ID(_3)) +#define CHLIST04(_tag, _1, _2, _3, _4) CHLIST(_tag, 4, ID(_1), ID(_2), ID(_3), ID(_4)) +#define CHLIST05(_tag, _1, _2, _3, _4, _5) CHLIST(_tag, 5, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5)) +#define CHLIST06(_tag, _1, _2, _3, _4, _5, _6) CHLIST(_tag, 6, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6)) +#define CHLIST07(_tag, _1, _2, _3, _4, _5, _6, _7) CHLIST(_tag, 7, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7)) +#define CHLIST08(_tag, _1, _2, _3, _4, _5, _6, _7, _8) CHLIST(_tag, 8, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7), ID(_8)) +#define CHLIST09(_tag, _1, _2, _3, _4, _5, _6, _7, _8, _9) CHLIST(_tag, 9, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7), ID(_8), ID(_9)) +#define CHLIST16(_tag, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16) \ + CHLIST(_tag, 16, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7), ID(_8), ID(_9), ID(_10), \ + ID(_11), ID(_12), ID(_13), ID(_14), ID(_15), ID(_16)) +#define CHLIST21(_tag, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21) \ + CHLIST(_tag, 21, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7), ID(_8), ID(_9), ID(_10), \ + ID(_11), ID(_12), ID(_13), ID(_14), ID(_15), ID(_16), ID(_17), ID(_18), ID(_19), ID(_20), ID(_21)) static const struct MovChannelLayoutMap mov_ch_layout_map[] = { CHLIST01( MOV_CH_LAYOUT_MONO, C ), @@ -281,14 +285,6 @@ static const struct { static const struct MovChannelLayoutMap* find_layout_map(uint32_t tag) { -#if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1 - { - int i; - for (i = 0; i < FF_ARRAY_ELEMS(mov_ch_layout_map); i += 1 + (mov_ch_layout_map[i].tag & 0xffff)) - av_assert2(mov_ch_layout_map[i].tag & 0xffff0000); - av_assert2(i == FF_ARRAY_ELEMS(mov_ch_layout_map)); - } -#endif 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]; 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 { From patchwork Mon Apr 1 18:56:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 47700 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp922651pzb; Mon, 1 Apr 2024 11:56:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWbVP58sIg9Tcosx9vnAnKB7Xy5ITzYCUEXwKtov5kVvnx3NBNJtKM630Tfovi98X7b9TxYSrnWC5Z9FE95NQC8E91phJWr5XcJjA== X-Google-Smtp-Source: AGHT+IFIcFUeLRIdoBTif6N60UlmO8orE8GZZstQ2vZPVgI6MJoGEBnav3JHyTcuRIttWeeolmlz X-Received: by 2002:a17:906:eec7:b0:a4e:68bb:360 with SMTP id wu7-20020a170906eec700b00a4e68bb0360mr2713685ejb.3.1711997816662; Mon, 01 Apr 2024 11:56:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711997816; cv=none; d=google.com; s=arc-20160816; b=ZEc5HpEa6/MdslhQuKZ7WGY92Jlb8pDItFEdonmekH2rrdO+nkbEyuBjAYBYMYjH38 jQDz9qZ34FcE/EZ6eOwovxC371NPjA4S/lIOdBQ6oaNIrLHAypFk1tWlnMUTNYD1lTD0 4IqKk1qlwx2gS4GnNLSWQicgttvVrMbb0AeAv64b9ppnZD8rgfa2aZnftH8IzvVgTfq7 KIQjXpO4xCClCgFrWtRscqEno7DLYDwyDIuzPgx2iCcojxe7lV7pJuNXe7YL5PFVt2Jz QPlGP/TFz3x5hJ/xa85sO1Kz1PQhGXss9F/AXb68UYy5diPKwIIQq8H1a4oB3I3FZ95n 0BgA== 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=X2IqIUjcVx3YyPJ0HMc4B9QkvgRGPvwjZUTZeRjrmws=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=p/8/65KFzot8RG3qMPjvTWlGtcGuFIs+1hdZOp5O/dETNmzhBUCV9mX0dmGmcHMkIC HYaUN8WV7L8qy7oJtMJrnJmDFnRs1ti5xzEfMnOEdhiWL2ibEcUcJlJEEfVOribyuMJP Uqt1VCdQKq9XZrGcZj+i6IbtbK+n/roPg50QfoaFbNAW1orQUXkg5tgrdGbXfvxHRE7z v7DyInDVTYw7oo4oPNU9nSw4smFkp9I4ngaf0x8WSJTMbtrqJT1Hijl9qwGA7oYR43Bq oaeN0Ee6LFn4a7hDfENLwk154GgBgdXKjLlnHvaJeUWAwqEbvz14j9rJtx+CRA/MKdpN 8brg==; 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 14-20020a170906310e00b00a47325ce46bsi4515930ejx.200.2024.04.01.11.56.56; Mon, 01 Apr 2024 11:56:56 -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 3F20168D027; Mon, 1 Apr 2024 21:56:41 +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 3A00168CFEC for ; Mon, 1 Apr 2024 21:56:35 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 0C938EA292; Mon, 1 Apr 2024 20:56:35 +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 v5gwv0Jaw8rx; Mon, 1 Apr 2024 20:56:32 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 4B119EA349; Mon, 1 Apr 2024 20:56:32 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Mon, 1 Apr 2024 20:56:20 +0200 Message-Id: <20240401185621.15297-3-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 3/4] avformat/mov_chan: respect channel order when parsing and creating chnl atom 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: rezZn3NdGg4r Previously we always assumed that the channels are in native order, even if they were not. The new channel layout API allows us to signal the proper channel order, so let's do so. Signed-off-by: Marton Balint --- libavformat/mov_chan.c | 145 +++++++++++++++++++++---------------- libavformat/mov_chan.h | 5 +- tests/ref/fate/mov-mp4-pcm | 2 +- 3 files changed, 86 insertions(+), 66 deletions(-) diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index 9ee896f229..e3cef3f4e8 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -74,6 +74,46 @@ enum { c_Haptic = AV_CHAN_NONE, }; +enum { + iso_L = AV_CHAN_FRONT_LEFT, + iso_R = AV_CHAN_FRONT_RIGHT, + iso_C = AV_CHAN_FRONT_CENTER, + iso_LFE = AV_CHAN_LOW_FREQUENCY, + iso_Lsr = AV_CHAN_BACK_LEFT, + iso_Rsr = AV_CHAN_BACK_RIGHT, + iso_Lc = AV_CHAN_FRONT_LEFT_OF_CENTER, + iso_Rc = AV_CHAN_FRONT_RIGHT_OF_CENTER, + iso_Cs = AV_CHAN_BACK_CENTER, + /* Side and surround are not exactly the same, but in order to have + * consistent 5.1/7.1 layouts we map them to the side channels. */ + iso_Ls = AV_CHAN_SIDE_LEFT, + iso_Lss = AV_CHAN_SIDE_LEFT, + iso_Rs = AV_CHAN_SIDE_RIGHT, + iso_Rss = AV_CHAN_SIDE_RIGHT, + iso_Ts = AV_CHAN_TOP_CENTER, + iso_Lv = AV_CHAN_TOP_FRONT_LEFT, + iso_Cv = AV_CHAN_TOP_FRONT_CENTER, + iso_Rv = AV_CHAN_TOP_FRONT_RIGHT, + iso_Lvr = AV_CHAN_TOP_BACK_LEFT, + iso_Cvr = AV_CHAN_TOP_BACK_CENTER, + iso_Rvr = AV_CHAN_TOP_BACK_RIGHT, + // = AV_CHAN_STEREO_LEFT, + // = AV_CHAN_STEREO_RIGHT, + iso_Lw = AV_CHAN_WIDE_LEFT, + iso_Rw = AV_CHAN_WIDE_RIGHT, + iso_Lsd = AV_CHAN_SURROUND_DIRECT_LEFT, + iso_Rsd = AV_CHAN_SURROUND_DIRECT_RIGHT, + iso_LFE2 = AV_CHAN_LOW_FREQUENCY_2, + iso_Lvss = AV_CHAN_TOP_SIDE_LEFT, + iso_Rvss = AV_CHAN_TOP_SIDE_RIGHT, + iso_Cb = AV_CHAN_BOTTOM_FRONT_CENTER, + iso_Lb = AV_CHAN_BOTTOM_FRONT_LEFT, + iso_Rb = AV_CHAN_BOTTOM_FRONT_RIGHT, + /* The following have no exact counterparts */ + iso_Lvs = AV_CHAN_NONE, + iso_Rvs = AV_CHAN_NONE, +}; + struct MovChannelLayoutMap { union { uint32_t tag; @@ -103,6 +143,10 @@ static int nonconst_expr(void) { #define CHLIST21(_tag, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21) \ CHLIST(_tag, 21, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7), ID(_8), ID(_9), ID(_10), \ ID(_11), ID(_12), ID(_13), ID(_14), ID(_15), ID(_16), ID(_17), ID(_18), ID(_19), ID(_20), ID(_21)) +#define CHLIST24(_tag, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24) \ + CHLIST(_tag, 24, ID(_1), ID(_2), ID(_3), ID(_4), ID(_5), ID(_6), ID(_7), ID(_8), ID(_9), ID(_10), \ + ID(_11), ID(_12), ID(_13), ID(_14), ID(_15), ID(_16), ID(_17), ID(_18), ID(_19), ID(_20), \ + ID(_21), ID(_22), ID(_23), ID(_24)) static const struct MovChannelLayoutMap mov_ch_layout_map[] = { CHLIST01( MOV_CH_LAYOUT_MONO, C ), @@ -190,6 +234,29 @@ static const struct MovChannelLayoutMap mov_ch_layout_map[] = { { {0} }, }; +#undef ID +#undef TAG +#define ID(_0) {.id = iso_##_0} +#define TAG(_tag, _cnt) {.tag = (_tag << 16) | _cnt} + +/* ISO/IEC 23001-8 */ +static const struct MovChannelLayoutMap iso_ch_layout_map[] = { + CHLIST01( 1, C ), + CHLIST02( 2, L, R ), + CHLIST03( 3, C, L, R ), + CHLIST04( 4, C, L, R, Cs ), + CHLIST05( 5, C, L, R, Ls, Rs ), + CHLIST06( 6, C, L, R, Ls, Rs, LFE ), + CHLIST08( 7, C, Lc, Rc, L, R, Ls, Rs, LFE ), + CHLIST03( 9, L, R, Cs ), + CHLIST04( 10, L, R, Ls, Rs ), + CHLIST07( 11, C, L, R, Ls, Rs, Cs, LFE ), + CHLIST08( 12, C, L, R, Ls, Rs, Lsr, Rsr, LFE ), + CHLIST24( 13, C, Lc, Rc, L, R, Lss, Rss, Lsr, Rsr, Cs, LFE, LFE2, Cv, Lv, Rv, Lvss, Rvss, Ts, Lvr, Rvr, Cvr, Cb, Lb, Rb), + CHLIST08( 14, C, L, R, Ls, Rs, LFE, Lv, Rv), + { {0} }, +}; + static const enum MovChannelLayoutTag mov_ch_layouts_aac[] = { MOV_CH_LAYOUT_MONO, MOV_CH_LAYOUT_STEREO, @@ -529,60 +596,6 @@ out: return ret; } -/* ISO/IEC 23001-8, 8.2 */ -static const AVChannelLayout iso_channel_configuration[] = { - // 0: any setup - {0}, - - // 1: centre front - AV_CHANNEL_LAYOUT_MONO, - - // 2: left front, right front - AV_CHANNEL_LAYOUT_STEREO, - - // 3: centre front, left front, right front - AV_CHANNEL_LAYOUT_SURROUND, - - // 4: centre front, left front, right front, rear centre - AV_CHANNEL_LAYOUT_4POINT0, - - // 5: centre front, left front, right front, left surround, right surround - AV_CHANNEL_LAYOUT_5POINT0, - - // 6: 5 + LFE - AV_CHANNEL_LAYOUT_5POINT1, - - // 7: centre front, left front centre, right front centre, - // left front, right front, left surround, right surround, LFE - AV_CHANNEL_LAYOUT_7POINT1_WIDE, - - // 8: channel1, channel2 - AV_CHANNEL_LAYOUT_STEREO_DOWNMIX, - - // 9: left front, right front, rear centre - AV_CHANNEL_LAYOUT_2_1, - - // 10: left front, right front, left surround, right surround - AV_CHANNEL_LAYOUT_2_2, - - // 11: centre front, left front, right front, left surround, right surround, rear centre, LFE - AV_CHANNEL_LAYOUT_6POINT1, - - // 12: centre front, left front, right front - // left surround, right surround - // rear surround left, rear surround right - // LFE - AV_CHANNEL_LAYOUT_7POINT1, - - // 13: - AV_CHANNEL_LAYOUT_22POINT2, - - // 14: - AV_CHANNEL_LAYOUT_7POINT1_TOP_BACK, - - // TODO: 15 - 20 -}; - /* ISO/IEC 23001-8, table 8 */ static const enum AVChannel iso_channel_position[] = { // 0: left front @@ -718,9 +731,9 @@ int ff_mov_get_channel_config_from_layout(const AVChannelLayout *layout, int *co { // Set default value which means any setup in 23001-8 *config = 0; - for (int i = 0; i < FF_ARRAY_ELEMS(iso_channel_configuration); i++) { - if (!av_channel_layout_compare(layout, iso_channel_configuration + i)) { - *config = i; + for (int i = 0; iso_ch_layout_map[i].tag & 0xffff; i += 1 + (iso_ch_layout_map[i].tag & 0xffff)) { + if (is_layout_valid_for_tag(layout, iso_ch_layout_map[i].tag, &iso_ch_layout_map[i])) { + *config = iso_ch_layout_map[i].tag >> 16; break; } } @@ -730,12 +743,16 @@ int ff_mov_get_channel_config_from_layout(const AVChannelLayout *layout, int *co int ff_mov_get_channel_layout_from_config(int config, AVChannelLayout *layout) { - if (config > 0 && config < FF_ARRAY_ELEMS(iso_channel_configuration)) { - av_channel_layout_copy(layout, &iso_channel_configuration[config]); - return 0; - } + if (config > 0) { + uint32_t layout_tag; + + if (layout->nb_channels <= 0 || layout->nb_channels > UINT16_MAX) + return AVERROR_INVALIDDATA; - return -1; + layout_tag = (config << 16) | layout->nb_channels; + return mov_get_channel_layout(layout, layout_tag, iso_ch_layout_map); + } + return 1; } int ff_mov_get_channel_positions_from_layout(const AVChannelLayout *layout, @@ -815,7 +832,9 @@ int ff_mov_read_chnl(AVFormatContext *s, AVIOContext *pb, AVStream *st) omitted_channel_map); return AVERROR_PATCHWELCOME; } - ff_mov_get_channel_layout_from_config(layout, &st->codecpar->ch_layout); + ret = ff_mov_get_channel_layout_from_config(layout, &st->codecpar->ch_layout); + if (ret < 0) + return ret; } } diff --git a/libavformat/mov_chan.h b/libavformat/mov_chan.h index e480809c44..604395d7d3 100644 --- a/libavformat/mov_chan.h +++ b/libavformat/mov_chan.h @@ -172,9 +172,10 @@ int ff_mov_get_channel_config_from_layout(const AVChannelLayout *layout, int *co /** * Get AVChannelLayout from ISO/IEC 23001-8 ChannelConfiguration. * - * @return 0 for success, -1 for doesn't match, layout is untouched on failure + * @return 1 if the config was unknown, layout is untouched in this case + * 0 if the config was found + * <0 on error */ - int ff_mov_get_channel_layout_from_config(int config, AVChannelLayout *layout); /** diff --git a/tests/ref/fate/mov-mp4-pcm b/tests/ref/fate/mov-mp4-pcm index 6bae8f800b..19a978df95 100644 --- a/tests/ref/fate/mov-mp4-pcm +++ b/tests/ref/fate/mov-mp4-pcm @@ -1,4 +1,4 @@ -99ad26b4054794e84bd962a1124cdccf *tests/data/fate/mov-mp4-pcm.mp4 +462668dd69e7ce4fde4934d1d5978531 *tests/data/fate/mov-mp4-pcm.mp4 10587977 tests/data/fate/mov-mp4-pcm.mp4 #tb 0: 1/44100 #media_type 0: audio From patchwork Mon Apr 1 18:56:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 47701 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp922718pzb; Mon, 1 Apr 2024 11:57:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWk42OvZGZql6T+Np0ZSrtA+sp9OE/r2gyR3+oCasOcREgq4R8anXhmzLMRQ4CBycActADDs8pWF7SwnVtQEz9AK3yLFpwG9a8faw== X-Google-Smtp-Source: AGHT+IEmPoiNVq8PIamLPekAp+MVHaPR2428JxXguCqNys1MaeWaYeZASfzBRUnnX35db/t8XzWc X-Received: by 2002:a50:ed01:0:b0:56c:5a49:731 with SMTP id j1-20020a50ed01000000b0056c5a490731mr6484855eds.1.1711997826185; Mon, 01 Apr 2024 11:57:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711997826; cv=none; d=google.com; s=arc-20160816; b=yQUh2C+/Udm0lyM/poCfb1Wepg7envPh2n2PD5ABBY+OSIbkX2+qQHwJm8iFIiY1iO +8ffFpGzw8Ep39TLX3PsciTYgM2vUU0AxZXvi0ev+rewFmSPgPoITBrigX6+HziOGt0P y7neiASiXBl7JrqluOA97ogJ0AoSzmvXyASHxxFho6VPK2xm/BsCyxMcgPwmWaNFfhzu IR6SEvEh1TTeh1PJ3n2J0fblsFZoTCN7Rqt3X1BFPmcvVtmFpzwXUgWtnc0J49Tz06xO lFyYRs3ZGWXsikqrXDnSXsZf41yPvX4N43BLEhFdIjPUl8YsJzwSTl3+A9sAFplvmIFQ O9XA== 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=LVbzQkZSCu2V4yErLPdLciTM4TDdMV2malQavCtTQeA=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=FSj48tVu/s5qbwwIqyvLrUm4yMYvOVTv884GDoGap+ToMu2npL1TO3VB6ZEQ8leBP0 mkrk2pYkiFklbuUjpkdPcdb7gigWYxjW1JecxSC7aVzoeHAOo2p1cQvq0C1583Bb322W xIUAfpZgoWvTtTls+EyPclHuRr1NhD6mqAZkhfaWKyvGEgu+XYXvJpRcmJRspURSqiz6 5/PV8y1OWYiH5Nznsz4msL6ehZmqAbNiakdnxe/ueTf9GEVM5ky/I4QXVRz2UnCz9JAr +yctpT2teEfaGhXVRxMZ/6PkIgSrq139E8gqRV9OQZr1V5esnOnK6kNUfnZXXp5npDTR AHbw==; 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 r9-20020a056402234900b00568c171cc3fsi4877215eda.19.2024.04.01.11.57.05; Mon, 01 Apr 2024 11:57:06 -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 558AB68CAA7; Mon, 1 Apr 2024 21:56:48 +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 686D868CAA7 for ; Mon, 1 Apr 2024 21:56:42 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 4CBB8EA2A1; Mon, 1 Apr 2024 20:56:42 +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 FBKDW6xYzRc4; Mon, 1 Apr 2024 20:56:40 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 4931EEA292; Mon, 1 Apr 2024 20:56:40 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Mon, 1 Apr 2024 20:56:21 +0200 Message-Id: <20240401185621.15297-4-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 4/4] avformat/mov_chan: add support for omitted_channel bitmask in chnl atom 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: kHqa/9yYhgI1 Signed-off-by: Marton Balint --- libavformat/mov_chan.c | 43 ++++++++++++++++++++++-------------------- libavformat/mov_chan.h | 2 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index e3cef3f4e8..e591ff031b 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -367,25 +367,33 @@ static const struct MovChannelLayoutMap* find_layout_map(uint32_t tag, const str * @param[in] tag channel layout tag * @return <0 on error */ -static int mov_get_channel_layout(AVChannelLayout *ch_layout, uint32_t tag, const struct MovChannelLayoutMap *map) +static int mov_get_channel_layout(AVChannelLayout *ch_layout, uint32_t tag, uint64_t omitted_channel_map, const struct MovChannelLayoutMap *map) { - int i, channels; const struct MovChannelLayoutMap *layout_map; - channels = tag & 0xFFFF; - /* find the channel layout for the specified layout tag */ layout_map = find_layout_map(tag, map); if (layout_map) { int ret; + int map_layout_nb_channels = tag & 0xFFFF; + int nb_channels = ch_layout->nb_channels; + + /* Omitted channel bits must not exceed number of channels in map */ + if (omitted_channel_map >> map_layout_nb_channels) + return AVERROR_INVALIDDATA; + av_channel_layout_uninit(ch_layout); - ret = av_channel_layout_custom_init(ch_layout, channels); + ret = av_channel_layout_custom_init(ch_layout, nb_channels); if (ret < 0) return ret; - for (i = 0; i < channels; i++) { - enum AVChannel id = layout_map[i].id; - ch_layout->u.map[i].id = (id != AV_CHAN_NONE ? id : AV_CHAN_UNKNOWN); + + for (int i = 0, idx = 0; i < map_layout_nb_channels && idx < nb_channels; i++, omitted_channel_map >>= 1) { + if (!(omitted_channel_map & 1)) { + enum AVChannel id = layout_map[i].id; + ch_layout->u.map[idx++].id = (id != AV_CHAN_NONE ? id : AV_CHAN_UNKNOWN); + } } + return av_channel_layout_retype(ch_layout, 0, AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL); } return 0; @@ -580,7 +588,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, mov_ch_layout_map); + ret = mov_get_channel_layout(ch_layout, layout_tag, 0, mov_ch_layout_map); if (ret < 0) return ret; } else { @@ -741,16 +749,17 @@ int ff_mov_get_channel_config_from_layout(const AVChannelLayout *layout, int *co return 0; } -int ff_mov_get_channel_layout_from_config(int config, AVChannelLayout *layout) +int ff_mov_get_channel_layout_from_config(int config, AVChannelLayout *layout, uint64_t omitted_channel_map) { if (config > 0) { uint32_t layout_tag; + int nb_omitted_channels = av_popcount64(omitted_channel_map); - if (layout->nb_channels <= 0 || layout->nb_channels > UINT16_MAX) + if (layout->nb_channels <= 0 || layout->nb_channels > UINT16_MAX - nb_omitted_channels) return AVERROR_INVALIDDATA; - layout_tag = (config << 16) | layout->nb_channels; - return mov_get_channel_layout(layout, layout_tag, iso_ch_layout_map); + layout_tag = (config << 16) | (layout->nb_channels + nb_omitted_channels); + return mov_get_channel_layout(layout, layout_tag, omitted_channel_map, iso_ch_layout_map); } return 1; } @@ -826,13 +835,7 @@ int ff_mov_read_chnl(AVFormatContext *s, AVIOContext *pb, AVStream *st) return ret; } else { uint64_t omitted_channel_map = avio_rb64(pb); - - if (omitted_channel_map) { - avpriv_request_sample(s, "omitted_channel_map 0x%" PRIx64 " != 0", - omitted_channel_map); - return AVERROR_PATCHWELCOME; - } - ret = ff_mov_get_channel_layout_from_config(layout, &st->codecpar->ch_layout); + ret = ff_mov_get_channel_layout_from_config(layout, &st->codecpar->ch_layout, omitted_channel_map); if (ret < 0) return ret; } diff --git a/libavformat/mov_chan.h b/libavformat/mov_chan.h index 604395d7d3..ea8be47196 100644 --- a/libavformat/mov_chan.h +++ b/libavformat/mov_chan.h @@ -176,7 +176,7 @@ int ff_mov_get_channel_config_from_layout(const AVChannelLayout *layout, int *co * 0 if the config was found * <0 on error */ -int ff_mov_get_channel_layout_from_config(int config, AVChannelLayout *layout); +int ff_mov_get_channel_layout_from_config(int config, AVChannelLayout *layout, uint64_t omitted_channel_map); /** * Get ISO/IEC 23001-8 OutputChannelPosition from AVChannelLayout.