diff options
author | James Almer <jamrial@gmail.com> | 2024-04-26 11:37:10 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2024-04-30 11:15:13 -0300 |
commit | 37c8d93e56955638983d48e04f08d767eae265e1 (patch) | |
tree | 83524e6223d59c7e74dafaf94aaaef8420524da9 /libavformat/mov.c | |
parent | 08781ebe1aabe99b94e2ee949ca0c95c1443c756 (diff) | |
download | ffmpeg-37c8d93e56955638983d48e04f08d767eae265e1.tar.gz |
avformat/mov: support SpatialAudioBox ambisonic layouts with arbitrary channel mapping
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavformat/mov.c')
-rw-r--r-- | libavformat/mov.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/libavformat/mov.c b/libavformat/mov.c index ede25d3342..d99c971999 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7925,7 +7925,8 @@ cleanup: static int mov_read_SA3D(MOVContext *c, AVIOContext *pb, MOVAtom atom) { AVStream *st; - int i, version, type; + AVChannelLayout ch_layout = { 0 }; + int ret, i, version, type; int ambisonic_order, channel_order, normalization, channel_count; if (c->fc->nb_streams < 1) @@ -7968,24 +7969,38 @@ static int mov_read_SA3D(MOVContext *c, AVIOContext *pb, MOVAtom atom) } channel_count = avio_rb32(pb); - if (ambisonic_order < 0 || channel_count != (ambisonic_order + 1LL) * (ambisonic_order + 1LL)) { + if (ambisonic_order < 0 || ambisonic_order > 31 || + channel_count != (ambisonic_order + 1LL) * (ambisonic_order + 1LL)) { av_log(c->fc, AV_LOG_ERROR, "Invalid number of channels (%d / %d)\n", channel_count, ambisonic_order); return 0; } + ret = av_channel_layout_custom_init(&ch_layout, channel_count); + if (ret < 0) + return 0; + for (i = 0; i < channel_count; i++) { - if (i != avio_rb32(pb)) { - av_log(c->fc, AV_LOG_WARNING, - "Ambisonic channel reordering is not supported\n"); + unsigned channel = avio_rb32(pb); + + if (channel >= channel_count) { + av_log(c->fc, AV_LOG_ERROR, "Invalid channel index (%d / %d)\n", + channel, ambisonic_order); + av_channel_layout_uninit(&ch_layout); return 0; } + ch_layout.u.map[i].id = AV_CHAN_AMBISONIC_BASE + channel; + } + + ret = av_channel_layout_retype(&ch_layout, 0, AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL); + if (ret < 0) { + av_channel_layout_uninit(&ch_layout); + return 0; } av_channel_layout_uninit(&st->codecpar->ch_layout); - st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_AMBISONIC; - st->codecpar->ch_layout.nb_channels = channel_count; + st->codecpar->ch_layout = ch_layout; return 0; } |