[FFmpeg-devel] =?y?q?=5BPATCH=5D=20ffprobe=3A=20generalize=20nesting=20model=20for=20the=20compact=20writer?=

Stefano Sabatini stefasab at gmail.com
Wed Sep 26 15:57:50 CEST 2012


Regular section fields nested in a regular section are now prefixed by
the nested section name.

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.
---
 ffprobe.c                      |   41 +++++++++++++++++++++++++++++----------
 tests/ref/fate/ffprobe_compact |    2 +-
 2 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/ffprobe.c b/ffprobe.c
index f93ff6c..1b6bea7 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -662,6 +662,8 @@ typedef struct CompactContext {
     int print_section;
     char *escape_mode_str;
     const char * (*escape_str)(AVBPrint *dst, const char *src, const char sep, void *log_ctx);
+    int nested_section[SECTION_MAX_NB_LEVELS];
+    AVBPrint prefix[SECTION_MAX_NB_LEVELS];
 } CompactContext;
 
 #undef OFFSET
@@ -684,6 +686,7 @@ DEFINE_WRITER_CLASS(compact);
 static av_cold int compact_init(WriterContext *wctx)
 {
     CompactContext *compact = wctx->priv;
+    int i;
 
     if (strlen(compact->item_sep_str) != 1) {
         av_log(wctx, AV_LOG_ERROR, "Item separator '%s' specified, but must contain a single character\n",
@@ -700,44 +703,59 @@ static av_cold int compact_init(WriterContext *wctx)
         return AVERROR(EINVAL);
     }
 
+    for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
+        av_bprint_init(&compact->prefix[i], 1, AV_BPRINT_SIZE_UNLIMITED);
     return 0;
 }
 
+static void compact_uninit(WriterContext *wctx)
+{
+    CompactContext *compact = wctx->priv;
+    int i;
+
+    for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
+        av_bprint_finalize(&compact->prefix[i], NULL);
+}
+
 static void compact_print_section_header(WriterContext *wctx)
 {
     CompactContext *compact = wctx->priv;
     const struct section *section = wctx->section[wctx->level];
+    const struct section *parent_section = wctx->level ?
+        wctx->section[wctx->level-1] : NULL;
 
-    if (!strcmp(section->name, "tags"))
+    av_bprint_clear(&compact->prefix[wctx->level]);
+    if (parent_section &&
+        !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) {
+        compact->nested_section[wctx->level] = 1;
+        av_bprintf(&compact->prefix[wctx->level], "%s%s:",
+                   compact->prefix[wctx->level-1].str, section->name);
         wctx->nb_item[wctx->level] = wctx->nb_item[wctx->level-1];
-    else if (compact->print_section &&
+    } else if (compact->print_section &&
         !(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
-        printf("%s%c", section->name, compact->item_sep);
+       printf("%s%c", section->name, compact->item_sep);
 }
 
 static void compact_print_section_footer(WriterContext *wctx)
 {
-    const struct section *section = wctx->section[wctx->level];
+    CompactContext *compact = wctx->priv;
 
-    if (strcmp(section->name, "tags") &&
-        !(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
+    if (!compact->nested_section[wctx->level] &&
+        !(wctx->section[wctx->level]->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
         printf("\n");
 }
 
 static void compact_print_str(WriterContext *wctx, const char *key, const char *value)
 {
     CompactContext *compact = wctx->priv;
-    const struct section *section = wctx->section[wctx->level];
-    const char *key_prefix = !strcmp(section->name, "tags") ? "tag:" : "";
     AVBPrint buf;
 
     if (wctx->nb_item[wctx->level]) printf("%c", compact->item_sep);
     if (!compact->nokey)
-        printf("%s%s=", key_prefix, key);
+        printf("%s%s=", compact->prefix[wctx->level].str, key);
     av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
     printf("%s", compact->escape_str(&buf, value, compact->item_sep, wctx));
     av_bprint_finalize(&buf, NULL);
-
 }
 
 static void compact_print_int(WriterContext *wctx, const char *key, long long int value)
@@ -746,7 +764,7 @@ static void compact_print_int(WriterContext *wctx, const char *key, long long in
 
     if (wctx->nb_item[wctx->level]) printf("%c", compact->item_sep);
     if (!compact->nokey)
-        printf("%s=", key);
+        printf("%s%s=", compact->prefix[wctx->level].str, key);
     printf("%lld", value);
 }
 
@@ -754,6 +772,7 @@ static const Writer compact_writer = {
     .name                 = "compact",
     .priv_size            = sizeof(CompactContext),
     .init                 = compact_init,
+    .uninit               = compact_uninit,
     .print_section_header = compact_print_section_header,
     .print_section_footer = compact_print_section_footer,
     .print_integer        = compact_print_int,
diff --git a/tests/ref/fate/ffprobe_compact b/tests/ref/fate/ffprobe_compact
index 71239fe..87c3240 100644
--- a/tests/ref/fate/ffprobe_compact
+++ b/tests/ref/fate/ffprobe_compact
@@ -29,4 +29,4 @@ frame|media_type=video|key_frame=1|pkt_pts=3|pkt_pts_time=0.120000|pkt_dts=3|pkt
 stream|index=0|codec_name=pcm_s16le|profile=unknown|codec_type=audio|codec_time_base=1/44100|codec_tag_string=[1][0][0][0]|codec_tag=0x0001|default=0|forced=0|sample_fmt=s16|sample_rate=44100|channels=1|bits_per_sample=16|id=N/A|r_frame_rate=0/0|avg_frame_rate=0/0|time_base=1/44100|start_pts=0|start_time=0.000000|duration_ts=527313|duration=11.957211|bit_rate=705600|nb_frames=N/A|nb_read_frames=6|nb_read_packets=6
 stream|index=1|codec_name=rawvideo|profile=unknown|codec_type=video|codec_time_base=1/25|codec_tag_string=RGB[24]|codec_tag=0x18424752|default=0|forced=0|width=320|height=240|has_b_frames=0|sample_aspect_ratio=1:1|display_aspect_ratio=4:3|pix_fmt=rgb24|level=-99|timecode=N/A|attached_pic=0|id=N/A|r_frame_rate=25/1|avg_frame_rate=0/0|time_base=1/25|start_pts=0|start_time=0.000000|duration_ts=299|duration=11.960000|bit_rate=N/A|nb_frames=N/A|nb_read_frames=4|nb_read_packets=4
 stream|index=2|codec_name=rawvideo|profile=unknown|codec_type=video|codec_time_base=1/25|codec_tag_string=RGB[24]|codec_tag=0x18424752|default=0|forced=0|width=100|height=100|has_b_frames=0|sample_aspect_ratio=1:1|display_aspect_ratio=1:1|pix_fmt=rgb24|level=-99|timecode=N/A|attached_pic=0|id=N/A|r_frame_rate=25/1|avg_frame_rate=0/0|time_base=1/25|start_pts=0|start_time=0.000000|duration_ts=299|duration=11.960000|bit_rate=N/A|nb_frames=N/A|nb_read_frames=4|nb_read_packets=4
-format|filename=tests/data/ffprobe-test.nut|nb_streams=3|format_name=nut|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€
+format|filename=tests/data/ffprobe-test.nut|nb_streams=3|format_name=nut|start_time=0.000000|duration=11.960000|size=1054625|bit_rate=705434|tags:title=ffprobe test file|tags:comment='A comment with CSV, XML & JSON special chars': <tag value="x">|tags:comment2=I ♥ Üñîçød€
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list