From 5666a1b270ffffb2f7d5485b9176758cab399df5 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Thu, 9 Aug 2012 22:55:49 +0200 Subject: [PATCH] lavu/opt: support NULL and special "none" values for size and pixel format options Allow to specify NULL values explicitly, thus overriding the default values set in the context. --- libavutil/opt.c | 12 ++++++++++-- libavutil/version.h | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/libavutil/opt.c b/libavutil/opt.c index 960170b86f..5f8aaad6a1 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -241,7 +241,7 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags) const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); if (!o || !target_obj) return AVERROR_OPTION_NOT_FOUND; - if (!val && o->type != AV_OPT_TYPE_STRING) + if (!val && (o->type != AV_OPT_TYPE_STRING && o->type != AV_OPT_TYPE_PIXEL_FMT && o->type != AV_OPT_TYPE_IMAGE_SIZE)) return AVERROR(EINVAL); dst = ((uint8_t*)target_obj) + o->offset; @@ -255,11 +255,18 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags) case AV_OPT_TYPE_DOUBLE: case AV_OPT_TYPE_RATIONAL: return set_string_number(obj, o, val, dst); case AV_OPT_TYPE_IMAGE_SIZE: + if (!val || !strcmp(val, "none")) { + *(int *)dst = *((int *)dst + 1) = 0; + return 0; + } ret = av_parse_video_size(dst, ((int *)dst) + 1, val); if (ret < 0) av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as image size\n", val); return ret; case AV_OPT_TYPE_PIXEL_FMT: + if (!val || !strcmp(val, "none")) + ret = PIX_FMT_NONE; + else { ret = av_get_pix_fmt(val); if (ret == PIX_FMT_NONE) { char *tail; @@ -269,6 +276,7 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags) return AVERROR(EINVAL); } } + } *(enum PixelFormat *)dst = ret; return 0; } @@ -457,7 +465,7 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val) 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 PixelFormat *)dst), "?")); + ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum PixelFormat *)dst), "none")); break; default: return AVERROR(EINVAL); diff --git a/libavutil/version.h b/libavutil/version.h index f8cc602e8d..535c1af7e3 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -40,7 +40,7 @@ #define LIBAVUTIL_VERSION_MAJOR 51 #define LIBAVUTIL_VERSION_MINOR 71 -#define LIBAVUTIL_VERSION_MICRO 100 +#define LIBAVUTIL_VERSION_MICRO 101 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ LIBAVUTIL_VERSION_MINOR, \