You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-11-23 21:54:53 +02:00
avutil/opt: add support for children objects in av_opt_serialize
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user