Add a method for overriding the logging function in welsCodecTrace

This commit is contained in:
Martin Storsjö 2014-06-10 14:47:25 +03:00
parent ce8065fe68
commit 6e5f31214a
4 changed files with 15 additions and 5 deletions

View File

@ -37,6 +37,6 @@
// Internal details.
int32_t welsStderrTrace (const char* string);
void welsStderrTrace (void* ctx, int level, const char* string);
#endif

View File

@ -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 @@ class welsCodecTrace {
~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 @@ class welsCodecTrace {
int32_t m_iTraceLevel;
CM_WELS_TRACE m_fpTrace;
void* m_pTraceCtx;
public:
SLogContext m_sLogCtx;

View File

@ -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;
}

View File

@ -51,6 +51,7 @@ welsCodecTrace::welsCodecTrace() {
m_iTraceLevel = WELS_LOG_DEFAULT;
m_fpTrace = welsStderrTrace;
m_pTraceCtx = NULL;
m_sLogCtx.pLogCtx = this;
m_sLogCtx.pfLog = StaticCodecTrace;
@ -75,7 +76,7 @@ void welsCodecTrace::CodecTrace (const int32_t iLevel, const char* Str_Format, v
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 @@ void welsCodecTrace::SetTraceLevel (const int32_t iLevel) {
m_iTraceLevel = iLevel;
}
void welsCodecTrace::SetTraceCallback (CM_WELS_TRACE func) {
m_fpTrace = func;
}
void welsCodecTrace::SetTraceCallbackContext (void* ctx) {
m_pTraceCtx = ctx;
}