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. --- libavformat/options.c | 51 +++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) (limited to 'libavformat/options.c') diff --git a/libavformat/options.c b/libavformat/options.c index 43a6dec323..475166f3ce 100644 --- a/libavformat/options.c +++ b/libavformat/options.c @@ -33,30 +33,36 @@ static const char* format_to_name(void* ptr) else return "NULL"; } -static const AVOption *opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags) +static void *format_child_next(void *obj, void *prev) +{ + AVFormatContext *s = obj; + if (!prev && s->priv_data && + ((s->iformat && s->iformat->priv_class) || + s->oformat && s->oformat->priv_class)) + return s->priv_data; + return NULL; +} + +static const AVClass *format_child_class_next(const AVClass *prev) { - AVFormatContext *s = obj; AVInputFormat *ifmt = NULL; AVOutputFormat *ofmt = NULL; - if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ) && s->priv_data) { - if ((s->iformat && !s->iformat->priv_class) || - (s->oformat && !s->oformat->priv_class)) - return NULL; - return av_opt_find(s->priv_data, name, unit, opt_flags, search_flags); - } - - while ((ifmt = av_iformat_next(ifmt))) { - const AVOption *o; - - if (ifmt->priv_class && (o = av_opt_find(&ifmt->priv_class, name, unit, opt_flags, search_flags))) - return o; - } - while ((ofmt = av_oformat_next(ofmt))) { - const AVOption *o; - - if (ofmt->priv_class && (o = av_opt_find(&ofmt->priv_class, name, unit, opt_flags, search_flags))) - return o; - } + + while (prev && (ifmt = av_iformat_next(ifmt))) + if (ifmt->priv_class == prev) + break; + if ((prev && ifmt) || (!prev)) + while (ifmt = av_iformat_next(ifmt)) + if (ifmt->priv_class) + return ifmt->priv_class; + + while (prev && (ofmt = av_oformat_next(ofmt))) + if (ofmt->priv_class == prev) + break; + while (ofmt = av_oformat_next(ofmt)) + if (ofmt->priv_class) + return ofmt->priv_class; + return NULL; } @@ -103,7 +109,8 @@ static const AVClass av_format_context_class = { .item_name = format_to_name, .option = options, .version = LIBAVUTIL_VERSION_INT, - .opt_find = opt_find, + .child_next = format_child_next, + .child_class_next = format_child_class_next, }; static void avformat_get_context_defaults(AVFormatContext *s) -- cgit v1.2.3