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 97A594AB73 for ; Wed, 15 May 2024 01:08:51 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 497C868D654; Wed, 15 May 2024 04:08:48 +0300 (EEST) Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BB29A68D4E8 for ; Wed, 15 May 2024 04:08:42 +0300 (EEST) Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-6f44390e328so5760244b3a.2 for ; Tue, 14 May 2024 18:08:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715735319; x=1716340119; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=UvbMLB54jW4Sq4H8Bv+SrlU+z7aA1NA/RAjYcLiJ/iA=; b=b93Jfu4nJHZ/al4zhzQqEsL2+TiDfEWPW3pqnrIsz9IdfJoDnGPSIk7quacvHj+FYq iA9d7K3tRQugqtwFI7W4EKyFHM2772eF4UgGVJh7hlDmqnO/EDQcgeqMF8JMX5+M/TxM e7gqBiEPTApxG3lF5yv2wa0kmMTBTZ9tmw5sxUIZZSe9ayAb899Fz6c9e1jxxQzACs6r OOj1Nu8wJ2oATftFJcX6X9xdaIj9bNGoZI7abZDPY/f1f10UI0FPfOAw7x5x5jr12ag6 /KNAeP8dW/nCGE3dQO/gC4li8Q1TEBYi8e598DKQcNpaqugDcDKfUQ3GOyCdUqGjVLS+ GMVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715735319; x=1716340119; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UvbMLB54jW4Sq4H8Bv+SrlU+z7aA1NA/RAjYcLiJ/iA=; b=g8Qjey3/71BP6bweztdyhAMD3viZydQjfvzWZ26yEwLXPKdKN5/zf+HLxxFf8RRtq6 2dVfz3TK5alH6zyodW+P0kVZcShT9ijriOZbqx6IkWROlIy2mE/d2x/C0Nwhp0AGfWNJ md4tpzP+8v/Ub1g9kwIC8+aSc4xmgjWzNna5W3IvpLV6PyzNz0rsVvs9UQ9RJy/6kHIJ 9Dz8th4QkzPOdf3n2ALZVje8htgObrYup1HJFDvYPPM+S3q9IshpcOCa/eWd6yIj+UfB 9D5SNB7l/MliBa2KLGlXnm013gNWmx7VHlLkRV1wkCAnp8xpmEP1M/26aITVECWrr3B+ qZig== X-Gm-Message-State: AOJu0YzL58NRqzyqOHa5Si599m0MX2bePL+ZZ/p82jYoyc3qjsSz3fZA 2zzoGdK1omtM3/diuXaF6691BhG8tA5YNDtC9Qx1T+/w5Sm5xRdFuygWLw== X-Google-Smtp-Source: AGHT+IEJQrlXBbBgSTITBk2Asqymz5mioEmU6P+986cu+/tS5DdV3LopioF5Tr7WA5rT0ypBsva53Q== X-Received: by 2002:a05:6a00:99f:b0:6ed:21c0:986c with SMTP id d2e1a72fcca58-6f4e03484a5mr23903350b3a.24.1715735319203; Tue, 14 May 2024 18:08:39 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f4d2a66691sm10135237b3a.16.2024.05.14.18.08.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 18:08:38 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 14 May 2024 22:08:28 -0300 Message-ID: <20240515010829.2667-1-jamrial@gmail.com> X-Mailer: git-send-email 2.45.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avutil/channel_layout: add a helper function to get the ambisonic order of a 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: Signed-off-by: James Almer --- libavutil/channel_layout.c | 17 ++++++++--------- libavutil/channel_layout.h | 10 ++++++++++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index fd6718e0e7..e213f68666 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -473,15 +473,14 @@ static int has_channel_names(const AVChannelLayout *channel_layout) return 0; } -/** - * If the layout is n-th order standard-order ambisonic, with optional - * extra non-diegetic channels at the end, return the order. - * Return a negative error code otherwise. - */ -static int ambisonic_order(const AVChannelLayout *channel_layout) +int av_channel_layout_get_ambisonic_order(const AVChannelLayout *channel_layout) { int i, highest_ambi, order; + if (channel_layout->order != AV_CHANNEL_ORDER_AMBISONIC && + channel_layout->order != AV_CHANNEL_ORDER_CUSTOM) + return AVERROR(EINVAL); + highest_ambi = -1; if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) highest_ambi = channel_layout->nb_channels - av_popcount64(channel_layout->u.mask) - 1; @@ -536,7 +535,7 @@ static enum AVChannelOrder canonical_order(AVChannelLayout *channel_layout) if (masked_description(channel_layout, 0) > 0) return AV_CHANNEL_ORDER_NATIVE; - order = ambisonic_order(channel_layout); + order = av_channel_layout_get_ambisonic_order(channel_layout); if (order >= 0 && masked_description(channel_layout, (order + 1) * (order + 1)) >= 0) return AV_CHANNEL_ORDER_AMBISONIC; @@ -551,7 +550,7 @@ static enum AVChannelOrder canonical_order(AVChannelLayout *channel_layout) static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout) { int nb_ambi_channels; - int order = ambisonic_order(channel_layout); + int order = av_channel_layout_get_ambisonic_order(channel_layout); if (order < 0) return order; @@ -945,7 +944,7 @@ int av_channel_layout_retype(AVChannelLayout *channel_layout, enum AVChannelOrde if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) { int64_t mask; int nb_channels = channel_layout->nb_channels; - int order = ambisonic_order(channel_layout); + int order = av_channel_layout_get_ambisonic_order(channel_layout); if (order < 0) return AVERROR(ENOSYS); mask = masked_description(channel_layout, (order + 1) * (order + 1)); diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h index 8a078d1601..c2ab236488 100644 --- a/libavutil/channel_layout.h +++ b/libavutil/channel_layout.h @@ -679,6 +679,16 @@ int av_channel_layout_check(const AVChannelLayout *channel_layout); */ int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1); +/** + * Return the order if the layout is n-th order standard-order ambisonic. + * The presence of optional extra non-diegetic channels at the end is not taken + * into account. + * + * @param channel_layout input channel layout + * @return the order of the layout, a negative error code otherwise. + */ +int av_channel_layout_get_ambisonic_order(const AVChannelLayout *channel_layout); + /** * The conversion must be lossless. */ -- 2.45.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".