Commit Graph

301 Commits

Author SHA1 Message Date
James Almer 4e069ba80a avutil/opt: free the temporary layout in av_opt_is_set_to_default()
Signed-off-by: James Almer <jamrial@gmail.com>
2024-05-07 20:11:42 -03:00
James Almer ae0293ee41 avutil/opt: propagate av_dict_copy() errors in av_opt_{get,set}_dict_val()
Signed-off-by: James Almer <jamrial@gmail.com>
2024-05-07 20:11:42 -03:00
James Almer 9614efc258 avutil/opt: don't set a channel layout if the option is flagged as read only
Signed-off-by: James Almer <jamrial@gmail.com>
2024-05-07 20:11:42 -03:00
James Almer d053290d8d avutil/opt: add an unsigned option type
Signed-off-by: James Almer <jamrial@gmail.com>
2024-05-04 21:17:40 -03:00
James Almer 8616cfe089 avutil/opt: add support for children objects in av_opt_serialize
Signed-off-by: James Almer <jamrial@gmail.com>
2024-04-23 23:54:46 -03:00
Andreas Rheinhardt 790f793844 avutil/common: Don't auto-include mem.h
There are lots of files that don't need it: The number of object
files that actually need it went down from 2011 to 884 here.

Keep it for external users in order to not cause breakages.

Also improve the other headers a bit while just at it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-31 00:08:43 +01:00
Andreas Rheinhardt ba7980d9c0 avutil/opt: Avoid av_uninit
GCC 9-13 do not emit warnings for this at all optimization
levels even when -Wmaybe-uninitialized is not disabled.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-30 05:06:28 +01:00
Andreas Rheinhardt c85477f78d avutil/opt: Don't cast when the result might be misaligned
A pointer conversion is UB if the resulting pointer is not
correctly aligned for the resultant type, even if no
load/store is ever performed through that pointer (C11 6.3.2.3 (7)).

This may happen in opt_copy_elem(), because the pointers are
converted even when they belong to a type that does not guarantee
sufficient alignment.

Fix this by deferring the cast after having checked the type.
Also make the casts -Wcast-qual safe and avoid an indirection
for src.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-28 03:08:01 +01:00
Andreas Rheinhardt aa7d6520e6 avutil/opt: Avoid av_strdup(NULL)
It is not documented to be safe and in any case it is nonsense:
Currently av_strdup(NULL) returns NULL and in order to distinguish
this from a genuine allocation failure, opt_copy_elem()
checked afterwards whether src was actually NULL. But then one
can simply check in advance whether one should call av_strdup()
at all.
set_string() was even worse and returned ENOMEM in case the value
to be duplicated is NULL; this only worked because
av_opt_set_defaults2() does not check the return value at all
(given that it can't propagate it).

These two places account for 389114 of 390356 av_strdup(NULL)
calls during one FATE run.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-03-28 03:08:01 +01:00
Anton Khirnov efe4478778 lavu/opt: add array options 2024-03-08 07:36:15 +01:00
Anton Khirnov c259f80315 lavu/opt: factor per-type dispatch out of av_opt_copy()
Will be useful in following commits.
2024-03-08 07:24:50 +01:00
Anton Khirnov 2cd89194b0 libavutil/opt: rework figuring out option sizes
Replace the opt_size() function, currently only called from
av_opt_copy(), with
* a constant array of element sizes
* a function that signals whether an option type is POD (i.e.
  memcpyable) or not

Will be useful in following commits.
2024-03-08 07:24:50 +01:00
Anton Khirnov 85797886fe lavu/opt: factor per-type dispatch out of av_opt_set()
Will be useful in following commits.
2024-03-08 07:24:50 +01:00
Anton Khirnov a1be08ba05 lavu/opt: factor per-type dispatch out of av_opt_get()
Will be useful in following commits.
2024-03-08 07:24:50 +01:00
James Almer 65ddc74988 avutil: remove deprecated FF_API_OLD_CHANNEL_LAYOUT
Signed-off-by: James Almer <jamrial@gmail.com>
2024-03-07 08:53:30 -03:00
Anton Khirnov 200f82e3f8 lavu/opt: get rid of useless read_number() calls
The option type is known and fixed for all these, so reading the value
directly is simpler and more clear.
2024-03-01 16:57:24 +01:00
Anton Khirnov 1ffa657a03 lavu/opt: simplify error handling in get_number() 2024-03-01 16:57:24 +01:00
Anton Khirnov 84ba46fa5e lavu/opt: drop an always-NULL argument to get_number() 2024-03-01 16:57:24 +01:00
Anton Khirnov 9fabdd64b2 lavu/opt: drop useless handling of NULL return from get_bool_name()
That function always returns an actual string.
2024-03-01 16:57:24 +01:00
Anton Khirnov 333cc9bff8 lavu/opt: factor out printing option default from opt_list() 2024-03-01 16:57:24 +01:00
Anton Khirnov 8904f35133 lavu/opt: simplify printing option type in opt_list() 2024-03-01 16:57:24 +01:00
Andreas Rheinhardt f705b8b5b4 avutil/opt: Use correct function pointer type
av_get_sample/pix_fmt() return their respective enums
and are therefore not of the type int (*)(const char*),
yet they are called as-if they were of this type.
This works in practice, but is actually undefined behaviour.

With Clang 17 UBSan these violations are flagged, affecting lots
of tests. The number of failing tests went down from 3363 to 164
here with this patch.

Reviewed-by: Mark Thompson <sw@jkqxz.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-02-25 02:19:18 +01:00
Andreas Rheinhardt ed56ca856c avutil/opt: Fix AV_OPT_TYPE_CONST default value
It uses the int64_t instead of the double member.

(This code can currently not be reached: av_opt_get() calls
av_opt_find2() with NULL as unit in which case AV_OPT_TYPE_CONST
options are never returned, leading av_opt_get() to always
return AVERROR_OPTION_NOT_FOUND when searching for AV_OPT_TYPE_CONST*.
For the same reason the code read_number() will never be called
from get_number() when searching for an option of type
AV_OPT_TYPE_CONST. The other callers of read_number() also only
call it with types other than AV_OPT_TYPE_CONST.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-02-07 10:23:00 +01:00
Anton Khirnov 5c36f4ef84 lavu/opt: use AV_DICT_MULTIKEY in av_opt_set_dict2()
If the dictionary provided on input contains multiple entries for an
option (relevant for flags modifying the previous value with '+' or
'-') and the option is not found in the target object, only the last
entry would be returned to the caller.

Pass AV_DICT_MULTIKEY to av_dict_set() to make sure all such entries are
returned.
2023-01-31 09:08:03 +01:00
Marvin Scholz 81747b5259 avutil: use av_dict_iterate
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-12-07 10:22:02 +01:00
Andreas Rheinhardt 8d7d52721a avutil/opt: Combine multiple av_log statements
Reviewed-by: Thilo Borgmann <thilo.borgmann@mail.de>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-08-03 21:09:24 +02:00
James Almer 327efa6633 avutil/opt: add missing case for AV_OPT_TYPE_CHLAYOUT in av_opt_free()
Fixes potential memleaks for existing options of this type.

Signed-off-by: James Almer <jamrial@gmail.com>
2022-03-18 18:59:03 -03:00
Anton Khirnov f423497b45 lavu: support AVChannelLayout AVOptions
Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2022-03-15 09:42:29 -03:00
Soft Works 99a49f9147 avutil/opt: fix mis-alignment of option and constant values for filter help
Before:

overlay AVOptions:
  x                 <string>     ..FV....... set the x expression (default "0")
  y                 <string>     ..FV....... set the y expression (default "0")
  eof_action        <int>        ..FV....... Action to take when encountering EOF from secondary input  (from 0 to 2) (default repeat)
     repeat          0            ..FV....... Repeat the previous frame.
     endall          1            ..FV....... End both streams.
     pass            2            ..FV....... Pass through the main input.
  eval              <int>        ..FV....... specify when to evaluate expressions (from 0 to 1) (default frame)

After:
a
overlay AVOptions:
   x                 <string>     ..FV....... set the x expression (default "0")
   y                 <string>     ..FV....... set the y expression (default "0")
   eof_action        <int>        ..FV....... Action to take when encountering EOF from secondary input  (from 0 to 2) (default repeat)
     repeat          0            ..FV....... Repeat the previous frame.
     endall          1            ..FV....... End both streams.
     pass            2            ..FV....... Pass through the main input.
   eval              <int>        ..FV....... specify when to evaluate expressions (from 0 to 1) (default frame)

Signed-off-by: softworkz <softworkz@hotmail.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
2021-11-13 19:55:32 +01:00
Zhao Zhili 9fd2b39428 avutil/opt: handle whole range of int64_t in av_opt_get_int
Make get_int/set_int symetric. The int64_t to double to int64_t
conversion is unprecise for large value.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2021-11-11 13:14:58 +01:00
Andreas Rheinhardt 386a4989df avutil/opt: Remove outdated version check
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-27 05:42:48 +02:00
Andreas Rheinhardt 3df34e7bf7 avutil/opt: Simplify av_opt_set_dict2()
Make it clearer that the ordinary exit always returns 0.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-20 00:25:16 +02:00
Andreas Rheinhardt 3ba1bbf8d0 avutil/opt: Also warn for deprecated named constants
Intended for the "truncated" AVCodecContext flag.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-20 00:24:12 +02:00
Andreas Rheinhardt 7e03d962a4 avutil/opt: Check directly for av_dict_copy() failure
av_dict_copy() returned void when this code was written.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-06-08 12:52:50 +02:00
James Almer 0bf3a7361d avutil: remove deprecated AVClass.child_class_next
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 11:48:04 -03:00
Limin Wang 48235c8263 avutil/opt: add AV_OPT_FLAG_DEPRECATED option
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-12-05 09:00:53 +08:00
Limin Wang 200c9b1c96 avutil/opt: check return value of av_bprint_finalize()
Reviewed-by:   Nicolas George <george@nsup.org>
Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
2020-07-02 21:12:37 +08:00
Anton Khirnov 1b4a98b029 lavu/opt: add a more general child class iteration API
Use opaque iteration state instead of the previous child class. This
mirrors similar changes done in lavf/lavc.

Deprecate the av_opt_child_class_next() API.
2020-06-10 12:36:42 +02:00
Marton Balint af9e622776 avutil/opt: add AV_OPT_FLAG_CHILD_CONSTS
This will be used for AVCodecContext->profile. By specifying constants in the
encoders we won't have to use the common AVCodecContext options table and
different encoders can use the same profile name even with different values.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-05-22 22:16:52 +02:00
Marton Balint 6847affcb7 avutil/opt: only skip evaluation for rational options
Fixes problems when non-rational options were set using rational expressions,
causing rounding errors and the option range limits not to be enforced
properly.

ffmpeg -f lavfi -i "sine=r=96000/2"

This caused an assertion failure with assert level 2.

Signed-off-by: Marton Balint <cus@passwd.hu>
2020-05-01 17:22:58 +02:00
Andreas Rheinhardt a500b975a8 avutil/opt: Don't use NULL for %s string in a log message
If one calls av_opt_set() with an incorrect string to set the value of
an option of type AV_OPT_TYPE_VIDEO_RATE, the given string is used in a
log message via %s. This also happens when the string is actually a
nullpointer in which case using it for %s is forbidden.

This commit changes this by erroring out early in case of a nullpointer.

This also fixes a warning from GCC 9.2:
"‘%s’ directive argument is null [-Wformat-overflow=]"

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-04-01 04:09:18 +02:00
Jun Zhao 3c8da7b982 libavutil/opt: fix memory leak after av_dict_parse_string fail
In case of failure, all the successfully set entries are stored in
*pm. We need to manually free the created dictionary to avoid
memory leak.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2020-01-04 09:05:23 +08:00
Marton Balint 5edacc4609 avutil/opt: add full support for AV_OPT_TYPE_DICT
Now it is possible to set them from a string, to serialize them and to use a
default value.

Signed-off-by: Marton Balint <cus@passwd.hu>
2019-12-27 21:52:21 +01:00
Paul B Mahol c109dfc1b1 avutil/opt: print runtime flag too 2019-10-14 11:28:54 +02:00
Andreas Rheinhardt 25a501b528 avutil/opt: Fix type specifier
This bug has been introduced in 9e0a071e.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-09-22 18:16:38 +02:00
Soft Works 9e0a071ede avutil/opt: Print out numeric values of option constants
It's often not obvious how option constants relate to numerical values.
Defaults are sometimes printed as numbers and from/to are always printed as numbers.
Printing the numeric values of options constants avoids this confusion.
It also allows to see which constants are equivalent.

Before this patch:

  -segment_list_type <int>        E........ set the segment list type (from -1 to 4) (default -1)
     flat                         E........ flat format
     csv                          E........ csv format
     ext                          E........ extended format
     ffconcat                     E........ ffconcat format
     m3u8                         E........ M3U8 format
     hls                          E........ Apple HTTP Live Streaming compatible

Afterwards:

  -segment_list_type <int>        E........ set the segment list type (from -1 to 4) (default -1)
     flat            0            E........ flat format
     csv             1            E........ csv format
     ext             3            E........ extended format
     ffconcat        4            E........ ffconcat format
     m3u8            2            E........ M3U8 format
     hls             2            E........ Apple HTTP Live Streaming compatible

Signed-off-by: softworkz <softworkz@hotmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-09-20 23:26:34 +02:00
Soft Works 667df60b14 avutil/opt: Fix printing integer option defaults
Integer values should not be printed using format specifier '%g' which leads to inexact display in case of higher values.

Before this patch:
  -trans_color       <int>        .D.V..... color value [...] (default 1.67772e+07)

Afterwards:
  -trans_color       <int>        .D.V..... color value [...] (default 16777215)

Signed-off-by: softworkz <softworkz@hotmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-09-20 23:26:34 +02:00
Marton Balint d40dc64173 avutil/opt: check for minimum and maximum values when setting AV_OPT_TYPE_DURATION fields
Signed-off-by: Marton Balint <cus@passwd.hu>
2018-10-07 20:26:29 +02:00
Clément Bœsch 5be0410cb3 lavu/opt: add AV_OPT_FLAG_DEPRECATED 2018-04-26 19:50:29 +02:00
Jun Zhao 7b5cf0a410 lavu/opt: add bit stream filter option dump support.
enable dump bit stream filter and update opt fate test ref.

Signed-off-by: Jun Zhao <mypopydev@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-03-16 02:09:59 +01:00