shithub: openh264

Download patch

ref: 6e5f31214ab683c9f9e2c853b9e02ec050fc7700
parent: ce8065fe683e5f89204db4ea548461ed75cd4cbd
author: Martin Storsjö <[email protected]>
date: Tue Jun 10 10:47:25 EDT 2014

Add a method for overriding the logging function in welsCodecTrace

--- a/codec/common/inc/logging.h
+++ b/codec/common/inc/logging.h
@@ -37,6 +37,6 @@
 
 
 // Internal details.
-int32_t welsStderrTrace (const char* string);
+void welsStderrTrace (void* ctx, int level, const char* string);
 
 #endif
--- a/codec/common/inc/welsCodecTrace.h
+++ b/codec/common/inc/welsCodecTrace.h
@@ -37,7 +37,7 @@
 #include "typedefs.h"
 #include "utils.h"
 
-typedef int32_t (*CM_WELS_TRACE) (const char* string);
+typedef void (*CM_WELS_TRACE) (void* ctx, int level, const char* string);
 
 class welsCodecTrace {
  public:
@@ -45,6 +45,8 @@
   ~welsCodecTrace();
 
   void SetTraceLevel (const int32_t kiLevel);
+  void SetTraceCallback (CM_WELS_TRACE func);
+  void SetTraceCallbackContext (void* pCtx);
 
  private:
   static void StaticCodecTrace (void* pCtx, const int32_t kiLevel, const char* kpStrFormat, va_list vl);
@@ -52,6 +54,7 @@
 
   int32_t	m_iTraceLevel;
   CM_WELS_TRACE m_fpTrace;
+  void*         m_pTraceCtx;
  public:
 
   SLogContext m_sLogCtx;
--- a/codec/common/src/logging.cpp
+++ b/codec/common/src/logging.cpp
@@ -35,7 +35,6 @@
 #include <stdio.h>
 #include "typedefs.h"
 
-int32_t welsStderrTrace (const char* string) {
+void welsStderrTrace (void* ctx, int level, const char* string) {
   fprintf (stderr, "%s", string);
-  return 0;
 }
--- a/codec/common/src/welsCodecTrace.cpp
+++ b/codec/common/src/welsCodecTrace.cpp
@@ -51,6 +51,7 @@
 
   m_iTraceLevel = WELS_LOG_DEFAULT;
   m_fpTrace = welsStderrTrace;
+  m_pTraceCtx = NULL;
 
   m_sLogCtx.pLogCtx = this;
   m_sLogCtx.pfLog = StaticCodecTrace;
@@ -75,7 +76,7 @@
   char pBuf[MAX_LOG_SIZE] = {0};
   WelsVsnprintf (pBuf, MAX_LOG_SIZE, Str_Format, vl);	// confirmed_safe_unsafe_usage
 
-  m_fpTrace (pBuf);
+  m_fpTrace (m_pTraceCtx, iLevel, pBuf);
 }
 
 void welsCodecTrace::SetTraceLevel (const int32_t iLevel) {
@@ -83,4 +84,11 @@
     m_iTraceLevel	= iLevel;
 }
 
+void welsCodecTrace::SetTraceCallback (CM_WELS_TRACE func) {
+  m_fpTrace = func;
+}
+
+void welsCodecTrace::SetTraceCallbackContext (void* ctx) {
+  m_pTraceCtx = ctx;
+}