[x264-devel] [PATCH 04/29] common: Move log helper functions to a separate file
Vittorio Giovara
vittorio.giovara at gmail.com
Fri Feb 10 22:18:39 CET 2017
The main x264_log() function needs to remain in common.c because it is
tightly coupled with the x264_t type.
---
Makefile | 1 +
common/common.c | 31 ++-----------------------------
common/common.h | 1 +
common/log.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
common/log.h | 40 ++++++++++++++++++++++++++++++++++++++++
5 files changed, 97 insertions(+), 29 deletions(-)
create mode 100644 common/log.c
create mode 100644 common/log.h
diff --git a/Makefile b/Makefile
index d97c9e6..0718c2c 100644
--- a/Makefile
+++ b/Makefile
@@ -18,6 +18,7 @@ SRCS = common/mc.c common/predict.c common/pixel.c common/macroblock.c \
common/common.c common/osdep.c common/rectangle.c \
common/set.c common/quant.c common/deblock.c common/vlc.c \
common/mvpred.c common/bitstream.c \
+ common/log.c \
encoder/analyse.c encoder/me.c encoder/ratecontrol.c \
encoder/set.c encoder/macroblock.c encoder/cabac.c \
encoder/cavlc.c encoder/encoder.c encoder/lookahead.c
diff --git a/common/common.c b/common/common.c
index a1404ae..154af36 100644
--- a/common/common.c
+++ b/common/common.c
@@ -39,8 +39,6 @@ const int x264_bit_depth = BIT_DEPTH;
const int x264_chroma_format = X264_CHROMA_FORMAT;
-static void log_default( void *, int, const char *, va_list );
-
/****************************************************************************
* x264_param_default:
****************************************************************************/
@@ -123,7 +121,7 @@ void x264_param_default( x264_param_t *param )
param->rc.b_mb_tree = 1;
/* Log */
- param->pf_log = log_default;
+ param->pf_log = x264_log_default;
param->p_log_private = NULL;
param->i_log_level = X264_LOG_INFO;
@@ -1079,38 +1077,13 @@ void x264_log( x264_t *h, int i_level, const char *psz_fmt, ... )
va_list arg;
va_start( arg, psz_fmt );
if( !h )
- log_default( NULL, i_level, psz_fmt, arg );
+ x264_log_default( NULL, i_level, psz_fmt, arg );
else
h->param.pf_log( h->param.p_log_private, i_level, psz_fmt, arg );
va_end( arg );
}
}
-static void 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 );
- x264_vfprintf( stderr, psz_fmt, arg );
-}
-
/****************************************************************************
* x264_picture_init:
****************************************************************************/
diff --git a/common/common.h b/common/common.h
index 8cc1dc1..35a982c 100644
--- a/common/common.h
+++ b/common/common.h
@@ -115,6 +115,7 @@ do {\
* Includes
****************************************************************************/
#include "osdep.h"
+#include "log.h"
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
diff --git a/common/log.c b/common/log.c
new file mode 100644
index 0000000..f736e69
--- /dev/null
+++ b/common/log.c
@@ -0,0 +1,53 @@
+/*****************************************************************************
+ * log.c: log helper functions
+ *****************************************************************************
+ * Copyright (C) 2003-2016 x264 project
+ *
+ * Authors: Loren Merritt <lorenm at u.washington.edu>
+ * Laurent Aimar <fenrir at via.ecp.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing at x264.com.
+ *****************************************************************************/
+
+#include "log.h"
+#include "x264.h"
+
+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 );
+ x264_vfprintf( stderr, psz_fmt, arg );
+}
diff --git a/common/log.h b/common/log.h
new file mode 100644
index 0000000..0dd75aa
--- /dev/null
+++ b/common/log.h
@@ -0,0 +1,40 @@
+/*****************************************************************************
+ * log.h: log helper functions
+ *****************************************************************************
+ * Copyright (C) 2003-2016 x264 project
+ *
+ * Authors: Loren Merritt <lorenm at u.washington.edu>
+ * Laurent Aimar <fenrir at via.ecp.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing at x264.com.
+ *****************************************************************************/
+
+#ifndef COMMON_LOG_H
+#define COMMON_LOG_H
+
+#include "osdep.h"
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <limits.h>
+
+void x264_log_default( void *p_unused, int i_level, const char *psz_fmt, va_list arg );
+
+#endif
--
2.10.0
More information about the x264-devel
mailing list