From patchwork Sat Aug 17 08:13:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 51059 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:b6ca:0:b0:48e:c0f8:d0de with SMTP id s10csp886835vqj; Sat, 17 Aug 2024 01:31:18 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXlrtuVYK6W6iT7zJVpSoLgYUP9veUVzAmnjlr+9bLGMpDgszdAl3UkL0bN0OfjlmsraR7LpYVmXTugHbgqhw0xmmb90yfNfDW3zw== X-Google-Smtp-Source: AGHT+IGOZdfg7O/HAwSJGE+pJ3rWccdY0nj6QZSw94bHyRpUApLb57lKf8Evi3BGJcKK/bQsx/IL X-Received: by 2002:a05:6402:3595:b0:5a3:18a6:6988 with SMTP id 4fb4d7f45d1cf-5beca593dc7mr4790651a12.17.1723883478118; Sat, 17 Aug 2024 01:31:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1723883478; cv=none; d=google.com; s=arc-20160816; b=d59na5NgLUNC+Kkd38Wu7/AiQG7VUk3Lc8zY/BcMtwmpOv7gU191vi88XTV9tDbqj5 83deVjoXy3MYPLrEtIepWTYWmzr+NKhlnzc8LYsZY9MT9tDTrz5uUH4befaeq+kGK93b iaoH6mhQtAZYYHj30u9foo4tHcJ0brU43WdIgdFvWjJeXZtbWjV+NrrWzJXUBYVVq/2q i5kEQWQDyihCkSRkA8w4JurX1gd2nHdm2wr0OkC80DC6a9QsClq5MzQfKKwx6KGng1Bp YZIkuSoJ2V70V7BRfXwAx1SLzOabnnYdT2MUPCetzBRdRXrybFKFBC9fEi31FYch/1rW XCUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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:dkim-signature:delivered-to; bh=SPX22/HDzbexqUunDPaWA3rDXC77SzJyicf+ApK9ruk=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=CjUfO4jtkUPf4gCv7NcSBG/hmYKEdcyk+mpn8QriABf8oKc9a6p5Z4OLJGlTnamKyr 3EDIYWCD0LBsj5DS17pWgQTknRfCKwa9UQ+JvXksum9dYKAIgoO+1deroCsSw3kS2tvE NyYtkgQKbQLOtDGUbw7tEssN9B5KbCzdFdhIz1aRlTizwP62LWyrFOZI9morvV/gWM++ GvQKQR0mLANV+zbdmJ02kYz3Mdpz84gSbdmKWFLmv3MA63r6/vPSmlDc1n6fDcAlxQOZ S4/yxh2ttofo6peBsOa38G4KIMCivxI+SU7gaEV3/Z7n/IlJE5gM54s/VpE7B2WXCkw1 G4tQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b="O0rWno/r"; 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 4fb4d7f45d1cf-5bebc7fde15si2838193a12.373.2024.08.17.01.31.17; Sat, 17 Aug 2024 01:31:18 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b="O0rWno/r"; 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 042DF68DCF9; Sat, 17 Aug 2024 11:14:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2649068DCC6 for ; Sat, 17 Aug 2024 11:14:09 +0300 (EEST) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=O0rWno/r; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id C06224DD7 for ; Sat, 17 Aug 2024 10:14:08 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id Xgiuo8tuRQAf for ; Sat, 17 Aug 2024 10:14:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1723882446; bh=LKGnqHK+Zqyhz9gF0pUvOMWwhm98FMJoikGMqKUlf+4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=O0rWno/rILrKOJHrtTUdMC7gNAB6StucNcgbwVjDp56rGJv7LiuXYn60RwTW4lBcW mDkVGbrzGG4up/BnKNNJ9y34BuM9LV6lvj+o/aa7r/ohrIDg6arzwsq4HPsxJFahGE 8KTuKqsAfCkAnBuR7SwkOzF9h5w4T3K36oAmhW33sAQWgR2aiULA7xB3lEtAvvHJ8w ehj1XE06bv/Jy9cCITSzJ2BuIdk5sDPy3oS3r+U4ecmXYhTPvMJK0BFqrctx5CEO/7 BZEoLYSib9IPeP1LxazwcJuGDnYqzticwDCUiaVuWGEaDScE7f9/fGb2pSSuYgb/8G idMA9T0XX2ViA== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 97C3A4DDE for ; Sat, 17 Aug 2024 10:14:06 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 401613A170F for ; Sat, 17 Aug 2024 10:14:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 17 Aug 2024 10:13:53 +0200 Message-ID: <20240817081358.2354-3-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240817081358.2354-1-anton@khirnov.net> References: <20240817081358.2354-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/8] lavfi: move ff_parse_{sample_rate, channel_layout}() to audio.[ch] 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: YTQjL/gY/2E1 That is a more appropriate place for those functions. --- libavfilter/audio.c | 36 +++++++++++++++++++++++++++++++++++ libavfilter/audio.h | 25 ++++++++++++++++++++++++ libavfilter/formats.c | 38 ------------------------------------- libavfilter/internal.h | 27 -------------------------- libavfilter/tests/formats.c | 1 + 5 files changed, 62 insertions(+), 65 deletions(-) diff --git a/libavfilter/audio.c b/libavfilter/audio.c index 1768b31184..11b3d0c9c3 100644 --- a/libavfilter/audio.c +++ b/libavfilter/audio.c @@ -23,6 +23,7 @@ #include "libavutil/channel_layout.h" #include "libavutil/common.h" #include "libavutil/cpu.h" +#include "libavutil/eval.h" #include "audio.h" #include "avfilter.h" @@ -107,3 +108,38 @@ AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples) return ret; } + +int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx) +{ + char *tail; + double srate = av_strtod(arg, &tail); + if (*tail || srate < 1 || (int)srate != srate || srate > INT_MAX) { + av_log(log_ctx, AV_LOG_ERROR, "Invalid sample rate '%s'\n", arg); + return AVERROR(EINVAL); + } + *ret = srate; + return 0; +} + +int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg, + void *log_ctx) +{ + AVChannelLayout chlayout = { 0 }; + int res; + + res = av_channel_layout_from_string(&chlayout, arg); + if (res < 0) { + av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg); + return AVERROR(EINVAL); + } + + if (chlayout.order == AV_CHANNEL_ORDER_UNSPEC && !nret) { + av_log(log_ctx, AV_LOG_ERROR, "Unknown channel layout '%s' is not supported.\n", arg); + return AVERROR(EINVAL); + } + *ret = chlayout; + if (nret) + *nret = chlayout.nb_channels; + + return 0; +} diff --git a/libavfilter/audio.h b/libavfilter/audio.h index aab80baa50..881df0cf87 100644 --- a/libavfilter/audio.h +++ b/libavfilter/audio.h @@ -47,4 +47,29 @@ AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples); */ AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples); +/** + * Parse a sample rate. + * + * @param ret unsigned integer pointer to where the value should be written + * @param arg string to parse + * @param log_ctx log context + * @return >= 0 in case of success, a negative AVERROR code on error + */ +av_warn_unused_result +int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx); + +/** + * Parse a channel layout or a corresponding integer representation. + * + * @param ret 64bit integer pointer to where the value should be written. + * @param nret integer pointer to the number of channels; + * if not NULL, then unknown channel layouts are accepted + * @param arg string to parse + * @param log_ctx log context + * @return >= 0 in case of success, a negative AVERROR code on error + */ +av_warn_unused_result +int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg, + void *log_ctx); + #endif /* AVFILTER_AUDIO_H */ diff --git a/libavfilter/formats.c b/libavfilter/formats.c index 18f7b89104..cd7c68f592 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -22,7 +22,6 @@ #include "libavutil/avassert.h" #include "libavutil/channel_layout.h" #include "libavutil/common.h" -#include "libavutil/eval.h" #include "libavutil/mem.h" #include "libavutil/pixdesc.h" #include "avfilter.h" @@ -937,43 +936,6 @@ int ff_default_query_formats(AVFilterContext *ctx) return 0; } -/* internal functions for parsing audio format arguments */ - -int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx) -{ - char *tail; - double srate = av_strtod(arg, &tail); - if (*tail || srate < 1 || (int)srate != srate || srate > INT_MAX) { - av_log(log_ctx, AV_LOG_ERROR, "Invalid sample rate '%s'\n", arg); - return AVERROR(EINVAL); - } - *ret = srate; - return 0; -} - -int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg, - void *log_ctx) -{ - AVChannelLayout chlayout = { 0 }; - int res; - - res = av_channel_layout_from_string(&chlayout, arg); - if (res < 0) { - av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg); - return AVERROR(EINVAL); - } - - if (chlayout.order == AV_CHANNEL_ORDER_UNSPEC && !nret) { - av_log(log_ctx, AV_LOG_ERROR, "Unknown channel layout '%s' is not supported.\n", arg); - return AVERROR(EINVAL); - } - *ret = chlayout; - if (nret) - *nret = chlayout.nb_channels; - - return 0; -} - static int check_list(void *log, const char *name, const AVFilterFormats *fmts) { unsigned i, j; diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 343bc0b330..eb312ab485 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -33,33 +33,6 @@ */ int ff_fmt_is_regular_yuv(enum AVPixelFormat fmt); -/* Functions to parse audio format arguments */ - -/** - * Parse a sample rate. - * - * @param ret unsigned integer pointer to where the value should be written - * @param arg string to parse - * @param log_ctx log context - * @return >= 0 in case of success, a negative AVERROR code on error - */ -av_warn_unused_result -int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx); - -/** - * Parse a channel layout or a corresponding integer representation. - * - * @param ret 64bit integer pointer to where the value should be written. - * @param nret integer pointer to the number of channels; - * if not NULL, then unknown channel layouts are accepted - * @param arg string to parse - * @param log_ctx log context - * @return >= 0 in case of success, a negative AVERROR code on error - */ -av_warn_unused_result -int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg, - void *log_ctx); - /** * Negotiate the media format, dimensions, etc of all inputs to a filter. * diff --git a/libavfilter/tests/formats.c b/libavfilter/tests/formats.c index ed1de24a4c..5cc3ca3371 100644 --- a/libavfilter/tests/formats.c +++ b/libavfilter/tests/formats.c @@ -19,6 +19,7 @@ */ #include "libavutil/channel_layout.h" +#include "libavfilter/audio.h" #include "libavfilter/formats.c" #undef printf