diff mbox series

[FFmpeg-devel] fftools/cmdutils: Allow expressions for opt_cpucount()

Message ID 20210717162159.17358-1-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel] fftools/cmdutils: Allow expressions for opt_cpucount() | expand

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

Michael Niedermayer July 17, 2021, 4:21 p.m. UTC
This allows for example
"-cpucount cpu/2" to use half the available CPUs

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 fftools/cmdutils.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

Comments

James Almer July 17, 2021, 5:22 p.m. UTC | #1
On 7/17/2021 1:21 PM, Michael Niedermayer wrote:
> This allows for example
> "-cpucount cpu/2" to use half the available CPUs
> 
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>   fftools/cmdutils.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
> index 6e875104fd..a902354669 100644
> --- a/fftools/cmdutils.c
> +++ b/fftools/cmdutils.c
> @@ -859,11 +859,12 @@ 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},
> +    AVOption opts[] = {
> +        {"count", NULL, 0, AV_OPT_TYPE_INT, { .i64 = -1}, -1, INT_MAX, 0, "val"},
> +        {"cpu", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = -1}, 0, 0, 0, "val"},
>           {NULL},
>       };
> -    static const AVClass class = {
> +    const AVClass class = {
>           .class_name = "cpucount",
>           .item_name  = av_default_item_name,
>           .option     = opts,
> @@ -871,6 +872,8 @@ int opt_cpucount(void *optctx, const char *opt, const char *arg)
>       };
>       const AVClass *pclass = &class;
>   
> +    opts[1].default_val.i64 = av_cpu_count();

You could set this directly as the default value instead of -1 above.

Should be ok either way.

> +
>       ret = av_opt_eval_int(&pclass, opts, arg, &count);
>   
>       if (!ret) {
>
James Almer July 17, 2021, 7:25 p.m. UTC | #2
On 7/17/2021 2:22 PM, James Almer wrote:
> On 7/17/2021 1:21 PM, Michael Niedermayer wrote:
>> This allows for example
>> "-cpucount cpu/2" to use half the available CPUs
>>
>> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>> ---
>>   fftools/cmdutils.c | 9 ++++++---
>>   1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
>> index 6e875104fd..a902354669 100644
>> --- a/fftools/cmdutils.c
>> +++ b/fftools/cmdutils.c
>> @@ -859,11 +859,12 @@ 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},
>> +    AVOption opts[] = {
>> +        {"count", NULL, 0, AV_OPT_TYPE_INT, { .i64 = -1}, -1, 
>> INT_MAX, 0, "val"},
>> +        {"cpu", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = -1}, 0, 0, 0, 
>> "val"},
>>           {NULL},
>>       };
>> -    static const AVClass class = {
>> +    const AVClass class = {
>>           .class_name = "cpucount",
>>           .item_name  = av_default_item_name,
>>           .option     = opts,
>> @@ -871,6 +872,8 @@ int opt_cpucount(void *optctx, const char *opt, 
>> const char *arg)
>>       };
>>       const AVClass *pclass = &class;
>> +    opts[1].default_val.i64 = av_cpu_count();
> 
> You could set this directly as the default value instead of -1 above.
> 
> Should be ok either way.

Actually, the "cpu" constant should be documented.

> 
>> +
>>       ret = av_opt_eval_int(&pclass, opts, arg, &count);
>>       if (!ret) {
>>
>
diff mbox series

Patch

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 6e875104fd..a902354669 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -859,11 +859,12 @@  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},
+    AVOption opts[] = {
+        {"count", NULL, 0, AV_OPT_TYPE_INT, { .i64 = -1}, -1, INT_MAX, 0, "val"},
+        {"cpu", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = -1}, 0, 0, 0, "val"},
         {NULL},
     };
-    static const AVClass class = {
+    const AVClass class = {
         .class_name = "cpucount",
         .item_name  = av_default_item_name,
         .option     = opts,
@@ -871,6 +872,8 @@  int opt_cpucount(void *optctx, const char *opt, const char *arg)
     };
     const AVClass *pclass = &class;
 
+    opts[1].default_val.i64 = av_cpu_count();
+
     ret = av_opt_eval_int(&pclass, opts, arg, &count);
 
     if (!ret) {