Commit 3b1355bb authored by Stefano Sabatini's avatar Stefano Sabatini

ffprobe: change formatting logic in the JSON writer

Print a "\n" at the end of each section, also print the section name in
the section print function, print the chapter name only in case the
chapter contains multiple entries.

Increase textual output readability - different sections can be
distinguished more easily.
parent 48f37b1d
...@@ -798,15 +798,16 @@ static void json_print_chapter_header(WriterContext *wctx, const char *chapter) ...@@ -798,15 +798,16 @@ static void json_print_chapter_header(WriterContext *wctx, const char *chapter)
if (wctx->nb_chapter) if (wctx->nb_chapter)
printf(","); printf(",");
printf("\n");
json->multiple_entries = !strcmp(chapter, "packets") || !strcmp(chapter, "frames" ) || json->multiple_entries = !strcmp(chapter, "packets") || !strcmp(chapter, "frames" ) ||
!strcmp(chapter, "packets_and_frames") || !strcmp(chapter, "packets_and_frames") ||
!strcmp(chapter, "streams"); !strcmp(chapter, "streams");
printf("\n"); JSON_INDENT(); if (json->multiple_entries) {
printf("\"%s\":%s", json_escape_str(&json->buf, &json->buf_size, chapter, wctx), JSON_INDENT();
json->multiple_entries ? " [" : " "); printf("\"%s\": [\n", json_escape_str(&json->buf, &json->buf_size, chapter, wctx));
json->print_packets_and_frames = !strcmp(chapter, "packets_and_frames"); json->print_packets_and_frames = !strcmp(chapter, "packets_and_frames");
if (json->multiple_entries)
json->indent_level++; json->indent_level++;
}
} }
static void json_print_chapter_footer(WriterContext *wctx, const char *chapter) static void json_print_chapter_footer(WriterContext *wctx, const char *chapter)
...@@ -814,8 +815,10 @@ static void json_print_chapter_footer(WriterContext *wctx, const char *chapter) ...@@ -814,8 +815,10 @@ static void json_print_chapter_footer(WriterContext *wctx, const char *chapter)
JSONContext *json = wctx->priv; JSONContext *json = wctx->priv;
if (json->multiple_entries) { if (json->multiple_entries) {
printf("]"); printf("\n");
json->indent_level--; json->indent_level--;
JSON_INDENT();
printf("]");
} }
} }
...@@ -823,7 +826,11 @@ static void json_print_section_header(WriterContext *wctx, const char *section) ...@@ -823,7 +826,11 @@ static void json_print_section_header(WriterContext *wctx, const char *section)
{ {
JSONContext *json = wctx->priv; JSONContext *json = wctx->priv;
if (wctx->nb_section) printf(","); if (wctx->nb_section)
printf(",\n");
JSON_INDENT();
if (!json->multiple_entries)
printf("\"%s\": ", section);
printf("{\n"); printf("{\n");
json->indent_level++; json->indent_level++;
/* this is required so the parser can distinguish between packets and frames */ /* this is required so the parser can distinguish between packets and frames */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment