From: Laurent Aimar Date: Tue, 17 Aug 2004 19:56:36 +0000 (+0000) Subject: * all: introduced a x264_log function. It's not yet used everywhere X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a01315f4e71b38b63ca08f9453b3409bf4f044b8;p=libx264 * all: introduced a x264_log function. It's not yet used everywhere but we should start using it :) git-svn-id: svn://svn.videolan.org/x264/trunk@32 df754926-b1dd-0310-bc7b-ec298dee348c --- diff --git a/core/common.c b/core/common.c index 61a78306..b69db9b9 100644 --- a/core/common.c +++ b/core/common.c @@ -24,6 +24,7 @@ #include #include #include +#include #ifdef HAVE_MALLOC_H #include @@ -32,6 +33,8 @@ #include "common.h" #include "cpu.h" +static void x264_log_default( void *, int, const char *, va_list ); + /**************************************************************************** * x264_param_default: ****************************************************************************/ @@ -42,14 +45,6 @@ void x264_param_default( x264_param_t *param ) /* CPU autodetect */ param->cpu = x264_cpu_detect(); - fprintf( stderr, "x264: cpu capabilities: %s%s%s%s%s%s\n", - param->cpu&X264_CPU_MMX ? "MMX " : "", - param->cpu&X264_CPU_MMXEXT ? "MMXEXT " : "", - param->cpu&X264_CPU_SSE ? "SSE " : "", - param->cpu&X264_CPU_SSE2 ? "SSE2 " : "", - param->cpu&X264_CPU_3DNOW ? "3DNow! " : "", - param->cpu&X264_CPU_ALTIVEC ? "Altivec " : "" ); - /* Video properties */ param->i_csp = X264_CSP_I420; @@ -85,10 +80,55 @@ void x264_param_default( x264_param_t *param ) param->f_ip_factor = 2.0; param->f_pb_factor = 2.0; + /* Log */ + param->pf_log = x264_log_default; + param->p_log_private = NULL; + param->i_log_level = X264_LOG_INFO; + + /* */ param->analyse.intra = X264_ANALYSE_I4x4; param->analyse.inter = X264_ANALYSE_I4x4 | X264_ANALYSE_PSUB16x16; } +/**************************************************************************** + * x264_log: + ****************************************************************************/ +void x264_log( x264_t *h, int i_level, const char *psz_fmt, ... ) +{ + if( i_level <= h->param.i_log_level ) + { + va_list arg; + va_start( arg, psz_fmt ); + h->param.pf_log( h->param.p_log_private, i_level, psz_fmt, arg ); + va_end( arg ); + } +} + +static void x264_log_default( void *p_unused, int i_level, const char *psz_fmt, va_list arg ) +{ + char *psz_prefix; + switch( i_level ) + { + case X264_LOG_ERROR: + psz_prefix = "error"; + break; + case X264_LOG_WARNING: + psz_prefix = "warning"; + break; + case X264_LOG_INFO: + psz_prefix = "info"; + break; + case X264_LOG_DEBUG: + psz_prefix = "debug"; + break; + default: + psz_prefix = "unknown"; + break; + } + fprintf( stderr, "x264 [%s]: ", psz_prefix ); + vfprintf( stderr, psz_fmt, arg ); +} + /**************************************************************************** * x264_picture_alloc: ****************************************************************************/ diff --git a/core/common.h b/core/common.h index 65ae4b45..ec9ab227 100644 --- a/core/common.h +++ b/core/common.h @@ -29,6 +29,7 @@ #else #include #endif +#include #include "../x264.h" #include "bs.h" @@ -41,10 +42,16 @@ #include "cabac.h" #include "csp.h" +/**************************************************************************** + * Macros + ****************************************************************************/ #define X264_MIN(a,b) ( (a)<(b) ? (a) : (b) ) #define X264_MAX(a,b) ( (a)>(b) ? (a) : (b) ) #define X264_ABS(a) ( (a)< 0 ? -(a) : (a) ) +/**************************************************************************** + * Generals functions + ****************************************************************************/ /* x264_malloc : will do or emulate a memalign * XXX you HAVE TO use x264_free for buffer allocated * with x264_malloc @@ -56,6 +63,9 @@ void x264_free( void * ); /* mdate: return the current date in microsecond */ int64_t x264_mdate( void ); +/* log */ +void x264_log( x264_t *h, int i_level, const char *psz_fmt, ... ); + static inline int x264_clip3( int v, int i_min, int i_max ) { if( v < i_min ) @@ -72,6 +82,10 @@ static inline int x264_clip3( int v, int i_min, int i_max ) } } + +/**************************************************************************** + * + ****************************************************************************/ enum slice_type_e { SLICE_TYPE_P = 0, diff --git a/core/cpu.c b/core/cpu.c index 5cce5db0..a39c4271 100644 --- a/core/cpu.c +++ b/core/cpu.c @@ -28,6 +28,7 @@ #endif #include #include +#include #include "../x264.h" #include "cpu.h" diff --git a/core/dct.c b/core/dct.c index da018287..c8a0c8fa 100644 --- a/core/dct.c +++ b/core/dct.c @@ -27,6 +27,7 @@ #include #endif #include +#include #include "x264.h" diff --git a/core/i386/dct-c.c b/core/i386/dct-c.c index 368603e0..adba9480 100644 --- a/core/i386/dct-c.c +++ b/core/i386/dct-c.c @@ -27,6 +27,7 @@ #include #endif #include +#include #include "x264.h" diff --git a/core/i386/mc-c.c b/core/i386/mc-c.c index 08207c17..e2e9251b 100644 --- a/core/i386/mc-c.c +++ b/core/i386/mc-c.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "x264.h" /* DECLARE_ALIGNED */ #include "../mc.h" diff --git a/core/i386/predict.c b/core/i386/predict.c index ef1a027d..febb4a2e 100644 --- a/core/i386/predict.c +++ b/core/i386/predict.c @@ -30,6 +30,7 @@ #include #endif #include +#include #include "x264.h" /* for keyword inline */ #include "../predict.h" diff --git a/core/mc.c b/core/mc.c index ae9c6685..5eb94c4f 100644 --- a/core/mc.c +++ b/core/mc.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "../x264.h" diff --git a/core/pixel.c b/core/pixel.c index 056491ca..d0001b1b 100644 --- a/core/pixel.c +++ b/core/pixel.c @@ -28,6 +28,7 @@ #endif #include #include +#include #include "../x264.h" #include "pixel.h" diff --git a/core/predict.c b/core/predict.c index 2df27394..13c98603 100644 --- a/core/predict.c +++ b/core/predict.c @@ -30,6 +30,7 @@ #include #endif #include +#include #include "x264.h" #include "predict.h" diff --git a/encoder/encoder.c b/encoder/encoder.c index 9b7d4dfa..dc0250ab 100644 --- a/encoder/encoder.c +++ b/encoder/encoder.c @@ -437,6 +437,15 @@ x264_t *x264_encoder_open ( x264_param_t *param ) h->stat.i_mb_count[SLICE_TYPE_P][i] = 0; h->stat.i_mb_count[SLICE_TYPE_B][i] = 0; } + + x264_log( h, X264_LOG_INFO, "using cpu capabilities %s%s%s%s%s%s\n", + param->cpu&X264_CPU_MMX ? "MMX " : "", + param->cpu&X264_CPU_MMXEXT ? "MMXEXT " : "", + param->cpu&X264_CPU_SSE ? "SSE " : "", + param->cpu&X264_CPU_SSE2 ? "SSE2 " : "", + param->cpu&X264_CPU_3DNOW ? "3DNow! " : "", + param->cpu&X264_CPU_ALTIVEC ? "Altivec " : "" ); + return h; } diff --git a/encoder/set.c b/encoder/set.c index 64f32462..94b1343f 100644 --- a/encoder/set.c +++ b/encoder/set.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "../x264.h" #include "../core/bs.h" diff --git a/x264.h b/x264.h index 2cfbbd65..16a969f7 100644 --- a/x264.h +++ b/x264.h @@ -71,6 +71,14 @@ typedef struct x264_t x264_t; #define X264_TYPE_P 0x0003 #define X264_TYPE_B 0x0004 +/* Log level + */ +#define X264_LOG_NONE (-1) +#define X264_LOG_ERROR 0 +#define X264_LOG_WARNING 1 +#define X264_LOG_INFO 2 +#define X264_LOG_DEBUG 3 + typedef struct { /* CPU flags */ @@ -117,6 +125,11 @@ typedef struct float f_ip_factor; float f_pb_factor; + /* Log */ + void (*pf_log)( void *, int i_level, const char *psz, va_list ); + void *p_log_private; + int i_log_level; + /* Encoder analyser parameters */ struct {