diff mbox series

[FFmpeg-devel,2/2] avformat/iamf: use the new Binaural channel layout

Message ID 20241027224748.9189-2-jamrial@gmail.com
State New
Headers show
Series None | expand

Commit Message

James Almer Oct. 27, 2024, 10:47 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/dump.c                 |  6 +++---
 libavformat/iamf.c                 |  2 +-
 libavformat/iamf_parse.c           |  3 ++-
 libavformat/iamf_writer.c          |  3 +++
 libavutil/iamf.h                   | 10 +++++++---
 tests/ref/fate/iamf-stereo         |  2 +-
 tests/ref/fate/mov-mp4-iamf-stereo |  2 +-
 7 files changed, 18 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/dump.c b/libavformat/dump.c
index 7dc7f0ad5a..b7125a652f 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -752,12 +752,12 @@  static void dump_stream_group(const AVFormatContext *ic, uint8_t *printed,
             for (int k = 0; k < sub_mix->nb_layouts; k++) {
                 const AVIAMFSubmixLayout *submix_layout = sub_mix->layouts[k];
                 av_log(NULL, AV_LOG_INFO, "      Layout #%d:", k);
-                if (submix_layout->layout_type == 2) {
+                if (submix_layout->layout_type == 2 ||
+                    submix_layout->layout_type == 3) {
                     ret = av_channel_layout_describe(&submix_layout->sound_system, buf, sizeof(buf));
                     if (ret >= 0)
                         av_log(NULL, AV_LOG_INFO, " %s", buf);
-                } else if (submix_layout->layout_type == 3)
-                    av_log(NULL, AV_LOG_INFO, " Binaural");
+                }
                 av_log(NULL, AV_LOG_INFO, "\n");
             }
         }
diff --git a/libavformat/iamf.c b/libavformat/iamf.c
index 5de70dc082..3fcf145a85 100644
--- a/libavformat/iamf.c
+++ b/libavformat/iamf.c
@@ -42,7 +42,7 @@  const AVChannelLayout ff_iamf_scalable_ch_layouts[10] = {
     // Front subset of "Loudspeaker configuration for Sound System J"
     AV_CHANNEL_LAYOUT_3POINT1POINT2,
     // Binaural
-    AV_CHANNEL_LAYOUT_STEREO,
+    AV_CHANNEL_LAYOUT_BINAURAL,
 };
 
 const struct IAMFSoundSystemMap ff_iamf_sound_system_map[13] = {
diff --git a/libavformat/iamf_parse.c b/libavformat/iamf_parse.c
index e0a138a07d..4aed894796 100644
--- a/libavformat/iamf_parse.c
+++ b/libavformat/iamf_parse.c
@@ -956,7 +956,8 @@  static int mix_presentation_obu(void *s, IAMFContext *c, AVIOContext *pb, int le
                     goto fail;
                 }
                 av_channel_layout_copy(&submix_layout->sound_system, &ff_iamf_sound_system_map[sound_system].layout);
-            }
+            } else
+                submix_layout->sound_system = (AVChannelLayout)AV_CHANNEL_LAYOUT_BINAURAL;
 
             info_type = avio_r8(pbc);
             submix_layout->integrated_loudness = av_make_q(sign_extend(avio_rb16(pbc), 16), 1 << 8);
diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c
index 1b620c38ee..7703729e07 100644
--- a/libavformat/iamf_writer.c
+++ b/libavformat/iamf_writer.c
@@ -817,6 +817,9 @@  static int iamf_write_mixing_presentation(const IAMFContext *iamf,
                     av_log(log_ctx, AV_LOG_ERROR, "Invalid Sound System value in a submix\n");
                     return AVERROR(EINVAL);
                 }
+            } else if (submix_layout->layout_type != AV_IAMF_SUBMIX_LAYOUT_TYPE_BINAURAL) {
+                av_log(log_ctx, AV_LOG_ERROR, "Unsupported Layout Type value in a submix\n");
+                return AVERROR(EINVAL);
             }
             init_put_bits(&pbc, header, sizeof(header));
             put_bits(&pbc, 2, submix_layout->layout_type); // layout_type
diff --git a/libavutil/iamf.h b/libavutil/iamf.h
index 1fa73893cd..2ed7b0f2d8 100644
--- a/libavutil/iamf.h
+++ b/libavutil/iamf.h
@@ -493,10 +493,14 @@  typedef struct AVIAMFSubmixElement {
 enum AVIAMFSubmixLayoutType {
     /**
      * The layout follows the loudspeaker sound system convention of ITU-2051-3.
+     * @ref AVIAMFSubmixLayout.sound_system must be set.
      */
     AV_IAMF_SUBMIX_LAYOUT_TYPE_LOUDSPEAKERS = 2,
     /**
      * The layout is binaural.
+     *
+     * @note @ref AVIAMFSubmixLayout.sound_system may be set to
+     * AV_CHANNEL_LAYOUT_BINAURAL to simplify API usage, but it's not mandatory.
      */
     AV_IAMF_SUBMIX_LAYOUT_TYPE_BINAURAL = 3,
 };
@@ -514,9 +518,9 @@  typedef struct AVIAMFSubmixLayout {
 
     /**
      * Channel layout matching one of Sound Systems A to J of ITU-2051-3, plus
-     * 7.1.2ch and 3.1.2ch
-     * If layout_type is not AV_IAMF_SUBMIX_LAYOUT_TYPE_LOUDSPEAKERS, this field
-     * is undefined.
+     * 7.1.2ch, 3.1.2ch, and binaural.
+     * If layout_type is not AV_IAMF_SUBMIX_LAYOUT_TYPE_LOUDSPEAKERS or
+     * AV_IAMF_SUBMIX_LAYOUT_TYPE_BINAURAL, this field is undefined.
      */
     AVChannelLayout sound_system;
     /**
diff --git a/tests/ref/fate/iamf-stereo b/tests/ref/fate/iamf-stereo
index 9b3f7e0a79..843d1525e5 100644
--- a/tests/ref/fate/iamf-stereo
+++ b/tests/ref/fate/iamf-stereo
@@ -135,7 +135,7 @@  duration=0
 constant_subblock_duration=0
 [/PIECE]
 [PIECE]
-sound_system=0 channels
+sound_system=binaural
 integrated_loudness=0/256
 digital_peak=0/256
 true_peak=0/1
diff --git a/tests/ref/fate/mov-mp4-iamf-stereo b/tests/ref/fate/mov-mp4-iamf-stereo
index e40d164fc4..ca8f6a76f5 100644
--- a/tests/ref/fate/mov-mp4-iamf-stereo
+++ b/tests/ref/fate/mov-mp4-iamf-stereo
@@ -157,7 +157,7 @@  duration=0
 constant_subblock_duration=0
 [/PIECE]
 [PIECE]
-sound_system=0 channels
+sound_system=binaural
 integrated_loudness=0/256
 digital_peak=0/256
 true_peak=0/1