shithub: openh264

Download patch

ref: 4e428ab020298405e0587389e2bb71b6cad16c3a
parent: c8b81b423979651e125609947af70bb1b227b1a9
author: Martin Storsjö <[email protected]>
date: Tue Jun 10 08:29:14 EDT 2014

Add a log context to the encoder and decoder contexts

This will allow setting non-global logging callbacks, that
are different for each encoder or decoder instance.

--- a/codec/common/inc/utils.h
+++ b/codec/common/inc/utils.h
@@ -64,6 +64,10 @@
 // wels log output
 typedef void (*PWelsLogCallbackFunc) (void* pCtx, const int32_t iLevel, const char* kpFmt, va_list argv);
 
+typedef struct TagLogContext {
+  PWelsLogCallbackFunc pfLog;
+  void* pLogCtx;
+} SLogContext;
 
 
 #ifdef __GNUC__
--- a/codec/common/src/utils.cpp
+++ b/codec/common/src/utils.cpp
@@ -66,9 +66,15 @@
 }
 
 void WelsLog (void* pCtx, int32_t iLevel, const char* kpFmt, ...) {
+  SLogContext* logCtx = (SLogContext*) pCtx;
+  PWelsLogCallbackFunc pfLog = wlog;
+  if (logCtx != NULL && logCtx->pfLog != NULL) {
+    pfLog = logCtx->pfLog;
+    pCtx = logCtx->pLogCtx;
+  }
   va_list vl;
   va_start (vl, kpFmt);
-  wlog (pCtx, iLevel, kpFmt, vl);
+  pfLog (pCtx, iLevel, kpFmt, vl);
   va_end (vl);
 }
 
--- a/codec/decoder/core/inc/decoder_context.h
+++ b/codec/decoder/core/inc/decoder_context.h
@@ -164,6 +164,7 @@
  */
 
 typedef struct TagWelsDecoderContext {
+  SLogContext sLogCtx;
   // Input
   void*				pArgDec;			// structured arguments for decoder, reserved here for extension in the future
 
--- a/codec/encoder/core/inc/encoder_context.h
+++ b/codec/encoder/core/inc/encoder_context.h
@@ -53,6 +53,7 @@
 #include "wels_preprocess.h"
 #include "wels_func_ptr_def.h"
 #include "crt_util_safe_x.h"
+#include "utils.h"
 
 #include "mt_defs.h"	// for multiple threadin,
 #include "WelsThreadLib.h"
@@ -110,6 +111,7 @@
 } SStrideTables;
 
 typedef struct TagWelsEncCtx {
+  SLogContext sLogCtx;
   // Input
   SWelsSvcCodingParam*		pSvcParam;	// SVC parameter, WelsSVCParamConfig in svc_param_settings.h
   SWelsSliceBs*		 	pSliceBs;		// bitstream buffering for various slices, [uiSliceIdx]