[FFmpeg-cvslog] lavu/opt: add av_opt_ accessors for pixel/format/image size options
Stefano Sabatini
git at videolan.org
Sun Nov 25 15:05:42 CET 2012
ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Sun Nov 4 15:32:56 2012 +0100| [c70ec631c928ac202fdb8efc999a50fc339f263c] | committer: Stefano Sabatini
lavu/opt: add av_opt_ accessors for pixel/format/image size options
The interface is implemented against the style of the other options
accessors. Possibly simplify programmatic setting of options.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c70ec631c928ac202fdb8efc999a50fc339f263c
---
doc/APIchanges | 9 +++++
libavutil/opt.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++
libavutil/opt.h | 8 ++++
libavutil/version.h | 2 +-
4 files changed, 120 insertions(+), 1 deletion(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index 57be6ba..5707d13 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,15 @@ libavutil: 2012-10-22
API changes, most recent first:
+2012-11-25 - xxxxxxx - lavu 52.9.100 - opt.h
+ Add the following convenience functions to opt.h:
+ av_opt_get_image_size
+ av_opt_get_pixel_fmt
+ av_opt_get_sample_fmt
+ av_opt_set_image_size
+ av_opt_set_pixel_fmt
+ av_opt_set_sample_fmt
+
2012-11-17 - xxxxxxx - lavu 52.8.100 - bprint.h
Add av_bprint_strftime().
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 7a7f893..24f7439 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -402,6 +402,62 @@ int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int
return 0;
}
+int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags)
+{
+ void *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->type != AV_OPT_TYPE_IMAGE_SIZE) {
+ av_log(obj, AV_LOG_ERROR,
+ "The value set by option '%s' is not an image size.\n", o->name);
+ return AVERROR(EINVAL);
+ }
+ if (w<0 || h<0) {
+ av_log(obj, AV_LOG_ERROR,
+ "Invalid negative size value %dx%d for size '%s'\n", w, h, o->name);
+ return AVERROR(EINVAL);
+ }
+ *(int *)(((uint8_t *)target_obj) + o->offset) = w;
+ *(int *)(((uint8_t *)target_obj+sizeof(int)) + o->offset) = h;
+ return 0;
+}
+
+static int set_format(void *obj, const char *name, int fmt, int search_flags,
+ enum AVOptionType type, const char *desc, int max)
+{
+ void *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->type != type) {
+ av_log(obj, AV_LOG_ERROR,
+ "The value set by option '%s' is not a %s format", name, desc);
+ return AVERROR(EINVAL);
+ }
+
+ if (fmt < -1 || fmt > max) {
+ av_log(obj, AV_LOG_ERROR,
+ "Value %d for parameter '%s' out of %s format range [0 - %d]\n",
+ fmt, name, desc, max);
+ return AVERROR(ERANGE);
+ }
+ *(int *)(((uint8_t *)target_obj) + o->offset) = fmt;
+ return 0;
+}
+
+int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags)
+{
+ return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_PIXEL_FMT, "pixel", AV_PIX_FMT_NB-1);
+}
+
+int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags)
+{
+ return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, "sample", AV_SAMPLE_FMT_NB-1);
+}
+
#if FF_API_OLD_AVOPTIONS
/**
*
@@ -596,6 +652,52 @@ int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_
return 0;
}
+int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out)
+{
+ 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->type != AV_OPT_TYPE_IMAGE_SIZE) {
+ av_log(obj, AV_LOG_ERROR,
+ "The value for option '%s' is not an image size.\n", name);
+ return AVERROR(EINVAL);
+ }
+
+ dst = ((uint8_t*)target_obj) + o->offset;
+ if (w_out) *w_out = *(int *)dst;
+ if (h_out) *h_out = *((int *)dst+1);
+ return 0;
+}
+
+static int get_format(void *obj, const char *name, int search_flags, int *out_fmt,
+ enum AVOptionType type, const char *desc)
+{
+ 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->type != type) {
+ av_log(obj, AV_LOG_ERROR,
+ "The value for option '%s' is not a %s format.\n", desc, name);
+ return AVERROR(EINVAL);
+ }
+
+ dst = ((uint8_t*)target_obj) + o->offset;
+ *out_fmt = *(int *)dst;
+ return 0;
+}
+
+int av_opt_get_pixel_fmt(void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt)
+{
+ return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_PIXEL_FMT, "pixel");
+}
+
+int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt)
+{
+ return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_SAMPLE_FMT, "sample");
+}
+
int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
{
const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0);
diff --git a/libavutil/opt.h b/libavutil/opt.h
index c168f59..bf84a9b 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -31,6 +31,8 @@
#include "avutil.h"
#include "dict.h"
#include "log.h"
+#include "pixfmt.h"
+#include "samplefmt.h"
/**
* @defgroup avoptions AVOptions
@@ -629,6 +631,9 @@ int av_opt_set_int (void *obj, const char *name, int64_t val, int search_f
int av_opt_set_double(void *obj, const char *name, double val, int search_flags);
int av_opt_set_q (void *obj, const char *name, AVRational val, int search_flags);
int av_opt_set_bin (void *obj, const char *name, const uint8_t *val, int size, int search_flags);
+int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags);
+int av_opt_set_pixel_fmt (void *obj, const char *name, enum AVPixelFormat fmt, int search_flags);
+int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags);
/**
* @}
*/
@@ -652,6 +657,9 @@ int av_opt_get (void *obj, const char *name, int search_flags, uint8_t *
int av_opt_get_int (void *obj, const char *name, int search_flags, int64_t *out_val);
int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val);
int av_opt_get_q (void *obj, const char *name, int search_flags, AVRational *out_val);
+int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out);
+int av_opt_get_pixel_fmt (void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt);
+int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt);
/**
* @}
*/
diff --git a/libavutil/version.h b/libavutil/version.h
index 16771ad..792086a 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -75,7 +75,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 52
-#define LIBAVUTIL_VERSION_MINOR 8
+#define LIBAVUTIL_VERSION_MINOR 9
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
More information about the ffmpeg-cvslog
mailing list