[FFmpeg-devel] [PATCH] ffprobe: print array element sections to separate lines

Stefano Sabatini stefasab at gmail.com
Fri Jul 26 17:20:54 CEST 2013


In particular, fix rendering for nested array, as in the
programs->streams->stream case.
---
 ffprobe.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/ffprobe.c b/ffprobe.c
index 0693505..62c6675 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -690,6 +690,7 @@ typedef struct CompactContext {
     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];
+    int dont_terminate_line[SECTION_MAX_NB_LEVELS];
 } CompactContext;
 
 #undef OFFSET
@@ -740,15 +741,23 @@ static void compact_print_section_header(WriterContext *wctx)
 
     av_bprint_clear(&wctx->section_pbuf[wctx->level]);
     if (parent_section &&
-        !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) {
+        !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)) &&
+        !(section       ->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) {
         compact->nested_section[wctx->level] = 1;
         av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
                    wctx->section_pbuf[wctx->level-1].str,
                    (char *)av_x_if_null(section->element_name, section->name));
         wctx->nb_item[wctx->level] = wctx->nb_item[wctx->level-1];
-    } else if (compact->print_section &&
-        !(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
-       printf("%s%c", section->name, compact->item_sep);
+    } else if (!(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) {
+        if (wctx->level >= 2 &&
+            !(wctx->section[wctx->level-2]->flags & SECTION_FLAG_IS_ARRAY) &&  wctx->nb_item[wctx->level-2] &&
+             (wctx->section[wctx->level-1]->flags & SECTION_FLAG_IS_ARRAY) && !wctx->nb_item[wctx->level-1]) {
+            printf("\n");
+            compact->dont_terminate_line[wctx->level] = 1;
+        }
+        if (compact->print_section)
+            printf("%s%c", section->name, compact->item_sep);
+    }
 }
 
 static void compact_print_section_footer(WriterContext *wctx)
@@ -756,7 +765,8 @@ static void compact_print_section_footer(WriterContext *wctx)
     CompactContext *compact = wctx->priv;
 
     if (!compact->nested_section[wctx->level] &&
-        !(wctx->section[wctx->level]->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
+        !(wctx->section[wctx->level]->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)) &&
+        !compact->dont_terminate_line[wctx->level])
         printf("\n");
 }
 
-- 
1.8.1.2



More information about the ffmpeg-devel mailing list