aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/opt.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-06-18 04:40:18 +0200
committerMichael Niedermayer <michaelni@gmx.at>2011-06-18 05:10:38 +0200
commit2905e3ff6462431d55f89614b24e2a407707c82a (patch)
treed482d458a449228c8475942117c7eb81ec8934c6 /libavutil/opt.c
parent44d1b4088f2959912a27ffbffc5884db1b35a645 (diff)
parent78440c007cd310bb27ac2af5fb7ea5b7555efc84 (diff)
downloadffmpeg-2905e3ff6462431d55f89614b24e2a407707c82a.tar.gz
Merge remote-tracking branch 'qatar/master'
* qatar/master: lavc: add opt_find to AVCodecContext class. h264: Complexify frame num gap shortening code intreadwrite.h: fix AV_RL32/AV_RB32 signedness. Fix decoding of mpegts streams with h264 video that does *NOT* have b frames Add minor bumps and APIChanges entries for lavf private options. ffmpeg: deprecate -vc and -tvstd ffmpeg: use new avformat_open_* API. ffserver: use new avformat_open_* API. ffprobe: use new avformat_open_* API. ffplay: use new avformat_open_* API. cmdutils: add opt_default2(). dict: add AV_DICT_APPEND flag. lavf: add avformat_write_header() as a replacement for av_write_header(). Deprecate av_open_input_* and remove their uses. lavf: add avformat_open_input() as a replacement for av_open_input_* AVOptions: add av_opt_find() as a replacement for av_find_opt. AVOptions: add av_opt_set_dict() mapping a dictionary struct to a context. ffmpeg: don't abuse a global for passing frame size from input to output ffmpeg: don't abuse a global for passing pixel format from input to output ffmpeg: initialise encoders earlier. Conflicts: cmdutils.c doc/APIchanges ffmpeg.c ffplay.c ffprobe.c libavcodec/h264.c libavformat/avformat.h libavformat/utils.c libavformat/version.h libavutil/avutil.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil/opt.c')
-rw-r--r--libavutil/opt.c52
1 files changed, 47 insertions, 5 deletions
diff --git a/libavutil/opt.c b/libavutil/opt.c
index d57a547377..8c351488a8 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -29,7 +29,9 @@
#include "avstring.h"
#include "opt.h"
#include "eval.h"
+#include "dict.h"
+#if FF_API_FIND_OPT
//FIXME order them and do a bin search
const AVOption *av_find_opt(void *v, const char *name, const char *unit, int mask, int flags)
{
@@ -41,6 +43,7 @@ const AVOption *av_find_opt(void *v, const char *name, const char *unit, int mas
}
return NULL;
}
+#endif
const AVOption *av_next_option(void *obj, const AVOption *last)
{
@@ -51,7 +54,7 @@ const AVOption *av_next_option(void *obj, const AVOption *last)
static int av_set_number2(void *obj, const char *name, double num, int den, int64_t intnum, const AVOption **o_out)
{
- const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
+ const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
void *dst;
if (o_out)
*o_out= o;
@@ -114,7 +117,7 @@ static int hexchar2int(char c) {
int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out)
{
int ret;
- const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
+ const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
if (o_out)
*o_out = o;
if (!o)
@@ -161,7 +164,7 @@ int av_set_string3(void *obj, const char *name, const char *val, int alloc, cons
buf[i]=0;
{
- const AVOption *o_named= av_find_opt(obj, buf, o->unit, 0, 0);
+ const AVOption *o_named = av_opt_find(obj, buf, o->unit, 0, 0);
if (o_named && o_named->type == FF_OPT_TYPE_CONST)
d= o_named->default_val.dbl;
else if (!strcmp(buf, "default")) d= o->default_val.dbl;
@@ -226,7 +229,7 @@ const AVOption *av_set_int(void *obj, const char *name, int64_t n)
*/
const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len)
{
- const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
+ const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
void *dst;
uint8_t *bin;
int len, i;
@@ -259,7 +262,7 @@ const char *av_get_string(void *obj, const char *name, const AVOption **o_out, c
static int av_get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum)
{
- const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
+ const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
void *dst;
if (!o || (o->offset<=0 && o->type != FF_OPT_TYPE_CONST))
goto error;
@@ -538,6 +541,45 @@ void av_opt_free(void *obj)
av_freep((uint8_t *)obj + o->offset);
}
+int av_opt_set_dict(void *obj, AVDictionary **options)
+{
+ AVDictionaryEntry *t = NULL;
+ AVDictionary *tmp = NULL;
+ int ret = 0;
+
+ while ((t = av_dict_get(*options, "", t, AV_DICT_IGNORE_SUFFIX))) {
+ ret = av_set_string3(obj, t->key, t->value, 1, NULL);
+ if (ret == AVERROR_OPTION_NOT_FOUND)
+ av_dict_set(&tmp, t->key, t->value, 0);
+ else if (ret < 0) {
+ av_log(obj, AV_LOG_ERROR, "Error setting option %s to value %s.\n", t->key, t->value);
+ break;
+ }
+ ret = 0;
+ }
+ av_dict_free(options);
+ *options = tmp;
+ return ret;
+}
+
+const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
+ int opt_flags, int search_flags)
+{
+ AVClass *c = *(AVClass**)obj;
+ const AVOption *o = NULL;
+
+ if (c->opt_find && search_flags & AV_OPT_SEARCH_CHILDREN &&
+ (o = c->opt_find(obj, name, unit, opt_flags, search_flags)))
+ return o;
+
+ while (o = av_next_option(obj, o)) {
+ if (!strcmp(o->name, name) && (!unit || (o->unit && !strcmp(o->unit, unit))) &&
+ (o->flags & opt_flags) == opt_flags)
+ return o;
+ }
+ return NULL;
+}
+
#ifdef TEST
#undef printf