[FFmpeg-devel] [PATCH 1/2] lavu: introduce av_log_format_line.

Michael Niedermayer michaelni at gmx.at
Thu Dec 8 17:42:33 CET 2011


On Thu, Dec 08, 2011 at 02:45:32PM +0100, Nicolas George wrote:
> 
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
> ---
>  doc/APIchanges     |    3 +++
>  libavutil/avutil.h |    2 +-
>  libavutil/log.c    |   37 ++++++++++++++++++++++---------------
>  libavutil/log.h    |   10 ++++++++++
>  4 files changed, 36 insertions(+), 16 deletions(-)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 6f7d46d..5207b42 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -13,6 +13,9 @@ libavutil:   2011-04-18
>  
>  API changes, most recent first:
>  
> +2011-12-08 - xxxxxxx - lavu 51.31.0
> +  Add av_log_format_line.
> +
>  2011-12-03 - xxxxxxx - lavu 51.30.0
>    Add AVERROR_BUG.
>  
> diff --git a/libavutil/avutil.h b/libavutil/avutil.h
> index af43cc5..acc4c22 100644
> --- a/libavutil/avutil.h
> +++ b/libavutil/avutil.h
> @@ -153,7 +153,7 @@
>   */
>  
>  #define LIBAVUTIL_VERSION_MAJOR 51
> -#define LIBAVUTIL_VERSION_MINOR 30
> +#define LIBAVUTIL_VERSION_MINOR 31
>  #define LIBAVUTIL_VERSION_MICRO  0
>  
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
> diff --git a/libavutil/log.c b/libavutil/log.c
> index 3182885..6a9015f 100644
> --- a/libavutil/log.c
> +++ b/libavutil/log.c
> @@ -92,44 +92,51 @@ static void sanitize(uint8_t *line){
>      }
>  }
>  
> -void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
> +void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
> +                        char *line, int line_size, int *print_prefix)
>  {
> -    static int print_prefix = 1;
> -    static int count;
> -    static char prev[1024];
> -    char line[1024];
> -    static int is_atty;
>      AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
> -    if (level > av_log_level)
> -        return;
>      line[0] = 0;
> -#undef fprintf
> -    if (print_prefix && avc) {
> +    if (*print_prefix && avc) {
>          if (avc->parent_log_context_offset) {
>              AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) +
>                                     avc->parent_log_context_offset);
>              if (parent && *parent) {
> -                snprintf(line, sizeof(line), "[%s @ %p] ",
> +                snprintf(line, line_size, "[%s @ %p] ",
>                           (*parent)->item_name(parent), parent);
>              }
>          }
> -        snprintf(line + strlen(line), sizeof(line) - strlen(line), "[%s @ %p] ",
> +        snprintf(line + strlen(line), line_size - strlen(line), "[%s @ %p] ",
>                   avc->item_name(ptr), ptr);
>      }
>  
> -    vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl);
> +    vsnprintf(line + strlen(line), line_size - strlen(line), fmt, vl);
> +
> +    *print_prefix = strlen(line) && line[strlen(line) - 1] == '\n';
> +}
> +
> +void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
> +{
> +    static int print_prefix = 1;
> +    static int count;
> +    static char prev[1024];
> +    char line[1024];
> +    static int is_atty;
>  
> -    print_prefix = strlen(line) && line[strlen(line) - 1] == '\n';
> +    if (level > av_log_level)
> +        return;
> +    av_log_format_line(ptr, level, fmt, vl, line, sizeof(line), &print_prefix);
>  
>  #if HAVE_ISATTY
>      if (!is_atty)
>          is_atty = isatty(2) ? 1 : -1;
>  #endif
>  
> +#undef fprintf


>      if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev)){
>          count++;
>          if (is_atty == 1)
> -            fprintf(stderr, "    Last message repeated %d times\r", count);
> +            fprintf(stderr, "    Last message repeated %d times\n", count);
>          return;

why ?


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Avoid a single point of failure, be that a person or equipment.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20111208/823fdc49/attachment.asc>


More information about the ffmpeg-devel mailing list