Browse code

ffprobe: rework/fix flat writer

Do not build from scratch the section header for each section, but build
using the previous level buffer, thus improving efficiency and fix some
few corner cases which are exposed by the pending disposition patch.

Stefano Sabatini authored on 2012/09/27 02:18:03
Showing 1 changed files
... ...
@@ -898,35 +898,32 @@ static void flat_print_section_header(WriterContext *wctx)
898 898
 {
899 899
     FlatContext *flat = wctx->priv;
900 900
     AVBPrint *buf = &flat->section_header[wctx->level];
901
-    int i;
901
+    const struct section *section = wctx->section[wctx->level];
902
+    const struct section *parent_section = wctx->level ?
903
+        wctx->section[wctx->level-1] : NULL;
902 904
 
903 905
     /* build section header */
904 906
     av_bprint_clear(buf);
905
-    for (i = 1; i <= wctx->level; i++) {
906
-        if (flat->hierarchical ||
907
-            !(wctx->section[i]->flags & (SECTION_FLAG_IS_ARRAY|SECTION_FLAG_IS_WRAPPER)))
908
-            av_bprintf(buf, "%s%s", wctx->section[i]->name, flat->sep_str);
909
-    }
910
-}
911
-
912
-static void flat_print_key_prefix(WriterContext *wctx)
913
-{
914
-    FlatContext *flat = wctx->priv;
915
-    const struct section *parent_section = wctx->section[wctx->level-1];
907
+    if (!parent_section)
908
+        return;
909
+    av_bprintf(buf, "%s", flat->section_header[wctx->level-1].str);
916 910
 
917
-    printf("%s", flat->section_header[wctx->level].str);
911
+    if (flat->hierarchical ||
912
+        !(section->flags & (SECTION_FLAG_IS_ARRAY|SECTION_FLAG_IS_WRAPPER))) {
913
+        av_bprintf(buf, "%s%s", wctx->section[wctx->level]->name, flat->sep_str);
918 914
 
919
-    if (parent_section->flags & SECTION_FLAG_IS_ARRAY) {
920
-        int n = parent_section->id == SECTION_ID_PACKETS_AND_FRAMES ?
921
-            wctx->nb_section_packet_frame : wctx->nb_item[wctx->level-1];
922
-        printf("%d%s", n, flat->sep_str);
915
+        if (parent_section->flags & SECTION_FLAG_IS_ARRAY) {
916
+            int n = parent_section->id == SECTION_ID_PACKETS_AND_FRAMES ?
917
+                wctx->nb_section_packet_frame : wctx->nb_item[wctx->level-1];
918
+            av_bprintf(buf, "%d%s", n, flat->sep_str);
919
+        }
923 920
     }
924 921
 }
925 922
 
926 923
 static void flat_print_int(WriterContext *wctx, const char *key, long long int value)
927 924
 {
928
-    flat_print_key_prefix(wctx);
929
-    printf("%s=%lld\n", key, value);
925
+    FlatContext *flat = wctx->priv;
926
+    printf("%s%s=%lld\n", flat->section_header[wctx->level].str, key, value);
930 927
 }
931 928
 
932 929
 static void flat_print_str(WriterContext *wctx, const char *key, const char *value)
... ...
@@ -934,7 +931,7 @@ static void flat_print_str(WriterContext *wctx, const char *key, const char *val
934 934
     FlatContext *flat = wctx->priv;
935 935
     AVBPrint buf;
936 936
 
937
-    flat_print_key_prefix(wctx);
937
+    printf("%s", flat->section_header[wctx->level].str);
938 938
     av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED);
939 939
     printf("%s=", flat_escape_key_str(&buf, key, flat->sep));
940 940
     av_bprint_clear(&buf);