History

Set and use a proper log context in the encoder

Martin Storsjö committed 12 years ago

Commit 9583ac41 parent 8bac9315 files · +97 −73Browse files

Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 5 files). Show all

Unified · Split

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

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