History

Merge pull request #945 from mstorsjo/log-callback

Don't use a global trace level, allow user-specified trace callbacks

ruil2 committed 12 years ago

Commit 84c1f3a2 parents 7574e5c 090229f27 files · +216 −316Browse files

Unified · Split

27 files
  1. codec/api/svc/codec_app_def.h +6 −1
  2. codec/build/android/dec/jni/welsdecdemo.mk +0 −1
  3. codec/build/android/enc/jni/welsencdemo.mk +0 −1
  4. codec/build/iOS/common/common.xcodeproj/project.pbxproj +0 −6
  5. codec/build/win32/dec/WelsDecCore.vcproj +0 −4
  6. codec/build/win32/dec/decConsole.vcproj +0 −4
  7. codec/build/win32/enc/WelsEncCore.vcproj +0 −4
  8. codec/build/win32/enc/encConsole.vcproj +0 −4
  9. codec/common/inc/logging.h +0 −54
  10. codec/common/inc/utils.h +5 −23
  11. codec/common/inc/welsCodecTrace.h +12 −9
  12. codec/common/src/logging.cpp +0 −49
  13. codec/common/src/utils.cpp +2 −18
  14. codec/common/src/welsCodecTrace.cpp +25 −42
  15. codec/common/targets.mk +0 −1
  16. codec/console/dec/src/h264dec.cpp +6 −3
  17. codec/console/enc/src/welsenc.cpp +4 −2
  18. codec/decoder/core/inc/decoder.h +1 −1
  19. codec/decoder/core/inc/decoder_context.h +1 −0
  20. codec/decoder/core/src/decoder.cpp +4 −3
  21. codec/decoder/plus/src/welsDecoderExt.cpp +36 −12
  22. codec/encoder/core/inc/encoder_context.h +2 −0
  23. codec/encoder/core/inc/extern.h +3 −3
  24. codec/encoder/core/inc/slice_multi_threading.h +2 −2
  25. codec/encoder/core/src/encoder_ext.cpp +36 −28
  26. codec/encoder/core/src/slice_multi_threading.cpp +3 −3
  27. codec/encoder/plus/src/welsEncoderExt.cpp +68 −38
codec/api/svc/codec_app_def.h+6−1
@@ -93,7 +93,9 @@ typedef enum { · 92 unmodified lines
9393
9494 ENCODER_OPTION_CURRENT_PATH,
9595 ENCODER_OPTION_DUMP_FILE,
96− ENCODER_OPTION_TRACE_LEVEL
96+ ENCODER_OPTION_TRACE_LEVEL,
97+ ENCODER_OPTION_TRACE_CALLBACK, // a void (*)(void* context, int level, const char* message) function which receives log messages
98+ ENCODER_OPTION_TRACE_CALLBACK_CONTEXT,
9799 } ENCODER_OPTION;
98100
99101 /* Option types introduced in decoder application */
@@ -107,6 +109,9 @@ typedef enum { · 7 unmodified lines
107109 DECODER_OPTION_LTR_MARKING_FLAG, // feedback wether current frame mark a LTR
108110 DECODER_OPTION_LTR_MARKED_FRAME_NUM, // feedback frame num marked by current Frame
109111 DECODER_OPTION_ERROR_CON_IDC, //not finished yet, indicate decoder error concealment status, in progress
112+ DECODER_OPTION_TRACE_LEVEL,
113+ DECODER_OPTION_TRACE_CALLBACK, // a void (*)(void* context, int level, const char* message) function which receives log messages
114+ DECODER_OPTION_TRACE_CALLBACK_CONTEXT,
110115
111116 } DECODER_OPTION;
112117
codec/build/android/dec/jni/welsdecdemo.mk+0−1
@@ -26,7 +26,6 @@ LOCAL_SRC_FILES := \ · 25 unmodified lines
2626 $(CONSOLE_DEC_PATH)/src/h264dec.cpp \
2727 $(CONSOLE_DEC_PATH)/src/read_config.cpp \
2828 $(CONSOLE_DEC_PATH)/src/d3d9_utils.cpp \
29− $(CODEC_PATH)/common/src/logging.cpp \
3029 myjni.cpp
3130 #
3231 # Header Includes
codec/build/android/enc/jni/welsencdemo.mk+0−1
@@ -25,7 +25,6 @@ CONSOLE_ENC_PATH := ../../../../console/enc · 24 unmodified lines
2525 LOCAL_SRC_FILES := \
2626 $(CONSOLE_ENC_PATH)/src/welsenc.cpp \
2727 $(CONSOLE_ENC_PATH)/src/read_config.cpp \
28− $(CODEC_PATH)/common/src/logging.cpp \
2928 myjni.cpp
3029
3130 #
codec/build/iOS/common/common.xcodeproj/project.pbxproj+0−6
@@ -14,7 +14,6 @@ · 13 unmodified lines
1414 4C3406CD18D96EA600DFA14A /* cpu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C3406C418D96EA600DFA14A /* cpu.cpp */; };
1515 4C3406CE18D96EA600DFA14A /* crt_util_safe_x.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C3406C518D96EA600DFA14A /* crt_util_safe_x.cpp */; };
1616 4C3406CF18D96EA600DFA14A /* deblocking_common.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C3406C618D96EA600DFA14A /* deblocking_common.cpp */; };
17− 4C3406D018D96EA600DFA14A /* logging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C3406C718D96EA600DFA14A /* logging.cpp */; };
1817 4C3406D118D96EA600DFA14A /* WelsThreadLib.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C3406C818D96EA600DFA14A /* WelsThreadLib.cpp */; };
1918 4CC61F0918FF6B4B00E56EAB /* copy_mb_neon.S in Sources */ = {isa = PBXBuildFile; fileRef = 4CC61F0818FF6B4B00E56EAB /* copy_mb_neon.S */; };
2019 4CE443D918B722CD0017DF25 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CE443D818B722CD0017DF25 /* Foundation.framework */; };
@@ -47,7 +46,6 @@ · 26 unmodified lines
4746 4C3406B818D96EA600DFA14A /* cpu_core.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cpu_core.h; sourceTree = "<group>"; };
4847 4C3406B918D96EA600DFA14A /* crt_util_safe_x.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = crt_util_safe_x.h; sourceTree = "<group>"; };
4948 4C3406BA18D96EA600DFA14A /* deblocking_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = deblocking_common.h; sourceTree = "<group>"; };
50− 4C3406BC18D96EA600DFA14A /* logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = logging.h; sourceTree = "<group>"; };
5149 4C3406BD18D96EA600DFA14A /* ls_defines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ls_defines.h; sourceTree = "<group>"; };
5250 4C3406BE18D96EA600DFA14A /* macros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = macros.h; sourceTree = "<group>"; };
5351 4C3406BF18D96EA600DFA14A /* mc_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mc_common.h; sourceTree = "<group>"; };
@@ -57,7 +55,6 @@ · 3 unmodified lines
5755 4C3406C418D96EA600DFA14A /* cpu.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cpu.cpp; sourceTree = "<group>"; };
5856 4C3406C518D96EA600DFA14A /* crt_util_safe_x.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = crt_util_safe_x.cpp; sourceTree = "<group>"; };
5957 4C3406C618D96EA600DFA14A /* deblocking_common.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = deblocking_common.cpp; sourceTree = "<group>"; };
60− 4C3406C718D96EA600DFA14A /* logging.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = logging.cpp; sourceTree = "<group>"; };
6158 4C3406C818D96EA600DFA14A /* WelsThreadLib.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WelsThreadLib.cpp; sourceTree = "<group>"; };
6259 4CC61F0818FF6B4B00E56EAB /* copy_mb_neon.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = copy_mb_neon.S; sourceTree = "<group>"; };
6360 4CE443D518B722CD0017DF25 /* libcommon.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libcommon.a; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -108,7 +105,6 @@ · 44 unmodified lines
108105 4C3406B918D96EA600DFA14A /* crt_util_safe_x.h */,
109106 53C1C9BA193F0F9E00404D8F /* expand_pic.h */,
110107 4C3406BA18D96EA600DFA14A /* deblocking_common.h */,
111− 4C3406BC18D96EA600DFA14A /* logging.h */,
112108 4C3406BD18D96EA600DFA14A /* ls_defines.h */,
113109 4C3406BE18D96EA600DFA14A /* macros.h */,
114110 4C3406BF18D96EA600DFA14A /* mc_common.h */,
@@ -128,7 +124,6 @@ · 13 unmodified lines
128124 4C3406C518D96EA600DFA14A /* crt_util_safe_x.cpp */,
129125 53C1C9BB193F0FB000404D8F /* expand_pic.cpp */,
130126 4C3406C618D96EA600DFA14A /* deblocking_common.cpp */,
131− 4C3406C718D96EA600DFA14A /* logging.cpp */,
132127 4C3406C818D96EA600DFA14A /* WelsThreadLib.cpp */,
133128 );
134129 path = src;
@@ -238,7 +233,6 @@ · 103 unmodified lines
238233 F556A8241906673900E156A8 /* arm_arch64_common_macro.S in Sources */,
239234 4C3406CE18D96EA600DFA14A /* crt_util_safe_x.cpp in Sources */,
240235 4C3406CF18D96EA600DFA14A /* deblocking_common.cpp in Sources */,
241− 4C3406D018D96EA600DFA14A /* logging.cpp in Sources */,
242236 4C3406D118D96EA600DFA14A /* WelsThreadLib.cpp in Sources */,
243237 4C3406CC18D96EA600DFA14A /* mc_neon.S in Sources */,
244238 4C3406CB18D96EA600DFA14A /* expand_picture_neon.S in Sources */,
codec/build/win32/dec/WelsDecCore.vcproj+0−4
@@ -902,10 +902,6 @@ · 901 unmodified lines
902902 RelativePath="..\..\..\decoder\core\src\get_intra_predictor.cpp"
903903 >
904904 </File>
905− <File
906− RelativePath="..\..\..\common\src\logging.cpp"
907− >
908− </File>
909905 <File
910906 RelativePath="..\..\..\decoder\core\src\manage_dec_ref.cpp"
911907 >
codec/build/win32/dec/decConsole.vcproj+0−4
@@ -394,10 +394,6 @@ · 393 unmodified lines
394394 RelativePath="..\..\..\console\dec\src\h264dec.cpp"
395395 >
396396 </File>
397− <File
398− RelativePath="..\..\..\common\src\logging.cpp"
399− >
400− </File>
401397 <File
402398 RelativePath="..\..\..\console\dec\src\read_config.cpp"
403399 >
codec/build/win32/enc/WelsEncCore.vcproj+0−4
@@ -395,10 +395,6 @@ · 394 unmodified lines
395395 RelativePath="..\..\..\encoder\core\src\get_intra_predictor.cpp"
396396 >
397397 </File>
398− <File
399− RelativePath="..\..\..\common\src\logging.cpp"
400− >
401− </File>
402398 <File
403399 RelativePath="..\..\..\encoder\core\src\mc.cpp"
404400 >
codec/build/win32/enc/encConsole.vcproj+0−4
@@ -394,10 +394,6 @@ · 393 unmodified lines
394394 Name="Source Files"
395395 Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
396396 >
397− <File
398− RelativePath="..\..\..\common\src\logging.cpp"
399− >
400− </File>
401397 <File
402398 RelativePath="..\..\..\console\enc\src\read_config.cpp"
403399 >
codec/common/inc/logging.h+0−54
@@ -1,54 +0,0 @@
1−/*!
2− * \copy
3− * Copyright (c) 2013, Cisco Systems
4− * Copyright (c) 2013, Mozilla
5− * All rights reserved.
6− *
7− * Redistribution and use in source and binary forms, with or without
8− * modification, are permitted provided that the following conditions
9− * are met:
10− *
11− * * Redistributions of source code must retain the above copyright
12− * notice, this list of conditions and the following disclaimer.
13− *
14− * * Redistributions in binary form must reproduce the above copyright
15− * notice, this list of conditions and the following disclaimer in
16− * the documentation and/or other materials provided with the
17− * distribution.
18− *
19− * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20− * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21− * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22− * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23− * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24− * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25− * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26− * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27− * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28− * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29− * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30− * POSSIBILITY OF SUCH DAMAGE.
31− *
32− */
33−
34−
35−#ifndef WELS_LOGGING_H__
36−#define WELS_LOGGING_H__
37−
38−// API surface.
39−void WelsStderrSetTraceLevel (int32_t level);
40−
41−
42−// Internal details.
43−int32_t welsStderrLevelTrace (int32_t level, const char* format, va_list ap);
44−
45−template<int level> int32_t welsStderrTrace (
46− const char* format, ...) {
47− va_list ap;
48− va_start (ap, format);
49− welsStderrLevelTrace (level, format, ap);
50− va_end (ap);
51− return 0;
52−}
53−
54−#endif
codec/common/inc/utils.h+5−23
@@ -47,7 +47,6 @@ · 46 unmodified lines
4747 * Log output routines
4848 */
4949
50−typedef int32_t iWelsLogLevel;
5150 enum {
5251 WELS_LOG_QUIET = 0x00, // Quiet mode
5352 WELS_LOG_ERROR = 1 << 0, // Error log iLevel
@@ -56,7 +55,7 @@ enum { · 2 unmodified lines
5655 WELS_LOG_DEBUG = 1 << 3, // Debug log iLevel
5756 WELS_LOG_RESV = 1 << 4, // Resversed log iLevel
5857 WELS_LOG_LEVEL_COUNT = 5,
59− WELS_LOG_DEFAULT = WELS_LOG_ERROR | WELS_LOG_WARNING | WELS_LOG_INFO | WELS_LOG_DEBUG // Default log iLevel in Wels codec
58+ WELS_LOG_DEFAULT = WELS_LOG_DEBUG // Default log iLevel in Wels codec
6059 };
6160
6261 /*
@@ -65,14 +64,10 @@ enum { · 2 unmodified lines
6564 // wels log output
6665 typedef void (*PWelsLogCallbackFunc) (void* pCtx, const int32_t iLevel, const char* kpFmt, va_list argv);
6766
68−// wels psnr calc
69−typedef float (*PWelsPsnrFunc) (const void* kpTarPic,
70− const int32_t kiTarStride,
71− const void* kpRefPic,
72− const int32_t kiRefStride,
73− const int32_t kiWidth,
74− const int32_t kiHeight);
75−
67+typedef struct TagLogContext {
68+ PWelsLogCallbackFunc pfLog;
69+ void* pLogCtx;
70+} SLogContext;
7671
7772
7873 #ifdef __GNUC__
@@ -82,19 +77,6 @@ extern void WelsLog (void* pCtx, int32_t iLevel, const char* kpFmt, ...) __attri · 3 unmodified lines
8277 extern void WelsLog (void* pCtx, int32_t iLevel, const char* kpFmt, ...);
8378 #endif
8479
85−/*!
86− *************************************************************************************
87− * \brief set log callback from external call
88− *
89− * \param _log log function routine
90− *
91− * \return NONE
92− *
93− * \note N/A
94− *************************************************************************************
95− */
96−void WelsSetLogCallback (PWelsLogCallbackFunc _log);
97−
9880 /*
9981 * PSNR calculation routines
10082 */
codec/common/inc/welsCodecTrace.h+12−9
@@ -35,26 +35,29 @@ · 34 unmodified lines
3535
3636 #include <stdarg.h>
3737 #include "typedefs.h"
38+#include "utils.h"
3839
39−typedef int32_t (*CM_WELS_TRACE) (const char* format, ...);
40+typedef void (*CM_WELS_TRACE) (void* ctx, int level, const char* string);
4041
4142 class welsCodecTrace {
4243 public:
4344 welsCodecTrace();
4445 ~welsCodecTrace();
4546
46− static void TraceString (int32_t iLevel, const char* kpStrFormat);
47− static void CODEC_TRACE (void* pIgnore, const int32_t kiLevel, const char* kpStrFormat, va_list vl);
48−
4947 void SetTraceLevel (const int32_t kiLevel);
48+ void SetTraceCallback (CM_WELS_TRACE func);
49+ void SetTraceCallbackContext (void* pCtx);
50+
51+ private:
52+ static void StaticCodecTrace (void* pCtx, const int32_t kiLevel, const char* kpStrFormat, va_list vl);
53+ void CodecTrace (const int32_t kiLevel, const char* kpStrFormat, va_list vl);
5054
55+ int32_t m_iTraceLevel;
56+ CM_WELS_TRACE m_fpTrace;
57+ void* m_pTraceCtx;
5158 public:
52− static int32_t m_iTraceLevel;
53− static CM_WELS_TRACE m_fpDebugTrace;
54− static CM_WELS_TRACE m_fpInfoTrace;
55− static CM_WELS_TRACE m_fpWarnTrace;
56− static CM_WELS_TRACE m_fpErrorTrace;
5759
60+ SLogContext m_sLogCtx;
5861 };
5962
6063 #endif //WELS_CODEC_TRACE
codec/common/src/logging.cpp+0−49
@@ -1,49 +0,0 @@
1−/*!
2− * \copy
3− * Copyright (c) 2013, Cisco Systems
4− * Copyright (c) 2013, Mozilla
5− * All rights reserved.
6− *
7− * Redistribution and use in source and binary forms, with or without
8− * modification, are permitted provided that the following conditions
9− * are met:
10− *
11− * * Redistributions of source code must retain the above copyright
12− * notice, this list of conditions and the following disclaimer.
13− *
14− * * Redistributions in binary form must reproduce the above copyright
15− * notice, this list of conditions and the following disclaimer in
16− * the documentation and/or other materials provided with the
17− * distribution.
18− *
19− * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20− * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21− * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22− * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23− * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24− * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25− * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26− * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27− * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28− * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29− * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30− * POSSIBILITY OF SUCH DAMAGE.
31− *
32− */
33−
34−#include <stdarg.h>
35−#include <stdio.h>
36−#include "typedefs.h"
37−
38−static int32_t g_TraceLevel = 0;
39−
40−void WelsStderrSetTraceLevel (int32_t level) {
41− g_TraceLevel = level;
42−}
43−
44−int32_t welsStderrLevelTrace (int32_t level, const char* format, va_list ap) {
45− if (level < g_TraceLevel) {
46− vfprintf (stderr, format, ap);
47− }
48− return 0;
49−}
codec/common/src/utils.cpp+2−18
@@ -48,27 +48,11 @@ float WelsCalcPsnr (const void* kpTarPic, · 47 unmodified lines
4848 const int32_t kiHeight);
4949
5050
51−static PWelsLogCallbackFunc wlog;
52−
53−/*!
54− *************************************************************************************
55− * \brief set log callback from external call
56− *
57− * \param _log log function routine
58− *
59− * \return NONE
60− *
61− * \note N/A
62− *************************************************************************************
63− */
64−void WelsSetLogCallback (PWelsLogCallbackFunc _log) {
65− wlog = _log;
66−}
67−
6851 void WelsLog (void* pCtx, int32_t iLevel, const char* kpFmt, ...) {
52+ SLogContext* logCtx = (SLogContext*) pCtx;
6953 va_list vl;
7054 va_start (vl, kpFmt);
71− wlog (pCtx, iLevel, kpFmt, vl);
55+ logCtx->pfLog (logCtx->pLogCtx, iLevel, kpFmt, vl);
7256 va_end (vl);
7357 }
7458
codec/common/src/welsCodecTrace.cpp+25−42
@@ -44,57 +44,34 @@ · 43 unmodified lines
4444 #include "welsCodecTrace.h"
4545 #include "utils.h"
4646
47−#include "logging.h"
4847
49−int32_t welsCodecTrace::m_iTraceLevel = WELS_LOG_DEFAULT;
50−CM_WELS_TRACE welsCodecTrace::m_fpDebugTrace = NULL;
51−CM_WELS_TRACE welsCodecTrace::m_fpInfoTrace = NULL;
52−CM_WELS_TRACE welsCodecTrace::m_fpWarnTrace = NULL;
53−CM_WELS_TRACE welsCodecTrace::m_fpErrorTrace = NULL;
48+
49+static void welsStderrTrace (void* ctx, int level, const char* string) {
50+ fprintf (stderr, "%s", string);
51+}
5452
5553 welsCodecTrace::welsCodecTrace() {
5654
57− m_fpDebugTrace = welsStderrTrace<WELS_LOG_DEBUG>;
58− m_fpInfoTrace = welsStderrTrace<WELS_LOG_INFO>;
59− m_fpWarnTrace = welsStderrTrace<WELS_LOG_WARNING>;
60− m_fpErrorTrace = welsStderrTrace<WELS_LOG_ERROR>;
61−}
55+ m_iTraceLevel = WELS_LOG_DEFAULT;
56+ m_fpTrace = welsStderrTrace;
57+ m_pTraceCtx = NULL;
6258
63−welsCodecTrace::~welsCodecTrace() {
64− m_fpDebugTrace = NULL;
65− m_fpInfoTrace = NULL;
66− m_fpWarnTrace = NULL;
67− m_fpErrorTrace = NULL;
59+ m_sLogCtx.pLogCtx = this;
60+ m_sLogCtx.pfLog = StaticCodecTrace;
6861 }
6962
70−void welsCodecTrace::TraceString (int32_t iLevel, const char* str) {
71− switch (iLevel) {
72− case WELS_LOG_ERROR:
73− if (m_fpErrorTrace)
74− m_fpErrorTrace ("%s", str);
75− break;
76− case WELS_LOG_WARNING:
77− if (m_fpWarnTrace)
78− m_fpWarnTrace ("%s", str);
79− break;
80− case WELS_LOG_INFO:
81− if (m_fpInfoTrace)
82− m_fpInfoTrace ("%s", str);
83− break;
84− case WELS_LOG_DEBUG:
85− if (m_fpDebugTrace)
86− m_fpDebugTrace ("%s", str);
87− break;
88− default:
89− if (m_fpDebugTrace)
90− m_fpInfoTrace ("%s", str);
91− break;
92− }
63+welsCodecTrace::~welsCodecTrace() {
64+ m_fpTrace = NULL;
9365 }
9466
9567 #define MAX_LOG_SIZE 1024
9668
97−void welsCodecTrace::CODEC_TRACE (void* ignore, const int32_t iLevel, const char* Str_Format, va_list vl) {
69+void welsCodecTrace::StaticCodecTrace (void* pCtx, const int32_t iLevel, const char* Str_Format, va_list vl) {
70+ welsCodecTrace* self = (welsCodecTrace*) pCtx;
71+ self->CodecTrace (iLevel, Str_Format, vl);
72+}
73+
74+void welsCodecTrace::CodecTrace (const int32_t iLevel, const char* Str_Format, va_list vl) {
9875 if (m_iTraceLevel < iLevel) {
9976 return;
10077 }
@@ -102,13 +79,19 @@ void welsCodecTrace::CODEC_TRACE (void* ignore, const int32_t iLevel, const char · 1 unmodified line
10279 char pBuf[MAX_LOG_SIZE] = {0};
10380 WelsVsnprintf (pBuf, MAX_LOG_SIZE, Str_Format, vl); // confirmed_safe_unsafe_usage
10481
105− welsCodecTrace::TraceString (iLevel, pBuf);
82+ m_fpTrace (m_pTraceCtx, iLevel, pBuf);
10683 }
10784
10885 void welsCodecTrace::SetTraceLevel (const int32_t iLevel) {
10986 if (iLevel >= 0)
11087 m_iTraceLevel = iLevel;
111− WelsStderrSetTraceLevel (iLevel);
11288 }
11389
90+void welsCodecTrace::SetTraceCallback (CM_WELS_TRACE func) {
91+ m_fpTrace = func;
92+}
93+
94+void welsCodecTrace::SetTraceCallbackContext (void* ctx) {
95+ m_pTraceCtx = ctx;
96+}
11497
codec/common/targets.mk+0−1
@@ -5,7 +5,6 @@ COMMON_CPP_SRCS=\ · 4 unmodified lines
55 $(COMMON_SRCDIR)/src/crt_util_safe_x.cpp\
66 $(COMMON_SRCDIR)/src/deblocking_common.cpp\
77 $(COMMON_SRCDIR)/src/expand_pic.cpp\
8− $(COMMON_SRCDIR)/src/logging.cpp\
98 $(COMMON_SRCDIR)/src/sad_common.cpp\
109 $(COMMON_SRCDIR)/src/utils.cpp\
1110 $(COMMON_SRCDIR)/src/welsCodecTrace.cpp\
codec/console/dec/src/h264dec.cpp+6−3
@@ -51,7 +51,6 @@ · 50 unmodified lines
5151 #include "typedefs.h"
5252 #include "measure_time.h"
5353 #include "d3d9_utils.h"
54−#include "logging.h"
5554
5655
5756 using namespace std;
@@ -311,6 +310,7 @@ int32_t main (int32_t iArgC, char* pArgV[]) { · 253 unmodified lines
311310
312311 SDecodingParam sDecParam = {0};
313312 string strInputFile (""), strOutputFile (""), strOptionFile ("");
313+ int iLevelSetting = -1;
314314
315315 sDecParam.sVideoProperty.size = sizeof (sDecParam.sVideoProperty);
316316
@@ -384,14 +384,14 @@ int32_t main (int32_t iArgC, char* pArgV[]) { · 67 unmodified lines
384384
385385 if (!strcmp (cmd, "-options")) {
386386 if (i + 1 < iArgC)
387− strOptionFile = pArgV[i++];
387+ strOptionFile = pArgV[++i];
388388 else {
389389 printf ("options file not specified.\n");
390390 return 1;
391391 }
392392 } else if (!strcmp (cmd, "-trace")) {
393393 if (i + 1 < iArgC)
394− WelsStderrSetTraceLevel (atoi (pArgV[i++]));
394+ iLevelSetting = atoi (pArgV[++i]);
395395 else {
396396 printf ("trace level not specified.\n");
397397 return 1;
@@ -418,6 +418,9 @@ int32_t main (int32_t iArgC, char* pArgV[]) { · 20 unmodified lines
418418 printf ("Create Decoder failed.\n");
419419 return 1;
420420 }
421+ if (iLevelSetting >= 0) {
422+ pDecoder->SetOption (DECODER_OPTION_TRACE_LEVEL, &iLevelSetting);
423+ }
421424
422425 if (pDecoder->Initialize (&sDecParam)) {
423426 printf ("Decoder initialization failed.\n");
codec/console/enc/src/welsenc.cpp+4−2
@@ -67,7 +67,6 @@ · 66 unmodified lines
6767 #include "extern.h"
6868 #include "macros.h"
6969 #include "wels_const.h"
70−#include "logging.h"
7170
7271 #include "mt_defs.h"
7372 #include "WelsThreadLib.h"
@@ -102,7 +101,7 @@ static int g_iCtrlC = 0; · 28 unmodified lines
102101 static void SigIntHandler (int a) {
103102 g_iCtrlC = 1;
104103 }
105−static int g_LevelSetting = 0;
104+static int g_LevelSetting = -1;
106105
107106 int ParseLayerConfig (CReadConfig& cRdLayerCfg, const int iLayer, SEncParamExt& pSvcParam, SFilesSet& sFileSet) {
108107 if (!cRdLayerCfg.ExistFile()) {
@@ -665,6 +664,9 @@ int ProcessEncoding(ISVCEncoder* pPtrEnc, int argc, char** argv,bool bConfigFile · 556 unmodified lines
665664 iRet = 1;
666665 goto INSIDE_MEM_FREE;
667666 }
667+ if (g_LevelSetting >= 0) {
668+ pPtrEnc->SetOption (ENCODER_OPTION_TRACE_LEVEL, &g_LevelSetting);
669+ }
668670 //finish reading the configurations
669671 iSourceWidth = pSrcPic->iPicWidth;
670672 iSourceHeight = pSrcPic->iPicHeight;
codec/decoder/core/inc/decoder.h+1−1
@@ -68,7 +68,7 @@ int32_t DecoderConfigParam (PWelsDecoderContext pCtx, const SDecodingParam* kpPa · 67 unmodified lines
6868 * \note N/A
6969 *************************************************************************************
7070 */
71−int32_t WelsInitDecoder (PWelsDecoderContext pCtx);
71+int32_t WelsInitDecoder (PWelsDecoderContext pCtx, SLogContext* pLogCtx);
7272
7373 /*!
7474 *************************************************************************************
codec/decoder/core/inc/decoder_context.h+1−0
@@ -164,6 +164,7 @@ enum { · 163 unmodified lines
164164 */
165165
166166 typedef struct TagWelsDecoderContext {
167+ SLogContext sLogCtx;
167168 // Input
168169 void* pArgDec; // structured arguments for decoder, reserved here for extension in the future
169170
codec/decoder/core/src/decoder.cpp+4−3
@@ -127,9 +127,10 @@ static void DestroyPicBuff (PPicBuff* ppPicBuf) { · 126 unmodified lines
127127 /*
128128 * fill data fields in default for decoder context
129129 */
130−void WelsDecoderDefaults (PWelsDecoderContext pCtx) {
130+void WelsDecoderDefaults (PWelsDecoderContext pCtx, SLogContext* pLogCtx) {
131131 int32_t iCpuCores = 1;
132132 memset (pCtx, 0, sizeof (SWelsDecoderContext)); // fill zero first
133+ pCtx->sLogCtx = *pLogCtx;
133134
134135 pCtx->pArgDec = NULL;
135136
@@ -350,13 +351,13 @@ int32_t DecoderConfigParam (PWelsDecoderContext pCtx, const SDecodingParam* kpPa · 214 unmodified lines
350351 * \note N/A
351352 *************************************************************************************
352353 */
353−int32_t WelsInitDecoder (PWelsDecoderContext pCtx) {
354+int32_t WelsInitDecoder (PWelsDecoderContext pCtx, SLogContext* pLogCtx) {
354355 if (pCtx == NULL) {
355356 return ERR_INFO_INVALID_PTR;
356357 }
357358
358359 // default
359− WelsDecoderDefaults (pCtx);
360+ WelsDecoderDefaults (pCtx, pLogCtx);
360361
361362 // open decoder
362363 WelsOpenDecoder (pCtx);
codec/decoder/plus/src/welsDecoderExt.cpp+36−12
@@ -103,10 +103,9 @@ CWelsDecoder::CWelsDecoder (void) · 102 unmodified lines
103103 m_pWelsTrace = new welsCodecTrace();
104104 if (m_pWelsTrace != NULL) {
105105 m_pWelsTrace->SetTraceLevel (WELS_LOG_ERROR);
106− WelsSetLogCallback (welsCodecTrace::CODEC_TRACE);
107− }
108106
109− WelsLog (NULL, WELS_LOG_INFO, "CWelsDecoder::CWelsDecoder() entry");
107+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::CWelsDecoder() entry");
108+ }
110109
111110 #ifdef OUTPUT_BIT_STREAM
112111 SWelsTime sCurTime;
@@ -161,7 +160,9 @@ CWelsDecoder::CWelsDecoder (void) · 48 unmodified lines
161160 * return: none
162161 ***************************************************************************/
163162 CWelsDecoder::~CWelsDecoder() {
164− WelsLog (NULL, WELS_LOG_INFO, "CWelsDecoder::~CWelsDecoder()");
163+ if (m_pWelsTrace != NULL) {
164+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::~CWelsDecoder()");
165+ }
165166
166167 UninitDecoder();
167168
@@ -183,8 +184,12 @@ CWelsDecoder::~CWelsDecoder() { · 15 unmodified lines
183184 }
184185
185186 long CWelsDecoder::Initialize (const SDecodingParam* pParam) {
187+ if (m_pWelsTrace == NULL) {
188+ return cmMallocMemeError;
189+ }
190+
186191 if (pParam == NULL) {
187− WelsLog (NULL, WELS_LOG_INFO, "CWelsDecoder::Initialize(), invalid input argument.");
192+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::Initialize(), invalid input argument.");
188193 return cmInitParaError;
189194 }
190195
@@ -206,7 +211,7 @@ void CWelsDecoder::UninitDecoder (void) { · 15 unmodified lines
206211 if (NULL == m_pDecContext)
207212 return;
208213
209− WelsLog (NULL, WELS_LOG_INFO, "into CWelsDecoder::uninit_decoder()..");
214+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "into CWelsDecoder::uninit_decoder()..");
210215
211216 WelsEndDecoder (m_pDecContext);
212217
@@ -216,19 +221,19 @@ void CWelsDecoder::UninitDecoder (void) { · 3 unmodified lines
216221 m_pDecContext = NULL;
217222 }
218223
219− WelsLog (NULL , WELS_LOG_INFO, "left CWelsDecoder::uninit_decoder()..");
224+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "left CWelsDecoder::uninit_decoder()..");
220225 }
221226
222227 // the return value of this function is not suitable, it need report failure info to upper layer.
223228 void CWelsDecoder::InitDecoder (void) {
224229
225− WelsLog (NULL, WELS_LOG_INFO, "CWelsDecoder::init_decoder()..");
230+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::init_decoder()..");
226231
227232 m_pDecContext = (PWelsDecoderContext)WelsMalloc (sizeof (SWelsDecoderContext), "m_pDecContext");
228233
229− WelsInitDecoder (m_pDecContext);
234+ WelsInitDecoder (m_pDecContext, &m_pWelsTrace->m_sLogCtx);
230235
231− WelsLog (NULL, WELS_LOG_INFO, "CWelsDecoder::init_decoder().. left");
236+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::init_decoder().. left");
232237 }
233238
234239 /*
@@ -237,7 +242,8 @@ void CWelsDecoder::InitDecoder (void) { · 2 unmodified lines
237242 long CWelsDecoder::SetOption (DECODER_OPTION eOptID, void* pOption) {
238243 int iVal = 0;
239244
240− if (m_pDecContext == NULL)
245+ if (m_pDecContext == NULL && eOptID != DECODER_OPTION_TRACE_LEVEL &&
246+ eOptID != DECODER_OPTION_TRACE_CALLBACK && eOptID != DECODER_OPTION_TRACE_CALLBACK_CONTEXT)
241247 return dsInitialOptExpected;
242248
243249 if (eOptID == DECODER_OPTION_DATAFORMAT) { // Set color space of decoding output frame
@@ -263,6 +269,24 @@ long CWelsDecoder::SetOption (DECODER_OPTION eOptID, void* pOption) { · 19 unmodified lines
263269 iVal = * ((int*)pOption); //EC method
264270 m_pDecContext->iErrorConMethod = iVal;
265271 return cmResultSuccess;
272+ } else if (eOptID == DECODER_OPTION_TRACE_LEVEL) {
273+ if (m_pWelsTrace) {
274+ uint32_t level = * ((uint32_t*)pOption);
275+ m_pWelsTrace->SetTraceLevel (level);
276+ }
277+ return cmResultSuccess;
278+ } else if (eOptID == DECODER_OPTION_TRACE_CALLBACK) {
279+ if (m_pWelsTrace) {
280+ CM_WELS_TRACE callback = * ((CM_WELS_TRACE*)pOption);
281+ m_pWelsTrace->SetTraceCallback (callback);
282+ }
283+ return cmResultSuccess;
284+ } else if (eOptID == DECODER_OPTION_TRACE_CALLBACK_CONTEXT) {
285+ if (m_pWelsTrace) {
286+ void* ctx = * ((void**)pOption);
287+ m_pWelsTrace->SetTraceCallbackContext (ctx);
288+ }
289+ return cmResultSuccess;
266290 }
267291
268292 return cmInitParaError;
@@ -386,7 +410,7 @@ DECODING_STATE CWelsDecoder::DecodeFrame2 (const unsigned char* kpSrc, · 117 unmodified lines
386410 }
387411 }
388412
389− WelsLog (NULL, WELS_LOG_INFO, "decode failed, failure type:%d \n",
413+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "decode failed, failure type:%d \n",
390414 m_pDecContext->iErrorCode);
391415 return (DECODING_STATE)m_pDecContext->iErrorCode;
392416 }
codec/encoder/core/inc/encoder_context.h+2−0
@@ -53,6 +53,7 @@ · 52 unmodified lines
5353 #include "wels_preprocess.h"
5454 #include "wels_func_ptr_def.h"
5555 #include "crt_util_safe_x.h"
56+#include "utils.h"
5657
5758 #include "mt_defs.h" // for multiple threadin,
5859 #include "WelsThreadLib.h"
@@ -110,6 +111,7 @@ typedef struct TagStrideTables { · 51 unmodified lines
110111 } SStrideTables;
111112
112113 typedef struct TagWelsEncCtx {
114+ SLogContext sLogCtx;
113115 // Input
114116 SWelsSvcCodingParam* pSvcParam; // SVC parameter, WelsSVCParamConfig in svc_param_settings.h
115117 SWelsSliceBs* pSliceBs; // bitstream buffering for various slices, [uiSliceIdx]
codec/encoder/core/inc/extern.h+3−3
@@ -64,7 +64,7 @@ int32_t InitPic (const void* kpSrc, const int32_t kiCsp, const int32_t kiWidth, · 63 unmodified lines
6464 * \pParam pParam SWelsSvcCodingParam*
6565 * \return successful - 0; otherwise none 0 for failed
6666 */
67−int32_t ParamValidationExt (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pParam);
67+int32_t ParamValidationExt (SLogContext* pCtx, SWelsSvcCodingParam* pParam);
6868
6969 // GOM based RC related for uiSliceNum decision
7070 void GomValidCheck (const int32_t kiMbWidth, const int32_t kiMbHeight, int32_t* pSliceNum);
@@ -75,7 +75,7 @@ void GomValidCheck (const int32_t kiMbWidth, const int32_t kiMbHeight, int32_t* · 4 unmodified lines
7575 * \param para SWelsSvcCodingParam*
7676 * \return successful - 0; otherwise none 0 for failed
7777 */
78−int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pPara);
78+int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pPara, SLogContext* pLogCtx);
7979
8080 /*!
8181 * \brief uninitialize Wels encoder core library
@@ -107,7 +107,7 @@ int32_t ForceCodingIDR (sWelsEncCtx* pCtx); · 25 unmodified lines
107107 */
108108 int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNew);
109109 void WelsEncoderApplyFrameRate (SWelsSvcCodingParam* pParam);
110−void WelsEncoderApplyBitRate (SWelsSvcCodingParam* pParam, int32_t iLayer);
110+void WelsEncoderApplyBitRate (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int32_t iLayer);
111111
112112 int32_t FilterLTRRecoveryRequest (sWelsEncCtx* pCtx, SLTRRecoverRequest* pLTRRecoverRequest);
113113
codec/encoder/core/inc/slice_multi_threading.h+2−2
@@ -81,8 +81,8 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg); · 80 unmodified lines
8181
8282 int32_t CreateSliceThreads (sWelsEncCtx* pCtx);
8383
84−int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList, WELS_EVENT* pMasterEventsList,
85− SLayerBSInfo* pLayerBsInfo,
84+int32_t FiredSliceThreads (sWelsEncCtx* pCtx, SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList,
85+ WELS_EVENT* pMasterEventsList, SLayerBSInfo* pLayerBsInfo,
8686 const uint32_t kuiNumThreads/*, int32_t *iLayerNum*/, SSliceCtx* pSliceCtx, const bool kbIsDynamicSlicingMode);
8787
8888 int32_t DynamicDetectCpuCores();
codec/encoder/core/src/encoder_ext.cpp+36−28
@@ -73,7 +73,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 72 unmodified lines
7373 * \pParam pParam SWelsSvcCodingParam*
7474 * \return successful - 0; otherwise none 0 for failed
7575 */
76−int32_t ParamValidation (SWelsSvcCodingParam* pCfg) {
76+int32_t ParamValidation (SLogContext* pLogCtx, SWelsSvcCodingParam* pCfg) {
7777 float fMaxFrameRate = 0.0f;
7878 const float fEpsn = 0.000001f;
7979 int32_t i = 0;
@@ -81,7 +81,7 @@ int32_t ParamValidation (SWelsSvcCodingParam* pCfg) { · 1 unmodified line
8181 assert (pCfg != NULL);
8282
8383 if ((pCfg->iUsageType != CAMERA_VIDEO_REAL_TIME) && (pCfg->iUsageType != SCREEN_CONTENT_REAL_TIME)) {
84− WelsLog (NULL, WELS_LOG_ERROR, "ParamValidation(),Invalid usage type = %d\n", pCfg->iUsageType);
84+ WelsLog (pLogCtx, WELS_LOG_ERROR, "ParamValidation(),Invalid usage type = %d\n", pCfg->iUsageType);
8585 return ENC_RETURN_UNSUPPORTED_PARA;
8686 }
8787 for (i = 0; i < pCfg->iSpatialLayerNum; ++ i) {
@@ -89,13 +89,13 @@ int32_t ParamValidation (SWelsSvcCodingParam* pCfg) { · 1 unmodified line
8989 if (fDlp->fOutputFrameRate > fDlp->fInputFrameRate || (fDlp->fInputFrameRate >= -fEpsn
9090 && fDlp->fInputFrameRate <= fEpsn)
9191 || (fDlp->fOutputFrameRate >= -fEpsn && fDlp->fOutputFrameRate <= fEpsn)) {
92− WelsLog (NULL, WELS_LOG_ERROR,
92+ WelsLog (pLogCtx, WELS_LOG_ERROR,
9393 "Invalid settings in input frame rate(%.6f) or output frame rate(%.6f) of layer #%d config file..\n",
9494 fDlp->fInputFrameRate, fDlp->fOutputFrameRate, i);
9595 return ENC_RETURN_INVALIDINPUT;
9696 }
9797 if (UINT_MAX == GetLogFactor (fDlp->fOutputFrameRate, fDlp->fInputFrameRate)) {
98− WelsLog (NULL, WELS_LOG_ERROR,
98+ WelsLog (pLogCtx, WELS_LOG_ERROR,
9999 "Invalid settings in input frame rate(%.6f) and output frame rate(%.6f) of layer #%d config file: iResult of output frame rate divided by input frame rate should be power of 2(i.e,in/pOut=2^n)..\n",
100100 fDlp->fInputFrameRate, fDlp->fOutputFrameRate, i);
101101 return ENC_RETURN_INVALIDINPUT;
@@ -121,7 +121,7 @@ int32_t ParamValidation (SWelsSvcCodingParam* pCfg) { · 19 unmodified lines
121121 iTotalBitrate += fDlp->iSpatialBitrate;
122122 }
123123 if (iTotalBitrate > pCfg->iTargetBitrate) {
124− WelsLog (NULL, WELS_LOG_ERROR,
124+ WelsLog (pLogCtx, WELS_LOG_ERROR,
125125 "Invalid settings in bitrate. the sum of each layer bitrate(%d) is larger than total bitrate setting(%d)\n",
126126 iTotalBitrate, pCfg->iTargetBitrate);
127127 }
@@ -131,7 +131,7 @@ int32_t ParamValidation (SWelsSvcCodingParam* pCfg) { · 3 unmodified lines
131131 }
132132
133133
134−int32_t ParamValidationExt (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pCodingParam) {
134+int32_t ParamValidationExt (SLogContext* pCtx, SWelsSvcCodingParam* pCodingParam) {
135135 int8_t i = 0;
136136 int32_t iIdx = 0;
137137
@@ -383,7 +383,7 @@ int32_t ParamValidationExt (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pCodingParam · 245 unmodified lines
383383 }
384384 }
385385
386− return ParamValidation (pCodingParam);
386+ return ParamValidation (pCtx, pCodingParam);
387387 }
388388
389389
@@ -412,7 +412,7 @@ void WelsEncoderApplyFrameRate (SWelsSvcCodingParam* pParam) { · 22 unmodified lines
412412 }
413413
414414
415−void WelsEncoderApplyBitRate (SWelsSvcCodingParam* pParam, int iLayer) {
415+void WelsEncoderApplyBitRate (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int iLayer) {
416416 //TODO (Sijia): this is a temporary solution which keep the ratio between layers
417417 //but it is also possible to fulfill the bitrate of lower layer first
418418
@@ -421,7 +421,7 @@ void WelsEncoderApplyBitRate (SWelsSvcCodingParam* pParam, int iLayer) { · 2 unmodified lines
421421 int32_t i, iOrigTotalBitrate = 0;
422422 if (iLayer == SPATIAL_LAYER_ALL) {
423423 if (pParam->iMaxBitrate < pParam->iTargetBitrate) {
424− WelsLog (NULL, WELS_LOG_WARNING,
424+ WelsLog (pLogCtx, WELS_LOG_WARNING,
425425 "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE,overall settting,TargetBitrate = %d,iMaxBitrate = %d\n",
426426 pParam->iTargetBitrate, pParam->iMaxBitrate);
427427 pParam->iMaxBitrate = pParam->iTargetBitrate;
@@ -439,7 +439,7 @@ void WelsEncoderApplyBitRate (SWelsSvcCodingParam* pParam, int iLayer) { · 11 unmodified lines
439439 }
440440 } else {
441441 if (pParam->sSpatialLayers[iLayer].iMaxSpatialBitrate < pParam->sSpatialLayers[iLayer].iSpatialBitrate) {
442− WelsLog (NULL, WELS_LOG_WARNING,
442+ WelsLog (pLogCtx, WELS_LOG_WARNING,
443443 "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE,iLayer = %d,iTargetBitrate = %d,iMaxBitrate = %d\n",
444444 iLayer, pParam->sSpatialLayers[iLayer].iSpatialBitrate, pParam->sSpatialLayers[iLayer].iMaxSpatialBitrate);
445445 pParam->sSpatialLayers[iLayer].iMaxSpatialBitrate = pParam->sSpatialLayers[iLayer].iSpatialBitrate;
@@ -1723,7 +1723,7 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 1277 unmodified lines
17231723 #endif//MEMORY_MONITOR
17241724
17251725 if ((*ppCtx)->pMemAlign != NULL) {
1726− WelsLog (NULL, WELS_LOG_INFO, "FreeMemorySvc(), verify memory usage (%d bytes) after free..\n",
1726+ WelsLog (*ppCtx, WELS_LOG_INFO, "FreeMemorySvc(), verify memory usage (%d bytes) after free..\n",
17271727 (*ppCtx)->pMemAlign->WelsGetMemoryUsage());
17281728 delete (*ppCtx)->pMemAlign;
17291729 (*ppCtx)->pMemAlign = NULL;
@@ -1734,7 +1734,8 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 4 unmodified lines
17341734 }
17351735 }
17361736
1737−int32_t InitSliceSettings (SWelsSvcCodingParam* pCodingParam, const int32_t kiCpuCores, int16_t* pMaxSliceCount) {
1737+int32_t InitSliceSettings (SLogContext* pLogCtx, SWelsSvcCodingParam* pCodingParam, const int32_t kiCpuCores,
1738+ int16_t* pMaxSliceCount) {
17381739 int32_t iSpatialIdx = 0, iSpatialNum = pCodingParam->iSpatialLayerNum;
17391740 uint16_t iMaxSliceCount = 0;
17401741
@@ -1784,7 +1785,7 @@ int32_t InitSliceSettings (SWelsSvcCodingParam* pCodingParam, const int32_t kiCp · 43 unmodified lines
17841785 pDlp->sSliceCfg.sSliceArgument.uiSliceNum = iMaxSliceCount;
17851786 }
17861787 if (pDlp->sSliceCfg.sSliceArgument.uiSliceNum == 1) {
1787− WelsLog (NULL, WELS_LOG_DEBUG,
1788+ WelsLog (pLogCtx, WELS_LOG_DEBUG,
17881789 "InitSliceSettings(), uiSliceNum(%d) you set for SM_AUTO_SLICE, now turn to SM_SINGLE_SLICE type!\n",
17891790 pDlp->sSliceCfg.sSliceArgument.uiSliceNum);
17901791 pDlp->sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;
@@ -1799,7 +1800,7 @@ int32_t InitSliceSettings (SWelsSvcCodingParam* pCodingParam, const int32_t kiCp · 8 unmodified lines
17991800 } else if (!CheckFixedSliceNumMultiSliceSetting (kiMbNumInFrame,
18001801 &pDlp->sSliceCfg.sSliceArgument)) { // verify interleave mode settings
18011802 //check uiSliceMbNum with current uiSliceNum
1802− WelsLog (NULL, WELS_LOG_ERROR,
1803+ WelsLog (pLogCtx, WELS_LOG_ERROR,
18031804 "InitSliceSettings(), invalid uiSliceMbNum (%d) settings!,now turn to SM_SINGLE_SLICE type\n",
18041805 pDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[0]);
18051806 pDlp->sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;
@@ -1838,9 +1839,10 @@ int32_t InitSliceSettings (SWelsSvcCodingParam* pCodingParam, const int32_t kiCp · 32 unmodified lines
18381839 /*!
18391840 * \brief log output for cpu features/capabilities
18401841 */
1841−void OutputCpuFeaturesLog (uint32_t uiCpuFeatureFlags, uint32_t uiCpuCores, int32_t iCacheLineSize) {
1842+void OutputCpuFeaturesLog (SLogContext* pLogCtx, uint32_t uiCpuFeatureFlags, uint32_t uiCpuCores,
1843+ int32_t iCacheLineSize) {
18421844 // welstracer output
1843− WelsLog (NULL, WELS_LOG_INFO, "WELS CPU features/capacities (0x%x) detected: \t" \
1845+ WelsLog (pLogCtx, WELS_LOG_INFO, "WELS CPU features/capacities (0x%x) detected: \t" \
18441846 "HTT: %c, " \
18451847 "MMX: %c, " \
18461848 "MMXEX: %c, " \
@@ -1890,7 +1892,7 @@ void OutputCpuFeaturesLog (uint32_t uiCpuFeatureFlags, uint32_t uiCpuCores, int3 · 43 unmodified lines
18901892 * \pParam pParam SWelsSvcCodingParam*
18911893 * \return successful - 0; otherwise none 0 for failed
18921894 */
1893−int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingParam) {
1895+int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingParam, SLogContext* pLogCtx) {
18941896 sWelsEncCtx* pCtx = NULL;
18951897 int32_t iRet = 0;
18961898 uint32_t uiCpuFeatureFlags = 0; // CPU features
@@ -1900,14 +1902,14 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 3 unmodified lines
19001902 int16_t iSliceNum = 1; // number of slices used
19011903
19021904 if (NULL == ppCtx || NULL == pCodingParam) {
1903− WelsLog (NULL, WELS_LOG_ERROR, "WelsInitEncoderExt(), NULL == ppCtx(0x%p) or NULL == pCodingParam(0x%p).\n",
1905+ WelsLog (pLogCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), NULL == ppCtx(0x%p) or NULL == pCodingParam(0x%p).\n",
19041906 (void*)ppCtx, (void*)pCodingParam);
19051907 return 1;
19061908 }
19071909
1908− iRet = ParamValidationExt (*ppCtx, pCodingParam);
1910+ iRet = ParamValidationExt (pLogCtx, pCodingParam);
19091911 if (iRet != 0) {
1910− WelsLog (NULL, WELS_LOG_ERROR, "WelsInitEncoderExt(), ParamValidationExt failed return %d.\n", iRet);
1912+ WelsLog (pLogCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), ParamValidationExt failed return %d.\n", iRet);
19111913 return iRet;
19121914 }
19131915
@@ -1922,7 +1924,7 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 8 unmodified lines
19221924 iCacheLineSize = 32;
19231925 else if (uiCpuFeatureFlags & WELS_CPU_CACHELINE_16)
19241926 iCacheLineSize = 16;
1925− OutputCpuFeaturesLog (uiCpuFeatureFlags, uiCpuCores, iCacheLineSize);
1927+ OutputCpuFeaturesLog (pLogCtx, uiCpuFeatureFlags, uiCpuCores, iCacheLineSize);
19261928 #else
19271929 iCacheLineSize = 16; // 16 bytes aligned in default
19281930 #endif//X86_ASM
@@ -1953,8 +1955,8 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 24 unmodified lines
19531955
19541956 uiCpuCores = WELS_CLIP3 (uiCpuCores, 1, MAX_THREADS_NUM);
19551957
1956− if (InitSliceSettings (pCodingParam, uiCpuCores, &iSliceNum)) {
1957− WelsLog (NULL, WELS_LOG_ERROR, "WelsInitEncoderExt(), InitSliceSettings failed.\n");
1958+ if (InitSliceSettings (pLogCtx, pCodingParam, uiCpuCores, &iSliceNum)) {
1959+ WelsLog (pLogCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), InitSliceSettings failed.\n");
19581960 return 1;
19591961 }
19601962
@@ -1965,6 +1967,8 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 4 unmodified lines
19651967 WELS_VERIFY_RETURN_IF (1, (NULL == pCtx))
19661968 memset (pCtx, 0, sizeof (sWelsEncCtx));
19671969
1970+ pCtx->sLogCtx = *pLogCtx;
1971+
19681972 pCtx->pMemAlign = new CMemoryAlign (iCacheLineSize);
19691973 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pCtx->pMemAlign), FreeMemorySvc (&pCtx))
19701974
@@ -3133,7 +3137,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 1162 unmodified lines
31333137
31343138 pCtx->iActiveThreadsNum = iSliceCount;
31353139 // to fire slice coding threads
3136− iRet = FiredSliceThreads (&pCtx->pSliceThreading->pThreadPEncCtx[0], &pCtx->pSliceThreading->pReadySliceCodingEvent[0],
3140+ iRet = FiredSliceThreads (pCtx, &pCtx->pSliceThreading->pThreadPEncCtx[0],
3141+ &pCtx->pSliceThreading->pReadySliceCodingEvent[0],
31373142 &pCtx->pSliceThreading->pThreadMasterEvent[0],
31383143 pLayerBsInfo, iSliceCount, pCtx->pCurDqLayer->pSliceEncCtx, false);
31393144 if (iRet) {
@@ -3172,7 +3177,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 32 unmodified lines
31723177 iNumThreadsScheduled = pCtx->iActiveThreadsNum;
31733178 iNumThreadsRunning = iNumThreadsScheduled;
31743179 // to fire slice coding threads
3175− iRet = FiredSliceThreads (&pCtx->pSliceThreading->pThreadPEncCtx[0], &pCtx->pSliceThreading->pReadySliceCodingEvent[0],
3180+ iRet = FiredSliceThreads (pCtx, &pCtx->pSliceThreading->pThreadPEncCtx[0],
3181+ &pCtx->pSliceThreading->pReadySliceCodingEvent[0],
31763182 &pCtx->pSliceThreading->pThreadMasterEvent[0],
31773183 pLayerBsInfo, iNumThreadsRunning, pCtx->pCurDqLayer->pSliceEncCtx, false);
31783184 if (iRet) {
@@ -3218,7 +3224,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 39 unmodified lines
32183224 const int32_t kiPartitionCnt = pCtx->iActiveThreadsNum; //pSvcParam->iCountThreadsNum;
32193225
32203226 // to fire slice coding threads
3221− iRet = FiredSliceThreads (&pCtx->pSliceThreading->pThreadPEncCtx[0], &pCtx->pSliceThreading->pReadySliceCodingEvent[0],
3227+ iRet = FiredSliceThreads (pCtx, &pCtx->pSliceThreading->pThreadPEncCtx[0],
3228+ &pCtx->pSliceThreading->pReadySliceCodingEvent[0],
32223229 &pCtx->pSliceThreading->pThreadMasterEvent[0],
32233230 pLayerBsInfo, kiPartitionCnt, pCtx->pCurDqLayer->pSliceEncCtx, true);
32243231 if (iRet) {
@@ -3509,7 +3516,7 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa · 284 unmodified lines
35093516 if (NULL == ppCtx || NULL == *ppCtx || NULL == pNewParam) return 1;
35103517
35113518 /* Check validation in new parameters */
3512− iReturn = ParamValidationExt (*ppCtx, pNewParam);
3519+ iReturn = ParamValidationExt (& (*ppCtx)->sLogCtx, pNewParam);
35133520 if (iReturn != ENC_RETURN_SUCCESS) return iReturn;
35143521
35153522 pOldParam = (*ppCtx)->pSvcParam;
@@ -3574,6 +3581,7 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa · 58 unmodified lines
35743581 if (bNeedReset) {
35753582 SParaSetOffsetVariable sTmpPsoVariable[PARA_SET_TYPE];
35763583 uint16_t uiTmpIdrPicId;//this is for LTR!
3584+ SLogContext sLogCtx = (*ppCtx)->sLogCtx;
35773585 memcpy (sTmpPsoVariable, (*ppCtx)->sPSOVector.sParaSetOffsetVariable,
35783586 (PARA_SET_TYPE)*sizeof (SParaSetOffsetVariable)); // confirmed_safe_unsafe_usage
35793587 uiTmpIdrPicId = (*ppCtx)->sPSOVector.uiIdrPicId;
@@ -3581,7 +3589,7 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa · 1 unmodified line
35813589 WelsUninitEncoderExt (ppCtx);
35823590
35833591 /* Update new parameters */
3584− if (WelsInitEncoderExt (ppCtx, pNewParam))
3592+ if (WelsInitEncoderExt (ppCtx, pNewParam, &sLogCtx))
35853593 return 1;
35863594
35873595 // reset the scaled spatial picture size
codec/encoder/core/src/slice_multi_threading.cpp+3−3
@@ -968,15 +968,15 @@ int32_t CreateSliceThreads (sWelsEncCtx* pCtx) { · 967 unmodified lines
968968 return 0;
969969 }
970970
971−int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList, WELS_EVENT* pMasterEventsList,
972− SLayerBSInfo* pLbi,
971+int32_t FiredSliceThreads (sWelsEncCtx* pCtx, SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList,
972+ WELS_EVENT* pMasterEventsList, SLayerBSInfo* pLbi,
973973 const uint32_t uiNumThreads, SSliceCtx* pSliceCtx, const bool bIsDynamicSlicingMode) {
974974 int32_t iEndMbIdx = 0;
975975 int32_t iIdx = 0;
976976 const int32_t kiEventCnt = uiNumThreads;
977977
978978 if (pPriData == NULL || pLbi == NULL || kiEventCnt <= 0 || pEventsList == NULL) {
979− WelsLog (NULL, WELS_LOG_ERROR,
979+ WelsLog (pCtx, WELS_LOG_ERROR,
980980 "FiredSliceThreads(), fail due pPriData == %p || pLbi == %p || iEventCnt(%d) <= 0 || pEventsList == %p!!\n",
981981 (void*)pPriData, (void*)pLbi, uiNumThreads, (void*)pEventsList);
982982 return 1;
codec/encoder/plus/src/welsEncoderExt.cpp+68−38
@@ -131,17 +131,15 @@ CWelsH264SVCEncoder::CWelsH264SVCEncoder() · 130 unmodified lines
131131 }
132132
133133 CWelsH264SVCEncoder::~CWelsH264SVCEncoder() {
134− WelsLog (NULL, WELS_LOG_INFO, "CWelsH264SVCEncoder::~CWelsH264SVCEncoder()\n");
134+ if (m_pWelsTrace) {
135+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsH264SVCEncoder::~CWelsH264SVCEncoder()\n");
135136
136− if (m_pWelsTrace != NULL) {
137− delete m_pWelsTrace;
138− m_pWelsTrace = NULL;
139− }
140137 #ifdef REC_FRAME_COUNT
141− WelsLog (m_pEncContext, WELS_LOG_INFO,
142− "CWelsH264SVCEncoder::~CWelsH264SVCEncoder(), m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum,
143− m_iCspInternal);
138+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
139+ "CWelsH264SVCEncoder::~CWelsH264SVCEncoder(), m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum,
140+ m_iCspInternal);
144141 #endif
142+ }
145143
146144 #ifdef REC_FRAME_COUNT
147145 m_uiCountFrameNum = 0;
@@ -161,20 +159,26 @@ CWelsH264SVCEncoder::~CWelsH264SVCEncoder() { · 13 unmodified lines
161159 #endif//OUTPUT_BIT_STREAM
162160
163161 Uninitialize();
162+
163+ if (m_pWelsTrace) {
164+ delete m_pWelsTrace;
165+ m_pWelsTrace = NULL;
166+ }
164167 }
165168
166169 void CWelsH264SVCEncoder::InitEncoder (void) {
167170
171+ m_pWelsTrace = new welsCodecTrace();
172+ if (m_pWelsTrace == NULL) {
173+ return;
174+ }
175+
176+ m_pWelsTrace->SetTraceLevel (WELS_LOG_ERROR);
177+
168178 #ifdef REC_FRAME_COUNT
169− WelsLog (m_pEncContext, WELS_LOG_INFO,
179+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
170180 "CWelsH264SVCEncoder::InitEncoder, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal);
171181 #endif
172−
173− m_pWelsTrace = new welsCodecTrace();
174− if (m_pWelsTrace != NULL) {
175− m_pWelsTrace->SetTraceLevel (WELS_LOG_ERROR);
176− WelsSetLogCallback (welsCodecTrace::CODEC_TRACE);
177− }
178182 }
179183
180184 /* Interfaces override from ISVCEncoder */
@@ -188,9 +192,12 @@ int CWelsH264SVCEncoder::GetDefaultParams (SEncParamExt* argv) { · 7 unmodified lines
188192 * SVC Encoder Initialization
189193 */
190194 int CWelsH264SVCEncoder::Initialize (const SEncParamBase* argv) {
195+ if (m_pWelsTrace == NULL) {
196+ return cmMallocMemeError;
197+ }
191198
192199 if (NULL == argv) {
193− WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid argv= 0x%p\n",
200+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid argv= 0x%p\n",
194201 argv);
195202 return cmInitParaError;
196203 }
@@ -198,7 +205,8 @@ int CWelsH264SVCEncoder::Initialize (const SEncParamBase* argv) { · 1 unmodified line
198205 SWelsSvcCodingParam sConfig;
199206 // Convert SEncParamBase into WelsSVCParamConfig here..
200207 if (sConfig.ParamBaseTranscode (*argv)) {
201− WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), parameter_translation failed.\n");
208+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
209+ "CWelsH264SVCEncoder::Initialize(), parameter_translation failed.\n");
202210 Uninitialize();
203211 return cmInitParaError;
204212 }
@@ -207,9 +215,12 @@ int CWelsH264SVCEncoder::Initialize (const SEncParamBase* argv) { · 2 unmodified lines
207215 }
208216
209217 int CWelsH264SVCEncoder::InitializeExt (const SEncParamExt* argv) {
218+ if (m_pWelsTrace == NULL) {
219+ return cmMallocMemeError;
220+ }
210221
211222 if (NULL == argv) {
212− WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::InitializeExt(), invalid argv= 0x%p\n",
223+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::InitializeExt(), invalid argv= 0x%p\n",
213224 argv);
214225 return cmInitParaError;
215226 }
@@ -217,7 +228,8 @@ int CWelsH264SVCEncoder::InitializeExt (const SEncParamExt* argv) { · 1 unmodified line
217228 SWelsSvcCodingParam sConfig;
218229 // Convert SEncParamExt into WelsSVCParamConfig here..
219230 if (sConfig.ParamTranscode (*argv)) {
220− WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::InitializeExt(), parameter_translation failed.\n");
231+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
232+ "CWelsH264SVCEncoder::InitializeExt(), parameter_translation failed.\n");
221233 Uninitialize();
222234 return cmInitParaError;
223235 }
@@ -227,22 +239,24 @@ int CWelsH264SVCEncoder::InitializeExt (const SEncParamExt* argv) { · 3 unmodified lines
227239
228240 int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) {
229241 if (NULL == pCfg) {
230− WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid argv= 0x%p.\n",
242+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid argv= 0x%p.\n",
231243 pCfg);
232244 return cmInitParaError;
233245 }
234246
235247 if (m_bInitialFlag) {
236− WelsLog (m_pEncContext, WELS_LOG_WARNING, "CWelsH264SVCEncoder::Initialize(), reinitialize, m_bInitialFlag= %d.\n",
248+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING,
249+ "CWelsH264SVCEncoder::Initialize(), reinitialize, m_bInitialFlag= %d.\n",
237250 m_bInitialFlag);
238251 Uninitialize();
239252 }
240253
241254 #ifdef REC_FRAME_COUNT
242255 SWelsSvcCodingParam& sEncodingParam = *pCfg;
243− WelsLog (m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::Initialize, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n",
256+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
257+ "CWelsH264SVCEncoder::Initialize, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n",
244258 m_uiCountFrameNum, m_iCspInternal);
245− WelsLog (m_pEncContext, WELS_LOG_INFO,
259+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
246260 "coding_param->iPicWidth= %d;coding_param->iPicHeight= %d;coding_param->iTargetBitrate= %d;coding_param->iRCMode= %d;coding_param->iTemporalLayerNum= %d;coding_param->iSpatialLayerNum= %d;coding_param->fFrameRate= %.6ff;coding_param->iInputCsp= %d;coding_param->uiIntraPeriod= %d;coding_param->bEnableSpsPpsIdAddition = %d;coding_param->bPrefixNalAddingCtrl = %d;coding_param->bEnableDenoise= %d;coding_param->bEnableBackgroundDetection= %d;coding_param->bEnableAdaptiveQuant= %d;coding_param->bEnableFrameSkip= %d;coding_param->bEnableCropPic= %d;coding_param->bEnableLongTermReference= %d;coding_param->iLtrMarkPeriod= %d;\n",
247261 sEncodingParam.iPicWidth,
248262 sEncodingParam.iPicHeight,
@@ -265,7 +279,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 16 unmodified lines
265279 int32_t i = 0;
266280 while (i < sEncodingParam.iSpatialLayerNum) {
267281 SSpatialLayerConfig* spatial_cfg = &sEncodingParam.sSpatialLayers[i];
268− WelsLog (m_pEncContext, WELS_LOG_INFO,
282+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
269283 "coding_param->sSpatialLayers[%d]: .iVideoWidth= %d; .iVideoHeight= %d; .fFrameRate= %.6ff; .iSpatialBitrate= %d; .sSliceCfg.uiSliceMode= %d; .sSliceCfg.sSliceArgument.uiSliceNum= %d; .sSliceCfg.sSliceArgument.uiSliceSizeConstraint= %d;\n",
270284 i, spatial_cfg->iVideoWidth,
271285 spatial_cfg->iVideoHeight,
@@ -281,7 +295,8 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 9 unmodified lines
281295
282296 const int32_t iColorspace = pCfg->iInputCsp;
283297 if (videoFormatI420 != iColorspace) {
284− WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid iInputCsp= %d.\n", iColorspace);
298+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid iInputCsp= %d.\n",
299+ iColorspace);
285300 Uninitialize();
286301 return cmInitParaError;
287302 }
@@ -289,7 +304,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 1 unmodified line
289304 // Check valid parameters
290305 const int32_t iNumOfLayers = pCfg->iSpatialLayerNum;
291306 if (iNumOfLayers < 1 || iNumOfLayers > MAX_DEPENDENCY_LAYER) {
292− WelsLog (m_pEncContext, WELS_LOG_ERROR,
307+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
293308 "CWelsH264SVCEncoder::Initialize(), invalid iSpatialLayerNum= %d, valid at range of [1, %d].\n", iNumOfLayers,
294309 MAX_DEPENDENCY_LAYER);
295310 Uninitialize();
@@ -298,7 +313,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 2 unmodified lines
298313 if (pCfg->iTemporalLayerNum < 1)
299314 pCfg->iTemporalLayerNum = 1;
300315 if (pCfg->iTemporalLayerNum > MAX_TEMPORAL_LEVEL) {
301− WelsLog (m_pEncContext, WELS_LOG_ERROR,
316+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
302317 "CWelsH264SVCEncoder::Initialize(), invalid iTemporalLayerNum= %d, valid at range of [1, %d].\n",
303318 pCfg->iTemporalLayerNum, MAX_TEMPORAL_LEVEL);
304319 Uninitialize();
@@ -308,7 +323,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 3 unmodified lines
308323 // assert( cfg.uiGopSize >= 1 && ( cfg.uiIntraPeriod && (cfg.uiIntraPeriod % cfg.uiGopSize) == 0) );
309324
310325 if (pCfg->uiGopSize < 1 || pCfg->uiGopSize > MAX_GOP_SIZE) {
311− WelsLog (m_pEncContext, WELS_LOG_ERROR,
326+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
312327 "CWelsH264SVCEncoder::Initialize(), invalid uiGopSize= %d, valid at range of [1, %d].\n", pCfg->uiGopSize,
313328 MAX_GOP_SIZE);
314329 Uninitialize();
@@ -316,7 +331,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 1 unmodified line
316331 }
317332
318333 if (!WELS_POWER2_IF (pCfg->uiGopSize)) {
319− WelsLog (m_pEncContext, WELS_LOG_ERROR,
334+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
320335 "CWelsH264SVCEncoder::Initialize(), invalid uiGopSize= %d, valid at range of [1, %d] and yield to power of 2.\n",
321336 pCfg->uiGopSize, MAX_GOP_SIZE);
322337 Uninitialize();
@@ -324,7 +339,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 1 unmodified line
324339 }
325340
326341 if (pCfg->uiIntraPeriod && pCfg->uiIntraPeriod < pCfg->uiGopSize) {
327− WelsLog (m_pEncContext, WELS_LOG_ERROR,
342+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
328343 "CWelsH264SVCEncoder::Initialize(), invalid uiIntraPeriod= %d, valid in case it equals to 0 for unlimited intra period or exceeds specified uiGopSize= %d.\n",
329344 pCfg->uiIntraPeriod, pCfg->uiGopSize);
330345 Uninitialize();
@@ -332,7 +347,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 1 unmodified line
332347 }
333348
334349 if ((pCfg->uiIntraPeriod && (pCfg->uiIntraPeriod & (pCfg->uiGopSize - 1)) != 0)) {
335− WelsLog (m_pEncContext, WELS_LOG_ERROR,
350+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
336351 "CWelsH264SVCEncoder::Initialize(), invalid uiIntraPeriod= %d, valid in case it equals to 0 for unlimited intra period or exceeds specified uiGopSize= %d also multiple of it.\n",
337352 pCfg->uiIntraPeriod, pCfg->uiGopSize);
338353 Uninitialize();
@@ -371,8 +386,8 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) { · 32 unmodified lines
371386 m_iMaxPicWidth = pCfg->iPicWidth;
372387 m_iMaxPicHeight = pCfg->iPicHeight;
373388
374− if (WelsInitEncoderExt (&m_pEncContext, pCfg)) {
375− WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), WelsInitEncoderExt failed.\n");
389+ if (WelsInitEncoderExt (&m_pEncContext, pCfg, &m_pWelsTrace->m_sLogCtx)) {
390+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), WelsInitEncoderExt failed.\n");
376391 Uninitialize();
377392 return cmInitParaError;
378393 }
@@ -391,10 +406,10 @@ int32_t CWelsH264SVCEncoder::Uninitialize() { · 12 unmodified lines
391406 return 0;
392407 }
393408
394− WelsLog (m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::Uninitialize()..\n");
409+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsH264SVCEncoder::Uninitialize()..\n");
395410
396411 #ifdef REC_FRAME_COUNT
397− WelsLog (m_pEncContext, WELS_LOG_INFO,
412+ WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
398413 "CWelsH264SVCEncoder::Uninitialize, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal);
399414 #endif//REC_FRAME_COUNT
400415
@@ -548,7 +563,8 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) { · 147 unmodified lines
548563 return cmInitParaError;
549564 }
550565
551− if (NULL == m_pEncContext || false == m_bInitialFlag) {
566+ if ((NULL == m_pEncContext || false == m_bInitialFlag) && eOptionId != ENCODER_OPTION_TRACE_LEVEL
567+ && eOptionId != ENCODER_OPTION_TRACE_CALLBACK && eOptionId != ENCODER_OPTION_TRACE_CALLBACK_CONTEXT) {
552568 return cmInitExpected;
553569 }
554570
@@ -734,7 +750,7 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) { · 179 unmodified lines
734750 break;
735751 }
736752 //adjust to valid range
737− WelsEncoderApplyBitRate (m_pEncContext->pSvcParam, pInfo->iLayer);
753+ WelsEncoderApplyBitRate (&m_pWelsTrace->m_sLogCtx, m_pEncContext->pSvcParam, pInfo->iLayer);
738754 }
739755 break;
740756 case ENCODER_OPTION_MAX_BITRATE: { // Target bit-rate
@@ -775,7 +791,7 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) { · 34 unmodified lines
775791 break;
776792 }
777793 //adjust to valid range
778− WelsEncoderApplyBitRate (m_pEncContext->pSvcParam, pInfo->iLayer);
794+ WelsEncoderApplyBitRate (&m_pWelsTrace->m_sLogCtx, m_pEncContext->pSvcParam, pInfo->iLayer);
779795 }
780796 break;
781797 case ENCODER_OPTION_RC_MODE: { // 0:quality mode;1:bit-rate mode;2:bitrate limited mode
@@ -856,6 +872,20 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) { · 74 unmodified lines
856872 }
857873 }
858874 break;
875+ case ENCODER_OPTION_TRACE_CALLBACK: {
876+ if (m_pWelsTrace) {
877+ CM_WELS_TRACE callback = * ((CM_WELS_TRACE*)pOption);
878+ m_pWelsTrace->SetTraceCallback (callback);
879+ }
880+ }
881+ break;
882+ case ENCODER_OPTION_TRACE_CALLBACK_CONTEXT: {
883+ if (m_pWelsTrace) {
884+ void* ctx = * ((void**)pOption);
885+ m_pWelsTrace->SetTraceCallbackContext (ctx);
886+ }
887+ }
888+ break;
859889 default:
860890 return cmInitParaError;
861891 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t