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, \ From patchwork Sat Mar 9 21:54:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 46922 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dc95:b0:1a1:738b:6bc0 with SMTP id ky21csp442217pzb; Sat, 9 Mar 2024 13:54:52 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCV2kZYsAjL0On95vr15KlTnVvAqwqYSM6vT/5l3qCQCFu4XDQGhm+5EQOiksGbzpnNmrloOulHU3KAeiV5Ve84PZYWe2YQh8qDkFg== X-Google-Smtp-Source: AGHT+IEtRZl5HtzyqHI6J+wuyq3bbDSTUBpH4TohF/cVyqYr/m0lHO3alfPxC/kKCUuZxVrvswW4 X-Received: by 2002:a50:cd98:0:b0:568:171:f82a with SMTP id p24-20020a50cd98000000b005680171f82amr1792182edi.20.1710021291755; Sat, 09 Mar 2024 13:54:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1710021291; cv=none; d=google.com; s=arc-20160816; b=jeI7X2oYWpKn609GHM9riStRYUTb8mow5Ae/L44N971CBdEydcTKr3r22IHirgBH0B JCqArO6m8c6jQvmBzdlBb5RdwD2+FSnqbHzkFxW4SMBj1cAMRNR0Th7vdstJiJqqCqXX tq/+k/7V0ZbruhWM8G2yh/0q14PBF4+b+KSDUtJPJqKsyNOs1LZ/lbD/UsoBja6ceXXy gP453LdlWXdLHs+iVR796FGiIhkK03+P5iaUdQTxKuvRpgxGyrbRljEO6z8gGVdj1+Sf RvJhwZuFNtXedcWX7VJ/O8QhOPhgocI5Pn4VJrtLQzOXnYllggyVTh3WErnF7NzufC6k o9TQ== 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:references:in-reply-to :message-id:date:to:from:delivered-to; bh=6smUzRTvVNb34yJhjPzeo5ep7IuEXn0tyU8JDgaFOVc=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=NclBM/pEMoLly0yxBI4zfJTWRPn9X1bo2C5ytv2xJOUL7Gj2lsoO84c8VQrHYV2CC/ rc4R/SO1kHU39KGGYMzlbVY0MD8eCf8a1QG0skqpR6/o2aM+8jR9PXP/BOmrrXBh5V2f az2RfojRKWM+S2Sbr9wQiJIdI/cgOyppSh77y2Zr/qV0a68RCcxCw9P+XCK+Bj788t4d NepB1y7RCQ4s9Clw4dRxUDT0fmuFR7/P+oDOMvkufR+mynkbmiaaXE6e2koIAKmTYdxM kKyFP+hhL3XMx3UjLxTOBCoNumM+LngZ1mPdYO6Nc92Y/N5uzeQnUYHEYsvVWwz5Nn+G zquQ==; 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 q4-20020a056402032400b00566dedfb08dsi1062562edw.582.2024.03.09.13.54.51; Sat, 09 Mar 2024 13:54:51 -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 EB20068CD3F; Sat, 9 Mar 2024 23:54:39 +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 0CBC168C82F for ; Sat, 9 Mar 2024 23:54:34 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id D9F3AE8EA0; Sat, 9 Mar 2024 22:54:33 +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 0HPyJjojNg8X; Sat, 9 Mar 2024 22:54:32 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 3E7F0E98EB; Sat, 9 Mar 2024 22:54:32 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 9 Mar 2024 22:54:09 +0100 Message-Id: <20240309215414.26699-2-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240309215414.26699-1-cus@passwd.hu> References: <20240309215414.26699-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/7] avformat/mov_chan: simplify channel layout canonicalization 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: oKuQmyj2H6sQ Signed-off-by: Marton Balint --- libavformat/mov_chan.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/libavformat/mov_chan.c b/libavformat/mov_chan.c index 3e186b0837..ead3a9b91b 100644 --- a/libavformat/mov_chan.c +++ b/libavformat/mov_chan.c @@ -543,10 +543,8 @@ int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st, ch_layout->u.map[i].id = mov_get_channel_id(label); } - ret = av_channel_layout_retype(ch_layout, AV_CHANNEL_ORDER_NATIVE, AV_CHANNEL_LAYOUT_RETYPE_FLAG_LOSSLESS); - if (ret == AVERROR(ENOSYS)) - ret = av_channel_layout_retype(ch_layout, AV_CHANNEL_ORDER_UNSPEC, AV_CHANNEL_LAYOUT_RETYPE_FLAG_LOSSLESS); - if (ret < 0 && ret != AVERROR(ENOSYS)) + ret = av_channel_layout_retype(ch_layout, 0, AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL); + if (ret < 0) goto out; } else { uint64_t mask = mov_get_channel_layout(layout_tag, bitmap); @@ -843,10 +841,8 @@ int ff_mov_read_chnl(AVFormatContext *s, AVIOContext *pb, AVStream *st) ch_layout->u.map[i].id = channel; } - ret = av_channel_layout_retype(ch_layout, AV_CHANNEL_ORDER_NATIVE, AV_CHANNEL_LAYOUT_RETYPE_FLAG_LOSSLESS); - if (ret == AVERROR(ENOSYS)) - ret = av_channel_layout_retype(ch_layout, AV_CHANNEL_ORDER_UNSPEC, AV_CHANNEL_LAYOUT_RETYPE_FLAG_LOSSLESS); - if (ret < 0 && ret != AVERROR(ENOSYS)) + ret = av_channel_layout_retype(ch_layout, 0, AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL); + if (ret < 0) return ret; } else { uint64_t omitted_channel_map = avio_rb64(pb); From patchwork Sat Mar 9 21:54:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 46923 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dc95:b0:1a1:738b:6bc0 with SMTP id ky21csp442250pzb; Sat, 9 Mar 2024 13:55:00 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXIW6gOuX6+2PmeA9E7vkLcGGPfgwOAaUhD5c/jnKtA50ljuJeSnsD6YSh54VB1W5E873zZgywaLP/xWhh8avrHPdQQxOEkpT4Xkw== X-Google-Smtp-Source: AGHT+IHjCI8+MxbeaftZW1KAl+MoecPj9s1yo1sTrpMgpXSrWunVUkKCD8h4fMQcguIg0nfbjvck X-Received: by 2002:a17:906:40d1:b0:a45:b74c:6e14 with SMTP id a17-20020a17090640d100b00a45b74c6e14mr1568180ejk.57.1710021300547; Sat, 09 Mar 2024 13:55:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1710021300; cv=none; d=google.com; s=arc-20160816; b=n1VSO1S4yajSfEoag3+FfyKnb/TurvSTQhMvg7rWs2ae2/QNTBxRCWG/cV6Sk8+7/r zWNH7k9vaRTKLWBcMzju6dzzo2AZXIMjE8tduBJrsJuqoTCvMOyPVAH/2KoaEoiYaNE0 Vdcys5xwDoCspTGinBmKqfmeB4ayjblBTDZUnYktm1PLoHJFH7N+q0/m0TLn2+pbftfn qU6fQWva6RQgnZEmE38j8opCk7hzJvYRw0cwQGDlhIYAO+hoxnHQufLSRao9Zddgu3sK KTBydKCOMHLwzBp+TUBph7JJnKoB/MUOyx4dBf9bta0ijqH5ldAc6vhLgMmyyfSTMqX5 jcKg== 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:references:in-reply-to :message-id:date:to:from:delivered-to; bh=axeD2d274C7EKDQJBpwDskg1r1ZmjE+9nQ7VOtVCcig=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=Gqh9rfwsUD8aHNugMqEPrsGE60ZjgZ5qjNq4lx3VldYWsXkFxl8rLs9brLj3KqpPU/ puQUrSBsFJtGJYLXtTHQt35VAejOPnBa+X5FzoRVHpdh607mb9cQhz3wwEbASFcf4Im/ CulYR5qBEEdytAKZH7S+GkUoxnZVOR/O9r7q5N5tqwPRyIIYoywj187gYtOEtQ5Iv/Fz 5IoUDIm77aZSN+2z0jMnQ55ZSU8H4KwjhZmlaqFOO6oZOAABjlbyPOo1oH0XQ5lc5rTZ P4TVFJcQw+jV0W79AkZp/L0nXMCoC7h8PtLrdewEG4iCpiKhgRddO54HZLpvg6Q55d8u M1NA==; 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 bt3-20020a170906b14300b00a4422dcbc2bsi1053277ejb.774.2024.03.09.13.55.00; Sat, 09 Mar 2024 13:55:00 -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 3018068CDB9; Sat, 9 Mar 2024 23:54:45 +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 C184D68CCF8 for ; Sat, 9 Mar 2024 23:54:38 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id A507CE98EB; Sat, 9 Mar 2024 22:54:38 +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 35ResHFlmmen; Sat, 9 Mar 2024 22:54:35 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 8D059E8EC5; Sat, 9 Mar 2024 22:54:35 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 9 Mar 2024 22:54:10 +0100 Message-Id: <20240309215414.26699-3-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240309215414.26699-1-cus@passwd.hu> References: <20240309215414.26699-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/7] avutil/tests/channel_layout: make printing results part of the tests 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: N34I1XsVBvsW Deduplicates a lot of code. Some minor differences (mostly white space and inconsistent use of quotes) are expected in the fate tests, there was no point aiming for exactly the same formatting. Signed-off-by: Marton Balint --- libavutil/tests/channel_layout.c | 283 +++++++++++-------------------- tests/ref/fate/channel_layout | 176 +++++++++---------- 2 files changed, 186 insertions(+), 273 deletions(-) diff --git a/libavutil/tests/channel_layout.c b/libavutil/tests/channel_layout.c index 23bb6009fb..d62b69a5db 100644 --- a/libavutil/tests/channel_layout.c +++ b/libavutil/tests/channel_layout.c @@ -162,39 +162,50 @@ static const char *channel_layout_retype(AVChannelLayout *layout, AVBPrint *bp, } #define CHANNEL_NAME(x) \ - channel_name(&bp, (x)); + channel_name(&bp, (x)); \ + printf("With %-32s %14s\n", AV_STRINGIFY(x)":", bp.str) #define CHANNEL_DESCRIPTION(x) \ - channel_description(&bp, (x)); + channel_description(&bp, (x)); \ + printf("With %-23s %23s\n", AV_STRINGIFY(x)":", bp.str); + +#define CHANNEL_FROM_STRING(x) \ + printf("With %-38s %8d\n", AV_STRINGIFY(x)":", av_channel_from_string(x)) #define CHANNEL_LAYOUT_FROM_MASK(x) \ channel_layout_from_mask(&layout, &bp, (x)); #define CHANNEL_LAYOUT_FROM_STRING(x) \ - channel_layout_from_string(&layout, &bp, (x)); + channel_layout_from_string(&layout, &bp, (x)); \ + printf("With \"%s\":%*s %32s\n", x, strlen(x) > 32 ? 0 : 32 - (int)strlen(x), "", bp.str); -#define CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(x) \ +#define CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(l, x) \ ret = av_channel_layout_channel_from_index(&layout, x); \ if (ret < 0) \ - ret = -1 + ret = -1; \ + printf("On \"%s\" layout with %2d: %8d\n", l, x, ret) -#define CHANNEL_LAYOUT_SUBSET(x) \ - mask = av_channel_layout_subset(&layout, x) +#define CHANNEL_LAYOUT_SUBSET(l, xstr, x) \ + mask = av_channel_layout_subset(&layout, x); \ + printf("On \"%s\" layout with %-22s 0x%"PRIx64"\n", l, xstr, mask) -#define CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(x) \ +#define CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(l, x) \ ret = av_channel_layout_index_from_channel(&layout, x); \ if (ret < 0) \ - ret = -1 + ret = -1; \ + printf("On \"%s\" layout with %-23s %3d\n", l, AV_STRINGIFY(x)":", ret) -#define CHANNEL_LAYOUT_CHANNEL_FROM_STRING(x) \ +#define CHANNEL_LAYOUT_CHANNEL_FROM_STRING(l, x) \ ret = av_channel_layout_channel_from_string(&layout, x); \ if (ret < 0) \ - ret = -1 + ret = -1; \ + printf("On \"%s\" layout with %-21s %3d\n", bp.str, AV_STRINGIFY(x)":", ret); -#define CHANNEL_LAYOUT_INDEX_FROM_STRING(x) \ +#define CHANNEL_LAYOUT_INDEX_FROM_STRING(l, x) \ ret = av_channel_layout_index_from_string(&layout, x); \ if (ret < 0) \ - ret = -1 + ret = -1; \ + printf("On \"%s\" layout with %-20s %3d\n", l, AV_STRINGIFY(x)":", ret); int main(void) { @@ -226,152 +237,94 @@ int main(void) printf("\nTesting av_channel_name\n"); CHANNEL_NAME(AV_CHAN_FRONT_LEFT); - printf("With AV_CHAN_FRONT_LEFT: %27s\n", bp.str); CHANNEL_NAME(AV_CHAN_FRONT_RIGHT); - printf("With AV_CHAN_FRONT_RIGHT: %26s\n", bp.str); CHANNEL_NAME(63); - printf("With 63: %43s\n", bp.str); CHANNEL_NAME(AV_CHAN_AMBISONIC_BASE); - printf("With AV_CHAN_AMBISONIC_BASE: %23s\n", bp.str); CHANNEL_NAME(AV_CHAN_AMBISONIC_END); - printf("With AV_CHAN_AMBISONIC_END: %24s\n", bp.str); printf("Testing av_channel_description\n"); CHANNEL_DESCRIPTION(AV_CHAN_FRONT_LEFT); - printf("With AV_CHAN_FRONT_LEFT: %27s\n", bp.str); CHANNEL_DESCRIPTION(AV_CHAN_FRONT_RIGHT); - printf("With AV_CHAN_FRONT_RIGHT: %26s\n", bp.str); CHANNEL_DESCRIPTION(63); - printf("With 63: %43s\n", bp.str); CHANNEL_DESCRIPTION(AV_CHAN_AMBISONIC_BASE); - printf("With AV_CHAN_AMBISONIC_BASE: %23s\n", bp.str); CHANNEL_DESCRIPTION(AV_CHAN_AMBISONIC_END); - printf("With AV_CHAN_AMBISONIC_END: %24s\n", bp.str); printf("\nTesting av_channel_from_string\n"); - printf("With \"FL\": %41d\n", av_channel_from_string("FL")); - printf("With \"FR\": %41d\n", av_channel_from_string("FR")); - printf("With \"USR63\": %38d\n", av_channel_from_string("USR63")); - printf("With \"AMBI0\": %38d\n", av_channel_from_string("AMBI0")); - printf("With \"AMBI1023\": %35d\n", av_channel_from_string("AMBI1023")); + CHANNEL_FROM_STRING("FL"); + CHANNEL_FROM_STRING("FR"); + CHANNEL_FROM_STRING("USR63"); + CHANNEL_FROM_STRING("AMBI0"); + CHANNEL_FROM_STRING("AMBI1023"); printf("\n==Native layouts==\n"); printf("\nTesting av_channel_layout_from_string\n"); CHANNEL_LAYOUT_FROM_STRING("0x3f"); - printf("With \"0x3f\": %39s\n", bp.str); CHANNEL_LAYOUT_FROM_STRING("63"); - printf("With \"63\": %41s\n", bp.str); CHANNEL_LAYOUT_FROM_STRING("6c"); - printf("With \"6c\": %41s\n", bp.str); CHANNEL_LAYOUT_FROM_STRING("6C"); - printf("With \"6C\": %41s\n", bp.str); CHANNEL_LAYOUT_FROM_STRING("6 channels"); - printf("With \"6 channels\": %33s\n", bp.str); CHANNEL_LAYOUT_FROM_STRING("6 channels (FL+FR+FC+LFE+BL+BR)"); - printf("With \"6 channels (FL+FR+FC+LFE+BL+BR)\": %12s\n", bp.str); CHANNEL_LAYOUT_FROM_STRING("FL+FR+FC+LFE+BL+BR"); - printf("With \"FL+FR+FC+LFE+BL+BR\": %25s\n", bp.str); CHANNEL_LAYOUT_FROM_STRING("5.1"); - printf("With \"5.1\": %40s\n", bp.str); CHANNEL_LAYOUT_FROM_STRING("FL+FR+USR63"); - printf("With \"FL+FR+USR63\": %32s\n", bp.str); CHANNEL_LAYOUT_FROM_STRING("FL+FR+FC+LFE+SL+SR"); - printf("With \"FL+FR+FC+LFE+SL+SR\": %25s\n", bp.str); CHANNEL_LAYOUT_FROM_STRING("5.1(side)"); - printf("With \"5.1(side)\": %34s\n", bp.str); printf("\nTesting av_channel_layout_from_mask\n"); CHANNEL_LAYOUT_FROM_MASK(AV_CH_LAYOUT_5POINT1); printf("With AV_CH_LAYOUT_5POINT1: %25s\n", bp.str); printf("\nTesting av_channel_layout_channel_from_index\n"); - CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(0); - printf("On 5.1(side) layout with 0: %24d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(1); - printf("On 5.1(side) layout with 1: %24d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(2); - printf("On 5.1(side) layout with 2: %24d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(3); - printf("On 5.1(side) layout with 3: %24d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(4); - printf("On 5.1(side) layout with 4: %24d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(5); - printf("On 5.1(side) layout with 5: %24d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(6); - printf("On 5.1(side) layout with 6: %24d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 0); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 1); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 2); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 3); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 4); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 5); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 6); printf("\nTesting av_channel_layout_index_from_channel\n"); - CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_FRONT_LEFT); - printf("On 5.1(side) layout with AV_CHAN_FRONT_LEFT: %7d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_FRONT_RIGHT); - printf("On 5.1(side) layout with AV_CHAN_FRONT_RIGHT: %6d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_FRONT_CENTER); - printf("On 5.1(side) layout with AV_CHAN_FRONT_CENTER: %5d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_LOW_FREQUENCY); - printf("On 5.1(side) layout with AV_CHAN_LOW_FREQUENCY: %4d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_SIDE_LEFT); - printf("On 5.1(side) layout with AV_CHAN_SIDE_LEFT: %8d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_SIDE_RIGHT); - printf("On 5.1(side) layout with AV_CHAN_SIDE_RIGHT: %7d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_BACK_CENTER); - printf("On 5.1(side) layout with AV_CHAN_BACK_CENTER: %6d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_FRONT_LEFT); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_FRONT_RIGHT); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_FRONT_CENTER); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_LOW_FREQUENCY); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_SIDE_LEFT); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_SIDE_RIGHT); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_BACK_CENTER); printf("\nTesting av_channel_layout_channel_from_string\n"); - CHANNEL_LAYOUT_CHANNEL_FROM_STRING("FL"); - printf("On 5.1(side) layout with \"FL\": %21d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_STRING("FR"); - printf("On 5.1(side) layout with \"FR\": %21d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_STRING("FC"); - printf("On 5.1(side) layout with \"FC\": %21d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_STRING("LFE"); - printf("On 5.1(side) layout with \"LFE\": %20d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_STRING("SL"); - printf("On 5.1(side) layout with \"SL\": %21d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_STRING("SR"); - printf("On 5.1(side) layout with \"SR\": %21d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_STRING("BC"); - printf("On 5.1(side) layout with \"BC\": %21d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "FL"); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "FR"); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "FC"); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "LFE"); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "SL"); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "SR"); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "BC"); printf("\nTesting av_channel_layout_index_from_string\n"); - CHANNEL_LAYOUT_INDEX_FROM_STRING("FL"); - printf("On 5.1(side) layout with \"FL\": %21d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_STRING("FR"); - printf("On 5.1(side) layout with \"FR\": %21d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_STRING("FC"); - printf("On 5.1(side) layout with \"FC\": %21d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_STRING("LFE"); - printf("On 5.1(side) layout with \"LFE\": %20d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_STRING("SL"); - printf("On 5.1(side) layout with \"SL\": %21d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_STRING("SR"); - printf("On 5.1(side) layout with \"SR\": %21d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_STRING("BC"); - printf("On 5.1(side) layout with \"BC\": %21d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "FL"); + CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "FR"); + CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "FC"); + CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "LFE"); + CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "SL"); + CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "SR"); + CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "BC"); printf("\nTesting av_channel_layout_subset\n"); - CHANNEL_LAYOUT_SUBSET(AV_CH_LAYOUT_STEREO); - printf("On 5.1(side) layout with AV_CH_LAYOUT_STEREO: 0x%"PRIx64"\n", mask); - CHANNEL_LAYOUT_SUBSET(AV_CH_LAYOUT_2POINT1); - printf("On 5.1(side) layout with AV_CH_LAYOUT_2POINT1: 0x%"PRIx64"\n", mask); - CHANNEL_LAYOUT_SUBSET(AV_CH_LAYOUT_4POINT1); - printf("On 5.1(side) layout with AV_CH_LAYOUT_4POINT1: 0x%"PRIx64"\n", mask); + CHANNEL_LAYOUT_SUBSET(bp.str, "AV_CH_LAYOUT_STEREO:", AV_CH_LAYOUT_STEREO); + CHANNEL_LAYOUT_SUBSET(bp.str, "AV_CH_LAYOUT_2POINT1:", AV_CH_LAYOUT_2POINT1); + CHANNEL_LAYOUT_SUBSET(bp.str, "AV_CH_LAYOUT_4POINT1:", AV_CH_LAYOUT_4POINT1); printf("\n==Custom layouts==\n"); printf("\nTesting av_channel_layout_from_string\n"); CHANNEL_LAYOUT_FROM_STRING("FL+FR+FC+BL+BR+LFE"); - printf("With \"FL+FR+FC+BL+BR+LFE\": %34s\n", bp.str); CHANNEL_LAYOUT_FROM_STRING("2 channels (FR+FL)"); - printf("With \"2 channels (FR+FL)\": %34s\n", bp.str); CHANNEL_LAYOUT_FROM_STRING("ambisonic 1+FR+FL"); - printf("With \"ambisonic 1+FR+FL\": %35s\n", bp.str); CHANNEL_LAYOUT_FROM_STRING("ambisonic 2+FC@Foo"); - printf("With \"ambisonic 2+FC@Foo\": %34s\n", bp.str); CHANNEL_LAYOUT_FROM_STRING("FL@Foo+FR@Bar"); - printf("With \"FL@Foo+FR@Bar\": %39s\n", bp.str); CHANNEL_LAYOUT_FROM_STRING("FR+FL@Foo+USR63@Foo"); - printf("With \"FR+FL@Foo+USR63@Foo\": %33s\n", bp.str); ret = av_channel_layout_copy(&layout2, &layout); if (ret < 0) { @@ -383,104 +336,64 @@ int main(void) printf("Channel layout and its copy compare unequal; ret: %d\n", ret); printf("\nTesting av_channel_layout_index_from_string\n"); - CHANNEL_LAYOUT_INDEX_FROM_STRING("FR"); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"FR\": %18d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_STRING("FL"); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"FL\": %18d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_STRING("USR63"); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"USR63\": %15d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_STRING("Foo"); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"Foo\": %17d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_STRING("@Foo"); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"@Foo\": %16d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_STRING("FR@Foo"); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"FR@Foo\": %14d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_STRING("FL@Foo"); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"FL@Foo\": %14d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_STRING("USR63@Foo"); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"USR63@Foo\": %11d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_STRING("BC"); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"BC\": %18d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "FR"); + CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "FL"); + CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "USR63"); + CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "Foo"); + CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "@Foo"); + CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "FR@Foo"); + CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "FL@Foo"); + CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "USR63@Foo"); + CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "BC"); printf("\nTesting av_channel_layout_channel_from_string\n"); - CHANNEL_LAYOUT_CHANNEL_FROM_STRING("FR"); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"FR\": %18d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_STRING("FL"); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"FL\": %18d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_STRING("USR63"); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"USR63\": %15d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_STRING("Foo"); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"Foo\": %17d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_STRING("@Foo"); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"@Foo\": %16d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_STRING("FR@Foo"); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"FR@Foo\": %14d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_STRING("FL@Foo"); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"FL@Foo\": %14d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_STRING("USR63@Foo"); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"USR63@Foo\": %11d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_STRING("BC"); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with \"BC\": %18d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "FR"); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "FL"); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "USR63"); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "Foo"); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "@Foo"); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "FR@Foo"); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "FL@Foo"); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "USR63@Foo"); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "BC"); printf("\nTesting av_channel_layout_index_from_channel\n"); - CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_FRONT_RIGHT); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with AV_CHAN_FRONT_RIGHT: %3d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_FRONT_LEFT); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with AV_CHAN_FRONT_LEFT: %4d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(63); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with 63: %20d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_BACK_CENTER); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with AV_CHAN_BACK_CENTER: %3d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_FRONT_RIGHT); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_FRONT_LEFT); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, 63); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_BACK_CENTER); printf("\nTesting av_channel_layout_channel_from_index\n"); - CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(0); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with 0: %21d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(1); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with 1: %21d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(2); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with 2: %21d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(3); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with 3: %21d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 0); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 1); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 2); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 3); printf("\nTesting av_channel_layout_subset\n"); - CHANNEL_LAYOUT_SUBSET(AV_CH_LAYOUT_STEREO); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with AV_CH_LAYOUT_STEREO: 0x%"PRIx64"\n", mask); - CHANNEL_LAYOUT_SUBSET(AV_CH_LAYOUT_QUAD); - printf("On \"FR+FL@Foo+USR63@Foo\" layout with AV_CH_LAYOUT_QUAD: 0x%"PRIx64"\n", mask); + CHANNEL_LAYOUT_SUBSET(bp.str, "AV_CH_LAYOUT_STEREO:", AV_CH_LAYOUT_STEREO); + CHANNEL_LAYOUT_SUBSET(bp.str, "AV_CH_LAYOUT_QUAD:", AV_CH_LAYOUT_QUAD); printf("\n==Ambisonic layouts==\n"); printf("\nTesting av_channel_layout_from_string\n"); CHANNEL_LAYOUT_FROM_STRING("ambisonic 1"); - printf("With \"ambisonic 1\": %41s\n", bp.str); CHANNEL_LAYOUT_FROM_STRING("ambisonic 2+stereo"); - printf("With \"ambisonic 2+stereo\": %34s\n", bp.str); printf("\nTesting av_channel_layout_index_from_channel\n"); - CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_AMBISONIC_BASE); - printf("On \"ambisonic 2+stereo\" layout with AV_CHAN_AMBISONIC_BASE: %d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_FRONT_LEFT); - printf("On \"ambisonic 2+stereo\" layout with AV_CHAN_FRONT_LEFT: %5d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_FRONT_RIGHT); - printf("On \"ambisonic 2+stereo\" layout with AV_CHAN_FRONT_RIGHT: %4d\n", ret); - CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(AV_CHAN_BACK_CENTER); - printf("On \"ambisonic 2+stereo\" layout with AV_CHAN_BACK_CENTER: %4d\n", ret); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_AMBISONIC_BASE); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_FRONT_LEFT); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_FRONT_RIGHT); + CHANNEL_LAYOUT_INDEX_FROM_CHANNEL(bp.str, AV_CHAN_BACK_CENTER); printf("\nTesting av_channel_layout_channel_from_index\n"); - CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(0); - printf("On \"ambisonic 2+stereo\" layout with 0: %22d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(9); - printf("On \"ambisonic 2+stereo\" layout with 9: %22d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(10); - printf("On \"ambisonic 2+stereo\" layout with 10: %21d\n", ret); - CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(11); - printf("On \"ambisonic 2+stereo\" layout with 11: %21d\n", ret); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 0); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 9); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 10); + CHANNEL_LAYOUT_CHANNEL_FROM_INDEX(bp.str, 11); printf("\nTesting av_channel_layout_subset\n"); - CHANNEL_LAYOUT_SUBSET(AV_CH_LAYOUT_STEREO); - printf("On \"ambisonic 2+stereo\" layout with AV_CH_LAYOUT_STEREO: 0x%"PRIx64"\n", mask); - CHANNEL_LAYOUT_SUBSET(AV_CH_LAYOUT_QUAD); - printf("On \"ambisonic 2+stereo\" layout with AV_CH_LAYOUT_QUAD: 0x%"PRIx64"\n", mask); + CHANNEL_LAYOUT_SUBSET(bp.str, "AV_CH_LAYOUT_STEREO:", AV_CH_LAYOUT_STEREO); + CHANNEL_LAYOUT_SUBSET(bp.str, "AV_CH_LAYOUT_QUAD:", AV_CH_LAYOUT_QUAD); av_channel_layout_uninit(&layout); av_channel_layout_uninit(&layout2); diff --git a/tests/ref/fate/channel_layout b/tests/ref/fate/channel_layout index 466fa78d9e..b98ccdb0f0 100644 --- a/tests/ref/fate/channel_layout +++ b/tests/ref/fate/channel_layout @@ -60,131 +60,131 @@ With "AMBI1023": 2047 ==Native layouts== Testing av_channel_layout_from_string -With "0x3f": 5.1 -With "63": 5.1 -With "6c": 5.1 -With "6C": 6 channels -With "6 channels": 6 channels -With "6 channels (FL+FR+FC+LFE+BL+BR)": 5.1 -With "FL+FR+FC+LFE+BL+BR": 5.1 -With "5.1": 5.1 -With "FL+FR+USR63": 3 channels (FL+FR+USR63) -With "FL+FR+FC+LFE+SL+SR": 5.1(side) -With "5.1(side)": 5.1(side) +With "0x3f": 5.1 +With "63": 5.1 +With "6c": 5.1 +With "6C": 6 channels +With "6 channels": 6 channels +With "6 channels (FL+FR+FC+LFE+BL+BR)": 5.1 +With "FL+FR+FC+LFE+BL+BR": 5.1 +With "5.1": 5.1 +With "FL+FR+USR63": 3 channels (FL+FR+USR63) +With "FL+FR+FC+LFE+SL+SR": 5.1(side) +With "5.1(side)": 5.1(side) Testing av_channel_layout_from_mask With AV_CH_LAYOUT_5POINT1: 5.1(side) Testing av_channel_layout_channel_from_index -On 5.1(side) layout with 0: 0 -On 5.1(side) layout with 1: 1 -On 5.1(side) layout with 2: 2 -On 5.1(side) layout with 3: 3 -On 5.1(side) layout with 4: 9 -On 5.1(side) layout with 5: 10 -On 5.1(side) layout with 6: -1 +On "5.1(side)" layout with 0: 0 +On "5.1(side)" layout with 1: 1 +On "5.1(side)" layout with 2: 2 +On "5.1(side)" layout with 3: 3 +On "5.1(side)" layout with 4: 9 +On "5.1(side)" layout with 5: 10 +On "5.1(side)" layout with 6: -1 Testing av_channel_layout_index_from_channel -On 5.1(side) layout with AV_CHAN_FRONT_LEFT: 0 -On 5.1(side) layout with AV_CHAN_FRONT_RIGHT: 1 -On 5.1(side) layout with AV_CHAN_FRONT_CENTER: 2 -On 5.1(side) layout with AV_CHAN_LOW_FREQUENCY: 3 -On 5.1(side) layout with AV_CHAN_SIDE_LEFT: 4 -On 5.1(side) layout with AV_CHAN_SIDE_RIGHT: 5 -On 5.1(side) layout with AV_CHAN_BACK_CENTER: -1 +On "5.1(side)" layout with AV_CHAN_FRONT_LEFT: 0 +On "5.1(side)" layout with AV_CHAN_FRONT_RIGHT: 1 +On "5.1(side)" layout with AV_CHAN_FRONT_CENTER: 2 +On "5.1(side)" layout with AV_CHAN_LOW_FREQUENCY: 3 +On "5.1(side)" layout with AV_CHAN_SIDE_LEFT: 4 +On "5.1(side)" layout with AV_CHAN_SIDE_RIGHT: 5 +On "5.1(side)" layout with AV_CHAN_BACK_CENTER: -1 Testing av_channel_layout_channel_from_string -On 5.1(side) layout with "FL": 0 -On 5.1(side) layout with "FR": 1 -On 5.1(side) layout with "FC": 2 -On 5.1(side) layout with "LFE": 3 -On 5.1(side) layout with "SL": 9 -On 5.1(side) layout with "SR": 10 -On 5.1(side) layout with "BC": -1 +On "5.1(side)" layout with "FL": 0 +On "5.1(side)" layout with "FR": 1 +On "5.1(side)" layout with "FC": 2 +On "5.1(side)" layout with "LFE": 3 +On "5.1(side)" layout with "SL": 9 +On "5.1(side)" layout with "SR": 10 +On "5.1(side)" layout with "BC": -1 Testing av_channel_layout_index_from_string -On 5.1(side) layout with "FL": 0 -On 5.1(side) layout with "FR": 1 -On 5.1(side) layout with "FC": 2 -On 5.1(side) layout with "LFE": 3 -On 5.1(side) layout with "SL": 4 -On 5.1(side) layout with "SR": 5 -On 5.1(side) layout with "BC": -1 +On "5.1(side)" layout with "FL": 0 +On "5.1(side)" layout with "FR": 1 +On "5.1(side)" layout with "FC": 2 +On "5.1(side)" layout with "LFE": 3 +On "5.1(side)" layout with "SL": 4 +On "5.1(side)" layout with "SR": 5 +On "5.1(side)" layout with "BC": -1 Testing av_channel_layout_subset -On 5.1(side) layout with AV_CH_LAYOUT_STEREO: 0x3 -On 5.1(side) layout with AV_CH_LAYOUT_2POINT1: 0xb -On 5.1(side) layout with AV_CH_LAYOUT_4POINT1: 0xf +On "5.1(side)" layout with AV_CH_LAYOUT_STEREO: 0x3 +On "5.1(side)" layout with AV_CH_LAYOUT_2POINT1: 0xb +On "5.1(side)" layout with AV_CH_LAYOUT_4POINT1: 0xf ==Custom layouts== Testing av_channel_layout_from_string -With "FL+FR+FC+BL+BR+LFE": 6 channels (FL+FR+FC+BL+BR+LFE) -With "2 channels (FR+FL)": 2 channels (FR+FL) -With "ambisonic 1+FR+FL": ambisonic 1+2 channels (FR+FL) -With "ambisonic 2+FC@Foo": ambisonic 2+1 channels (FC@Foo) -With "FL@Foo+FR@Bar": 2 channels (FL@Foo+FR@Bar) -With "FR+FL@Foo+USR63@Foo": 3 channels (FR+FL@Foo+USR63@Foo) +With "FL+FR+FC+BL+BR+LFE": 6 channels (FL+FR+FC+BL+BR+LFE) +With "2 channels (FR+FL)": 2 channels (FR+FL) +With "ambisonic 1+FR+FL": ambisonic 1+2 channels (FR+FL) +With "ambisonic 2+FC@Foo": ambisonic 2+1 channels (FC@Foo) +With "FL@Foo+FR@Bar": 2 channels (FL@Foo+FR@Bar) +With "FR+FL@Foo+USR63@Foo": 3 channels (FR+FL@Foo+USR63@Foo) Testing av_channel_layout_index_from_string -On "FR+FL@Foo+USR63@Foo" layout with "FR": 0 -On "FR+FL@Foo+USR63@Foo" layout with "FL": 1 -On "FR+FL@Foo+USR63@Foo" layout with "USR63": 2 -On "FR+FL@Foo+USR63@Foo" layout with "Foo": -1 -On "FR+FL@Foo+USR63@Foo" layout with "@Foo": 1 -On "FR+FL@Foo+USR63@Foo" layout with "FR@Foo": -1 -On "FR+FL@Foo+USR63@Foo" layout with "FL@Foo": 1 -On "FR+FL@Foo+USR63@Foo" layout with "USR63@Foo": 2 -On "FR+FL@Foo+USR63@Foo" layout with "BC": -1 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with "FR": 0 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with "FL": 1 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with "USR63": 2 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with "Foo": -1 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with "@Foo": 1 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with "FR@Foo": -1 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with "FL@Foo": 1 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with "USR63@Foo": 2 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with "BC": -1 Testing av_channel_layout_channel_from_string -On "FR+FL@Foo+USR63@Foo" layout with "FR": 1 -On "FR+FL@Foo+USR63@Foo" layout with "FL": 0 -On "FR+FL@Foo+USR63@Foo" layout with "USR63": 63 -On "FR+FL@Foo+USR63@Foo" layout with "Foo": -1 -On "FR+FL@Foo+USR63@Foo" layout with "@Foo": 0 -On "FR+FL@Foo+USR63@Foo" layout with "FR@Foo": -1 -On "FR+FL@Foo+USR63@Foo" layout with "FL@Foo": 0 -On "FR+FL@Foo+USR63@Foo" layout with "USR63@Foo": 63 -On "FR+FL@Foo+USR63@Foo" layout with "BC": -1 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with "FR": 1 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with "FL": 0 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with "USR63": 63 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with "Foo": -1 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with "@Foo": 0 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with "FR@Foo": -1 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with "FL@Foo": 0 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with "USR63@Foo": 63 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with "BC": -1 Testing av_channel_layout_index_from_channel -On "FR+FL@Foo+USR63@Foo" layout with AV_CHAN_FRONT_RIGHT: 0 -On "FR+FL@Foo+USR63@Foo" layout with AV_CHAN_FRONT_LEFT: 1 -On "FR+FL@Foo+USR63@Foo" layout with 63: 2 -On "FR+FL@Foo+USR63@Foo" layout with AV_CHAN_BACK_CENTER: -1 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with AV_CHAN_FRONT_RIGHT: 0 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with AV_CHAN_FRONT_LEFT: 1 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with 63: 2 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with AV_CHAN_BACK_CENTER: -1 Testing av_channel_layout_channel_from_index -On "FR+FL@Foo+USR63@Foo" layout with 0: 1 -On "FR+FL@Foo+USR63@Foo" layout with 1: 0 -On "FR+FL@Foo+USR63@Foo" layout with 2: 63 -On "FR+FL@Foo+USR63@Foo" layout with 3: -1 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with 0: 1 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with 1: 0 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with 2: 63 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with 3: -1 Testing av_channel_layout_subset -On "FR+FL@Foo+USR63@Foo" layout with AV_CH_LAYOUT_STEREO: 0x3 -On "FR+FL@Foo+USR63@Foo" layout with AV_CH_LAYOUT_QUAD: 0x3 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with AV_CH_LAYOUT_STEREO: 0x3 +On "3 channels (FR+FL@Foo+USR63@Foo)" layout with AV_CH_LAYOUT_QUAD: 0x3 ==Ambisonic layouts== Testing av_channel_layout_from_string -With "ambisonic 1": ambisonic 1 -With "ambisonic 2+stereo": ambisonic 2+stereo +With "ambisonic 1": ambisonic 1 +With "ambisonic 2+stereo": ambisonic 2+stereo Testing av_channel_layout_index_from_channel -On "ambisonic 2+stereo" layout with AV_CHAN_AMBISONIC_BASE: 0 -On "ambisonic 2+stereo" layout with AV_CHAN_FRONT_LEFT: 9 -On "ambisonic 2+stereo" layout with AV_CHAN_FRONT_RIGHT: 10 -On "ambisonic 2+stereo" layout with AV_CHAN_BACK_CENTER: -1 +On "ambisonic 2+stereo" layout with AV_CHAN_AMBISONIC_BASE: 0 +On "ambisonic 2+stereo" layout with AV_CHAN_FRONT_LEFT: 9 +On "ambisonic 2+stereo" layout with AV_CHAN_FRONT_RIGHT: 10 +On "ambisonic 2+stereo" layout with AV_CHAN_BACK_CENTER: -1 Testing av_channel_layout_channel_from_index -On "ambisonic 2+stereo" layout with 0: 1024 -On "ambisonic 2+stereo" layout with 9: 0 -On "ambisonic 2+stereo" layout with 10: 1 -On "ambisonic 2+stereo" layout with 11: -1 +On "ambisonic 2+stereo" layout with 0: 1024 +On "ambisonic 2+stereo" layout with 9: 0 +On "ambisonic 2+stereo" layout with 10: 1 +On "ambisonic 2+stereo" layout with 11: -1 Testing av_channel_layout_subset -On "ambisonic 2+stereo" layout with AV_CH_LAYOUT_STEREO: 0x3 -On "ambisonic 2+stereo" layout with AV_CH_LAYOUT_QUAD: 0x3 +On "ambisonic 2+stereo" layout with AV_CH_LAYOUT_STEREO: 0x3 +On "ambisonic 2+stereo" layout with AV_CH_LAYOUT_QUAD: 0x3 Testing av_channel_layout_retype With "FL@Boo": CUSTOM (1 channels (FL@Boo)) From patchwork Sat Mar 9 21:54:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 46924 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dc95:b0:1a1:738b:6bc0 with SMTP id ky21csp442295pzb; Sat, 9 Mar 2024 13:55:09 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUlW69Px7o7IkuMBw+VriiEm60b4+aGBI6n5XpuoJwdKZn/eP9O3t0i1ZyKlnRJgRvxcXUefEkrwZO5g4QubRKTOljp2UIxMk9OZw== X-Google-Smtp-Source: AGHT+IEEnA8rJPy0nBQmE4RtBK3UHa+NCavVNl0JkIGu2an43p1HK8yJWdYdAt1hlOLXPh//K0E8 X-Received: by 2002:a17:906:718:b0:a40:3aa3:9b8a with SMTP id y24-20020a170906071800b00a403aa39b8amr1541798ejb.15.1710021309669; Sat, 09 Mar 2024 13:55:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1710021309; cv=none; d=google.com; s=arc-20160816; b=bGyfGBcivunIGBz+RrhKKIqaU7LC25XS/N0Za57JFUK2QjH0YxQsNVxggTnjm39DDd 8ji50yYmGz/WSK/f9H0zsLoo250hSTMcXOJYwEmCH8G7DLlXpWKPKxhlDM/p6sWCB68N 5ksOzVvEmLU9wgF0DpbTc1+sP8tjz4LsF9FSaf7ckKKLbpxRI9hOPDy8kW6aE1vo5zsJ Wk0a+DuxO7TxFJBsfZbFOjklntFG6dQqmZBwn+E2yaqn7s1rf7IoSNHog3CE2j26/Ygm 4J7hUgRZY59HPHdPMPYedrqNDVih5mCeBRdI1B8JAZdTFwrE008uRCo/A3uGB1gsDSGs 1pVw== 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:references:in-reply-to :message-id:date:to:from:delivered-to; bh=H0j001k1q1/zyFo49swnwohfHSw58cZUAADPw/p3dTY=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=jlq5G1s1tsI4lX0gCYc2ES2tEXCRr+DqDMc312xqDiEO9//EdLnMHphpiK5/U9FntE hyqW/BJITMEmCoFrAYGDvdjbmrVcTH41rAyAqXdjStHY3zduOvVAcKdz7UJLpmnegBlo xMKjLFqhoxG5Gw1Z05T2h6etFDhAGt0DkcwlmurTKhJM3miqu+olGCeAYFH9PQfe7zAh sQ0DOtpS5Vc2ZezdqpmmZK7AA12nK5082Z4kITR1RvhL6kAIKUlyryxFRTP8eUAknnsc KKI13kZ5Wk8jyvDSxMaZmHc9mnW+IoBNPCCSPD0zTk4cN/QTKNiTQdiml1sOCqhBOQ/g iEWA==; 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 v12-20020a170906180c00b00a45ff20b165si972239eje.761.2024.03.09.13.55.09; Sat, 09 Mar 2024 13:55:09 -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 56AF668CDD1; Sat, 9 Mar 2024 23:54:47 +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 87C8868CDD1 for ; Sat, 9 Mar 2024 23:54:40 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 53BD5E8EA0; Sat, 9 Mar 2024 22:54:40 +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 M3MqxztXtCnF; Sat, 9 Mar 2024 22:54:38 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 3CA7FE9B9E; Sat, 9 Mar 2024 22:54:38 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 9 Mar 2024 22:54:11 +0100 Message-Id: <20240309215414.26699-4-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240309215414.26699-1-cus@passwd.hu> References: <20240309215414.26699-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/7] avutil/tests/channel_layout: add some av_channel_from_string and av_channel_layout_from_string tests 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: b7SzCOuoDesx We lacked tests which supposed to fail, and there are some which should fail but right now it does not. This will be fixed in a later commit. Signed-off-by: Marton Balint --- libavutil/tests/channel_layout.c | 26 ++++++++++++++++++++++++++ tests/ref/fate/channel_layout | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/libavutil/tests/channel_layout.c b/libavutil/tests/channel_layout.c index d62b69a5db..14d36c71b5 100644 --- a/libavutil/tests/channel_layout.c +++ b/libavutil/tests/channel_layout.c @@ -255,6 +255,11 @@ int main(void) CHANNEL_FROM_STRING("USR63"); CHANNEL_FROM_STRING("AMBI0"); CHANNEL_FROM_STRING("AMBI1023"); + CHANNEL_FROM_STRING("AMBI1024"); + CHANNEL_FROM_STRING("Dummy"); + CHANNEL_FROM_STRING("FL@Foo"); + CHANNEL_FROM_STRING("Foo@FL"); + CHANNEL_FROM_STRING("@FL"); printf("\n==Native layouts==\n"); @@ -301,6 +306,9 @@ int main(void) CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "SL"); CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "SR"); CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "BC"); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "@"); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "@Foo"); + CHANNEL_LAYOUT_CHANNEL_FROM_STRING(bp.str, "FL@Foo"); printf("\nTesting av_channel_layout_index_from_string\n"); CHANNEL_LAYOUT_INDEX_FROM_STRING(bp.str, "FL"); @@ -321,9 +329,27 @@ int main(void) printf("\nTesting av_channel_layout_from_string\n"); CHANNEL_LAYOUT_FROM_STRING("FL+FR+FC+BL+BR+LFE"); CHANNEL_LAYOUT_FROM_STRING("2 channels (FR+FL)"); + CHANNEL_LAYOUT_FROM_STRING("2 channels (AMBI1023+FL)"); + CHANNEL_LAYOUT_FROM_STRING("3 channels (FR+FL)"); + CHANNEL_LAYOUT_FROM_STRING("-3 channels (FR+FL)"); + CHANNEL_LAYOUT_FROM_STRING("0 channels ()"); + CHANNEL_LAYOUT_FROM_STRING("2 channels (FL+FR"); CHANNEL_LAYOUT_FROM_STRING("ambisonic 1+FR+FL"); CHANNEL_LAYOUT_FROM_STRING("ambisonic 2+FC@Foo"); CHANNEL_LAYOUT_FROM_STRING("FL@Foo+FR@Bar"); + CHANNEL_LAYOUT_FROM_STRING("FL+stereo"); + CHANNEL_LAYOUT_FROM_STRING("stereo+stereo"); + CHANNEL_LAYOUT_FROM_STRING("stereo@Boo"); + CHANNEL_LAYOUT_FROM_STRING(""); + CHANNEL_LAYOUT_FROM_STRING("@"); + CHANNEL_LAYOUT_FROM_STRING("@Dummy"); + CHANNEL_LAYOUT_FROM_STRING("@FL"); + CHANNEL_LAYOUT_FROM_STRING("Dummy"); + CHANNEL_LAYOUT_FROM_STRING("Dummy@FL"); + CHANNEL_LAYOUT_FROM_STRING("FR+Dummy"); + CHANNEL_LAYOUT_FROM_STRING("FR+Dummy@FL"); + CHANNEL_LAYOUT_FROM_STRING("FR+@FL"); + CHANNEL_LAYOUT_FROM_STRING("FL+@"); CHANNEL_LAYOUT_FROM_STRING("FR+FL@Foo+USR63@Foo"); ret = av_channel_layout_copy(&layout2, &layout); diff --git a/tests/ref/fate/channel_layout b/tests/ref/fate/channel_layout index b98ccdb0f0..ea7ec6fa3c 100644 --- a/tests/ref/fate/channel_layout +++ b/tests/ref/fate/channel_layout @@ -56,6 +56,11 @@ With "FR": 1 With "USR63": 63 With "AMBI0": 1024 With "AMBI1023": 2047 +With "AMBI1024": -1 +With "Dummy": -1 +With "FL@Foo": -1 +With "Foo@FL": -1 +With "@FL": -1 ==Native layouts== @@ -101,6 +106,9 @@ On "5.1(side)" layout with "LFE": 3 On "5.1(side)" layout with "SL": 9 On "5.1(side)" layout with "SR": 10 On "5.1(side)" layout with "BC": -1 +On "5.1(side)" layout with "@": -1 +On "5.1(side)" layout with "@Foo": -1 +On "5.1(side)" layout with "FL@Foo": -1 Testing av_channel_layout_index_from_string On "5.1(side)" layout with "FL": 0 @@ -121,9 +129,27 @@ On "5.1(side)" layout with AV_CH_LAYOUT_4POINT1: 0xf Testing av_channel_layout_from_string With "FL+FR+FC+BL+BR+LFE": 6 channels (FL+FR+FC+BL+BR+LFE) With "2 channels (FR+FL)": 2 channels (FR+FL) +With "2 channels (AMBI1023+FL)": fail +With "3 channels (FR+FL)": fail +With "-3 channels (FR+FL)": fail +With "0 channels ()": fail +With "2 channels (FL+FR": fail With "ambisonic 1+FR+FL": ambisonic 1+2 channels (FR+FL) With "ambisonic 2+FC@Foo": ambisonic 2+1 channels (FC@Foo) With "FL@Foo+FR@Bar": 2 channels (FL@Foo+FR@Bar) +With "FL+stereo": fail +With "stereo+stereo": fail +With "stereo@Boo": fail +With "": fail +With "@": fail +With "@Dummy": fail +With "@FL": 1 channels (FL) +With "Dummy": fail +With "Dummy@FL": fail +With "FR+Dummy": fail +With "FR+Dummy@FL": 1 channels (FR) +With "FR+@FL": 2 channels (FR+FL@FL) +With "FL+@": fail With "FR+FL@Foo+USR63@Foo": 3 channels (FR+FL@Foo+USR63@Foo) Testing av_channel_layout_index_from_string From patchwork Sat Mar 9 21:54:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 46927 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dc95:b0:1a1:738b:6bc0 with SMTP id ky21csp442417pzb; Sat, 9 Mar 2024 13:55:35 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXL5hFjnLn+sI451eIAo9W1Xn06gFSqmogxKXR7WObxKPpM6eyIwILTihqxL6SFbJYQrGBqVvlKqERg8yD0MUr2WWhMcnZhBEqfvg== X-Google-Smtp-Source: AGHT+IFh5XAF/nc6A7k62lNjSBEjEroeTm2UROOSnJlk7d2wVu6zRYpnZ+cq4jd6JcY2oXlqtVom X-Received: by 2002:a17:907:1004:b0:a45:1850:e6ed with SMTP id ox4-20020a170907100400b00a451850e6edmr1548101ejb.6.1710021335145; Sat, 09 Mar 2024 13:55:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1710021335; cv=none; d=google.com; s=arc-20160816; b=zdu9ZQ34TusfWRBKCzhPLASFt671jydzCBcmijOn+5TiOezl1tF+AFOD+In9L/GI1b LSE0CfmhEEbFXh4ExT+afxJUVHyNTOgffueVxq5vJo5+Uu1W0LV2edcb0jMsrDLUhm1w zrRTBYEBFXsNHup3CvhAYddKa8iIqplzUvcGBtoH+k1Horo5NVAsA7hXNV25yYtPZE0b s/s1Qf3iptQztkFi04cBTG07aobkfm6lN9m0lUBfi1Ph3RmcL+onz3jB+yJqghRv9ugS PkkkSrJYDyQtBK5UEW8nkb+MMP/fZTmJxshSSeoKdlzdh2QlwASisg1qsr7XU/xGx5sK Uwpg== 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:references:in-reply-to :message-id:date:to:from:delivered-to; bh=Z4JSpDxfu9DwUiQYqr/a0J/WClYq+w0aPT5xWdQpwgs=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=lxcw5Qf0f4aQpq2ysmtlQwmmDauFePmqLkzE0yBWQbXl/K5Xo+ciQnePfS7RbXoKQ7 +Y2iKx3b+Qi6A6mWP2rzAbjxEJui9u6RmeZntzxScKHBw48mBrKkkPfxmfzSXUK/nDra Mw2WtTcuJ+/c8M+0Tz+SYTbl6JXT2LdSuzs8ttQIQzFawcASOkdQHK9Dpq38PLZLDqCU YfD5NNa/en+7loHHZQtSvKNUOnQBi68nPXhvHoigMSb2GCGFgAkVNHVXrXbP9hNqU/D1 10lEjYPqT0PHk5V7h4Qv+T8w5o+Co1yLVs8J3EP00t4thgEJd5TUFrk9Ke8tTcVGk4x/ /NRw==; 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 g20-20020a170906539400b00a45cc26906csi1036153ejo.557.2024.03.09.13.55.34; Sat, 09 Mar 2024 13:55:35 -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 6B1B368CF41; Sat, 9 Mar 2024 23:54:55 +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 80EAC68CF0B for ; Sat, 9 Mar 2024 23:54:46 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 6FD47E8EA0; Sat, 9 Mar 2024 22:54:46 +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 iX1yR4AzRGDD; Sat, 9 Mar 2024 22:54:43 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id C06CFE8EC5; Sat, 9 Mar 2024 22:54:41 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 9 Mar 2024 22:54:12 +0100 Message-Id: <20240309215414.26699-5-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240309215414.26699-1-cus@passwd.hu> References: <20240309215414.26699-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/7] avutil/channel_layout: factorize parsing list of channel names 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: rteDW0NDynE7 Also make use of the av_channel_from_string() function to determine the channel id. This fixes some parse issues in av_channel_layout_from_string(). Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 172 ++++++++++++---------------------- tests/ref/fate/channel_layout | 8 +- 2 files changed, 62 insertions(+), 118 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index d3abb2dc42..5db4cc9df0 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -239,13 +239,58 @@ int av_channel_layout_from_mask(AVChannelLayout *channel_layout, return 0; } +static int parse_channel_list(AVChannelLayout *ch_layout, const char *str) +{ + int ret; + int nb_channels = 0; + AVChannelCustom *map = NULL; + AVChannelCustom custom = {0}; + + while (*str) { + char *channel, *chname; + int ret = av_opt_get_key_value(&str, "@", "+", AV_OPT_FLAG_IMPLICIT_KEY, &channel, &chname); + if (ret < 0) { + av_freep(&map); + return ret; + } + if (*str) + str++; // skip separator + if (!channel) { + channel = chname; + chname = NULL; + } + av_strlcpy(custom.name, chname ? chname : "", sizeof(custom.name)); + custom.id = av_channel_from_string(channel); + av_free(channel); + av_free(chname); + if (custom.id == AV_CHAN_NONE) { + av_freep(&map); + return AVERROR(EINVAL); + } + + av_dynarray2_add((void **)&map, &nb_channels, sizeof(custom), (void *)&custom); + if (!map) + return AVERROR(ENOMEM); + } + + if (!nb_channels) + return AVERROR(EINVAL); + + ch_layout->order = AV_CHANNEL_ORDER_CUSTOM; + ch_layout->u.map = map; + ch_layout->nb_channels = nb_channels; + + ret = av_channel_layout_retype(ch_layout, 0, AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL); + av_assert0(ret == 0); + + return 0; +} + int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str) { - int i; - int channels = 0, nb_channels = 0, native = 1; - enum AVChannel highest_channel = AV_CHAN_NONE; - const char *dup; + int i, matches, ret; + int channels = 0, nb_channels = 0; char *chlist, *end; uint64_t mask = 0; @@ -321,121 +366,20 @@ int av_channel_layout_from_string(AVChannelLayout *channel_layout, return AVERROR(ENOMEM); /* channel names */ - av_sscanf(str, "%d channels (%[^)]", &nb_channels, chlist); - end = strchr(str, ')'); - - dup = chlist; - while (*dup) { - char *channel, *chname; - int ret = av_opt_get_key_value(&dup, "@", "+", AV_OPT_FLAG_IMPLICIT_KEY, &channel, &chname); - if (ret < 0) { - av_free(chlist); - return ret; - } - if (*dup) - dup++; // skip separator - if (channel && !*channel) - av_freep(&channel); - for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++) { - if (channel_names[i].name && !strcmp(channel ? channel : chname, channel_names[i].name)) { - if (channel || i < highest_channel || mask & (1ULL << i)) - native = 0; // Not a native layout, use a custom one - highest_channel = i; - mask |= 1ULL << i; - break; - } - } - - if (!channel && i >= FF_ARRAY_ELEMS(channel_names)) { - char *endptr = chname; - enum AVChannel id = AV_CHAN_NONE; - - if (!strncmp(chname, "USR", 3)) { - const char *p = chname + 3; - id = strtol(p, &endptr, 0); - } - if (id < 0 || *endptr) { - native = 0; // Unknown channel name - channels = 0; - mask = 0; - av_free(chname); - break; - } - if (id > 63) - native = 0; // Not a native layout, use a custom one - else { - if (id < highest_channel || mask & (1ULL << id)) - native = 0; // Not a native layout, use a custom one - highest_channel = id; - mask |= 1ULL << id; - } - } - channels++; - av_free(channel); - av_free(chname); - } - - if (mask && native) { - av_free(chlist); - if (nb_channels && ((nb_channels != channels) || (!end || *++end))) - return AVERROR(EINVAL); - av_channel_layout_from_mask(channel_layout, mask); - return 0; - } - - /* custom layout of channel names */ - if (channels && !native) { - int idx = 0; + matches = av_sscanf(str, "%d channels (%[^)]", &nb_channels, chlist); + ret = parse_channel_list(channel_layout, chlist); + av_freep(&chlist); + if (ret < 0 && ret != AVERROR(EINVAL)) + return ret; - if (nb_channels && ((nb_channels != channels) || (!end || *++end))) { - av_free(chlist); + if (ret >= 0) { + end = strchr(str, ')'); + if (matches == 2 && (nb_channels != channel_layout->nb_channels || !end || *++end)) { + av_channel_layout_uninit(channel_layout); return AVERROR(EINVAL); } - - channel_layout->u.map = av_calloc(channels, sizeof(*channel_layout->u.map)); - if (!channel_layout->u.map) { - av_free(chlist); - return AVERROR(ENOMEM); - } - - channel_layout->order = AV_CHANNEL_ORDER_CUSTOM; - channel_layout->nb_channels = channels; - - dup = chlist; - while (*dup) { - char *channel, *chname; - int ret = av_opt_get_key_value(&dup, "@", "+", AV_OPT_FLAG_IMPLICIT_KEY, &channel, &chname); - if (ret < 0) { - av_freep(&channel_layout->u.map); - av_free(chlist); - return ret; - } - if (*dup) - dup++; // skip separator - for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++) { - if (channel_names[i].name && !strcmp(channel ? channel : chname, channel_names[i].name)) { - channel_layout->u.map[idx].id = i; - if (channel) - av_strlcpy(channel_layout->u.map[idx].name, chname, sizeof(channel_layout->u.map[idx].name)); - idx++; - break; - } - } - if (i >= FF_ARRAY_ELEMS(channel_names)) { - const char *p = (channel ? channel : chname) + 3; - channel_layout->u.map[idx].id = strtol(p, NULL, 0); - if (channel) - av_strlcpy(channel_layout->u.map[idx].name, chname, sizeof(channel_layout->u.map[idx].name)); - idx++; - } - av_free(channel); - av_free(chname); - } - av_free(chlist); - return 0; } - av_freep(&chlist); errno = 0; mask = strtoull(str, &end, 0); diff --git a/tests/ref/fate/channel_layout b/tests/ref/fate/channel_layout index ea7ec6fa3c..117a5fd84d 100644 --- a/tests/ref/fate/channel_layout +++ b/tests/ref/fate/channel_layout @@ -129,7 +129,7 @@ On "5.1(side)" layout with AV_CH_LAYOUT_4POINT1: 0xf Testing av_channel_layout_from_string With "FL+FR+FC+BL+BR+LFE": 6 channels (FL+FR+FC+BL+BR+LFE) With "2 channels (FR+FL)": 2 channels (FR+FL) -With "2 channels (AMBI1023+FL)": fail +With "2 channels (AMBI1023+FL)": 2 channels (AMBI1023+FL) With "3 channels (FR+FL)": fail With "-3 channels (FR+FL)": fail With "0 channels ()": fail @@ -143,12 +143,12 @@ With "stereo@Boo": fail With "": fail With "@": fail With "@Dummy": fail -With "@FL": 1 channels (FL) +With "@FL": fail With "Dummy": fail With "Dummy@FL": fail With "FR+Dummy": fail -With "FR+Dummy@FL": 1 channels (FR) -With "FR+@FL": 2 channels (FR+FL@FL) +With "FR+Dummy@FL": fail +With "FR+@FL": fail With "FL+@": fail With "FR+FL@Foo+USR63@Foo": 3 channels (FR+FL@Foo+USR63@Foo) From patchwork Sat Mar 9 21:54:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 46925 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dc95:b0:1a1:738b:6bc0 with SMTP id ky21csp442338pzb; Sat, 9 Mar 2024 13:55:18 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUVScLPDxC+cckK5VP3SZmWglf/yPcWPK3wi/qzhuXN6RqpCiylVM7xHu/YsWZSMA3JrEmYwpDbBTX2XaK2za2ZcDFITVlN5OlWzQ== X-Google-Smtp-Source: AGHT+IGKsFNmDfeFJAE3F5HAHKSwadE5x+2SGaQ2WJbDPJsFqBYqHjOMIejG8sShcOgfaRQ3UjUc X-Received: by 2002:a17:906:2616:b0:a45:b5a0:f3a with SMTP id h22-20020a170906261600b00a45b5a00f3amr1342147ejc.17.1710021318046; Sat, 09 Mar 2024 13:55:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1710021318; cv=none; d=google.com; s=arc-20160816; b=y05ZuxaO4FQfKzmWRNyqdaPaYDp8VFQYnBdw+pdSEtgF3I5z/O+sto6Yd0DEg5PP4N vFiqPTdl96GDwEVuCniBvRAbFqNs0EXGpZb7n+ixPORj5qQaO24cLkx1mlgoEUMvBP2V 2cDlYW8EAO9DeqJAXKcBj2FAha6r/L6CuKBYSrOtOSd2q2awCaY4hBXjK2h+ev4SLInT n/qtZZSDBK3frG3j9CDeFky4SECY5AzgqdWDfBveamCRfVBaRFx8JuN0euwMd0E4zGQu KYURmdVtrWEXoGJcwyvXqNs3niuVNkRVaWviuVIJWetS1kns4/rSXNR5C4iw1916cFTF w04A== 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:references:in-reply-to :message-id:date:to:from:delivered-to; bh=E+19Zus0R7cOXT1Wo4YkoPLFho7kcyR8IjcTtHZUr2A=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=IFi+SRS/n2CQIXP7u5jWtEu1UyT7EPLoDr2sWpKAs3eGX1TX9FctLpuhC95Nl7teUG X47Cji7YZBhhWxNxx6qDkCsCP8Ygo6jrhbrfvtb0DtAAssKWoIjh6E1ZscTG/97GIQ24 zy4NC+uMWoe3ojvxnzLOyXwL+tgMtSNVLX2JuEcPfbwiqxkjz4AS+V9OFIZHWoXC6ceX BJNGR54IJ5hO4L2u+TNyjm6/rlZA2iO36fSBKNh66F8Ywt5qL5R5z667SWDzvM56ssp3 ufmfBkusToLFppMyFWF5W171kvA4nquUm8Bx2D/OfshHEEUScuDcGhXMERagfMlrjNOx Ewmw==; 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 g8-20020a1709063b0800b00a44387ebd42si1015531ejf.886.2024.03.09.13.55.17; Sat, 09 Mar 2024 13:55:18 -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 626B368CEE5; Sat, 9 Mar 2024 23:54:51 +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 16CBF68CBCB for ; Sat, 9 Mar 2024 23:54:45 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id E9910E98EB; Sat, 9 Mar 2024 22:54:44 +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 x8ce6GkjohEf; Sat, 9 Mar 2024 22:54:43 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 67766E9B87; Sat, 9 Mar 2024 22:54:43 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 9 Mar 2024 22:54:13 +0100 Message-Id: <20240309215414.26699-6-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240309215414.26699-1-cus@passwd.hu> References: <20240309215414.26699-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/7] avutil/channel_layout: fix some (un)initialization issues in av_channel_layout_from_string() 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: wV0YcAw6ZCOe Also make initialization/uninitialization behaviour more explicit in the docs, and make sure we do not leak a channel map on error. Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 5 +++++ libavutil/channel_layout.h | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 5db4cc9df0..9e8a1c12e6 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -302,6 +302,10 @@ int av_channel_layout_from_string(AVChannelLayout *channel_layout, } } + /* This function is a channel layout initializer, so we have to + * zero-initialize before we start setting fields individually. */ + memset(channel_layout, 0, sizeof(*channel_layout)); + /* ambisonic */ if (!strncmp(str, "ambisonic ", 10)) { const char *p = str + 10; @@ -343,6 +347,7 @@ int av_channel_layout_from_string(AVChannelLayout *channel_layout, for (i = 0; i < extra.nb_channels; i++) { enum AVChannel ch = av_channel_layout_channel_from_index(&extra, i); if (CHAN_IS_AMBI(ch)) { + av_channel_layout_uninit(channel_layout); av_channel_layout_uninit(&extra); return AVERROR(EINVAL); } diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h index a1e9b08064..8a078d1601 100644 --- a/libavutil/channel_layout.h +++ b/libavutil/channel_layout.h @@ -512,10 +512,14 @@ int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask); * - the number of unordered channels (eg. "4C" or "4 channels") * - the ambisonic order followed by optional non-diegetic channels (eg. * "ambisonic 2+stereo") + * On error, the channel layout will remain uninitialized, but not necessarily + * untouched. * - * @param channel_layout input channel layout + * @param channel_layout uninitialized channel layout for the result * @param str string describing the channel layout - * @return 0 channel layout was detected, AVERROR_INVALIDATATA otherwise + * @return 0 on success parsing the channel layout + * AVERROR(EINVAL) if an invalid channel layout string was provided + * AVERROR(ENOMEM) if there was not enough memory */ int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str); From patchwork Sat Mar 9 21:54:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 46926 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dc95:b0:1a1:738b:6bc0 with SMTP id ky21csp442377pzb; Sat, 9 Mar 2024 13:55:27 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUFZp24HC+7asKlWnVXAYG21zXNUAeZo6SmekrOxHVG2IweS4yDQ7v2pYG+A7YeWvqZxiqWq0YHlBvnoslmO7BcosVNpNyVQrwx+A== X-Google-Smtp-Source: AGHT+IGZGQ0eFCoNo+Jwg1tyOCsMNMfckTJ76Z6Z8xZ9WtaTQwWBaOd9RGyBLj97i32Spa1GPrwc X-Received: by 2002:a50:c192:0:b0:568:1a8:58b with SMTP id m18-20020a50c192000000b0056801a8058bmr1634053edf.14.1710021326708; Sat, 09 Mar 2024 13:55:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1710021326; cv=none; d=google.com; s=arc-20160816; b=R4XaNzadzw0K2CGrGWkXNU32l52mKYS8BVImpr3NRIfCfoxbqaw71la09V4q8V/5xr EPw1Dg1YORaKF3mxleArdjO5/RKR9tjIOCjfRqrD3Fw9jnAJCxFOP9ofDyJTBPFzNhVR GaFLcLzICiMiIGOsLkYo4mnpJEifwZRdVbhuEVwOscmySuy/C8Khjpfkq4bXFKa+cZLe EX1Ol1qVjV7GhtB5O+sB9S8vrM1OsnE+hRzsy3RYCCjH0uiF6wTvRn31/4sXobIFF4t7 /SDlVP1hI8XZrPcJgU0ZjamvtNH8sOzj2DuV92g+REZ0KYgd6Pe7ok2HSGhP6WOyYdAK Q0Gg== 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:references:in-reply-to :message-id:date:to:from:delivered-to; bh=ZvR3ncJIuuhFenu3thizyZEjNbTyc1j0FNh9pEngJMQ=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=V/0lOWVBLlBrucCIVCBMRfudTg7AyziYeLr+iXsJvYyfTZCbEqofgUG5HbLJ+s3Q27 bVNL/u+RPnZcn2cQZuC9CWdkw+xEO/Anmo2bVG+XwCi5H8QjZRreGHGPaXkBSFUEb0rm 3Ui1XcLKd1q0CLVZHMEX/wrzhETh68W3NKPGiJ3Sq/fCoKiSRrR99z3JoW2AAebj6N0O iu7RL3jsBvhzYHA2mw+CF0Lt7zj1IL6aKMgsmEBEuaswWrzwLU+Cu93zcjpHRgv/XwML tLgd9OHhQ1MXX/LhBouvxk9NZLMUFXS6YrxkSsqWsUL4ooBpqGLdj6aZi/pQD/emcDdc H8mg==; 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 v1-20020a056402348100b005676553bc54si1038044edc.625.2024.03.09.13.55.26; Sat, 09 Mar 2024 13:55:26 -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 62E0568CF45; Sat, 9 Mar 2024 23:54:52 +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 DC1D268CDD9 for ; Sat, 9 Mar 2024 23:54:50 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 9B040E98EB; Sat, 9 Mar 2024 22:54:50 +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 KCEGqTKpMLp6; Sat, 9 Mar 2024 22:54:49 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 66146E8EC5; Sat, 9 Mar 2024 22:54:47 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 9 Mar 2024 22:54:14 +0100 Message-Id: <20240309215414.26699-7-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240309215414.26699-1-cus@passwd.hu> References: <20240309215414.26699-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 7/7] avutil/channel_layout: add specific text versions for unknown and unused channels 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: arH6U8cifdy6 Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 13 +++++++++++++ libavutil/tests/channel_layout.c | 2 ++ tests/ref/fate/channel_layout | 4 +++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 9e8a1c12e6..a83618bcc7 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -86,6 +86,10 @@ void av_channel_name_bprint(AVBPrint *bp, enum AVChannel channel_id) av_bprintf(bp, "%s", channel_names[channel_id].name); else if (channel_id == AV_CHAN_NONE) av_bprintf(bp, "NONE"); + else if (channel_id == AV_CHAN_UNKNOWN) + av_bprintf(bp, "UNK"); + else if (channel_id == AV_CHAN_UNUSED) + av_bprintf(bp, "UNSD"); else av_bprintf(bp, "USR%d", channel_id); } @@ -115,6 +119,10 @@ void av_channel_description_bprint(AVBPrint *bp, enum AVChannel channel_id) av_bprintf(bp, "%s", channel_names[channel_id].description); else if (channel_id == AV_CHAN_NONE) av_bprintf(bp, "none"); + else if (channel_id == AV_CHAN_UNKNOWN) + av_bprintf(bp, "unknown"); + else if (channel_id == AV_CHAN_UNUSED) + av_bprintf(bp, "unused"); else av_bprintf(bp, "user %d", channel_id); } @@ -151,6 +159,11 @@ enum AVChannel av_channel_from_string(const char *str) if (channel_names[i].name && !strcmp(str, channel_names[i].name)) return i; } + if (!strcmp(str, "UNK")) + return AV_CHAN_UNKNOWN; + if (!strcmp(str, "UNSD")) + return AV_CHAN_UNUSED; + if (!strncmp(str, "USR", 3)) { const char *p = str + 3; id = strtol(p, &endptr, 0); diff --git a/libavutil/tests/channel_layout.c b/libavutil/tests/channel_layout.c index 14d36c71b5..8132b83434 100644 --- a/libavutil/tests/channel_layout.c +++ b/libavutil/tests/channel_layout.c @@ -348,6 +348,8 @@ int main(void) CHANNEL_LAYOUT_FROM_STRING("Dummy@FL"); CHANNEL_LAYOUT_FROM_STRING("FR+Dummy"); CHANNEL_LAYOUT_FROM_STRING("FR+Dummy@FL"); + CHANNEL_LAYOUT_FROM_STRING("UNK+UNSD"); + CHANNEL_LAYOUT_FROM_STRING("NONE"); CHANNEL_LAYOUT_FROM_STRING("FR+@FL"); CHANNEL_LAYOUT_FROM_STRING("FL+@"); CHANNEL_LAYOUT_FROM_STRING("FR+FL@Foo+USR63@Foo"); diff --git a/tests/ref/fate/channel_layout b/tests/ref/fate/channel_layout index 117a5fd84d..0bcfefce3b 100644 --- a/tests/ref/fate/channel_layout +++ b/tests/ref/fate/channel_layout @@ -148,6 +148,8 @@ With "Dummy": fail With "Dummy@FL": fail With "FR+Dummy": fail With "FR+Dummy@FL": fail +With "UNK+UNSD": 2 channels (UNK+UNSD) +With "NONE": fail With "FR+@FL": fail With "FL+@": fail With "FR+FL@Foo+USR63@Foo": 3 channels (FR+FL@Foo+USR63@Foo) @@ -236,5 +238,5 @@ With "ambisonic 2+stereo": AMBI (ambisonic 2+stereo) With "2C": UNSPEC (2 channels) == UNSPEC (2 channels) != NATIVE - == CUSTOM (2 channels (USR768+USR768)) + == CUSTOM (2 channels (UNK+UNK)) != AMBI