From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 018214F5BD for ; Wed, 18 Jun 2025 01:40:29 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 43CAB68DCFC; Wed, 18 Jun 2025 04:39:37 +0300 (EEST) Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 5A9B268DCD6 for ; Wed, 18 Jun 2025 04:39:28 +0300 (EEST) Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-748e63d4b05so129981b3a.2 for ; Tue, 17 Jun 2025 18:39:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750210766; x=1750815566; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=aPribopTjKbTRdfYf/1r+TCv3v4bMLrvSdC+Ky/08UQ=; b=abc35u9lA5NQF0qPWWhxejp0SI6XZozvNRVf1MxmQogaS/Gaz2pKHCVOfP7mAOzCYL bmuPxmcA1V+gYZ5+Xwg9Mu5kqpYRv240iC9MRdlQQQHKT36ghQ5RvoLLMDYLiEaDZRov Cck3iNIkGmxEHxJ4ok70bkDLCwfIzgSjxaf6A+nHPmUq8JGifMVRG/wx2Ezb/FpEOA6i 5zEC+l8IASRlsEdu7RzB8i6it+F4eJYJbeX9UI5UDaDbmXLlKD3Zw7//9qMA55Z+thIN ZyTVN+IScK4a+qLRqdTMm/chdwiU4reY7qsurH8ViYTZbNHVbYDC1XEsjMM9UxLqxt7b 3THQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750210766; x=1750815566; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aPribopTjKbTRdfYf/1r+TCv3v4bMLrvSdC+Ky/08UQ=; b=B3W5Bf024dFZuVYBP+8Jp7PF3Rp7CMvusDJ1KvviHXebG3FUo4seYj3nU+hKW5rn+f ybRzLxyGngwNjs+mFVo5ozuma8HP57PLiqMe9Z2FqUgU6OI28jX6uArAZe56XiSeOW/O OJIm8B6jRz7BJrjdbT/+z1ieaOEBGLZnZu/k/+cjva8ujk+C0zHITEZpBgndN3Ag94cX c+Y2MddVSh4z7R/7i4uOSc5uDrZQDOWoZengfDu9FzUKBMANUgkXyb695A0eERlUYMcU VtH3Pq14o84467LSO3MKhqEMGtuXj3zEIp6VglOyRWY78qGUILU5sTQQlpGEMnreRsQH TLEQ== X-Gm-Message-State: AOJu0Yw/9EnWG1uUQ70+z44F58NiiE+T9B7KuaysWbPp2vPYQ8vj3J99 xEgNGI2zLRyppUpVEAV9RfxPztF/pNK6OsZBAUIzUH2E/5dZ6OpUzF5LTxUjVg== X-Gm-Gg: ASbGncsiGDvvl7UQ/BkJiXCpPls+QJo4RInotgwnlgPNxFIKAXoepJd5ikfDcNobbtq 2w8dVSRIObnf6HsgNHLe9BNu9k5Ma6o98gujnjo4X2D3SgOWElv3yfcUSMIbsX3FdxmOP6oN0SF 17br2zXVz+g1JqBFqsLQrsFO0Hx6O7id+LWlOr0fGX1PJxi/aFhtfoAjaPQ7JSE21MWnQms1XGl vvIVXwwVJOkmTwnr+vUfI2e7j7wc2R7NsLD/k1mWSiQRdrv03HUaIooHc2G/MUeBRGZmQwAuNqA hC6R9aiwqegva1PAFJCkJUpdKjcwWcDoW6QwWeux60h1P3LlUWZLFID8DVE= X-Google-Smtp-Source: AGHT+IGcd3EEt9VVqnj7WXm45kT0Z3HCOc4DvPiPf+2OodE3WNkX9wcJmOwsG7IOoi/L+hs4KedekA== X-Received: by 2002:a05:6a00:14c2:b0:742:a77b:8bc with SMTP id d2e1a72fcca58-7489ce0cd46mr20623998b3a.2.1750210766119; Tue, 17 Jun 2025 18:39:26 -0700 (PDT) Received: from Gryph ([2800:2121:b000:82e:746f:8b87:8ec9:3872]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-748e566bee6sm431865b3a.127.2025.06.17.18.39.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jun 2025 18:39:25 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 17 Jun 2025 22:39:01 -0300 Message-ID: <20250618013904.15638-6-jamrial@gmail.com> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250618013904.15638-1-jamrial@gmail.com> References: <20250618013904.15638-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/9] avformat/iamf_writer: factorize out getting loudspeaker_layout values X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Signed-off-by: James Almer --- 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".