History

lavu/opt: extend AVOptionRange by extra values

AVOptionRange is not flexible enough to store AV_OPT_TYPE_IMAGE_SIZE ranges. Current implementation can only store pixel count. This patch aims to keep backward compatibility and extend AVOptionRange with possibility to store width/height ranges.

Lukasz Marek committed 12 years ago

Commit eaed4da1 parent fd2bcfc4 files · +81 −10Browse files

Unified · Split

4 files
  1. doc/APIchanges +4 −0
  2. libavutil/opt.c +11 −3
  3. libavutil/opt.h +65 −6
  4. libavutil/version.h +1 −1
doc/APIchanges+4−0
@@ -15,6 +15,10 @@ libavutil: 2012-10-22 · 14 unmodified lines
15 15
16API changes, most recent first:16API changes, most recent first:
17 17
182014-04-xx - xxxxxxx - lavu 52.72.100 - opt.h
19 Add AV_OPT_MULTI_COMPONENT_RANGE define to allow return
20 multi-component option ranges.
21
182014-03-xx - xxxxxxx - lavu 52.70.100 - mem.h222014-03-xx - xxxxxxx - lavu 52.70.100 - mem.h
19 Add av_dynarray_add_nofree() function.23 Add av_dynarray_add_nofree() function.
20 24
libavutil/opt.c+11−3
@@ -1514,6 +1514,7 @@ void *av_opt_ptr(const AVClass *class, void *obj, const char *name) · 1513 unmodified lines
1514 1514
1515int av_opt_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)1515int av_opt_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
1516{1516{
1517 int ret;
1517 const AVClass *c = *(AVClass**)obj;1518 const AVClass *c = *(AVClass**)obj;
1518 int (*callback)(AVOptionRanges **, void *obj, const char *key, int flags) = NULL;1519 int (*callback)(AVOptionRanges **, void *obj, const char *key, int flags) = NULL;
1519 1520
@@ -1523,7 +1524,13 @@ int av_opt_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, · 3 unmodified lines
1523 if (!callback)1524 if (!callback)
1524 callback = av_opt_query_ranges_default;1525 callback = av_opt_query_ranges_default;
1525 1526
1526 return callback(ranges_arg, obj, key, flags);1527 ret = callback(ranges_arg, obj, key, flags);
1528 if (ret >= 0) {
1529 if (!(flags & AV_OPT_MULTI_COMPONENT_RANGE))
1530 ret = 1;
1531 (*ranges_arg)->nb_components = ret;
1532 }
1533 return ret;
1527}1534}
1528 1535
1529int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)1536int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
@@ -1544,6 +1551,7 @@ int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const ch · 14 unmodified lines
1544 ranges->range = range_array;1551 ranges->range = range_array;
1545 ranges->range[0] = range;1552 ranges->range[0] = range;
1546 ranges->nb_ranges = 1;1553 ranges->nb_ranges = 1;
1554 ranges->nb_components = 1;
1547 range->is_range = 1;1555 range->is_range = 1;
1548 range->value_min = field->min;1556 range->value_min = field->min;
1549 range->value_max = field->max;1557 range->value_max = field->max;
@@ -1587,7 +1595,7 @@ int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const ch · 37 unmodified lines
1587 }1595 }
1588 1596
1589 *ranges_arg = ranges;1597 *ranges_arg = ranges;
1590 return 0;1598 return 1;
1591fail:1599fail:
1592 av_free(ranges);1600 av_free(ranges);
1593 av_free(range);1601 av_free(range);
@@ -1600,7 +1608,7 @@ void av_opt_freep_ranges(AVOptionRanges **rangesp) · 6 unmodified lines
1600 int i;1608 int i;
1601 AVOptionRanges *ranges = *rangesp;1609 AVOptionRanges *ranges = *rangesp;
1602 1610
1603 for (i = 0; i < ranges->nb_ranges; i++) {1611 for (i = 0; i < ranges->nb_ranges * ranges->nb_components; i++) {
1604 AVOptionRange *range = ranges->range[i];1612 AVOptionRange *range = ranges->range[i];
1605 av_freep(&range->str);1613 av_freep(&range->str);
1606 av_freep(&ranges->range[i]);1614 av_freep(&ranges->range[i]);
libavutil/opt.h+65−6
@@ -313,17 +313,67 @@ typedef struct AVOption { · 312 unmodified lines
313 */313 */
314typedef struct AVOptionRange {314typedef struct AVOptionRange {
315 const char *str;315 const char *str;
316 double value_min, value_max; ///< For string ranges this represents the min/max length, for dimensions this represents the min/max pixel count316 /**
317 double component_min, component_max; ///< For string this represents the unicode range for chars, 0-127 limits to ASCII317 * Value range.
318 int is_range; ///< if set to 1 the struct encodes a range, if set to 0 a single value318 * For string ranges this represents the min/max length.
319 * For dimensions this represents the min/max pixel count or width/height in multi-component case.
320 */
321 double value_min, value_max;
322 /**
323 * Value's component range.
324 * For string this represents the unicode range for chars, 0-127 limits to ASCII.
325 */
326 double component_min, component_max;
327 /**
328 * Range flag.
329 * If set to 1 the struct encodes a range, if set to 0 a single value.
330 */
331 int is_range;
319} AVOptionRange;332} AVOptionRange;
320 333
321/**334/**
322 * List of AVOptionRange structs335 * List of AVOptionRange structs.
323 */336 */
324typedef struct AVOptionRanges {337typedef struct AVOptionRanges {
338 /**
339 * Array of option ranges.
340 *
341 * Most of option types use just one component.
342 * Following describes multi-component option types:
343 *
344 * AV_OPT_TYPE_IMAGE_SIZE:
345 * component index 0: range of pixel count (width * height).
346 * component index 1: range of width.
347 * component index 2: range of height.
348 *
349 * @note To obtain multi-component version of this structure, user must
350 * provide AV_OPT_MULTI_COMPONENT_RANGE to av_opt_query_ranges or
351 * av_opt_query_ranges_default function.
352 *
353 * Multi-component range can be read as in following example:
354 *
355 * @code
356 * int range_index, component_index;
357 * AVOptionRanges *ranges;
358 * AVOptionRange *range[3]; //may require more than 3 in the future.
359 * av_opt_query_ranges(&ranges, obj, key, AV_OPT_MULTI_COMPONENT_RANGE);
360 * for (range_index = 0; range_index < ranges->nb_ranges; range_index++) {
361 * for (component_index = 0; component_index < ranges->nb_components; component_index++)
362 * range[component_index] = ranges->range[ranges->nb_ranges * component_index + range_index];
363 * //do something with range here.
364 * }
365 * av_opt_freep_ranges(&ranges);
366 * @endcode
367 */
325 AVOptionRange **range;368 AVOptionRange **range;
369 /**
370 * Number of ranges per component.
371 */
326 int nb_ranges;372 int nb_ranges;
373 /**
374 * Number of componentes.
375 */
376 int nb_components;
327} AVOptionRanges;377} AVOptionRanges;
328 378
329 379
@@ -558,6 +608,13 @@ int av_opt_eval_q (void *obj, const AVOption *o, const char *val, AVRational · 228 unmodified lines
558 */608 */
559#define AV_OPT_SEARCH_FAKE_OBJ 0x0002609#define AV_OPT_SEARCH_FAKE_OBJ 0x0002
560 610
611/**
612 * Allows av_opt_query_ranges and av_opt_query_ranges_default to return more than
613 * one component for certain option types.
614 * @see AVOptionRanges for details.
615 */
616#define AV_OPT_MULTI_COMPONENT_RANGE 0x1000
617
561/**618/**
562 * Look for an option in an object. Consider only options which619 * Look for an option in an object. Consider only options which
563 * have all the specified flags set.620 * have all the specified flags set.
@@ -739,10 +796,11 @@ void av_opt_freep_ranges(AVOptionRanges **ranges); · 175 unmodified lines
739 *796 *
740 * @param flags is a bitmask of flags, undefined flags should not be set and should be ignored797 * @param flags is a bitmask of flags, undefined flags should not be set and should be ignored
741 * AV_OPT_SEARCH_FAKE_OBJ indicates that the obj is a double pointer to a AVClass instead of a full instance798 * AV_OPT_SEARCH_FAKE_OBJ indicates that the obj is a double pointer to a AVClass instead of a full instance
799 * AV_OPT_MULTI_COMPONENT_RANGE indicates that function may return more than one component, @see AVOptionRanges
742 *800 *
743 * The result must be freed with av_opt_freep_ranges.801 * The result must be freed with av_opt_freep_ranges.
744 *802 *
745 * @return >= 0 on success, a negative errro code otherwise803 * @return number of compontents returned on success, a negative errro code otherwise
746 */804 */
747int av_opt_query_ranges(AVOptionRanges **, void *obj, const char *key, int flags);805int av_opt_query_ranges(AVOptionRanges **, void *obj, const char *key, int flags);
748 806
@@ -754,10 +812,11 @@ int av_opt_query_ranges(AVOptionRanges **, void *obj, const char *key, int flags · 5 unmodified lines
754 *812 *
755 * @param flags is a bitmask of flags, undefined flags should not be set and should be ignored813 * @param flags is a bitmask of flags, undefined flags should not be set and should be ignored
756 * AV_OPT_SEARCH_FAKE_OBJ indicates that the obj is a double pointer to a AVClass instead of a full instance814 * AV_OPT_SEARCH_FAKE_OBJ indicates that the obj is a double pointer to a AVClass instead of a full instance
815 * AV_OPT_MULTI_COMPONENT_RANGE indicates that function may return more than one component, @see AVOptionRanges
757 *816 *
758 * The result must be freed with av_opt_free_ranges.817 * The result must be freed with av_opt_free_ranges.
759 *818 *
760 * @return >= 0 on success, a negative errro code otherwise819 * @return number of compontents returned on success, a negative errro code otherwise
761 */820 */
762int av_opt_query_ranges_default(AVOptionRanges **, void *obj, const char *key, int flags);821int av_opt_query_ranges_default(AVOptionRanges **, void *obj, const char *key, int flags);
763 822
libavutil/version.h+1−1
@@ -56,7 +56,7 @@ · 55 unmodified lines
56 */56 */
57 57
58#define LIBAVUTIL_VERSION_MAJOR 5258#define LIBAVUTIL_VERSION_MAJOR 52
59#define LIBAVUTIL_VERSION_MINOR 7159#define LIBAVUTIL_VERSION_MINOR 72
60#define LIBAVUTIL_VERSION_MICRO 10060#define LIBAVUTIL_VERSION_MICRO 100
61 61
62#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \62#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

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