diff mbox series

[FFmpeg-devel] cmdutils: simplify opt_cpucount()

Message ID 20210717002616.5906-1-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel] cmdutils: simplify opt_cpucount()
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

James Almer July 17, 2021, 12:26 a.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 fftools/cmdutils.c | 27 +++++++--------------------
 1 file changed, 7 insertions(+), 20 deletions(-)

Comments

Michael Niedermayer July 17, 2021, 4:24 p.m. UTC | #1
On Fri, Jul 16, 2021 at 09:26:16PM -0300, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  fftools/cmdutils.c | 27 +++++++--------------------
>  1 file changed, 7 insertions(+), 20 deletions(-)

Posted an alternative patch which goes the opposit direction and
make use of the features of the eval stuff

thx

[...]
diff mbox series

Patch

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 6e875104fd..a3b6b78d50 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -856,28 +856,15 @@  int opt_cpuflags(void *optctx, const char *opt, const char *arg)
 
 int opt_cpucount(void *optctx, const char *opt, const char *arg)
 {
-    int ret;
-    int count;
-
-    static const AVOption opts[] = {
-        {"count", NULL, 0, AV_OPT_TYPE_INT, { .i64 = -1}, -1, INT_MAX, NULL},
-        {NULL},
-    };
-    static const AVClass class = {
-        .class_name = "cpucount",
-        .item_name  = av_default_item_name,
-        .option     = opts,
-        .version    = LIBAVUTIL_VERSION_INT,
-    };
-    const AVClass *pclass = &class;
-
-    ret = av_opt_eval_int(&pclass, opts, arg, &count);
+    char *tail;
+    int64_t count;
 
-    if (!ret) {
-        av_force_cpu_count(count);
-    }
+    count = strtol(arg, &tail, 10);
+    if (*tail || count < -1 || count > INT_MAX)
+        return AVERROR(EINVAL);
 
-    return ret;
+    av_force_cpu_count(count);
+    return 0;
 }
 
 int opt_loglevel(void *optctx, const char *opt, const char *arg)