From patchwork Mon Dec 26 17:14:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 1932 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp1120656vsb; Mon, 26 Dec 2016 09:15:09 -0800 (PST) X-Received: by 10.28.127.20 with SMTP id a20mr25018018wmd.15.1482772509525; Mon, 26 Dec 2016 09:15:09 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f187si43030456wma.87.2016.12.26.09.15.07; Mon, 26 Dec 2016 09:15: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 24737689C48; Mon, 26 Dec 2016 19:14: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 C3B4A689BEC for ; Mon, 26 Dec 2016 19:14:45 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 078EF100BD2; Mon, 26 Dec 2016 18:14:48 +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 RaJZbK538nAF; Mon, 26 Dec 2016 18:14:46 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 63FBCFFC60; Mon, 26 Dec 2016 18:14:46 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Dec 2016 18:14:34 +0100 Message-Id: <20161226171434.935-3-cus@passwd.hu> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161226171434.935-1-cus@passwd.hu> References: <20161226171434.935-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 3/3] avfilter/formats: do not allow unknown layouts in ff_parse_channel_layout if nret is not set X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Current code returned the number of channels as channel layout in that case, and if nret is not set then unknown layouts are typically not supported. Also use the common parsing code. This breaks a very specific case, using af_pan with an unknown channel layout such as '13c', from now on, only '13C' will work. Signed-off-by: Marton Balint --- libavfilter/formats.c | 20 ++++++-------------- libavfilter/tests/formats.c | 3 +++ tests/ref/fate/filter-formats | 5 ++++- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/libavfilter/formats.c b/libavfilter/formats.c index 840780d..8be606f 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -662,24 +662,16 @@ int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx) int ff_parse_channel_layout(int64_t *ret, int *nret, const char *arg, void *log_ctx) { - char *tail; int64_t chlayout; + int nb_channels; - chlayout = av_get_channel_layout(arg); - if (chlayout == 0) { - chlayout = strtol(arg, &tail, 10); - if (!(*tail == '\0' || *tail == 'c' && *(tail + 1) == '\0') || chlayout <= 0 || chlayout > 63) { - av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg); - return AVERROR(EINVAL); - } - if (nret) { - *nret = chlayout; - *ret = 0; - return 0; - } + if (av_get_extended_channel_layout(arg, &chlayout, &nb_channels) < 0 || (!chlayout && !nret)) { + av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg); + return AVERROR(EINVAL); } *ret = chlayout; if (nret) - *nret = av_get_channel_layout_nb_channels(chlayout); + *nret = nb_channels; + return 0; } diff --git a/libavfilter/tests/formats.c b/libavfilter/tests/formats.c index 0e8ba4a..5450742 100644 --- a/libavfilter/tests/formats.c +++ b/libavfilter/tests/formats.c @@ -39,6 +39,9 @@ int main(void) "-1c", "60c", "65c", + "2C", + "60C", + "65C", "5.1", "stereo", "1+1+1+1", diff --git a/tests/ref/fate/filter-formats b/tests/ref/fate/filter-formats index 4c303d8..17ff5b2 100644 --- a/tests/ref/fate/filter-formats +++ b/tests/ref/fate/filter-formats @@ -75,8 +75,11 @@ quad(side) 0 = ff_parse_channel_layout(0000000000000004, 1, 1c); 0 = ff_parse_channel_layout(0000000000000003, 2, 2c); -1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, -1c); -0 = ff_parse_channel_layout(0000000000000000, 60, 60c); +-1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, 60c); -1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, 65c); +0 = ff_parse_channel_layout(0000000000000000, 2, 2C); +0 = ff_parse_channel_layout(0000000000000000, 60, 60C); +-1 = ff_parse_channel_layout(FFFFFFFFFFFFFFFF, -1, 65C); 0 = ff_parse_channel_layout(000000000000003F, 6, 5.1); 0 = ff_parse_channel_layout(0000000000000003, 2, stereo); 0 = ff_parse_channel_layout(0000000000000001, 1, 1+1+1+1);