[FFmpeg-devel] [PATCH 2/2] graphdump: use av_bprintf API.

Clément Bœsch ubitux at gmail.com
Wed Feb 1 23:35:00 CET 2012


On Wed, Feb 01, 2012 at 09:37:01PM +0100, Nicolas George wrote:
> 
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
> ---
>  libavfilter/graphdump.c |  109 +++++++++++++++++++++-------------------------
>  1 files changed, 50 insertions(+), 59 deletions(-)
> 
> 
> Reindentation would be needed afterwards.
> 
> 
> diff --git a/libavfilter/graphdump.c b/libavfilter/graphdump.c
> index 8775c1c..f284294 100644
> --- a/libavfilter/graphdump.c
> +++ b/libavfilter/graphdump.c
> @@ -21,27 +21,22 @@
>  
>  #include <string.h>
>  
> +#include "libavutil/avstring.h"
>  #include "libavutil/pixdesc.h"
>  #include "avfilter.h"
>  #include "avfiltergraph.h"
>  
> -#define BPRINTF(...) \
> -    cur += snprintf(cur, buf_end - FFMIN(cur, buf_end), __VA_ARGS__)
> -
> -#define BPAD(c, l) \
> -    do { \
> -        if (cur < buf_end) memset(cur, c, FFMIN(l, buf_end - cur)); cur += l; \
> -    } while (0)
> -
> -static int snprint_link_prop(char *buf, char *buf_end, AVFilterLink *link)
> +static int print_link_prop(AVBPrint *buf, AVFilterLink *link)
>  {
> -    char *cur = buf, *format;
> +    char *format;
>      char layout[64];
>  
> +    if (!buf)
> +        buf = &(AVBPrint){ }; /* dummy buffer */

Isn't {} really supported by all compilers? I think you need to {0}.

>      switch (link->type) {
>          case AVMEDIA_TYPE_VIDEO:
>              format = av_x_if_null(av_get_pix_fmt_name(link->format), "?");
> -            BPRINTF("[%dx%d %d:%d %s]", link->w, link->h,
> +            av_bprintf(buf, "[%dx%d %d:%d %s]", link->w, link->h,
>                      link->sample_aspect_ratio.num,
>                      link->sample_aspect_ratio.den,
>                      format);
> @@ -51,23 +46,21 @@ static int snprint_link_prop(char *buf, char *buf_end, AVFilterLink *link)
>              av_get_channel_layout_string(layout, sizeof(layout),
>                                           -1, link->channel_layout);
>              format = av_x_if_null(av_get_sample_fmt_name(link->format), "?");
> -            BPRINTF("[%dHz %s:%s:%s]",
> +            av_bprintf(buf, "[%dHz %s:%s:%s]",
>                      (int)link->sample_rate, format, layout,
>                      link->planar ? "planar" : "packed");
>              break;
>  
>          default:
> -            BPRINTF("?");
> +            av_bprintf(buf, "?");
>              break;
>      }
> -    return cur - buf;
> +    return buf->len;
>  }
>  
> -static size_t avfilter_graph_dump_to_buf(AVFilterGraph *graph,
> -                                         char *buf, char *buf_end)
> +static void avfilter_graph_dump_to_buf(AVBPrint *buf, AVFilterGraph *graph)
>  {
> -    char *cur = buf, *e;
> -    unsigned i, j, x;
> +    unsigned i, j, x, e;
>  
>      for (i = 0; i < graph->filter_count; i++) {
>          AVFilterContext *filter = graph->filters[i];
> @@ -83,23 +76,23 @@ static size_t avfilter_graph_dump_to_buf(AVFilterGraph *graph,
>              unsigned ln = strlen(l->src->name) + 1 + strlen(l->srcpad->name);
>              max_src_name = FFMAX(max_src_name, ln);
>              max_in_name = FFMAX(max_in_name, strlen(l->dstpad->name));
> -            max_in_fmt = FFMAX(max_in_fmt, snprint_link_prop(NULL, NULL, l));
> +            max_in_fmt = FFMAX(max_in_fmt, print_link_prop(NULL, l));
>          }
>          for (j = 0; j < filter->output_count; j++) {
>              AVFilterLink *l = filter->outputs[j];
>              unsigned ln = strlen(l->dst->name) + 1 + strlen(l->dstpad->name);
>              max_dst_name = FFMAX(max_dst_name, ln);
>              max_out_name = FFMAX(max_out_name, strlen(l->srcpad->name));
> -            max_out_fmt = FFMAX(max_out_fmt, snprint_link_prop(NULL, NULL, l));
> +            max_out_fmt = FFMAX(max_out_fmt, print_link_prop(NULL, l));
>          }
>          in_indent = max_src_name + max_in_name + max_in_fmt;
>          in_indent += in_indent ? 4 : 0;
>          width = FFMAX(lname + 2, ltype + 4);
>          height = FFMAX3(2, filter->input_count, filter->output_count);
> -        BPAD(' ', in_indent);
> -        BPRINTF("+");
> -        BPAD('-', width);
> -        BPRINTF("+\n");
> +        av_bprint_chars(buf, ' ', in_indent);
> +        av_bprintf(buf, "+");
> +        av_bprint_chars(buf, '-', width);
> +        av_bprintf(buf, "+\n");

I think you can use av_bprintf("%*c+", in_indent, ' ') for the spaces, but
unfortunately it won't work with '-' (maybe there is a trick I'm not aware
of).

[...]

Thank you for this, I think it can also be applied in ffprobe… :)

-- 
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/20120201/a2005418/attachment.asc>


More information about the ffmpeg-devel mailing list