From f4bfdf789335e690dd92c9ee85974c338429103a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 15 Aug 2024 22:00:50 +0200 Subject: [PATCH] lavfi: move ff_parse_pixel_format() to vf_format, its only caller The only thing this function does beyond calling av_get_pix_fmt() is falling back onto parsing the argument as a number. No other filters should need to do this. --- libavfilter/formats.c | 15 --------------- libavfilter/internal.h | 11 ----------- libavfilter/vf_format.c | 17 ++++++++++++++++- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/libavfilter/formats.c b/libavfilter/formats.c index 15099ac545..18f7b89104 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -939,21 +939,6 @@ int ff_default_query_formats(AVFilterContext *ctx) /* internal functions for parsing audio format arguments */ -int ff_parse_pixel_format(enum AVPixelFormat *ret, const char *arg, void *log_ctx) -{ - char *tail; - int pix_fmt = av_get_pix_fmt(arg); - if (pix_fmt == AV_PIX_FMT_NONE) { - pix_fmt = strtol(arg, &tail, 0); - if (*tail || !av_pix_fmt_desc_get(pix_fmt)) { - av_log(log_ctx, AV_LOG_ERROR, "Invalid pixel format '%s'\n", arg); - return AVERROR(EINVAL); - } - } - *ret = pix_fmt; - return 0; -} - int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx) { char *tail; diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 4938612593..343bc0b330 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -35,17 +35,6 @@ int ff_fmt_is_regular_yuv(enum AVPixelFormat fmt); /* Functions to parse audio format arguments */ -/** - * Parse a pixel format. - * - * @param ret pixel format 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_pixel_format(enum AVPixelFormat *ret, const char *arg, void *log_ctx); - /** * Parse a sample rate. * diff --git a/libavfilter/vf_format.c b/libavfilter/vf_format.c index 2b88b10f65..83deff7190 100644 --- a/libavfilter/vf_format.c +++ b/libavfilter/vf_format.c @@ -86,6 +86,21 @@ static av_cold int invert_formats(AVFilterFormats **fmts, return 0; } +static int parse_pixel_format(enum AVPixelFormat *ret, const char *arg, void *log_ctx) +{ + char *tail; + int pix_fmt = av_get_pix_fmt(arg); + if (pix_fmt == AV_PIX_FMT_NONE) { + pix_fmt = strtol(arg, &tail, 0); + if (*tail || !av_pix_fmt_desc_get(pix_fmt)) { + av_log(log_ctx, AV_LOG_ERROR, "Invalid pixel format '%s'\n", arg); + return AVERROR(EINVAL); + } + } + *ret = pix_fmt; + return 0; +} + static av_cold int init(AVFilterContext *ctx) { FormatContext *s = ctx->priv; @@ -96,7 +111,7 @@ static av_cold int init(AVFilterContext *ctx) sep = strchr(cur, '|'); if (sep && *sep) *sep++ = 0; - if ((ret = ff_parse_pixel_format(&pix_fmt, cur, ctx)) < 0 || + if ((ret = parse_pixel_format(&pix_fmt, cur, ctx)) < 0 || (ret = ff_add_format(&s->formats, pix_fmt)) < 0) return ret; }