Set and use a proper log context in the encoder

This commit is contained in:
Martin Storsjö 2014-06-10 12:35:55 +03:00
parent 8bac9315e6
commit 9583ac4d52
5 changed files with 97 additions and 73 deletions

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,27 @@ 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);
WelsSetLogCallback (welsCodecTrace::CODEC_TRACE);
#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 +193,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 +206,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 +216,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 +229,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 +240,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 +280,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 +296,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 +305,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 +314,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 +324,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 +332,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 +340,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 +348,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 +387,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 +407,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
@ -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