From patchwork Sat Mar 9 21:54:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 46921 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dc95:b0:1a1:738b:6bc0 with SMTP id ky21csp442154pzb; Sat, 9 Mar 2024 13:54:41 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXGOFn+Vj76ARfWGnknUBughmJyUhhszixaZHUoOi9JRgS7dlU2fTy/awjealZ2wMxUYdt1NNE55KwdnKo2i3x/r0w8eXvqSdiMdg== X-Google-Smtp-Source: AGHT+IEmif+15QXcL0yHap4fSEvTZk79l0AigDDCZCw4H7vk639PmgNdmJbxPBGNGV+1ysMuuhUY X-Received: by 2002:adf:f287:0:b0:33e:77e6:40bf with SMTP id k7-20020adff287000000b0033e77e640bfmr1760813wro.37.1710021281281; Sat, 09 Mar 2024 13:54:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1710021281; cv=none; d=google.com; s=arc-20160816; b=MehGpU7SpwMfHYWQiY/GM7I5loeG0Bu8ec3ytV8KeNbmJSLlvHXLmdn15eE0/o+4j0 tF1PI4cXtbG1d3DyisZ5/N8GdjX8frmYVlpEMfg0hMHIt3mtN980u+NxDh9rAu52xtvG Fz+CW2O15o6o+Pf99AdaJjezUC1dAap5aLoY55p7A2rhGfA1zwjuHtreeQFg79NHDVlQ 9PfT3Doz16j4xdLF3C9CYwNf30400SQdfLYGnfAs0acaSAcY7xTLsBfsMAT1h+WA7VkP Kyt1C2cariNObezUDmZUwlYYPakQyTcZnb7e7xHLMeWqeWV/bqv42hWoFer1RBzzxb2M UjIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=8yHO4kwHzpKIfbdjBde6m59589TdEts3+97xpcIuJ+k=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=Zj11tqwtEPVhEn7gLDaNAd5b6rMAN8+vMDw5eoVBkfBe2pARZP9YrxarcLcDfpIbd/ cVGqyteBvEc8uUY3xRswOjeVjiG9JO0CCAFvZSkgINC8ml7gjKOoSeL+xXYcMthVBiHd 0YGKb/0m6GFk64t6F++NqPlsgKNA8UcjRHMu/WHbvBaV57bjHfaivPnV+ncnsbUl5V4H YU9QxomR0aa/o0RwIo5e2kvFbN2GWfYPtjghsqgebHEswlkV+LE+XgmbESQyzi0J555d OEnDbuxpGFXJaQmeB3gahjIlIDykB+IYBdnss2Lfh34cU9MMg7IdzbzI+IUXgI9LP/gY Vnog==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r21-20020a50c015000000b005648769c8f6si1022013edb.442.2024.03.09.13.54.40; Sat, 09 Mar 2024 13:54:41 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D23E168CCB3; Sat, 9 Mar 2024 23:54:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4402C68C82F for ; Sat, 9 Mar 2024 23:54:30 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id C1186E8EC5; Sat, 9 Mar 2024 22:54:28 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hxC5eGFyXVpi; Sat, 9 Mar 2024 22:54:26 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 707A7E8EA0; Sat, 9 Mar 2024 22:54:26 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 9 Mar 2024 22:54:08 +0100 Message-Id: <20240309215414.26699-1-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/7] avutil/channel_layout: add AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL 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 Cc: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: dn7HlN3YzMGW Signed-off-by: Marton Balint --- doc/APIchanges | 3 +++ libavutil/channel_layout.c | 30 ++++++++++++++++++++++++++++++ libavutil/channel_layout.h | 7 +++++++ libavutil/version.h | 2 +- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index cf58c8c5f0..a44c8e4f10 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07 API changes, most recent first: +2024-03-xx - xxxxxxxxxx - lavu 59.2.100 - channel_layout.h + Add AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL. + 2024-03-08 - xxxxxxxxxx - lavc 61.1.100 - avcodec.h Add AVCodecContext.[nb_]side_data_prefer_packet. diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 8c1b3362f7..d3abb2dc42 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -553,6 +553,33 @@ static int ambisonic_order(const AVChannelLayout *channel_layout) return order; } +static enum AVChannelOrder canonical_order(AVChannelLayout *channel_layout) +{ + int has_known_channel = 0; + int order; + + if (channel_layout->order != AV_CHANNEL_ORDER_CUSTOM) + return channel_layout->order; + + if (has_channel_names(channel_layout)) + return AV_CHANNEL_ORDER_CUSTOM; + + for (int i = 0; i < channel_layout->nb_channels && !has_known_channel; i++) + if (channel_layout->u.map[i].id != AV_CHAN_UNKNOWN) + has_known_channel = 1; + if (!has_known_channel) + return AV_CHANNEL_ORDER_UNSPEC; + + if (masked_description(channel_layout, 0) > 0) + return AV_CHANNEL_ORDER_NATIVE; + + order = ambisonic_order(channel_layout); + if (order >= 0 && masked_description(channel_layout, (order + 1) * (order + 1)) >= 0) + return AV_CHANNEL_ORDER_AMBISONIC; + + return AV_CHANNEL_ORDER_CUSTOM; +} + /** * If the custom layout is n-th order standard-order ambisonic, with optional * extra non-diegetic channels at the end, write its string description in bp. @@ -892,6 +919,9 @@ int av_channel_layout_retype(AVChannelLayout *channel_layout, enum AVChannelOrde if (!av_channel_layout_check(channel_layout)) return AVERROR(EINVAL); + if (flags & AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL) + order = canonical_order(channel_layout); + if (channel_layout->order == order) return 0; diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h index 10ffe74468..a1e9b08064 100644 --- a/libavutil/channel_layout.h +++ b/libavutil/channel_layout.h @@ -680,6 +680,13 @@ int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout */ #define AV_CHANNEL_LAYOUT_RETYPE_FLAG_LOSSLESS (1 << 0) +/** + * The specified retype target order is ignored and the simplest possible + * (canonical) order is used for which the input layout can be losslessy + * represented. + */ +#define AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL (1 << 1) + /** * Change the AVChannelOrder of a channel layout. * diff --git a/libavutil/version.h b/libavutil/version.h index 09f8cdc292..57cad02ec0 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 59 -#define LIBAVUTIL_VERSION_MINOR 1 +#define LIBAVUTIL_VERSION_MINOR 2 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \