Signed-off-by: Michael Niedermayer <michae...@gmx.at> --- libavutil/opt.c | 32 ++++++++++++++++++++++++++++++++ libavutil/opt.h | 21 +++++++++++++++++++++ 2 files changed, 53 insertions(+)
diff --git a/libavutil/opt.c b/libavutil/opt.c index 62db1b5..12b5532 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -1876,6 +1876,8 @@ int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer, continue; if (flags & AV_OPT_SERIALIZE_SKIP_DEFAULTS && av_opt_is_set_to_default(obj, o) > 0) continue; + if (o->type == AV_OPT_TYPE_PTR) + continue; if ((ret = av_opt_get(obj, o->name, 0, &buf)) < 0) { av_bprint_finalize(&bprint, NULL); return ret; @@ -1893,6 +1895,36 @@ int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer, return 0; } +static const char* default_format_option_for_user(void *obj, const char* name, const char* value, char *tmp, int tmp_len) +{ + snprintf(tmp, tmp_len, "set '%s' to '%s'", name, value); + return tmp; +} + +const char* av_format_option_for_user(void *obj, const char* name, const char* value, char *tmp, int tmp_len) +{ + const AVClass *c = *(AVClass**)obj; + av_format_option_for_user_func *ptr = av_opt_ptr(c, obj, "format_option_for_user_func"); + av_format_option_for_user_func format_option_for_user = NULL; + + if (ptr) + format_option_for_user = *ptr; + + if (!format_option_for_user) + format_option_for_user = default_format_option_for_user; + + return format_option_for_user(obj, name, value, tmp, tmp_len); +} + +void av_set_format_option_for_user_func(void *obj, av_format_option_for_user_func f) +{ + const AVClass *c = *(AVClass**)obj; + av_format_option_for_user_func *ptr = av_opt_ptr(c, obj, "format_option_for_user_func"); + + if (ptr) + *ptr = f; +} + #ifdef TEST typedef struct TestContext diff --git a/libavutil/opt.h b/libavutil/opt.h index 5fc8a9b..4283b83 100644 --- a/libavutil/opt.h +++ b/libavutil/opt.h @@ -218,6 +218,8 @@ * before the file is actually opened. */ +typedef const char * (*av_format_option_for_user_func)(void *obj, const char* name, const char* value, char *tmp, int tmp_len); + enum AVOptionType{ AV_OPT_TYPE_FLAGS, AV_OPT_TYPE_INT, @@ -236,6 +238,7 @@ enum AVOptionType{ AV_OPT_TYPE_DURATION = MKBETAG('D','U','R',' '), AV_OPT_TYPE_COLOR = MKBETAG('C','O','L','R'), AV_OPT_TYPE_CHANNEL_LAYOUT = MKBETAG('C','H','L','A'), + AV_OPT_TYPE_PTR = MKBETAG('P','T','R',' '), #if FF_API_OLD_AVOPTIONS FF_OPT_TYPE_FLAGS = 0, FF_OPT_TYPE_INT, @@ -894,6 +897,24 @@ int av_opt_is_set_to_default_by_name(void *obj, const char *name, int search_fla */ int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer, const char key_val_sep, const char pairs_sep); + +/** + * Formats the given AVOption for display to the user. + * + * This uses a callback with the name "format_option_for_user_func" if such field + * exists in obj. + * + * @param obj pointer to a AVClass based object. + * @param name name of the AVOption + * @param value value to set the AVOption to, may be NULL + * @param tmp space in which the formatted option is constructed + * @param tmp_len, length of the tmp array + * @returns pointer to the formated string, this may match tmp + */ +const char* av_format_option_for_user(void *obj, const char* name, const char* value, char *tmp, int tmp_len); + +void av_set_format_option_for_user_func(void *obj, av_format_option_for_user_func f); + /** * @} */ -- 1.7.9.5 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel