[FFmpeg-devel] =?y?q?=5BPATCH=5D=20ffprobe=3A=20generalize=20nesting=20model=20for=20the=20default=20writer?=
Stefano Sabatini
stefasab at gmail.com
Wed Sep 26 13:11:19 CEST 2012
This is required by the pending change related to disposition.
"TAGS" section is no more treated like a special case, and thus the
prefix name for the TAGS section is changed from "TAG:" to "TAGS:".
This changes the writer output.
---
doc/ffprobe.texi | 2 +-
ffprobe.c | 47 +++++++++++++++++++++++++++++----------
tests/ref/fate/ffprobe_default | 6 ++--
3 files changed, 39 insertions(+), 16 deletions(-)
diff --git a/doc/ffprobe.texi b/doc/ffprobe.texi
index 58ea383..a312c86 100644
--- a/doc/ffprobe.texi
+++ b/doc/ffprobe.texi
@@ -204,7 +204,7 @@ keyN=valN
@end example
Metadata tags are printed as a line in the corresponding FORMAT or
-STREAM section, and are prefixed by the string "TAG:".
+STREAM section, and are prefixed by the string "TAGS:".
This writer accepts options as a list of @var{key}=@var{value} pairs,
separated by ":".
diff --git a/ffprobe.c b/ffprobe.c
index 5cff171..0a3ec06 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -491,6 +491,8 @@ typedef struct DefaultContext {
const AVClass *class;
int nokey;
int noprint_wrappers;
+ int nested_section[SECTION_MAX_NB_LEVELS];
+ AVBPrint prefix[SECTION_MAX_NB_LEVELS];
} DefaultContext;
#define OFFSET(x) offsetof(DefaultContext, x)
@@ -515,6 +517,25 @@ static inline char *upcase_string(char *dst, size_t dst_size, const char *src)
return dst;
}
+static int default_init(WriterContext *wctx, const char *args)
+{
+ DefaultContext *def = wctx->priv;
+ int i;
+
+ for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
+ av_bprint_init(&def->prefix[i], 1, AV_BPRINT_SIZE_UNLIMITED);
+ return 0;
+}
+
+static void default_uninit(WriterContext *wctx)
+{
+ DefaultContext *def = wctx->priv;
+ int i;
+
+ for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
+ av_bprint_finalize(&def->prefix[i], NULL);
+}
+
static void default_print_section_header(WriterContext *wctx)
{
DefaultContext *def = wctx->priv;
@@ -523,9 +544,15 @@ static void default_print_section_header(WriterContext *wctx)
const struct section *parent_section = wctx->level ?
wctx->section[wctx->level-1] : NULL;
- if (def->noprint_wrappers ||
- (parent_section &&
- !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))))
+ av_bprint_clear(&def->prefix[wctx->level]);
+ if (parent_section &&
+ !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) {
+ def->nested_section[wctx->level] = 1;
+ av_bprintf(&def->prefix[wctx->level], "%s%s:", def->prefix[wctx->level-1].str,
+ upcase_string(buf, sizeof(buf), section->name));
+ }
+
+ if (def->noprint_wrappers || def->nested_section[wctx->level])
return;
if (!(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
@@ -536,13 +563,9 @@ static void default_print_section_footer(WriterContext *wctx)
{
DefaultContext *def = wctx->priv;
const struct section *section = wctx->section[wctx->level];
- const struct section *parent_section = wctx->level ?
- wctx->section[wctx->level-1] : NULL;
char buf[32];
- if (def->noprint_wrappers ||
- (parent_section &&
- !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))))
+ if (def->noprint_wrappers || def->nested_section[wctx->level])
return;
if (!(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
@@ -552,11 +575,9 @@ static void default_print_section_footer(WriterContext *wctx)
static void default_print_str(WriterContext *wctx, const char *key, const char *value)
{
DefaultContext *def = wctx->priv;
- const struct section *section = wctx->section[wctx->level];
- const char *key_prefix = !strcmp(section->name, "tags") ? "TAG:" : "";
if (!def->nokey)
- printf("%s%s=", key_prefix, key);
+ printf("%s%s=", def->prefix[wctx->level].str, key);
printf("%s\n", value);
}
@@ -565,13 +586,15 @@ static void default_print_int(WriterContext *wctx, const char *key, long long in
DefaultContext *def = wctx->priv;
if (!def->nokey)
- printf("%s=", key);
+ printf("%s%s=", def->prefix[wctx->level].str, key);
printf("%lld\n", value);
}
static const Writer default_writer = {
.name = "default",
.priv_size = sizeof(DefaultContext),
+ .init = default_init,
+ .uninit = default_uninit,
.print_section_header = default_print_section_header,
.print_section_footer = default_print_section_footer,
.print_integer = default_print_int,
diff --git a/tests/ref/fate/ffprobe_default b/tests/ref/fate/ffprobe_default
index a9b555b..d65f7c1 100644
--- a/tests/ref/fate/ffprobe_default
+++ b/tests/ref/fate/ffprobe_default
@@ -573,7 +573,7 @@ start_time=0.000000
duration=11.960000
size=1054625
bit_rate=705434
-TAG:title=ffprobe test file
-TAG:comment='A comment with CSV, XML & JSON special chars': <tag value="x">
-TAG:comment2=I ⥠Ãñîçødâ¬
+TAGS:title=ffprobe test file
+TAGS:comment='A comment with CSV, XML & JSON special chars': <tag value="x">
+TAGS:comment2=I ⥠Ãñîçødâ¬
[/FORMAT]
--
1.7.5.4
More information about the ffmpeg-devel
mailing list