Merge pull request #945 from mstorsjo/log-callback

Don't use a global trace level, allow user-specified trace callbacks
This commit is contained in:
ruil2 2014-06-11 13:25:48 +08:00
commit 84c1f3a4ee
27 changed files with 216 additions and 316 deletions

View File

@ -93,7 +93,9 @@ typedef enum {
ENCODER_OPTION_CURRENT_PATH,
ENCODER_OPTION_DUMP_FILE,
ENCODER_OPTION_TRACE_LEVEL
ENCODER_OPTION_TRACE_LEVEL,
ENCODER_OPTION_TRACE_CALLBACK, // a void (*)(void* context, int level, const char* message) function which receives log messages
ENCODER_OPTION_TRACE_CALLBACK_CONTEXT,
} ENCODER_OPTION;
/* Option types introduced in decoder application */
@ -107,6 +109,9 @@ typedef enum {
DECODER_OPTION_LTR_MARKING_FLAG, // feedback wether current frame mark a LTR
DECODER_OPTION_LTR_MARKED_FRAME_NUM, // feedback frame num marked by current Frame
DECODER_OPTION_ERROR_CON_IDC, //not finished yet, indicate decoder error concealment status, in progress
DECODER_OPTION_TRACE_LEVEL,
DECODER_OPTION_TRACE_CALLBACK, // a void (*)(void* context, int level, const char* message) function which receives log messages
DECODER_OPTION_TRACE_CALLBACK_CONTEXT,
} DECODER_OPTION;

View File

@ -26,7 +26,6 @@ LOCAL_SRC_FILES := \
$(CONSOLE_DEC_PATH)/src/h264dec.cpp \
$(CONSOLE_DEC_PATH)/src/read_config.cpp \
$(CONSOLE_DEC_PATH)/src/d3d9_utils.cpp \
$(CODEC_PATH)/common/src/logging.cpp \
myjni.cpp
#
# Header Includes

View File

@ -25,7 +25,6 @@ CONSOLE_ENC_PATH := ../../../../console/enc
LOCAL_SRC_FILES := \
$(CONSOLE_ENC_PATH)/src/welsenc.cpp \
$(CONSOLE_ENC_PATH)/src/read_config.cpp \
$(CODEC_PATH)/common/src/logging.cpp \
myjni.cpp
#

View File

@ -14,7 +14,6 @@
4C3406CD18D96EA600DFA14A /* cpu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C3406C418D96EA600DFA14A /* cpu.cpp */; };
4C3406CE18D96EA600DFA14A /* crt_util_safe_x.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C3406C518D96EA600DFA14A /* crt_util_safe_x.cpp */; };
4C3406CF18D96EA600DFA14A /* deblocking_common.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C3406C618D96EA600DFA14A /* deblocking_common.cpp */; };
4C3406D018D96EA600DFA14A /* logging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C3406C718D96EA600DFA14A /* logging.cpp */; };
4C3406D118D96EA600DFA14A /* WelsThreadLib.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C3406C818D96EA600DFA14A /* WelsThreadLib.cpp */; };
4CC61F0918FF6B4B00E56EAB /* copy_mb_neon.S in Sources */ = {isa = PBXBuildFile; fileRef = 4CC61F0818FF6B4B00E56EAB /* copy_mb_neon.S */; };
4CE443D918B722CD0017DF25 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CE443D818B722CD0017DF25 /* Foundation.framework */; };
@ -47,7 +46,6 @@
4C3406B818D96EA600DFA14A /* cpu_core.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cpu_core.h; sourceTree = "<group>"; };
4C3406B918D96EA600DFA14A /* crt_util_safe_x.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = crt_util_safe_x.h; sourceTree = "<group>"; };
4C3406BA18D96EA600DFA14A /* deblocking_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = deblocking_common.h; sourceTree = "<group>"; };
4C3406BC18D96EA600DFA14A /* logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = logging.h; sourceTree = "<group>"; };
4C3406BD18D96EA600DFA14A /* ls_defines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ls_defines.h; sourceTree = "<group>"; };
4C3406BE18D96EA600DFA14A /* macros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = macros.h; sourceTree = "<group>"; };
4C3406BF18D96EA600DFA14A /* mc_common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mc_common.h; sourceTree = "<group>"; };
@ -57,7 +55,6 @@
4C3406C418D96EA600DFA14A /* cpu.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cpu.cpp; sourceTree = "<group>"; };
4C3406C518D96EA600DFA14A /* crt_util_safe_x.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = crt_util_safe_x.cpp; sourceTree = "<group>"; };
4C3406C618D96EA600DFA14A /* deblocking_common.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = deblocking_common.cpp; sourceTree = "<group>"; };
4C3406C718D96EA600DFA14A /* logging.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = logging.cpp; sourceTree = "<group>"; };
4C3406C818D96EA600DFA14A /* WelsThreadLib.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WelsThreadLib.cpp; sourceTree = "<group>"; };
4CC61F0818FF6B4B00E56EAB /* copy_mb_neon.S */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = copy_mb_neon.S; sourceTree = "<group>"; };
4CE443D518B722CD0017DF25 /* libcommon.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libcommon.a; sourceTree = BUILT_PRODUCTS_DIR; };
@ -108,7 +105,6 @@
4C3406B918D96EA600DFA14A /* crt_util_safe_x.h */,
53C1C9BA193F0F9E00404D8F /* expand_pic.h */,
4C3406BA18D96EA600DFA14A /* deblocking_common.h */,
4C3406BC18D96EA600DFA14A /* logging.h */,
4C3406BD18D96EA600DFA14A /* ls_defines.h */,
4C3406BE18D96EA600DFA14A /* macros.h */,
4C3406BF18D96EA600DFA14A /* mc_common.h */,
@ -128,7 +124,6 @@
4C3406C518D96EA600DFA14A /* crt_util_safe_x.cpp */,
53C1C9BB193F0FB000404D8F /* expand_pic.cpp */,
4C3406C618D96EA600DFA14A /* deblocking_common.cpp */,
4C3406C718D96EA600DFA14A /* logging.cpp */,
4C3406C818D96EA600DFA14A /* WelsThreadLib.cpp */,
);
path = src;
@ -238,7 +233,6 @@
F556A8241906673900E156A8 /* arm_arch64_common_macro.S in Sources */,
4C3406CE18D96EA600DFA14A /* crt_util_safe_x.cpp in Sources */,
4C3406CF18D96EA600DFA14A /* deblocking_common.cpp in Sources */,
4C3406D018D96EA600DFA14A /* logging.cpp in Sources */,
4C3406D118D96EA600DFA14A /* WelsThreadLib.cpp in Sources */,
4C3406CC18D96EA600DFA14A /* mc_neon.S in Sources */,
4C3406CB18D96EA600DFA14A /* expand_picture_neon.S in Sources */,

View File

@ -902,10 +902,6 @@
RelativePath="..\..\..\decoder\core\src\get_intra_predictor.cpp"
>
</File>
<File
RelativePath="..\..\..\common\src\logging.cpp"
>
</File>
<File
RelativePath="..\..\..\decoder\core\src\manage_dec_ref.cpp"
>

View File

@ -394,10 +394,6 @@
RelativePath="..\..\..\console\dec\src\h264dec.cpp"
>
</File>
<File
RelativePath="..\..\..\common\src\logging.cpp"
>
</File>
<File
RelativePath="..\..\..\console\dec\src\read_config.cpp"
>

View File

@ -395,10 +395,6 @@
RelativePath="..\..\..\encoder\core\src\get_intra_predictor.cpp"
>
</File>
<File
RelativePath="..\..\..\common\src\logging.cpp"
>
</File>
<File
RelativePath="..\..\..\encoder\core\src\mc.cpp"
>

View File

@ -394,10 +394,6 @@
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
>
<File
RelativePath="..\..\..\common\src\logging.cpp"
>
</File>
<File
RelativePath="..\..\..\console\enc\src\read_config.cpp"
>

View File

@ -1,54 +0,0 @@
/*!
* \copy
* Copyright (c) 2013, Cisco Systems
* Copyright (c) 2013, Mozilla
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef WELS_LOGGING_H__
#define WELS_LOGGING_H__
// API surface.
void WelsStderrSetTraceLevel (int32_t level);
// Internal details.
int32_t welsStderrLevelTrace (int32_t level, const char* format, va_list ap);
template<int level> int32_t welsStderrTrace (
const char* format, ...) {
va_list ap;
va_start (ap, format);
welsStderrLevelTrace (level, format, ap);
va_end (ap);
return 0;
}
#endif

View File

@ -47,7 +47,6 @@
* Log output routines
*/
typedef int32_t iWelsLogLevel;
enum {
WELS_LOG_QUIET = 0x00, // Quiet mode
WELS_LOG_ERROR = 1 << 0, // Error log iLevel
@ -56,7 +55,7 @@ enum {
WELS_LOG_DEBUG = 1 << 3, // Debug log iLevel
WELS_LOG_RESV = 1 << 4, // Resversed log iLevel
WELS_LOG_LEVEL_COUNT = 5,
WELS_LOG_DEFAULT = WELS_LOG_ERROR | WELS_LOG_WARNING | WELS_LOG_INFO | WELS_LOG_DEBUG // Default log iLevel in Wels codec
WELS_LOG_DEFAULT = WELS_LOG_DEBUG // Default log iLevel in Wels codec
};
/*
@ -65,14 +64,10 @@ enum {
// wels log output
typedef void (*PWelsLogCallbackFunc) (void* pCtx, const int32_t iLevel, const char* kpFmt, va_list argv);
// wels psnr calc
typedef float (*PWelsPsnrFunc) (const void* kpTarPic,
const int32_t kiTarStride,
const void* kpRefPic,
const int32_t kiRefStride,
const int32_t kiWidth,
const int32_t kiHeight);
typedef struct TagLogContext {
PWelsLogCallbackFunc pfLog;
void* pLogCtx;
} SLogContext;
#ifdef __GNUC__
@ -82,19 +77,6 @@ extern void WelsLog (void* pCtx, int32_t iLevel, const char* kpFmt, ...) __attri
extern void WelsLog (void* pCtx, int32_t iLevel, const char* kpFmt, ...);
#endif
/*!
*************************************************************************************
* \brief set log callback from external call
*
* \param _log log function routine
*
* \return NONE
*
* \note N/A
*************************************************************************************
*/
void WelsSetLogCallback (PWelsLogCallbackFunc _log);
/*
* PSNR calculation routines
*/

View File

@ -35,26 +35,29 @@
#include <stdarg.h>
#include "typedefs.h"
#include "utils.h"
typedef int32_t (*CM_WELS_TRACE) (const char* format, ...);
typedef void (*CM_WELS_TRACE) (void* ctx, int level, const char* string);
class welsCodecTrace {
public:
welsCodecTrace();
~welsCodecTrace();
static void TraceString (int32_t iLevel, const char* kpStrFormat);
static void CODEC_TRACE (void* pIgnore, const int32_t kiLevel, const char* kpStrFormat, va_list vl);
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);
void CodecTrace (const int32_t kiLevel, const char* kpStrFormat, va_list vl);
int32_t m_iTraceLevel;
CM_WELS_TRACE m_fpTrace;
void* m_pTraceCtx;
public:
static int32_t m_iTraceLevel;
static CM_WELS_TRACE m_fpDebugTrace;
static CM_WELS_TRACE m_fpInfoTrace;
static CM_WELS_TRACE m_fpWarnTrace;
static CM_WELS_TRACE m_fpErrorTrace;
SLogContext m_sLogCtx;
};
#endif //WELS_CODEC_TRACE

View File

@ -1,49 +0,0 @@
/*!
* \copy
* Copyright (c) 2013, Cisco Systems
* Copyright (c) 2013, Mozilla
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <stdarg.h>
#include <stdio.h>
#include "typedefs.h"
static int32_t g_TraceLevel = 0;
void WelsStderrSetTraceLevel (int32_t level) {
g_TraceLevel = level;
}
int32_t welsStderrLevelTrace (int32_t level, const char* format, va_list ap) {
if (level < g_TraceLevel) {
vfprintf (stderr, format, ap);
}
return 0;
}

View File

@ -48,27 +48,11 @@ float WelsCalcPsnr (const void* kpTarPic,
const int32_t kiHeight);
static PWelsLogCallbackFunc wlog;
/*!
*************************************************************************************
* \brief set log callback from external call
*
* \param _log log function routine
*
* \return NONE
*
* \note N/A
*************************************************************************************
*/
void WelsSetLogCallback (PWelsLogCallbackFunc _log) {
wlog = _log;
}
void WelsLog (void* pCtx, int32_t iLevel, const char* kpFmt, ...) {
SLogContext* logCtx = (SLogContext*) pCtx;
va_list vl;
va_start (vl, kpFmt);
wlog (pCtx, iLevel, kpFmt, vl);
logCtx->pfLog (logCtx->pLogCtx, iLevel, kpFmt, vl);
va_end (vl);
}

View File

@ -44,57 +44,34 @@
#include "welsCodecTrace.h"
#include "utils.h"
#include "logging.h"
int32_t welsCodecTrace::m_iTraceLevel = WELS_LOG_DEFAULT;
CM_WELS_TRACE welsCodecTrace::m_fpDebugTrace = NULL;
CM_WELS_TRACE welsCodecTrace::m_fpInfoTrace = NULL;
CM_WELS_TRACE welsCodecTrace::m_fpWarnTrace = NULL;
CM_WELS_TRACE welsCodecTrace::m_fpErrorTrace = NULL;
static void welsStderrTrace (void* ctx, int level, const char* string) {
fprintf (stderr, "%s", string);
}
welsCodecTrace::welsCodecTrace() {
m_fpDebugTrace = welsStderrTrace<WELS_LOG_DEBUG>;
m_fpInfoTrace = welsStderrTrace<WELS_LOG_INFO>;
m_fpWarnTrace = welsStderrTrace<WELS_LOG_WARNING>;
m_fpErrorTrace = welsStderrTrace<WELS_LOG_ERROR>;
m_iTraceLevel = WELS_LOG_DEFAULT;
m_fpTrace = welsStderrTrace;
m_pTraceCtx = NULL;
m_sLogCtx.pLogCtx = this;
m_sLogCtx.pfLog = StaticCodecTrace;
}
welsCodecTrace::~welsCodecTrace() {
m_fpDebugTrace = NULL;
m_fpInfoTrace = NULL;
m_fpWarnTrace = NULL;
m_fpErrorTrace = NULL;
}
void welsCodecTrace::TraceString (int32_t iLevel, const char* str) {
switch (iLevel) {
case WELS_LOG_ERROR:
if (m_fpErrorTrace)
m_fpErrorTrace ("%s", str);
break;
case WELS_LOG_WARNING:
if (m_fpWarnTrace)
m_fpWarnTrace ("%s", str);
break;
case WELS_LOG_INFO:
if (m_fpInfoTrace)
m_fpInfoTrace ("%s", str);
break;
case WELS_LOG_DEBUG:
if (m_fpDebugTrace)
m_fpDebugTrace ("%s", str);
break;
default:
if (m_fpDebugTrace)
m_fpInfoTrace ("%s", str);
break;
}
m_fpTrace = NULL;
}
#define MAX_LOG_SIZE 1024
void welsCodecTrace::CODEC_TRACE (void* ignore, const int32_t iLevel, const char* Str_Format, va_list vl) {
void welsCodecTrace::StaticCodecTrace (void* pCtx, const int32_t iLevel, const char* Str_Format, va_list vl) {
welsCodecTrace* self = (welsCodecTrace*) pCtx;
self->CodecTrace (iLevel, Str_Format, vl);
}
void welsCodecTrace::CodecTrace (const int32_t iLevel, const char* Str_Format, va_list vl) {
if (m_iTraceLevel < iLevel) {
return;
}
@ -102,13 +79,19 @@ void welsCodecTrace::CODEC_TRACE (void* ignore, const int32_t iLevel, const char
char pBuf[MAX_LOG_SIZE] = {0};
WelsVsnprintf (pBuf, MAX_LOG_SIZE, Str_Format, vl); // confirmed_safe_unsafe_usage
welsCodecTrace::TraceString (iLevel, pBuf);
m_fpTrace (m_pTraceCtx, iLevel, pBuf);
}
void welsCodecTrace::SetTraceLevel (const int32_t iLevel) {
if (iLevel >= 0)
m_iTraceLevel = iLevel;
WelsStderrSetTraceLevel (iLevel);
}
void welsCodecTrace::SetTraceCallback (CM_WELS_TRACE func) {
m_fpTrace = func;
}
void welsCodecTrace::SetTraceCallbackContext (void* ctx) {
m_pTraceCtx = ctx;
}

View File

@ -5,7 +5,6 @@ COMMON_CPP_SRCS=\
$(COMMON_SRCDIR)/src/crt_util_safe_x.cpp\
$(COMMON_SRCDIR)/src/deblocking_common.cpp\
$(COMMON_SRCDIR)/src/expand_pic.cpp\
$(COMMON_SRCDIR)/src/logging.cpp\
$(COMMON_SRCDIR)/src/sad_common.cpp\
$(COMMON_SRCDIR)/src/utils.cpp\
$(COMMON_SRCDIR)/src/welsCodecTrace.cpp\

View File

@ -51,7 +51,6 @@
#include "typedefs.h"
#include "measure_time.h"
#include "d3d9_utils.h"
#include "logging.h"
using namespace std;
@ -311,6 +310,7 @@ int32_t main (int32_t iArgC, char* pArgV[]) {
SDecodingParam sDecParam = {0};
string strInputFile (""), strOutputFile (""), strOptionFile ("");
int iLevelSetting = -1;
sDecParam.sVideoProperty.size = sizeof (sDecParam.sVideoProperty);
@ -384,14 +384,14 @@ int32_t main (int32_t iArgC, char* pArgV[]) {
if (!strcmp (cmd, "-options")) {
if (i + 1 < iArgC)
strOptionFile = pArgV[i++];
strOptionFile = pArgV[++i];
else {
printf ("options file not specified.\n");
return 1;
}
} else if (!strcmp (cmd, "-trace")) {
if (i + 1 < iArgC)
WelsStderrSetTraceLevel (atoi (pArgV[i++]));
iLevelSetting = atoi (pArgV[++i]);
else {
printf ("trace level not specified.\n");
return 1;
@ -418,6 +418,9 @@ int32_t main (int32_t iArgC, char* pArgV[]) {
printf ("Create Decoder failed.\n");
return 1;
}
if (iLevelSetting >= 0) {
pDecoder->SetOption (DECODER_OPTION_TRACE_LEVEL, &iLevelSetting);
}
if (pDecoder->Initialize (&sDecParam)) {
printf ("Decoder initialization failed.\n");

View File

@ -67,7 +67,6 @@
#include "extern.h"
#include "macros.h"
#include "wels_const.h"
#include "logging.h"
#include "mt_defs.h"
#include "WelsThreadLib.h"
@ -102,7 +101,7 @@ static int g_iCtrlC = 0;
static void SigIntHandler (int a) {
g_iCtrlC = 1;
}
static int g_LevelSetting = 0;
static int g_LevelSetting = -1;
int ParseLayerConfig (CReadConfig& cRdLayerCfg, const int iLayer, SEncParamExt& pSvcParam, SFilesSet& sFileSet) {
if (!cRdLayerCfg.ExistFile()) {
@ -665,6 +664,9 @@ int ProcessEncoding(ISVCEncoder* pPtrEnc, int argc, char** argv,bool bConfigFile
iRet = 1;
goto INSIDE_MEM_FREE;
}
if (g_LevelSetting >= 0) {
pPtrEnc->SetOption (ENCODER_OPTION_TRACE_LEVEL, &g_LevelSetting);
}
//finish reading the configurations
iSourceWidth = pSrcPic->iPicWidth;
iSourceHeight = pSrcPic->iPicHeight;

View File

@ -68,7 +68,7 @@ int32_t DecoderConfigParam (PWelsDecoderContext pCtx, const SDecodingParam* kpPa
* \note N/A
*************************************************************************************
*/
int32_t WelsInitDecoder (PWelsDecoderContext pCtx);
int32_t WelsInitDecoder (PWelsDecoderContext pCtx, SLogContext* pLogCtx);
/*!
*************************************************************************************

View File

@ -164,6 +164,7 @@ enum {
*/
typedef struct TagWelsDecoderContext {
SLogContext sLogCtx;
// Input
void* pArgDec; // structured arguments for decoder, reserved here for extension in the future

View File

@ -127,9 +127,10 @@ static void DestroyPicBuff (PPicBuff* ppPicBuf) {
/*
* fill data fields in default for decoder context
*/
void WelsDecoderDefaults (PWelsDecoderContext pCtx) {
void WelsDecoderDefaults (PWelsDecoderContext pCtx, SLogContext* pLogCtx) {
int32_t iCpuCores = 1;
memset (pCtx, 0, sizeof (SWelsDecoderContext)); // fill zero first
pCtx->sLogCtx = *pLogCtx;
pCtx->pArgDec = NULL;
@ -350,13 +351,13 @@ int32_t DecoderConfigParam (PWelsDecoderContext pCtx, const SDecodingParam* kpPa
* \note N/A
*************************************************************************************
*/
int32_t WelsInitDecoder (PWelsDecoderContext pCtx) {
int32_t WelsInitDecoder (PWelsDecoderContext pCtx, SLogContext* pLogCtx) {
if (pCtx == NULL) {
return ERR_INFO_INVALID_PTR;
}
// default
WelsDecoderDefaults (pCtx);
WelsDecoderDefaults (pCtx, pLogCtx);
// open decoder
WelsOpenDecoder (pCtx);

View File

@ -103,10 +103,9 @@ CWelsDecoder::CWelsDecoder (void)
m_pWelsTrace = new welsCodecTrace();
if (m_pWelsTrace != NULL) {
m_pWelsTrace->SetTraceLevel (WELS_LOG_ERROR);
WelsSetLogCallback (welsCodecTrace::CODEC_TRACE);
}
WelsLog (NULL, WELS_LOG_INFO, "CWelsDecoder::CWelsDecoder() entry");
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::CWelsDecoder() entry");
}
#ifdef OUTPUT_BIT_STREAM
SWelsTime sCurTime;
@ -161,7 +160,9 @@ CWelsDecoder::CWelsDecoder (void)
* return: none
***************************************************************************/
CWelsDecoder::~CWelsDecoder() {
WelsLog (NULL, WELS_LOG_INFO, "CWelsDecoder::~CWelsDecoder()");
if (m_pWelsTrace != NULL) {
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::~CWelsDecoder()");
}
UninitDecoder();
@ -183,8 +184,12 @@ CWelsDecoder::~CWelsDecoder() {
}
long CWelsDecoder::Initialize (const SDecodingParam* pParam) {
if (m_pWelsTrace == NULL) {
return cmMallocMemeError;
}
if (pParam == NULL) {
WelsLog (NULL, WELS_LOG_INFO, "CWelsDecoder::Initialize(), invalid input argument.");
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::Initialize(), invalid input argument.");
return cmInitParaError;
}
@ -206,7 +211,7 @@ void CWelsDecoder::UninitDecoder (void) {
if (NULL == m_pDecContext)
return;
WelsLog (NULL, WELS_LOG_INFO, "into CWelsDecoder::uninit_decoder()..");
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "into CWelsDecoder::uninit_decoder()..");
WelsEndDecoder (m_pDecContext);
@ -216,19 +221,19 @@ void CWelsDecoder::UninitDecoder (void) {
m_pDecContext = NULL;
}
WelsLog (NULL , WELS_LOG_INFO, "left CWelsDecoder::uninit_decoder()..");
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "left CWelsDecoder::uninit_decoder()..");
}
// the return value of this function is not suitable, it need report failure info to upper layer.
void CWelsDecoder::InitDecoder (void) {
WelsLog (NULL, WELS_LOG_INFO, "CWelsDecoder::init_decoder()..");
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::init_decoder()..");
m_pDecContext = (PWelsDecoderContext)WelsMalloc (sizeof (SWelsDecoderContext), "m_pDecContext");
WelsInitDecoder (m_pDecContext);
WelsInitDecoder (m_pDecContext, &m_pWelsTrace->m_sLogCtx);
WelsLog (NULL, WELS_LOG_INFO, "CWelsDecoder::init_decoder().. left");
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsDecoder::init_decoder().. left");
}
/*
@ -237,7 +242,8 @@ void CWelsDecoder::InitDecoder (void) {
long CWelsDecoder::SetOption (DECODER_OPTION eOptID, void* pOption) {
int iVal = 0;
if (m_pDecContext == NULL)
if (m_pDecContext == NULL && eOptID != DECODER_OPTION_TRACE_LEVEL &&
eOptID != DECODER_OPTION_TRACE_CALLBACK && eOptID != DECODER_OPTION_TRACE_CALLBACK_CONTEXT)
return dsInitialOptExpected;
if (eOptID == DECODER_OPTION_DATAFORMAT) { // Set color space of decoding output frame
@ -263,6 +269,24 @@ long CWelsDecoder::SetOption (DECODER_OPTION eOptID, void* pOption) {
iVal = * ((int*)pOption); //EC method
m_pDecContext->iErrorConMethod = iVal;
return cmResultSuccess;
} else if (eOptID == DECODER_OPTION_TRACE_LEVEL) {
if (m_pWelsTrace) {
uint32_t level = * ((uint32_t*)pOption);
m_pWelsTrace->SetTraceLevel (level);
}
return cmResultSuccess;
} else if (eOptID == DECODER_OPTION_TRACE_CALLBACK) {
if (m_pWelsTrace) {
CM_WELS_TRACE callback = * ((CM_WELS_TRACE*)pOption);
m_pWelsTrace->SetTraceCallback (callback);
}
return cmResultSuccess;
} else if (eOptID == DECODER_OPTION_TRACE_CALLBACK_CONTEXT) {
if (m_pWelsTrace) {
void* ctx = * ((void**)pOption);
m_pWelsTrace->SetTraceCallbackContext (ctx);
}
return cmResultSuccess;
}
return cmInitParaError;
@ -386,7 +410,7 @@ DECODING_STATE CWelsDecoder::DecodeFrame2 (const unsigned char* kpSrc,
}
}
WelsLog (NULL, WELS_LOG_INFO, "decode failed, failure type:%d \n",
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "decode failed, failure type:%d \n",
m_pDecContext->iErrorCode);
return (DECODING_STATE)m_pDecContext->iErrorCode;
}

View File

@ -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 @@ typedef struct TagStrideTables {
} 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]

View File

@ -64,7 +64,7 @@ int32_t InitPic (const void* kpSrc, const int32_t kiCsp, const int32_t kiWidth,
* \pParam pParam SWelsSvcCodingParam*
* \return successful - 0; otherwise none 0 for failed
*/
int32_t ParamValidationExt (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pParam);
int32_t ParamValidationExt (SLogContext* pCtx, SWelsSvcCodingParam* pParam);
// GOM based RC related for uiSliceNum decision
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*
* \param para SWelsSvcCodingParam*
* \return successful - 0; otherwise none 0 for failed
*/
int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pPara);
int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pPara, SLogContext* pLogCtx);
/*!
* \brief uninitialize Wels encoder core library
@ -107,7 +107,7 @@ int32_t ForceCodingIDR (sWelsEncCtx* pCtx);
*/
int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNew);
void WelsEncoderApplyFrameRate (SWelsSvcCodingParam* pParam);
void WelsEncoderApplyBitRate (SWelsSvcCodingParam* pParam, int32_t iLayer);
void WelsEncoderApplyBitRate (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int32_t iLayer);
int32_t FilterLTRRecoveryRequest (sWelsEncCtx* pCtx, SLTRRecoverRequest* pLTRRecoverRequest);

View File

@ -81,8 +81,8 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg);
int32_t CreateSliceThreads (sWelsEncCtx* pCtx);
int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList, WELS_EVENT* pMasterEventsList,
SLayerBSInfo* pLayerBsInfo,
int32_t FiredSliceThreads (sWelsEncCtx* pCtx, SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList,
WELS_EVENT* pMasterEventsList, SLayerBSInfo* pLayerBsInfo,
const uint32_t kuiNumThreads/*, int32_t *iLayerNum*/, SSliceCtx* pSliceCtx, const bool kbIsDynamicSlicingMode);
int32_t DynamicDetectCpuCores();

View File

@ -73,7 +73,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx,
* \pParam pParam SWelsSvcCodingParam*
* \return successful - 0; otherwise none 0 for failed
*/
int32_t ParamValidation (SWelsSvcCodingParam* pCfg) {
int32_t ParamValidation (SLogContext* pLogCtx, SWelsSvcCodingParam* pCfg) {
float fMaxFrameRate = 0.0f;
const float fEpsn = 0.000001f;
int32_t i = 0;
@ -81,7 +81,7 @@ int32_t ParamValidation (SWelsSvcCodingParam* pCfg) {
assert (pCfg != NULL);
if ((pCfg->iUsageType != CAMERA_VIDEO_REAL_TIME) && (pCfg->iUsageType != SCREEN_CONTENT_REAL_TIME)) {
WelsLog (NULL, WELS_LOG_ERROR, "ParamValidation(),Invalid usage type = %d\n", pCfg->iUsageType);
WelsLog (pLogCtx, WELS_LOG_ERROR, "ParamValidation(),Invalid usage type = %d\n", pCfg->iUsageType);
return ENC_RETURN_UNSUPPORTED_PARA;
}
for (i = 0; i < pCfg->iSpatialLayerNum; ++ i) {
@ -89,13 +89,13 @@ int32_t ParamValidation (SWelsSvcCodingParam* pCfg) {
if (fDlp->fOutputFrameRate > fDlp->fInputFrameRate || (fDlp->fInputFrameRate >= -fEpsn
&& fDlp->fInputFrameRate <= fEpsn)
|| (fDlp->fOutputFrameRate >= -fEpsn && fDlp->fOutputFrameRate <= fEpsn)) {
WelsLog (NULL, WELS_LOG_ERROR,
WelsLog (pLogCtx, WELS_LOG_ERROR,
"Invalid settings in input frame rate(%.6f) or output frame rate(%.6f) of layer #%d config file..\n",
fDlp->fInputFrameRate, fDlp->fOutputFrameRate, i);
return ENC_RETURN_INVALIDINPUT;
}
if (UINT_MAX == GetLogFactor (fDlp->fOutputFrameRate, fDlp->fInputFrameRate)) {
WelsLog (NULL, WELS_LOG_ERROR,
WelsLog (pLogCtx, WELS_LOG_ERROR,
"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",
fDlp->fInputFrameRate, fDlp->fOutputFrameRate, i);
return ENC_RETURN_INVALIDINPUT;
@ -121,7 +121,7 @@ int32_t ParamValidation (SWelsSvcCodingParam* pCfg) {
iTotalBitrate += fDlp->iSpatialBitrate;
}
if (iTotalBitrate > pCfg->iTargetBitrate) {
WelsLog (NULL, WELS_LOG_ERROR,
WelsLog (pLogCtx, WELS_LOG_ERROR,
"Invalid settings in bitrate. the sum of each layer bitrate(%d) is larger than total bitrate setting(%d)\n",
iTotalBitrate, pCfg->iTargetBitrate);
}
@ -131,7 +131,7 @@ int32_t ParamValidation (SWelsSvcCodingParam* pCfg) {
}
int32_t ParamValidationExt (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pCodingParam) {
int32_t ParamValidationExt (SLogContext* pCtx, SWelsSvcCodingParam* pCodingParam) {
int8_t i = 0;
int32_t iIdx = 0;
@ -383,7 +383,7 @@ int32_t ParamValidationExt (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pCodingParam
}
}
return ParamValidation (pCodingParam);
return ParamValidation (pCtx, pCodingParam);
}
@ -412,7 +412,7 @@ void WelsEncoderApplyFrameRate (SWelsSvcCodingParam* pParam) {
}
void WelsEncoderApplyBitRate (SWelsSvcCodingParam* pParam, int iLayer) {
void WelsEncoderApplyBitRate (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int iLayer) {
//TODO (Sijia): this is a temporary solution which keep the ratio between layers
//but it is also possible to fulfill the bitrate of lower layer first
@ -421,7 +421,7 @@ void WelsEncoderApplyBitRate (SWelsSvcCodingParam* pParam, int iLayer) {
int32_t i, iOrigTotalBitrate = 0;
if (iLayer == SPATIAL_LAYER_ALL) {
if (pParam->iMaxBitrate < pParam->iTargetBitrate) {
WelsLog (NULL, WELS_LOG_WARNING,
WelsLog (pLogCtx, WELS_LOG_WARNING,
"CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE,overall settting,TargetBitrate = %d,iMaxBitrate = %d\n",
pParam->iTargetBitrate, pParam->iMaxBitrate);
pParam->iMaxBitrate = pParam->iTargetBitrate;
@ -439,7 +439,7 @@ void WelsEncoderApplyBitRate (SWelsSvcCodingParam* pParam, int iLayer) {
}
} else {
if (pParam->sSpatialLayers[iLayer].iMaxSpatialBitrate < pParam->sSpatialLayers[iLayer].iSpatialBitrate) {
WelsLog (NULL, WELS_LOG_WARNING,
WelsLog (pLogCtx, WELS_LOG_WARNING,
"CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE,iLayer = %d,iTargetBitrate = %d,iMaxBitrate = %d\n",
iLayer, pParam->sSpatialLayers[iLayer].iSpatialBitrate, pParam->sSpatialLayers[iLayer].iMaxSpatialBitrate);
pParam->sSpatialLayers[iLayer].iMaxSpatialBitrate = pParam->sSpatialLayers[iLayer].iSpatialBitrate;
@ -1723,7 +1723,7 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) {
#endif//MEMORY_MONITOR
if ((*ppCtx)->pMemAlign != NULL) {
WelsLog (NULL, WELS_LOG_INFO, "FreeMemorySvc(), verify memory usage (%d bytes) after free..\n",
WelsLog (*ppCtx, WELS_LOG_INFO, "FreeMemorySvc(), verify memory usage (%d bytes) after free..\n",
(*ppCtx)->pMemAlign->WelsGetMemoryUsage());
delete (*ppCtx)->pMemAlign;
(*ppCtx)->pMemAlign = NULL;
@ -1734,7 +1734,8 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) {
}
}
int32_t InitSliceSettings (SWelsSvcCodingParam* pCodingParam, const int32_t kiCpuCores, int16_t* pMaxSliceCount) {
int32_t InitSliceSettings (SLogContext* pLogCtx, SWelsSvcCodingParam* pCodingParam, const int32_t kiCpuCores,
int16_t* pMaxSliceCount) {
int32_t iSpatialIdx = 0, iSpatialNum = pCodingParam->iSpatialLayerNum;
uint16_t iMaxSliceCount = 0;
@ -1784,7 +1785,7 @@ int32_t InitSliceSettings (SWelsSvcCodingParam* pCodingParam, const int32_t kiCp
pDlp->sSliceCfg.sSliceArgument.uiSliceNum = iMaxSliceCount;
}
if (pDlp->sSliceCfg.sSliceArgument.uiSliceNum == 1) {
WelsLog (NULL, WELS_LOG_DEBUG,
WelsLog (pLogCtx, WELS_LOG_DEBUG,
"InitSliceSettings(), uiSliceNum(%d) you set for SM_AUTO_SLICE, now turn to SM_SINGLE_SLICE type!\n",
pDlp->sSliceCfg.sSliceArgument.uiSliceNum);
pDlp->sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;
@ -1799,7 +1800,7 @@ int32_t InitSliceSettings (SWelsSvcCodingParam* pCodingParam, const int32_t kiCp
} else if (!CheckFixedSliceNumMultiSliceSetting (kiMbNumInFrame,
&pDlp->sSliceCfg.sSliceArgument)) { // verify interleave mode settings
//check uiSliceMbNum with current uiSliceNum
WelsLog (NULL, WELS_LOG_ERROR,
WelsLog (pLogCtx, WELS_LOG_ERROR,
"InitSliceSettings(), invalid uiSliceMbNum (%d) settings!,now turn to SM_SINGLE_SLICE type\n",
pDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[0]);
pDlp->sSliceCfg.uiSliceMode = SM_SINGLE_SLICE;
@ -1838,9 +1839,10 @@ int32_t InitSliceSettings (SWelsSvcCodingParam* pCodingParam, const int32_t kiCp
/*!
* \brief log output for cpu features/capabilities
*/
void OutputCpuFeaturesLog (uint32_t uiCpuFeatureFlags, uint32_t uiCpuCores, int32_t iCacheLineSize) {
void OutputCpuFeaturesLog (SLogContext* pLogCtx, uint32_t uiCpuFeatureFlags, uint32_t uiCpuCores,
int32_t iCacheLineSize) {
// welstracer output
WelsLog (NULL, WELS_LOG_INFO, "WELS CPU features/capacities (0x%x) detected: \t" \
WelsLog (pLogCtx, WELS_LOG_INFO, "WELS CPU features/capacities (0x%x) detected: \t" \
"HTT: %c, " \
"MMX: %c, " \
"MMXEX: %c, " \
@ -1890,7 +1892,7 @@ void OutputCpuFeaturesLog (uint32_t uiCpuFeatureFlags, uint32_t uiCpuCores, int3
* \pParam pParam SWelsSvcCodingParam*
* \return successful - 0; otherwise none 0 for failed
*/
int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingParam) {
int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingParam, SLogContext* pLogCtx) {
sWelsEncCtx* pCtx = NULL;
int32_t iRet = 0;
uint32_t uiCpuFeatureFlags = 0; // CPU features
@ -1900,14 +1902,14 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar
int16_t iSliceNum = 1; // number of slices used
if (NULL == ppCtx || NULL == pCodingParam) {
WelsLog (NULL, WELS_LOG_ERROR, "WelsInitEncoderExt(), NULL == ppCtx(0x%p) or NULL == pCodingParam(0x%p).\n",
WelsLog (pLogCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), NULL == ppCtx(0x%p) or NULL == pCodingParam(0x%p).\n",
(void*)ppCtx, (void*)pCodingParam);
return 1;
}
iRet = ParamValidationExt (*ppCtx, pCodingParam);
iRet = ParamValidationExt (pLogCtx, pCodingParam);
if (iRet != 0) {
WelsLog (NULL, WELS_LOG_ERROR, "WelsInitEncoderExt(), ParamValidationExt failed return %d.\n", iRet);
WelsLog (pLogCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), ParamValidationExt failed return %d.\n", iRet);
return iRet;
}
@ -1922,7 +1924,7 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar
iCacheLineSize = 32;
else if (uiCpuFeatureFlags & WELS_CPU_CACHELINE_16)
iCacheLineSize = 16;
OutputCpuFeaturesLog (uiCpuFeatureFlags, uiCpuCores, iCacheLineSize);
OutputCpuFeaturesLog (pLogCtx, uiCpuFeatureFlags, uiCpuCores, iCacheLineSize);
#else
iCacheLineSize = 16; // 16 bytes aligned in default
#endif//X86_ASM
@ -1953,8 +1955,8 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar
uiCpuCores = WELS_CLIP3 (uiCpuCores, 1, MAX_THREADS_NUM);
if (InitSliceSettings (pCodingParam, uiCpuCores, &iSliceNum)) {
WelsLog (NULL, WELS_LOG_ERROR, "WelsInitEncoderExt(), InitSliceSettings failed.\n");
if (InitSliceSettings (pLogCtx, pCodingParam, uiCpuCores, &iSliceNum)) {
WelsLog (pLogCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), InitSliceSettings failed.\n");
return 1;
}
@ -1965,6 +1967,8 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar
WELS_VERIFY_RETURN_IF (1, (NULL == pCtx))
memset (pCtx, 0, sizeof (sWelsEncCtx));
pCtx->sLogCtx = *pLogCtx;
pCtx->pMemAlign = new CMemoryAlign (iCacheLineSize);
WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pCtx->pMemAlign), FreeMemorySvc (&pCtx))
@ -3133,7 +3137,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
pCtx->iActiveThreadsNum = iSliceCount;
// to fire slice coding threads
iRet = FiredSliceThreads (&pCtx->pSliceThreading->pThreadPEncCtx[0], &pCtx->pSliceThreading->pReadySliceCodingEvent[0],
iRet = FiredSliceThreads (pCtx, &pCtx->pSliceThreading->pThreadPEncCtx[0],
&pCtx->pSliceThreading->pReadySliceCodingEvent[0],
&pCtx->pSliceThreading->pThreadMasterEvent[0],
pLayerBsInfo, iSliceCount, pCtx->pCurDqLayer->pSliceEncCtx, false);
if (iRet) {
@ -3172,7 +3177,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
iNumThreadsScheduled = pCtx->iActiveThreadsNum;
iNumThreadsRunning = iNumThreadsScheduled;
// to fire slice coding threads
iRet = FiredSliceThreads (&pCtx->pSliceThreading->pThreadPEncCtx[0], &pCtx->pSliceThreading->pReadySliceCodingEvent[0],
iRet = FiredSliceThreads (pCtx, &pCtx->pSliceThreading->pThreadPEncCtx[0],
&pCtx->pSliceThreading->pReadySliceCodingEvent[0],
&pCtx->pSliceThreading->pThreadMasterEvent[0],
pLayerBsInfo, iNumThreadsRunning, pCtx->pCurDqLayer->pSliceEncCtx, false);
if (iRet) {
@ -3218,7 +3224,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour
const int32_t kiPartitionCnt = pCtx->iActiveThreadsNum; //pSvcParam->iCountThreadsNum;
// to fire slice coding threads
iRet = FiredSliceThreads (&pCtx->pSliceThreading->pThreadPEncCtx[0], &pCtx->pSliceThreading->pReadySliceCodingEvent[0],
iRet = FiredSliceThreads (pCtx, &pCtx->pSliceThreading->pThreadPEncCtx[0],
&pCtx->pSliceThreading->pReadySliceCodingEvent[0],
&pCtx->pSliceThreading->pThreadMasterEvent[0],
pLayerBsInfo, kiPartitionCnt, pCtx->pCurDqLayer->pSliceEncCtx, true);
if (iRet) {
@ -3509,7 +3516,7 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa
if (NULL == ppCtx || NULL == *ppCtx || NULL == pNewParam) return 1;
/* Check validation in new parameters */
iReturn = ParamValidationExt (*ppCtx, pNewParam);
iReturn = ParamValidationExt (& (*ppCtx)->sLogCtx, pNewParam);
if (iReturn != ENC_RETURN_SUCCESS) return iReturn;
pOldParam = (*ppCtx)->pSvcParam;
@ -3574,6 +3581,7 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa
if (bNeedReset) {
SParaSetOffsetVariable sTmpPsoVariable[PARA_SET_TYPE];
uint16_t uiTmpIdrPicId;//this is for LTR!
SLogContext sLogCtx = (*ppCtx)->sLogCtx;
memcpy (sTmpPsoVariable, (*ppCtx)->sPSOVector.sParaSetOffsetVariable,
(PARA_SET_TYPE)*sizeof (SParaSetOffsetVariable)); // confirmed_safe_unsafe_usage
uiTmpIdrPicId = (*ppCtx)->sPSOVector.uiIdrPicId;
@ -3581,7 +3589,7 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa
WelsUninitEncoderExt (ppCtx);
/* Update new parameters */
if (WelsInitEncoderExt (ppCtx, pNewParam))
if (WelsInitEncoderExt (ppCtx, pNewParam, &sLogCtx))
return 1;
// reset the scaled spatial picture size

View File

@ -968,15 +968,15 @@ int32_t CreateSliceThreads (sWelsEncCtx* pCtx) {
return 0;
}
int32_t FiredSliceThreads (SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList, WELS_EVENT* pMasterEventsList,
SLayerBSInfo* pLbi,
int32_t FiredSliceThreads (sWelsEncCtx* pCtx, SSliceThreadPrivateData* pPriData, WELS_EVENT* pEventsList,
WELS_EVENT* pMasterEventsList, SLayerBSInfo* pLbi,
const uint32_t uiNumThreads, SSliceCtx* pSliceCtx, const bool bIsDynamicSlicingMode) {
int32_t iEndMbIdx = 0;
int32_t iIdx = 0;
const int32_t kiEventCnt = uiNumThreads;
if (pPriData == NULL || pLbi == NULL || kiEventCnt <= 0 || pEventsList == NULL) {
WelsLog (NULL, WELS_LOG_ERROR,
WelsLog (pCtx, WELS_LOG_ERROR,
"FiredSliceThreads(), fail due pPriData == %p || pLbi == %p || iEventCnt(%d) <= 0 || pEventsList == %p!!\n",
(void*)pPriData, (void*)pLbi, uiNumThreads, (void*)pEventsList);
return 1;

View File

@ -131,17 +131,15 @@ CWelsH264SVCEncoder::CWelsH264SVCEncoder()
}
CWelsH264SVCEncoder::~CWelsH264SVCEncoder() {
WelsLog (NULL, WELS_LOG_INFO, "CWelsH264SVCEncoder::~CWelsH264SVCEncoder()\n");
if (m_pWelsTrace) {
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsH264SVCEncoder::~CWelsH264SVCEncoder()\n");
if (m_pWelsTrace != NULL) {
delete m_pWelsTrace;
m_pWelsTrace = NULL;
}
#ifdef REC_FRAME_COUNT
WelsLog (m_pEncContext, WELS_LOG_INFO,
"CWelsH264SVCEncoder::~CWelsH264SVCEncoder(), m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum,
m_iCspInternal);
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
"CWelsH264SVCEncoder::~CWelsH264SVCEncoder(), m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum,
m_iCspInternal);
#endif
}
#ifdef REC_FRAME_COUNT
m_uiCountFrameNum = 0;
@ -161,20 +159,26 @@ CWelsH264SVCEncoder::~CWelsH264SVCEncoder() {
#endif//OUTPUT_BIT_STREAM
Uninitialize();
if (m_pWelsTrace) {
delete m_pWelsTrace;
m_pWelsTrace = NULL;
}
}
void CWelsH264SVCEncoder::InitEncoder (void) {
m_pWelsTrace = new welsCodecTrace();
if (m_pWelsTrace == NULL) {
return;
}
m_pWelsTrace->SetTraceLevel (WELS_LOG_ERROR);
#ifdef REC_FRAME_COUNT
WelsLog (m_pEncContext, WELS_LOG_INFO,
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
"CWelsH264SVCEncoder::InitEncoder, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal);
#endif
m_pWelsTrace = new welsCodecTrace();
if (m_pWelsTrace != NULL) {
m_pWelsTrace->SetTraceLevel (WELS_LOG_ERROR);
WelsSetLogCallback (welsCodecTrace::CODEC_TRACE);
}
}
/* Interfaces override from ISVCEncoder */
@ -188,9 +192,12 @@ int CWelsH264SVCEncoder::GetDefaultParams (SEncParamExt* argv) {
* SVC Encoder Initialization
*/
int CWelsH264SVCEncoder::Initialize (const SEncParamBase* argv) {
if (m_pWelsTrace == NULL) {
return cmMallocMemeError;
}
if (NULL == argv) {
WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid argv= 0x%p\n",
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid argv= 0x%p\n",
argv);
return cmInitParaError;
}
@ -198,7 +205,8 @@ int CWelsH264SVCEncoder::Initialize (const SEncParamBase* argv) {
SWelsSvcCodingParam sConfig;
// Convert SEncParamBase into WelsSVCParamConfig here..
if (sConfig.ParamBaseTranscode (*argv)) {
WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), parameter_translation failed.\n");
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
"CWelsH264SVCEncoder::Initialize(), parameter_translation failed.\n");
Uninitialize();
return cmInitParaError;
}
@ -207,9 +215,12 @@ int CWelsH264SVCEncoder::Initialize (const SEncParamBase* argv) {
}
int CWelsH264SVCEncoder::InitializeExt (const SEncParamExt* argv) {
if (m_pWelsTrace == NULL) {
return cmMallocMemeError;
}
if (NULL == argv) {
WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::InitializeExt(), invalid argv= 0x%p\n",
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::InitializeExt(), invalid argv= 0x%p\n",
argv);
return cmInitParaError;
}
@ -217,7 +228,8 @@ int CWelsH264SVCEncoder::InitializeExt (const SEncParamExt* argv) {
SWelsSvcCodingParam sConfig;
// Convert SEncParamExt into WelsSVCParamConfig here..
if (sConfig.ParamTranscode (*argv)) {
WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::InitializeExt(), parameter_translation failed.\n");
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
"CWelsH264SVCEncoder::InitializeExt(), parameter_translation failed.\n");
Uninitialize();
return cmInitParaError;
}
@ -227,22 +239,24 @@ int CWelsH264SVCEncoder::InitializeExt (const SEncParamExt* argv) {
int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) {
if (NULL == pCfg) {
WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid argv= 0x%p.\n",
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid argv= 0x%p.\n",
pCfg);
return cmInitParaError;
}
if (m_bInitialFlag) {
WelsLog (m_pEncContext, WELS_LOG_WARNING, "CWelsH264SVCEncoder::Initialize(), reinitialize, m_bInitialFlag= %d.\n",
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_WARNING,
"CWelsH264SVCEncoder::Initialize(), reinitialize, m_bInitialFlag= %d.\n",
m_bInitialFlag);
Uninitialize();
}
#ifdef REC_FRAME_COUNT
SWelsSvcCodingParam& sEncodingParam = *pCfg;
WelsLog (m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::Initialize, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n",
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
"CWelsH264SVCEncoder::Initialize, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n",
m_uiCountFrameNum, m_iCspInternal);
WelsLog (m_pEncContext, WELS_LOG_INFO,
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
"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",
sEncodingParam.iPicWidth,
sEncodingParam.iPicHeight,
@ -265,7 +279,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) {
int32_t i = 0;
while (i < sEncodingParam.iSpatialLayerNum) {
SSpatialLayerConfig* spatial_cfg = &sEncodingParam.sSpatialLayers[i];
WelsLog (m_pEncContext, WELS_LOG_INFO,
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
"coding_param->sSpatialLayers[%d]: .iVideoWidth= %d; .iVideoHeight= %d; .fFrameRate= %.6ff; .iSpatialBitrate= %d; .sSliceCfg.uiSliceMode= %d; .sSliceCfg.sSliceArgument.uiSliceNum= %d; .sSliceCfg.sSliceArgument.uiSliceSizeConstraint= %d;\n",
i, spatial_cfg->iVideoWidth,
spatial_cfg->iVideoHeight,
@ -281,7 +295,8 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) {
const int32_t iColorspace = pCfg->iInputCsp;
if (videoFormatI420 != iColorspace) {
WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid iInputCsp= %d.\n", iColorspace);
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), invalid iInputCsp= %d.\n",
iColorspace);
Uninitialize();
return cmInitParaError;
}
@ -289,7 +304,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) {
// Check valid parameters
const int32_t iNumOfLayers = pCfg->iSpatialLayerNum;
if (iNumOfLayers < 1 || iNumOfLayers > MAX_DEPENDENCY_LAYER) {
WelsLog (m_pEncContext, WELS_LOG_ERROR,
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
"CWelsH264SVCEncoder::Initialize(), invalid iSpatialLayerNum= %d, valid at range of [1, %d].\n", iNumOfLayers,
MAX_DEPENDENCY_LAYER);
Uninitialize();
@ -298,7 +313,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) {
if (pCfg->iTemporalLayerNum < 1)
pCfg->iTemporalLayerNum = 1;
if (pCfg->iTemporalLayerNum > MAX_TEMPORAL_LEVEL) {
WelsLog (m_pEncContext, WELS_LOG_ERROR,
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
"CWelsH264SVCEncoder::Initialize(), invalid iTemporalLayerNum= %d, valid at range of [1, %d].\n",
pCfg->iTemporalLayerNum, MAX_TEMPORAL_LEVEL);
Uninitialize();
@ -308,7 +323,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) {
// assert( cfg.uiGopSize >= 1 && ( cfg.uiIntraPeriod && (cfg.uiIntraPeriod % cfg.uiGopSize) == 0) );
if (pCfg->uiGopSize < 1 || pCfg->uiGopSize > MAX_GOP_SIZE) {
WelsLog (m_pEncContext, WELS_LOG_ERROR,
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
"CWelsH264SVCEncoder::Initialize(), invalid uiGopSize= %d, valid at range of [1, %d].\n", pCfg->uiGopSize,
MAX_GOP_SIZE);
Uninitialize();
@ -316,7 +331,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) {
}
if (!WELS_POWER2_IF (pCfg->uiGopSize)) {
WelsLog (m_pEncContext, WELS_LOG_ERROR,
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
"CWelsH264SVCEncoder::Initialize(), invalid uiGopSize= %d, valid at range of [1, %d] and yield to power of 2.\n",
pCfg->uiGopSize, MAX_GOP_SIZE);
Uninitialize();
@ -324,7 +339,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) {
}
if (pCfg->uiIntraPeriod && pCfg->uiIntraPeriod < pCfg->uiGopSize) {
WelsLog (m_pEncContext, WELS_LOG_ERROR,
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
"CWelsH264SVCEncoder::Initialize(), invalid uiIntraPeriod= %d, valid in case it equals to 0 for unlimited intra period or exceeds specified uiGopSize= %d.\n",
pCfg->uiIntraPeriod, pCfg->uiGopSize);
Uninitialize();
@ -332,7 +347,7 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) {
}
if ((pCfg->uiIntraPeriod && (pCfg->uiIntraPeriod & (pCfg->uiGopSize - 1)) != 0)) {
WelsLog (m_pEncContext, WELS_LOG_ERROR,
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR,
"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",
pCfg->uiIntraPeriod, pCfg->uiGopSize);
Uninitialize();
@ -371,8 +386,8 @@ int CWelsH264SVCEncoder::InitializeInternal (SWelsSvcCodingParam* pCfg) {
m_iMaxPicWidth = pCfg->iPicWidth;
m_iMaxPicHeight = pCfg->iPicHeight;
if (WelsInitEncoderExt (&m_pEncContext, pCfg)) {
WelsLog (m_pEncContext, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), WelsInitEncoderExt failed.\n");
if (WelsInitEncoderExt (&m_pEncContext, pCfg, &m_pWelsTrace->m_sLogCtx)) {
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_ERROR, "CWelsH264SVCEncoder::Initialize(), WelsInitEncoderExt failed.\n");
Uninitialize();
return cmInitParaError;
}
@ -391,10 +406,10 @@ int32_t CWelsH264SVCEncoder::Uninitialize() {
return 0;
}
WelsLog (m_pEncContext, WELS_LOG_INFO, "CWelsH264SVCEncoder::Uninitialize()..\n");
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO, "CWelsH264SVCEncoder::Uninitialize()..\n");
#ifdef REC_FRAME_COUNT
WelsLog (m_pEncContext, WELS_LOG_INFO,
WelsLog (&m_pWelsTrace->m_sLogCtx, WELS_LOG_INFO,
"CWelsH264SVCEncoder::Uninitialize, m_uiCountFrameNum= %d, m_iCspInternal= 0x%x\n", m_uiCountFrameNum, m_iCspInternal);
#endif//REC_FRAME_COUNT
@ -548,7 +563,8 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) {
return cmInitParaError;
}
if (NULL == m_pEncContext || false == m_bInitialFlag) {
if ((NULL == m_pEncContext || false == m_bInitialFlag) && eOptionId != ENCODER_OPTION_TRACE_LEVEL
&& eOptionId != ENCODER_OPTION_TRACE_CALLBACK && eOptionId != ENCODER_OPTION_TRACE_CALLBACK_CONTEXT) {
return cmInitExpected;
}
@ -734,7 +750,7 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) {
break;
}
//adjust to valid range
WelsEncoderApplyBitRate (m_pEncContext->pSvcParam, pInfo->iLayer);
WelsEncoderApplyBitRate (&m_pWelsTrace->m_sLogCtx, m_pEncContext->pSvcParam, pInfo->iLayer);
}
break;
case ENCODER_OPTION_MAX_BITRATE: { // Target bit-rate
@ -775,7 +791,7 @@ int CWelsH264SVCEncoder::SetOption (ENCODER_OPTION eOptionId, void* pOption) {
break;
}
//adjust to valid range
WelsEncoderApplyBitRate (m_pEncContext->pSvcParam, pInfo->iLayer);
WelsEncoderApplyBitRate (&m_pWelsTrace->m_sLogCtx, m_pEncContext->pSvcParam, pInfo->iLayer);
}
break;
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) {
}
}
break;
case ENCODER_OPTION_TRACE_CALLBACK: {
if (m_pWelsTrace) {
CM_WELS_TRACE callback = * ((CM_WELS_TRACE*)pOption);
m_pWelsTrace->SetTraceCallback (callback);
}
}
break;
case ENCODER_OPTION_TRACE_CALLBACK_CONTEXT: {
if (m_pWelsTrace) {
void* ctx = * ((void**)pOption);
m_pWelsTrace->SetTraceCallbackContext (ctx);
}
}
break;
default:
return cmInitParaError;
}