[FFmpeg-devel] [PATCH] ffprobe: generalize nesting model for the compact writer
Clément Bœsch
ubitux at gmail.com
Fri Sep 28 23:47:00 CEST 2012
On Fri, Sep 28, 2012 at 07:34:21PM +0200, Stefano Sabatini wrote:
> On date Wednesday 2012-09-26 15:57:50 +0200, Stefano Sabatini encoded:
> > 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.
>
> Updated.
> --
> FFmpeg = Frightening Fierce Magical Political Ephemeral Game
> From 4a6fc68f5c02eab96e0bf6cd14f51ff2d95a3f11 Mon Sep 17 00:00:00 2001
> From: Stefano Sabatini <stefasab at gmail.com>
> Date: Wed, 26 Sep 2012 15:39:12 +0200
> Subject: [PATCH] ffprobe: generalize nesting model for the compact writer
>
> 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.
> ---
> ffprobe.c | 42 +++++++++++++++++++++++++++++++-----------
> 1 files changed, 31 insertions(+), 11 deletions(-)
>
> diff --git a/ffprobe.c b/ffprobe.c
> index 77ddcba..acde8eb 100644
> --- a/ffprobe.c
> +++ b/ffprobe.c
> @@ -661,6 +661,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
> @@ -683,6 +685,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",
> @@ -699,44 +702,60 @@ 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);
> +}
> +
Note: I hope this will get factorized with the other writers at some point
> 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,
> + (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 &&
> + } 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)
> @@ -745,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);
> }
>
> @@ -753,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,
Just like the change to the default writer, LGTM
--
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120928/53356396/attachment.asc>
More information about the ffmpeg-devel
mailing list