[x264-devel] [PATCH 09/32] log: Add an internal log function and use it where needed

Vittorio Giovara vittorio.giovara at gmail.com
Fri Jan 20 15:20:34 CET 2017


This will help in decoupling log from common.
---
 common/common.c   | 22 +++++++++++-----------
 common/cpu.c      |  2 +-
 common/log.c      |  8 ++++++++
 common/log.h      |  2 ++
 encoder/encoder.c |  2 +-
 5 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/common/common.c b/common/common.c
index 7d02a1b..13f6a09 100644
--- a/common/common.c
+++ b/common/common.c
@@ -293,7 +293,7 @@ static int x264_param_apply_preset( x264_param_t *param, const char *preset )
     }
     else
     {
-        x264_log( NULL, X264_LOG_ERROR, "invalid preset '%s'\n", preset );
+        x264_log_internal( X264_LOG_ERROR, "invalid preset '%s'\n", preset );
         return -1;
     }
     return 0;
@@ -390,14 +390,14 @@ static int x264_param_apply_tune( x264_param_t *param, const char *tune )
         }
         else
         {
-            x264_log( NULL, X264_LOG_ERROR, "invalid tune '%s'\n", s );
+            x264_log_internal( X264_LOG_ERROR, "invalid tune '%s'\n", s );
             x264_free( tmp );
             return -1;
         }
         if( 0 )
         {
     psy_failure:
-            x264_log( NULL, X264_LOG_WARNING, "only 1 psy tuning can be used: ignoring tune %s\n", s );
+            x264_log_internal( X264_LOG_WARNING, "only 1 psy tuning can be used: ignoring tune %s\n", s );
         }
         s = strtok( NULL, ",./-+" );
     }
@@ -456,28 +456,28 @@ int x264_param_apply_profile( x264_param_t *param, const char *profile )
     int p = profile_string_to_int( profile );
     if( p < 0 )
     {
-        x264_log( NULL, X264_LOG_ERROR, "invalid profile: %s\n", profile );
+        x264_log_internal( X264_LOG_ERROR, "invalid profile: %s\n", profile );
         return -1;
     }
     if( p < PROFILE_HIGH444_PREDICTIVE && ((param->rc.i_rc_method == X264_RC_CQP && param->rc.i_qp_constant <= 0) ||
         (param->rc.i_rc_method == X264_RC_CRF && (int)(param->rc.f_rf_constant + QP_BD_OFFSET) <= 0)) )
     {
-        x264_log( NULL, X264_LOG_ERROR, "%s profile doesn't support lossless\n", profile );
+        x264_log_internal( X264_LOG_ERROR, "%s profile doesn't support lossless\n", profile );
         return -1;
     }
     if( p < PROFILE_HIGH444_PREDICTIVE && (param->i_csp & X264_CSP_MASK) >= X264_CSP_I444 )
     {
-        x264_log( NULL, X264_LOG_ERROR, "%s profile doesn't support 4:4:4\n", profile );
+        x264_log_internal( X264_LOG_ERROR, "%s profile doesn't support 4:4:4\n", profile );
         return -1;
     }
     if( p < PROFILE_HIGH422 && (param->i_csp & X264_CSP_MASK) >= X264_CSP_I422 )
     {
-        x264_log( NULL, X264_LOG_ERROR, "%s profile doesn't support 4:2:2\n", profile );
+        x264_log_internal( X264_LOG_ERROR, "%s profile doesn't support 4:2:2\n", profile );
         return -1;
     }
     if( p < PROFILE_HIGH10 && BIT_DEPTH > 8 )
     {
-        x264_log( NULL, X264_LOG_ERROR, "%s profile doesn't support a bit depth of %d\n", profile, BIT_DEPTH );
+        x264_log_internal( X264_LOG_ERROR, "%s profile doesn't support a bit depth of %d\n", profile, BIT_DEPTH );
         return -1;
     }
 
@@ -491,12 +491,12 @@ int x264_param_apply_profile( x264_param_t *param, const char *profile )
         param->analyse.i_weighted_pred = X264_WEIGHTP_NONE;
         if( param->b_interlaced )
         {
-            x264_log( NULL, X264_LOG_ERROR, "baseline profile doesn't support interlacing\n" );
+            x264_log_internal( X264_LOG_ERROR, "baseline profile doesn't support interlacing\n" );
             return -1;
         }
         if( param->b_fake_interlaced )
         {
-            x264_log( NULL, X264_LOG_ERROR, "baseline profile doesn't support fake interlacing\n" );
+            x264_log_internal( X264_LOG_ERROR, "baseline profile doesn't support fake interlacing\n" );
             return -1;
         }
     }
@@ -1195,7 +1195,7 @@ void *x264_malloc( int i_size )
     }
 #endif
     if( !align_buf )
-        x264_log( NULL, X264_LOG_ERROR, "malloc of size %d failed\n", i_size );
+        x264_log_internal( X264_LOG_ERROR, "malloc of size %d failed\n", i_size );
     return align_buf;
 }
 
diff --git a/common/cpu.c b/common/cpu.c
index 135bb5e..653b761 100644
--- a/common/cpu.c
+++ b/common/cpu.c
@@ -304,7 +304,7 @@ uint32_t x264_cpu_detect( void )
         else if( cache == 64 )
             cpu |= X264_CPU_CACHELINE_64;
         else
-            x264_log( NULL, X264_LOG_WARNING, "unable to determine cacheline size\n" );
+            x264_log_internal( X264_LOG_WARNING, "unable to determine cacheline size\n" );
     }
 
 #if STACK_ALIGNMENT < 16
diff --git a/common/log.c b/common/log.c
index f736e69..15d8404 100644
--- a/common/log.c
+++ b/common/log.c
@@ -27,6 +27,14 @@
 #include "log.h"
 #include "x264.h"
 
+void x264_log_internal( int i_level, const char *psz_fmt, ... )
+{
+    va_list arg;
+    va_start( arg, psz_fmt );
+    x264_log_default( NULL, i_level, psz_fmt, arg );
+    va_end( arg );
+}
+
 void x264_log_default( void *p_unused, int i_level, const char *psz_fmt, va_list arg )
 {
     char *psz_prefix;
diff --git a/common/log.h b/common/log.h
index 0dd75aa..a4a56c5 100644
--- a/common/log.h
+++ b/common/log.h
@@ -35,6 +35,8 @@
 #include <assert.h>
 #include <limits.h>
 
+void x264_log_internal( int i_level, const char *psz_fmt, ... );
+
 void x264_log_default( void *p_unused, int i_level, const char *psz_fmt, va_list arg );
 
 #endif
diff --git a/encoder/encoder.c b/encoder/encoder.c
index df74328..59f8f7c 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -422,7 +422,7 @@ static int x264_validate_parameters( x264_t *h, int b_open )
 {
     if( !h->param.pf_log )
     {
-        x264_log( NULL, X264_LOG_ERROR, "pf_log not set! did you forget to call x264_param_default?\n" );
+        x264_log_internal( X264_LOG_ERROR, "pf_log not set! did you forget to call x264_param_default?\n" );
         return -1;
     }
 
-- 
2.10.0



More information about the x264-devel mailing list