summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2011-10-03 19:49:12 +0200
committerAnton Khirnov <anton@khirnov.net>2011-10-12 16:51:16 +0200
commit641c7afe3c17334b81e3e2eef88f1751eb68f89f (patch)
tree27ff55b88d052b7947b40a40834f80f0c2c99083 /libavcodec
parent1bca8f4bc596d286dc50e572f5f8d52e4fc3a8dc (diff)
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.
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/options.c32
1 files changed, 19 insertions, 13 deletions
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){