Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial-at-gmail.com@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 7/9] avformat/iamf_writer: add extra constrains for Parameter Sets in Audio Elements
Date: Tue, 17 Jun 2025 22:39:02 -0300
Message-ID: <20250618013904.15638-7-jamrial@gmail.com> (raw)
In-Reply-To: <20250618013904.15638-1-jamrial@gmail.com>

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".

  parent reply	other threads:[~2025-06-18  1:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` James Almer [this message]
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

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=20250618013904.15638-7-jamrial@gmail.com \
    --to=jamrial-at-gmail.com@ffmpeg.org \
    --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