From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 8385D495B9 for ; Tue, 13 Feb 2024 17:40:02 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B09EE68D148; Tue, 13 Feb 2024 19:39:59 +0200 (EET) Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2944668CD3F for ; Tue, 13 Feb 2024 19:39:54 +0200 (EET) Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6e0cd3bed29so1384623b3a.1 for ; Tue, 13 Feb 2024 09:39:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707845991; x=1708450791; 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=l1z2w1ZTHsAZKW9PBv5a2zAbLIKbvT3rvNEK5+eHTOw=; b=TR13brFNQH85134+y/eVvkooA730/rPLxJWIZKSWKks1tLb6ChEtplhPeQ4XhsL6zE 5ijpAqNg0PDqU367Nvjxo3gf1roVZiBVR/NtpvMGewRYn7/4A2i+Rq0vg2hUgol1r6KT eqbhZAmwie9VqKoLphPyGFA6K3nN0XA4h+wY+mu8NWXl4+EDWM+HCDDvvRR2TiErWGmR eeYciNPXF46AODMrjgIKcozzbrm0OFvbhpzt5JGTeYP1/I9R5BnJ0xdMW5/NZQs6WGim J+hVgKlZEdZgxbcK6DD83+p9S18BPFJ6JPq0hskvl4w8lVEghyZmU5Qtm/pW+CEtc1G4 /pfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707845991; x=1708450791; 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=l1z2w1ZTHsAZKW9PBv5a2zAbLIKbvT3rvNEK5+eHTOw=; b=GsfXpLGXYDDa3CQT0I1erV3PJxSut/G5URouZdIRnTJ22v1Yy13KU9iESwRFkOWZO0 fUH+IR9Tr7PSt25XcWgFPRt0YJpLQQ7Yx/3EO48i+903TJqWj7yS8qnZ6HPbG4NC5+tq 4y7j7KVzdotS02csO6xsoosi3DKMTnpIRjFVrL83ch2bqMgbLNuaI3t7Q9oAgq9C+zQz EwwCG59/R27EkIfvylJY09XiI4l7sT6l95cFflMowDfVRSZt3hp5bBXJUe46boPc0Kwn gYHEkp0p+aTyf83/fK+dvqvmdpouUMVtfdhiR62pzVh92GQHirXLmiinu5tey7EHfXGr uVMg== X-Gm-Message-State: AOJu0Yyxfd8o+3dPwdT6pRQM81w0dNsyYoEikFU8T2nwGuriIQfXPsYl 6ZKZPHsF86j3tTAXm+K9Gg8TtUwzY6ol0kVfHRvakha0EtB7Sy/Vn5LEwI0M X-Google-Smtp-Source: AGHT+IHZf4Tms3b3CowH7BdoTubCk112cgZbIXR6NewUXy/kQX5QmQFxEO/dJ7VKG6AyyI/Zgesf4g== X-Received: by 2002:a05:6a20:c707:b0:19e:9da6:c73b with SMTP id hi7-20020a056a20c70700b0019e9da6c73bmr497958pzb.8.1707845991135; Tue, 13 Feb 2024 09:39:51 -0800 (PST) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id u33-20020a056a0009a100b006e0f7b8d15bsm1805643pfg.185.2024.02.13.09.39.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 09:39:50 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 13 Feb 2024 14:39:38 -0300 Message-ID: <20240213173938.6645-1-jamrial@gmail.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240212211537.18468-3-cus@passwd.hu> References: <20240212211537.18468-3-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avutil/channel_layout: print known layout names in custom layout 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: If a custom layout is equivalent to a native one, check if it matches one of the known layout names and print that instead. Signed-off-by: James Almer --- Should be applied after the patch this one is a reply to. libavutil/channel_layout.c | 68 +++++++++++++++++++++-------------- tests/ref/fate/channel_layout | 4 +-- 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 7f51c076dc..8b3bf2f4af 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -679,6 +679,29 @@ int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src) return 0; } +static int64_t masked_description(const AVChannelLayout *channel_layout, int start_channel) +{ + uint64_t mask = 0; + for (int i = start_channel; i < channel_layout->nb_channels; i++) { + enum AVChannel ch = channel_layout->u.map[i].id; + if (ch >= 0 && ch < 63 && mask < (1ULL << ch)) + mask |= (1ULL << ch); + else + return AVERROR(EINVAL); + } + return mask; +} + +static int has_channel_names(const AVChannelLayout *channel_layout) +{ + if (channel_layout->order != AV_CHANNEL_ORDER_CUSTOM) + return 0; + for (int i = 0; i < channel_layout->nb_channels; i++) + if (channel_layout->u.map[i].name[0]) + return 1; + return 0; +} + /** * If the layout is n-th order standard-order ambisonic, with optional * extra non-diegetic channels at the end, return the order. @@ -746,9 +769,17 @@ static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_l extra.nb_channels = av_popcount64(channel_layout->u.mask); extra.u.mask = channel_layout->u.mask; } else { - extra.order = AV_CHANNEL_ORDER_CUSTOM; - extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels; - extra.u.map = channel_layout->u.map + nb_ambi_channels; + int64_t mask; + if (!has_channel_names(channel_layout) && + (mask = masked_description(channel_layout, nb_ambi_channels)) > 0) { + extra.order = AV_CHANNEL_ORDER_NATIVE; + extra.nb_channels = av_popcount64(mask); + extra.u.mask = mask; + } else { + extra.order = AV_CHANNEL_ORDER_CUSTOM; + extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels; + extra.u.map = channel_layout->u.map + nb_ambi_channels; + } } av_bprint_chars(bp, '+', 1); @@ -774,9 +805,17 @@ int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout, // fall-through case AV_CHANNEL_ORDER_CUSTOM: if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) { + int64_t mask; int res = try_describe_ambisonic(bp, channel_layout); if (res >= 0) return 0; + if (!has_channel_names(channel_layout) && + (mask = masked_description(channel_layout, 0)) > 0) { + AVChannelLayout native = { .order = AV_CHANNEL_ORDER_NATIVE, + .nb_channels = av_popcount64(mask), + .u.mask = mask }; + return av_channel_layout_describe_bprint(&native, bp); + } } if (channel_layout->nb_channels) av_bprintf(bp, "%d channels (", channel_layout->nb_channels); @@ -1037,29 +1076,6 @@ uint64_t av_channel_layout_subset(const AVChannelLayout *channel_layout, return ret; } -static int64_t masked_description(AVChannelLayout *channel_layout, int start_channel) -{ - uint64_t mask = 0; - for (int i = start_channel; i < channel_layout->nb_channels; i++) { - enum AVChannel ch = channel_layout->u.map[i].id; - if (ch >= 0 && ch < 63 && mask < (1ULL << ch)) - mask |= (1ULL << ch); - else - return AVERROR(EINVAL); - } - return mask; -} - -static int has_channel_names(AVChannelLayout *channel_layout) -{ - if (channel_layout->order != AV_CHANNEL_ORDER_CUSTOM) - return 0; - for (int i = 0; i < channel_layout->nb_channels; i++) - if (channel_layout->u.map[i].name[0]) - return 1; - return 0; -} - int av_channel_layout_retype(AVChannelLayout *channel_layout, enum AVChannelOrder order, int flags) { int allow_lossy = !(flags & AV_CHANNEL_LAYOUT_RETYPE_FLAG_LOSSLESS); diff --git a/tests/ref/fate/channel_layout b/tests/ref/fate/channel_layout index 1d1f1cb082..466fa78d9e 100644 --- a/tests/ref/fate/channel_layout +++ b/tests/ref/fate/channel_layout @@ -195,7 +195,7 @@ With "FL@Boo": CUSTOM (1 channels (FL@Boo)) With "stereo": NATIVE (stereo) ~~ UNSPEC (2 channels) == NATIVE (stereo) - == CUSTOM (2 channels (FL+FR)) + == CUSTOM (stereo) != AMBI With "FR+FL": CUSTOM (2 channels (FR+FL)) ~~ UNSPEC (2 channels) @@ -205,7 +205,7 @@ With "FR+FL": CUSTOM (2 channels (FR+FL)) With "ambisonic 2+stereo": AMBI (ambisonic 2+stereo) ~~ UNSPEC (11 channels) != NATIVE - == CUSTOM (ambisonic 2+2 channels (FL+FR)) + == CUSTOM (ambisonic 2+stereo) == AMBI (ambisonic 2+stereo) With "2C": UNSPEC (2 channels) == UNSPEC (2 channels) -- 2.43.1 _______________________________________________ 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".