[FFmpeg-devel] [PATCH 2/3] ffprobe: replace fmt callback with str callback.

Stefano Sabatini stefano.sabatini-lala at poste.it
Tue Sep 6 15:31:36 CEST 2011


On date Saturday 2011-09-03 20:12:55 +0200, Clément Bœsch encoded:
> ---
>  ffprobe.c |   23 ++++++++++++-----------
>  1 files changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/ffprobe.c b/ffprobe.c
> index 2748224..ce2b505 100644
> --- a/ffprobe.c
> +++ b/ffprobe.c
> @@ -23,6 +23,7 @@
>  
>  #include "libavformat/avformat.h"
>  #include "libavcodec/avcodec.h"
> +#include "libavutil/avstring.h"
>  #include "libavutil/opt.h"
>  #include "libavutil/pixdesc.h"
>  #include "libavutil/dict.h"
> @@ -132,8 +133,8 @@ struct writer {
>      const char *header, *footer;
>      void (*print_header)(const char *);
>      void (*print_footer)(const char *);
> -    void (*print_fmt_f)(const char *, const char *, ...);
>      void (*print_int_f)(const char *, int);
> +    void (*print_str_f)(const char *, const char *);
>      void (*show_tags)(struct writer *w, AVDictionary *dict);
>  };
>  
> @@ -145,13 +146,9 @@ static void default_print_header(const char *section)
>      printf("[%s]\n", section);
>  }
>  
> -static void default_print_fmt(const char *key, const char *fmt, ...)
> +static void default_print_str(const char *key, const char *value)
>  {
> -    va_list ap;
> -    va_start(ap, fmt);
> -    printf("%s=", key);
> -    vprintf(fmt, ap);
> -    va_end(ap);
> +    printf("%s=%s", key, value);
>  }
>  
>  static void default_print_int(const char *key, int value)
> @@ -167,11 +164,15 @@ static void default_print_footer(const char *section)
>  
>  /* Print helpers */
>  
> -#define print_fmt0(k, f, a...) w->print_fmt_f(k, f, ##a)
> -#define print_fmt( k, f, a...) do {   \
> +#define print_fmt0(k, f, a...) do {   \
> +    char *strv = av_asprintf(f, ##a); \

> +    w->print_str_f(k, strv);          \
> +    av_free(strv);                    \
> +} while (0)
> +#define print_fmt(k, f, a...) do {    \
>      if (w->item_sep)                  \
>          printf("%s", w->item_sep);    \
> -    w->print_fmt_f(k, f, ##a);        \
> +    print_fmt0(k, f, ##a);            \
>  } while (0)

Is print_fmt/print_fmt0 still required? (I can't see any use in the
code right now.)

Also I noticed that ## is a GNU cpp extension, so it may fail with
other pre-processors.

Also I'm afraid that all this malloc/free may slow down the overall
performance.

>  #define print_int0(k, v) w->print_int_f(k, v)
> @@ -375,8 +376,8 @@ static int open_input_file(AVFormatContext **fmt_ctx_ptr, const char *filename)
>  #define WRITER_FUNC(func)                  \
>      .print_header = func ## _print_header, \
>      .print_footer = func ## _print_footer, \
> -    .print_fmt_f  = func ## _print_fmt,    \
>      .print_int_f  = func ## _print_int,    \
> +    .print_str_f  = func ## _print_str,    \
>      .show_tags    = func ## _show_tags
>  
>  static struct writer writers[] = {{
> -- 
> 1.7.6.1
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

-- 
FFmpeg = Friendly Fancy Mere Ponderous Evangelical Guide


More information about the ffmpeg-devel mailing list