[x265] cli: unify x265 log function

Steve Borho steve at borho.org
Tue Mar 31 17:13:54 CEST 2015


On 03/30, Xinyue Lu wrote:
> # HG changeset patch
> # User Xinyue Lu <i at 7086.in>
> # Date 1427776048 25200
> #      Mon Mar 30 21:27:28 2015 -0700
> # Branch Yuuki
> # Node ID 123d028332d6fe5d3b08e35a8a9be98314e69031
> # Parent  a877426691da454fdbc9095944d93c89b436a026
> cli: unify x265 log function
> 
> diff -r a877426691da -r 123d028332d6 source/common/common.cpp
> --- a/source/common/common.cpp	Mon Mar 30 20:39:17 2015 -0700
> +++ b/source/common/common.cpp	Mon Mar 30 21:27:28 2015 -0700
> @@ -100,10 +100,12 @@
>      return (x265_exp2_lut[i & 63] + 256) << (i >> 6) >> 8;
>  }
> 
> -void x265_log(const x265_param *param, int level, const char *fmt, ...)
> +void general_log(const x265_param *param, const char *caller, int level, const char *fmt, ...)

we've been slowly enforcing a pointer decl style with the asterisk next
to the type. not all of the code has been updated yet, but we try to fix
these when we find the style wrong.  So this should be:

void general_log(const x265_param* param, const char* caller, int level, const char* fmt, ...)

(and similar elsewhere)

>  {
>      if (param && level > param->logLevel)
>          return;
> +    char buffer[4096];
> +    int p = 0;
>      const char *log_level;
>      switch (level)
>      {
> @@ -127,11 +129,14 @@
>          break;
>      }
> 
> -    fprintf(stderr, "x265 [%s]: ", log_level);
> +    if (caller)
> +        p += sprintf(buffer, "%-4s [%s]: ", caller, log_level);
>      va_list arg;
>      va_start(arg, fmt);
> -    vfprintf(stderr, fmt, arg);
> +    vsprintf(buffer + p, fmt, arg);

vsnprintf?

>      va_end(arg);
> +    if (!(param && level > param->logLevel))
> +        fputs(buffer, stderr);
>  }
> 
>  double x265_ssim2dB(double ssim)
> diff -r a877426691da -r 123d028332d6 source/common/common.h
> --- a/source/common/common.h	Mon Mar 30 20:39:17 2015 -0700
> +++ b/source/common/common.h	Mon Mar 30 21:27:28 2015 -0700
> @@ -413,7 +413,8 @@
> 
>  /* outside x265 namespace, but prefixed. defined in common.cpp */
>  int64_t  x265_mdate(void);
> -void     x265_log(const x265_param *param, int level, const char *fmt, ...);
> +#define  x265_log(param, ...) general_log(param, "x265", __VA_ARGS__)
> +void     general_log(const x265_param *param, const char *caller, int level, const char *fmt, ...);
>  int      x265_exp2fix8(double x);
> 
>  double   x265_ssim2dB(double ssim);
> diff -r a877426691da -r 123d028332d6 source/x265.cpp
> --- a/source/x265.cpp	Mon Mar 30 20:39:17 2015 -0700
> +++ b/source/x265.cpp	Mon Mar 30 21:27:28 2015 -0700
> @@ -399,7 +399,7 @@
>          else
>              sprintf(buf + p, " frames %u - %d of %d", this->seek, this->seek + this->framesToBeEncoded - 1, info.frameCount);
> 
> -        fprintf(stderr, "%s  [info]: %s\n", input->getName(), buf);
> +        general_log(param, input->getName(), X265_LOG_INFO, "%s\n", buf);
>      }
> 
>      this->input->startReader();
> @@ -632,25 +632,27 @@
>      cliopt.bitstreamFile.close();
> 
>      if (b_ctrl_c)
> -        fprintf(stderr, "aborted at input frame %d, output frame %d\n",
> +        general_log(param, NULL, X265_LOG_INFO, "aborted at input frame %d, output frame %d\n",
>                  cliopt.seek + inFrameCount, stats.encodedPictureCount);

re-line up cliopt.seek with (, same below

>      if (stats.encodedPictureCount)
>      {
> -        printf("\nencoded %d frames in %.2fs (%.2f fps), %.2f kb/s", stats.encodedPictureCount,
> +        char buffer[4096];
> +        int p = sprintf(buffer, "\nencoded %d frames in %.2fs (%.2f fps), %.2f kb/s", stats.encodedPictureCount,
>                 stats.elapsedEncodeTime, stats.encodedPictureCount / stats.elapsedEncodeTime, stats.bitrate);
> 
>          if (param->bEnablePsnr)
> -            printf(", Global PSNR: %.3f", stats.globalPsnr);
> +            p += sprintf(buffer + p, ", Global PSNR: %.3f", stats.globalPsnr);
> 
>          if (param->bEnableSsim)
> -            printf(", SSIM Mean Y: %.7f (%6.3f dB)", stats.globalSsim, x265_ssim2dB(stats.globalSsim));
> +            p += sprintf(buffer + p, ", SSIM Mean Y: %.7f (%6.3f dB)", stats.globalSsim, x265_ssim2dB(stats.globalSsim));
> 
> -        printf("\n");
> +        sprintf(buffer + p, "\n");
> +        general_log(param, NULL, X265_LOG_INFO, buffer);
>      }
>      else
>      {
> -        printf("\nencoded 0 frames\n");
> +        general_log(param, NULL, X265_LOG_INFO, "\nencoded 0 frames\n");
>      }
> 
>      x265_cleanup(); /* Free library singletons */
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel

-- 
Steve Borho


More information about the x265-devel mailing list