History

avutil/opt: add an unsigned option type

James Almer committed 2 years ago

Commit d0532901 parent 9902fc56 files · +63 −4Browse files

Unified · Split

6 files
  1. doc/APIchanges +3 −0
  2. libavutil/opt.c +17 −0
  3. libavutil/opt.h +2 −0
  4. libavutil/tests/opt.c +9 −0
  5. libavutil/version.h +2 −2
  6. tests/ref/fate/opt +30 −2
doc/APIchanges+3−0
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07 · 1 unmodified line
22
33 API changes, most recent first:
44
5+2024-05-04 - xxxxxxxxxx - lavu 59.17.100 - opt.h
6+ Add AV_OPT_TYPE_UINT and av_opt_eval_uint().
7+
58 2024-04-24 - 8616cfe0890 - lavu 59.16.100 - opt.h
69 Add AV_OPT_SERIALIZE_SEARCH_CHILDREN.
710
libavutil/opt.c+17−0
@@ -62,6 +62,7 @@ static const size_t opt_elem_size[] = { · 61 unmodified lines
6262 [AV_OPT_TYPE_FLAGS] = sizeof(unsigned),
6363 [AV_OPT_TYPE_INT] = sizeof(int),
6464 [AV_OPT_TYPE_INT64] = sizeof(int64_t),
65+ [AV_OPT_TYPE_UINT] = sizeof(unsigned),
6566 [AV_OPT_TYPE_UINT64] = sizeof(uint64_t),
6667 [AV_OPT_TYPE_DOUBLE] = sizeof(double),
6768 [AV_OPT_TYPE_FLOAT] = sizeof(float),
@@ -166,6 +167,9 @@ static int read_number(const AVOption *o, const void *dst, double *num, int *den · 98 unmodified lines
166167 case AV_OPT_TYPE_INT:
167168 *intnum = *(int *)dst;
168169 return 0;
170+ case AV_OPT_TYPE_UINT:
171+ *intnum = *(unsigned int *)dst;
172+ return 0;
169173 case AV_OPT_TYPE_DURATION:
170174 case AV_OPT_TYPE_INT64:
171175 case AV_OPT_TYPE_UINT64:
@@ -219,6 +223,7 @@ static int write_number(void *obj, const AVOption *o, void *dst, double num, int · 47 unmodified lines
219223 case AV_OPT_TYPE_BOOL:
220224 case AV_OPT_TYPE_FLAGS:
221225 case AV_OPT_TYPE_INT:
226+ case AV_OPT_TYPE_UINT:
222227 *(int *)dst = llrint(num / den) * intnum;
223228 break;
224229 case AV_OPT_TYPE_DURATION:
@@ -319,6 +324,7 @@ static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **d · 94 unmodified lines
319324 opt->type == AV_OPT_TYPE_UINT64 || \
320325 opt->type == AV_OPT_TYPE_CONST || \
321326 opt->type == AV_OPT_TYPE_FLAGS || \
327+ opt->type == AV_OPT_TYPE_UINT || \
322328 opt->type == AV_OPT_TYPE_INT) \
323329 ? opt->default_val.i64 \
324330 : opt->default_val.dbl)
@@ -605,6 +611,7 @@ static int opt_set_elem(void *obj, void *target_obj, const AVOption *o, · 280 unmodified lines
605611 return set_string_binary(obj, o, val, dst);
606612 case AV_OPT_TYPE_FLAGS:
607613 case AV_OPT_TYPE_INT:
614+ case AV_OPT_TYPE_UINT:
608615 case AV_OPT_TYPE_INT64:
609616 case AV_OPT_TYPE_UINT64:
610617 case AV_OPT_TYPE_FLOAT:
@@ -767,6 +774,7 @@ int av_opt_eval_ ## name(void *obj, const AVOption *o, \ · 156 unmodified lines
767774
768775 OPT_EVAL_NUMBER(flags, AV_OPT_TYPE_FLAGS, int)
769776 OPT_EVAL_NUMBER(int, AV_OPT_TYPE_INT, int)
777+OPT_EVAL_NUMBER(uint, AV_OPT_TYPE_UINT, unsigned)
770778 OPT_EVAL_NUMBER(int64, AV_OPT_TYPE_INT64, int64_t)
771779 OPT_EVAL_NUMBER(float, AV_OPT_TYPE_FLOAT, float)
772780 OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE, double)
@@ -997,6 +1005,9 @@ static int opt_get_elem(const AVOption *o, uint8_t **pbuf, size_t buf_len, · 224 unmodified lines
9971005 case AV_OPT_TYPE_INT:
9981006 ret = snprintf(*pbuf, buf_len, "%d", *(int *)dst);
9991007 break;
1008+ case AV_OPT_TYPE_UINT:
1009+ ret = snprintf(*pbuf, buf_len, "%u", *(unsigned *)dst);
1010+ break;
10001011 case AV_OPT_TYPE_INT64:
10011012 ret = snprintf(*pbuf, buf_len, "%"PRId64, *(int64_t *)dst);
10021013 break;
@@ -1444,6 +1455,7 @@ static void log_type(void *av_log_obj, const AVOption *o, · 441 unmodified lines
14441455 [AV_OPT_TYPE_FLAGS] = "<flags>",
14451456 [AV_OPT_TYPE_INT] = "<int>",
14461457 [AV_OPT_TYPE_INT64] = "<int64>",
1458+ [AV_OPT_TYPE_UINT] = "<unsigned>",
14471459 [AV_OPT_TYPE_UINT64] = "<uint64>",
14481460 [AV_OPT_TYPE_DOUBLE] = "<double>",
14491461 [AV_OPT_TYPE_FLOAT] = "<float>",
@@ -1515,6 +1527,7 @@ static void log_default(void *obj, void *av_log_obj, const AVOption *opt) · 65 unmodified lines
15151527 av_log(av_log_obj, AV_LOG_INFO, "%s", buf);
15161528 break;
15171529 }
1530+ case AV_OPT_TYPE_UINT:
15181531 case AV_OPT_TYPE_INT:
15191532 case AV_OPT_TYPE_UINT64:
15201533 case AV_OPT_TYPE_INT64: {
@@ -1600,6 +1613,7 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit, · 79 unmodified lines
16001613 if (av_opt_query_ranges(&r, obj, opt->name, AV_OPT_SEARCH_FAKE_OBJ) >= 0) {
16011614 switch (opt->type) {
16021615 case AV_OPT_TYPE_INT:
1616+ case AV_OPT_TYPE_UINT:
16031617 case AV_OPT_TYPE_INT64:
16041618 case AV_OPT_TYPE_UINT64:
16051619 case AV_OPT_TYPE_DOUBLE:
@@ -1676,6 +1690,7 @@ void av_opt_set_defaults2(void *s, int mask, int flags) · 70 unmodified lines
16761690 case AV_OPT_TYPE_BOOL:
16771691 case AV_OPT_TYPE_FLAGS:
16781692 case AV_OPT_TYPE_INT:
1693+ case AV_OPT_TYPE_UINT:
16791694 case AV_OPT_TYPE_INT64:
16801695 case AV_OPT_TYPE_UINT64:
16811696 case AV_OPT_TYPE_DURATION:
@@ -2177,6 +2192,7 @@ int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const ch · 495 unmodified lines
21772192 switch (field->type) {
21782193 case AV_OPT_TYPE_BOOL:
21792194 case AV_OPT_TYPE_INT:
2195+ case AV_OPT_TYPE_UINT:
21802196 case AV_OPT_TYPE_INT64:
21812197 case AV_OPT_TYPE_UINT64:
21822198 case AV_OPT_TYPE_PIXEL_FMT:
@@ -2281,6 +2297,7 @@ int av_opt_is_set_to_default(void *obj, const AVOption *o) · 98 unmodified lines
22812297 case AV_OPT_TYPE_PIXEL_FMT:
22822298 case AV_OPT_TYPE_SAMPLE_FMT:
22832299 case AV_OPT_TYPE_INT:
2300+ case AV_OPT_TYPE_UINT:
22842301 case AV_OPT_TYPE_DURATION:
22852302 case AV_OPT_TYPE_INT64:
22862303 case AV_OPT_TYPE_UINT64:
libavutil/opt.h+2−0
@@ -260,6 +260,7 @@ enum AVOptionType{ · 259 unmodified lines
260260 AV_OPT_TYPE_COLOR,
261261 AV_OPT_TYPE_BOOL,
262262 AV_OPT_TYPE_CHLAYOUT,
263+ AV_OPT_TYPE_UINT,
263264
264265 /**
265266 * May be combined with another regular option type to declare an array
@@ -883,6 +884,7 @@ int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDiction · 617 unmodified lines
883884 */
884885 int av_opt_eval_flags (void *obj, const AVOption *o, const char *val, int *flags_out);
885886 int av_opt_eval_int (void *obj, const AVOption *o, const char *val, int *int_out);
887+int av_opt_eval_uint (void *obj, const AVOption *o, const char *val, unsigned *uint_out);
886888 int av_opt_eval_int64 (void *obj, const AVOption *o, const char *val, int64_t *int64_out);
887889 int av_opt_eval_float (void *obj, const AVOption *o, const char *val, float *float_out);
888890 int av_opt_eval_double(void *obj, const AVOption *o, const char *val, double *double_out);
libavutil/tests/opt.c+9−0
@@ -32,6 +32,7 @@ typedef struct TestContext { · 31 unmodified lines
3232 const AVClass *class;
3333 struct ChildContext *child;
3434 int num;
35+ int unum;
3536 int toggle;
3637 char *string;
3738 int flags;
@@ -87,6 +88,7 @@ static const AVOptionArrayDef array_dict = { · 49 unmodified lines
8788
8889 static const AVOption test_options[]= {
8990 {"num", "set num", OFFSET(num), AV_OPT_TYPE_INT, { .i64 = 0 }, -1, 100, 1 },
91+ {"unum", "set unum", OFFSET(unum), AV_OPT_TYPE_UINT, { .i64 = 1U << 31 }, 0, 1U << 31, 1 },
9092 {"toggle", "set toggle", OFFSET(toggle), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, 1 },
9193 {"rational", "set rational", OFFSET(rational), AV_OPT_TYPE_RATIONAL, { .dbl = 1 }, 0, 10, 1 },
9294 {"string", "set string", OFFSET(string), AV_OPT_TYPE_STRING, { .str = "default" }, CHAR_MIN, CHAR_MAX, 1 },
@@ -186,6 +188,7 @@ int main(void) · 93 unmodified lines
186188 av_opt_set_defaults(&test_ctx);
187189
188190 printf("num=%d\n", test_ctx.num);
191+ printf("unum=%u\n", test_ctx.unum);
189192 printf("toggle=%d\n", test_ctx.toggle);
190193 printf("string=%s\n", test_ctx.string);
191194 printf("escape=%s\n", test_ctx.escape);
@@ -386,6 +389,12 @@ int main(void) · 194 unmodified lines
386389 "num=-1",
387390 "num=-2",
388391 "num=101",
392+ "unum=bogus",
393+ "unum=44",
394+ "unum=44.4",
395+ "unum=-1",
396+ "unum=2147483648",
397+ "unum=2147483649",
389398 "num64=bogus",
390399 "num64=44",
391400 "num64=44.4",
libavutil/version.h+2−2
@@ -79,8 +79,8 @@ · 78 unmodified lines
7979 */
8080
8181 #define LIBAVUTIL_VERSION_MAJOR 59
82−#define LIBAVUTIL_VERSION_MINOR 16
83−#define LIBAVUTIL_VERSION_MICRO 101
82+#define LIBAVUTIL_VERSION_MINOR 17
83+#define LIBAVUTIL_VERSION_MICRO 100
8484
8585 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
8686 LIBAVUTIL_VERSION_MINOR, \
tests/ref/fate/opt+30−2
@@ -1,5 +1,6 @@
11 Testing default values
22 num=0
3+unum=2147483648
34 toggle=1
45 string=default
56 escape=\=,
@@ -25,6 +26,7 @@ array_dict[0]: k01 v,01 · 19 unmodified lines
2526 array_dict[1]: k10 v=1:0
2627 TestContext AVOptions:
2728 -num <int> E.......... set num (from -1 to 100) (default 0)
29+ -unum <unsigned> E.......... set unum (from 0 to 2.14748e+09) (default 2147483648)
2830 -toggle <int> E.......... set toggle (from 0 to 1) (default 1)
2931 -rational <rational> E.......... set rational (from 0 to 10) (default 1/1)
3032 -string <string> E.......... set string (default "default")
@@ -57,6 +59,7 @@ TestContext AVOptions: · 26 unmodified lines
5759
5860 Testing av_opt_is_set_to_default()
5961 name: num default:1 error:
62+name: unum default:0 error:
6063 name: toggle default:0 error:
6164 name: rational default:0 error:
6265 name: string default:0 error:
@@ -87,6 +90,7 @@ name: array_int default:0 error: · 24 unmodified lines
8790 name: array_str default:0 error:
8891 name:array_dict default:0 error:
8992 name: num default:1 error:
93+name: unum default:1 error:
9094 name: toggle default:1 error:
9195 name: rational default:1 error:
9296 name: string default:1 error:
@@ -119,6 +123,7 @@ name:array_dict default:1 error: · 26 unmodified lines
119123
120124 Testing av_opt_get/av_opt_set()
121125 name: num get: 0 set: OK get: 0 OK
126+name: unum get: 2147483648 set: OK get: 2147483648 OK
122127 name: toggle get: 1 set: OK get: 1 OK
123128 name: rational get: 1/1 set: OK get: 1/1 OK
124129 name: string get: default set: OK get: default OK
@@ -150,8 +155,9 @@ array_dict=NULL; nb_array_dict=0 · 25 unmodified lines
150155 av_opt_get("array_dict") -> NULL
151156
152157 Test av_opt_serialize()
153−num=0,toggle=1,rational=1/1,string=default,escape=\\\=\,,flags=0x00000001,size=200x300,pix_fmt=0bgr,sample_fmt=s16,video_rate=25/1,duration=0.001,color=0xffc0cbff,cl=hexagonal,bin=62696E00,bin1=,bin2=,num64=4294967296,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-),array_int=,array_str=str0|str\\|1|str\\\\2,array_dict=k00\=v\\\\\\\\00:k01\=v\\\,01\,k10\=v\\\\\=1\\\\:0
158+num=0,unum=2147483648,toggle=1,rational=1/1,string=default,escape=\\\=\,,flags=0x00000001,size=200x300,pix_fmt=0bgr,sample_fmt=s16,video_rate=25/1,duration=0.001,color=0xffc0cbff,cl=hexagonal,bin=62696E00,bin1=,bin2=,num64=4294967296,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-),array_int=,array_str=str0|str\\|1|str\\\\2,array_dict=k00\=v\\\\\\\\00:k01\=v\\\,01\,k10\=v\\\\\=1\\\\:0
154159 Setting entry with key 'num' to value '0'
160+Setting entry with key 'unum' to value '2147483648'
155161 Setting entry with key 'toggle' to value '1'
156162 Setting entry with key 'rational' to value '1/1'
157163 Setting entry with key 'string' to value 'default'
@@ -178,7 +184,7 @@ Setting entry with key 'dict2' to value 'happy=\:-)' · 20 unmodified lines
178184 Setting entry with key 'array_int' to value ''
179185 Setting entry with key 'array_str' to value 'str0|str\|1|str\\2'
180186 Setting entry with key 'array_dict' to value 'k00=v\\\\00:k01=v\,01,k10=v\\=1\\:0'
181−num=0,toggle=1,rational=1/1,string=default,escape=\\\=\,,flags=0x00000001,size=200x300,pix_fmt=0bgr,sample_fmt=s16,video_rate=25/1,duration=0.001,color=0xffc0cbff,cl=hexagonal,bin=62696E00,bin1=,bin2=,num64=4294967296,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-),array_int=,array_str=str0|str\\|1|str\\\\2,array_dict=k00\=v\\\\\\\\00:k01\=v\\\,01\,k10\=v\\\\\=1\\\\:0
187+num=0,unum=2147483648,toggle=1,rational=1/1,string=default,escape=\\\=\,,flags=0x00000001,size=200x300,pix_fmt=0bgr,sample_fmt=s16,video_rate=25/1,duration=0.001,color=0xffc0cbff,cl=hexagonal,bin=62696E00,bin1=,bin2=,num64=4294967296,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-),array_int=,array_str=str0|str\\|1|str\\\\2,array_dict=k00\=v\\\\\\\\00:k01\=v\\\,01\,k10\=v\\\\\=1\\\\:0
182188 child_num=0,flt=0.333333,dbl=0.333333,array_int=
183189
184190 Testing av_set_options_string()
@@ -359,6 +365,28 @@ Setting options string 'num=101' · 174 unmodified lines
359365 Setting entry with key 'num' to value '101'
360366 Value 101.000000 for parameter 'num' out of range [-1 - 100]
361367 Error 'num=101'
368+Setting options string 'unum=bogus'
369+Setting entry with key 'unum' to value 'bogus'
370+Undefined constant or missing '(' in 'bogus'
371+Unable to parse option value "bogus"
372+Error 'unum=bogus'
373+Setting options string 'unum=44'
374+Setting entry with key 'unum' to value '44'
375+OK 'unum=44'
376+Setting options string 'unum=44.4'
377+Setting entry with key 'unum' to value '44.4'
378+OK 'unum=44.4'
379+Setting options string 'unum=-1'
380+Setting entry with key 'unum' to value '-1'
381+Value -1.000000 for parameter 'unum' out of range [0 - 2.14748e+09]
382+Error 'unum=-1'
383+Setting options string 'unum=2147483648'
384+Setting entry with key 'unum' to value '2147483648'
385+OK 'unum=2147483648'
386+Setting options string 'unum=2147483649'
387+Setting entry with key 'unum' to value '2147483649'
388+Value 2147483649.000000 for parameter 'unum' out of range [0 - 2.14748e+09]
389+Error 'unum=2147483649'
362390 Setting options string 'num64=bogus'
363391 Setting entry with key 'num64' to value 'bogus'
364392 Undefined constant or missing '(' in 'bogus'

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t