aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/tests
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2024-04-12 19:10:25 -0300
committerJames Almer <jamrial@gmail.com>2024-04-23 23:54:46 -0300
commit8616cfe0890e49437d2b373f97a9c791eb1b7c4c (patch)
tree1ae274c18177a035880b37baaf8c26ed20100298 /libavutil/tests
parent855d4b52547b2f8fc38b400e5d18cf44e621e163 (diff)
downloadffmpeg-8616cfe0890e49437d2b373f97a9c791eb1b7c4c.tar.gz
avutil/opt: add support for children objects in av_opt_serialize
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavutil/tests')
-rw-r--r--libavutil/tests/opt.c49
1 files changed, 46 insertions, 3 deletions
diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c
index d43391025a..abe1b0dee4 100644
--- a/libavutil/tests/opt.c
+++ b/libavutil/tests/opt.c
@@ -30,6 +30,7 @@
typedef struct TestContext {
const AVClass *class;
+ struct ChildContext *child;
int num;
int toggle;
char *string;
@@ -123,10 +124,46 @@ static const char *test_get_name(void *ctx)
return "test";
}
+typedef struct ChildContext {
+ const AVClass *class;
+ int64_t child_num64;
+ int child_num;
+} ChildContext;
+
+#undef OFFSET
+#define OFFSET(x) offsetof(ChildContext, x)
+
+static const AVOption child_options[]= {
+ {"child_num64", "set num 64bit", OFFSET(child_num64), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, 100, 1 },
+ {"child_num", "set child_num", OFFSET(child_num), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 100, 1 },
+ { NULL },
+};
+
+static const char *child_get_name(void *ctx)
+{
+ return "child";
+}
+
+static const AVClass child_class = {
+ .class_name = "ChildContext",
+ .item_name = child_get_name,
+ .option = child_options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
+static void *test_child_next(void *obj, void *prev)
+{
+ TestContext *test_ctx = obj;
+ if (!prev)
+ return test_ctx->child;
+ return NULL;
+}
+
static const AVClass test_class = {
.class_name = "TestContext",
.item_name = test_get_name,
.option = test_options,
+ .child_next = test_child_next,
.version = LIBAVUTIL_VERSION_INT,
};
@@ -277,13 +314,19 @@ int main(void)
av_set_options_string(&test_ctx, buf, "=", ",");
av_free(buf);
if (av_opt_serialize(&test_ctx, 0, 0, &buf, '=', ',') >= 0) {
+ ChildContext child_ctx = { 0 };
printf("%s\n", buf);
av_free(buf);
- if (av_opt_serialize(&test_ctx, 0, AV_OPT_SERIALIZE_SKIP_DEFAULTS, &buf, '=', ',') >= 0) {
- if (strlen(buf))
- printf("%s\n", buf);
+ child_ctx.class = &child_class;
+ test_ctx.child = &child_ctx;
+ if (av_opt_serialize(&test_ctx, 0,
+ AV_OPT_SERIALIZE_SKIP_DEFAULTS|AV_OPT_SERIALIZE_SEARCH_CHILDREN,
+ &buf, '=', ',') >= 0) {
+ printf("%s\n", buf);
av_free(buf);
}
+ av_opt_free(&child_ctx);
+ test_ctx.child = NULL;
}
}
av_opt_free(&test_ctx);