mirror of https://git.ffmpeg.org/ffmpeg.git
ffprobe: add support for nested options in writer contexts
This commit is contained in:
parent
e87190f5d2
commit
11cba3ba9d
37
ffprobe.c
37
ffprobe.c
|
@ -306,11 +306,22 @@ static const char *writer_get_name(void *p)
|
||||||
return wctx->writer->name;
|
return wctx->writer->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define OFFSET(x) offsetof(WriterContext, x)
|
||||||
|
|
||||||
|
static void *writer_child_next(void *obj, void *prev)
|
||||||
|
{
|
||||||
|
WriterContext *ctx = obj;
|
||||||
|
if (!prev && ctx->writer && ctx->writer->priv_class && ctx->priv)
|
||||||
|
return ctx->priv;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static const AVClass writer_class = {
|
static const AVClass writer_class = {
|
||||||
"Writer",
|
"Writer",
|
||||||
writer_get_name,
|
writer_get_name,
|
||||||
NULL,
|
NULL,
|
||||||
LIBAVUTIL_VERSION_INT,
|
LIBAVUTIL_VERSION_INT,
|
||||||
|
.child_next = writer_child_next,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void writer_close(WriterContext **wctx)
|
static void writer_close(WriterContext **wctx)
|
||||||
|
@ -351,14 +362,35 @@ static int writer_open(WriterContext **wctx, const Writer *writer, const char *a
|
||||||
(*wctx)->sections = sections;
|
(*wctx)->sections = sections;
|
||||||
(*wctx)->nb_sections = nb_sections;
|
(*wctx)->nb_sections = nb_sections;
|
||||||
|
|
||||||
|
av_opt_set_defaults(*wctx);
|
||||||
|
|
||||||
if (writer->priv_class) {
|
if (writer->priv_class) {
|
||||||
void *priv_ctx = (*wctx)->priv;
|
void *priv_ctx = (*wctx)->priv;
|
||||||
*((const AVClass **)priv_ctx) = writer->priv_class;
|
*((const AVClass **)priv_ctx) = writer->priv_class;
|
||||||
av_opt_set_defaults(priv_ctx);
|
av_opt_set_defaults(priv_ctx);
|
||||||
|
}
|
||||||
|
|
||||||
if (args &&
|
/* convert options to dictionary */
|
||||||
(ret = av_set_options_string(priv_ctx, args, "=", ":")) < 0)
|
if (args) {
|
||||||
|
AVDictionary *opts = NULL;
|
||||||
|
AVDictionaryEntry *opt = NULL;
|
||||||
|
|
||||||
|
if ((ret = av_dict_parse_string(&opts, args, "=", ":", 0)) < 0) {
|
||||||
|
av_log(*wctx, AV_LOG_ERROR, "Failed to parse option string '%s' provided to writer context\n", args);
|
||||||
|
av_dict_free(&opts);
|
||||||
goto fail;
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((opt = av_dict_get(opts, "", opt, AV_DICT_IGNORE_SUFFIX))) {
|
||||||
|
if ((ret = av_opt_set(*wctx, opt->key, opt->value, AV_OPT_SEARCH_CHILDREN)) < 0) {
|
||||||
|
av_log(*wctx, AV_LOG_ERROR, "Failed to set option '%s' with value '%s' provided to writer context\n",
|
||||||
|
opt->key, opt->value);
|
||||||
|
av_dict_free(&opts);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
av_dict_free(&opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
|
for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
|
||||||
|
@ -557,6 +589,7 @@ typedef struct DefaultContext {
|
||||||
int nested_section[SECTION_MAX_NB_LEVELS];
|
int nested_section[SECTION_MAX_NB_LEVELS];
|
||||||
} DefaultContext;
|
} DefaultContext;
|
||||||
|
|
||||||
|
#undef OFFSET
|
||||||
#define OFFSET(x) offsetof(DefaultContext, x)
|
#define OFFSET(x) offsetof(DefaultContext, x)
|
||||||
|
|
||||||
static const AVOption default_options[] = {
|
static const AVOption default_options[] = {
|
||||||
|
|
Loading…
Reference in New Issue