summaryrefslogtreecommitdiff
path: root/libavutil/opt.c
diff options
context:
space:
mode:
authorStefano Sabatini <stefasab@gmail.com>2012-08-09 22:55:49 +0200
committerStefano Sabatini <stefasab@gmail.com>2012-09-05 16:08:06 +0200
commit5666a1b270ffffb2f7d5485b9176758cab399df5 (patch)
treec60e4ea27c1b0ea8e3aa5475b81c9ac46835d8b9 /libavutil/opt.c
parentb21b5b04cca0633bd88db972ff1187ab7825b667 (diff)
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.
Diffstat (limited to 'libavutil/opt.c')
-rw-r--r--libavutil/opt.c12
1 files changed, 10 insertions, 2 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);