[x264-devel] [PATCH 08/32] common: Move log helper functions to a separate file

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


The main x264_log() function needs to remain in common.c because it is
tightly coupled with x264_t type.
---
 Makefile        |  1 +
 common/common.c | 27 ---------------------------
 common/common.h |  1 +
 common/log.c    | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 common/log.h    | 40 ++++++++++++++++++++++++++++++++++++++++
 5 files changed, 95 insertions(+), 27 deletions(-)
 create mode 100644 common/log.c
 create mode 100644 common/log.h

diff --git a/Makefile b/Makefile
index d0b1633..2d0b1a4 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 f4b4d42..7d02a1b 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 x264_log_default( void *, int, const char *, va_list );
-
 /****************************************************************************
  * x264_param_default:
  ****************************************************************************/
@@ -1086,31 +1084,6 @@ void x264_log( x264_t *h, int i_level, const char *psz_fmt, ... )
     }
 }
 
-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 );
-    x264_vfprintf( stderr, psz_fmt, arg );
-}
-
 /****************************************************************************
  * x264_picture_init:
  ****************************************************************************/
diff --git a/common/common.h b/common/common.h
index 9183a93..b0a68d8 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