From 641c7afe3c17334b81e3e2eef88f1751eb68f89f Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 3 Oct 2011 19:49:12 +0200 Subject: AVOptions: add new API for enumerating children. This will allow the caller to enumerate child contexts in a generic way and since the API is recursive, it also allows for deeper nesting (e.g. AVFormatContext->AVIOContext->URLContext) This will also allow the new setting/reading API to transparently apply to children contexts. --- libavcodec/options.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'libavcodec/options.c') diff --git a/libavcodec/options.c b/libavcodec/options.c index 1c5240634b..3483db7cc6 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -39,22 +39,27 @@ static const char* context_to_name(void* ptr) { return "NULL"; } -static const AVOption *opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags) +static void *codec_child_next(void *obj, void *prev) { AVCodecContext *s = obj; - AVCodec *c = NULL; + if (!prev && s->codec && s->codec->priv_class && s->priv_data) + return s->priv_data; + return NULL; +} - if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ) && s->priv_data) { - if (s->codec->priv_class) - return av_opt_find(s->priv_data, name, unit, opt_flags, search_flags); - return NULL; - } +static const AVClass *codec_child_class_next(const AVClass *prev) +{ + AVCodec *c = NULL; - while ((c = av_codec_next(c))) { - const AVOption *o; - if (c->priv_class && (o = av_opt_find(&c->priv_class, name, unit, opt_flags, search_flags))) - return o; - } + /* find the codec that corresponds to prev */ + while (prev && (c = av_codec_next(c))) + if (c->priv_class == prev) + break; + + /* find next codec with priv options */ + while (c = av_codec_next(c)) + if (c->priv_class) + return c->priv_class; return NULL; } @@ -522,7 +527,8 @@ static const AVClass av_codec_context_class = { .option = options, .version = LIBAVUTIL_VERSION_INT, .log_level_offset_offset = OFFSET(log_level_offset), - .opt_find = opt_find, + .child_next = codec_child_next, + .child_class_next = codec_child_class_next, }; void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType codec_type){ -- cgit v1.2.3