diff mbox series

[FFmpeg-devel,v4,11/22] avutil/opt: document AVOptionRange min_value > max_value

Message ID 20220325141041.1748-12-dcnieho@gmail.com
State Superseded, archived
Headers show
Series avdevice (mostly dshow) enhancements | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Diederick C. Niehorster March 25, 2022, 2:10 p.m. UTC
AVOptionRange needs a way to encode that an option is not set. Here i
provide a documentation solution. When a range is invalid (value_min >
value_max), it should be considered unset/value not available.

When querying a range of formats of an avdevice, sometimes for a given
format the queried option is not available. This is not an error as the
user is asking for a valid capability, it just doesn't always apply to
all the matching formats of the device. This cannot be communicated
through a single special value (like 0 or -1) as that has the same
problem asany special value solution. Documenting that an invalid range
means value not available allows communicating this situation without
adding a field to the AVOptionRange struct.

This further documents that an AVOptionRange denotes a single value when
value_min == value_max, and a range only when value_max > value_min.
This makes the is_range field superfluous.

Signed-off-by: Diederick Niehorster <dcnieho@gmail.com>
---
 libavutil/opt.c | 2 +-
 libavutil/opt.h | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavutil/opt.c b/libavutil/opt.c
index 8ffb10449b..ebffbb2f36 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -1979,9 +1979,9 @@  int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const ch
     ranges->range[0] = range;
     ranges->nb_ranges = 1;
     ranges->nb_components = 1;
-    range->is_range = 1;
     range->value_min = field->min;
     range->value_max = field->max;
+    range->is_range = field->max > field->min;
 
     switch (field->type) {
     case AV_OPT_TYPE_BOOL:
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 461b5d3b6b..4e7d7433e9 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -316,6 +316,11 @@  typedef struct AVOptionRange {
      * Value range.
      * For string ranges this represents the min/max length.
      * For dimensions this represents the min/max pixel count or width/height in multi-component case.
+     * If value_min  < value_max, the struct encodes a range.
+     * If value_min == value_max, the struct encodes a single value.
+     * If value_min  > value_max, the range is empty (a value is not available).
+     *                            Good sentinel values to use when a range is empty
+     *                            are value_min=0, value_max=-1, but this is not required.
      */
     double value_min, value_max;
     /**