Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 5 files). Show all
Unified · Split
| @@ -73,7 +73,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 72 unmodified lines | ||
| 73 | 73 | * \pParam pParam SWelsSvcCodingParam* |
| 74 | 74 | * \return successful - 0; otherwise none 0 for failed |
| 75 | 75 | */ |
| 76 | −int32_t ParamValidation (SWelsSvcCodingParam* pCfg) { | |
| 76 | +int32_t ParamValidation (SLogContext* pLogCtx, SWelsSvcCodingParam* pCfg) { | |
| 77 | 77 | float fMaxFrameRate = 0.0f; |
| 78 | 78 | const float fEpsn = 0.000001f; |
| 79 | 79 | int32_t i = 0; |
| @@ -81,7 +81,7 @@ int32_t ParamValidation (SWelsSvcCodingParam* pCfg) { · 1 unmodified line | ||
| 81 | 81 | assert (pCfg != NULL); |
| 82 | 82 | |
| 83 | 83 | 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); | |
| 85 | 85 | return ENC_RETURN_UNSUPPORTED_PARA; |
| 86 | 86 | } |
| 87 | 87 | for (i = 0; i < pCfg->iSpatialLayerNum; ++ i) { |
| @@ -89,13 +89,13 @@ int32_t ParamValidation (SWelsSvcCodingParam* pCfg) { · 1 unmodified line | ||
| 89 | 89 | if (fDlp->fOutputFrameRate > fDlp->fInputFrameRate || (fDlp->fInputFrameRate >= -fEpsn |
| 90 | 90 | && fDlp->fInputFrameRate <= fEpsn) |
| 91 | 91 | || (fDlp->fOutputFrameRate >= -fEpsn && fDlp->fOutputFrameRate <= fEpsn)) { |
| 92 | − WelsLog (NULL, WELS_LOG_ERROR, | |
| 92 | + WelsLog (pLogCtx, WELS_LOG_ERROR, | |
| 93 | 93 | "Invalid settings in input frame rate(%.6f) or output frame rate(%.6f) of layer #%d config file..\n", |
| 94 | 94 | fDlp->fInputFrameRate, fDlp->fOutputFrameRate, i); |
| 95 | 95 | return ENC_RETURN_INVALIDINPUT; |
| 96 | 96 | } |
| 97 | 97 | if (UINT_MAX == GetLogFactor (fDlp->fOutputFrameRate, fDlp->fInputFrameRate)) { |
| 98 | − WelsLog (NULL, WELS_LOG_ERROR, | |
| 98 | + WelsLog (pLogCtx, WELS_LOG_ERROR, | |
| 99 | 99 | "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", |
| 100 | 100 | fDlp->fInputFrameRate, fDlp->fOutputFrameRate, i); |
| 101 | 101 | return ENC_RETURN_INVALIDINPUT; |
| @@ -121,7 +121,7 @@ int32_t ParamValidation (SWelsSvcCodingParam* pCfg) { · 19 unmodified lines | ||
| 121 | 121 | iTotalBitrate += fDlp->iSpatialBitrate; |
| 122 | 122 | } |
| 123 | 123 | if (iTotalBitrate > pCfg->iTargetBitrate) { |
| 124 | − WelsLog (NULL, WELS_LOG_ERROR, | |
| 124 | + WelsLog (pLogCtx, WELS_LOG_ERROR, | |
| 125 | 125 | "Invalid settings in bitrate. the sum of each layer bitrate(%d) is larger than total bitrate setting(%d)\n", |
| 126 | 126 | iTotalBitrate, pCfg->iTargetBitrate); |
| 127 | 127 | } |
| @@ -131,7 +131,7 @@ int32_t ParamValidation (SWelsSvcCodingParam* pCfg) { · 3 unmodified lines | ||
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | |
| 134 | −int32_t ParamValidationExt (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pCodingParam) { | |
| 134 | +int32_t ParamValidationExt (SLogContext* pCtx, SWelsSvcCodingParam* pCodingParam) { | |
| 135 | 135 | int8_t i = 0; |
| 136 | 136 | int32_t iIdx = 0; |
| 137 | 137 | |
| @@ -383,7 +383,7 @@ int32_t ParamValidationExt (sWelsEncCtx* pCtx, SWelsSvcCodingParam* pCodingParam · 245 unmodified lines | ||
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | − return ParamValidation (pCodingParam); | |
| 386 | + return ParamValidation (pCtx, pCodingParam); | |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | |
| @@ -412,7 +412,7 @@ void WelsEncoderApplyFrameRate (SWelsSvcCodingParam* pParam) { · 22 unmodified lines | ||
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | |
| 415 | −void WelsEncoderApplyBitRate (SWelsSvcCodingParam* pParam, int iLayer) { | |
| 415 | +void WelsEncoderApplyBitRate (SLogContext* pLogCtx, SWelsSvcCodingParam* pParam, int iLayer) { | |
| 416 | 416 | //TODO (Sijia): this is a temporary solution which keep the ratio between layers |
| 417 | 417 | //but it is also possible to fulfill the bitrate of lower layer first |
| 418 | 418 | |
| @@ -421,7 +421,7 @@ void WelsEncoderApplyBitRate (SWelsSvcCodingParam* pParam, int iLayer) { · 2 unmodified lines | ||
| 421 | 421 | int32_t i, iOrigTotalBitrate = 0; |
| 422 | 422 | if (iLayer == SPATIAL_LAYER_ALL) { |
| 423 | 423 | if (pParam->iMaxBitrate < pParam->iTargetBitrate) { |
| 424 | − WelsLog (NULL, WELS_LOG_WARNING, | |
| 424 | + WelsLog (pLogCtx, WELS_LOG_WARNING, | |
| 425 | 425 | "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE,overall settting,TargetBitrate = %d,iMaxBitrate = %d\n", |
| 426 | 426 | pParam->iTargetBitrate, pParam->iMaxBitrate); |
| 427 | 427 | pParam->iMaxBitrate = pParam->iTargetBitrate; |
| @@ -439,7 +439,7 @@ void WelsEncoderApplyBitRate (SWelsSvcCodingParam* pParam, int iLayer) { · 11 unmodified lines | ||
| 439 | 439 | } |
| 440 | 440 | } else { |
| 441 | 441 | if (pParam->sSpatialLayers[iLayer].iMaxSpatialBitrate < pParam->sSpatialLayers[iLayer].iSpatialBitrate) { |
| 442 | − WelsLog (NULL, WELS_LOG_WARNING, | |
| 442 | + WelsLog (pLogCtx, WELS_LOG_WARNING, | |
| 443 | 443 | "CWelsH264SVCEncoder::SetOption():ENCODER_OPTION_BITRATE,iLayer = %d,iTargetBitrate = %d,iMaxBitrate = %d\n", |
| 444 | 444 | iLayer, pParam->sSpatialLayers[iLayer].iSpatialBitrate, pParam->sSpatialLayers[iLayer].iMaxSpatialBitrate); |
| 445 | 445 | pParam->sSpatialLayers[iLayer].iMaxSpatialBitrate = pParam->sSpatialLayers[iLayer].iSpatialBitrate; |
| @@ -1723,7 +1723,7 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 1277 unmodified lines | ||
| 1723 | 1723 | #endif//MEMORY_MONITOR |
| 1724 | 1724 | |
| 1725 | 1725 | 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", | |
| 1727 | 1727 | (*ppCtx)->pMemAlign->WelsGetMemoryUsage()); |
| 1728 | 1728 | delete (*ppCtx)->pMemAlign; |
| 1729 | 1729 | (*ppCtx)->pMemAlign = NULL; |
| @@ -1734,7 +1734,8 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 4 unmodified lines | ||
| 1734 | 1734 | } |
| 1735 | 1735 | } |
| 1736 | 1736 | |
| 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) { | |
| 1738 | 1739 | int32_t iSpatialIdx = 0, iSpatialNum = pCodingParam->iSpatialLayerNum; |
| 1739 | 1740 | uint16_t iMaxSliceCount = 0; |
| 1740 | 1741 | |
| @@ -1784,7 +1785,7 @@ int32_t InitSliceSettings (SWelsSvcCodingParam* pCodingParam, const int32_t kiCp · 43 unmodified lines | ||
| 1784 | 1785 | pDlp->sSliceCfg.sSliceArgument.uiSliceNum = iMaxSliceCount; |
| 1785 | 1786 | } |
| 1786 | 1787 | if (pDlp->sSliceCfg.sSliceArgument.uiSliceNum == 1) { |
| 1787 | − WelsLog (NULL, WELS_LOG_DEBUG, | |
| 1788 | + WelsLog (pLogCtx, WELS_LOG_DEBUG, | |
| 1788 | 1789 | "InitSliceSettings(), uiSliceNum(%d) you set for SM_AUTO_SLICE, now turn to SM_SINGLE_SLICE type!\n", |
| 1789 | 1790 | pDlp->sSliceCfg.sSliceArgument.uiSliceNum); |
| 1790 | 1791 | pDlp->sSliceCfg.uiSliceMode = SM_SINGLE_SLICE; |
| @@ -1799,7 +1800,7 @@ int32_t InitSliceSettings (SWelsSvcCodingParam* pCodingParam, const int32_t kiCp · 8 unmodified lines | ||
| 1799 | 1800 | } else if (!CheckFixedSliceNumMultiSliceSetting (kiMbNumInFrame, |
| 1800 | 1801 | &pDlp->sSliceCfg.sSliceArgument)) { // verify interleave mode settings |
| 1801 | 1802 | //check uiSliceMbNum with current uiSliceNum |
| 1802 | − WelsLog (NULL, WELS_LOG_ERROR, | |
| 1803 | + WelsLog (pLogCtx, WELS_LOG_ERROR, | |
| 1803 | 1804 | "InitSliceSettings(), invalid uiSliceMbNum (%d) settings!,now turn to SM_SINGLE_SLICE type\n", |
| 1804 | 1805 | pDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[0]); |
| 1805 | 1806 | pDlp->sSliceCfg.uiSliceMode = SM_SINGLE_SLICE; |
| @@ -1838,9 +1839,10 @@ int32_t InitSliceSettings (SWelsSvcCodingParam* pCodingParam, const int32_t kiCp · 32 unmodified lines | ||
| 1838 | 1839 | /*! |
| 1839 | 1840 | * \brief log output for cpu features/capabilities |
| 1840 | 1841 | */ |
| 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) { | |
| 1842 | 1844 | // 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" \ | |
| 1844 | 1846 | "HTT: %c, " \ |
| 1845 | 1847 | "MMX: %c, " \ |
| 1846 | 1848 | "MMXEX: %c, " \ |
| @@ -1890,7 +1892,7 @@ void OutputCpuFeaturesLog (uint32_t uiCpuFeatureFlags, uint32_t uiCpuCores, int3 · 43 unmodified lines | ||
| 1890 | 1892 | * \pParam pParam SWelsSvcCodingParam* |
| 1891 | 1893 | * \return successful - 0; otherwise none 0 for failed |
| 1892 | 1894 | */ |
| 1893 | −int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingParam) { | |
| 1895 | +int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingParam, SLogContext* pLogCtx) { | |
| 1894 | 1896 | sWelsEncCtx* pCtx = NULL; |
| 1895 | 1897 | int32_t iRet = 0; |
| 1896 | 1898 | uint32_t uiCpuFeatureFlags = 0; // CPU features |
| @@ -1900,14 +1902,14 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 3 unmodified lines | ||
| 1900 | 1902 | int16_t iSliceNum = 1; // number of slices used |
| 1901 | 1903 | |
| 1902 | 1904 | 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", | |
| 1904 | 1906 | (void*)ppCtx, (void*)pCodingParam); |
| 1905 | 1907 | return 1; |
| 1906 | 1908 | } |
| 1907 | 1909 | |
| 1908 | − iRet = ParamValidationExt (*ppCtx, pCodingParam); | |
| 1910 | + iRet = ParamValidationExt (pLogCtx, pCodingParam); | |
| 1909 | 1911 | 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); | |
| 1911 | 1913 | return iRet; |
| 1912 | 1914 | } |
| 1913 | 1915 | |
| @@ -1922,7 +1924,7 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 8 unmodified lines | ||
| 1922 | 1924 | iCacheLineSize = 32; |
| 1923 | 1925 | else if (uiCpuFeatureFlags & WELS_CPU_CACHELINE_16) |
| 1924 | 1926 | iCacheLineSize = 16; |
| 1925 | − OutputCpuFeaturesLog (uiCpuFeatureFlags, uiCpuCores, iCacheLineSize); | |
| 1927 | + OutputCpuFeaturesLog (pLogCtx, uiCpuFeatureFlags, uiCpuCores, iCacheLineSize); | |
| 1926 | 1928 | #else |
| 1927 | 1929 | iCacheLineSize = 16; // 16 bytes aligned in default |
| 1928 | 1930 | #endif//X86_ASM |
| @@ -1953,8 +1955,8 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 24 unmodified lines | ||
| 1953 | 1955 | |
| 1954 | 1956 | uiCpuCores = WELS_CLIP3 (uiCpuCores, 1, MAX_THREADS_NUM); |
| 1955 | 1957 | |
| 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"); | |
| 1958 | 1960 | return 1; |
| 1959 | 1961 | } |
| 1960 | 1962 | |
| @@ -1965,6 +1967,8 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 4 unmodified lines | ||
| 1965 | 1967 | WELS_VERIFY_RETURN_IF (1, (NULL == pCtx)) |
| 1966 | 1968 | memset (pCtx, 0, sizeof (sWelsEncCtx)); |
| 1967 | 1969 | |
| 1970 | + pCtx->sLogCtx = *pLogCtx; | |
| 1971 | + | |
| 1968 | 1972 | pCtx->pMemAlign = new CMemoryAlign (iCacheLineSize); |
| 1969 | 1973 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pCtx->pMemAlign), FreeMemorySvc (&pCtx)) |
| 1970 | 1974 | |
| @@ -3133,7 +3137,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 1162 unmodified lines | ||
| 3133 | 3137 | |
| 3134 | 3138 | pCtx->iActiveThreadsNum = iSliceCount; |
| 3135 | 3139 | // 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], | |
| 3137 | 3142 | &pCtx->pSliceThreading->pThreadMasterEvent[0], |
| 3138 | 3143 | pLayerBsInfo, iSliceCount, pCtx->pCurDqLayer->pSliceEncCtx, false); |
| 3139 | 3144 | if (iRet) { |
| @@ -3172,7 +3177,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 32 unmodified lines | ||
| 3172 | 3177 | iNumThreadsScheduled = pCtx->iActiveThreadsNum; |
| 3173 | 3178 | iNumThreadsRunning = iNumThreadsScheduled; |
| 3174 | 3179 | // 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], | |
| 3176 | 3182 | &pCtx->pSliceThreading->pThreadMasterEvent[0], |
| 3177 | 3183 | pLayerBsInfo, iNumThreadsRunning, pCtx->pCurDqLayer->pSliceEncCtx, false); |
| 3178 | 3184 | if (iRet) { |
| @@ -3218,7 +3224,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, SFrameBSInfo* pFbi, const SSour · 39 unmodified lines | ||
| 3218 | 3224 | const int32_t kiPartitionCnt = pCtx->iActiveThreadsNum; //pSvcParam->iCountThreadsNum; |
| 3219 | 3225 | |
| 3220 | 3226 | // 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], | |
| 3222 | 3229 | &pCtx->pSliceThreading->pThreadMasterEvent[0], |
| 3223 | 3230 | pLayerBsInfo, kiPartitionCnt, pCtx->pCurDqLayer->pSliceEncCtx, true); |
| 3224 | 3231 | if (iRet) { |
| @@ -3509,7 +3516,7 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa · 284 unmodified lines | ||
| 3509 | 3516 | if (NULL == ppCtx || NULL == *ppCtx || NULL == pNewParam) return 1; |
| 3510 | 3517 | |
| 3511 | 3518 | /* Check validation in new parameters */ |
| 3512 | − iReturn = ParamValidationExt (*ppCtx, pNewParam); | |
| 3519 | + iReturn = ParamValidationExt (& (*ppCtx)->sLogCtx, pNewParam); | |
| 3513 | 3520 | if (iReturn != ENC_RETURN_SUCCESS) return iReturn; |
| 3514 | 3521 | |
| 3515 | 3522 | pOldParam = (*ppCtx)->pSvcParam; |
| @@ -3574,6 +3581,7 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa · 58 unmodified lines | ||
| 3574 | 3581 | if (bNeedReset) { |
| 3575 | 3582 | SParaSetOffsetVariable sTmpPsoVariable[PARA_SET_TYPE]; |
| 3576 | 3583 | uint16_t uiTmpIdrPicId;//this is for LTR! |
| 3584 | + SLogContext sLogCtx = (*ppCtx)->sLogCtx; | |
| 3577 | 3585 | memcpy (sTmpPsoVariable, (*ppCtx)->sPSOVector.sParaSetOffsetVariable, |
| 3578 | 3586 | (PARA_SET_TYPE)*sizeof (SParaSetOffsetVariable)); // confirmed_safe_unsafe_usage |
| 3579 | 3587 | uiTmpIdrPicId = (*ppCtx)->sPSOVector.uiIdrPicId; |
| @@ -3581,7 +3589,7 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa · 1 unmodified line | ||
| 3581 | 3589 | WelsUninitEncoderExt (ppCtx); |
| 3582 | 3590 | |
| 3583 | 3591 | /* Update new parameters */ |
| 3584 | − if (WelsInitEncoderExt (ppCtx, pNewParam)) | |
| 3592 | + if (WelsInitEncoderExt (ppCtx, pNewParam, &sLogCtx)) | |
| 3585 | 3593 | return 1; |
| 3586 | 3594 | |
| 3587 | 3595 | // reset the scaled spatial picture size |