* [FFmpeg-devel] [PATCH 1/9] avformat/iamf_writer: ensure each layer's channel layout contains all channels from the previous one
@ 2025-06-18 1:38 James Almer
2025-06-18 1:38 ` [FFmpeg-devel] [PATCH 2/9] avformat/iamf_parse: try to retype the channel layout for ambisonics_mode == 0 James Almer
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: James Almer @ 2025-06-18 1:38 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/iamf_writer.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c
index 60a0990504..e34afb9a2c 100644
--- a/libavformat/iamf_writer.c
+++ b/libavformat/iamf_writer.c
@@ -245,7 +245,9 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void
return AVERROR(EINVAL);
}
}
- } else
+ } else {
+ AVBPrint bp;
+
for (int j, i = 0; i < iamf_audio_element->nb_layers; i++) {
const AVIAMFLayer *layer = iamf_audio_element->layers[i];
for (j = 0; j < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts); j++)
@@ -257,7 +259,6 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void
if (!av_channel_layout_compare(&layer->ch_layout, &ff_iamf_expanded_scalable_ch_layouts[j]))
break;
if (j >= FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts)) {
- AVBPrint bp;
av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
av_channel_layout_describe_bprint(&layer->ch_layout, &bp);
av_log(log_ctx, AV_LOG_ERROR, "Unsupported channel layout in Audio Element id %"PRId64
@@ -267,7 +268,26 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void
return AVERROR(EINVAL);
}
}
+
+ if (!i)
+ continue;
+
+ const AVIAMFLayer *prev_layer = iamf_audio_element->layers[i-1];
+ uint64_t prev_mask = av_channel_layout_subset(&prev_layer->ch_layout, UINT64_MAX);
+ if (av_channel_layout_subset(&layer->ch_layout, prev_mask) != prev_mask || (layer->ch_layout.nb_channels <=
+ prev_layer->ch_layout.nb_channels)) {
+ av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
+ av_bprintf(&bp, "Channel layout \"");
+ av_channel_layout_describe_bprint(&layer->ch_layout, &bp);
+ av_bprintf(&bp, "\" can't follow channel layout \"");
+ av_channel_layout_describe_bprint(&prev_layer->ch_layout, &bp);
+ av_bprintf(&bp, "\" in Scalable Audio Element id %"PRId64, stg->id);
+ av_log(log_ctx, AV_LOG_ERROR, "%s\n", bp.str);
+ av_bprint_finalize(&bp, NULL);
+ return AVERROR(EINVAL);
+ }
}
+ }
for (int i = 0; i < iamf->nb_audio_elements; i++) {
if (stg->id == iamf->audio_elements[i]->audio_element_id) {
--
2.50.0
_______________________________________________
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 2/9] avformat/iamf_parse: try to retype the channel layout for ambisonics_mode == 0
2025-06-18 1:38 [FFmpeg-devel] [PATCH 1/9] avformat/iamf_writer: ensure each layer's channel layout contains all channels from the previous one James Almer
@ 2025-06-18 1:38 ` James Almer
2025-06-18 1:38 ` [FFmpeg-devel] [PATCH 3/9] tests/iamf: reorder muxed streams James Almer
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: James Almer @ 2025-06-18 1:38 UTC (permalink / raw)
To: ffmpeg-devel
In most cases, the channel ids will match the standard Ambisonic Order, saving us the
need to use a custom order layout.
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/iamf_parse.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/libavformat/iamf_parse.c b/libavformat/iamf_parse.c
index 71497876ac..f37edf5156 100644
--- a/libavformat/iamf_parse.c
+++ b/libavformat/iamf_parse.c
@@ -458,14 +458,16 @@ static int ambisonics_config(void *s, AVIOContext *pb,
return ret;
}
- layer->ch_layout.order = AV_CHANNEL_ORDER_CUSTOM;
- layer->ch_layout.nb_channels = output_channel_count;
- layer->ch_layout.u.map = av_calloc(output_channel_count, sizeof(*layer->ch_layout.u.map));
- if (!layer->ch_layout.u.map)
- return AVERROR(ENOMEM);
+ ret = av_channel_layout_custom_init(&layer->ch_layout, output_channel_count);
+ if (ret < 0)
+ return ret;
for (int i = 0; i < output_channel_count; i++)
layer->ch_layout.u.map[i].id = avio_r8(pb) + AV_CHAN_AMBISONIC_BASE;
+
+ ret = av_channel_layout_retype(&layer->ch_layout, AV_CHANNEL_ORDER_AMBISONIC, 0);
+ if (ret < 0 && ret != AVERROR(ENOSYS))
+ return ret;
} else {
int coupled_substream_count = avio_r8(pb); // M
int nb_demixing_matrix = substream_count + coupled_substream_count;
--
2.50.0
_______________________________________________
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 3/9] tests/iamf: reorder muxed streams
2025-06-18 1:38 [FFmpeg-devel] [PATCH 1/9] avformat/iamf_writer: ensure each layer's channel layout contains all channels from the previous one James Almer
2025-06-18 1:38 ` [FFmpeg-devel] [PATCH 2/9] avformat/iamf_parse: try to retype the channel layout for ambisonics_mode == 0 James Almer
@ 2025-06-18 1:38 ` James Almer
2025-06-18 1:38 ` [FFmpeg-devel] [PATCH 4/9] tests/iamf: rename BACK to SIDE filterchain labels in the 5.1.4 iamf tests James Almer
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: James Almer @ 2025-06-18 1:38 UTC (permalink / raw)
To: ffmpeg-devel
Follows the proper order defined by the spec, even if mostly cosmetic, and is
also preparation for a following change.
Signed-off-by: James Almer <jamrial@gmail.com>
---
tests/fate/iamf.mak | 4 +-
tests/fate/mov.mak | 4 +-
tests/ref/fate/iamf-9_1_6 | 82 +++++++++++++++++++--------------------
3 files changed, 45 insertions(+), 45 deletions(-)
diff --git a/tests/fate/iamf.mak b/tests/fate/iamf.mak
index 6b2a60cb2f..ff745bc59a 100644
--- a/tests/fate/iamf.mak
+++ b/tests/fate/iamf.mak
@@ -24,7 +24,7 @@ fate-iamf-7_1_4: CMD = transcode wav $(SRC) iamf "-auto_conversion_filters \
-/filter_complex $(TARGET_PATH)/tests/data/filtergraphs/iamf_7_1_4 \
-/stream_group $(TARGET_PATH)/tests/data/streamgroups/audio_element-7_1_4 \
-/stream_group $(TARGET_PATH)/tests/data/streamgroups/mix_presentation-7_1_4 \
- -streamid 0:0 -streamid 1:1 -streamid 2:2 -streamid 3:3 -streamid 4:4 -streamid 5:5 -streamid 6:6 -map [FRONT] -map [BACK] -map [CENTER] -map [LFE] -map [SIDE] -map [TOP_FRONT] -map [TOP_BACK] -c:a flac -t 1" "-c:a copy -map 0" \
+ -streamid 0:0 -streamid 1:1 -streamid 2:2 -streamid 3:3 -streamid 4:4 -streamid 5:5 -streamid 6:6 -map [FRONT] -map [TOP_FRONT] -map [CENTER] -map [LFE] -map [SIDE] -map [BACK] -map [TOP_BACK] -c:a flac -t 1" "-c:a copy -map 0" \
"-show_entries stream_group=index,id,nb_streams,type:stream_group_components:stream_group_stream=index,id:stream_group_stream_disposition"
FATE_IAMF-$(call TRANSCODE, FLAC, IAMF, WAV_DEMUXER PCM_S16LE_DECODER ARESAMPLE_FILTER) += fate-iamf-9_1_6
@@ -35,7 +35,7 @@ fate-iamf-9_1_6: CMD = transcode wav $(SRC) iamf "-auto_conversion_filters \
-/stream_group $(TARGET_PATH)/tests/data/streamgroups/audio_element-9_1_6 \
-/stream_group $(TARGET_PATH)/tests/data/streamgroups/audio_element-9_1_6-stereo \
-/stream_group $(TARGET_PATH)/tests/data/streamgroups/mix_presentation-9_1_6 \
- -streamid 0:0 -streamid 1:1 -streamid 2:2 -streamid 3:3 -streamid 4:4 -streamid 5:5 -streamid 6:6 -streamid 7:7 -streamid 8:8 -streamid 9:9 -map [FRONT] -map [BACK] -map [CENTER] -map [LFE] -map [FRONT_CENTER] -map [SIDE] -map [TOP_FRONT] -map [TOP_BACK] -map [TOP_SIDE] -map [STEREO] -c:a flac -t 1" "-c:a copy -map 0" \
+ -streamid 0:0 -streamid 1:1 -streamid 2:2 -streamid 3:3 -streamid 4:4 -streamid 5:5 -streamid 6:6 -streamid 7:7 -streamid 8:8 -streamid 9:9 -map [FRONT] -map [FRONT_CENTER] -map [SIDE] -map [BACK] -map [TOP_FRONT] -map [TOP_SIDE] -map [TOP_BACK] -map [CENTER] -map [LFE] -map [STEREO] -c:a flac -t 1" "-c:a copy -map 0" \
"-show_entries stream_group=index,id,nb_streams,type:stream_group_components:stream_group_stream=index,id:stream_group_stream_disposition"
FATE_IAMF-$(call TRANSCODE, FLAC, IAMF, WAV_DEMUXER PCM_S16LE_DECODER ARESAMPLE_FILTER) += fate-iamf-ambisonic_1
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 71796879c3..4f6231abbc 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -265,7 +265,7 @@ fate-mov-mp4-iamf-7_1_4-video-first: CMD = transcode wav $(SRC) mp4 "-auto_conve
-/filter_complex $(TARGET_PATH)/tests/data/filtergraphs/iamf_7_1_4 \
-/stream_group $(TARGET_PATH)/tests/data/streamgroups/audio_element-7_1_4-2 \
-/stream_group $(TARGET_PATH)/tests/data/streamgroups/mix_presentation-7_1_4 \
- -streamid 0:1 -streamid 1:2 -streamid 2:3 -streamid 3:4 -streamid 4:5 -streamid 5:6 -streamid 6:7 -streamid 7:8 -map 1:v:0 -map [FRONT] -map [BACK] -map [CENTER] -map [LFE] -map [SIDE] -map [TOP_FRONT] -map [TOP_BACK] -c:a flac -c:v mpeg4 -t 1" "-c:a copy -c:v copy -map 0" \
+ -streamid 0:1 -streamid 1:2 -streamid 2:3 -streamid 3:4 -streamid 4:5 -streamid 5:6 -streamid 6:7 -streamid 7:8 -map 1:v:0 -map [FRONT] -map [TOP_FRONT] -map [CENTER] -map [LFE] -map [SIDE] -map [BACK] -map [TOP_BACK] -c:a flac -c:v mpeg4 -t 1" "-c:a copy -c:v copy -map 0" \
"-show_entries stream_group=index,id,nb_streams,type:stream_group_components:stream_group_disposition:stream_group_tags:stream_group_stream=index,id:stream_group_stream_disposition:stream=index,id" \
"-f rawvideo -s 352x288 -pix_fmt yuv420p -i $(SRC2)"
@@ -278,7 +278,7 @@ fate-mov-mp4-iamf-7_1_4-video-last: CMD = transcode wav $(SRC) mp4 "-auto_conver
-/filter_complex $(TARGET_PATH)/tests/data/filtergraphs/iamf_7_1_4 \
-/stream_group $(TARGET_PATH)/tests/data/streamgroups/audio_element-7_1_4 \
-/stream_group $(TARGET_PATH)/tests/data/streamgroups/mix_presentation-7_1_4 \
- -streamid 0:1 -streamid 1:2 -streamid 2:3 -streamid 3:4 -streamid 4:5 -streamid 5:6 -streamid 6:7 -streamid 7:8 -map [FRONT] -map [BACK] -map [CENTER] -map [LFE] -map [SIDE] -map [TOP_FRONT] -map [TOP_BACK] -map 1:v:0 -use_stream_ids_as_track_ids true -c:a flac -c:v mpeg4 -t 1" "-c:a copy -c:v copy -map 0" \
+ -streamid 0:1 -streamid 1:2 -streamid 2:3 -streamid 3:4 -streamid 4:5 -streamid 5:6 -streamid 6:7 -streamid 7:8 -map [FRONT] -map [TOP_FRONT] -map [CENTER] -map [LFE] -map [SIDE] -map [BACK] -map [TOP_BACK] -map 1:v:0 -use_stream_ids_as_track_ids true -c:a flac -c:v mpeg4 -t 1" "-c:a copy -c:v copy -map 0" \
"-show_entries stream_group=index,id,nb_streams,type:stream_group_components:stream_group_disposition:stream_group_tags:stream_group_stream=index,id:stream_group_stream_disposition:stream=index,id" \
"-f rawvideo -s 352x288 -pix_fmt yuv420p -i $(SRC2)"
diff --git a/tests/ref/fate/iamf-9_1_6 b/tests/ref/fate/iamf-9_1_6
index 0f5cc44fd1..0c55a22774 100644
--- a/tests/ref/fate/iamf-9_1_6
+++ b/tests/ref/fate/iamf-9_1_6
@@ -1,4 +1,4 @@
-bf3dd0294cbf9b842d09f388da706554 *tests/data/fate/iamf-9_1_6.iamf
+bba1dc4edb2c5011dfddfe53bd412e99 *tests/data/fate/iamf-9_1_6.iamf
142594 tests/data/fate/iamf-9_1_6.iamf
#extradata 0: 34, 0xafa70d5e
#extradata 1: 34, 0xafa70d5e
@@ -62,103 +62,103 @@ bf3dd0294cbf9b842d09f388da706554 *tests/data/fate/iamf-9_1_6.iamf
#channel_layout_name 9: stereo
0, 0, 0, 4608, 1399, 0x6e89566e
1, 0, 0, 4608, 1399, 0x6e89566e
-2, 0, 0, 4608, 1396, 0x0dcb5677
-3, 0, 0, 4608, 1396, 0x0dcb5677
+2, 0, 0, 4608, 1399, 0x6e89566e
+3, 0, 0, 4608, 1399, 0x6e89566e
4, 0, 0, 4608, 1399, 0x6e89566e
5, 0, 0, 4608, 1399, 0x6e89566e
6, 0, 0, 4608, 1399, 0x6e89566e
-7, 0, 0, 4608, 1399, 0x6e89566e
-8, 0, 0, 4608, 1399, 0x6e89566e
+7, 0, 0, 4608, 1396, 0x0dcb5677
+8, 0, 0, 4608, 1396, 0x0dcb5677
9, 0, 0, 4608, 1399, 0x6e89566e
0, 4608, 4608, 4608, 1442, 0x6c3c5b13
1, 4608, 4608, 4608, 1442, 0x6c3c5b13
-2, 4608, 4608, 4608, 1439, 0xc46b5ac5
-3, 4608, 4608, 4608, 1439, 0xc46b5ac5
+2, 4608, 4608, 4608, 1442, 0x6c3c5b13
+3, 4608, 4608, 4608, 1442, 0x6c3c5b13
4, 4608, 4608, 4608, 1442, 0x6c3c5b13
5, 4608, 4608, 4608, 1442, 0x6c3c5b13
6, 4608, 4608, 4608, 1442, 0x6c3c5b13
-7, 4608, 4608, 4608, 1442, 0x6c3c5b13
-8, 4608, 4608, 4608, 1442, 0x6c3c5b13
+7, 4608, 4608, 4608, 1439, 0xc46b5ac5
+8, 4608, 4608, 4608, 1439, 0xc46b5ac5
9, 4608, 4608, 4608, 1442, 0x6c3c5b13
0, 9216, 9216, 4608, 1380, 0xc497571b
1, 9216, 9216, 4608, 1380, 0xc497571b
-2, 9216, 9216, 4608, 1377, 0x5b2a55fe
-3, 9216, 9216, 4608, 1377, 0x5b2a55fe
+2, 9216, 9216, 4608, 1380, 0xc497571b
+3, 9216, 9216, 4608, 1380, 0xc497571b
4, 9216, 9216, 4608, 1380, 0xc497571b
5, 9216, 9216, 4608, 1380, 0xc497571b
6, 9216, 9216, 4608, 1380, 0xc497571b
-7, 9216, 9216, 4608, 1380, 0xc497571b
-8, 9216, 9216, 4608, 1380, 0xc497571b
+7, 9216, 9216, 4608, 1377, 0x5b2a55fe
+8, 9216, 9216, 4608, 1377, 0x5b2a55fe
9, 9216, 9216, 4608, 1380, 0xc497571b
0, 13824, 13824, 4608, 1383, 0x48e9510f
1, 13824, 13824, 4608, 1383, 0x48e9510f
-2, 13824, 13824, 4608, 1380, 0x045550d3
-3, 13824, 13824, 4608, 1380, 0x045550d3
+2, 13824, 13824, 4608, 1383, 0x48e9510f
+3, 13824, 13824, 4608, 1383, 0x48e9510f
4, 13824, 13824, 4608, 1383, 0x48e9510f
5, 13824, 13824, 4608, 1383, 0x48e9510f
6, 13824, 13824, 4608, 1383, 0x48e9510f
-7, 13824, 13824, 4608, 1383, 0x48e9510f
-8, 13824, 13824, 4608, 1383, 0x48e9510f
+7, 13824, 13824, 4608, 1380, 0x045550d3
+8, 13824, 13824, 4608, 1380, 0x045550d3
9, 13824, 13824, 4608, 1383, 0x48e9510f
0, 18432, 18432, 4608, 1572, 0x9a514719
1, 18432, 18432, 4608, 1572, 0x9a514719
-2, 18432, 18432, 4608, 1568, 0xa2bc45f4
-3, 18432, 18432, 4608, 1568, 0xa2bc45f4
+2, 18432, 18432, 4608, 1572, 0x9a514719
+3, 18432, 18432, 4608, 1572, 0x9a514719
4, 18432, 18432, 4608, 1572, 0x9a514719
5, 18432, 18432, 4608, 1572, 0x9a514719
6, 18432, 18432, 4608, 1572, 0x9a514719
-7, 18432, 18432, 4608, 1572, 0x9a514719
-8, 18432, 18432, 4608, 1572, 0x9a514719
+7, 18432, 18432, 4608, 1568, 0xa2bc45f4
+8, 18432, 18432, 4608, 1568, 0xa2bc45f4
9, 18432, 18432, 4608, 1572, 0x9a514719
0, 23040, 23040, 4608, 1391, 0x74ac5014
1, 23040, 23040, 4608, 1391, 0x74ac5014
-2, 23040, 23040, 4608, 1388, 0x96c85007
-3, 23040, 23040, 4608, 1388, 0x96c85007
+2, 23040, 23040, 4608, 1391, 0x74ac5014
+3, 23040, 23040, 4608, 1391, 0x74ac5014
4, 23040, 23040, 4608, 1391, 0x74ac5014
5, 23040, 23040, 4608, 1391, 0x74ac5014
6, 23040, 23040, 4608, 1391, 0x74ac5014
-7, 23040, 23040, 4608, 1391, 0x74ac5014
-8, 23040, 23040, 4608, 1391, 0x74ac5014
+7, 23040, 23040, 4608, 1388, 0x96c85007
+8, 23040, 23040, 4608, 1388, 0x96c85007
9, 23040, 23040, 4608, 1391, 0x74ac5014
0, 27648, 27648, 4608, 1422, 0x2f9d47c5
1, 27648, 27648, 4608, 1422, 0x2f9d47c5
-2, 27648, 27648, 4608, 1419, 0x4d4d466a
-3, 27648, 27648, 4608, 1419, 0x4d4d466a
+2, 27648, 27648, 4608, 1422, 0x2f9d47c5
+3, 27648, 27648, 4608, 1422, 0x2f9d47c5
4, 27648, 27648, 4608, 1422, 0x2f9d47c5
5, 27648, 27648, 4608, 1422, 0x2f9d47c5
6, 27648, 27648, 4608, 1422, 0x2f9d47c5
-7, 27648, 27648, 4608, 1422, 0x2f9d47c5
-8, 27648, 27648, 4608, 1422, 0x2f9d47c5
+7, 27648, 27648, 4608, 1419, 0x4d4d466a
+8, 27648, 27648, 4608, 1419, 0x4d4d466a
9, 27648, 27648, 4608, 1422, 0x2f9d47c5
0, 32256, 32256, 4608, 1768, 0x2a044b99
1, 32256, 32256, 4608, 1768, 0x2a044b99
-2, 32256, 32256, 4608, 1765, 0xacb84b24
-3, 32256, 32256, 4608, 1765, 0xacb84b24
+2, 32256, 32256, 4608, 1768, 0x2a044b99
+3, 32256, 32256, 4608, 1768, 0x2a044b99
4, 32256, 32256, 4608, 1768, 0x2a044b99
5, 32256, 32256, 4608, 1768, 0x2a044b99
6, 32256, 32256, 4608, 1768, 0x2a044b99
-7, 32256, 32256, 4608, 1768, 0x2a044b99
-8, 32256, 32256, 4608, 1768, 0x2a044b99
+7, 32256, 32256, 4608, 1765, 0xacb84b24
+8, 32256, 32256, 4608, 1765, 0xacb84b24
9, 32256, 32256, 4608, 1768, 0x2a044b99
0, 36864, 36864, 4608, 1534, 0xb0b35a3f
1, 36864, 36864, 4608, 1534, 0xb0b35a3f
-2, 36864, 36864, 4608, 1531, 0x996458aa
-3, 36864, 36864, 4608, 1531, 0x996458aa
+2, 36864, 36864, 4608, 1534, 0xb0b35a3f
+3, 36864, 36864, 4608, 1534, 0xb0b35a3f
4, 36864, 36864, 4608, 1534, 0xb0b35a3f
5, 36864, 36864, 4608, 1534, 0xb0b35a3f
6, 36864, 36864, 4608, 1534, 0xb0b35a3f
-7, 36864, 36864, 4608, 1534, 0xb0b35a3f
-8, 36864, 36864, 4608, 1534, 0xb0b35a3f
+7, 36864, 36864, 4608, 1531, 0x996458aa
+8, 36864, 36864, 4608, 1531, 0x996458aa
9, 36864, 36864, 4608, 1534, 0xb0b35a3f
0, 41472, 41472, 4608, 926, 0xc26a5eae
1, 41472, 41472, 4608, 926, 0xc26a5eae
-2, 41472, 41472, 4608, 923, 0xa7225edf
-3, 41472, 41472, 4608, 923, 0xa7225edf
+2, 41472, 41472, 4608, 926, 0xc26a5eae
+3, 41472, 41472, 4608, 926, 0xc26a5eae
4, 41472, 41472, 4608, 926, 0xc26a5eae
5, 41472, 41472, 4608, 926, 0xc26a5eae
6, 41472, 41472, 4608, 926, 0xc26a5eae
-7, 41472, 41472, 4608, 926, 0xc26a5eae
-8, 41472, 41472, 4608, 926, 0xc26a5eae
+7, 41472, 41472, 4608, 923, 0xa7225edf
+8, 41472, 41472, 4608, 923, 0xa7225edf
9, 41472, 41472, 4608, 926, 0xc26a5eae
[STREAM_GROUP]
index=0
--
2.50.0
_______________________________________________
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 4/9] tests/iamf: rename BACK to SIDE filterchain labels in the 5.1.4 iamf tests
2025-06-18 1:38 [FFmpeg-devel] [PATCH 1/9] avformat/iamf_writer: ensure each layer's channel layout contains all channels from the previous one James Almer
2025-06-18 1:38 ` [FFmpeg-devel] [PATCH 2/9] avformat/iamf_parse: try to retype the channel layout for ambisonics_mode == 0 James Almer
2025-06-18 1:38 ` [FFmpeg-devel] [PATCH 3/9] tests/iamf: reorder muxed streams James Almer
@ 2025-06-18 1:38 ` James Almer
2025-06-18 1:39 ` [FFmpeg-devel] [PATCH 5/9] avformat/iamf: fix setting channel layout for Scalable layers James Almer
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: James Almer @ 2025-06-18 1:38 UTC (permalink / raw)
To: ffmpeg-devel
Cosmetic change to reflect the actual channels used in the layouts.
Signed-off-by: James Almer <jamrial@gmail.com>
---
tests/fate/iamf.mak | 2 +-
tests/fate/mov.mak | 2 +-
tests/filtergraphs/iamf_5_1_4 | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/fate/iamf.mak b/tests/fate/iamf.mak
index ff745bc59a..eddea66ba1 100644
--- a/tests/fate/iamf.mak
+++ b/tests/fate/iamf.mak
@@ -14,7 +14,7 @@ fate-iamf-5_1_4: CMD = transcode wav $(SRC) iamf "-auto_conversion_filters \
-/filter_complex $(TARGET_PATH)/tests/data/filtergraphs/iamf_5_1_4 \
-/stream_group $(TARGET_PATH)/tests/data/streamgroups/audio_element-5_1_4 \
-/stream_group $(TARGET_PATH)/tests/data/streamgroups/mix_presentation-5_1_4 \
- -streamid 0:0 -streamid 1:1 -streamid 2:2 -streamid 3:3 -streamid 4:4 -streamid 5:5 -map [FRONT] -map [BACK] -map [CENTER] -map [LFE] -map [TOP_FRONT] -map [TOP_BACK] -c:a flac -t 1" "-c:a copy -map 0" \
+ -streamid 0:0 -streamid 1:1 -streamid 2:2 -streamid 3:3 -streamid 4:4 -streamid 5:5 -map [FRONT] -map [SIDE] -map [CENTER] -map [LFE] -map [TOP_FRONT] -map [TOP_BACK] -c:a flac -t 1" "-c:a copy -map 0" \
"-show_entries stream_group=index,id,nb_streams,type:stream_group_components:stream_group_stream=index,id:stream_group_stream_disposition"
FATE_IAMF-$(call TRANSCODE, FLAC, IAMF, WAV_DEMUXER PCM_S16LE_DECODER ARESAMPLE_FILTER) += fate-iamf-7_1_4
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 4f6231abbc..95440347f6 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -253,7 +253,7 @@ fate-mov-mp4-iamf-5_1_4: CMD = transcode wav $(SRC) mp4 "-auto_conversion_filter
-/filter_complex $(TARGET_PATH)/tests/data/filtergraphs/iamf_5_1_4 \
-/stream_group $(TARGET_PATH)/tests/data/streamgroups/audio_element-5_1_4 \
-/stream_group $(TARGET_PATH)/tests/data/streamgroups/mix_presentation-5_1_4 \
- -streamid 0:0 -streamid 1:1 -streamid 2:2 -streamid 3:3 -streamid 4:4 -streamid 5:5 -map [FRONT] -map [BACK] -map [CENTER] -map [LFE] -map [TOP_FRONT] -map [TOP_BACK] -c:a flac -t 1" "-c:a copy -map 0" \
+ -streamid 0:0 -streamid 1:1 -streamid 2:2 -streamid 3:3 -streamid 4:4 -streamid 5:5 -map [FRONT] -map [SIDE] -map [CENTER] -map [LFE] -map [TOP_FRONT] -map [TOP_BACK] -c:a flac -t 1" "-c:a copy -map 0" \
"-show_entries stream_group=index,id,nb_streams,type:stream_group_components:stream_group_disposition:stream_group_tags:stream_group_stream=index,id:stream_group_stream_disposition"
# Test muxing an IAMF track alongside a video one, with video as the first track.
diff --git a/tests/filtergraphs/iamf_5_1_4 b/tests/filtergraphs/iamf_5_1_4
index 80dcc1f580..b600f1cc91 100644
--- a/tests/filtergraphs/iamf_5_1_4
+++ b/tests/filtergraphs/iamf_5_1_4
@@ -1,5 +1,5 @@
[0:a]channelmap=0|1:stereo[FRONT];
-[0:a]channelmap=4|5:stereo[BACK];
+[0:a]channelmap=4|5:stereo[SIDE];
[0:a]channelmap=2:mono[CENTER];
[0:a]channelmap=3:mono[LFE];
[0:a]channelmap=6|7:stereo[TOP_FRONT];
--
2.50.0
_______________________________________________
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 5/9] avformat/iamf: fix setting channel layout for Scalable layers
2025-06-18 1:38 [FFmpeg-devel] [PATCH 1/9] avformat/iamf_writer: ensure each layer's channel layout contains all channels from the previous one James Almer
` (2 preceding siblings ...)
2025-06-18 1:38 ` [FFmpeg-devel] [PATCH 4/9] tests/iamf: rename BACK to SIDE filterchain labels in the 5.1.4 iamf tests James Almer
@ 2025-06-18 1:39 ` James Almer
2025-06-18 1:39 ` [FFmpeg-devel] [PATCH 6/9] avformat/iamf_writer: factorize out getting loudspeaker_layout values James Almer
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: James Almer @ 2025-06-18 1:39 UTC (permalink / raw)
To: ffmpeg-devel
The way streams are coded in an IAMF struct follows a scalable model where the
channel layouts for each layer may not match the channel order our API can
represent in a Native order layout.
For example, an audio element may have six coded streams in the form of two
stereo streams, followed by two mono streams, and then by another two stereo
streams, for a total of 10 channels, and define for them four scalable layers
with loudspeaker_layout values "Stereo", "5.1ch", "5.1.2ch", and "5.1.4ch".
The first layer references the first stream, and each following layer will
reference all previous streams plus extra ones.
In this case, the "5.1ch" layer will reference four streams (the first two
stereo and the two mono) to encompass six channels, which does not match out
native layout 5.1(side) given that FC and LFE come after FL+FR but before
SL+SR, and here, they are at the end.
For this reason, we need to build Custom order layouts that properly represent
what we're exporting.
----
Before:
Stream group #0:0[0x12c]: IAMF Audio Element:
Layer 0: stereo
Stream #0:0[0x0]: Audio: opus, 48000 Hz, stereo, fltp (default)
Layer 1: 5.1(side)
Stream #0:0[0x0]: Audio: opus, 48000 Hz, stereo, fltp (default)
Stream #0:1[0x1]: Audio: opus, 48000 Hz, stereo, fltp (dependent)
Stream #0:2[0x2]: Audio: opus, 48000 Hz, mono, fltp (dependent)
Stream #0:3[0x3]: Audio: opus, 48000 Hz, mono, fltp (dependent)
Layer 2: 5.1.2
Stream #0:0[0x0]: Audio: opus, 48000 Hz, stereo, fltp (default)
Stream #0:1[0x1]: Audio: opus, 48000 Hz, stereo, fltp (dependent)
Stream #0:2[0x2]: Audio: opus, 48000 Hz, mono, fltp (dependent)
Stream #0:3[0x3]: Audio: opus, 48000 Hz, mono, fltp (dependent)
Stream #0:4[0x4]: Audio: opus, 48000 Hz, stereo, fltp (dependent)
Layer 3: 5.1.4
Stream #0:0[0x0]: Audio: opus, 48000 Hz, stereo, fltp (default)
Stream #0:1[0x1]: Audio: opus, 48000 Hz, stereo, fltp (dependent)
Stream #0:2[0x2]: Audio: opus, 48000 Hz, mono, fltp (dependent)
Stream #0:3[0x3]: Audio: opus, 48000 Hz, mono, fltp (dependent)
Stream #0:4[0x4]: Audio: opus, 48000 Hz, stereo, fltp (dependent)
Stream #0:5[0x5]: Audio: opus, 48000 Hz, stereo, fltp (dependent)
----
AFter:
Stream group #0:0[0x12c]: IAMF Audio Element:
Layer 0: stereo
Stream #0:0[0x0]: Audio: opus, 48000 Hz, stereo, fltp (default)
Layer 1: 6 channels (FL+FR+SL+SR+FC+LFE)
Stream #0:0[0x0]: Audio: opus, 48000 Hz, stereo, fltp (default)
Stream #0:1[0x1]: Audio: opus, 48000 Hz, stereo, fltp (dependent)
Stream #0:2[0x2]: Audio: opus, 48000 Hz, mono, fltp (dependent)
Stream #0:3[0x3]: Audio: opus, 48000 Hz, mono, fltp (dependent)
Layer 2: 8 channels (FL+FR+SL+SR+FC+LFE+TFL+TFR)
Stream #0:0[0x0]: Audio: opus, 48000 Hz, stereo, fltp (default)
Stream #0:1[0x1]: Audio: opus, 48000 Hz, stereo, fltp (dependent)
Stream #0:2[0x2]: Audio: opus, 48000 Hz, mono, fltp (dependent)
Stream #0:3[0x3]: Audio: opus, 48000 Hz, mono, fltp (dependent)
Stream #0:4[0x4]: Audio: opus, 48000 Hz, stereo, fltp (dependent)
Layer 3: 10 channels (FL+FR+SL+SR+FC+LFE+TFL+TFR+TBL+TBR)
Stream #0:0[0x0]: Audio: opus, 48000 Hz, stereo, fltp (default)
Stream #0:1[0x1]: Audio: opus, 48000 Hz, stereo, fltp (dependent)
Stream #0:2[0x2]: Audio: opus, 48000 Hz, mono, fltp (dependent)
Stream #0:3[0x3]: Audio: opus, 48000 Hz, mono, fltp (dependent)
Stream #0:4[0x4]: Audio: opus, 48000 Hz, stereo, fltp (dependent)
Stream #0:5[0x5]: Audio: opus, 48000 Hz, stereo, fltp (dependent)
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/iamf_parse.c | 77 +++++++++++++++++--
libavformat/iamf_writer.c | 28 +++++--
libavformat/iamfdec.c | 19 -----
tests/ref/fate/iamf-5_1-copy | 2 +-
tests/ref/fate/iamf-5_1-demux | 2 +-
tests/ref/fate/iamf-5_1_4 | 6 +-
tests/ref/fate/iamf-7_1_4 | 54 ++++++-------
tests/ref/fate/iamf-9_1_6 | 2 +-
tests/ref/fate/mov-mp4-iamf-5_1_4 | 6 +-
tests/ref/fate/mov-mp4-iamf-7_1_4-video-first | 6 +-
tests/ref/fate/mov-mp4-iamf-7_1_4-video-last | 6 +-
11 files changed, 135 insertions(+), 73 deletions(-)
diff --git a/libavformat/iamf_parse.c b/libavformat/iamf_parse.c
index f37edf5156..7c239ae946 100644
--- a/libavformat/iamf_parse.c
+++ b/libavformat/iamf_parse.c
@@ -357,7 +357,8 @@ static int scalable_channel_layout_config(void *s, AVIOContext *pb,
return AVERROR(ENOMEM);
audio_element->nb_layers = nb_layers;
- for (int i = 0; i < nb_layers; i++) {
+ for (int i = 0, n = 0; i < nb_layers; i++) {
+ AVChannelLayout ch_layout = { 0 };
AVIAMFLayer *layer;
int loudspeaker_layout, output_gain_is_present_flag;
int substream_count, coupled_substream_count;
@@ -387,12 +388,16 @@ static int scalable_channel_layout_config(void *s, AVIOContext *pb,
if (!i && loudspeaker_layout == 15)
expanded_loudspeaker_layout = avio_r8(pb);
- if (expanded_loudspeaker_layout > 0 && expanded_loudspeaker_layout < 13)
- av_channel_layout_copy(&layer->ch_layout, &ff_iamf_expanded_scalable_ch_layouts[expanded_loudspeaker_layout]);
- else if (loudspeaker_layout < 10)
- av_channel_layout_copy(&layer->ch_layout, &ff_iamf_scalable_ch_layouts[loudspeaker_layout]);
- else
- layer->ch_layout = (AVChannelLayout){ .order = AV_CHANNEL_ORDER_UNSPEC,
+ if (expanded_loudspeaker_layout > 0 && expanded_loudspeaker_layout < 13) {
+ av_channel_layout_copy(&ch_layout, &ff_iamf_expanded_scalable_ch_layouts[expanded_loudspeaker_layout]);
+ if (i)
+ ch_layout.u.mask &= ~av_channel_layout_subset(&audio_element->element->layers[i-1]->ch_layout, UINT64_MAX);
+ } else if (loudspeaker_layout < 10) {
+ av_channel_layout_copy(&ch_layout, &ff_iamf_scalable_ch_layouts[loudspeaker_layout]);
+ if (i)
+ ch_layout.u.mask &= ~av_channel_layout_subset(&audio_element->element->layers[i-1]->ch_layout, UINT64_MAX);
+ } else
+ ch_layout = (AVChannelLayout){ .order = AV_CHANNEL_ORDER_UNSPEC,
.nb_channels = substream_count +
coupled_substream_count };
@@ -407,6 +412,64 @@ static int scalable_channel_layout_config(void *s, AVIOContext *pb,
return ret;
}
+ if (ch_layout.order == AV_CHANNEL_ORDER_NATIVE) {
+ ret = av_channel_layout_custom_init(&layer->ch_layout, ch_layout.nb_channels);
+ if (ret < 0)
+ return ret;
+
+ for (int j = 0; j < n; j++)
+ layer->ch_layout.u.map[j].id = av_channel_layout_channel_from_index(&audio_element->element->layers[i-1]->ch_layout, j);
+
+ coupled_substream_count = audio_element->layers[i].coupled_substream_count;
+ while (coupled_substream_count--) {
+ if (ch_layout.u.mask & AV_CH_LAYOUT_STEREO) {
+ layer->ch_layout.u.map[n++].id = AV_CHAN_FRONT_LEFT;
+ layer->ch_layout.u.map[n++].id = AV_CHAN_FRONT_RIGHT;
+ ch_layout.u.mask &= ~AV_CH_LAYOUT_STEREO;
+ } else if (ch_layout.u.mask & (AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)) {
+ layer->ch_layout.u.map[n++].id = AV_CHAN_FRONT_LEFT_OF_CENTER;
+ layer->ch_layout.u.map[n++].id = AV_CHAN_FRONT_RIGHT_OF_CENTER;
+ ch_layout.u.mask &= ~(AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER);
+ } else if (ch_layout.u.mask & (AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT)) {
+ layer->ch_layout.u.map[n++].id = AV_CHAN_SIDE_LEFT;
+ layer->ch_layout.u.map[n++].id = AV_CHAN_SIDE_RIGHT;
+ ch_layout.u.mask &= ~(AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT);
+ } else if (ch_layout.u.mask & (AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)) {
+ layer->ch_layout.u.map[n++].id = AV_CHAN_BACK_LEFT;
+ layer->ch_layout.u.map[n++].id = AV_CHAN_BACK_RIGHT;
+ ch_layout.u.mask &= ~(AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT);
+ } else if (ch_layout.u.mask & (AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT)) {
+ layer->ch_layout.u.map[n++].id = AV_CHAN_TOP_FRONT_LEFT;
+ layer->ch_layout.u.map[n++].id = AV_CHAN_TOP_FRONT_RIGHT;
+ ch_layout.u.mask &= ~(AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT);
+ } else if (ch_layout.u.mask & (AV_CH_TOP_SIDE_LEFT|AV_CH_TOP_SIDE_RIGHT)) {
+ layer->ch_layout.u.map[n++].id = AV_CHAN_TOP_SIDE_LEFT;
+ layer->ch_layout.u.map[n++].id = AV_CHAN_TOP_SIDE_RIGHT;
+ ch_layout.u.mask &= ~(AV_CH_TOP_SIDE_LEFT|AV_CH_TOP_SIDE_RIGHT);
+ } else if (ch_layout.u.mask & (AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_RIGHT)) {
+ layer->ch_layout.u.map[n++].id = AV_CHAN_TOP_BACK_LEFT;
+ layer->ch_layout.u.map[n++].id = AV_CHAN_TOP_BACK_RIGHT;
+ ch_layout.u.mask &= ~(AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_RIGHT);
+ }
+ }
+
+ substream_count -= audio_element->layers[i].coupled_substream_count;
+ while (substream_count--) {
+ if (ch_layout.u.mask & AV_CH_FRONT_CENTER) {
+ layer->ch_layout.u.map[n++].id = AV_CHAN_FRONT_CENTER;
+ ch_layout.u.mask &= ~AV_CH_FRONT_CENTER;
+ }
+ if (ch_layout.u.mask & AV_CH_LOW_FREQUENCY) {
+ layer->ch_layout.u.map[n++].id = AV_CHAN_LOW_FREQUENCY;
+ ch_layout.u.mask &= ~AV_CH_LOW_FREQUENCY;
+ }
+ }
+
+ ret = av_channel_layout_retype(&layer->ch_layout, AV_CHANNEL_ORDER_NATIVE, 0);
+ if (ret < 0 && ret != AVERROR(ENOSYS))
+ return ret;
+ } else // AV_CHANNEL_ORDER_UNSPEC
+ av_channel_layout_copy(&layer->ch_layout, &ch_layout);
}
return 0;
diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c
index e34afb9a2c..86d09c3308 100644
--- a/libavformat/iamf_writer.c
+++ b/libavformat/iamf_writer.c
@@ -250,14 +250,18 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void
for (int j, i = 0; i < iamf_audio_element->nb_layers; i++) {
const AVIAMFLayer *layer = iamf_audio_element->layers[i];
+
for (j = 0; j < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts); j++)
- if (!av_channel_layout_compare(&layer->ch_layout, &ff_iamf_scalable_ch_layouts[j]))
+ if (av_channel_layout_subset(&layer->ch_layout, UINT64_MAX) ==
+ av_channel_layout_subset(&ff_iamf_scalable_ch_layouts[j], UINT64_MAX))
break;
if (j >= FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts)) {
for (j = 0; j < FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts); j++)
- if (!av_channel_layout_compare(&layer->ch_layout, &ff_iamf_expanded_scalable_ch_layouts[j]))
+ if (av_channel_layout_subset(&layer->ch_layout, UINT64_MAX) ==
+ av_channel_layout_subset(&ff_iamf_expanded_scalable_ch_layouts[j], UINT64_MAX))
break;
+
if (j >= FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts)) {
av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
av_channel_layout_describe_bprint(&layer->ch_layout, &bp);
@@ -592,12 +596,26 @@ static int scalable_channel_layout_config(const IAMFAudioElement *audio_element,
if (!av_channel_layout_compare(&layer->ch_layout, &ff_iamf_scalable_ch_layouts[layout]))
break;
}
- if (layout >= FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts))
- for (expanded_layout = 0; expanded_layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts); expanded_layout++) {
+ if (layout >= FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts)) {
+ for (layout = 0; layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts); layout++)
+ if (av_channel_layout_subset(&layer->ch_layout, UINT64_MAX) ==
+ av_channel_layout_subset(&ff_iamf_scalable_ch_layouts[layout], UINT64_MAX))
+ break;
+ }
+ if (layout >= FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts)) {
+ for (expanded_layout = 0; expanded_layout < FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts); expanded_layout++) {
if (!av_channel_layout_compare(&layer->ch_layout, &ff_iamf_expanded_scalable_ch_layouts[expanded_layout]))
break;
}
- av_assert0(expanded_layout > 0 || layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts));
+ if (expanded_layout >= FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts)) {
+ for (expanded_layout = 0; expanded_layout < FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts); expanded_layout++)
+ if (av_channel_layout_subset(&layer->ch_layout, UINT64_MAX) ==
+ av_channel_layout_subset(&ff_iamf_expanded_scalable_ch_layouts[expanded_layout], UINT64_MAX))
+ break;
+ }
+ }
+ av_assert0((expanded_layout > 0 && expanded_layout < FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts)) ||
+ layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts));
init_put_bits(&pb, header, sizeof(header));
put_bits(&pb, 4, expanded_layout >= 0 ? 15 : layout);
put_bits(&pb, 1, !!layer->output_gain_flags);
diff --git a/libavformat/iamfdec.c b/libavformat/iamfdec.c
index 3a6276dcde..e7b5bef907 100644
--- a/libavformat/iamfdec.c
+++ b/libavformat/iamfdec.c
@@ -81,10 +81,8 @@ static int iamf_read_header(AVFormatContext *s)
for (int i = 0; i < iamf->nb_audio_elements; i++) {
IAMFAudioElement *audio_element = iamf->audio_elements[i];
- const AVIAMFLayer *layer = audio_element->element->layers[audio_element->nb_layers - 1];
AVStreamGroup *stg = avformat_stream_group_create(s, AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT, NULL);
int coupled_substream_count = audio_element->layers[audio_element->nb_layers - 1].coupled_substream_count;
- int side_substream_id = -1, back_substream_id = -1;
if (!stg)
return AVERROR(ENOMEM);
@@ -114,28 +112,11 @@ static int iamf_read_header(AVFormatContext *s)
st->disposition |= AV_DISPOSITION_DEFAULT;
else if (audio_element->nb_layers > 1 || audio_element->layers[0].substream_count > 1)
st->disposition |= AV_DISPOSITION_DEPENDENT;
- if (k == av_channel_layout_index_from_channel(&layer->ch_layout, AV_CHAN_BACK_LEFT))
- back_substream_id = j;
- else if (k == av_channel_layout_index_from_channel(&layer->ch_layout, AV_CHAN_SIDE_LEFT))
- side_substream_id = j;
st->id = substream->audio_substream_id;
avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
k += 1 + (coupled_substream_count-- > 0);
}
-
- // Swap back and side stream ids as our native channel layout ordering doen't match the
- // order from ITU-R - BS.2051-3 for Systems I and J (where side channels come before back ones).
- if (back_substream_id >= 0 && side_substream_id >= 0 && av_channel_layout_compare(&layer->ch_layout,
- &(AVChannelLayout)AV_CHANNEL_LAYOUT_9POINT1POINT6)) {
- const IAMFSubStream *back_substream = &audio_element->substreams[back_substream_id];
- const IAMFSubStream *side_substream = &audio_element->substreams[side_substream_id];
- AVStream *back_st = stg->streams[back_substream_id];
- AVStream *side_st = stg->streams[side_substream_id];
-
- back_st->id = side_substream->audio_substream_id;
- side_st->id = back_substream->audio_substream_id;
- }
}
for (int i = 0; i < iamf->nb_mix_presentations; i++) {
diff --git a/tests/ref/fate/iamf-5_1-copy b/tests/ref/fate/iamf-5_1-copy
index 5f7d9f98c0..fe912d4ee7 100644
--- a/tests/ref/fate/iamf-5_1-copy
+++ b/tests/ref/fate/iamf-5_1-copy
@@ -37,7 +37,7 @@ output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
[SUBCOMPONENT]
-channel_layout=5.1(side)
+channel_layout=6 channels (FL+FR+SL+SR+FC+LFE)
output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
diff --git a/tests/ref/fate/iamf-5_1-demux b/tests/ref/fate/iamf-5_1-demux
index 5f7d9f98c0..fe912d4ee7 100644
--- a/tests/ref/fate/iamf-5_1-demux
+++ b/tests/ref/fate/iamf-5_1-demux
@@ -37,7 +37,7 @@ output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
[SUBCOMPONENT]
-channel_layout=5.1(side)
+channel_layout=6 channels (FL+FR+SL+SR+FC+LFE)
output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
diff --git a/tests/ref/fate/iamf-5_1_4 b/tests/ref/fate/iamf-5_1_4
index 1d4c055906..4c765dc8e1 100644
--- a/tests/ref/fate/iamf-5_1_4
+++ b/tests/ref/fate/iamf-5_1_4
@@ -111,17 +111,17 @@ output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
[SUBCOMPONENT]
-channel_layout=5.1(side)
+channel_layout=6 channels (FL+FR+SL+SR+FC+LFE)
output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
[SUBCOMPONENT]
-channel_layout=5.1.2
+channel_layout=8 channels (FL+FR+SL+SR+FC+LFE+TFL+TFR)
output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
[SUBCOMPONENT]
-channel_layout=5.1.4
+channel_layout=10 channels (FL+FR+SL+SR+FC+LFE+TFL+TFR+TBL+TBR)
output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
diff --git a/tests/ref/fate/iamf-7_1_4 b/tests/ref/fate/iamf-7_1_4
index 72b10f771a..4259e40135 100644
--- a/tests/ref/fate/iamf-7_1_4
+++ b/tests/ref/fate/iamf-7_1_4
@@ -45,72 +45,72 @@
0, 0, 0, 4608, 1399, 0x6e89566e
1, 0, 0, 4608, 1399, 0x6e89566e
2, 0, 0, 4608, 1396, 0x0dcb5677
-3, 0, 0, 4608, 1399, 0x6e89566e
+3, 0, 0, 4608, 1396, 0x0dcb5677
4, 0, 0, 4608, 1399, 0x6e89566e
-5, 0, 0, 4608, 1396, 0x0dcb5677
+5, 0, 0, 4608, 1399, 0x6e89566e
6, 0, 0, 4608, 1399, 0x6e89566e
0, 4608, 4608, 4608, 1442, 0x6c3c5b13
1, 4608, 4608, 4608, 1442, 0x6c3c5b13
2, 4608, 4608, 4608, 1439, 0xc46b5ac5
-3, 4608, 4608, 4608, 1442, 0x6c3c5b13
+3, 4608, 4608, 4608, 1439, 0xc46b5ac5
4, 4608, 4608, 4608, 1442, 0x6c3c5b13
-5, 4608, 4608, 4608, 1439, 0xc46b5ac5
+5, 4608, 4608, 4608, 1442, 0x6c3c5b13
6, 4608, 4608, 4608, 1442, 0x6c3c5b13
0, 9216, 9216, 4608, 1380, 0xc497571b
1, 9216, 9216, 4608, 1380, 0xc497571b
2, 9216, 9216, 4608, 1377, 0x5b2a55fe
-3, 9216, 9216, 4608, 1380, 0xc497571b
+3, 9216, 9216, 4608, 1377, 0x5b2a55fe
4, 9216, 9216, 4608, 1380, 0xc497571b
-5, 9216, 9216, 4608, 1377, 0x5b2a55fe
+5, 9216, 9216, 4608, 1380, 0xc497571b
6, 9216, 9216, 4608, 1380, 0xc497571b
0, 13824, 13824, 4608, 1383, 0x48e9510f
1, 13824, 13824, 4608, 1383, 0x48e9510f
2, 13824, 13824, 4608, 1380, 0x045550d3
-3, 13824, 13824, 4608, 1383, 0x48e9510f
+3, 13824, 13824, 4608, 1380, 0x045550d3
4, 13824, 13824, 4608, 1383, 0x48e9510f
-5, 13824, 13824, 4608, 1380, 0x045550d3
+5, 13824, 13824, 4608, 1383, 0x48e9510f
6, 13824, 13824, 4608, 1383, 0x48e9510f
0, 18432, 18432, 4608, 1572, 0x9a514719
1, 18432, 18432, 4608, 1572, 0x9a514719
2, 18432, 18432, 4608, 1568, 0xa2bc45f4
-3, 18432, 18432, 4608, 1572, 0x9a514719
+3, 18432, 18432, 4608, 1568, 0xa2bc45f4
4, 18432, 18432, 4608, 1572, 0x9a514719
-5, 18432, 18432, 4608, 1568, 0xa2bc45f4
+5, 18432, 18432, 4608, 1572, 0x9a514719
6, 18432, 18432, 4608, 1572, 0x9a514719
0, 23040, 23040, 4608, 1391, 0x74ac5014
1, 23040, 23040, 4608, 1391, 0x74ac5014
2, 23040, 23040, 4608, 1388, 0x96c85007
-3, 23040, 23040, 4608, 1391, 0x74ac5014
+3, 23040, 23040, 4608, 1388, 0x96c85007
4, 23040, 23040, 4608, 1391, 0x74ac5014
-5, 23040, 23040, 4608, 1388, 0x96c85007
+5, 23040, 23040, 4608, 1391, 0x74ac5014
6, 23040, 23040, 4608, 1391, 0x74ac5014
0, 27648, 27648, 4608, 1422, 0x2f9d47c5
1, 27648, 27648, 4608, 1422, 0x2f9d47c5
2, 27648, 27648, 4608, 1419, 0x4d4d466a
-3, 27648, 27648, 4608, 1422, 0x2f9d47c5
+3, 27648, 27648, 4608, 1419, 0x4d4d466a
4, 27648, 27648, 4608, 1422, 0x2f9d47c5
-5, 27648, 27648, 4608, 1419, 0x4d4d466a
+5, 27648, 27648, 4608, 1422, 0x2f9d47c5
6, 27648, 27648, 4608, 1422, 0x2f9d47c5
0, 32256, 32256, 4608, 1768, 0x2a044b99
1, 32256, 32256, 4608, 1768, 0x2a044b99
2, 32256, 32256, 4608, 1765, 0xacb84b24
-3, 32256, 32256, 4608, 1768, 0x2a044b99
+3, 32256, 32256, 4608, 1765, 0xacb84b24
4, 32256, 32256, 4608, 1768, 0x2a044b99
-5, 32256, 32256, 4608, 1765, 0xacb84b24
+5, 32256, 32256, 4608, 1768, 0x2a044b99
6, 32256, 32256, 4608, 1768, 0x2a044b99
0, 36864, 36864, 4608, 1534, 0xb0b35a3f
1, 36864, 36864, 4608, 1534, 0xb0b35a3f
2, 36864, 36864, 4608, 1531, 0x996458aa
-3, 36864, 36864, 4608, 1534, 0xb0b35a3f
+3, 36864, 36864, 4608, 1531, 0x996458aa
4, 36864, 36864, 4608, 1534, 0xb0b35a3f
-5, 36864, 36864, 4608, 1531, 0x996458aa
+5, 36864, 36864, 4608, 1534, 0xb0b35a3f
6, 36864, 36864, 4608, 1534, 0xb0b35a3f
0, 41472, 41472, 4608, 926, 0xc26a5eae
1, 41472, 41472, 4608, 926, 0xc26a5eae
2, 41472, 41472, 4608, 923, 0xa7225edf
-3, 41472, 41472, 4608, 926, 0xc26a5eae
+3, 41472, 41472, 4608, 923, 0xa7225edf
4, 41472, 41472, 4608, 926, 0xc26a5eae
-5, 41472, 41472, 4608, 923, 0xa7225edf
+5, 41472, 41472, 4608, 926, 0xc26a5eae
6, 41472, 41472, 4608, 926, 0xc26a5eae
[STREAM_GROUP]
index=0
@@ -127,17 +127,17 @@ output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
[SUBCOMPONENT]
-channel_layout=3.1.2
+channel_layout=6 channels (FL+FR+TFL+TFR+FC+LFE)
output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
[SUBCOMPONENT]
-channel_layout=7.1.2
+channel_layout=10 channels (FL+FR+TFL+TFR+FC+LFE+SL+SR+BL+BR)
output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
[SUBCOMPONENT]
-channel_layout=7.1.4
+channel_layout=12 channels (FL+FR+TFL+TFR+FC+LFE+SL+SR+BL+BR+TBL+TBR)
output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
@@ -226,7 +226,7 @@ DISPOSITION:multilayer=0
[/STREAM]
[STREAM]
index=3
-id=0x5
+id=0x3
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
@@ -272,7 +272,7 @@ DISPOSITION:multilayer=0
[/STREAM]
[STREAM]
index=5
-id=0x3
+id=0x5
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
@@ -462,7 +462,7 @@ DISPOSITION:multilayer=0
[/STREAM]
[STREAM]
index=3
-id=0x5
+id=0x3
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
@@ -508,7 +508,7 @@ DISPOSITION:multilayer=0
[/STREAM]
[STREAM]
index=5
-id=0x3
+id=0x5
DISPOSITION:default=0
DISPOSITION:dub=0
DISPOSITION:original=0
diff --git a/tests/ref/fate/iamf-9_1_6 b/tests/ref/fate/iamf-9_1_6
index 0c55a22774..4082d35729 100644
--- a/tests/ref/fate/iamf-9_1_6
+++ b/tests/ref/fate/iamf-9_1_6
@@ -170,7 +170,7 @@ nb_layers=1
audio_element_type=0
default_w=0
[SUBCOMPONENT]
-channel_layout=9.1.6
+channel_layout=16 channels (FL+FR+FLC+FRC+SL+SR+BL+BR+TFL+TFR+TSL+TSR+TBL+TBR+FC+LFE)
output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
diff --git a/tests/ref/fate/mov-mp4-iamf-5_1_4 b/tests/ref/fate/mov-mp4-iamf-5_1_4
index 225bbba267..18a1f5337f 100644
--- a/tests/ref/fate/mov-mp4-iamf-5_1_4
+++ b/tests/ref/fate/mov-mp4-iamf-5_1_4
@@ -111,17 +111,17 @@ output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
[SUBCOMPONENT]
-channel_layout=5.1(side)
+channel_layout=6 channels (FL+FR+SL+SR+FC+LFE)
output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
[SUBCOMPONENT]
-channel_layout=5.1.2
+channel_layout=8 channels (FL+FR+SL+SR+FC+LFE+TFL+TFR)
output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
[SUBCOMPONENT]
-channel_layout=5.1.4
+channel_layout=10 channels (FL+FR+SL+SR+FC+LFE+TFL+TFR+TBL+TBR)
output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
diff --git a/tests/ref/fate/mov-mp4-iamf-7_1_4-video-first b/tests/ref/fate/mov-mp4-iamf-7_1_4-video-first
index d3b37896b2..d5a1fe1cad 100644
--- a/tests/ref/fate/mov-mp4-iamf-7_1_4-video-first
+++ b/tests/ref/fate/mov-mp4-iamf-7_1_4-video-first
@@ -158,17 +158,17 @@ output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
[SUBCOMPONENT]
-channel_layout=3.1.2
+channel_layout=6 channels (FL+FR+TFL+TFR+FC+LFE)
output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
[SUBCOMPONENT]
-channel_layout=7.1.2
+channel_layout=10 channels (FL+FR+TFL+TFR+FC+LFE+SL+SR+BL+BR)
output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
[SUBCOMPONENT]
-channel_layout=7.1.4
+channel_layout=12 channels (FL+FR+TFL+TFR+FC+LFE+SL+SR+BL+BR+TBL+TBR)
output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
diff --git a/tests/ref/fate/mov-mp4-iamf-7_1_4-video-last b/tests/ref/fate/mov-mp4-iamf-7_1_4-video-last
index ede4a40025..caf89d41f6 100644
--- a/tests/ref/fate/mov-mp4-iamf-7_1_4-video-last
+++ b/tests/ref/fate/mov-mp4-iamf-7_1_4-video-last
@@ -158,17 +158,17 @@ output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
[SUBCOMPONENT]
-channel_layout=3.1.2
+channel_layout=6 channels (FL+FR+TFL+TFR+FC+LFE)
output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
[SUBCOMPONENT]
-channel_layout=7.1.2
+channel_layout=10 channels (FL+FR+TFL+TFR+FC+LFE+SL+SR+BL+BR)
output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
[SUBCOMPONENT]
-channel_layout=7.1.4
+channel_layout=12 channels (FL+FR+TFL+TFR+FC+LFE+SL+SR+BL+BR+TBL+TBR)
output_gain_flags=0
output_gain=0/1
[/SUBCOMPONENT]
--
2.50.0
_______________________________________________
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 6/9] avformat/iamf_writer: factorize out getting loudspeaker_layout values
2025-06-18 1:38 [FFmpeg-devel] [PATCH 1/9] avformat/iamf_writer: ensure each layer's channel layout contains all channels from the previous one James Almer
` (3 preceding siblings ...)
2025-06-18 1:39 ` [FFmpeg-devel] [PATCH 5/9] avformat/iamf: fix setting channel layout for Scalable layers James Almer
@ 2025-06-18 1:39 ` James Almer
2025-06-18 1:39 ` [FFmpeg-devel] [PATCH 7/9] avformat/iamf_writer: add extra constrains for Parameter Sets in Audio Elements James Almer
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: James Almer @ 2025-06-18 1:39 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/iamf_writer.c | 65 +++++++++++++++++++++++----------------
1 file changed, 39 insertions(+), 26 deletions(-)
diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c
index 86d09c3308..635d1989ef 100644
--- a/libavformat/iamf_writer.c
+++ b/libavformat/iamf_writer.c
@@ -577,6 +577,41 @@ static inline int rescale_rational(AVRational q, int b)
return av_clip_int16(av_rescale(q.num, b, q.den));
}
+static void get_loudspeaker_layout(const AVIAMFLayer *layer,
+ int *playout, int *pexpanded_layout)
+{
+ int layout, expanded_layout = -1;
+
+ for (layout = 0; layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts); layout++) {
+ if (!av_channel_layout_compare(&layer->ch_layout, &ff_iamf_scalable_ch_layouts[layout]))
+ break;
+ }
+ if (layout >= FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts)) {
+ for (layout = 0; layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts); layout++)
+ if (av_channel_layout_subset(&layer->ch_layout, UINT64_MAX) ==
+ av_channel_layout_subset(&ff_iamf_scalable_ch_layouts[layout], UINT64_MAX))
+ break;
+ }
+ if (layout >= FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts)) {
+ layout = 15;
+ for (expanded_layout = 0; expanded_layout < FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts); expanded_layout++) {
+ if (!av_channel_layout_compare(&layer->ch_layout, &ff_iamf_expanded_scalable_ch_layouts[expanded_layout]))
+ break;
+ }
+ if (expanded_layout >= FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts)) {
+ for (expanded_layout = 0; expanded_layout < FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts); expanded_layout++)
+ if (av_channel_layout_subset(&layer->ch_layout, UINT64_MAX) ==
+ av_channel_layout_subset(&ff_iamf_expanded_scalable_ch_layouts[expanded_layout], UINT64_MAX))
+ break;
+ }
+ }
+ av_assert0((expanded_layout > 0 && expanded_layout < FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts)) ||
+ layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts));
+
+ *playout = layout;
+ *pexpanded_layout = expanded_layout;
+}
+
static int scalable_channel_layout_config(const IAMFAudioElement *audio_element,
AVIOContext *dyn_bc)
{
@@ -591,33 +626,11 @@ static int scalable_channel_layout_config(const IAMFAudioElement *audio_element,
avio_write(dyn_bc, header, put_bytes_count(&pb, 1));
for (int i = 0; i < element->nb_layers; i++) {
const AVIAMFLayer *layer = element->layers[i];
- int layout, expanded_layout = -1;
- for (layout = 0; layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts); layout++) {
- if (!av_channel_layout_compare(&layer->ch_layout, &ff_iamf_scalable_ch_layouts[layout]))
- break;
- }
- if (layout >= FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts)) {
- for (layout = 0; layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts); layout++)
- if (av_channel_layout_subset(&layer->ch_layout, UINT64_MAX) ==
- av_channel_layout_subset(&ff_iamf_scalable_ch_layouts[layout], UINT64_MAX))
- break;
- }
- if (layout >= FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts)) {
- for (expanded_layout = 0; expanded_layout < FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts); expanded_layout++) {
- if (!av_channel_layout_compare(&layer->ch_layout, &ff_iamf_expanded_scalable_ch_layouts[expanded_layout]))
- break;
- }
- if (expanded_layout >= FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts)) {
- for (expanded_layout = 0; expanded_layout < FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts); expanded_layout++)
- if (av_channel_layout_subset(&layer->ch_layout, UINT64_MAX) ==
- av_channel_layout_subset(&ff_iamf_expanded_scalable_ch_layouts[expanded_layout], UINT64_MAX))
- break;
- }
- }
- av_assert0((expanded_layout > 0 && expanded_layout < FF_ARRAY_ELEMS(ff_iamf_expanded_scalable_ch_layouts)) ||
- layout < FF_ARRAY_ELEMS(ff_iamf_scalable_ch_layouts));
+ int layout, expanded_layout;
+
+ get_loudspeaker_layout(layer, &layout, &expanded_layout);
init_put_bits(&pb, header, sizeof(header));
- put_bits(&pb, 4, expanded_layout >= 0 ? 15 : layout);
+ put_bits(&pb, 4, layout);
put_bits(&pb, 1, !!layer->output_gain_flags);
put_bits(&pb, 1, !!(layer->flags & AV_IAMF_LAYER_FLAG_RECON_GAIN));
put_bits(&pb, 2, 0); // reserved
--
2.50.0
_______________________________________________
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 7/9] avformat/iamf_writer: add extra constrains for Parameter Sets in Audio Elements
2025-06-18 1:38 [FFmpeg-devel] [PATCH 1/9] avformat/iamf_writer: ensure each layer's channel layout contains all channels from the previous one James Almer
` (4 preceding siblings ...)
2025-06-18 1:39 ` [FFmpeg-devel] [PATCH 6/9] avformat/iamf_writer: factorize out getting loudspeaker_layout values James Almer
@ 2025-06-18 1:39 ` James Almer
2025-06-18 1:39 ` [FFmpeg-devel] [PATCH 8/9] avformat/iamf_writer: reindent after previous commit James Almer
2025-06-18 1:39 ` [FFmpeg-devel] [PATCH 9/9] avformat/iamf_writer: use named constants in more places James Almer
7 siblings, 0 replies; 9+ messages in thread
From: James Almer @ 2025-06-18 1:39 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/iamf_writer.c | 40 ++++++++++++++++++++++++++++++++-------
1 file changed, 33 insertions(+), 7 deletions(-)
diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c
index 635d1989ef..37e75dc01a 100644
--- a/libavformat/iamf_writer.c
+++ b/libavformat/iamf_writer.c
@@ -248,6 +248,11 @@ int ff_iamf_add_audio_element(IAMFContext *iamf, const AVStreamGroup *stg, void
} else {
AVBPrint bp;
+ if (iamf_audio_element->nb_layers < 1) {
+ av_log(log_ctx, AV_LOG_ERROR, "Invalid amount of layers for CHANNEL_BASED audio element. Must be >= 1\n");
+ return AVERROR(EINVAL);
+ }
+
for (int j, i = 0; i < iamf_audio_element->nb_layers; i++) {
const AVIAMFLayer *layer = iamf_audio_element->layers[i];
@@ -741,13 +746,40 @@ static int iamf_write_audio_element(const IAMFContext *iamf,
for (int i = 0; i < audio_element->nb_substreams; i++)
ffio_write_leb(dyn_bc, audio_element->substreams[i].audio_substream_id);
- if (element->nb_layers == 1)
+ /* When audio_element_type = 1, num_parameters SHALL be set to 0 */
+ if (element->audio_element_type == AV_IAMF_AUDIO_ELEMENT_TYPE_SCENE)
+ param_definition_types = 0;
+ else {
+ int layout = 0, expanded_layout = 0;
+ get_loudspeaker_layout(element->layers[0], &layout, &expanded_layout);
+ /* When the loudspeaker_layout = 15, the type PARAMETER_DEFINITION_DEMIXING SHALL NOT be present. */
+ if (layout == 15)
+ param_definition_types &= ~AV_IAMF_PARAMETER_DEFINITION_DEMIXING;
+ /* When the loudspeaker_layout of the (non-)scalable channel audio (i.e., num_layers = 1) is less than or equal to 3.1.2ch,
+ * (i.e., Mono, Stereo, or 3.1.2ch), the type PARAMETER_DEFINITION_DEMIXING SHALL NOT be present. */
+ else if (element->nb_layers == 1 && (layout == 0 || layout == 1 || layout == 8))
param_definition_types &= ~AV_IAMF_PARAMETER_DEFINITION_DEMIXING;
+ /* When num_layers > 1, the type PARAMETER_DEFINITION_RECON_GAIN SHALL be present */
if (element->nb_layers > 1)
param_definition_types |= AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN;
+ /* When codec_id = fLaC or ipcm, the type PARAMETER_DEFINITION_RECON_GAIN SHALL NOT be present. */
if (codec_config->codec_tag == MKTAG('f','L','a','C') ||
codec_config->codec_tag == MKTAG('i','p','c','m'))
param_definition_types &= ~AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN;
+ if ((param_definition_types & AV_IAMF_PARAMETER_DEFINITION_DEMIXING) && !element->demixing_info) {
+ if (element->nb_layers > 1) {
+ get_loudspeaker_layout(element->layers[element->nb_layers-1], &layout, &expanded_layout);
+ /* When the highest loudspeaker_layout of the scalable channel audio (i.e., num_layers > 1) is greater than 3.1.2ch,
+ * (i.e., 5.1.2ch, 5.1.4ch, 7.1.2ch, or 7.1.4ch), type PARAMETER_DEFINITION_DEMIXING SHALL be present. */
+ if (layout == 3 && layout == 4 && layout == 6 && layout == 7) {
+ av_log(log_ctx, AV_LOG_ERROR, "demixing_info needed but not set in Stream Group #%u\n",
+ audio_element->audio_element_id);
+ return AVERROR(EINVAL);
+ }
+ }
+ param_definition_types &= ~AV_IAMF_PARAMETER_DEFINITION_DEMIXING;
+ }
+ }
ffio_write_leb(dyn_bc, av_popcount(param_definition_types)); // num_parameters
@@ -756,12 +788,6 @@ static int iamf_write_audio_element(const IAMFContext *iamf,
const IAMFParamDefinition *param_def;
const AVIAMFDemixingInfo *demix;
- if (!param) {
- av_log(log_ctx, AV_LOG_ERROR, "demixing_info needed but not set in Stream Group #%u\n",
- audio_element->audio_element_id);
- return AVERROR(EINVAL);
- }
-
demix = av_iamf_param_definition_get_subblock(param, 0);
ffio_write_leb(dyn_bc, AV_IAMF_PARAMETER_DEFINITION_DEMIXING); // type
--
2.50.0
_______________________________________________
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 8/9] avformat/iamf_writer: reindent after previous commit
2025-06-18 1:38 [FFmpeg-devel] [PATCH 1/9] avformat/iamf_writer: ensure each layer's channel layout contains all channels from the previous one James Almer
` (5 preceding siblings ...)
2025-06-18 1:39 ` [FFmpeg-devel] [PATCH 7/9] avformat/iamf_writer: add extra constrains for Parameter Sets in Audio Elements James Almer
@ 2025-06-18 1:39 ` James Almer
2025-06-18 1:39 ` [FFmpeg-devel] [PATCH 9/9] avformat/iamf_writer: use named constants in more places James Almer
7 siblings, 0 replies; 9+ messages in thread
From: James Almer @ 2025-06-18 1:39 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/iamf_writer.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c
index 37e75dc01a..ad40871fa1 100644
--- a/libavformat/iamf_writer.c
+++ b/libavformat/iamf_writer.c
@@ -758,14 +758,14 @@ static int iamf_write_audio_element(const IAMFContext *iamf,
/* When the loudspeaker_layout of the (non-)scalable channel audio (i.e., num_layers = 1) is less than or equal to 3.1.2ch,
* (i.e., Mono, Stereo, or 3.1.2ch), the type PARAMETER_DEFINITION_DEMIXING SHALL NOT be present. */
else if (element->nb_layers == 1 && (layout == 0 || layout == 1 || layout == 8))
- param_definition_types &= ~AV_IAMF_PARAMETER_DEFINITION_DEMIXING;
- /* When num_layers > 1, the type PARAMETER_DEFINITION_RECON_GAIN SHALL be present */
- if (element->nb_layers > 1)
- param_definition_types |= AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN;
- /* When codec_id = fLaC or ipcm, the type PARAMETER_DEFINITION_RECON_GAIN SHALL NOT be present. */
- if (codec_config->codec_tag == MKTAG('f','L','a','C') ||
- codec_config->codec_tag == MKTAG('i','p','c','m'))
- param_definition_types &= ~AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN;
+ param_definition_types &= ~AV_IAMF_PARAMETER_DEFINITION_DEMIXING;
+ /* When num_layers > 1, the type PARAMETER_DEFINITION_RECON_GAIN SHALL be present */
+ if (element->nb_layers > 1)
+ param_definition_types |= AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN;
+ /* When codec_id = fLaC or ipcm, the type PARAMETER_DEFINITION_RECON_GAIN SHALL NOT be present. */
+ if (codec_config->codec_tag == MKTAG('f','L','a','C') ||
+ codec_config->codec_tag == MKTAG('i','p','c','m'))
+ param_definition_types &= ~AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN;
if ((param_definition_types & AV_IAMF_PARAMETER_DEFINITION_DEMIXING) && !element->demixing_info) {
if (element->nb_layers > 1) {
get_loudspeaker_layout(element->layers[element->nb_layers-1], &layout, &expanded_layout);
--
2.50.0
_______________________________________________
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
* [FFmpeg-devel] [PATCH 9/9] avformat/iamf_writer: use named constants in more places
2025-06-18 1:38 [FFmpeg-devel] [PATCH 1/9] avformat/iamf_writer: ensure each layer's channel layout contains all channels from the previous one James Almer
` (6 preceding siblings ...)
2025-06-18 1:39 ` [FFmpeg-devel] [PATCH 8/9] avformat/iamf_writer: reindent after previous commit James Almer
@ 2025-06-18 1:39 ` James Almer
7 siblings, 0 replies; 9+ messages in thread
From: James Almer @ 2025-06-18 1:39 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/iamf_writer.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c
index ad40871fa1..4302df7931 100644
--- a/libavformat/iamf_writer.c
+++ b/libavformat/iamf_writer.c
@@ -783,7 +783,7 @@ static int iamf_write_audio_element(const IAMFContext *iamf,
ffio_write_leb(dyn_bc, av_popcount(param_definition_types)); // num_parameters
- if (param_definition_types & 1) {
+ if (param_definition_types & AV_IAMF_PARAMETER_DEFINITION_DEMIXING) {
const AVIAMFParamDefinition *param = element->demixing_info;
const IAMFParamDefinition *param_def;
const AVIAMFDemixingInfo *demix;
@@ -799,7 +799,7 @@ static int iamf_write_audio_element(const IAMFContext *iamf,
avio_w8(dyn_bc, demix->dmixp_mode << 5); // dmixp_mode
avio_w8(dyn_bc, element->default_w << 4); // default_w
}
- if (param_definition_types & 2) {
+ if (param_definition_types & AV_IAMF_PARAMETER_DEFINITION_RECON_GAIN) {
const AVIAMFParamDefinition *param = element->recon_gain_info;
const IAMFParamDefinition *param_def;
--
2.50.0
_______________________________________________
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".
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-06-18 1:41 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-18 1:38 [FFmpeg-devel] [PATCH 1/9] avformat/iamf_writer: ensure each layer's channel layout contains all channels from the previous one James Almer
2025-06-18 1:38 ` [FFmpeg-devel] [PATCH 2/9] avformat/iamf_parse: try to retype the channel layout for ambisonics_mode == 0 James Almer
2025-06-18 1:38 ` [FFmpeg-devel] [PATCH 3/9] tests/iamf: reorder muxed streams James Almer
2025-06-18 1:38 ` [FFmpeg-devel] [PATCH 4/9] tests/iamf: rename BACK to SIDE filterchain labels in the 5.1.4 iamf tests James Almer
2025-06-18 1:39 ` [FFmpeg-devel] [PATCH 5/9] avformat/iamf: fix setting channel layout for Scalable layers James Almer
2025-06-18 1:39 ` [FFmpeg-devel] [PATCH 6/9] avformat/iamf_writer: factorize out getting loudspeaker_layout values James Almer
2025-06-18 1:39 ` [FFmpeg-devel] [PATCH 7/9] avformat/iamf_writer: add extra constrains for Parameter Sets in Audio Elements James Almer
2025-06-18 1:39 ` [FFmpeg-devel] [PATCH 8/9] avformat/iamf_writer: reindent after previous commit James Almer
2025-06-18 1:39 ` [FFmpeg-devel] [PATCH 9/9] avformat/iamf_writer: use named constants in more places James Almer
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