From: Marton Balint <cus@passwd.hu>
To: ffmpeg-devel@ffmpeg.org
Cc: Marton Balint <cus@passwd.hu>
Subject: [FFmpeg-devel] [PATCH 4/4] avformat/mov_chan: add support for omitted_channel bitmask in chnl atom
Date: Mon, 1 Apr 2024 20:56:21 +0200
Message-ID: <20240401185621.15297-4-cus@passwd.hu> (raw)
In-Reply-To: <20240401185621.15297-1-cus@passwd.hu>
Signed-off-by: Marton Balint <cus@passwd.hu>
---
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.
--
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".
next prev parent reply other threads:[~2024-04-01 18:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-01 18:56 [FFmpeg-devel] [PATCH 1/4] avformat/mov_chan: check channel count at compile time by using a nonconst expression Marton Balint
2024-04-01 18:56 ` [FFmpeg-devel] [PATCH 2/4] avformat/mov_chan: factorize some layout map search functions Marton Balint
2024-04-01 18:56 ` [FFmpeg-devel] [PATCH 3/4] avformat/mov_chan: respect channel order when parsing and creating chnl atom Marton Balint
2024-04-01 19:37 ` James Almer
2024-04-01 20:43 ` Marton Balint
2024-04-01 18:56 ` Marton Balint [this message]
2024-04-01 20:41 ` [FFmpeg-devel] [PATCH 1/4] avformat/mov_chan: check channel count at compile time by using a nonconst expression Andreas Rheinhardt
2024-04-02 22:40 ` [FFmpeg-devel] [PATCH v2 1/4] avformat/mov_chan: check channel count of layout tags at compile time Marton Balint
2024-04-08 19:48 ` Marton Balint
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240401185621.15297-4-cus@passwd.hu \
--to=cus@passwd.hu \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git