* [FFmpeg-devel] [PATCH 01/38] lavu/opt: cosmetics, change option flags to (1 << N) style
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 02/38] lavu/opt: cosmetics, move AV_OPT_FLAG_* out of AVOption Anton Khirnov
` (36 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
It is easier to read. Also, change their doxy comments to use the same
style.
---
libavutil/opt.h | 48 ++++++++++++++++++++++++++++++++++++------------
1 file changed, 36 insertions(+), 12 deletions(-)
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 461b5d3b6b..6ed3407b09 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -278,25 +278,49 @@ typedef struct AVOption {
double max; ///< maximum valid value for the option
int flags;
-#define AV_OPT_FLAG_ENCODING_PARAM 1 ///< a generic parameter which can be set by the user for muxing or encoding
-#define AV_OPT_FLAG_DECODING_PARAM 2 ///< a generic parameter which can be set by the user for demuxing or decoding
-#define AV_OPT_FLAG_AUDIO_PARAM 8
-#define AV_OPT_FLAG_VIDEO_PARAM 16
-#define AV_OPT_FLAG_SUBTITLE_PARAM 32
+
+/**
+ * A generic parameter which can be set by the user for muxing or encoding.
+ */
+#define AV_OPT_FLAG_ENCODING_PARAM (1 << 0)
+/**
+ * A generic parameter which can be set by the user for demuxing or decoding.
+ */
+#define AV_OPT_FLAG_DECODING_PARAM (1 << 1)
+#define AV_OPT_FLAG_AUDIO_PARAM (1 << 3)
+#define AV_OPT_FLAG_VIDEO_PARAM (1 << 4)
+#define AV_OPT_FLAG_SUBTITLE_PARAM (1 << 5)
/**
* The option is intended for exporting values to the caller.
*/
-#define AV_OPT_FLAG_EXPORT 64
+#define AV_OPT_FLAG_EXPORT (1 << 6)
/**
* The option may not be set through the AVOptions API, only read.
* This flag only makes sense when AV_OPT_FLAG_EXPORT is also set.
*/
-#define AV_OPT_FLAG_READONLY 128
-#define AV_OPT_FLAG_BSF_PARAM (1<<8) ///< a generic parameter which can be set by the user for bit stream filtering
-#define AV_OPT_FLAG_RUNTIME_PARAM (1<<15) ///< a generic parameter which can be set by the user at runtime
-#define AV_OPT_FLAG_FILTERING_PARAM (1<<16) ///< a generic parameter which can be set by the user for filtering
-#define AV_OPT_FLAG_DEPRECATED (1<<17) ///< set if option is deprecated, users should refer to AVOption.help text for more information
-#define AV_OPT_FLAG_CHILD_CONSTS (1<<18) ///< set if option constants can also reside in child objects
+#define AV_OPT_FLAG_READONLY (1 << 7)
+/**
+ * A generic parameter which can be set by the user for bit stream filtering.
+ */
+#define AV_OPT_FLAG_BSF_PARAM (1 << 8)
+
+/**
+ * A generic parameter which can be set by the user at runtime.
+ */
+#define AV_OPT_FLAG_RUNTIME_PARAM (1 << 15)
+/**
+ * A generic parameter which can be set by the user for filtering.
+ */
+#define AV_OPT_FLAG_FILTERING_PARAM (1 << 16)
+/**
+ * Set if option is deprecated, users should refer to AVOption.help text for
+ * more information.
+ */
+#define AV_OPT_FLAG_DEPRECATED (1 << 17)
+/**
+ * Set if option constants can also reside in child objects.
+ */
+#define AV_OPT_FLAG_CHILD_CONSTS (1 << 18)
//FIXME think about enc-audio, ... style flags
/**
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 02/38] lavu/opt: cosmetics, move AV_OPT_FLAG_* out of AVOption
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 01/38] lavu/opt: cosmetics, change option flags to (1 << N) style Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 03/38] lavu/opt: document AVOption.flags Anton Khirnov
` (35 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
Also drop an obsolete FIXME.
---
libavutil/opt.h | 69 ++++++++++++++++++++++++-------------------------
1 file changed, 34 insertions(+), 35 deletions(-)
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 6ed3407b09..36e28249ee 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -245,40 +245,6 @@ enum AVOptionType{
AV_OPT_TYPE_CHLAYOUT,
};
-/**
- * AVOption
- */
-typedef struct AVOption {
- const char *name;
-
- /**
- * short English help text
- * @todo What about other languages?
- */
- const char *help;
-
- /**
- * The offset relative to the context structure where the option
- * value is stored. It should be 0 for named constants.
- */
- int offset;
- enum AVOptionType type;
-
- /**
- * the default value for scalar options
- */
- union {
- int64_t i64;
- double dbl;
- const char *str;
- /* TODO those are unused now */
- AVRational q;
- } default_val;
- double min; ///< minimum valid value for the option
- double max; ///< maximum valid value for the option
-
- int flags;
-
/**
* A generic parameter which can be set by the user for muxing or encoding.
*/
@@ -321,7 +287,40 @@ typedef struct AVOption {
* Set if option constants can also reside in child objects.
*/
#define AV_OPT_FLAG_CHILD_CONSTS (1 << 18)
-//FIXME think about enc-audio, ... style flags
+
+/**
+ * AVOption
+ */
+typedef struct AVOption {
+ const char *name;
+
+ /**
+ * short English help text
+ * @todo What about other languages?
+ */
+ const char *help;
+
+ /**
+ * The offset relative to the context structure where the option
+ * value is stored. It should be 0 for named constants.
+ */
+ int offset;
+ enum AVOptionType type;
+
+ /**
+ * the default value for scalar options
+ */
+ union {
+ int64_t i64;
+ double dbl;
+ const char *str;
+ /* TODO those are unused now */
+ AVRational q;
+ } default_val;
+ double min; ///< minimum valid value for the option
+ double max; ///< maximum valid value for the option
+
+ int flags;
/**
* The logical unit to which the option belongs. Non-constant
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 03/38] lavu/opt: document AVOption.flags
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 01/38] lavu/opt: cosmetics, change option flags to (1 << N) style Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 02/38] lavu/opt: cosmetics, move AV_OPT_FLAG_* out of AVOption Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 04/38] lavu/opt: cosmetics, group (un)init and management functions together Anton Khirnov
` (34 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
---
libavutil/opt.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 36e28249ee..d72d65052f 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -320,6 +320,9 @@ typedef struct AVOption {
double min; ///< minimum valid value for the option
double max; ///< maximum valid value for the option
+ /**
+ * A combination of AV_OPT_FLAG_*.
+ */
int flags;
/**
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 04/38] lavu/opt: cosmetics, group (un)init and management functions together
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (2 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 03/38] lavu/opt: document AVOption.flags Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 05/38] lavu/opt: cosmetics, group option setting function together Anton Khirnov
` (33 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
---
libavutil/opt.h | 336 +++++++++++++++++++++++++-----------------------
1 file changed, 173 insertions(+), 163 deletions(-)
diff --git a/libavutil/opt.h b/libavutil/opt.h
index d72d65052f..e2b6ba1f35 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -402,15 +402,9 @@ typedef struct AVOptionRanges {
} AVOptionRanges;
/**
- * Show the obj options.
- *
- * @param req_flags requested flags for the options to show. Show only the
- * options for which it is opt->flags & req_flags.
- * @param rej_flags rejected flags for the options to show. Show only the
- * options for which it is !(opt->flags & req_flags).
- * @param av_log_obj log context to use for showing the options
+ * @defgroup opt_mng AVOption (un)initialization and inspection.
+ * @{
*/
-int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags);
/**
* Set the values of all AVOption fields to their default values.
@@ -430,161 +424,37 @@ void av_opt_set_defaults(void *s);
*/
void av_opt_set_defaults2(void *s, int mask, int flags);
-/**
- * Parse the key/value pairs list in opts. For each key/value pair
- * found, stores the value in the field in ctx that is named like the
- * key. ctx must be an AVClass context, storing is done using
- * AVOptions.
- *
- * @param opts options string to parse, may be NULL
- * @param key_val_sep a 0-terminated list of characters used to
- * separate key from value
- * @param pairs_sep a 0-terminated list of characters used to separate
- * two pairs from each other
- * @return the number of successfully set key/value pairs, or a negative
- * value corresponding to an AVERROR code in case of error:
- * AVERROR(EINVAL) if opts cannot be parsed,
- * the error code issued by av_opt_set() if a key/value pair
- * cannot be set
- */
-int av_set_options_string(void *ctx, const char *opts,
- const char *key_val_sep, const char *pairs_sep);
-
-/**
- * Parse the key-value pairs list in opts. For each key=value pair found,
- * set the value of the corresponding option in ctx.
- *
- * @param ctx the AVClass object to set options on
- * @param opts the options string, key-value pairs separated by a
- * delimiter
- * @param shorthand a NULL-terminated array of options names for shorthand
- * notation: if the first field in opts has no key part,
- * the key is taken from the first element of shorthand;
- * then again for the second, etc., until either opts is
- * finished, shorthand is finished or a named option is
- * found; after that, all options must be named
- * @param key_val_sep a 0-terminated list of characters used to separate
- * key from value, for example '='
- * @param pairs_sep a 0-terminated list of characters used to separate
- * two pairs from each other, for example ':' or ','
- * @return the number of successfully set key=value pairs, or a negative
- * value corresponding to an AVERROR code in case of error:
- * AVERROR(EINVAL) if opts cannot be parsed,
- * the error code issued by av_set_string3() if a key/value pair
- * cannot be set
- *
- * Options names must use only the following characters: a-z A-Z 0-9 - . / _
- * Separators must use characters distinct from option names and from each
- * other.
- */
-int av_opt_set_from_string(void *ctx, const char *opts,
- const char *const *shorthand,
- const char *key_val_sep, const char *pairs_sep);
/**
* Free all allocated objects in obj.
*/
void av_opt_free(void *obj);
/**
- * Check whether a particular flag is set in a flags field.
+ * Iterate over all AVOptions belonging to obj.
*
- * @param field_name the name of the flag field option
- * @param flag_name the name of the flag to check
- * @return non-zero if the flag is set, zero if the flag isn't set,
- * isn't of the right type, or the flags field doesn't exist.
+ * @param obj an AVOptions-enabled struct or a double pointer to an
+ * AVClass describing it.
+ * @param prev result of the previous call to av_opt_next() on this object
+ * or NULL
+ * @return next AVOption or NULL
*/
-int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name);
+const AVOption *av_opt_next(const void *obj, const AVOption *prev);
/**
- * Set all the options from a given dictionary on an object.
+ * Iterate over AVOptions-enabled children of obj.
*
- * @param obj a struct whose first element is a pointer to AVClass
- * @param options options to process. This dictionary will be freed and replaced
- * by a new one containing all options not found in obj.
- * Of course this new dictionary needs to be freed by caller
- * with av_dict_free().
- *
- * @return 0 on success, a negative AVERROR if some option was found in obj,
- * but could not be set.
- *
- * @see av_dict_copy()
+ * @param prev result of a previous call to this function or NULL
+ * @return next AVOptions-enabled child or NULL
*/
-int av_opt_set_dict(void *obj, struct AVDictionary **options);
-
+void *av_opt_child_next(void *obj, void *prev);
/**
- * Set all the options from a given dictionary on an object.
+ * Iterate over potential AVOptions-enabled children of parent.
*
- * @param obj a struct whose first element is a pointer to AVClass
- * @param options options to process. This dictionary will be freed and replaced
- * by a new one containing all options not found in obj.
- * Of course this new dictionary needs to be freed by caller
- * with av_dict_free().
- * @param search_flags A combination of AV_OPT_SEARCH_*.
- *
- * @return 0 on success, a negative AVERROR if some option was found in obj,
- * but could not be set.
- *
- * @see av_dict_copy()
- */
-int av_opt_set_dict2(void *obj, struct AVDictionary **options, int search_flags);
-
-/**
- * Extract a key-value pair from the beginning of a string.
- *
- * @param ropts pointer to the options string, will be updated to
- * point to the rest of the string (one of the pairs_sep
- * or the final NUL)
- * @param key_val_sep a 0-terminated list of characters used to separate
- * key from value, for example '='
- * @param pairs_sep a 0-terminated list of characters used to separate
- * two pairs from each other, for example ':' or ','
- * @param flags flags; see the AV_OPT_FLAG_* values below
- * @param rkey parsed key; must be freed using av_free()
- * @param rval parsed value; must be freed using av_free()
- *
- * @return >=0 for success, or a negative value corresponding to an
- * AVERROR code in case of error; in particular:
- * AVERROR(EINVAL) if no key is present
- *
- */
-int av_opt_get_key_value(const char **ropts,
- const char *key_val_sep, const char *pairs_sep,
- unsigned flags,
- char **rkey, char **rval);
-
-enum {
-
- /**
- * Accept to parse a value without a key; the key will then be returned
- * as NULL.
- */
- AV_OPT_FLAG_IMPLICIT_KEY = 1,
-};
-
-/**
- * @defgroup opt_eval_funcs Evaluating option strings
- * @{
- * This group of functions can be used to evaluate option strings
- * and get numbers out of them. They do the same thing as av_opt_set(),
- * except the result is written into the caller-supplied pointer.
- *
- * @param obj a struct whose first element is a pointer to AVClass.
- * @param o an option for which the string is to be evaluated.
- * @param val string to be evaluated.
- * @param *_out value of the string will be written here.
- *
- * @return 0 on success, a negative number on failure.
- */
-int av_opt_eval_flags (void *obj, const AVOption *o, const char *val, int *flags_out);
-int av_opt_eval_int (void *obj, const AVOption *o, const char *val, int *int_out);
-int av_opt_eval_int64 (void *obj, const AVOption *o, const char *val, int64_t *int64_out);
-int av_opt_eval_float (void *obj, const AVOption *o, const char *val, float *float_out);
-int av_opt_eval_double(void *obj, const AVOption *o, const char *val, double *double_out);
-int av_opt_eval_q (void *obj, const AVOption *o, const char *val, AVRational *q_out);
-/**
- * @}
+ * @param iter a pointer where iteration state is stored.
+ * @return AVClass corresponding to next potential child or NULL
*/
+const AVClass *av_opt_child_class_iterate(const AVClass *parent, void **iter);
#define AV_OPT_SEARCH_CHILDREN (1 << 0) /**< Search in possible children of the
given object first. */
@@ -659,31 +529,171 @@ const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
int opt_flags, int search_flags, void **target_obj);
/**
- * Iterate over all AVOptions belonging to obj.
+ * Show the obj options.
*
- * @param obj an AVOptions-enabled struct or a double pointer to an
- * AVClass describing it.
- * @param prev result of the previous call to av_opt_next() on this object
- * or NULL
- * @return next AVOption or NULL
+ * @param req_flags requested flags for the options to show. Show only the
+ * options for which it is opt->flags & req_flags.
+ * @param rej_flags rejected flags for the options to show. Show only the
+ * options for which it is !(opt->flags & req_flags).
+ * @param av_log_obj log context to use for showing the options
*/
-const AVOption *av_opt_next(const void *obj, const AVOption *prev);
+int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags);
/**
- * Iterate over AVOptions-enabled children of obj.
+ * Extract a key-value pair from the beginning of a string.
+ *
+ * @param ropts pointer to the options string, will be updated to
+ * point to the rest of the string (one of the pairs_sep
+ * or the final NUL)
+ * @param key_val_sep a 0-terminated list of characters used to separate
+ * key from value, for example '='
+ * @param pairs_sep a 0-terminated list of characters used to separate
+ * two pairs from each other, for example ':' or ','
+ * @param flags flags; see the AV_OPT_FLAG_* values below
+ * @param rkey parsed key; must be freed using av_free()
+ * @param rval parsed value; must be freed using av_free()
+ *
+ * @return >=0 for success, or a negative value corresponding to an
+ * AVERROR code in case of error; in particular:
+ * AVERROR(EINVAL) if no key is present
*
- * @param prev result of a previous call to this function or NULL
- * @return next AVOptions-enabled child or NULL
*/
-void *av_opt_child_next(void *obj, void *prev);
+int av_opt_get_key_value(const char **ropts,
+ const char *key_val_sep, const char *pairs_sep,
+ unsigned flags,
+ char **rkey, char **rval);
+
+enum {
+
+ /**
+ * Accept to parse a value without a key; the key will then be returned
+ * as NULL.
+ */
+ AV_OPT_FLAG_IMPLICIT_KEY = 1,
+};
/**
- * Iterate over potential AVOptions-enabled children of parent.
- *
- * @param iter a pointer where iteration state is stored.
- * @return AVClass corresponding to next potential child or NULL
+ * @}
+ */
+
+/**
+ * Parse the key/value pairs list in opts. For each key/value pair
+ * found, stores the value in the field in ctx that is named like the
+ * key. ctx must be an AVClass context, storing is done using
+ * AVOptions.
+ *
+ * @param opts options string to parse, may be NULL
+ * @param key_val_sep a 0-terminated list of characters used to
+ * separate key from value
+ * @param pairs_sep a 0-terminated list of characters used to separate
+ * two pairs from each other
+ * @return the number of successfully set key/value pairs, or a negative
+ * value corresponding to an AVERROR code in case of error:
+ * AVERROR(EINVAL) if opts cannot be parsed,
+ * the error code issued by av_opt_set() if a key/value pair
+ * cannot be set
+ */
+int av_set_options_string(void *ctx, const char *opts,
+ const char *key_val_sep, const char *pairs_sep);
+
+/**
+ * Parse the key-value pairs list in opts. For each key=value pair found,
+ * set the value of the corresponding option in ctx.
+ *
+ * @param ctx the AVClass object to set options on
+ * @param opts the options string, key-value pairs separated by a
+ * delimiter
+ * @param shorthand a NULL-terminated array of options names for shorthand
+ * notation: if the first field in opts has no key part,
+ * the key is taken from the first element of shorthand;
+ * then again for the second, etc., until either opts is
+ * finished, shorthand is finished or a named option is
+ * found; after that, all options must be named
+ * @param key_val_sep a 0-terminated list of characters used to separate
+ * key from value, for example '='
+ * @param pairs_sep a 0-terminated list of characters used to separate
+ * two pairs from each other, for example ':' or ','
+ * @return the number of successfully set key=value pairs, or a negative
+ * value corresponding to an AVERROR code in case of error:
+ * AVERROR(EINVAL) if opts cannot be parsed,
+ * the error code issued by av_set_string3() if a key/value pair
+ * cannot be set
+ *
+ * Options names must use only the following characters: a-z A-Z 0-9 - . / _
+ * Separators must use characters distinct from option names and from each
+ * other.
+ */
+int av_opt_set_from_string(void *ctx, const char *opts,
+ const char *const *shorthand,
+ const char *key_val_sep, const char *pairs_sep);
+
+/**
+ * Check whether a particular flag is set in a flags field.
+ *
+ * @param field_name the name of the flag field option
+ * @param flag_name the name of the flag to check
+ * @return non-zero if the flag is set, zero if the flag isn't set,
+ * isn't of the right type, or the flags field doesn't exist.
+ */
+int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name);
+
+/**
+ * Set all the options from a given dictionary on an object.
+ *
+ * @param obj a struct whose first element is a pointer to AVClass
+ * @param options options to process. This dictionary will be freed and replaced
+ * by a new one containing all options not found in obj.
+ * Of course this new dictionary needs to be freed by caller
+ * with av_dict_free().
+ *
+ * @return 0 on success, a negative AVERROR if some option was found in obj,
+ * but could not be set.
+ *
+ * @see av_dict_copy()
+ */
+int av_opt_set_dict(void *obj, struct AVDictionary **options);
+
+
+/**
+ * Set all the options from a given dictionary on an object.
+ *
+ * @param obj a struct whose first element is a pointer to AVClass
+ * @param options options to process. This dictionary will be freed and replaced
+ * by a new one containing all options not found in obj.
+ * Of course this new dictionary needs to be freed by caller
+ * with av_dict_free().
+ * @param search_flags A combination of AV_OPT_SEARCH_*.
+ *
+ * @return 0 on success, a negative AVERROR if some option was found in obj,
+ * but could not be set.
+ *
+ * @see av_dict_copy()
+ */
+int av_opt_set_dict2(void *obj, struct AVDictionary **options, int search_flags);
+
+/**
+ * @defgroup opt_eval_funcs Evaluating option strings
+ * @{
+ * This group of functions can be used to evaluate option strings
+ * and get numbers out of them. They do the same thing as av_opt_set(),
+ * except the result is written into the caller-supplied pointer.
+ *
+ * @param obj a struct whose first element is a pointer to AVClass.
+ * @param o an option for which the string is to be evaluated.
+ * @param val string to be evaluated.
+ * @param *_out value of the string will be written here.
+ *
+ * @return 0 on success, a negative number on failure.
+ */
+int av_opt_eval_flags (void *obj, const AVOption *o, const char *val, int *flags_out);
+int av_opt_eval_int (void *obj, const AVOption *o, const char *val, int *int_out);
+int av_opt_eval_int64 (void *obj, const AVOption *o, const char *val, int64_t *int64_out);
+int av_opt_eval_float (void *obj, const AVOption *o, const char *val, float *float_out);
+int av_opt_eval_double(void *obj, const AVOption *o, const char *val, double *double_out);
+int av_opt_eval_q (void *obj, const AVOption *o, const char *val, AVRational *q_out);
+/**
+ * @}
*/
-const AVClass *av_opt_child_class_iterate(const AVClass *parent, void **iter);
/**
* @defgroup opt_set_funcs Option setting functions
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 05/38] lavu/opt: cosmetics, group option setting function together
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (3 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 04/38] lavu/opt: cosmetics, group (un)init and management functions together Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 06/38] lavu/opt: cosmetics, group option reading " Anton Khirnov
` (32 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
---
libavutil/opt.h | 102 +++++++++++++++++++++++++-----------------------
1 file changed, 54 insertions(+), 48 deletions(-)
diff --git a/libavutil/opt.h b/libavutil/opt.h
index e2b6ba1f35..6ed19888a5 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -576,6 +576,11 @@ enum {
* @}
*/
+/**
+ * @defgroup opt_write Setting and modifying option values
+ * @{
+ */
+
/**
* Parse the key/value pairs list in opts. For each key/value pair
* found, stores the value in the field in ctx that is named like the
@@ -627,16 +632,6 @@ int av_opt_set_from_string(void *ctx, const char *opts,
const char *const *shorthand,
const char *key_val_sep, const char *pairs_sep);
-/**
- * Check whether a particular flag is set in a flags field.
- *
- * @param field_name the name of the flag field option
- * @param flag_name the name of the flag to check
- * @return non-zero if the flag is set, zero if the flag isn't set,
- * isn't of the right type, or the flags field doesn't exist.
- */
-int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name);
-
/**
* Set all the options from a given dictionary on an object.
*
@@ -672,28 +667,23 @@ int av_opt_set_dict(void *obj, struct AVDictionary **options);
int av_opt_set_dict2(void *obj, struct AVDictionary **options, int search_flags);
/**
- * @defgroup opt_eval_funcs Evaluating option strings
- * @{
- * This group of functions can be used to evaluate option strings
- * and get numbers out of them. They do the same thing as av_opt_set(),
- * except the result is written into the caller-supplied pointer.
+ * Copy options from src object into dest object.
*
- * @param obj a struct whose first element is a pointer to AVClass.
- * @param o an option for which the string is to be evaluated.
- * @param val string to be evaluated.
- * @param *_out value of the string will be written here.
+ * The underlying AVClass of both src and dest must coincide. The guarantee
+ * below does not apply if this is not fulfilled.
*
- * @return 0 on success, a negative number on failure.
- */
-int av_opt_eval_flags (void *obj, const AVOption *o, const char *val, int *flags_out);
-int av_opt_eval_int (void *obj, const AVOption *o, const char *val, int *int_out);
-int av_opt_eval_int64 (void *obj, const AVOption *o, const char *val, int64_t *int64_out);
-int av_opt_eval_float (void *obj, const AVOption *o, const char *val, float *float_out);
-int av_opt_eval_double(void *obj, const AVOption *o, const char *val, double *double_out);
-int av_opt_eval_q (void *obj, const AVOption *o, const char *val, AVRational *q_out);
-/**
- * @}
+ * Options that require memory allocation (e.g. string or binary) are malloc'ed in dest object.
+ * Original memory allocated for such options is freed unless both src and dest options points to the same memory.
+ *
+ * Even on error it is guaranteed that allocated options from src and dest
+ * no longer alias each other afterwards; in particular calling av_opt_free()
+ * on both src and dest is safe afterwards if dest has been memdup'ed from src.
+ *
+ * @param dest Object to copy from
+ * @param src Object to copy into
+ * @return 0 on success, negative on error
*/
+int av_opt_copy(void *dest, const void *src);
/**
* @defgroup opt_set_funcs Option setting functions
@@ -761,6 +751,7 @@ int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, in
av_int_list_length(val, term) * sizeof(*(val)), flags))
/**
+ * @}
* @}
*/
@@ -805,6 +796,31 @@ int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDiction
/**
* @}
*/
+
+/**
+ * @defgroup opt_eval_funcs Evaluating option strings
+ * @{
+ * This group of functions can be used to evaluate option strings
+ * and get numbers out of them. They do the same thing as av_opt_set(),
+ * except the result is written into the caller-supplied pointer.
+ *
+ * @param obj a struct whose first element is a pointer to AVClass.
+ * @param o an option for which the string is to be evaluated.
+ * @param val string to be evaluated.
+ * @param *_out value of the string will be written here.
+ *
+ * @return 0 on success, a negative number on failure.
+ */
+int av_opt_eval_flags (void *obj, const AVOption *o, const char *val, int *flags_out);
+int av_opt_eval_int (void *obj, const AVOption *o, const char *val, int *int_out);
+int av_opt_eval_int64 (void *obj, const AVOption *o, const char *val, int64_t *int64_out);
+int av_opt_eval_float (void *obj, const AVOption *o, const char *val, float *float_out);
+int av_opt_eval_double(void *obj, const AVOption *o, const char *val, double *double_out);
+int av_opt_eval_q (void *obj, const AVOption *o, const char *val, AVRational *q_out);
+/**
+ * @}
+ */
+
/**
* Gets a pointer to the requested field in a struct.
* This function allows accessing a struct even when its fields are moved or
@@ -835,25 +851,6 @@ void av_opt_freep_ranges(AVOptionRanges **ranges);
*/
int av_opt_query_ranges(AVOptionRanges **, void *obj, const char *key, int flags);
-/**
- * Copy options from src object into dest object.
- *
- * The underlying AVClass of both src and dest must coincide. The guarantee
- * below does not apply if this is not fulfilled.
- *
- * Options that require memory allocation (e.g. string or binary) are malloc'ed in dest object.
- * Original memory allocated for such options is freed unless both src and dest options points to the same memory.
- *
- * Even on error it is guaranteed that allocated options from src and dest
- * no longer alias each other afterwards; in particular calling av_opt_free()
- * on both src and dest is safe afterwards if dest has been memdup'ed from src.
- *
- * @param dest Object to copy from
- * @param src Object to copy into
- * @return 0 on success, negative on error
- */
-int av_opt_copy(void *dest, const void *src);
-
/**
* Get a default list of allowed ranges for the given option.
*
@@ -896,6 +893,15 @@ int av_opt_is_set_to_default(void *obj, const AVOption *o);
*/
int av_opt_is_set_to_default_by_name(void *obj, const char *name, int search_flags);
+/**
+ * Check whether a particular flag is set in a flags field.
+ *
+ * @param field_name the name of the flag field option
+ * @param flag_name the name of the flag to check
+ * @return non-zero if the flag is set, zero if the flag isn't set,
+ * isn't of the right type, or the flags field doesn't exist.
+ */
+int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name);
#define AV_OPT_SERIALIZE_SKIP_DEFAULTS 0x00000001 ///< Serialize options that are not set to default values only.
#define AV_OPT_SERIALIZE_OPT_FLAGS_EXACT 0x00000002 ///< Serialize options that exactly match opt_flags only.
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 06/38] lavu/opt: cosmetics, group option reading function together
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (4 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 05/38] lavu/opt: cosmetics, group option setting function together Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 07/38] lavu/opt: simplify printing option type in opt_list() Anton Khirnov
` (31 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
---
libavutil/opt.h | 82 +++++++++++++++++++++++++++----------------------
1 file changed, 46 insertions(+), 36 deletions(-)
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 6ed19888a5..e34b8506f8 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -755,6 +755,11 @@ int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, in
* @}
*/
+/**
+ * @defgroup opt_read Reading option values
+ * @{
+ */
+
/**
* @defgroup opt_get_funcs Option getting functions
* @{
@@ -831,42 +836,6 @@ int av_opt_eval_q (void *obj, const AVOption *o, const char *val, AVRational
*/
void *av_opt_ptr(const AVClass *avclass, void *obj, const char *name);
-/**
- * Free an AVOptionRanges struct and set it to NULL.
- */
-void av_opt_freep_ranges(AVOptionRanges **ranges);
-
-/**
- * Get a list of allowed ranges for the given option.
- *
- * The returned list may depend on other fields in obj like for example profile.
- *
- * @param flags is a bitmask of flags, undefined flags should not be set and should be ignored
- * AV_OPT_SEARCH_FAKE_OBJ indicates that the obj is a double pointer to a AVClass instead of a full instance
- * AV_OPT_MULTI_COMPONENT_RANGE indicates that function may return more than one component, @see AVOptionRanges
- *
- * The result must be freed with av_opt_freep_ranges.
- *
- * @return number of compontents returned on success, a negative errro code otherwise
- */
-int av_opt_query_ranges(AVOptionRanges **, void *obj, const char *key, int flags);
-
-/**
- * Get a default list of allowed ranges for the given option.
- *
- * This list is constructed without using the AVClass.query_ranges() callback
- * and can be used as fallback from within the callback.
- *
- * @param flags is a bitmask of flags, undefined flags should not be set and should be ignored
- * AV_OPT_SEARCH_FAKE_OBJ indicates that the obj is a double pointer to a AVClass instead of a full instance
- * AV_OPT_MULTI_COMPONENT_RANGE indicates that function may return more than one component, @see AVOptionRanges
- *
- * The result must be freed with av_opt_free_ranges.
- *
- * @return number of compontents returned on success, a negative errro code otherwise
- */
-int av_opt_query_ranges_default(AVOptionRanges **, void *obj, const char *key, int flags);
-
/**
* Check if given option is set to its default value.
*
@@ -926,6 +895,47 @@ int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
*/
int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer,
const char key_val_sep, const char pairs_sep);
+
+/**
+ * @}
+ */
+
+/**
+ * Free an AVOptionRanges struct and set it to NULL.
+ */
+void av_opt_freep_ranges(AVOptionRanges **ranges);
+
+/**
+ * Get a list of allowed ranges for the given option.
+ *
+ * The returned list may depend on other fields in obj like for example profile.
+ *
+ * @param flags is a bitmask of flags, undefined flags should not be set and should be ignored
+ * AV_OPT_SEARCH_FAKE_OBJ indicates that the obj is a double pointer to a AVClass instead of a full instance
+ * AV_OPT_MULTI_COMPONENT_RANGE indicates that function may return more than one component, @see AVOptionRanges
+ *
+ * The result must be freed with av_opt_freep_ranges.
+ *
+ * @return number of compontents returned on success, a negative errro code otherwise
+ */
+int av_opt_query_ranges(AVOptionRanges **, void *obj, const char *key, int flags);
+
+/**
+ * Get a default list of allowed ranges for the given option.
+ *
+ * This list is constructed without using the AVClass.query_ranges() callback
+ * and can be used as fallback from within the callback.
+ *
+ * @param flags is a bitmask of flags, undefined flags should not be set and should be ignored
+ * AV_OPT_SEARCH_FAKE_OBJ indicates that the obj is a double pointer to a AVClass instead of a full instance
+ * AV_OPT_MULTI_COMPONENT_RANGE indicates that function may return more than one component, @see AVOptionRanges
+ *
+ * The result must be freed with av_opt_free_ranges.
+ *
+ * @return number of compontents returned on success, a negative errro code otherwise
+ */
+int av_opt_query_ranges_default(AVOptionRanges **, void *obj, const char *key, int flags);
+
/**
* @}
*/
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 07/38] lavu/opt: simplify printing option type in opt_list()
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (5 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 06/38] lavu/opt: cosmetics, group option reading " Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 08/38] lavu/opt: factor out printing option default from opt_list() Anton Khirnov
` (30 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
---
libavutil/opt.c | 107 +++++++++++++++++-------------------------------
1 file changed, 37 insertions(+), 70 deletions(-)
diff --git a/libavutil/opt.c b/libavutil/opt.c
index d13b1ab504..554916fbaf 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -1231,6 +1231,41 @@ static char *get_opt_flags_string(void *obj, const char *unit, int64_t value)
return NULL;
}
+static void log_type(void *av_log_obj, const AVOption *o,
+ enum AVOptionType parent_type)
+{
+ const char *desc[] = {
+ [AV_OPT_TYPE_FLAGS] = "<flags>",
+ [AV_OPT_TYPE_INT] = "<int>",
+ [AV_OPT_TYPE_INT64] = "<int64>",
+ [AV_OPT_TYPE_UINT64] = "<uint64>",
+ [AV_OPT_TYPE_DOUBLE] = "<double>",
+ [AV_OPT_TYPE_FLOAT] = "<float>",
+ [AV_OPT_TYPE_STRING] = "<string>",
+ [AV_OPT_TYPE_RATIONAL] = "<rational>",
+ [AV_OPT_TYPE_BINARY] = "<binary>",
+ [AV_OPT_TYPE_DICT] = "<dictionary>",
+ [AV_OPT_TYPE_IMAGE_SIZE] = "<image_size>",
+ [AV_OPT_TYPE_VIDEO_RATE] = "<video_rate>",
+ [AV_OPT_TYPE_PIXEL_FMT] = "<pix_fmt>",
+ [AV_OPT_TYPE_SAMPLE_FMT] = "<sample_fmt>",
+ [AV_OPT_TYPE_DURATION] = "<duration>",
+ [AV_OPT_TYPE_COLOR] = "<color>",
+#if FF_API_OLD_CHANNEL_LAYOUT
+ [AV_OPT_TYPE_CHANNEL_LAYOUT]= "<channel_layout>",
+#endif
+ [AV_OPT_TYPE_CHLAYOUT] = "<channel_layout>",
+ [AV_OPT_TYPE_BOOL] = "<boolean>",
+ };
+
+ if (o->type == AV_OPT_TYPE_CONST && parent_type == AV_OPT_TYPE_INT)
+ av_log(av_log_obj, AV_LOG_INFO, "%-12"PRId64" ", o->default_val.i64);
+ else if (o->type < FF_ARRAY_ELEMS(desc) && desc[o->type])
+ av_log(av_log_obj, AV_LOG_INFO, "%-12s ", desc[o->type]);
+ else
+ av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
+}
+
static void opt_list(void *obj, void *av_log_obj, const char *unit,
int req_flags, int rej_flags, enum AVOptionType parent_type)
{
@@ -1259,76 +1294,8 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
(opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? " " : "-",
opt->name);
- switch (opt->type) {
- case AV_OPT_TYPE_FLAGS:
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<flags>");
- break;
- case AV_OPT_TYPE_INT:
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<int>");
- break;
- case AV_OPT_TYPE_INT64:
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<int64>");
- break;
- case AV_OPT_TYPE_UINT64:
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<uint64>");
- break;
- case AV_OPT_TYPE_DOUBLE:
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<double>");
- break;
- case AV_OPT_TYPE_FLOAT:
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<float>");
- break;
- case AV_OPT_TYPE_STRING:
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<string>");
- break;
- case AV_OPT_TYPE_RATIONAL:
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<rational>");
- break;
- case AV_OPT_TYPE_BINARY:
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<binary>");
- break;
- case AV_OPT_TYPE_DICT:
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<dictionary>");
- break;
- case AV_OPT_TYPE_IMAGE_SIZE:
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<image_size>");
- break;
- case AV_OPT_TYPE_VIDEO_RATE:
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<video_rate>");
- break;
- case AV_OPT_TYPE_PIXEL_FMT:
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<pix_fmt>");
- break;
- case AV_OPT_TYPE_SAMPLE_FMT:
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<sample_fmt>");
- break;
- case AV_OPT_TYPE_DURATION:
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<duration>");
- break;
- case AV_OPT_TYPE_COLOR:
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<color>");
- break;
- case AV_OPT_TYPE_CHLAYOUT:
-#if FF_API_OLD_CHANNEL_LAYOUT
-FF_DISABLE_DEPRECATION_WARNINGS
- case AV_OPT_TYPE_CHANNEL_LAYOUT:
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<channel_layout>");
- break;
- case AV_OPT_TYPE_BOOL:
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<boolean>");
- break;
- case AV_OPT_TYPE_CONST:
- if (parent_type == AV_OPT_TYPE_INT)
- av_log(av_log_obj, AV_LOG_INFO, "%-12"PRId64" ", opt->default_val.i64);
- else
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
- break;
- default:
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
- break;
- }
+ log_type(av_log_obj, opt, parent_type);
+
av_log(av_log_obj, AV_LOG_INFO, "%c%c%c%c%c%c%c%c%c%c%c",
(opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.',
(opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.',
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 08/38] lavu/opt: factor out printing option default from opt_list()
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (6 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 07/38] lavu/opt: simplify printing option type in opt_list() Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 09/38] lavu/opt: drop useless handling of NULL return from get_bool_name() Anton Khirnov
` (29 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
---
libavutil/opt.c | 150 +++++++++++++++++++++++++-----------------------
1 file changed, 78 insertions(+), 72 deletions(-)
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 554916fbaf..49b7da7742 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -1266,6 +1266,83 @@ static void log_type(void *av_log_obj, const AVOption *o,
av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
}
+static void log_default(void *obj, void *av_log_obj, const AVOption *opt)
+{
+ if (opt->type == AV_OPT_TYPE_CONST || opt->type == AV_OPT_TYPE_BINARY)
+ return;
+ if ((opt->type == AV_OPT_TYPE_COLOR ||
+ opt->type == AV_OPT_TYPE_IMAGE_SIZE ||
+ opt->type == AV_OPT_TYPE_STRING ||
+ opt->type == AV_OPT_TYPE_DICT ||
+ opt->type == AV_OPT_TYPE_CHLAYOUT ||
+ opt->type == AV_OPT_TYPE_VIDEO_RATE) &&
+ !opt->default_val.str)
+ return;
+
+ av_log(av_log_obj, AV_LOG_INFO, " (default ");
+ switch (opt->type) {
+ case AV_OPT_TYPE_BOOL:
+ av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(get_bool_name(opt->default_val.i64), "invalid"));
+ break;
+ case AV_OPT_TYPE_FLAGS: {
+ char *def_flags = get_opt_flags_string(obj, opt->unit, opt->default_val.i64);
+ if (def_flags) {
+ av_log(av_log_obj, AV_LOG_INFO, "%s", def_flags);
+ av_freep(&def_flags);
+ } else {
+ av_log(av_log_obj, AV_LOG_INFO, "%"PRIX64, opt->default_val.i64);
+ }
+ break;
+ }
+ case AV_OPT_TYPE_DURATION: {
+ char buf[25];
+ format_duration(buf, sizeof(buf), opt->default_val.i64);
+ av_log(av_log_obj, AV_LOG_INFO, "%s", buf);
+ break;
+ }
+ case AV_OPT_TYPE_INT:
+ case AV_OPT_TYPE_UINT64:
+ case AV_OPT_TYPE_INT64: {
+ const char *def_const = get_opt_const_name(obj, opt->unit, opt->default_val.i64);
+ if (def_const)
+ av_log(av_log_obj, AV_LOG_INFO, "%s", def_const);
+ else
+ log_int_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64);
+ break;
+ }
+ case AV_OPT_TYPE_DOUBLE:
+ case AV_OPT_TYPE_FLOAT:
+ log_value(av_log_obj, AV_LOG_INFO, opt->default_val.dbl);
+ break;
+ case AV_OPT_TYPE_RATIONAL: {
+ AVRational q = av_d2q(opt->default_val.dbl, INT_MAX);
+ av_log(av_log_obj, AV_LOG_INFO, "%d/%d", q.num, q.den); }
+ break;
+ case AV_OPT_TYPE_PIXEL_FMT:
+ av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(opt->default_val.i64), "none"));
+ break;
+ case AV_OPT_TYPE_SAMPLE_FMT:
+ av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(opt->default_val.i64), "none"));
+ break;
+ case AV_OPT_TYPE_COLOR:
+ case AV_OPT_TYPE_IMAGE_SIZE:
+ case AV_OPT_TYPE_STRING:
+ case AV_OPT_TYPE_DICT:
+ case AV_OPT_TYPE_VIDEO_RATE:
+ case AV_OPT_TYPE_CHLAYOUT:
+ av_log(av_log_obj, AV_LOG_INFO, "\"%s\"", opt->default_val.str);
+ break;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+ case AV_OPT_TYPE_CHANNEL_LAYOUT:
+ av_log(av_log_obj, AV_LOG_INFO, "0x%"PRIx64, opt->default_val.i64);
+ break;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+ }
+ av_log(av_log_obj, AV_LOG_INFO, ")");
+}
+
static void opt_list(void *obj, void *av_log_obj, const char *unit,
int req_flags, int rej_flags, enum AVOptionType parent_type)
{
@@ -1332,78 +1409,7 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
av_opt_freep_ranges(&r);
}
- if (opt->type != AV_OPT_TYPE_CONST &&
- opt->type != AV_OPT_TYPE_BINARY &&
- !((opt->type == AV_OPT_TYPE_COLOR ||
- opt->type == AV_OPT_TYPE_IMAGE_SIZE ||
- opt->type == AV_OPT_TYPE_STRING ||
- opt->type == AV_OPT_TYPE_DICT ||
- opt->type == AV_OPT_TYPE_CHLAYOUT ||
- opt->type == AV_OPT_TYPE_VIDEO_RATE) &&
- !opt->default_val.str)) {
- av_log(av_log_obj, AV_LOG_INFO, " (default ");
- switch (opt->type) {
- case AV_OPT_TYPE_BOOL:
- av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(get_bool_name(opt->default_val.i64), "invalid"));
- break;
- case AV_OPT_TYPE_FLAGS: {
- char *def_flags = get_opt_flags_string(obj, opt->unit, opt->default_val.i64);
- if (def_flags) {
- av_log(av_log_obj, AV_LOG_INFO, "%s", def_flags);
- av_freep(&def_flags);
- } else {
- av_log(av_log_obj, AV_LOG_INFO, "%"PRIX64, opt->default_val.i64);
- }
- break;
- }
- case AV_OPT_TYPE_DURATION: {
- char buf[25];
- format_duration(buf, sizeof(buf), opt->default_val.i64);
- av_log(av_log_obj, AV_LOG_INFO, "%s", buf);
- break;
- }
- case AV_OPT_TYPE_INT:
- case AV_OPT_TYPE_UINT64:
- case AV_OPT_TYPE_INT64: {
- const char *def_const = get_opt_const_name(obj, opt->unit, opt->default_val.i64);
- if (def_const)
- av_log(av_log_obj, AV_LOG_INFO, "%s", def_const);
- else
- log_int_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64);
- break;
- }
- case AV_OPT_TYPE_DOUBLE:
- case AV_OPT_TYPE_FLOAT:
- log_value(av_log_obj, AV_LOG_INFO, opt->default_val.dbl);
- break;
- case AV_OPT_TYPE_RATIONAL: {
- AVRational q = av_d2q(opt->default_val.dbl, INT_MAX);
- av_log(av_log_obj, AV_LOG_INFO, "%d/%d", q.num, q.den); }
- break;
- case AV_OPT_TYPE_PIXEL_FMT:
- av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(opt->default_val.i64), "none"));
- break;
- case AV_OPT_TYPE_SAMPLE_FMT:
- av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(opt->default_val.i64), "none"));
- break;
- case AV_OPT_TYPE_COLOR:
- case AV_OPT_TYPE_IMAGE_SIZE:
- case AV_OPT_TYPE_STRING:
- case AV_OPT_TYPE_DICT:
- case AV_OPT_TYPE_VIDEO_RATE:
- case AV_OPT_TYPE_CHLAYOUT:
- av_log(av_log_obj, AV_LOG_INFO, "\"%s\"", opt->default_val.str);
- break;
-#if FF_API_OLD_CHANNEL_LAYOUT
-FF_DISABLE_DEPRECATION_WARNINGS
- case AV_OPT_TYPE_CHANNEL_LAYOUT:
- av_log(av_log_obj, AV_LOG_INFO, "0x%"PRIx64, opt->default_val.i64);
- break;
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
- }
- av_log(av_log_obj, AV_LOG_INFO, ")");
- }
+ log_default(obj, av_log_obj, opt);
av_log(av_log_obj, AV_LOG_INFO, "\n");
if (opt->unit && opt->type != AV_OPT_TYPE_CONST)
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 09/38] lavu/opt: drop useless handling of NULL return from get_bool_name()
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (7 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 08/38] lavu/opt: factor out printing option default from opt_list() Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 10/38] lavu/opt: drop an always-NULL argument to get_number() Anton Khirnov
` (28 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
That function always returns an actual string.
---
libavutil/opt.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 49b7da7742..0ffdfc9a1e 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -853,7 +853,7 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
buf[0] = 0;
switch (o->type) {
case AV_OPT_TYPE_BOOL:
- ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(get_bool_name(*(int *)dst), "invalid"));
+ ret = snprintf(buf, sizeof(buf), "%s", get_bool_name(*(int *)dst));
break;
case AV_OPT_TYPE_FLAGS:
ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);
@@ -1282,7 +1282,7 @@ static void log_default(void *obj, void *av_log_obj, const AVOption *opt)
av_log(av_log_obj, AV_LOG_INFO, " (default ");
switch (opt->type) {
case AV_OPT_TYPE_BOOL:
- av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(get_bool_name(opt->default_val.i64), "invalid"));
+ av_log(av_log_obj, AV_LOG_INFO, "%s", get_bool_name(opt->default_val.i64));
break;
case AV_OPT_TYPE_FLAGS: {
char *def_flags = get_opt_flags_string(obj, opt->unit, opt->default_val.i64);
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 10/38] lavu/opt: drop an always-NULL argument to get_number()
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (8 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 09/38] lavu/opt: drop useless handling of NULL return from get_bool_name() Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 11/38] lavu/opt: simplify error handling in get_number() Anton Khirnov
` (27 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
---
libavutil/opt.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 0ffdfc9a1e..54a99c689c 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -955,7 +955,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
return *out_val ? 0 : AVERROR(ENOMEM);
}
-static int get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum,
+static int get_number(void *obj, const char *name, double *num, int *den, int64_t *intnum,
int search_flags)
{
void *dst, *target_obj;
@@ -965,8 +965,6 @@ static int get_number(void *obj, const char *name, const AVOption **o_out, doubl
dst = ((uint8_t *)target_obj) + o->offset;
- if (o_out) *o_out= o;
-
return read_number(o, dst, num, den, intnum);
error:
@@ -981,7 +979,7 @@ int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_v
double num = 1;
int ret, den = 1;
- if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
+ if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
return ret;
if (num == den)
*out_val = intnum;
@@ -996,7 +994,7 @@ int av_opt_get_double(void *obj, const char *name, int search_flags, double *out
double num = 1;
int ret, den = 1;
- if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
+ if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
return ret;
*out_val = num * intnum / den;
return 0;
@@ -1008,7 +1006,7 @@ int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_
double num = 1;
int ret, den = 1;
- if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
+ if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
return ret;
if (num == 1.0 && (int)intnum == intnum)
@@ -1042,7 +1040,7 @@ int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRatio
double num = 1;
int ret, den = 1;
- if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
+ if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
return ret;
if (num == 1.0 && (int)intnum == intnum)
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 11/38] lavu/opt: simplify error handling in get_number()
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (9 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 10/38] lavu/opt: drop an always-NULL argument to get_number() Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 12/38] lavu/opt: get rid of useless read_number() calls Anton Khirnov
` (26 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
---
libavutil/opt.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 54a99c689c..75a27c4d9b 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -961,16 +961,11 @@ static int get_number(void *obj, const char *name, double *num, int *den, int64_
void *dst, *target_obj;
const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
if (!o || !target_obj)
- goto error;
+ return AVERROR_OPTION_NOT_FOUND;
dst = ((uint8_t *)target_obj) + o->offset;
return read_number(o, dst, num, den, intnum);
-
-error:
- *den =
- *intnum = 0;
- return -1;
}
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 12/38] lavu/opt: get rid of useless read_number() calls
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (10 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 11/38] lavu/opt: simplify error handling in get_number() Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 13/38] lavu/opt: factor per-type dispatch out of av_opt_get() Anton Khirnov
` (25 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
The option type is known and fixed for all these, so reading the value
directly is simpler and more clear.
---
libavutil/opt.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 75a27c4d9b..8ee89237c5 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -313,7 +313,7 @@ static int set_string_number(void *obj, void *target_obj, const AVOption *o, con
}
}
if (o->type == AV_OPT_TYPE_FLAGS) {
- read_number(o, dst, NULL, NULL, &intnum);
+ intnum = *(unsigned int*)dst;
if (cmd == '+')
d = intnum | (int64_t)d;
else if (cmd == '-')
@@ -2025,8 +2025,7 @@ void av_opt_freep_ranges(AVOptionRanges **rangesp)
int av_opt_is_set_to_default(void *obj, const AVOption *o)
{
int64_t i64;
- double d, d2;
- float f;
+ double d;
AVRational q;
int ret, w, h;
char *str;
@@ -2071,13 +2070,11 @@ FF_ENABLE_DEPRECATION_WARNINGS
return 0;
return !strcmp(str, o->default_val.str);
case AV_OPT_TYPE_DOUBLE:
- read_number(o, dst, &d, NULL, NULL);
+ d = *(double *)dst;
return o->default_val.dbl == d;
case AV_OPT_TYPE_FLOAT:
- read_number(o, dst, &d, NULL, NULL);
- f = o->default_val.dbl;
- d2 = f;
- return d2 == d;
+ d = *(float *)dst;
+ return (float)o->default_val.dbl == d;
case AV_OPT_TYPE_RATIONAL:
q = av_d2q(o->default_val.dbl, INT_MAX);
return !av_cmp_q(*(AVRational*)dst, q);
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 13/38] lavu/opt: factor per-type dispatch out of av_opt_get()
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (11 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 12/38] lavu/opt: get rid of useless read_number() calls Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 14/38] lavu/opt: factor per-type dispatch out of av_opt_set() Anton Khirnov
` (24 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
Will be useful in following commits.
---
libavutil/opt.c | 220 ++++++++++++++++++++++++++----------------------
1 file changed, 121 insertions(+), 99 deletions(-)
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 8ee89237c5..0ca6d4d555 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -834,13 +834,123 @@ static void format_duration(char *buf, size_t size, int64_t d)
*(--e) = 0;
}
+static int opt_get_elem(const AVOption *o, uint8_t **pbuf, size_t buf_len,
+ void *dst, int search_flags)
+{
+ int ret;
+
+ switch (o->type) {
+ case AV_OPT_TYPE_BOOL:
+ ret = snprintf(*pbuf, buf_len, "%s", get_bool_name(*(int *)dst));
+ break;
+ case AV_OPT_TYPE_FLAGS:
+ ret = snprintf(*pbuf, buf_len, "0x%08X", *(int *)dst);
+ break;
+ case AV_OPT_TYPE_INT:
+ ret = snprintf(*pbuf, buf_len, "%d", *(int *)dst);
+ break;
+ case AV_OPT_TYPE_INT64:
+ ret = snprintf(*pbuf, buf_len, "%"PRId64, *(int64_t *)dst);
+ break;
+ case AV_OPT_TYPE_UINT64:
+ ret = snprintf(*pbuf, buf_len, "%"PRIu64, *(uint64_t *)dst);
+ break;
+ case AV_OPT_TYPE_FLOAT:
+ ret = snprintf(*pbuf, buf_len, "%f", *(float *)dst);
+ break;
+ case AV_OPT_TYPE_DOUBLE:
+ ret = snprintf(*pbuf, buf_len, "%f", *(double *)dst);
+ break;
+ case AV_OPT_TYPE_VIDEO_RATE:
+ case AV_OPT_TYPE_RATIONAL:
+ ret = snprintf(*pbuf, buf_len, "%d/%d", ((AVRational *)dst)->num, ((AVRational *)dst)->den);
+ break;
+ case AV_OPT_TYPE_CONST:
+ ret = snprintf(*pbuf, buf_len, "%"PRId64, o->default_val.i64);
+ break;
+ case AV_OPT_TYPE_STRING:
+ if (*(uint8_t **)dst) {
+ *pbuf = av_strdup(*(uint8_t **)dst);
+ } else if (search_flags & AV_OPT_ALLOW_NULL) {
+ *pbuf = NULL;
+ return 0;
+ } else {
+ *pbuf = av_strdup("");
+ }
+ return *pbuf ? 0 : AVERROR(ENOMEM);
+ case AV_OPT_TYPE_BINARY: {
+ const uint8_t *bin;
+ int len;
+
+ if (!*(uint8_t **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
+ *pbuf = NULL;
+ return 0;
+ }
+ len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *));
+ if ((uint64_t)len * 2 + 1 > INT_MAX)
+ return AVERROR(EINVAL);
+ if (!(*pbuf = av_malloc(len * 2 + 1)))
+ return AVERROR(ENOMEM);
+ if (!len) {
+ *pbuf[0] = '\0';
+ return 0;
+ }
+ bin = *(uint8_t **)dst;
+ for (int i = 0; i < len; i++)
+ snprintf(*pbuf + i * 2, 3, "%02X", bin[i]);
+ return 0;
+ }
+ case AV_OPT_TYPE_IMAGE_SIZE:
+ ret = snprintf(*pbuf, buf_len, "%dx%d", ((int *)dst)[0], ((int *)dst)[1]);
+ break;
+ case AV_OPT_TYPE_PIXEL_FMT:
+ ret = snprintf(*pbuf, buf_len, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum AVPixelFormat *)dst), "none"));
+ break;
+ case AV_OPT_TYPE_SAMPLE_FMT:
+ ret = snprintf(*pbuf, buf_len, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(*(enum AVSampleFormat *)dst), "none"));
+ break;
+ case AV_OPT_TYPE_DURATION: {
+ int64_t i64 = *(int64_t *)dst;
+ format_duration(*pbuf, buf_len, i64);
+ ret = strlen(*pbuf); // no overflow possible, checked by an assert
+ break;
+ }
+ case AV_OPT_TYPE_COLOR:
+ ret = snprintf(*pbuf, buf_len, "0x%02x%02x%02x%02x",
+ (int)((uint8_t *)dst)[0], (int)((uint8_t *)dst)[1],
+ (int)((uint8_t *)dst)[2], (int)((uint8_t *)dst)[3]);
+ break;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+ case AV_OPT_TYPE_CHANNEL_LAYOUT: {
+ int64_t i64 = *(int64_t *)dst;
+ ret = snprintf(*pbuf, buf_len, "0x%"PRIx64, i64);
+ break;
+ }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+ case AV_OPT_TYPE_CHLAYOUT:
+ ret = av_channel_layout_describe(dst, *pbuf, buf_len);
+ break;
+ case AV_OPT_TYPE_DICT:
+ if (!*(AVDictionary **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
+ *pbuf = NULL;
+ return 0;
+ }
+ return av_dict_get_string(*(AVDictionary **)dst, (char **)pbuf, '=', ':');
+ default:
+ return AVERROR(EINVAL);
+ }
+
+ return ret;
+}
+
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
{
void *dst, *target_obj;
const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
- uint8_t *bin, buf[128];
- int len, i, ret;
- int64_t i64;
+ uint8_t *out, buf[128];
+ int ret;
if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST))
return AVERROR_OPTION_NOT_FOUND;
@@ -851,107 +961,19 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
dst = (uint8_t *)target_obj + o->offset;
buf[0] = 0;
- switch (o->type) {
- case AV_OPT_TYPE_BOOL:
- ret = snprintf(buf, sizeof(buf), "%s", get_bool_name(*(int *)dst));
- break;
- case AV_OPT_TYPE_FLAGS:
- ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);
- break;
- case AV_OPT_TYPE_INT:
- ret = snprintf(buf, sizeof(buf), "%d", *(int *)dst);
- break;
- case AV_OPT_TYPE_INT64:
- ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t *)dst);
- break;
- case AV_OPT_TYPE_UINT64:
- ret = snprintf(buf, sizeof(buf), "%"PRIu64, *(uint64_t *)dst);
- break;
- case AV_OPT_TYPE_FLOAT:
- ret = snprintf(buf, sizeof(buf), "%f", *(float *)dst);
- break;
- case AV_OPT_TYPE_DOUBLE:
- ret = snprintf(buf, sizeof(buf), "%f", *(double *)dst);
- break;
- case AV_OPT_TYPE_VIDEO_RATE:
- case AV_OPT_TYPE_RATIONAL:
- ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational *)dst)->num, ((AVRational *)dst)->den);
- break;
- case AV_OPT_TYPE_CONST:
- ret = snprintf(buf, sizeof(buf), "%"PRId64, o->default_val.i64);
- break;
- case AV_OPT_TYPE_STRING:
- if (*(uint8_t **)dst) {
- *out_val = av_strdup(*(uint8_t **)dst);
- } else if (search_flags & AV_OPT_ALLOW_NULL) {
- *out_val = NULL;
- return 0;
- } else {
- *out_val = av_strdup("");
- }
- return *out_val ? 0 : AVERROR(ENOMEM);
- case AV_OPT_TYPE_BINARY:
- if (!*(uint8_t **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
- *out_val = NULL;
- return 0;
- }
- len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *));
- if ((uint64_t)len * 2 + 1 > INT_MAX)
- return AVERROR(EINVAL);
- if (!(*out_val = av_malloc(len * 2 + 1)))
- return AVERROR(ENOMEM);
- if (!len) {
- *out_val[0] = '\0';
- return 0;
- }
- bin = *(uint8_t **)dst;
- for (i = 0; i < len; i++)
- snprintf(*out_val + i * 2, 3, "%02X", bin[i]);
- return 0;
- case AV_OPT_TYPE_IMAGE_SIZE:
- ret = snprintf(buf, sizeof(buf), "%dx%d", ((int *)dst)[0], ((int *)dst)[1]);
- break;
- case AV_OPT_TYPE_PIXEL_FMT:
- ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum AVPixelFormat *)dst), "none"));
- break;
- case AV_OPT_TYPE_SAMPLE_FMT:
- ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_sample_fmt_name(*(enum AVSampleFormat *)dst), "none"));
- break;
- case AV_OPT_TYPE_DURATION:
- i64 = *(int64_t *)dst;
- format_duration(buf, sizeof(buf), i64);
- ret = strlen(buf); // no overflow possible, checked by an assert
- break;
- case AV_OPT_TYPE_COLOR:
- ret = snprintf(buf, sizeof(buf), "0x%02x%02x%02x%02x",
- (int)((uint8_t *)dst)[0], (int)((uint8_t *)dst)[1],
- (int)((uint8_t *)dst)[2], (int)((uint8_t *)dst)[3]);
- break;
-#if FF_API_OLD_CHANNEL_LAYOUT
-FF_DISABLE_DEPRECATION_WARNINGS
- case AV_OPT_TYPE_CHANNEL_LAYOUT:
- i64 = *(int64_t *)dst;
- ret = snprintf(buf, sizeof(buf), "0x%"PRIx64, i64);
- break;
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
- case AV_OPT_TYPE_CHLAYOUT:
- ret = av_channel_layout_describe(dst, buf, sizeof(buf));
- break;
- case AV_OPT_TYPE_DICT:
- if (!*(AVDictionary **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
- *out_val = NULL;
- return 0;
- }
- return av_dict_get_string(*(AVDictionary **)dst, (char **)out_val, '=', ':');
- default:
- return AVERROR(EINVAL);
+ out = buf;
+ ret = opt_get_elem(o, &out, sizeof(buf), dst, search_flags);
+ if (ret < 0)
+ return ret;
+ if (out != buf) {
+ *out_val = out;
+ return 0;
}
if (ret >= sizeof(buf))
return AVERROR(EINVAL);
- *out_val = av_strdup(buf);
+ *out_val = av_strdup(out);
return *out_val ? 0 : AVERROR(ENOMEM);
}
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 14/38] lavu/opt: factor per-type dispatch out of av_opt_set()
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (12 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 13/38] lavu/opt: factor per-type dispatch out of av_opt_get() Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 22:50 ` Michael Niedermayer
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 15/38] lavu/opt: add array options Anton Khirnov
` (23 subsequent siblings)
37 siblings, 1 reply; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
Will be useful in following commits.
---
libavutil/opt.c | 35 ++++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 0ca6d4d555..ebc8063dc6 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -484,13 +484,11 @@ static int set_string_channel_layout(void *obj, const AVOption *o,
return av_channel_layout_from_string(channel_layout, val);
}
-int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
+static int opt_set_elem(void *obj, void *target_obj, const AVOption *o,
+ const char *val, void *dst)
{
- int ret = 0;
- void *dst, *target_obj;
- const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
- if (!o || !target_obj)
- return AVERROR_OPTION_NOT_FOUND;
+ int ret;
+
FF_DISABLE_DEPRECATION_WARNINGS
if (!val && (o->type != AV_OPT_TYPE_STRING &&
o->type != AV_OPT_TYPE_PIXEL_FMT && o->type != AV_OPT_TYPE_SAMPLE_FMT &&
@@ -503,13 +501,6 @@ FF_DISABLE_DEPRECATION_WARNINGS
return AVERROR(EINVAL);
FF_ENABLE_DEPRECATION_WARNINGS
- if (o->flags & AV_OPT_FLAG_READONLY)
- return AVERROR(EINVAL);
-
- if (o->flags & AV_OPT_FLAG_DEPRECATED)
- av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help);
-
- dst = ((uint8_t *)target_obj) + o->offset;
switch (o->type) {
case AV_OPT_TYPE_BOOL:
return set_string_bool(obj, o, val, dst);
@@ -589,6 +580,24 @@ FF_ENABLE_DEPRECATION_WARNINGS
return AVERROR(EINVAL);
}
+int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
+{
+ void *dst, *target_obj;
+ const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
+ if (!o || !target_obj)
+ return AVERROR_OPTION_NOT_FOUND;
+
+ if (o->flags & AV_OPT_FLAG_READONLY)
+ return AVERROR(EINVAL);
+
+ if (o->flags & AV_OPT_FLAG_DEPRECATED)
+ av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help);
+
+ dst = ((uint8_t *)target_obj) + o->offset;
+
+ return opt_set_elem(obj, target_obj, o, val, dst);
+}
+
#define OPT_EVAL_NUMBER(name, opttype, vartype) \
int av_opt_eval_ ## name(void *obj, const AVOption *o, \
const char *val, vartype *name ## _out) \
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 14/38] lavu/opt: factor per-type dispatch out of av_opt_set()
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 14/38] lavu/opt: factor per-type dispatch out of av_opt_set() Anton Khirnov
@ 2024-02-23 22:50 ` Michael Niedermayer
2024-02-24 22:41 ` James Almer
2024-03-01 16:07 ` Anton Khirnov
0 siblings, 2 replies; 63+ messages in thread
From: Michael Niedermayer @ 2024-02-23 22:50 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1353 bytes --]
Hi Anton
On Fri, Feb 23, 2024 at 02:58:36PM +0100, Anton Khirnov wrote:
> Will be useful in following commits.
> ---
breaks:
./ffmpeg -y -request_channel_layout 3 -i bug/401/mlp_5point1_downmixof6channel.mlp -bitexact file-2-mlp_5point1_downmixof6channel.wav
[mlp @ 0x55690e23ff80] Error setting option request_channel_layout to value 3.
[mlp @ 0x55690e23ed00] Failed to open codec in avformat_find_stream_info
[mlp @ 0x55690e23ff80] Error setting option request_channel_layout to value 3.
Input #0, mlp, from 'bug/401/mlp_5point1_downmixof6channel.mlp':
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Audio: mlp, 48000 Hz, 5.1, s32 (24 bit)
[mlp @ 0x55690e257900] Error setting option request_channel_layout to value 3.
[aist#0:0/mlp @ 0x55690e254dc0] [dec:mlp @ 0x55690e256f40] Error while opening decoder: Invalid argument
[aost#0:0/pcm_s16le @ 0x55690e255a80] Error initializing a simple filtergraph
Error opening output file file-2-mlp_5point1_downmixof6channel.wav.
Error opening output files: Invalid argument
i suspect this isnt specific to the file but i can provide it if it
doesnt reproduce with a other file
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
The educated differ from the uneducated as much as the living from the
dead. -- Aristotle
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 14/38] lavu/opt: factor per-type dispatch out of av_opt_set()
2024-02-23 22:50 ` Michael Niedermayer
@ 2024-02-24 22:41 ` James Almer
2024-03-05 23:08 ` Michael Niedermayer
2024-03-01 16:07 ` Anton Khirnov
1 sibling, 1 reply; 63+ messages in thread
From: James Almer @ 2024-02-24 22:41 UTC (permalink / raw)
To: ffmpeg-devel
On 2/23/2024 7:50 PM, Michael Niedermayer wrote:
> Hi Anton
>
> On Fri, Feb 23, 2024 at 02:58:36PM +0100, Anton Khirnov wrote:
>> Will be useful in following commits.
>> ---
>
> breaks:
>
> ./ffmpeg -y -request_channel_layout 3 -i bug/401/mlp_5point1_downmixof6channel.mlp -bitexact file-2-mlp_5point1_downmixof6channel.wav
fwiw, request_channel_layout will be removed in the upcoming bump. You
should use -downmix stereo.
>
> [mlp @ 0x55690e23ff80] Error setting option request_channel_layout to value 3.
> [mlp @ 0x55690e23ed00] Failed to open codec in avformat_find_stream_info
> [mlp @ 0x55690e23ff80] Error setting option request_channel_layout to value 3.
> Input #0, mlp, from 'bug/401/mlp_5point1_downmixof6channel.mlp':
> Duration: N/A, start: 0.000000, bitrate: N/A
> Stream #0:0: Audio: mlp, 48000 Hz, 5.1, s32 (24 bit)
> [mlp @ 0x55690e257900] Error setting option request_channel_layout to value 3.
> [aist#0:0/mlp @ 0x55690e254dc0] [dec:mlp @ 0x55690e256f40] Error while opening decoder: Invalid argument
> [aost#0:0/pcm_s16le @ 0x55690e255a80] Error initializing a simple filtergraph
> Error opening output file file-2-mlp_5point1_downmixof6channel.wav.
> Error opening output files: Invalid argument
>
> i suspect this isnt specific to the file but i can provide it if it
> doesnt reproduce with a other file
>
> thx
>
> [...]
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 14/38] lavu/opt: factor per-type dispatch out of av_opt_set()
2024-02-24 22:41 ` James Almer
@ 2024-03-05 23:08 ` Michael Niedermayer
2024-03-05 23:14 ` James Almer
0 siblings, 1 reply; 63+ messages in thread
From: Michael Niedermayer @ 2024-03-05 23:08 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1125 bytes --]
On Sat, Feb 24, 2024 at 07:41:24PM -0300, James Almer wrote:
> On 2/23/2024 7:50 PM, Michael Niedermayer wrote:
> > Hi Anton
> >
> > On Fri, Feb 23, 2024 at 02:58:36PM +0100, Anton Khirnov wrote:
> > > Will be useful in following commits.
> > > ---
> >
> > breaks:
> >
> > ./ffmpeg -y -request_channel_layout 3 -i bug/401/mlp_5point1_downmixof6channel.mlp -bitexact file-2-mlp_5point1_downmixof6channel.wav
>
> fwiw, request_channel_layout will be removed in the upcoming bump. You
> should use -downmix stereo.
>
> >
> > [mlp @ 0x55690e23ff80] Error setting option request_channel_layout to value 3.
> > [mlp @ 0x55690e23ed00] Failed to open codec in avformat_find_stream_info
> > [mlp @ 0x55690e23ff80] Error setting option request_channel_layout to value 3.
the error message should point to the new option
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Concerning the gods, I have no means of knowing whether they exist or not
or of what sort they may be, because of the obscurity of the subject, and
the brevity of human life -- Protagoras
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 14/38] lavu/opt: factor per-type dispatch out of av_opt_set()
2024-03-05 23:08 ` Michael Niedermayer
@ 2024-03-05 23:14 ` James Almer
0 siblings, 0 replies; 63+ messages in thread
From: James Almer @ 2024-03-05 23:14 UTC (permalink / raw)
To: ffmpeg-devel
On 3/5/2024 8:08 PM, Michael Niedermayer wrote:
> On Sat, Feb 24, 2024 at 07:41:24PM -0300, James Almer wrote:
>> On 2/23/2024 7:50 PM, Michael Niedermayer wrote:
>>> Hi Anton
>>>
>>> On Fri, Feb 23, 2024 at 02:58:36PM +0100, Anton Khirnov wrote:
>>>> Will be useful in following commits.
>>>> ---
>>>
>>> breaks:
>>>
>>> ./ffmpeg -y -request_channel_layout 3 -i bug/401/mlp_5point1_downmixof6channel.mlp -bitexact file-2-mlp_5point1_downmixof6channel.wav
>>
>> fwiw, request_channel_layout will be removed in the upcoming bump. You
>> should use -downmix stereo.
>>
>>>
>>> [mlp @ 0x55690e23ff80] Error setting option request_channel_layout to value 3.
>>> [mlp @ 0x55690e23ed00] Failed to open codec in avformat_find_stream_info
>>> [mlp @ 0x55690e23ff80] Error setting option request_channel_layout to value 3.
>
> the error message should point to the new option
The error message points to the option you tried to set.
request_channel_layout is a valid but deprecated option separate from
downmix.
>
> thx
>
> [...]
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 14/38] lavu/opt: factor per-type dispatch out of av_opt_set()
2024-02-23 22:50 ` Michael Niedermayer
2024-02-24 22:41 ` James Almer
@ 2024-03-01 16:07 ` Anton Khirnov
2024-03-03 12:17 ` Anton Khirnov
1 sibling, 1 reply; 63+ messages in thread
From: Anton Khirnov @ 2024-03-01 16:07 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Michael Niedermayer (2024-02-23 23:50:10)
> Hi Anton
>
> On Fri, Feb 23, 2024 at 02:58:36PM +0100, Anton Khirnov wrote:
> > Will be useful in following commits.
> > ---
>
> breaks:
>
> ./ffmpeg -y -request_channel_layout 3 -i bug/401/mlp_5point1_downmixof6channel.mlp -bitexact file-2-mlp_5point1_downmixof6channel.wav
>
> [mlp @ 0x55690e23ff80] Error setting option request_channel_layout to value 3.
> [mlp @ 0x55690e23ed00] Failed to open codec in avformat_find_stream_info
> [mlp @ 0x55690e23ff80] Error setting option request_channel_layout to value 3.
> Input #0, mlp, from 'bug/401/mlp_5point1_downmixof6channel.mlp':
> Duration: N/A, start: 0.000000, bitrate: N/A
> Stream #0:0: Audio: mlp, 48000 Hz, 5.1, s32 (24 bit)
> [mlp @ 0x55690e257900] Error setting option request_channel_layout to value 3.
> [aist#0:0/mlp @ 0x55690e254dc0] [dec:mlp @ 0x55690e256f40] Error while opening decoder: Invalid argument
> [aost#0:0/pcm_s16le @ 0x55690e255a80] Error initializing a simple filtergraph
> Error opening output file file-2-mlp_5point1_downmixof6channel.wav.
> Error opening output files: Invalid argument
>
> i suspect this isnt specific to the file but i can provide it if it
> doesnt reproduce with a other file
Cannot reproduce with another mlp or 5.1 ac3 file.
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 14/38] lavu/opt: factor per-type dispatch out of av_opt_set()
2024-03-01 16:07 ` Anton Khirnov
@ 2024-03-03 12:17 ` Anton Khirnov
2024-03-05 23:12 ` Michael Niedermayer
0 siblings, 1 reply; 63+ messages in thread
From: Anton Khirnov @ 2024-03-03 12:17 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Anton Khirnov (2024-03-01 17:07:22)
> Quoting Michael Niedermayer (2024-02-23 23:50:10)
> > Hi Anton
> >
> > On Fri, Feb 23, 2024 at 02:58:36PM +0100, Anton Khirnov wrote:
> > > Will be useful in following commits.
> > > ---
> >
> > breaks:
> >
> > ./ffmpeg -y -request_channel_layout 3 -i bug/401/mlp_5point1_downmixof6channel.mlp -bitexact file-2-mlp_5point1_downmixof6channel.wav
> >
> > [mlp @ 0x55690e23ff80] Error setting option request_channel_layout to value 3.
> > [mlp @ 0x55690e23ed00] Failed to open codec in avformat_find_stream_info
> > [mlp @ 0x55690e23ff80] Error setting option request_channel_layout to value 3.
> > Input #0, mlp, from 'bug/401/mlp_5point1_downmixof6channel.mlp':
> > Duration: N/A, start: 0.000000, bitrate: N/A
> > Stream #0:0: Audio: mlp, 48000 Hz, 5.1, s32 (24 bit)
> > [mlp @ 0x55690e257900] Error setting option request_channel_layout to value 3.
> > [aist#0:0/mlp @ 0x55690e254dc0] [dec:mlp @ 0x55690e256f40] Error while opening decoder: Invalid argument
> > [aost#0:0/pcm_s16le @ 0x55690e255a80] Error initializing a simple filtergraph
> > Error opening output file file-2-mlp_5point1_downmixof6channel.wav.
> > Error opening output files: Invalid argument
> >
> > i suspect this isnt specific to the file but i can provide it if it
> > doesnt reproduce with a other file
>
> Cannot reproduce with another mlp or 5.1 ac3 file.
Cannot reproduce with your sample either. Are you sure you're using the
right code? It's branch 'avoption_list' in my tree.
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 14/38] lavu/opt: factor per-type dispatch out of av_opt_set()
2024-03-03 12:17 ` Anton Khirnov
@ 2024-03-05 23:12 ` Michael Niedermayer
2024-03-05 23:21 ` James Almer
0 siblings, 1 reply; 63+ messages in thread
From: Michael Niedermayer @ 2024-03-05 23:12 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1930 bytes --]
On Sun, Mar 03, 2024 at 01:17:57PM +0100, Anton Khirnov wrote:
> Quoting Anton Khirnov (2024-03-01 17:07:22)
> > Quoting Michael Niedermayer (2024-02-23 23:50:10)
> > > Hi Anton
> > >
> > > On Fri, Feb 23, 2024 at 02:58:36PM +0100, Anton Khirnov wrote:
> > > > Will be useful in following commits.
> > > > ---
> > >
> > > breaks:
> > >
> > > ./ffmpeg -y -request_channel_layout 3 -i bug/401/mlp_5point1_downmixof6channel.mlp -bitexact file-2-mlp_5point1_downmixof6channel.wav
> > >
> > > [mlp @ 0x55690e23ff80] Error setting option request_channel_layout to value 3.
> > > [mlp @ 0x55690e23ed00] Failed to open codec in avformat_find_stream_info
> > > [mlp @ 0x55690e23ff80] Error setting option request_channel_layout to value 3.
> > > Input #0, mlp, from 'bug/401/mlp_5point1_downmixof6channel.mlp':
> > > Duration: N/A, start: 0.000000, bitrate: N/A
> > > Stream #0:0: Audio: mlp, 48000 Hz, 5.1, s32 (24 bit)
> > > [mlp @ 0x55690e257900] Error setting option request_channel_layout to value 3.
> > > [aist#0:0/mlp @ 0x55690e254dc0] [dec:mlp @ 0x55690e256f40] Error while opening decoder: Invalid argument
> > > [aost#0:0/pcm_s16le @ 0x55690e255a80] Error initializing a simple filtergraph
> > > Error opening output file file-2-mlp_5point1_downmixof6channel.wav.
> > > Error opening output files: Invalid argument
> > >
> > > i suspect this isnt specific to the file but i can provide it if it
> > > doesnt reproduce with a other file
> >
> > Cannot reproduce with another mlp or 5.1 ac3 file.
>
> Cannot reproduce with your sample either. Are you sure you're using the
> right code? It's branch 'avoption_list' in my tree.
it worked with "-downmix stereo" instead of "-request_channel_layout 3"
as suggested by james
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
No snowflake in an avalanche ever feels responsible. -- Voltaire
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 14/38] lavu/opt: factor per-type dispatch out of av_opt_set()
2024-03-05 23:12 ` Michael Niedermayer
@ 2024-03-05 23:21 ` James Almer
0 siblings, 0 replies; 63+ messages in thread
From: James Almer @ 2024-03-05 23:21 UTC (permalink / raw)
To: ffmpeg-devel
On 3/5/2024 8:12 PM, Michael Niedermayer wrote:
> On Sun, Mar 03, 2024 at 01:17:57PM +0100, Anton Khirnov wrote:
>> Quoting Anton Khirnov (2024-03-01 17:07:22)
>>> Quoting Michael Niedermayer (2024-02-23 23:50:10)
>>>> Hi Anton
>>>>
>>>> On Fri, Feb 23, 2024 at 02:58:36PM +0100, Anton Khirnov wrote:
>>>>> Will be useful in following commits.
>>>>> ---
>>>>
>>>> breaks:
>>>>
>>>> ./ffmpeg -y -request_channel_layout 3 -i bug/401/mlp_5point1_downmixof6channel.mlp -bitexact file-2-mlp_5point1_downmixof6channel.wav
>>>>
>>>> [mlp @ 0x55690e23ff80] Error setting option request_channel_layout to value 3.
>>>> [mlp @ 0x55690e23ed00] Failed to open codec in avformat_find_stream_info
>>>> [mlp @ 0x55690e23ff80] Error setting option request_channel_layout to value 3.
>>>> Input #0, mlp, from 'bug/401/mlp_5point1_downmixof6channel.mlp':
>>>> Duration: N/A, start: 0.000000, bitrate: N/A
>>>> Stream #0:0: Audio: mlp, 48000 Hz, 5.1, s32 (24 bit)
>>>> [mlp @ 0x55690e257900] Error setting option request_channel_layout to value 3.
>>>> [aist#0:0/mlp @ 0x55690e254dc0] [dec:mlp @ 0x55690e256f40] Error while opening decoder: Invalid argument
>>>> [aost#0:0/pcm_s16le @ 0x55690e255a80] Error initializing a simple filtergraph
>>>> Error opening output file file-2-mlp_5point1_downmixof6channel.wav.
>>>> Error opening output files: Invalid argument
>>>>
>>>> i suspect this isnt specific to the file but i can provide it if it
>>>> doesnt reproduce with a other file
>>>
>>> Cannot reproduce with another mlp or 5.1 ac3 file.
>>
>> Cannot reproduce with your sample either. Are you sure you're using the
>> right code? It's branch 'avoption_list' in my tree.
>
> it worked with "-downmix stereo" instead of "-request_channel_layout 3"
> as suggested by james
Would be nice to find out why. downmix is a codec specific option
whereas request_channel_layout is a global AVCodecContext option.
Something here may have affected how child AVOptions are accessed. But
if Anton can't reproduce it, then maybe your tree was dirty?
>
> thx
>
> [...]
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 15/38] lavu/opt: add array options
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (13 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 14/38] lavu/opt: factor per-type dispatch out of av_opt_set() Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 19:05 ` Marton Balint
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 16/38] lavc: add a decoder option for configuring side data preference Anton Khirnov
` (22 subsequent siblings)
37 siblings, 1 reply; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
AVOption.array_max_size is added before AVOption.unit to avoid
increasing sizeof(AVOption).
---
doc/APIchanges | 3 +
libavutil/opt.c | 344 ++++++++++++++++++++++++++++++++++++------
libavutil/opt.h | 26 ++++
libavutil/tests/opt.c | 34 +++++
tests/ref/fate/opt | 23 ++-
5 files changed, 385 insertions(+), 45 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index d26110b285..371fd2f465 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
API changes, most recent first:
+2024-02-xx - xxxxxxxxxx - lavu 58.xx.100 - opt.h
+ Add AV_OPT_FLAG_ARRAY and AVOption.array_max_size.
+
2024-02-21 - xxxxxxxxxx - lavc 60.40.100 - avcodec.h
Deprecate AV_INPUT_BUFFER_MIN_SIZE without replacement.
diff --git a/libavutil/opt.c b/libavutil/opt.c
index ebc8063dc6..88236660a1 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -56,6 +56,77 @@ const AVOption *av_opt_next(const void *obj, const AVOption *last)
return NULL;
}
+static const size_t opt_elem_size[] = {
+ [AV_OPT_TYPE_FLAGS] = sizeof(unsigned),
+ [AV_OPT_TYPE_INT] = sizeof(int),
+ [AV_OPT_TYPE_INT64] = sizeof(int64_t),
+ [AV_OPT_TYPE_UINT64] = sizeof(uint64_t),
+ [AV_OPT_TYPE_DOUBLE] = sizeof(double),
+ [AV_OPT_TYPE_FLOAT] = sizeof(float),
+ [AV_OPT_TYPE_STRING] = sizeof(char *),
+ [AV_OPT_TYPE_RATIONAL] = sizeof(AVRational),
+ [AV_OPT_TYPE_BINARY] = sizeof(uint8_t *),
+ [AV_OPT_TYPE_DICT] = sizeof(AVDictionary *),
+ [AV_OPT_TYPE_IMAGE_SIZE] = sizeof(int[2]),
+ [AV_OPT_TYPE_VIDEO_RATE] = sizeof(AVRational),
+ [AV_OPT_TYPE_PIXEL_FMT] = sizeof(int),
+ [AV_OPT_TYPE_SAMPLE_FMT] = sizeof(int),
+ [AV_OPT_TYPE_DURATION] = sizeof(int64_t),
+ [AV_OPT_TYPE_COLOR] = sizeof(uint8_t[4]),
+#if FF_API_OLD_CHANNEL_LAYOUT
+ [AV_OPT_TYPE_CHANNEL_LAYOUT]= sizeof(uint64_t),
+#endif
+ [AV_OPT_TYPE_CHLAYOUT] = sizeof(AVChannelLayout),
+ [AV_OPT_TYPE_BOOL] = sizeof(int),
+};
+
+static uint8_t opt_array_sep(const AVOption *o)
+{
+ av_assert1(o->flags & AV_OPT_FLAG_ARRAY);
+ return o->default_val.str ? o->default_val.str[0] : ',';
+}
+
+static void *opt_array_pelem(const AVOption *o, void *array, unsigned idx)
+{
+ av_assert1(o->flags & AV_OPT_FLAG_ARRAY);
+ return (uint8_t *)array + idx * opt_elem_size[o->type];
+}
+
+static unsigned *opt_array_pcount(void *parray)
+{
+ return (unsigned *)((void **)parray + 1);
+}
+
+static void opt_free_elem(const AVOption *o, void *ptr)
+{
+ switch (o->type) {
+ case AV_OPT_TYPE_STRING:
+ case AV_OPT_TYPE_BINARY:
+ av_freep(ptr);
+ break;
+
+ case AV_OPT_TYPE_DICT:
+ av_dict_free((AVDictionary **)ptr);
+ break;
+
+ case AV_OPT_TYPE_CHLAYOUT:
+ av_channel_layout_uninit((AVChannelLayout *)ptr);
+ break;
+
+ default:
+ break;
+ }
+}
+
+static void opt_free_array(const AVOption *o, void *parray, unsigned *count)
+{
+ for (unsigned i = 0; i < *count; i++)
+ opt_free_elem(o, opt_array_pelem(o, *(void **)parray, i));
+
+ av_freep(parray);
+ *count = 0;
+}
+
static int read_number(const AVOption *o, const void *dst, double *num, int *den, int64_t *intnum)
{
switch (o->type) {
@@ -580,6 +651,76 @@ FF_ENABLE_DEPRECATION_WARNINGS
return AVERROR(EINVAL);
}
+static int opt_set_array(void *obj, void *target_obj, const AVOption *o,
+ const char *val, void *dst)
+{
+ const size_t elem_size = opt_elem_size[o->type];
+ const uint8_t sep = opt_array_sep(o);
+ uint8_t *str = NULL;
+
+ void *elems = NULL;
+ unsigned nb_elems = 0;
+ int ret;
+
+ if (val && *val) {
+ str = av_malloc(strlen(val) + 1);
+ if (!str)
+ return AVERROR(ENOMEM);
+ }
+
+ // split and unescape the string
+ while (val && *val) {
+ uint8_t *p = str;
+ void *tmp;
+
+ if (o->array_max_size && nb_elems >= o->array_max_size) {
+ av_log(obj, AV_LOG_ERROR,
+ "Cannot assign more than %u elements to array option %s\n",
+ o->array_max_size, o->name);
+ ret = AVERROR(EINVAL);
+ goto fail;
+ }
+
+ for (; *val; val++, p++) {
+ if (*val == '\\' && val[1])
+ val++;
+ else if (*val == sep) {
+ val++;
+ break;
+ }
+ *p = *val;
+ }
+ *p = 0;
+
+ tmp = av_realloc_array(elems, nb_elems + 1, elem_size);
+ if (!tmp) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
+ elems = tmp;
+
+ tmp = opt_array_pelem(o, elems, nb_elems);
+ memset(tmp, 0, elem_size);
+
+ ret = opt_set_elem(obj, target_obj, o, str, tmp);
+ if (ret < 0)
+ goto fail;
+ nb_elems++;
+ }
+ av_freep(&str);
+
+ opt_free_array(o, dst, opt_array_pcount(dst));
+
+ *((void **)dst) = elems;
+ *opt_array_pcount(dst) = nb_elems;
+
+ return 0;
+fail:
+ av_freep(&str);
+ opt_free_array(o, &elems, &nb_elems);
+ return ret;
+}
+
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
{
void *dst, *target_obj;
@@ -595,14 +736,16 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
dst = ((uint8_t *)target_obj) + o->offset;
- return opt_set_elem(obj, target_obj, o, val, dst);
+ return ((o->flags & AV_OPT_FLAG_ARRAY) ?
+ opt_set_array : opt_set_elem)(obj, target_obj, o, val, dst);
}
#define OPT_EVAL_NUMBER(name, opttype, vartype) \
int av_opt_eval_ ## name(void *obj, const AVOption *o, \
const char *val, vartype *name ## _out) \
{ \
- if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY) \
+ if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY || \
+ o->flags & AV_OPT_FLAG_ARRAY) \
return AVERROR(EINVAL); \
return set_string_number(obj, obj, o, val, name ## _out); \
}
@@ -623,7 +766,7 @@ static int set_number(void *obj, const char *name, double num, int den, int64_t
if (!o || !target_obj)
return AVERROR_OPTION_NOT_FOUND;
- if (o->flags & AV_OPT_FLAG_READONLY)
+ if (o->flags & (AV_OPT_FLAG_READONLY | AV_OPT_FLAG_ARRAY))
return AVERROR(EINVAL);
dst = ((uint8_t *)target_obj) + o->offset;
@@ -656,7 +799,8 @@ int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int
if (!o || !target_obj)
return AVERROR_OPTION_NOT_FOUND;
- if (o->type != AV_OPT_TYPE_BINARY || o->flags & AV_OPT_FLAG_READONLY)
+ if (o->type != AV_OPT_TYPE_BINARY ||
+ o->flags & (AV_OPT_FLAG_READONLY | AV_OPT_FLAG_ARRAY))
return AVERROR(EINVAL);
ptr = len ? av_malloc(len) : NULL;
@@ -682,9 +826,10 @@ int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_
if (!o || !target_obj)
return AVERROR_OPTION_NOT_FOUND;
- if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
+ if (o->type != AV_OPT_TYPE_IMAGE_SIZE ||
+ o->flags & AV_OPT_FLAG_ARRAY) {
av_log(obj, AV_LOG_ERROR,
- "The value set by option '%s' is not an image size.\n", o->name);
+ "The value set by option '%s' is not a scalar image size.\n", o->name);
return AVERROR(EINVAL);
}
if (w<0 || h<0) {
@@ -704,9 +849,11 @@ int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int searc
if (!o || !target_obj)
return AVERROR_OPTION_NOT_FOUND;
- if (o->type != AV_OPT_TYPE_VIDEO_RATE) {
+ if (o->type != AV_OPT_TYPE_VIDEO_RATE ||
+ o->flags & AV_OPT_FLAG_ARRAY) {
av_log(obj, AV_LOG_ERROR,
- "The value set by option '%s' is not a video rate.\n", o->name);
+ "The value set by option '%s' is not a scalar video rate.\n",
+ o->name);
return AVERROR(EINVAL);
}
if (val.num <= 0 || val.den <= 0)
@@ -724,9 +871,10 @@ static int set_format(void *obj, const char *name, int fmt, int search_flags,
if (!o || !target_obj)
return AVERROR_OPTION_NOT_FOUND;
- if (o->type != type) {
+ if (o->type != type ||
+ o->flags & AV_OPT_FLAG_ARRAY) {
av_log(obj, AV_LOG_ERROR,
- "The value set by option '%s' is not a %s format", name, desc);
+ "The value set by option '%s' is not a scalar %s format", name, desc);
return AVERROR(EINVAL);
}
@@ -762,9 +910,10 @@ int av_opt_set_channel_layout(void *obj, const char *name, int64_t cl, int searc
if (!o || !target_obj)
return AVERROR_OPTION_NOT_FOUND;
- if (o->type != AV_OPT_TYPE_CHANNEL_LAYOUT) {
+ if (o->type != AV_OPT_TYPE_CHANNEL_LAYOUT ||
+ o->flags & AV_OPT_FLAG_ARRAY) {
av_log(obj, AV_LOG_ERROR,
- "The value set by option '%s' is not a channel layout.\n", o->name);
+ "The value set by option '%s' is not a scalar channel layout.\n", o->name);
return AVERROR(EINVAL);
}
*(int64_t *)(((uint8_t *)target_obj) + o->offset) = cl;
@@ -782,7 +931,7 @@ int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val,
if (!o || !target_obj)
return AVERROR_OPTION_NOT_FOUND;
- if (o->flags & AV_OPT_FLAG_READONLY)
+ if (o->flags & (AV_OPT_FLAG_READONLY | AV_OPT_FLAG_ARRAY))
return AVERROR(EINVAL);
dst = (AVDictionary **)(((uint8_t *)target_obj) + o->offset);
@@ -802,6 +951,8 @@ int av_opt_set_chlayout(void *obj, const char *name,
if (!o || !target_obj)
return AVERROR_OPTION_NOT_FOUND;
+ if (o->flags & AV_OPT_FLAG_ARRAY)
+ return AVERROR(EINVAL);
dst = (AVChannelLayout*)((uint8_t*)target_obj + o->offset);
@@ -954,6 +1105,66 @@ FF_ENABLE_DEPRECATION_WARNINGS
return ret;
}
+static int opt_get_array(const AVOption *o, void *dst, uint8_t **out_val)
+{
+ const unsigned count = *opt_array_pcount(dst);
+ const uint8_t sep = opt_array_sep(o);
+
+ uint8_t *str = NULL;
+ size_t str_len = 0;
+ int ret;
+
+ *out_val = NULL;
+
+ for (unsigned i = 0; i < count; i++) {
+ uint8_t buf[128], *out = buf;
+ size_t out_len;
+
+ ret = opt_get_elem(o, &out, sizeof(buf),
+ opt_array_pelem(o, *(void **)dst, i), 0);
+ if (ret < 0)
+ goto fail;
+
+ out_len = strlen(out);
+ if (out_len > SIZE_MAX / 2 - !!i ||
+ !!i + out_len * 2 > SIZE_MAX - str_len - 1) {
+ ret = AVERROR(ERANGE);
+ goto fail;
+ }
+
+ // terminator escaping separator
+ // ↓ ↓ ↓
+ ret = av_reallocp(&str, str_len + 1 + out_len * 2 + !!i);
+ if (ret < 0)
+ goto fail;
+
+ // add separator if needed
+ if (i)
+ str[str_len++] = sep;
+
+ // escape the element
+ for (unsigned j = 0; j < out_len; j++) {
+ uint8_t val = out[j];
+ if (val == sep || val == '\\')
+ str[str_len++] = '\\';
+ str[str_len++] = val;
+ }
+ str[str_len] = 0;
+
+fail:
+ if (out != buf)
+ av_freep(&out);
+ if (ret < 0) {
+ av_freep(&str);
+ return ret;
+ }
+ }
+
+ *out_val = str;
+
+ return 0;
+}
+
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
{
void *dst, *target_obj;
@@ -969,8 +1180,19 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
dst = (uint8_t *)target_obj + o->offset;
- buf[0] = 0;
+ if (o->flags & AV_OPT_FLAG_ARRAY) {
+ ret = opt_get_array(o, dst, out_val);
+ if (ret < 0)
+ return ret;
+ if (!*out_val && !(search_flags & AV_OPT_ALLOW_NULL)) {
+ *out_val = av_strdup("");
+ if (!*out_val)
+ return AVERROR(ENOMEM);
+ }
+ return 0;
+ }
+ buf[0] = 0;
out = buf;
ret = opt_get_elem(o, &out, sizeof(buf), dst, search_flags);
if (ret < 0)
@@ -993,6 +1215,8 @@ static int get_number(void *obj, const char *name, double *num, int *den, int64_
const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
if (!o || !target_obj)
return AVERROR_OPTION_NOT_FOUND;
+ if (o->flags & AV_OPT_FLAG_ARRAY)
+ return AVERROR(EINVAL);
dst = ((uint8_t *)target_obj) + o->offset;
@@ -1048,9 +1272,10 @@ int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_
const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
if (!o || !target_obj)
return AVERROR_OPTION_NOT_FOUND;
- if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
+ if (o->type != AV_OPT_TYPE_IMAGE_SIZE ||
+ o->flags & AV_OPT_FLAG_ARRAY) {
av_log(obj, AV_LOG_ERROR,
- "The value for option '%s' is not an image size.\n", name);
+ "The value for option '%s' is not a scalar image size.\n", name);
return AVERROR(EINVAL);
}
@@ -1083,9 +1308,10 @@ static int get_format(void *obj, const char *name, int search_flags, int *out_fm
const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
if (!o || !target_obj)
return AVERROR_OPTION_NOT_FOUND;
- if (o->type != type) {
+ if (o->type != type ||
+ o->flags & AV_OPT_FLAG_ARRAY) {
av_log(obj, AV_LOG_ERROR,
- "The value for option '%s' is not a %s format.\n", desc, name);
+ "The value for option '%s' is not a scalar %s format.\n", desc, name);
return AVERROR(EINVAL);
}
@@ -1112,9 +1338,10 @@ int av_opt_get_channel_layout(void *obj, const char *name, int search_flags, int
const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
if (!o || !target_obj)
return AVERROR_OPTION_NOT_FOUND;
- if (o->type != AV_OPT_TYPE_CHANNEL_LAYOUT) {
+ if (o->type != AV_OPT_TYPE_CHANNEL_LAYOUT ||
+ o->flags & AV_OPT_FLAG_ARRAY) {
av_log(obj, AV_LOG_ERROR,
- "The value for option '%s' is not a channel layout.\n", name);
+ "The value for option '%s' is not a scalar channel layout.\n", name);
return AVERROR(EINVAL);
}
@@ -1131,9 +1358,10 @@ int av_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannel
const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
if (!o || !target_obj)
return AVERROR_OPTION_NOT_FOUND;
- if (o->type != AV_OPT_TYPE_CHLAYOUT) {
+ if (o->type != AV_OPT_TYPE_CHLAYOUT ||
+ o->flags & AV_OPT_FLAG_ARRAY) {
av_log(obj, AV_LOG_ERROR,
- "The value for option '%s' is not a channel layout.\n", name);
+ "The value for option '%s' is not a scalar channel layout.\n", name);
return AVERROR(EINVAL);
}
@@ -1149,7 +1377,8 @@ int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDiction
if (!o || !target_obj)
return AVERROR_OPTION_NOT_FOUND;
- if (o->type != AV_OPT_TYPE_DICT)
+ if (o->type != AV_OPT_TYPE_DICT ||
+ o->flags & AV_OPT_FLAG_ARRAY)
return AVERROR(EINVAL);
src = *(AVDictionary **)(((uint8_t *)target_obj) + o->offset);
@@ -1165,7 +1394,8 @@ int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
field ? field->unit : NULL, 0, 0);
int64_t res;
- if (!field || !flag || flag->type != AV_OPT_TYPE_CONST ||
+ if (!field || !(field->flags & AV_OPT_FLAG_ARRAY) ||
+ !flag || flag->type != AV_OPT_TYPE_CONST ||
av_opt_get_int(obj, field_name, 0, &res) < 0)
return 0;
return res & flag->default_val.i64;
@@ -1284,8 +1514,12 @@ static void log_type(void *av_log_obj, const AVOption *o,
if (o->type == AV_OPT_TYPE_CONST && parent_type == AV_OPT_TYPE_INT)
av_log(av_log_obj, AV_LOG_INFO, "%-12"PRId64" ", o->default_val.i64);
- else if (o->type < FF_ARRAY_ELEMS(desc) && desc[o->type])
- av_log(av_log_obj, AV_LOG_INFO, "%-12s ", desc[o->type]);
+ else if (o->type < FF_ARRAY_ELEMS(desc) && desc[o->type]) {
+ if (o->flags & AV_OPT_FLAG_ARRAY)
+ av_log(av_log_obj, AV_LOG_INFO, "×%-11s ", desc[o->type]);
+ else
+ av_log(av_log_obj, AV_LOG_INFO, "%-12s ", desc[o->type]);
+ }
else
av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
}
@@ -1470,6 +1704,22 @@ void av_opt_set_defaults2(void *s, int mask, int flags)
if (opt->flags & AV_OPT_FLAG_READONLY)
continue;
+ if (opt->flags & AV_OPT_FLAG_ARRAY) {
+ const char *val = opt->default_val.str;
+ if (val) {
+ const char sep = *val++;
+
+ // make sure people don't forget to set the separator correctly
+ av_assert0(sep &&
+ (sep < 'a' || sep > 'z') &&
+ (sep < 'A' || sep > 'Z') &&
+ (sep < '0' || sep > '9'));
+
+ opt_set_array(s, s, opt, val, dst);
+ }
+ continue;
+ }
+
switch (opt->type) {
case AV_OPT_TYPE_CONST:
/* Nothing to be done here */
@@ -1717,23 +1967,12 @@ void av_opt_free(void *obj)
{
const AVOption *o = NULL;
while ((o = av_opt_next(obj, o))) {
- switch (o->type) {
- case AV_OPT_TYPE_STRING:
- case AV_OPT_TYPE_BINARY:
- av_freep((uint8_t *)obj + o->offset);
- break;
+ void *pitem = (uint8_t *)obj + o->offset;
- case AV_OPT_TYPE_DICT:
- av_dict_free((AVDictionary **)(((uint8_t *)obj) + o->offset));
- break;
-
- case AV_OPT_TYPE_CHLAYOUT:
- av_channel_layout_uninit((AVChannelLayout *)(((uint8_t *)obj) + o->offset));
- break;
-
- default:
- break;
- }
+ if (o->flags & AV_OPT_FLAG_ARRAY)
+ opt_free_array(o, pitem, opt_array_pcount(pitem));
+ else
+ opt_free_elem(o, pitem);
}
}
@@ -1835,7 +2074,9 @@ const AVClass *av_opt_child_class_iterate(const AVClass *parent, void **iter)
void *av_opt_ptr(const AVClass *class, void *obj, const char *name)
{
const AVOption *opt= av_opt_find2(&class, name, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ, NULL);
- if(!opt)
+
+ // no direct access to array-type options
+ if (!opt || (opt->flags & AV_OPT_FLAG_ARRAY))
return NULL;
return (uint8_t*)obj + opt->offset;
}
@@ -2067,6 +2308,23 @@ int av_opt_is_set_to_default(void *obj, const AVOption *o)
dst = ((uint8_t*)obj) + o->offset;
+ if (o->flags & AV_OPT_FLAG_ARRAY) {
+ uint8_t *val;
+
+ ret = opt_get_array(o, dst, &val);
+ if (ret < 0)
+ return ret;
+
+ if (!!val != !!o->default_val.str)
+ ret = 0;
+ else if (val)
+ ret = !strcmp(val, o->default_val.str + 1);
+
+ av_freep(&val);
+
+ return ret;
+ }
+
switch (o->type) {
case AV_OPT_TYPE_CONST:
return 1;
diff --git a/libavutil/opt.h b/libavutil/opt.h
index e34b8506f8..c5678c0296 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -288,6 +288,16 @@ enum AVOptionType{
*/
#define AV_OPT_FLAG_CHILD_CONSTS (1 << 18)
+/**
+ * The option is an array.
+ *
+ * When adding array options to an object, @ref AVOption.offset should refer to
+ * a pointer corresponding to the option type. The pointer should be immediately
+ * followed by an unsigned int that will store the number of elements in the
+ * array.
+ */
+#define AV_OPT_FLAG_ARRAY (1 << 19)
+
/**
* AVOption
*/
@@ -313,6 +323,16 @@ typedef struct AVOption {
union {
int64_t i64;
double dbl;
+
+ /**
+ * This member is always used for AV_OPT_FLAG_ARRAY options. When
+ * non-NULL, the first character of the string must be the separator to
+ * be used for (de)serializing lists to/from strings with av_opt_get(),
+ * av_opt_set(), and similar. The separator must not conflict with valid
+ * option names or be a backslash. When the value is null, comma is used
+ * as the separator. The rest of the string is parsed as for
+ * av_opt_set().
+ */
const char *str;
/* TODO those are unused now */
AVRational q;
@@ -325,6 +345,12 @@ typedef struct AVOption {
*/
int flags;
+ /**
+ * For options flagged with AV_OPT_FLAG_ARRAY, this specifies the maximum
+ * number of elements that can be added to it.
+ */
+ unsigned array_max_size;
+
/**
* The logical unit to which the option belongs. Non-constant
* options and corresponding named constants share the same
diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c
index e2582cc93d..5b218b6b0a 100644
--- a/libavutil/tests/opt.c
+++ b/libavutil/tests/opt.c
@@ -57,6 +57,12 @@ typedef struct TestContext {
int bool3;
AVDictionary *dict1;
AVDictionary *dict2;
+
+ char **array_str;
+ unsigned nb_array_str;
+
+ AVDictionary **array_dict;
+ unsigned nb_array_dict;
} TestContext;
#define OFFSET(x) offsetof(TestContext, x)
@@ -93,6 +99,9 @@ static const AVOption test_options[]= {
{"bool3", "set boolean value", OFFSET(bool3), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, 1 },
{"dict1", "set dictionary value", OFFSET(dict1), AV_OPT_TYPE_DICT, { .str = NULL}, 0, 0, 1 },
{"dict2", "set dictionary value", OFFSET(dict2), AV_OPT_TYPE_DICT, { .str = "happy=':-)'"}, 0, 0, 1 },
+ {"array_str", "array of strings", OFFSET(array_str), AV_OPT_TYPE_STRING, { .str = "|str0|str\\|1|str\\\\2" }, .flags = AV_OPT_FLAG_ARRAY },
+ // there are three levels of escaping - C string, array option, dict - so 8 backslashes are needed to get a literal one inside a dict key/val
+ {"array_dict", "array of dicts", OFFSET(array_dict), AV_OPT_TYPE_DICT, { .str = ",k00=v\\\\\\\\00:k01=v\\,01,k10=v\\\\=1\\\\:0" }, .flags = AV_OPT_FLAG_ARRAY },
{ NULL },
};
@@ -146,6 +155,17 @@ int main(void)
printf("flt=%.6f\n", test_ctx.flt);
printf("dbl=%.6f\n", test_ctx.dbl);
+ for (unsigned i = 0; i < test_ctx.nb_array_str; i++)
+ printf("array_str[%u]=%s\n", i, test_ctx.array_str[i]);
+
+ for (unsigned i = 0; i < test_ctx.nb_array_dict; i++) {
+ AVDictionary *d = test_ctx.array_dict[i];
+ const AVDictionaryEntry *e = NULL;
+
+ while ((e = av_dict_iterate(d, e)))
+ printf("array_dict[%u]: %s\t%s\n", i, e->key, e->value);
+ }
+
av_opt_show2(&test_ctx, NULL, -1, 0);
av_opt_free(&test_ctx);
@@ -177,6 +197,9 @@ int main(void)
TestContext test_ctx = { 0 };
TestContext test2_ctx = { 0 };
const AVOption *o = NULL;
+ char *val = NULL;
+ int ret;
+
test_ctx.class = &test_class;
test2_ctx.class = &test_class;
@@ -209,6 +232,17 @@ int main(void)
av_free(value1);
av_free(value2);
}
+
+ // av_opt_set(NULL) with an array option resets it
+ ret = av_opt_set(&test_ctx, "array_dict", NULL, 0);
+ printf("av_opt_set(\"array_dict\", NULL) -> %d\n", ret);
+ printf("array_dict=%sNULL; nb_array_dict=%u\n",
+ test_ctx.array_dict ? "non-" : "", test_ctx.nb_array_dict);
+
+ // av_opt_get() on an empty array should return a NULL string
+ ret = av_opt_get(&test_ctx, "array_dict", AV_OPT_ALLOW_NULL, (uint8_t**)&val);
+ printf("av_opt_get(\"array_dict\") -> %s\n", val ? val : "NULL");
+
av_opt_free(&test_ctx);
av_opt_free(&test2_ctx);
}
diff --git a/tests/ref/fate/opt b/tests/ref/fate/opt
index 832f9cc8a9..4ed632fea8 100644
--- a/tests/ref/fate/opt
+++ b/tests/ref/fate/opt
@@ -17,6 +17,12 @@ binary_size=4
num64=1
flt=0.333333
dbl=0.333333
+array_str[0]=str0
+array_str[1]=str|1
+array_str[2]=str\2
+array_dict[0]: k00 v\00
+array_dict[0]: k01 v,01
+array_dict[1]: k10 v=1:0
TestContext AVOptions:
-num <int> E.......... set num (from 0 to 100) (default 0)
-toggle <int> E.......... set toggle (from 0 to 1) (default 1)
@@ -45,6 +51,8 @@ TestContext AVOptions:
-bool3 <boolean> E.......... set boolean value (default false)
-dict1 <dictionary> E.......... set dictionary value
-dict2 <dictionary> E.......... set dictionary value (default "happy=':-)'")
+ -array_str ×<string> ........... array of strings (default "|str0|str\|1|str\\2")
+ -array_dict ×<dictionary> ........... array of dicts (default ",k00=v\\\\00:k01=v\,01,k10=v\\=1\\:0")
Testing av_opt_is_set_to_default()
name: num default:1 error:
@@ -74,6 +82,8 @@ name: bool2 default:0 error:
name: bool3 default:1 error:
name: dict1 default:1 error:
name: dict2 default:0 error:
+name: array_str default:0 error:
+name:array_dict default:0 error:
name: num default:1 error:
name: toggle default:1 error:
name: rational default:1 error:
@@ -101,6 +111,8 @@ name: bool2 default:1 error:
name: bool3 default:1 error:
name: dict1 default:1 error:
name: dict2 default:1 error:
+name: array_str default:1 error:
+name:array_dict default:1 error:
Testing av_opt_get/av_opt_set()
name: num get: 0 set: OK get: 0 OK
@@ -127,9 +139,14 @@ name: bool2 get: true set: OK get: true
name: bool3 get: false set: OK get: false OK
name: dict1 get: set: OK get: OK
name: dict2 get: happy=\:-) set: OK get: happy=\:-) OK
+name: array_str get: str0|str\|1|str\\2 set: OK get: str0|str\|1|str\\2 OK
+name: array_dict get: k00=v\\\\00:k01=v\,01,k10=v\\=1\\:0 set: OK get: k00=v\\\\00:k01=v\,01,k10=v\\=1\\:0 OK
+av_opt_set("array_dict", NULL) -> 0
+array_dict=NULL; nb_array_dict=0
+av_opt_get("array_dict") -> NULL
Test av_opt_serialize()
-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=1,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-)
+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=1,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-),array_str=str0|str\\|1|str\\\\2,array_dict=k00\=v\\\\\\\\00:k01\=v\\\,01\,k10\=v\\\\\=1\\\\:0
Setting entry with key 'num' to value '0'
Setting entry with key 'toggle' to value '1'
Setting entry with key 'rational' to value '1/1'
@@ -154,7 +171,9 @@ Setting entry with key 'bool2' to value 'true'
Setting entry with key 'bool3' to value 'false'
Setting entry with key 'dict1' to value ''
Setting entry with key 'dict2' to value 'happy=\:-)'
-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=1,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-)
+Setting entry with key 'array_str' to value 'str0|str\|1|str\\2'
+Setting entry with key 'array_dict' to value 'k00=v\\\\00:k01=v\,01,k10=v\\=1\\:0'
+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=1,flt=0.333333,dbl=0.333333,bool1=auto,bool2=true,bool3=false,dict1=,dict2=happy\=\\:-),array_str=str0|str\\|1|str\\\\2,array_dict=k00\=v\\\\\\\\00:k01\=v\\\,01\,k10\=v\\\\\=1\\\\:0
Testing av_set_options_string()
Setting options string ''
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 15/38] lavu/opt: add array options
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 15/38] lavu/opt: add array options Anton Khirnov
@ 2024-02-23 19:05 ` Marton Balint
2024-02-26 17:14 ` Anton Khirnov
0 siblings, 1 reply; 63+ messages in thread
From: Marton Balint @ 2024-02-23 19:05 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Fri, 23 Feb 2024, Anton Khirnov wrote:
> AVOption.array_max_size is added before AVOption.unit to avoid
> increasing sizeof(AVOption).
> ---
> doc/APIchanges | 3 +
> libavutil/opt.c | 344 ++++++++++++++++++++++++++++++++++++------
> libavutil/opt.h | 26 ++++
> libavutil/tests/opt.c | 34 +++++
> tests/ref/fate/opt | 23 ++-
> 5 files changed, 385 insertions(+), 45 deletions(-)
>
[...]
> --- a/libavutil/opt.h
> +++ b/libavutil/opt.h
> @@ -288,6 +288,16 @@ enum AVOptionType{
> */
> #define AV_OPT_FLAG_CHILD_CONSTS (1 << 18)
>
> +/**
> + * The option is an array.
> + *
> + * When adding array options to an object, @ref AVOption.offset should refer to
> + * a pointer corresponding to the option type. The pointer should be immediately
> + * followed by an unsigned int that will store the number of elements in the
> + * array.
> + */
> +#define AV_OPT_FLAG_ARRAY (1 << 19)
> +
> /**
> * AVOption
> */
> @@ -313,6 +323,16 @@ typedef struct AVOption {
> union {
> int64_t i64;
> double dbl;
> +
> + /**
> + * This member is always used for AV_OPT_FLAG_ARRAY options. When
> + * non-NULL, the first character of the string must be the separator to
> + * be used for (de)serializing lists to/from strings with av_opt_get(),
This is quite ugly. Also it breaks the assumption that if the user sets an
option value to the default value of the option, than it will work. So
let's just remove this feature for now.
Eventually I think some new struct should be introduced, e.g.
AVOptionExtension, which can be used to specify additional option
settings, such as array min/max size, and maybe separator. It would be a
lot more clean and future proof than filling the holes in AVOption.
Regards,
Marton
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 15/38] lavu/opt: add array options
2024-02-23 19:05 ` Marton Balint
@ 2024-02-26 17:14 ` Anton Khirnov
2024-02-26 17:19 ` James Almer
` (2 more replies)
0 siblings, 3 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-26 17:14 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Marton Balint (2024-02-23 20:05:06)
>
>
> On Fri, 23 Feb 2024, Anton Khirnov wrote:
>
> > AVOption.array_max_size is added before AVOption.unit to avoid
> > increasing sizeof(AVOption).
> > ---
> > doc/APIchanges | 3 +
> > libavutil/opt.c | 344 ++++++++++++++++++++++++++++++++++++------
> > libavutil/opt.h | 26 ++++
> > libavutil/tests/opt.c | 34 +++++
> > tests/ref/fate/opt | 23 ++-
> > 5 files changed, 385 insertions(+), 45 deletions(-)
> >
> [...]
>
> > --- a/libavutil/opt.h
> > +++ b/libavutil/opt.h
> > @@ -288,6 +288,16 @@ enum AVOptionType{
> > */
> > #define AV_OPT_FLAG_CHILD_CONSTS (1 << 18)
> >
> > +/**
> > + * The option is an array.
> > + *
> > + * When adding array options to an object, @ref AVOption.offset should refer to
> > + * a pointer corresponding to the option type. The pointer should be immediately
> > + * followed by an unsigned int that will store the number of elements in the
> > + * array.
> > + */
> > +#define AV_OPT_FLAG_ARRAY (1 << 19)
> > +
> > /**
> > * AVOption
> > */
> > @@ -313,6 +323,16 @@ typedef struct AVOption {
> > union {
> > int64_t i64;
> > double dbl;
> > +
> > + /**
> > + * This member is always used for AV_OPT_FLAG_ARRAY options. When
> > + * non-NULL, the first character of the string must be the separator to
> > + * be used for (de)serializing lists to/from strings with av_opt_get(),
>
> This is quite ugly. Also it breaks the assumption that if the user sets an
> option value to the default value of the option, than it will work.
I don't follow, what assumption are you talking about?
> So let's just remove this feature for now.
>
> Eventually I think some new struct should be introduced, e.g.
> AVOptionExtension, which can be used to specify additional option
> settings, such as array min/max size, and maybe separator. It would be a
> lot more clean and future proof than filling the holes in AVOption.
I've actually considered that, but don't see a clean way of linking such
an extension with its option. We only have an int-sized hole, so can't
add a new pointer field to AVOption. I suppose there could be a new
array of extensions in AVClass, linked to options by name, but that
seems even more ugly and inefficient.
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 15/38] lavu/opt: add array options
2024-02-26 17:14 ` Anton Khirnov
@ 2024-02-26 17:19 ` James Almer
2024-02-26 17:20 ` Andreas Rheinhardt
2024-02-26 19:38 ` Marton Balint
2 siblings, 0 replies; 63+ messages in thread
From: James Almer @ 2024-02-26 17:19 UTC (permalink / raw)
To: ffmpeg-devel
On 2/26/2024 2:14 PM, Anton Khirnov wrote:
> Quoting Marton Balint (2024-02-23 20:05:06)
>>
>>
>> On Fri, 23 Feb 2024, Anton Khirnov wrote:
>>
>>> AVOption.array_max_size is added before AVOption.unit to avoid
>>> increasing sizeof(AVOption).
>>> ---
>>> doc/APIchanges | 3 +
>>> libavutil/opt.c | 344 ++++++++++++++++++++++++++++++++++++------
>>> libavutil/opt.h | 26 ++++
>>> libavutil/tests/opt.c | 34 +++++
>>> tests/ref/fate/opt | 23 ++-
>>> 5 files changed, 385 insertions(+), 45 deletions(-)
>>>
>> [...]
>>
>>> --- a/libavutil/opt.h
>>> +++ b/libavutil/opt.h
>>> @@ -288,6 +288,16 @@ enum AVOptionType{
>>> */
>>> #define AV_OPT_FLAG_CHILD_CONSTS (1 << 18)
>>>
>>> +/**
>>> + * The option is an array.
>>> + *
>>> + * When adding array options to an object, @ref AVOption.offset should refer to
>>> + * a pointer corresponding to the option type. The pointer should be immediately
>>> + * followed by an unsigned int that will store the number of elements in the
>>> + * array.
>>> + */
>>> +#define AV_OPT_FLAG_ARRAY (1 << 19)
>>> +
>>> /**
>>> * AVOption
>>> */
>>> @@ -313,6 +323,16 @@ typedef struct AVOption {
>>> union {
>>> int64_t i64;
>>> double dbl;
>>> +
>>> + /**
>>> + * This member is always used for AV_OPT_FLAG_ARRAY options. When
>>> + * non-NULL, the first character of the string must be the separator to
>>> + * be used for (de)serializing lists to/from strings with av_opt_get(),
>>
>> This is quite ugly. Also it breaks the assumption that if the user sets an
>> option value to the default value of the option, than it will work.
>
> I don't follow, what assumption are you talking about?
>
>> So let's just remove this feature for now.
>>
>> Eventually I think some new struct should be introduced, e.g.
>> AVOptionExtension, which can be used to specify additional option
>> settings, such as array min/max size, and maybe separator. It would be a
>> lot more clean and future proof than filling the holes in AVOption.
>
> I've actually considered that, but don't see a clean way of linking such
> an extension with its option. We only have an int-sized hole, so can't
> add a new pointer field to AVOption.
If there's no other solution, then adding a new field is ok.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 15/38] lavu/opt: add array options
2024-02-26 17:14 ` Anton Khirnov
2024-02-26 17:19 ` James Almer
@ 2024-02-26 17:20 ` Andreas Rheinhardt
2024-02-26 19:38 ` Marton Balint
2 siblings, 0 replies; 63+ messages in thread
From: Andreas Rheinhardt @ 2024-02-26 17:20 UTC (permalink / raw)
To: ffmpeg-devel
Anton Khirnov:
> Quoting Marton Balint (2024-02-23 20:05:06)
>>
>>
>> On Fri, 23 Feb 2024, Anton Khirnov wrote:
>>
>>> AVOption.array_max_size is added before AVOption.unit to avoid
>>> increasing sizeof(AVOption).
>>> ---
>>> doc/APIchanges | 3 +
>>> libavutil/opt.c | 344 ++++++++++++++++++++++++++++++++++++------
>>> libavutil/opt.h | 26 ++++
>>> libavutil/tests/opt.c | 34 +++++
>>> tests/ref/fate/opt | 23 ++-
>>> 5 files changed, 385 insertions(+), 45 deletions(-)
>>>
>> [...]
>>
>>> --- a/libavutil/opt.h
>>> +++ b/libavutil/opt.h
>>> @@ -288,6 +288,16 @@ enum AVOptionType{
>>> */
>>> #define AV_OPT_FLAG_CHILD_CONSTS (1 << 18)
>>>
>>> +/**
>>> + * The option is an array.
>>> + *
>>> + * When adding array options to an object, @ref AVOption.offset should refer to
>>> + * a pointer corresponding to the option type. The pointer should be immediately
>>> + * followed by an unsigned int that will store the number of elements in the
>>> + * array.
>>> + */
>>> +#define AV_OPT_FLAG_ARRAY (1 << 19)
>>> +
>>> /**
>>> * AVOption
>>> */
>>> @@ -313,6 +323,16 @@ typedef struct AVOption {
>>> union {
>>> int64_t i64;
>>> double dbl;
>>> +
>>> + /**
>>> + * This member is always used for AV_OPT_FLAG_ARRAY options. When
>>> + * non-NULL, the first character of the string must be the separator to
>>> + * be used for (de)serializing lists to/from strings with av_opt_get(),
>>
>> This is quite ugly. Also it breaks the assumption that if the user sets an
>> option value to the default value of the option, than it will work.
>
> I don't follow, what assumption are you talking about?
>
>> So let's just remove this feature for now.
>>
>> Eventually I think some new struct should be introduced, e.g.
>> AVOptionExtension, which can be used to specify additional option
>> settings, such as array min/max size, and maybe separator. It would be a
>> lot more clean and future proof than filling the holes in AVOption.
>
> I've actually considered that, but don't see a clean way of linking such
> an extension with its option. We only have an int-sized hole, so can't
> add a new pointer field to AVOption. I suppose there could be a new
> array of extensions in AVClass, linked to options by name, but that
> seems even more ugly and inefficient.
>
You could add an AVArrayOption struct and use a pointer to such a struct
as default value for an array option. Then you would not be constrained
by an int-sized hole.
- Andreas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 15/38] lavu/opt: add array options
2024-02-26 17:14 ` Anton Khirnov
2024-02-26 17:19 ` James Almer
2024-02-26 17:20 ` Andreas Rheinhardt
@ 2024-02-26 19:38 ` Marton Balint
2024-03-03 14:55 ` Anton Khirnov
2 siblings, 1 reply; 63+ messages in thread
From: Marton Balint @ 2024-02-26 19:38 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Mon, 26 Feb 2024, Anton Khirnov wrote:
> Quoting Marton Balint (2024-02-23 20:05:06)
>>
>>
>> On Fri, 23 Feb 2024, Anton Khirnov wrote:
>>
>>> AVOption.array_max_size is added before AVOption.unit to avoid
>>> increasing sizeof(AVOption).
>>> ---
>>> doc/APIchanges | 3 +
>>> libavutil/opt.c | 344 ++++++++++++++++++++++++++++++++++++------
>>> libavutil/opt.h | 26 ++++
>>> libavutil/tests/opt.c | 34 +++++
>>> tests/ref/fate/opt | 23 ++-
>>> 5 files changed, 385 insertions(+), 45 deletions(-)
>>>
>> [...]
>>
>>> --- a/libavutil/opt.h
>>> +++ b/libavutil/opt.h
>>> @@ -288,6 +288,16 @@ enum AVOptionType{
>>> */
>>> #define AV_OPT_FLAG_CHILD_CONSTS (1 << 18)
>>>
>>> +/**
>>> + * The option is an array.
>>> + *
>>> + * When adding array options to an object, @ref AVOption.offset should refer to
>>> + * a pointer corresponding to the option type. The pointer should be immediately
>>> + * followed by an unsigned int that will store the number of elements in the
>>> + * array.
>>> + */
>>> +#define AV_OPT_FLAG_ARRAY (1 << 19)
>>> +
>>> /**
>>> * AVOption
>>> */
>>> @@ -313,6 +323,16 @@ typedef struct AVOption {
>>> union {
>>> int64_t i64;
>>> double dbl;
>>> +
>>> + /**
>>> + * This member is always used for AV_OPT_FLAG_ARRAY options. When
>>> + * non-NULL, the first character of the string must be the separator to
>>> + * be used for (de)serializing lists to/from strings with av_opt_get(),
>>
>> This is quite ugly. Also it breaks the assumption that if the user sets an
>> option value to the default value of the option, than it will work.
>
> I don't follow, what assumption are you talking about?
The more I think about it, it is actually a broader problem.
You are changing the semantics of existing AV_OPT_TYPE_xxx types. So
previously an option with AV_OPT_TYPE_STRING used to have default value in
default_val.str. After your patch, it will be either default_val.str, or
default_val.str[1], based on if it is an array or not.
I think the API user safely assumed that if the option type is known to
him, he will always find the default value in the relevant default_val
field. It is actually a bigger issue for an array of AV_OPT_TYPE_INT,
because previously to get the default value AVOption->default_val.i64 was
used, and now .str[1] should be instead...
The way I see it, the ARRAY modifier should either be a flag/mask of the
option type (not AVOption->flags), or it should be a entierly new type,
AV_OPT_TYPE_ARRAY, and its base type should be stored elsewhere.
For new opt types, we can define the semantics of default_val as we want,
so Andreas's suggestion is good to make default_val point to an
AVArrayOptionSettings struct or something like that.
Regards,
Marton
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 15/38] lavu/opt: add array options
2024-02-26 19:38 ` Marton Balint
@ 2024-03-03 14:55 ` Anton Khirnov
2024-03-03 15:53 ` Diederick C. Niehorster
0 siblings, 1 reply; 63+ messages in thread
From: Anton Khirnov @ 2024-03-03 14:55 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Marton Balint (2024-02-26 20:38:46)
> The more I think about it, it is actually a broader problem.
>
> You are changing the semantics of existing AV_OPT_TYPE_xxx types. So
> previously an option with AV_OPT_TYPE_STRING used to have default value in
> default_val.str. After your patch, it will be either default_val.str, or
> default_val.str[1], based on if it is an array or not.
>
> I think the API user safely assumed that if the option type is known to
> him, he will always find the default value in the relevant default_val
> field. It is actually a bigger issue for an array of AV_OPT_TYPE_INT,
> because previously to get the default value AVOption->default_val.i64 was
> used, and now .str[1] should be instead...
In my view the semantics of default_val (and offset) are only defined
when declaring options on your own object, not when accessing those
fields when declared by some other code. I also see no good reason for
any user to read these fields.
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 15/38] lavu/opt: add array options
2024-03-03 14:55 ` Anton Khirnov
@ 2024-03-03 15:53 ` Diederick C. Niehorster
2024-03-03 15:57 ` James Almer
0 siblings, 1 reply; 63+ messages in thread
From: Diederick C. Niehorster @ 2024-03-03 15:53 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Sun, Mar 3, 2024 at 3:55 PM Anton Khirnov <anton@khirnov.net> wrote:
> Quoting Marton Balint (2024-02-26 20:38:46)
> > The more I think about it, it is actually a broader problem.
> >
> > You are changing the semantics of existing AV_OPT_TYPE_xxx types. So
> > previously an option with AV_OPT_TYPE_STRING used to have default value
> in
> > default_val.str. After your patch, it will be either default_val.str, or
> > default_val.str[1], based on if it is an array or not.
> >
> > I think the API user safely assumed that if the option type is known to
> > him, he will always find the default value in the relevant default_val
> > field. It is actually a bigger issue for an array of AV_OPT_TYPE_INT,
> > because previously to get the default value AVOption->default_val.i64
> was
> > used, and now .str[1] should be instead...
>
> In my view the semantics of default_val (and offset) are only defined
> when declaring options on your own object, not when accessing those
> fields when declared by some other code. I also see no good reason for
> any user to read these fields.
>
I disagree. Here an example: for a GUI using some part of ffmpeg and
wanting to give the user some control over the ffmpeg operation, it would
not be strange to be able to set options and either indicate which values
are default, or have a "reset to defaults" button. I have written such a
thing (not yet opensourced).
Also the ffmpeg CLI has the ability to print the options and their defaults
for a component. Can this still be done?
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 15/38] lavu/opt: add array options
2024-03-03 15:53 ` Diederick C. Niehorster
@ 2024-03-03 15:57 ` James Almer
2024-03-03 21:05 ` Marton Balint
0 siblings, 1 reply; 63+ messages in thread
From: James Almer @ 2024-03-03 15:57 UTC (permalink / raw)
To: ffmpeg-devel
On 3/3/2024 12:53 PM, Diederick C. Niehorster wrote:
> On Sun, Mar 3, 2024 at 3:55 PM Anton Khirnov <anton@khirnov.net> wrote:
>
>> Quoting Marton Balint (2024-02-26 20:38:46)
>>> The more I think about it, it is actually a broader problem.
>>>
>>> You are changing the semantics of existing AV_OPT_TYPE_xxx types. So
>>> previously an option with AV_OPT_TYPE_STRING used to have default value
>> in
>>> default_val.str. After your patch, it will be either default_val.str, or
>>> default_val.str[1], based on if it is an array or not.
>>>
>>> I think the API user safely assumed that if the option type is known to
>>> him, he will always find the default value in the relevant default_val
>>> field. It is actually a bigger issue for an array of AV_OPT_TYPE_INT,
>>> because previously to get the default value AVOption->default_val.i64
>> was
>>> used, and now .str[1] should be instead...
>>
>> In my view the semantics of default_val (and offset) are only defined
>> when declaring options on your own object, not when accessing those
>> fields when declared by some other code. I also see no good reason for
>> any user to read these fields.
>>
>
> I disagree. Here an example: for a GUI using some part of ffmpeg and
> wanting to give the user some control over the ffmpeg operation, it would
> not be strange to be able to set options and either indicate which values
> are default, or have a "reset to defaults" button. I have written such a
> thing (not yet opensourced).
There's av_opt_set_defaults() to set default values, then
av_opt_is_set_to_default() and av_opt_is_set_to_default_by_name() to
check if an option is already set to the default value.
What Anton said is that the user has no need to access the fields
directly when there are helpers explicitly documented for this purpose.
>
> Also the ffmpeg CLI has the ability to print the options and their defaults
> for a component. Can this still be done?
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 15/38] lavu/opt: add array options
2024-03-03 15:57 ` James Almer
@ 2024-03-03 21:05 ` Marton Balint
0 siblings, 0 replies; 63+ messages in thread
From: Marton Balint @ 2024-03-03 21:05 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Sun, 3 Mar 2024, James Almer wrote:
> On 3/3/2024 12:53 PM, Diederick C. Niehorster wrote:
>> On Sun, Mar 3, 2024 at 3:55 PM Anton Khirnov <anton@khirnov.net> wrote:
>>
>>> Quoting Marton Balint (2024-02-26 20:38:46)
>>>> The more I think about it, it is actually a broader problem.
>>>>
>>>> You are changing the semantics of existing AV_OPT_TYPE_xxx types. So
>>>> previously an option with AV_OPT_TYPE_STRING used to have default value
>>> in
>>>> default_val.str. After your patch, it will be either default_val.str, or
>>>> default_val.str[1], based on if it is an array or not.
>>>>
>>>> I think the API user safely assumed that if the option type is known to
>>>> him, he will always find the default value in the relevant default_val
>>>> field. It is actually a bigger issue for an array of AV_OPT_TYPE_INT,
>>>> because previously to get the default value AVOption->default_val.i64
>>> was
>>>> used, and now .str[1] should be instead...
>>>
>>> In my view the semantics of default_val (and offset) are only defined
>>> when declaring options on your own object, not when accessing those
>>> fields when declared by some other code. I also see no good reason for
>>> any user to read these fields.
>>>
>>
>> I disagree. Here an example: for a GUI using some part of ffmpeg and
>> wanting to give the user some control over the ffmpeg operation, it would
>> not be strange to be able to set options and either indicate which values
>> are default, or have a "reset to defaults" button. I have written such a
>> thing (not yet opensourced).
>
> There's av_opt_set_defaults() to set default values, then
> av_opt_is_set_to_default() and av_opt_is_set_to_default_by_name() to check if
> an option is already set to the default value.
>
> What Anton said is that the user has no need to access the fields directly
> when there are helpers explicitly documented for this purpose.
The AVOption struct is public, and the default_val field is public too.
There is nothing that warns the user not to access it. The fact that there
are helper functions does not change this.
But it is not the default values that is a problem. The semantic change is
the problem. I could have had a code which iterates through every AVOption
of an object and prints the values with type AV_OPT_TYPE_INT. Your change
will suddently break that, because arrays will also have the type of
AV_OPT_TYPE_INT.
So can you please introduce a new option type for arrays?
Thanks,
Marton
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 16/38] lavc: add a decoder option for configuring side data preference
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (14 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 15/38] lavu/opt: add array options Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 17:51 ` Marton Balint
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 17/38] avcodec: add internal side data wrappers Anton Khirnov
` (21 subsequent siblings)
37 siblings, 1 reply; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
This and the following commits fix #10857
---
doc/APIchanges | 3 +++
libavcodec/avcodec.h | 20 ++++++++++++++++++++
libavcodec/decode.c | 36 ++++++++++++++++++++++++++++++++++++
libavcodec/options_table.h | 12 ++++++++++++
4 files changed, 71 insertions(+)
diff --git a/doc/APIchanges b/doc/APIchanges
index 371fd2f465..78744a674a 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
API changes, most recent first:
+2024-02-xx - xxxxxxxxxx - lavc 60.xx.100 - avcodec.h
+ Add AVCodecContext.[nb_]side_data_prefer_global.
+
2024-02-xx - xxxxxxxxxx - lavu 58.xx.100 - opt.h
Add AV_OPT_FLAG_ARRAY and AVOption.array_max_size.
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 43859251cc..307a3e99db 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2120,6 +2120,26 @@ typedef struct AVCodecContext {
* an error.
*/
int64_t frame_num;
+
+ /**
+ * Decoding only. May be set by the caller before avcodec_open2() to an
+ * av_malloc()'ed array (or via AVOptions). Owned and freed by the decoder
+ * afterwards.
+ *
+ * By default, when some side data type is present both in global
+ * user-supplied coded_side_data and inside the coded bitstream, avcodec
+ * will propagate the latter to the decoded frame.
+ *
+ * This array contains a list of AVPacketSideDataType for which this
+ * preference should be switched, i.e. avcodec will prefer global side data
+ * over those in stored in the bytestream. It may also contain a single -1,
+ * in which case the preference is switched for all side data types.
+ */
+ int *side_data_prefer_global;
+ /**
+ * Number of entries in side_data_prefer_global.
+ */
+ unsigned nb_side_data_prefer_global;
} AVCodecContext;
/**
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index da6446d879..5524e229c2 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -60,6 +60,12 @@ typedef struct DecodeContext {
* The caller has submitted a NULL packet on input.
*/
int draining_started;
+
+ /**
+ * Bitmask indicating for which side data types we prefer global
+ * side data over per-packet.
+ */
+ uint64_t side_data_pref_mask;
} DecodeContext;
static DecodeContext *decode_ctx(AVCodecInternal *avci)
@@ -1744,6 +1750,7 @@ int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
int ff_decode_preinit(AVCodecContext *avctx)
{
AVCodecInternal *avci = avctx->internal;
+ DecodeContext *dc = decode_ctx(avci);
int ret = 0;
/* if the decoder init function was already called previously,
@@ -1804,6 +1811,35 @@ int ff_decode_preinit(AVCodecContext *avctx)
avctx->export_side_data |= AV_CODEC_EXPORT_DATA_MVS;
}
+ if (avctx->nb_side_data_prefer_global == 1 &&
+ avctx->side_data_prefer_global[0] == -1)
+ dc->side_data_pref_mask = ~0ULL;
+ else {
+ for (unsigned i = 0; i < avctx->nb_side_data_prefer_global; i++) {
+ int val = avctx->side_data_prefer_global[i];
+
+ if (val < 0 || val >= AV_PKT_DATA_NB) {
+ av_log(avctx, AV_LOG_ERROR, "Invalid side data type: %d\n", val);
+ return AVERROR(EINVAL);
+ }
+
+ for (unsigned j = 0; j < FF_ARRAY_ELEMS(sd_global_map); j++) {
+ if (sd_global_map[j].packet == val) {
+ val = sd_global_map[j].frame;
+
+ // this code will need to be changed when we have more than
+ // 64 frame side data types
+ if (val >= 64) {
+ av_log(avctx, AV_LOG_ERROR, "Side data type too big\n");
+ return AVERROR_BUG;
+ }
+
+ dc->side_data_pref_mask |= 1ULL << val;
+ }
+ }
+ }
+ }
+
avci->in_pkt = av_packet_alloc();
avci->last_pkt_props = av_packet_alloc();
if (!avci->in_pkt || !avci->last_pkt_props)
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index ac32d8928a..2f4f60218c 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -41,6 +41,7 @@
#define E AV_OPT_FLAG_ENCODING_PARAM
#define D AV_OPT_FLAG_DECODING_PARAM
#define CC AV_OPT_FLAG_CHILD_CONSTS
+#define AR AV_OPT_FLAG_ARRAY
#define AV_CODEC_DEFAULT_BITRATE 200*1000
@@ -405,6 +406,17 @@ static const AVOption avcodec_options[] = {
{"unsafe_output", "allow potentially unsafe hwaccel frame output that might require special care to process successfully", 0, AV_OPT_TYPE_CONST, {.i64 = AV_HWACCEL_FLAG_UNSAFE_OUTPUT }, INT_MIN, INT_MAX, V | D, .unit = "hwaccel_flags"},
{"extra_hw_frames", "Number of extra hardware frames to allocate for the user", OFFSET(extra_hw_frames), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, V|D },
{"discard_damaged_percentage", "Percentage of damaged samples to discard a frame", OFFSET(discard_damaged_percentage), AV_OPT_TYPE_INT, {.i64 = 95 }, 0, 100, V|D },
+{"side_data_prefer_global", "Comma-separated list of side data types for which global headers are preferred over frame-level data",
+ OFFSET(side_data_prefer_global), AV_OPT_TYPE_INT, .min = -1, .max = INT_MAX, .flags = V|A|S|D|AR, .unit = "side_data_pkt" },
+ {"replaygain", .default_val.i64 = AV_PKT_DATA_REPLAYGAIN, .type = AV_OPT_TYPE_CONST, .flags = A|D, .unit = "side_data_pkt" },
+ {"displaymatrix", .default_val.i64 = AV_PKT_DATA_DISPLAYMATRIX, .type = AV_OPT_TYPE_CONST, .flags = A|D, .unit = "side_data_pkt" },
+ {"spherical", .default_val.i64 = AV_PKT_DATA_SPHERICAL, .type = AV_OPT_TYPE_CONST, .flags = A|D, .unit = "side_data_pkt" },
+ {"stereo3d", .default_val.i64 = AV_PKT_DATA_STEREO3D, .type = AV_OPT_TYPE_CONST, .flags = A|D, .unit = "side_data_pkt" },
+ {"audio_service_type", .default_val.i64 = AV_PKT_DATA_AUDIO_SERVICE_TYPE, .type = AV_OPT_TYPE_CONST, .flags = A|D, .unit = "side_data_pkt" },
+ {"mastering_display_metadata", .default_val.i64 = AV_PKT_DATA_MASTERING_DISPLAY_METADATA, .type = AV_OPT_TYPE_CONST, .flags = A|D, .unit = "side_data_pkt" },
+ {"content_light_level", .default_val.i64 = AV_PKT_DATA_CONTENT_LIGHT_LEVEL, .type = AV_OPT_TYPE_CONST, .flags = A|D, .unit = "side_data_pkt" },
+ {"icc_profile", .default_val.i64 = AV_PKT_DATA_ICC_PROFILE, .type = AV_OPT_TYPE_CONST, .flags = A|D, .unit = "side_data_pkt" },
+ {"dynamic_hdr10_plus", .default_val.i64 = AV_PKT_DATA_DYNAMIC_HDR10_PLUS, .type = AV_OPT_TYPE_CONST, .flags = A|D, .unit = "side_data_pkt" },
{NULL},
};
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 16/38] lavc: add a decoder option for configuring side data preference
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 16/38] lavc: add a decoder option for configuring side data preference Anton Khirnov
@ 2024-02-23 17:51 ` Marton Balint
2024-02-23 17:53 ` James Almer
0 siblings, 1 reply; 63+ messages in thread
From: Marton Balint @ 2024-02-23 17:51 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Fri, 23 Feb 2024, Anton Khirnov wrote:
> This and the following commits fix #10857
> ---
> doc/APIchanges | 3 +++
> libavcodec/avcodec.h | 20 ++++++++++++++++++++
> libavcodec/decode.c | 36 ++++++++++++++++++++++++++++++++++++
> libavcodec/options_table.h | 12 ++++++++++++
> 4 files changed, 71 insertions(+)
>
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 371fd2f465..78744a674a 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
>
> API changes, most recent first:
>
> +2024-02-xx - xxxxxxxxxx - lavc 60.xx.100 - avcodec.h
> + Add AVCodecContext.[nb_]side_data_prefer_global.
> +
> 2024-02-xx - xxxxxxxxxx - lavu 58.xx.100 - opt.h
> Add AV_OPT_FLAG_ARRAY and AVOption.array_max_size.
>
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 43859251cc..307a3e99db 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -2120,6 +2120,26 @@ typedef struct AVCodecContext {
> * an error.
> */
> int64_t frame_num;
> +
> + /**
> + * Decoding only. May be set by the caller before avcodec_open2() to an
> + * av_malloc()'ed array (or via AVOptions). Owned and freed by the decoder
> + * afterwards.
> + *
> + * By default, when some side data type is present both in global
> + * user-supplied coded_side_data and inside the coded bitstream, avcodec
> + * will propagate the latter to the decoded frame.
> + *
> + * This array contains a list of AVPacketSideDataType for which this
> + * preference should be switched, i.e. avcodec will prefer global side data
> + * over those in stored in the bytestream. It may also contain a single -1,
> + * in which case the preference is switched for all side data types.
> + */
> + int *side_data_prefer_global;
Why is this a list and AV_OPT_FLAG_ARRAY? This simply should be a mask, so
AV_OPT_TYPE_FLAGS.
Regards,
Marton
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 16/38] lavc: add a decoder option for configuring side data preference
2024-02-23 17:51 ` Marton Balint
@ 2024-02-23 17:53 ` James Almer
2024-02-23 18:34 ` James Almer
0 siblings, 1 reply; 63+ messages in thread
From: James Almer @ 2024-02-23 17:53 UTC (permalink / raw)
To: ffmpeg-devel
On 2/23/2024 2:51 PM, Marton Balint wrote:
>
>
> On Fri, 23 Feb 2024, Anton Khirnov wrote:
>
>> This and the following commits fix #10857
>> ---
>> doc/APIchanges | 3 +++
>> libavcodec/avcodec.h | 20 ++++++++++++++++++++
>> libavcodec/decode.c | 36 ++++++++++++++++++++++++++++++++++++
>> libavcodec/options_table.h | 12 ++++++++++++
>> 4 files changed, 71 insertions(+)
>>
>> diff --git a/doc/APIchanges b/doc/APIchanges
>> index 371fd2f465..78744a674a 100644
>> --- a/doc/APIchanges
>> +++ b/doc/APIchanges
>> @@ -2,6 +2,9 @@ The last version increases of all libraries were on
>> 2023-02-09
>>
>> API changes, most recent first:
>>
>> +2024-02-xx - xxxxxxxxxx - lavc 60.xx.100 - avcodec.h
>> + Add AVCodecContext.[nb_]side_data_prefer_global.
>> +
>> 2024-02-xx - xxxxxxxxxx - lavu 58.xx.100 - opt.h
>> Add AV_OPT_FLAG_ARRAY and AVOption.array_max_size.
>>
>> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
>> index 43859251cc..307a3e99db 100644
>> --- a/libavcodec/avcodec.h
>> +++ b/libavcodec/avcodec.h
>> @@ -2120,6 +2120,26 @@ typedef struct AVCodecContext {
>> * an error.
>> */
>> int64_t frame_num;
>> +
>> + /**
>> + * Decoding only. May be set by the caller before avcodec_open2()
>> to an
>> + * av_malloc()'ed array (or via AVOptions). Owned and freed by
>> the decoder
>> + * afterwards.
>> + *
>> + * By default, when some side data type is present both in global
>> + * user-supplied coded_side_data and inside the coded bitstream,
>> avcodec
>> + * will propagate the latter to the decoded frame.
>> + *
>> + * This array contains a list of AVPacketSideDataType for which this
>> + * preference should be switched, i.e. avcodec will prefer global
>> side data
>> + * over those in stored in the bytestream. It may also contain a
>> single -1,
>> + * in which case the preference is switched for all side data types.
>> + */
>> + int *side_data_prefer_global;
>
> Why is this a list and AV_OPT_FLAG_ARRAY? This simply should be a mask,
> so AV_OPT_TYPE_FLAGS.
That would effectively limit side data element types to 64.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 16/38] lavc: add a decoder option for configuring side data preference
2024-02-23 17:53 ` James Almer
@ 2024-02-23 18:34 ` James Almer
2024-02-26 17:08 ` Anton Khirnov
0 siblings, 1 reply; 63+ messages in thread
From: James Almer @ 2024-02-23 18:34 UTC (permalink / raw)
To: ffmpeg-devel
On 2/23/2024 2:53 PM, James Almer wrote:
> On 2/23/2024 2:51 PM, Marton Balint wrote:
>>
>>
>> On Fri, 23 Feb 2024, Anton Khirnov wrote:
>>
>>> This and the following commits fix #10857
>>> ---
>>> doc/APIchanges | 3 +++
>>> libavcodec/avcodec.h | 20 ++++++++++++++++++++
>>> libavcodec/decode.c | 36 ++++++++++++++++++++++++++++++++++++
>>> libavcodec/options_table.h | 12 ++++++++++++
>>> 4 files changed, 71 insertions(+)
>>>
>>> diff --git a/doc/APIchanges b/doc/APIchanges
>>> index 371fd2f465..78744a674a 100644
>>> --- a/doc/APIchanges
>>> +++ b/doc/APIchanges
>>> @@ -2,6 +2,9 @@ The last version increases of all libraries were on
>>> 2023-02-09
>>>
>>> API changes, most recent first:
>>>
>>> +2024-02-xx - xxxxxxxxxx - lavc 60.xx.100 - avcodec.h
>>> + Add AVCodecContext.[nb_]side_data_prefer_global.
>>> +
>>> 2024-02-xx - xxxxxxxxxx - lavu 58.xx.100 - opt.h
>>> Add AV_OPT_FLAG_ARRAY and AVOption.array_max_size.
>>>
>>> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
>>> index 43859251cc..307a3e99db 100644
>>> --- a/libavcodec/avcodec.h
>>> +++ b/libavcodec/avcodec.h
>>> @@ -2120,6 +2120,26 @@ typedef struct AVCodecContext {
>>> * an error.
>>> */
>>> int64_t frame_num;
>>> +
>>> + /**
>>> + * Decoding only. May be set by the caller before
>>> avcodec_open2() to an
>>> + * av_malloc()'ed array (or via AVOptions). Owned and freed by
>>> the decoder
>>> + * afterwards.
>>> + *
>>> + * By default, when some side data type is present both in global
>>> + * user-supplied coded_side_data and inside the coded bitstream,
>>> avcodec
>>> + * will propagate the latter to the decoded frame.
>>> + *
>>> + * This array contains a list of AVPacketSideDataType for which
>>> this
>>> + * preference should be switched, i.e. avcodec will prefer
>>> global side data
>>> + * over those in stored in the bytestream. It may also contain a
>>> single -1,
>>> + * in which case the preference is switched for all side data
>>> types.
>>> + */
>>> + int *side_data_prefer_global;
>>
>> Why is this a list and AV_OPT_FLAG_ARRAY? This simply should be a
>> mask, so AV_OPT_TYPE_FLAGS.
>
> That would effectively limit side data element types to 64.
Actually no, it'd be 32 since _FLAGS expects an unsigned int.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 16/38] lavc: add a decoder option for configuring side data preference
2024-02-23 18:34 ` James Almer
@ 2024-02-26 17:08 ` Anton Khirnov
0 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-26 17:08 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting James Almer (2024-02-23 19:34:51)
> Actually no, it'd be 32 since _FLAGS expects an unsigned int.
And we currently have 36 packet side data types.
Now this option can only apply to some of them, but then we'd have to
introduce some kind a of a complicated mapping scheme, and we still end
up with a rather low limit.
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 17/38] avcodec: add internal side data wrappers
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (15 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 16/38] lavc: add a decoder option for configuring side data preference Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 18/38] lavc: add content light/mastering display " Anton Khirnov
` (20 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
From: Niklas Haas <git@haasn.dev>
The signature of ff_frame_new_side_data got more complicated due to
a need to distinguish between "failed allocating side data" and "side
data was already present".
We could do something similar to ff_frame_new_side_data_from_buf, but
most callers ignore the OOM condition on this function, which is merely
re-allocating the side data array. So preserve the return signature to
make it slightly less of a pain to use.
Signed-off-by: Anton Khirnov <anton@khirnov.net>
---
libavcodec/decode.c | 47 +++++++++++++++++++++++++++++++++++++++++++++
libavcodec/decode.h | 20 +++++++++++++++++++
2 files changed, 67 insertions(+)
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 5524e229c2..10946f208a 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1857,6 +1857,53 @@ int ff_decode_preinit(AVCodecContext *avctx)
return 0;
}
+/**
+ * Check side data preference and clear existing side data from frame
+ * if needed.
+ *
+ * @retval 0 side data of this type can be added to frame
+ * @retval 1 side data of this type should not be added to frame
+ */
+static int side_data_pref(const AVCodecContext *avctx, AVFrame *frame,
+ enum AVFrameSideDataType type)
+{
+ DecodeContext *dc = decode_ctx(avctx->internal);
+
+ // Note: could be skipped for `type` without corresponding packet sd
+ if (av_frame_get_side_data(frame, type)) {
+ if (dc->side_data_pref_mask & (1ULL << type))
+ return 1;
+ av_frame_remove_side_data(frame, type);
+ }
+
+ return 0;
+}
+
+
+int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame,
+ enum AVFrameSideDataType type, size_t size,
+ AVFrameSideData **sd)
+{
+ if (side_data_pref(avctx, frame, type)) {
+ *sd = NULL;
+ return 0;
+ }
+
+ *sd = av_frame_new_side_data(frame, type, size);
+ return *sd ? 0 : AVERROR(ENOMEM);
+}
+
+AVFrameSideData *ff_frame_new_side_data_from_buf(const AVCodecContext *avctx,
+ AVFrame *frame,
+ enum AVFrameSideDataType type,
+ AVBufferRef *buf)
+{
+ if (side_data_pref(avctx, frame, type))
+ return NULL;
+
+ return av_frame_new_side_data_from_buf(frame, type, buf);
+}
+
int ff_copy_palette(void *dst, const AVPacket *src, void *logctx)
{
size_t size;
diff --git a/libavcodec/decode.h b/libavcodec/decode.h
index daf1a67444..a131b9940a 100644
--- a/libavcodec/decode.h
+++ b/libavcodec/decode.h
@@ -155,4 +155,24 @@ int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_pr
const AVPacketSideData *ff_get_coded_side_data(const AVCodecContext *avctx,
enum AVPacketSideDataType type);
+/**
+ * Wrapper around av_frame_new_side_data, which rejects side data overridden by
+ * the demuxer. Returns 0 on success, and a negative error code otherwise.
+ * If successful, *sd may either be a pointer to the new side data, or NULL
+ * in case the side data was already present.
+ */
+int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame,
+ enum AVFrameSideDataType type, size_t size,
+ AVFrameSideData **sd);
+
+/**
+ * Similar to `ff_frame_new_side_data`, but using an existing buffer ref.
+ * On success, returns the newly added side data, and passes ownership
+ * of `buf` to the frame.
+ */
+AVFrameSideData *ff_frame_new_side_data_from_buf(const AVCodecContext *avctx,
+ AVFrame *frame,
+ enum AVFrameSideDataType type,
+ AVBufferRef *buf);
+
#endif /* AVCODEC_DECODE_H */
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 18/38] lavc: add content light/mastering display side data wrappers
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (16 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 17/38] avcodec: add internal side data wrappers Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 19/38] avcodec/av1dec: respect side data preference Anton Khirnov
` (19 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
---
libavcodec/decode.c | 25 +++++++++++++++++++++++++
libavcodec/decode.h | 21 +++++++++++++++++++++
2 files changed, 46 insertions(+)
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 10946f208a..ad5525860c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -35,6 +35,7 @@
#include "libavutil/hwcontext.h"
#include "libavutil/imgutils.h"
#include "libavutil/internal.h"
+#include "libavutil/mastering_display_metadata.h"
#include "avcodec.h"
#include "avcodec_internal.h"
@@ -1904,6 +1905,30 @@ AVFrameSideData *ff_frame_new_side_data_from_buf(const AVCodecContext *avctx,
return av_frame_new_side_data_from_buf(frame, type, buf);
}
+int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame,
+ AVMasteringDisplayMetadata **mdm)
+{
+ if (side_data_pref(avctx, frame, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA)) {
+ *mdm = NULL;
+ return 0;
+ }
+
+ *mdm = av_mastering_display_metadata_create_side_data(frame);
+ return *mdm ? 0 : AVERROR(ENOMEM);
+}
+
+int ff_decode_content_light_new(const AVCodecContext *avctx, AVFrame *frame,
+ AVContentLightMetadata **clm)
+{
+ if (side_data_pref(avctx, frame, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL)) {
+ *clm = NULL;
+ return 0;
+ }
+
+ *clm = av_content_light_metadata_create_side_data(frame);
+ return *clm ? 0 : AVERROR(ENOMEM);
+}
+
int ff_copy_palette(void *dst, const AVPacket *src, void *logctx)
{
size_t size;
diff --git a/libavcodec/decode.h b/libavcodec/decode.h
index a131b9940a..b8df095532 100644
--- a/libavcodec/decode.h
+++ b/libavcodec/decode.h
@@ -175,4 +175,25 @@ AVFrameSideData *ff_frame_new_side_data_from_buf(const AVCodecContext *avctx,
enum AVFrameSideDataType type,
AVBufferRef *buf);
+struct AVMasteringDisplayMetadata;
+struct AVContentLightMetadata;
+
+/**
+ * Wrapper around av_mastering_display_metadata_create_side_data(), which
+ * rejects side data overridden by the demuxer. Returns 0 on success, and a
+ * negative error code otherwise. If successful, *mdm may either be a pointer to
+ * the new side data, or NULL in case the side data was already present.
+ */
+int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame,
+ struct AVMasteringDisplayMetadata **mdm);
+
+/**
+ * Wrapper around av_content_light_metadata_create_side_data(), which
+ * rejects side data overridden by the demuxer. Returns 0 on success, and a
+ * negative error code otherwise. If successful, *clm may either be a pointer to
+ * the new side data, or NULL in case the side data was already present.
+ */
+int ff_decode_content_light_new(const AVCodecContext *avctx, AVFrame *frame,
+ struct AVContentLightMetadata **clm);
+
#endif /* AVCODEC_DECODE_H */
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 19/38] avcodec/av1dec: respect side data preference
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (17 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 18/38] lavc: add content light/mastering display " Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 20/38] avcodec/cri: " Anton Khirnov
` (18 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
From: Niklas Haas <git@haasn.dev>
---
libavcodec/av1dec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 7debc4deda..4fcfed3c7b 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -946,7 +946,7 @@ static int export_itut_t35(AVCodecContext *avctx, AVFrame *frame,
if (!ret)
break;
- if (!av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_A53_CC, buf))
+ if (!ff_frame_new_side_data_from_buf(avctx, frame, AV_FRAME_DATA_A53_CC, buf))
av_buffer_unref(&buf);
avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 20/38] avcodec/cri: respect side data preference
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (18 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 19/38] avcodec/av1dec: respect side data preference Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 21/38] avcodec/h264_slice: " Anton Khirnov
` (17 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
From: Niklas Haas <git@haasn.dev>
This function was already ignoring OOM errors.
---
libavcodec/cri.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libavcodec/cri.c b/libavcodec/cri.c
index c4eb468610..990e52ac99 100644
--- a/libavcodec/cri.c
+++ b/libavcodec/cri.c
@@ -398,8 +398,8 @@ skip:
}
if (hflip || vflip) {
- rotation = av_frame_new_side_data(p, AV_FRAME_DATA_DISPLAYMATRIX,
- sizeof(int32_t) * 9);
+ ff_frame_new_side_data(avctx, p, AV_FRAME_DATA_DISPLAYMATRIX,
+ sizeof(int32_t) * 9, &rotation);
if (rotation) {
av_display_rotation_set((int32_t *)rotation->data, 0.f);
av_display_matrix_flip((int32_t *)rotation->data, hflip, vflip);
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 21/38] avcodec/h264_slice: respect side data preference
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (19 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 20/38] avcodec/cri: " Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 22/38] lavc/hevcdec: pass an actual codec context to ff_h2645_sei_to_frame() Anton Khirnov
` (16 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
From: Niklas Haas <git@haasn.dev>
If the time code side data is overridden by the packet level, we also
make sure not to update `out->metadata` to a mismatched timecode.
---
libavcodec/h264_slice.c | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 8464a0b34c..f30ff33188 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1257,26 +1257,27 @@ static int h264_export_frame_props(H264Context *h)
if (h->sei.picture_timing.timecode_cnt > 0) {
uint32_t *tc_sd;
char tcbuf[AV_TIMECODE_STR_SIZE];
+ AVFrameSideData *tcside;
+ ret = ff_frame_new_side_data(h->avctx, out, AV_FRAME_DATA_S12M_TIMECODE,
+ sizeof(uint32_t)*4, &tcside);
+ if (ret < 0)
+ return ret;
- AVFrameSideData *tcside = av_frame_new_side_data(out,
- AV_FRAME_DATA_S12M_TIMECODE,
- sizeof(uint32_t)*4);
- if (!tcside)
- return AVERROR(ENOMEM);
+ if (tcside) {
+ tc_sd = (uint32_t*)tcside->data;
+ tc_sd[0] = h->sei.picture_timing.timecode_cnt;
- tc_sd = (uint32_t*)tcside->data;
- tc_sd[0] = h->sei.picture_timing.timecode_cnt;
+ for (int i = 0; i < tc_sd[0]; i++) {
+ int drop = h->sei.picture_timing.timecode[i].dropframe;
+ int hh = h->sei.picture_timing.timecode[i].hours;
+ int mm = h->sei.picture_timing.timecode[i].minutes;
+ int ss = h->sei.picture_timing.timecode[i].seconds;
+ int ff = h->sei.picture_timing.timecode[i].frame;
- for (int i = 0; i < tc_sd[0]; i++) {
- int drop = h->sei.picture_timing.timecode[i].dropframe;
- int hh = h->sei.picture_timing.timecode[i].hours;
- int mm = h->sei.picture_timing.timecode[i].minutes;
- int ss = h->sei.picture_timing.timecode[i].seconds;
- int ff = h->sei.picture_timing.timecode[i].frame;
-
- tc_sd[i + 1] = av_timecode_get_smpte(h->avctx->framerate, drop, hh, mm, ss, ff);
- av_timecode_make_smpte_tc_string2(tcbuf, h->avctx->framerate, tc_sd[i + 1], 0, 0);
- av_dict_set(&out->metadata, "timecode", tcbuf, 0);
+ tc_sd[i + 1] = av_timecode_get_smpte(h->avctx->framerate, drop, hh, mm, ss, ff);
+ av_timecode_make_smpte_tc_string2(tcbuf, h->avctx->framerate, tc_sd[i + 1], 0, 0);
+ av_dict_set(&out->metadata, "timecode", tcbuf, 0);
+ }
}
h->sei.picture_timing.timecode_cnt = 0;
}
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 22/38] lavc/hevcdec: pass an actual codec context to ff_h2645_sei_to_frame()
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (20 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 21/38] avcodec/h264_slice: " Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 23/38] avcodec/hevcdec: respect side data preference Anton Khirnov
` (15 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
Needed by following commit.
---
libavcodec/hevcdec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index b5311ae510..17c6a9212f 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -2778,7 +2778,7 @@ static int set_side_data(HEVCContext *s)
s->sei.common.content_light.present--;
}
- ret = ff_h2645_sei_to_frame(out, &s->sei.common, AV_CODEC_ID_HEVC, NULL,
+ ret = ff_h2645_sei_to_frame(out, &s->sei.common, AV_CODEC_ID_HEVC, s->avctx,
&s->ps.sps->vui.common,
s->ps.sps->bit_depth, s->ps.sps->bit_depth_chroma,
s->ref->poc /* no poc_offset in HEVC */);
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 23/38] avcodec/hevcdec: respect side data preference
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (21 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 22/38] lavc/hevcdec: pass an actual codec context to ff_h2645_sei_to_frame() Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 19:11 ` Marton Balint
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 24/38] avcodec/libjxldec: " Anton Khirnov
` (14 subsequent siblings)
37 siblings, 1 reply; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
From: Niklas Haas <git@haasn.dev>
If the time code side data is overridden by the packet level, we also
make sure not to update `out->metadata` to a mismatched timecode.
For HDR side data, we unfortunately need to omit a return check because
the new function does not distinguish between OOM and overridden side
data.
---
libavcodec/hevcdec.c | 37 +++++++++++++++++++------------------
1 file changed, 19 insertions(+), 18 deletions(-)
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 17c6a9212f..0cb2577b39 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -2788,24 +2788,27 @@ static int set_side_data(HEVCContext *s)
if (s->sei.timecode.present) {
uint32_t *tc_sd;
char tcbuf[AV_TIMECODE_STR_SIZE];
- AVFrameSideData *tcside = av_frame_new_side_data(out, AV_FRAME_DATA_S12M_TIMECODE,
- sizeof(uint32_t) * 4);
- if (!tcside)
- return AVERROR(ENOMEM);
+ AVFrameSideData *tcside;
+ ret = ff_frame_new_side_data(s->avctx, out, AV_FRAME_DATA_S12M_TIMECODE,
+ sizeof(uint32_t) * 4, &tcside);
+ if (ret < 0)
+ return ret;
- tc_sd = (uint32_t*)tcside->data;
- tc_sd[0] = s->sei.timecode.num_clock_ts;
+ if (tcside) {
+ tc_sd = (uint32_t*)tcside->data;
+ tc_sd[0] = s->sei.timecode.num_clock_ts;
- for (int i = 0; i < tc_sd[0]; i++) {
- int drop = s->sei.timecode.cnt_dropped_flag[i];
- int hh = s->sei.timecode.hours_value[i];
- int mm = s->sei.timecode.minutes_value[i];
- int ss = s->sei.timecode.seconds_value[i];
- int ff = s->sei.timecode.n_frames[i];
+ for (int i = 0; i < tc_sd[0]; i++) {
+ int drop = s->sei.timecode.cnt_dropped_flag[i];
+ int hh = s->sei.timecode.hours_value[i];
+ int mm = s->sei.timecode.minutes_value[i];
+ int ss = s->sei.timecode.seconds_value[i];
+ int ff = s->sei.timecode.n_frames[i];
- tc_sd[i + 1] = av_timecode_get_smpte(s->avctx->framerate, drop, hh, mm, ss, ff);
- av_timecode_make_smpte_tc_string2(tcbuf, s->avctx->framerate, tc_sd[i + 1], 0, 0);
- av_dict_set(&out->metadata, "timecode", tcbuf, 0);
+ tc_sd[i + 1] = av_timecode_get_smpte(s->avctx->framerate, drop, hh, mm, ss, ff);
+ av_timecode_make_smpte_tc_string2(tcbuf, s->avctx->framerate, tc_sd[i + 1], 0, 0);
+ av_dict_set(&out->metadata, "timecode", tcbuf, 0);
+ }
}
s->sei.timecode.num_clock_ts = 0;
@@ -2816,10 +2819,8 @@ static int set_side_data(HEVCContext *s)
if (!info_ref)
return AVERROR(ENOMEM);
- if (!av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_DYNAMIC_HDR_PLUS, info_ref)) {
+ if (!ff_frame_new_side_data_from_buf(s->avctx, out, AV_FRAME_DATA_DYNAMIC_HDR_PLUS, info_ref))
av_buffer_unref(&info_ref);
- return AVERROR(ENOMEM);
- }
}
if (s->rpu_buf) {
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* Re: [FFmpeg-devel] [PATCH 23/38] avcodec/hevcdec: respect side data preference
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 23/38] avcodec/hevcdec: respect side data preference Anton Khirnov
@ 2024-02-23 19:11 ` Marton Balint
0 siblings, 0 replies; 63+ messages in thread
From: Marton Balint @ 2024-02-23 19:11 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Fri, 23 Feb 2024, Anton Khirnov wrote:
> From: Niklas Haas <git@haasn.dev>
>
> If the time code side data is overridden by the packet level, we also
> make sure not to update `out->metadata` to a mismatched timecode.
>
> For HDR side data, we unfortunately need to omit a return check because
> the new function does not distinguish between OOM and overridden side
> data.
I don't think this is acceptable. If the API is not capable
of differentiating between OOM and overridden side data, then
the API should be fixed.
Regards,
Marton
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 24/38] avcodec/libjxldec: respect side data preference
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (22 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 23/38] avcodec/hevcdec: respect side data preference Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 25/38] avcodec/mjpegdec: " Anton Khirnov
` (13 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
From: Niklas Haas <git@haasn.dev>
Also fixes a memory leak where the side data was previously not properly
cleaned up on OOM, although we now unfortunately don't distinguish
between OOM and overriden side data.
Signed-off-by: Anton Khirnov <anton@khirnov.net>
---
libavcodec/libjxldec.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libavcodec/libjxldec.c b/libavcodec/libjxldec.c
index b830eee784..e1dda99b73 100644
--- a/libavcodec/libjxldec.c
+++ b/libavcodec/libjxldec.c
@@ -483,9 +483,9 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame)
/* full image is one frame, even if animated */
av_log(avctx, AV_LOG_DEBUG, "FULL_IMAGE event emitted\n");
if (ctx->iccp) {
- AVFrameSideData *sd = av_frame_new_side_data_from_buf(ctx->frame, AV_FRAME_DATA_ICC_PROFILE, ctx->iccp);
+ AVFrameSideData *sd = ff_frame_new_side_data_from_buf(avctx, ctx->frame, AV_FRAME_DATA_ICC_PROFILE, ctx->iccp);
if (!sd)
- return AVERROR(ENOMEM);
+ av_buffer_unref(&ctx->iccp);
/* ownership is transfered, and it is not ref-ed */
ctx->iccp = NULL;
}
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 25/38] avcodec/mjpegdec: respect side data preference
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (23 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 24/38] avcodec/libjxldec: " Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 26/38] avcodec/mpeg12dec: " Anton Khirnov
` (12 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
From: Niklas Haas <git@haasn.dev>
---
libavcodec/mjpegdec.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 81f724d230..43b36d0a8f 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -2840,16 +2840,18 @@ the_end:
for (i = 0; i < s->iccnum; i++)
total_size += s->iccentries[i].length;
- sd = av_frame_new_side_data(frame, AV_FRAME_DATA_ICC_PROFILE, total_size);
- if (!sd) {
+ ret = ff_frame_new_side_data(avctx, frame, AV_FRAME_DATA_ICC_PROFILE, total_size, &sd);
+ if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Could not allocate frame side data\n");
- return AVERROR(ENOMEM);
+ return ret;
}
- /* Reassemble the parts, which are now in-order. */
- for (i = 0; i < s->iccnum; i++) {
- memcpy(sd->data + offset, s->iccentries[i].data, s->iccentries[i].length);
- offset += s->iccentries[i].length;
+ if (sd) {
+ /* Reassemble the parts, which are now in-order. */
+ for (i = 0; i < s->iccnum; i++) {
+ memcpy(sd->data + offset, s->iccentries[i].data, s->iccentries[i].length);
+ offset += s->iccentries[i].length;
+ }
}
}
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 26/38] avcodec/mpeg12dec: respect side data preference
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (24 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 25/38] avcodec/mjpegdec: " Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 27/38] avcodec/pngdec: " Anton Khirnov
` (11 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
From: Niklas Haas <git@haasn.dev>
We only need to consider side data types that may possibly come from the
packet.
---
libavcodec/mpeg12dec.c | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index d07eed8744..96987f5a8e 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1306,16 +1306,17 @@ static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size)
}
}
- pan_scan = av_frame_new_side_data(s->current_picture_ptr->f,
- AV_FRAME_DATA_PANSCAN,
- sizeof(s1->pan_scan));
- if (!pan_scan)
- return AVERROR(ENOMEM);
- memcpy(pan_scan->data, &s1->pan_scan, sizeof(s1->pan_scan));
+ ret = ff_frame_new_side_data(s->avctx, s->current_picture_ptr->f,
+ AV_FRAME_DATA_PANSCAN, sizeof(s1->pan_scan),
+ &pan_scan);
+ if (ret < 0)
+ return ret;
+ if (pan_scan)
+ memcpy(pan_scan->data, &s1->pan_scan, sizeof(s1->pan_scan));
if (s1->a53_buf_ref) {
- AVFrameSideData *sd = av_frame_new_side_data_from_buf(
- s->current_picture_ptr->f, AV_FRAME_DATA_A53_CC,
+ AVFrameSideData *sd = ff_frame_new_side_data_from_buf(
+ s->avctx, s->current_picture_ptr->f, AV_FRAME_DATA_A53_CC,
s1->a53_buf_ref);
if (!sd)
av_buffer_unref(&s1->a53_buf_ref);
@@ -1332,13 +1333,13 @@ static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size)
}
if (s1->has_afd) {
- AVFrameSideData *sd =
- av_frame_new_side_data(s->current_picture_ptr->f,
- AV_FRAME_DATA_AFD, 1);
- if (!sd)
- return AVERROR(ENOMEM);
-
- *sd->data = s1->afd;
+ AVFrameSideData *sd;
+ ret = ff_frame_new_side_data(s->avctx, s->current_picture_ptr->f,
+ AV_FRAME_DATA_AFD, 1, &sd);
+ if (ret < 0)
+ return ret;
+ if (sd)
+ *sd->data = s1->afd;
s1->has_afd = 0;
}
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 27/38] avcodec/pngdec: respect side data preference
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (25 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 26/38] avcodec/mpeg12dec: " Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 28/38] avcodec/tiff: " Anton Khirnov
` (10 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
From: Niklas Haas <git@haasn.dev>
---
libavcodec/pngdec.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 026da30c25..8f409c74b8 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -660,6 +660,7 @@ static int decode_phys_chunk(AVCodecContext *avctx, PNGDecContext *s,
static int populate_avctx_color_fields(AVCodecContext *avctx, AVFrame *frame)
{
PNGDecContext *s = avctx->priv_data;
+ int ret;
if (s->have_cicp) {
if (s->cicp_primaries >= AVCOL_PRI_NB)
@@ -678,11 +679,15 @@ static int populate_avctx_color_fields(AVCodecContext *avctx, AVFrame *frame)
avctx->color_range = frame->color_range = AVCOL_RANGE_UNSPECIFIED;
}
} else if (s->iccp_data) {
- AVFrameSideData *sd = av_frame_new_side_data(frame, AV_FRAME_DATA_ICC_PROFILE, s->iccp_data_len);
- if (!sd)
- return AVERROR(ENOMEM);
- memcpy(sd->data, s->iccp_data, s->iccp_data_len);
- av_dict_set(&sd->metadata, "name", s->iccp_name, 0);
+ AVFrameSideData *sd;
+ ret = ff_frame_new_side_data(avctx, frame, AV_FRAME_DATA_ICC_PROFILE,
+ s->iccp_data_len, &sd);
+ if (ret < 0)
+ return ret;
+ if (sd) {
+ memcpy(sd->data, s->iccp_data, s->iccp_data_len);
+ av_dict_set(&sd->metadata, "name", s->iccp_name, 0);
+ }
} else if (s->have_srgb) {
avctx->color_primaries = frame->color_primaries = AVCOL_PRI_BT709;
avctx->color_trc = frame->color_trc = AVCOL_TRC_IEC61966_2_1;
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 28/38] avcodec/tiff: respect side data preference
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (26 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 27/38] avcodec/pngdec: " Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 29/38] avcodec/webp: " Anton Khirnov
` (9 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
From: Niklas Haas <git@haasn.dev>
---
libavcodec/tiff.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index 71cb703821..cb4d378753 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -1706,11 +1706,11 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
if (bytestream2_get_bytes_left(&gb_temp) < count)
return AVERROR_INVALIDDATA;
- sd = av_frame_new_side_data(frame, AV_FRAME_DATA_ICC_PROFILE, count);
- if (!sd)
- return AVERROR(ENOMEM);
-
- bytestream2_get_bufferu(&gb_temp, sd->data, count);
+ ret = ff_frame_new_side_data(s->avctx, frame, AV_FRAME_DATA_ICC_PROFILE, count, &sd);
+ if (ret < 0)
+ return ret;
+ if (sd)
+ bytestream2_get_bufferu(&gb_temp, sd->data, count);
break;
case TIFF_ARTIST:
ADD_METADATA(count, "artist", NULL);
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 29/38] avcodec/webp: respect side data preference
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (27 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 28/38] avcodec/tiff: " Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 30/38] avcodec/libdav1d: " Anton Khirnov
` (8 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
From: Niklas Haas <git@haasn.dev>
---
libavcodec/webp.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index 54b3fde6dc..9308ea2b69 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -1500,11 +1500,16 @@ exif_end:
"VP8X header\n");
s->has_iccp = 1;
- sd = av_frame_new_side_data(p, AV_FRAME_DATA_ICC_PROFILE, chunk_size);
- if (!sd)
- return AVERROR(ENOMEM);
- bytestream2_get_buffer(&gb, sd->data, chunk_size);
+ ret = ff_frame_new_side_data(avctx, p, AV_FRAME_DATA_ICC_PROFILE, chunk_size, &sd);
+ if (ret < 0)
+ return ret;
+
+ if (sd) {
+ bytestream2_get_buffer(&gb, sd->data, chunk_size);
+ } else {
+ bytestream2_skip(&gb, chunk_size);
+ }
break;
}
case MKTAG('A', 'N', 'I', 'M'):
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 30/38] avcodec/libdav1d: respect side data preference
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (28 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 29/38] avcodec/webp: " Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 31/38] avcodec/dpx: " Anton Khirnov
` (7 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
From: Niklas Haas <git@haasn.dev>
---
libavcodec/libdav1d.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
index 78a5c63bf4..f002c994c1 100644
--- a/libavcodec/libdav1d.c
+++ b/libavcodec/libdav1d.c
@@ -561,7 +561,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
if (!res)
break;
- if (!av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_A53_CC, buf))
+ if (!ff_frame_new_side_data_from_buf(c, frame, AV_FRAME_DATA_A53_CC, buf))
av_buffer_unref(&buf);
c->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 31/38] avcodec/dpx: respect side data preference
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (29 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 30/38] avcodec/libdav1d: " Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 32/38] avcodec/mpeg12dec: use ff_frame_new_side_data Anton Khirnov
` (6 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
From: Niklas Haas <git@haasn.dev>
If the time code side data is overridden by the packet level, we also
make sure not to update `p->metadata` to a mismatched timecode.
---
libavcodec/dpx.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/libavcodec/dpx.c b/libavcodec/dpx.c
index 31e4a3f82c..80616d98a2 100644
--- a/libavcodec/dpx.c
+++ b/libavcodec/dpx.c
@@ -287,19 +287,21 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *p,
tc = av_bswap32(read32(&buf, endian));
if (i != 0xFFFFFFFF) {
- AVFrameSideData *tcside =
- av_frame_new_side_data(p, AV_FRAME_DATA_S12M_TIMECODE,
- sizeof(uint32_t) * 4);
- if (!tcside)
- return AVERROR(ENOMEM);
+ AVFrameSideData *tcside;
+ ret = ff_frame_new_side_data(avctx, p, AV_FRAME_DATA_S12M_TIMECODE,
+ sizeof(uint32_t) * 4, &tcside);
+ if (ret < 0)
+ return ret;
- tc_sd = (uint32_t*)tcside->data;
- tc_sd[0] = 1;
- tc_sd[1] = tc;
+ if (tcside) {
+ tc_sd = (uint32_t*)tcside->data;
+ tc_sd[0] = 1;
+ tc_sd[1] = tc;
- av_timecode_make_smpte_tc_string2(tcbuf, avctx->framerate,
- tc_sd[1], 0, 0);
- av_dict_set(&p->metadata, "timecode", tcbuf, 0);
+ av_timecode_make_smpte_tc_string2(tcbuf, avctx->framerate,
+ tc_sd[1], 0, 0);
+ av_dict_set(&p->metadata, "timecode", tcbuf, 0);
+ }
}
}
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 32/38] avcodec/mpeg12dec: use ff_frame_new_side_data
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (30 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 31/38] avcodec/dpx: " Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 33/38] avcodec/h2645_sei: use ff_frame_new_side_data_from_buf Anton Khirnov
` (5 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
From: Niklas Haas <git@haasn.dev>
For consistency, even though this cannot be overriden at the packet
level.
---
libavcodec/mpeg12dec.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 96987f5a8e..1038a08637 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -2532,15 +2532,17 @@ static int mpeg_decode_frame(AVCodecContext *avctx, AVFrame *picture,
if (s->timecode_frame_start != -1 && *got_output) {
char tcbuf[AV_TIMECODE_STR_SIZE];
- AVFrameSideData *tcside = av_frame_new_side_data(picture,
- AV_FRAME_DATA_GOP_TIMECODE,
- sizeof(int64_t));
- if (!tcside)
- return AVERROR(ENOMEM);
- memcpy(tcside->data, &s->timecode_frame_start, sizeof(int64_t));
+ AVFrameSideData *tcside;
+ ret = ff_frame_new_side_data(avctx, picture, AV_FRAME_DATA_GOP_TIMECODE,
+ sizeof(int64_t), &tcside);
+ if (ret < 0)
+ return ret;
+ if (tcside) {
+ memcpy(tcside->data, &s->timecode_frame_start, sizeof(int64_t));
- av_timecode_make_mpeg_tc_string(tcbuf, s->timecode_frame_start);
- av_dict_set(&picture->metadata, "timecode", tcbuf, 0);
+ av_timecode_make_mpeg_tc_string(tcbuf, s->timecode_frame_start);
+ av_dict_set(&picture->metadata, "timecode", tcbuf, 0);
+ }
s->timecode_frame_start = -1;
}
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 33/38] avcodec/h2645_sei: use ff_frame_new_side_data_from_buf
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (31 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 32/38] avcodec/mpeg12dec: use ff_frame_new_side_data Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 34/38] avcodec/snowdec: use ff_frame_new_side_data Anton Khirnov
` (4 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
From: Niklas Haas <git@haasn.dev>
For consistency, even though this cannot be overriden at the packet
level.
Signed-off-by: Anton Khirnov <anton@khirnov.net>
---
libavcodec/h2645_sei.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c
index cb6be0594b..f3497d5568 100644
--- a/libavcodec/h2645_sei.c
+++ b/libavcodec/h2645_sei.c
@@ -35,6 +35,7 @@
#include "atsc_a53.h"
#include "avcodec.h"
+#include "decode.h"
#include "dynamic_hdr_vivid.h"
#include "get_bits.h"
#include "golomb.h"
@@ -607,7 +608,7 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei,
H2645SEIUnregistered *unreg = &sei->unregistered;
if (unreg->buf_ref[i]) {
- AVFrameSideData *sd = av_frame_new_side_data_from_buf(frame,
+ AVFrameSideData *sd = ff_frame_new_side_data_from_buf(avctx, frame,
AV_FRAME_DATA_SEI_UNREGISTERED,
unreg->buf_ref[i]);
if (!sd)
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 34/38] avcodec/snowdec: use ff_frame_new_side_data
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (32 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 33/38] avcodec/h2645_sei: use ff_frame_new_side_data_from_buf Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 35/38] avcodec/mjpegdec: " Anton Khirnov
` (3 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
From: Niklas Haas <git@haasn.dev>
For consistency, even though this cannot be overriden at the packet
level.
---
libavcodec/snowdec.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/libavcodec/snowdec.c b/libavcodec/snowdec.c
index 70fbab9a49..97aea748b6 100644
--- a/libavcodec/snowdec.c
+++ b/libavcodec/snowdec.c
@@ -787,11 +787,10 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *picture,
res = av_frame_ref(picture, s->mconly_picture);
if (res >= 0 && s->avmv_index) {
AVFrameSideData *sd;
-
- sd = av_frame_new_side_data(picture, AV_FRAME_DATA_MOTION_VECTORS, s->avmv_index * sizeof(AVMotionVector));
- if (!sd)
- return AVERROR(ENOMEM);
- memcpy(sd->data, s->avmv, s->avmv_index * sizeof(AVMotionVector));
+ res = ff_frame_new_side_data(s->avctx, picture, AV_FRAME_DATA_MOTION_VECTORS,
+ s->avmv_index * sizeof(AVMotionVector), &sd);
+ if (sd)
+ memcpy(sd->data, s->avmv, s->avmv_index * sizeof(AVMotionVector));
}
if (res < 0)
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 35/38] avcodec/mjpegdec: use ff_frame_new_side_data
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (33 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 34/38] avcodec/snowdec: use ff_frame_new_side_data Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 36/38] avcodec/hevcdec: switch to ff_frame_new_side_data_from_buf Anton Khirnov
` (2 subsequent siblings)
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
From: Niklas Haas <git@haasn.dev>
For consistency, even though this can't (yet) be overriden at the packet
level.
---
libavcodec/mjpegdec.c | 66 ++++++++++++++++++++++---------------------
1 file changed, 34 insertions(+), 32 deletions(-)
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 43b36d0a8f..4ef565fe2d 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -2865,42 +2865,44 @@ the_end:
if (orientation >= 2 && orientation <= 8) {
int32_t *matrix;
- sd = av_frame_new_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX, sizeof(int32_t) * 9);
- if (!sd) {
+ ret = ff_frame_new_side_data(avctx, frame, AV_FRAME_DATA_DISPLAYMATRIX, sizeof(int32_t) * 9, &sd);
+ if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, "Could not allocate frame side data\n");
- return AVERROR(ENOMEM);
+ return ret;
}
- matrix = (int32_t *)sd->data;
+ if (sd) {
+ matrix = (int32_t *)sd->data;
- switch (orientation) {
- case 2:
- av_display_rotation_set(matrix, 0.0);
- av_display_matrix_flip(matrix, 1, 0);
- break;
- case 3:
- av_display_rotation_set(matrix, 180.0);
- break;
- case 4:
- av_display_rotation_set(matrix, 180.0);
- av_display_matrix_flip(matrix, 1, 0);
- break;
- case 5:
- av_display_rotation_set(matrix, 90.0);
- av_display_matrix_flip(matrix, 1, 0);
- break;
- case 6:
- av_display_rotation_set(matrix, 90.0);
- break;
- case 7:
- av_display_rotation_set(matrix, -90.0);
- av_display_matrix_flip(matrix, 1, 0);
- break;
- case 8:
- av_display_rotation_set(matrix, -90.0);
- break;
- default:
- av_assert0(0);
+ switch (orientation) {
+ case 2:
+ av_display_rotation_set(matrix, 0.0);
+ av_display_matrix_flip(matrix, 1, 0);
+ break;
+ case 3:
+ av_display_rotation_set(matrix, 180.0);
+ break;
+ case 4:
+ av_display_rotation_set(matrix, 180.0);
+ av_display_matrix_flip(matrix, 1, 0);
+ break;
+ case 5:
+ av_display_rotation_set(matrix, 90.0);
+ av_display_matrix_flip(matrix, 1, 0);
+ break;
+ case 6:
+ av_display_rotation_set(matrix, 90.0);
+ break;
+ case 7:
+ av_display_rotation_set(matrix, -90.0);
+ av_display_matrix_flip(matrix, 1, 0);
+ break;
+ case 8:
+ av_display_rotation_set(matrix, -90.0);
+ break;
+ default:
+ av_assert0(0);
+ }
}
}
}
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 36/38] avcodec/hevcdec: switch to ff_frame_new_side_data_from_buf
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (34 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 35/38] avcodec/mjpegdec: " Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 37/38] lavc/*dec: use side data preference for mastering display/content light metadata Anton Khirnov
2024-02-23 13:59 ` [FFmpeg-devel] [PATCH 38/38] tests/fate/matroska: add tests for side data preference Anton Khirnov
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
From: Niklas Haas <git@haasn.dev>
For consistency, even though this cannot be overriden at the packet
level.
---
libavcodec/hevcdec.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 0cb2577b39..e5213aa252 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -2824,10 +2824,8 @@ static int set_side_data(HEVCContext *s)
}
if (s->rpu_buf) {
- AVFrameSideData *rpu = av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_DOVI_RPU_BUFFER, s->rpu_buf);
- if (!rpu)
- return AVERROR(ENOMEM);
-
+ if (!ff_frame_new_side_data_from_buf(s->avctx, out, AV_FRAME_DATA_DOVI_RPU_BUFFER, s->rpu_buf))
+ av_buffer_unref(&s->rpu_buf);
s->rpu_buf = NULL;
}
@@ -2839,10 +2837,8 @@ static int set_side_data(HEVCContext *s)
if (!info_ref)
return AVERROR(ENOMEM);
- if (!av_frame_new_side_data_from_buf(out, AV_FRAME_DATA_DYNAMIC_HDR_VIVID, info_ref)) {
+ if (!ff_frame_new_side_data_from_buf(s->avctx, out, AV_FRAME_DATA_DYNAMIC_HDR_VIVID, info_ref))
av_buffer_unref(&info_ref);
- return AVERROR(ENOMEM);
- }
}
return 0;
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 37/38] lavc/*dec: use side data preference for mastering display/content light metadata
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (35 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 36/38] avcodec/hevcdec: switch to ff_frame_new_side_data_from_buf Anton Khirnov
@ 2024-02-23 13:58 ` Anton Khirnov
2024-02-23 13:59 ` [FFmpeg-devel] [PATCH 38/38] tests/fate/matroska: add tests for side data preference Anton Khirnov
37 siblings, 0 replies; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:58 UTC (permalink / raw)
To: ffmpeg-devel
---
libavcodec/av1dec.c | 46 +++++++++++---------
libavcodec/h2645_sei.c | 96 +++++++++++++++++++++++-------------------
libavcodec/libdav1d.c | 47 ++++++++++++---------
libavcodec/pngdec.c | 54 ++++++++++++++----------
libavcodec/qsvdec.c | 50 +++++++++++++---------
5 files changed, 165 insertions(+), 128 deletions(-)
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 4fcfed3c7b..177c25f394 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -990,31 +990,39 @@ static int export_metadata(AVCodecContext *avctx, AVFrame *frame)
int ret = 0;
if (s->mdcv) {
- AVMasteringDisplayMetadata *mastering = av_mastering_display_metadata_create_side_data(frame);
- if (!mastering)
- return AVERROR(ENOMEM);
+ AVMasteringDisplayMetadata *mastering;
- for (int i = 0; i < 3; i++) {
- mastering->display_primaries[i][0] = av_make_q(s->mdcv->primary_chromaticity_x[i], 1 << 16);
- mastering->display_primaries[i][1] = av_make_q(s->mdcv->primary_chromaticity_y[i], 1 << 16);
+ ret = ff_decode_mastering_display_new(avctx, frame, &mastering);
+ if (ret < 0)
+ return ret;
+
+ if (mastering) {
+ for (int i = 0; i < 3; i++) {
+ mastering->display_primaries[i][0] = av_make_q(s->mdcv->primary_chromaticity_x[i], 1 << 16);
+ mastering->display_primaries[i][1] = av_make_q(s->mdcv->primary_chromaticity_y[i], 1 << 16);
+ }
+ mastering->white_point[0] = av_make_q(s->mdcv->white_point_chromaticity_x, 1 << 16);
+ mastering->white_point[1] = av_make_q(s->mdcv->white_point_chromaticity_y, 1 << 16);
+
+ mastering->max_luminance = av_make_q(s->mdcv->luminance_max, 1 << 8);
+ mastering->min_luminance = av_make_q(s->mdcv->luminance_min, 1 << 14);
+
+ mastering->has_primaries = 1;
+ mastering->has_luminance = 1;
}
- mastering->white_point[0] = av_make_q(s->mdcv->white_point_chromaticity_x, 1 << 16);
- mastering->white_point[1] = av_make_q(s->mdcv->white_point_chromaticity_y, 1 << 16);
-
- mastering->max_luminance = av_make_q(s->mdcv->luminance_max, 1 << 8);
- mastering->min_luminance = av_make_q(s->mdcv->luminance_min, 1 << 14);
-
- mastering->has_primaries = 1;
- mastering->has_luminance = 1;
}
if (s->cll) {
- AVContentLightMetadata *light = av_content_light_metadata_create_side_data(frame);
- if (!light)
- return AVERROR(ENOMEM);
+ AVContentLightMetadata *light;
- light->MaxCLL = s->cll->max_cll;
- light->MaxFALL = s->cll->max_fall;
+ ret = ff_decode_content_light_new(avctx, frame, &light);
+ if (ret < 0)
+ return ret;
+
+ if (light) {
+ light->MaxCLL = s->cll->max_cll;
+ light->MaxFALL = s->cll->max_fall;
+ }
}
while (av_fifo_read(s->itut_t35_fifo, &itut_t35, 1) >= 0) {
diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c
index f3497d5568..86a4c21820 100644
--- a/libavcodec/h2645_sei.c
+++ b/libavcodec/h2645_sei.c
@@ -516,6 +516,7 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei,
int seed)
{
H2645SEIFramePacking *fp = &sei->frame_packing;
+ int ret;
if (fp->present &&
is_frame_packing_type_valid(fp->arrangement_type, codec_id) &&
@@ -711,56 +712,63 @@ int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei,
const int chroma_den = 50000;
const int luma_den = 10000;
int i;
- AVMasteringDisplayMetadata *metadata =
- av_mastering_display_metadata_create_side_data(frame);
- if (!metadata)
- return AVERROR(ENOMEM);
+ AVMasteringDisplayMetadata *metadata;
- for (i = 0; i < 3; i++) {
- const int j = mapping[i];
- metadata->display_primaries[i][0].num = sei->mastering_display.display_primaries[j][0];
- metadata->display_primaries[i][0].den = chroma_den;
- metadata->display_primaries[i][1].num = sei->mastering_display.display_primaries[j][1];
- metadata->display_primaries[i][1].den = chroma_den;
+ ret = ff_decode_mastering_display_new(avctx, frame, &metadata);
+ if (ret < 0)
+ return ret;
+
+ if (metadata) {
+ for (i = 0; i < 3; i++) {
+ const int j = mapping[i];
+ metadata->display_primaries[i][0].num = sei->mastering_display.display_primaries[j][0];
+ metadata->display_primaries[i][0].den = chroma_den;
+ metadata->display_primaries[i][1].num = sei->mastering_display.display_primaries[j][1];
+ metadata->display_primaries[i][1].den = chroma_den;
+ }
+ metadata->white_point[0].num = sei->mastering_display.white_point[0];
+ metadata->white_point[0].den = chroma_den;
+ metadata->white_point[1].num = sei->mastering_display.white_point[1];
+ metadata->white_point[1].den = chroma_den;
+
+ metadata->max_luminance.num = sei->mastering_display.max_luminance;
+ metadata->max_luminance.den = luma_den;
+ metadata->min_luminance.num = sei->mastering_display.min_luminance;
+ metadata->min_luminance.den = luma_den;
+ metadata->has_luminance = 1;
+ metadata->has_primaries = 1;
+
+ av_log(avctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n");
+ av_log(avctx, AV_LOG_DEBUG,
+ "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n",
+ av_q2d(metadata->display_primaries[0][0]),
+ av_q2d(metadata->display_primaries[0][1]),
+ av_q2d(metadata->display_primaries[1][0]),
+ av_q2d(metadata->display_primaries[1][1]),
+ av_q2d(metadata->display_primaries[2][0]),
+ av_q2d(metadata->display_primaries[2][1]),
+ av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1]));
+ av_log(avctx, AV_LOG_DEBUG,
+ "min_luminance=%f, max_luminance=%f\n",
+ av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance));
}
- metadata->white_point[0].num = sei->mastering_display.white_point[0];
- metadata->white_point[0].den = chroma_den;
- metadata->white_point[1].num = sei->mastering_display.white_point[1];
- metadata->white_point[1].den = chroma_den;
-
- metadata->max_luminance.num = sei->mastering_display.max_luminance;
- metadata->max_luminance.den = luma_den;
- metadata->min_luminance.num = sei->mastering_display.min_luminance;
- metadata->min_luminance.den = luma_den;
- metadata->has_luminance = 1;
- metadata->has_primaries = 1;
-
- av_log(avctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n");
- av_log(avctx, AV_LOG_DEBUG,
- "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f)\n",
- av_q2d(metadata->display_primaries[0][0]),
- av_q2d(metadata->display_primaries[0][1]),
- av_q2d(metadata->display_primaries[1][0]),
- av_q2d(metadata->display_primaries[1][1]),
- av_q2d(metadata->display_primaries[2][0]),
- av_q2d(metadata->display_primaries[2][1]),
- av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1]));
- av_log(avctx, AV_LOG_DEBUG,
- "min_luminance=%f, max_luminance=%f\n",
- av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance));
}
if (sei->content_light.present) {
- AVContentLightMetadata *metadata =
- av_content_light_metadata_create_side_data(frame);
- if (!metadata)
- return AVERROR(ENOMEM);
- metadata->MaxCLL = sei->content_light.max_content_light_level;
- metadata->MaxFALL = sei->content_light.max_pic_average_light_level;
+ AVContentLightMetadata *metadata;
- av_log(avctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n");
- av_log(avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n",
- metadata->MaxCLL, metadata->MaxFALL);
+ ret = ff_decode_content_light_new(avctx, frame, &metadata);
+ if (ret < 0)
+ return ret;
+
+ if (metadata) {
+ metadata->MaxCLL = sei->content_light.max_content_light_level;
+ metadata->MaxFALL = sei->content_light.max_pic_average_light_level;
+
+ av_log(avctx, AV_LOG_DEBUG, "Content Light Level Metadata:\n");
+ av_log(avctx, AV_LOG_DEBUG, "MaxCLL=%d, MaxFALL=%d\n",
+ metadata->MaxCLL, metadata->MaxFALL);
+ }
}
return 0;
diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
index f002c994c1..f9a92d10d3 100644
--- a/libavcodec/libdav1d.c
+++ b/libavcodec/libdav1d.c
@@ -507,33 +507,38 @@ FF_ENABLE_DEPRECATION_WARNINGS
}
if (p->mastering_display) {
- AVMasteringDisplayMetadata *mastering = av_mastering_display_metadata_create_side_data(frame);
- if (!mastering) {
- res = AVERROR(ENOMEM);
+ AVMasteringDisplayMetadata *mastering;
+
+ res = ff_decode_mastering_display_new(c, frame, &mastering);
+ if (res < 0)
goto fail;
+
+ if (mastering) {
+ for (int i = 0; i < 3; i++) {
+ mastering->display_primaries[i][0] = av_make_q(p->mastering_display->primaries[i][0], 1 << 16);
+ mastering->display_primaries[i][1] = av_make_q(p->mastering_display->primaries[i][1], 1 << 16);
+ }
+ mastering->white_point[0] = av_make_q(p->mastering_display->white_point[0], 1 << 16);
+ mastering->white_point[1] = av_make_q(p->mastering_display->white_point[1], 1 << 16);
+
+ mastering->max_luminance = av_make_q(p->mastering_display->max_luminance, 1 << 8);
+ mastering->min_luminance = av_make_q(p->mastering_display->min_luminance, 1 << 14);
+
+ mastering->has_primaries = 1;
+ mastering->has_luminance = 1;
}
-
- for (int i = 0; i < 3; i++) {
- mastering->display_primaries[i][0] = av_make_q(p->mastering_display->primaries[i][0], 1 << 16);
- mastering->display_primaries[i][1] = av_make_q(p->mastering_display->primaries[i][1], 1 << 16);
- }
- mastering->white_point[0] = av_make_q(p->mastering_display->white_point[0], 1 << 16);
- mastering->white_point[1] = av_make_q(p->mastering_display->white_point[1], 1 << 16);
-
- mastering->max_luminance = av_make_q(p->mastering_display->max_luminance, 1 << 8);
- mastering->min_luminance = av_make_q(p->mastering_display->min_luminance, 1 << 14);
-
- mastering->has_primaries = 1;
- mastering->has_luminance = 1;
}
if (p->content_light) {
- AVContentLightMetadata *light = av_content_light_metadata_create_side_data(frame);
- if (!light) {
- res = AVERROR(ENOMEM);
+ AVContentLightMetadata *light;
+
+ res = ff_decode_content_light_new(c, frame, &light);
+ if (res < 0)
goto fail;
+
+ if (light) {
+ light->MaxCLL = p->content_light->max_content_light_level;
+ light->MaxFALL = p->content_light->max_frame_average_light_level;
}
- light->MaxCLL = p->content_light->max_content_light_level;
- light->MaxFALL = p->content_light->max_frame_average_light_level;
}
if (p->itut_t35) {
#if FF_DAV1D_VERSION_AT_LEAST(6,9)
diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 8f409c74b8..de50e6a5b6 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -746,33 +746,41 @@ static int populate_avctx_color_fields(AVCodecContext *avctx, AVFrame *frame)
avctx->bits_per_raw_sample = s->significant_bits;
if (s->have_clli) {
- AVContentLightMetadata *clli =
- av_content_light_metadata_create_side_data(frame);
- if (!clli)
- return AVERROR(ENOMEM);
- /*
- * 0.0001 divisor value
- * see: https://www.w3.org/TR/png-3/#cLLi-chunk
- */
- clli->MaxCLL = s->clli_max / 10000;
- clli->MaxFALL = s->clli_avg / 10000;
+ AVContentLightMetadata *clli;
+
+ ret = ff_decode_content_light_new(avctx, frame, &clli);
+ if (ret < 0)
+ return ret;
+
+ if (clli) {
+ /*
+ * 0.0001 divisor value
+ * see: https://www.w3.org/TR/png-3/#cLLi-chunk
+ */
+ clli->MaxCLL = s->clli_max / 10000;
+ clli->MaxFALL = s->clli_avg / 10000;
+ }
}
if (s->have_mdvc) {
- AVMasteringDisplayMetadata *mdvc =
- av_mastering_display_metadata_create_side_data(frame);
- if (!mdvc)
- return AVERROR(ENOMEM);
- mdvc->has_primaries = 1;
- for (int i = 0; i < 3; i++) {
- mdvc->display_primaries[i][0] = av_make_q(s->mdvc_primaries[i][0], 50000);
- mdvc->display_primaries[i][1] = av_make_q(s->mdvc_primaries[i][1], 50000);
+ AVMasteringDisplayMetadata *mdvc;
+
+ ret = ff_decode_mastering_display_new(avctx, frame, &mdvc);
+ if (ret < 0)
+ return ret;
+
+ if (mdvc) {
+ mdvc->has_primaries = 1;
+ for (int i = 0; i < 3; i++) {
+ mdvc->display_primaries[i][0] = av_make_q(s->mdvc_primaries[i][0], 50000);
+ mdvc->display_primaries[i][1] = av_make_q(s->mdvc_primaries[i][1], 50000);
+ }
+ mdvc->white_point[0] = av_make_q(s->mdvc_white_point[0], 50000);
+ mdvc->white_point[1] = av_make_q(s->mdvc_white_point[1], 50000);
+ mdvc->has_luminance = 1;
+ mdvc->max_luminance = av_make_q(s->mdvc_max_lum, 10000);
+ mdvc->min_luminance = av_make_q(s->mdvc_min_lum, 10000);
}
- mdvc->white_point[0] = av_make_q(s->mdvc_white_point[0], 50000);
- mdvc->white_point[1] = av_make_q(s->mdvc_white_point[1], 50000);
- mdvc->has_luminance = 1;
- mdvc->max_luminance = av_make_q(s->mdvc_max_lum, 10000);
- mdvc->min_luminance = av_make_q(s->mdvc_min_lum, 10000);
}
return 0;
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index d688a17c41..4f39f6942a 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -651,42 +651,50 @@ static int qsv_export_film_grain(AVCodecContext *avctx, mfxExtAV1FilmGrainParam
static int qsv_export_hdr_side_data(AVCodecContext *avctx, mfxExtMasteringDisplayColourVolume *mdcv,
mfxExtContentLightLevelInfo *clli, AVFrame *frame)
{
+ int ret;
+
// The SDK re-uses this flag for HDR SEI parsing
if (mdcv->InsertPayloadToggle) {
- AVMasteringDisplayMetadata *mastering = av_mastering_display_metadata_create_side_data(frame);
+ AVMasteringDisplayMetadata *mastering;
const int mapping[3] = {2, 0, 1};
const int chroma_den = 50000;
const int luma_den = 10000;
int i;
- if (!mastering)
- return AVERROR(ENOMEM);
+ ret = ff_decode_mastering_display_new(avctx, frame, &mastering);
+ if (ret < 0)
+ return ret;
- for (i = 0; i < 3; i++) {
- const int j = mapping[i];
- mastering->display_primaries[i][0] = av_make_q(mdcv->DisplayPrimariesX[j], chroma_den);
- mastering->display_primaries[i][1] = av_make_q(mdcv->DisplayPrimariesY[j], chroma_den);
+ if (mastering) {
+ for (i = 0; i < 3; i++) {
+ const int j = mapping[i];
+ mastering->display_primaries[i][0] = av_make_q(mdcv->DisplayPrimariesX[j], chroma_den);
+ mastering->display_primaries[i][1] = av_make_q(mdcv->DisplayPrimariesY[j], chroma_den);
+ }
+
+ mastering->white_point[0] = av_make_q(mdcv->WhitePointX, chroma_den);
+ mastering->white_point[1] = av_make_q(mdcv->WhitePointY, chroma_den);
+
+ mastering->max_luminance = av_make_q(mdcv->MaxDisplayMasteringLuminance, luma_den);
+ mastering->min_luminance = av_make_q(mdcv->MinDisplayMasteringLuminance, luma_den);
+
+ mastering->has_luminance = 1;
+ mastering->has_primaries = 1;
}
-
- mastering->white_point[0] = av_make_q(mdcv->WhitePointX, chroma_den);
- mastering->white_point[1] = av_make_q(mdcv->WhitePointY, chroma_den);
-
- mastering->max_luminance = av_make_q(mdcv->MaxDisplayMasteringLuminance, luma_den);
- mastering->min_luminance = av_make_q(mdcv->MinDisplayMasteringLuminance, luma_den);
-
- mastering->has_luminance = 1;
- mastering->has_primaries = 1;
}
// The SDK re-uses this flag for HDR SEI parsing
if (clli->InsertPayloadToggle) {
- AVContentLightMetadata *light = av_content_light_metadata_create_side_data(frame);
+ AVContentLightMetadata *light;
- if (!light)
- return AVERROR(ENOMEM);
+ ret = ff_decode_content_light_new(avctx, frame, &light);
+ if (ret < 0)
+ return ret;
- light->MaxCLL = clli->MaxContentLightLevel;
- light->MaxFALL = clli->MaxPicAverageLightLevel;
+ if (light) {
+ light->MaxCLL = clli->MaxContentLightLevel;
+ light->MaxFALL = clli->MaxPicAverageLightLevel;
+ }
}
return 0;
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread
* [FFmpeg-devel] [PATCH 38/38] tests/fate/matroska: add tests for side data preference
2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov
` (36 preceding siblings ...)
2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 37/38] lavc/*dec: use side data preference for mastering display/content light metadata Anton Khirnov
@ 2024-02-23 13:59 ` Anton Khirnov
2024-02-23 15:02 ` Anton Khirnov
37 siblings, 1 reply; 63+ messages in thread
From: Anton Khirnov @ 2024-02-23 13:59 UTC (permalink / raw)
To: ffmpeg-devel
Cf. #10857
---
tests/fate/matroska.mak | 6 +
tests/ref/fate/matroska-side-data-pref-codec | 255 ++++++++++++++++++
tests/ref/fate/matroska-side-data-pref-global | 255 ++++++++++++++++++
3 files changed, 516 insertions(+)
create mode 100644 tests/ref/fate/matroska-side-data-pref-codec
create mode 100644 tests/ref/fate/matroska-side-data-pref-global
diff --git a/tests/fate/matroska.mak b/tests/fate/matroska.mak
index 9ab747184a..e9433ce730 100644
--- a/tests/fate/matroska.mak
+++ b/tests/fate/matroska.mak
@@ -264,6 +264,12 @@ FATE_MATROSKA_FFMPEG_FFPROBE-$(call REMUX, MATROSKA, VP9_PARSER) \
+= fate-matroska-hdr10-plus-remux
fate-matroska-hdr10-plus-remux: CMD = transcode webm $(TARGET_SAMPLES)/mkv/hdr10_plus_vp9_sample.webm matroska "-map 0 -c:v copy" "-map 0 -c:v copy" "-show_packets"
+fate-matroska-side-data-pref-codec: CMD = run ffprobe$(PROGSSUF)$(EXESUF) $(TARGET_SAMPLES)/mkv/hdr10tags-both.mkv \
+ -show_streams -show_frames -show_entries stream=stream_side_data:frame=frame_side_data_list
+fate-matroska-side-data-pref-global: CMD = run ffprobe$(PROGSSUF)$(EXESUF) $(TARGET_SAMPLES)/mkv/hdr10tags-both.mkv \
+ -show_streams -show_frames -show_entries stream=stream_side_data:frame=frame_side_data_list -side_data_prefer_global mastering_display_metadata,content_light_level
+FATE_MATROSKA_FFPROBE-$(call ALLYES MATROSKA_DEMUXER HEVC_DECODER) += fate-matroska-side-data-pref-codec fate-matroska-side-data-pref-global
+
FATE_SAMPLES_AVCONV += $(FATE_MATROSKA-yes)
FATE_SAMPLES_FFPROBE += $(FATE_MATROSKA_FFPROBE-yes)
FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_MATROSKA_FFMPEG_FFPROBE-yes)
diff --git a/tests/ref/fate/matroska-side-data-pref-codec b/tests/ref/fate/matroska-side-data-pref-codec
new file mode 100644
index 0000000000..d27134d0c9
--- /dev/null
+++ b/tests/ref/fate/matroska-side-data-pref-codec
@@ -0,0 +1,255 @@
+[FRAME]
+[SIDE_DATA]
+side_data_type=H.26[45] User Data Unregistered SEI message
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=35400/50000
+red_y=14599/50000
+green_x=8500/50000
+green_y=39850/50000
+blue_x=6550/50000
+blue_y=2300/50000
+white_point_x=15634/50000
+white_point_y=16450/50000
+min_luminance=10/10000
+max_luminance=10000000/10000
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=35400/50000
+red_y=14599/50000
+green_x=8500/50000
+green_y=39850/50000
+blue_x=6550/50000
+blue_y=2300/50000
+white_point_x=15634/50000
+white_point_y=16450/50000
+min_luminance=10/10000
+max_luminance=10000000/10000
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=35400/50000
+red_y=14599/50000
+green_x=8500/50000
+green_y=39850/50000
+blue_x=6550/50000
+blue_y=2300/50000
+white_point_x=15634/50000
+white_point_y=16450/50000
+min_luminance=10/10000
+max_luminance=10000000/10000
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=35400/50000
+red_y=14599/50000
+green_x=8500/50000
+green_y=39850/50000
+blue_x=6550/50000
+blue_y=2300/50000
+white_point_x=15634/50000
+white_point_y=16450/50000
+min_luminance=10/10000
+max_luminance=10000000/10000
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=35400/50000
+red_y=14599/50000
+green_x=8500/50000
+green_y=39850/50000
+blue_x=6550/50000
+blue_y=2300/50000
+white_point_x=15634/50000
+white_point_y=16450/50000
+min_luminance=10/10000
+max_luminance=10000000/10000
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=35400/50000
+red_y=14599/50000
+green_x=8500/50000
+green_y=39850/50000
+blue_x=6550/50000
+blue_y=2300/50000
+white_point_x=15634/50000
+white_point_y=16450/50000
+min_luminance=10/10000
+max_luminance=10000000/10000
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=35400/50000
+red_y=14599/50000
+green_x=8500/50000
+green_y=39850/50000
+blue_x=6550/50000
+blue_y=2300/50000
+white_point_x=15634/50000
+white_point_y=16450/50000
+min_luminance=10/10000
+max_luminance=10000000/10000
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=35400/50000
+red_y=14599/50000
+green_x=8500/50000
+green_y=39850/50000
+blue_x=6550/50000
+blue_y=2300/50000
+white_point_x=15634/50000
+white_point_y=16450/50000
+min_luminance=10/10000
+max_luminance=10000000/10000
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=35400/50000
+red_y=14599/50000
+green_x=8500/50000
+green_y=39850/50000
+blue_x=6550/50000
+blue_y=2300/50000
+white_point_x=15634/50000
+white_point_y=16450/50000
+min_luminance=10/10000
+max_luminance=10000000/10000
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=35400/50000
+red_y=14599/50000
+green_x=8500/50000
+green_y=39850/50000
+blue_x=6550/50000
+blue_y=2300/50000
+white_point_x=15634/50000
+white_point_y=16450/50000
+min_luminance=10/10000
+max_luminance=10000000/10000
+[/SIDE_DATA]
+[/FRAME]
+[STREAM]
+DISPOSITION:default=1
+DISPOSITION:dub=0
+DISPOSITION:original=0
+DISPOSITION:comment=0
+DISPOSITION:lyrics=0
+DISPOSITION:karaoke=0
+DISPOSITION:forced=0
+DISPOSITION:hearing_impaired=0
+DISPOSITION:visual_impaired=0
+DISPOSITION:clean_effects=0
+DISPOSITION:attached_pic=0
+DISPOSITION:timed_thumbnails=0
+DISPOSITION:non_diegetic=0
+DISPOSITION:captions=0
+DISPOSITION:descriptions=0
+DISPOSITION:metadata=0
+DISPOSITION:dependent=0
+DISPOSITION:still_image=0
+TAG:BPS=216040
+TAG:BPS-eng=216040
+TAG:DURATION=00:00:00.400000000
+TAG:DURATION-eng=00:00:00.400000000
+TAG:NUMBER_OF_FRAMES=10
+TAG:NUMBER_OF_FRAMES-eng=10
+TAG:NUMBER_OF_BYTES=10802
+TAG:NUMBER_OF_BYTES-eng=10802
+TAG:_STATISTICS_WRITING_APP=mkvmerge v9.0.1 ('Mask Machine') 64bit
+TAG:_STATISTICS_WRITING_APP-eng=mkvmerge v9.0.1 ('Mask Machine') 64bit
+TAG:_STATISTICS_WRITING_DATE_UTC=2019-02-14 12:53:10
+TAG:_STATISTICS_WRITING_DATE_UTC-eng=2019-02-14 12:53:10
+TAG:_STATISTICS_TAGS=BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
+TAG:_STATISTICS_TAGS-eng=BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=11408507/16777216
+red_y=5368709/16777216
+green_x=2222981/8388608
+green_y=11576279/16777216
+blue_x=5033165/33554432
+blue_y=16106127/268435456
+white_point_x=10492471/33554432
+white_point_y=689963/2097152
+min_luminance=5368709/536870912
+max_luminance=1000/1
+[/SIDE_DATA]
+[/STREAM]
diff --git a/tests/ref/fate/matroska-side-data-pref-global b/tests/ref/fate/matroska-side-data-pref-global
new file mode 100644
index 0000000000..4ff0c2d9db
--- /dev/null
+++ b/tests/ref/fate/matroska-side-data-pref-global
@@ -0,0 +1,255 @@
+[FRAME]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=11408507/16777216
+red_y=5368709/16777216
+green_x=2222981/8388608
+green_y=11576279/16777216
+blue_x=5033165/33554432
+blue_y=16106127/268435456
+white_point_x=10492471/33554432
+white_point_y=689963/2097152
+min_luminance=5368709/536870912
+max_luminance=1000/1
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=H.26[45] User Data Unregistered SEI message
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=11408507/16777216
+red_y=5368709/16777216
+green_x=2222981/8388608
+green_y=11576279/16777216
+blue_x=5033165/33554432
+blue_y=16106127/268435456
+white_point_x=10492471/33554432
+white_point_y=689963/2097152
+min_luminance=5368709/536870912
+max_luminance=1000/1
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=11408507/16777216
+red_y=5368709/16777216
+green_x=2222981/8388608
+green_y=11576279/16777216
+blue_x=5033165/33554432
+blue_y=16106127/268435456
+white_point_x=10492471/33554432
+white_point_y=689963/2097152
+min_luminance=5368709/536870912
+max_luminance=1000/1
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=11408507/16777216
+red_y=5368709/16777216
+green_x=2222981/8388608
+green_y=11576279/16777216
+blue_x=5033165/33554432
+blue_y=16106127/268435456
+white_point_x=10492471/33554432
+white_point_y=689963/2097152
+min_luminance=5368709/536870912
+max_luminance=1000/1
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=11408507/16777216
+red_y=5368709/16777216
+green_x=2222981/8388608
+green_y=11576279/16777216
+blue_x=5033165/33554432
+blue_y=16106127/268435456
+white_point_x=10492471/33554432
+white_point_y=689963/2097152
+min_luminance=5368709/536870912
+max_luminance=1000/1
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=11408507/16777216
+red_y=5368709/16777216
+green_x=2222981/8388608
+green_y=11576279/16777216
+blue_x=5033165/33554432
+blue_y=16106127/268435456
+white_point_x=10492471/33554432
+white_point_y=689963/2097152
+min_luminance=5368709/536870912
+max_luminance=1000/1
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=11408507/16777216
+red_y=5368709/16777216
+green_x=2222981/8388608
+green_y=11576279/16777216
+blue_x=5033165/33554432
+blue_y=16106127/268435456
+white_point_x=10492471/33554432
+white_point_y=689963/2097152
+min_luminance=5368709/536870912
+max_luminance=1000/1
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=11408507/16777216
+red_y=5368709/16777216
+green_x=2222981/8388608
+green_y=11576279/16777216
+blue_x=5033165/33554432
+blue_y=16106127/268435456
+white_point_x=10492471/33554432
+white_point_y=689963/2097152
+min_luminance=5368709/536870912
+max_luminance=1000/1
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=11408507/16777216
+red_y=5368709/16777216
+green_x=2222981/8388608
+green_y=11576279/16777216
+blue_x=5033165/33554432
+blue_y=16106127/268435456
+white_point_x=10492471/33554432
+white_point_y=689963/2097152
+min_luminance=5368709/536870912
+max_luminance=1000/1
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[/FRAME]
+[FRAME]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=11408507/16777216
+red_y=5368709/16777216
+green_x=2222981/8388608
+green_y=11576279/16777216
+blue_x=5033165/33554432
+blue_y=16106127/268435456
+white_point_x=10492471/33554432
+white_point_y=689963/2097152
+min_luminance=5368709/536870912
+max_luminance=1000/1
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[/FRAME]
+[STREAM]
+DISPOSITION:default=1
+DISPOSITION:dub=0
+DISPOSITION:original=0
+DISPOSITION:comment=0
+DISPOSITION:lyrics=0
+DISPOSITION:karaoke=0
+DISPOSITION:forced=0
+DISPOSITION:hearing_impaired=0
+DISPOSITION:visual_impaired=0
+DISPOSITION:clean_effects=0
+DISPOSITION:attached_pic=0
+DISPOSITION:timed_thumbnails=0
+DISPOSITION:non_diegetic=0
+DISPOSITION:captions=0
+DISPOSITION:descriptions=0
+DISPOSITION:metadata=0
+DISPOSITION:dependent=0
+DISPOSITION:still_image=0
+TAG:BPS=216040
+TAG:BPS-eng=216040
+TAG:DURATION=00:00:00.400000000
+TAG:DURATION-eng=00:00:00.400000000
+TAG:NUMBER_OF_FRAMES=10
+TAG:NUMBER_OF_FRAMES-eng=10
+TAG:NUMBER_OF_BYTES=10802
+TAG:NUMBER_OF_BYTES-eng=10802
+TAG:_STATISTICS_WRITING_APP=mkvmerge v9.0.1 ('Mask Machine') 64bit
+TAG:_STATISTICS_WRITING_APP-eng=mkvmerge v9.0.1 ('Mask Machine') 64bit
+TAG:_STATISTICS_WRITING_DATE_UTC=2019-02-14 12:53:10
+TAG:_STATISTICS_WRITING_DATE_UTC-eng=2019-02-14 12:53:10
+TAG:_STATISTICS_TAGS=BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
+TAG:_STATISTICS_TAGS-eng=BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
+[SIDE_DATA]
+side_data_type=Content light level metadata
+max_content=1000
+max_average=300
+[/SIDE_DATA]
+[SIDE_DATA]
+side_data_type=Mastering display metadata
+red_x=11408507/16777216
+red_y=5368709/16777216
+green_x=2222981/8388608
+green_y=11576279/16777216
+blue_x=5033165/33554432
+blue_y=16106127/268435456
+white_point_x=10492471/33554432
+white_point_y=689963/2097152
+min_luminance=5368709/536870912
+max_luminance=1000/1
+[/SIDE_DATA]
+[/STREAM]
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 63+ messages in thread