[x265] cli: unify x265 log function

Steve Borho steve at borho.org
Thu Apr 2 20:04:26 CEST 2015


On 04/02, Xinyue Lu wrote:
> # HG changeset patch
> # User Xinyue Lu <i at 7086.in>
> # Date 1427969739 25200
> #      Thu Apr 02 03:15:39 2015 -0700
> # Branch Yuuki
> # Node ID b0e4b7b87ea4c8178473dec1c8a11e6abef66ab5
> # Parent  8cdf6fb6a335071dc0fc29510dbb8c0c7d301ee8
> cli: unify x265 log function

your patches are still getting line mangled somehow:

applying patch from stdin
abort: bad hunk #1 @@ -388,7 +388,7 @@
 (7 7 8 7)

fixed up manually and queued for testing

> diff -r 8cdf6fb6a335 -r b0e4b7b87ea4 source/common/common.cpp
> --- a/source/common/common.cpp	Thu Apr 02 02:03:29 2015 -0700
> +++ b/source/common/common.cpp	Thu Apr 02 03:15:39 2015 -0700
> @@ -100,11 +100,14 @@
>      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, ...)
>  {
>      if (param && level > param->logLevel)
>          return;
> -    const char *log_level;
> +    const int bufferSize = 4096;
> +    char buffer[bufferSize];
> +    int p = 0;
> +    const char* log_level;
>      switch (level)
>      {
>      case X265_LOG_ERROR:
> @@ -127,11 +130,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);
> +    vsnprintf(buffer + p, bufferSize - p, fmt, arg);
>      va_end(arg);
> +    if (!(param && level > param->logLevel))
> +        fputs(buffer, stderr);
>  }
> 
>  double x265_ssim2dB(double ssim)
> diff -r 8cdf6fb6a335 -r b0e4b7b87ea4 source/common/common.h
> --- a/source/common/common.h	Thu Apr 02 02:03:29 2015 -0700
> +++ b/source/common/common.h	Thu Apr 02 03:15:39 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 8cdf6fb6a335 -r b0e4b7b87ea4 source/x265.cpp
> --- a/source/x265.cpp	Thu Apr 02 02:03:29 2015 -0700
> +++ b/source/x265.cpp	Thu Apr 02 03:15:39 2015 -0700
> @@ -388,7 +388,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();
> @@ -618,25 +618,27 @@
>      cliopt.bitstreamFile.close();
> 
>      if (b_ctrl_c)
> -        fprintf(stderr, "aborted at input frame %d, output frame %d\n",
> -                cliopt.seek + inFrameCount, stats.encodedPictureCount);
> +        general_log(param, NULL, X265_LOG_INFO, "aborted at input frame %d, output frame %d\n",
> +                    cliopt.seek + inFrameCount, stats.encodedPictureCount);
> 
>      if (stats.encodedPictureCount)
>      {
> -        printf("\nencoded %d frames in %.2fs (%.2f fps), %.2f kb/s", stats.encodedPictureCount,
> -               stats.elapsedEncodeTime, stats.encodedPictureCount / stats.elapsedEncodeTime, stats.bitrate);
> +        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