ffprobe: do not treat array elements as nested in the compact writer

This fixes rendering of sections containing nested elements followed by
an array, for example as in the case:
programs->streams->stream

enabled by the -show_programs option.
pull/37/head
Stefano Sabatini 12 years ago
parent 18df69d238
commit 2fcd400669
  1. 21
      ffprobe.c

@ -675,6 +675,8 @@ typedef struct CompactContext {
char *escape_mode_str; char *escape_mode_str;
const char * (*escape_str)(AVBPrint *dst, const char *src, const char sep, void *log_ctx); const char * (*escape_str)(AVBPrint *dst, const char *src, const char sep, void *log_ctx);
int nested_section[SECTION_MAX_NB_LEVELS]; int nested_section[SECTION_MAX_NB_LEVELS];
int has_nested_elems[SECTION_MAX_NB_LEVELS];
int terminate_line[SECTION_MAX_NB_LEVELS];
} CompactContext; } CompactContext;
#undef OFFSET #undef OFFSET
@ -722,18 +724,28 @@ static void compact_print_section_header(WriterContext *wctx)
const struct section *section = wctx->section[wctx->level]; const struct section *section = wctx->section[wctx->level];
const struct section *parent_section = wctx->level ? const struct section *parent_section = wctx->level ?
wctx->section[wctx->level-1] : NULL; wctx->section[wctx->level-1] : NULL;
compact->terminate_line[wctx->level] = 1;
compact->has_nested_elems[wctx->level] = 0;
av_bprint_clear(&wctx->section_pbuf[wctx->level]); av_bprint_clear(&wctx->section_pbuf[wctx->level]);
if (parent_section && if (!(section->flags & SECTION_FLAG_IS_ARRAY) && parent_section &&
!(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) { !(parent_section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) {
compact->nested_section[wctx->level] = 1; compact->nested_section[wctx->level] = 1;
compact->has_nested_elems[wctx->level-1] = 1;
av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:", av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
wctx->section_pbuf[wctx->level-1].str, wctx->section_pbuf[wctx->level-1].str,
(char *)av_x_if_null(section->element_name, section->name)); (char *)av_x_if_null(section->element_name, section->name));
wctx->nb_item[wctx->level] = wctx->nb_item[wctx->level-1]; wctx->nb_item[wctx->level] = wctx->nb_item[wctx->level-1];
} else if (compact->print_section && } else {
!(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY))) if (parent_section && compact->has_nested_elems[wctx->level-1] &&
printf("%s%c", section->name, compact->item_sep); (section->flags & SECTION_FLAG_IS_ARRAY)) {
compact->terminate_line[wctx->level-1] = 0;
printf("\n");
}
if (compact->print_section &&
!(section->flags & (SECTION_FLAG_IS_WRAPPER|SECTION_FLAG_IS_ARRAY)))
printf("%s%c", section->name, compact->item_sep);
}
} }
static void compact_print_section_footer(WriterContext *wctx) static void compact_print_section_footer(WriterContext *wctx)
@ -741,6 +753,7 @@ static void compact_print_section_footer(WriterContext *wctx)
CompactContext *compact = wctx->priv; CompactContext *compact = wctx->priv;
if (!compact->nested_section[wctx->level] && if (!compact->nested_section[wctx->level] &&
compact->terminate_line[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)))
printf("\n"); printf("\n");
} }

Loading…
Cancel
Save