Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 16 files). Show all
Unified · Split
| @@ -140,7 +140,7 @@ int32_t ParamValidationExt (void* pParam) { · 139 unmodified lines | ||
| 140 | 140 | |
| 141 | 141 | assert (pCodingParam != NULL); |
| 142 | 142 | if (NULL == pCodingParam) |
| 143 | − return 1; | |
| 143 | + return ENC_RETURN_INVALIDINPUT; | |
| 144 | 144 | |
| 145 | 145 | if (pCodingParam->iSpatialLayerNum < 1 || pCodingParam->iSpatialLayerNum > MAX_DEPENDENCY_LAYER) { |
| 146 | 146 | #if defined (_DEBUG) |
| @@ -148,7 +148,7 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line | ||
| 148 | 148 | pCodingParam->iSpatialLayerNum); |
| 149 | 149 | #endif//#if _DEBUG |
| 150 | 150 | |
| 151 | − return 1; | |
| 151 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | if (pCodingParam->iTemporalLayerNum < 1 || pCodingParam->iTemporalLayerNum > MAX_TEMPORAL_LEVEL) { |
| @@ -156,14 +156,14 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line | ||
| 156 | 156 | fprintf (stderr, "ParamValidationExt(), monitor invalid pCodingParam->iTemporalLayerNum: %d!\n", |
| 157 | 157 | pCodingParam->iTemporalLayerNum); |
| 158 | 158 | #endif//#if _DEBUG |
| 159 | − return 1; | |
| 159 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | if (pCodingParam->uiGopSize < 1 || pCodingParam->uiGopSize > MAX_GOP_SIZE) { |
| 163 | 163 | #if defined (_DEBUG) |
| 164 | 164 | fprintf (stderr, "ParamValidationExt(), monitor invalid pCodingParam->uiGopSize: %d!\n", pCodingParam->uiGopSize); |
| 165 | 165 | #endif//#if _DEBUG |
| 166 | − return 1; | |
| 166 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | |
| @@ -173,7 +173,7 @@ int32_t ParamValidationExt (void* pParam) { · 3 unmodified lines | ||
| 173 | 173 | "ParamValidationExt(), uiIntraPeriod(%d) should be not less than that of uiGopSize(%d) or -1 specified!\n", |
| 174 | 174 | pCodingParam->uiIntraPeriod, pCodingParam->uiGopSize); |
| 175 | 175 | #endif//#if _DEBUG |
| 176 | − return 1; | |
| 176 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | if (pCodingParam->uiIntraPeriod && (pCodingParam->uiIntraPeriod & (pCodingParam->uiGopSize - 1)) != 0) { |
| @@ -181,7 +181,7 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line | ||
| 181 | 181 | fprintf (stderr, "ParamValidationExt(), uiIntraPeriod(%d) should be multiple of uiGopSize(%d) or -1 specified!\n", |
| 182 | 182 | pCodingParam->uiIntraPeriod, pCodingParam->uiGopSize); |
| 183 | 183 | #endif//#if _DEBUG |
| 184 | − return 1; | |
| 184 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | |
| @@ -213,7 +213,7 @@ int32_t ParamValidationExt (void* pParam) { · 25 unmodified lines | ||
| 213 | 213 | #if defined (_DEBUG) |
| 214 | 214 | fprintf (stderr, "ParamValidationExt(), invalid %d x %d in dependency layer settings!\n", kiPicWidth, kiPicHeight); |
| 215 | 215 | #endif//#if _DEBUG |
| 216 | − return 1; | |
| 216 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 217 | 217 | } |
| 218 | 218 | if ((kiPicWidth & 0x0F) != 0 || (kiPicHeight & 0x0F) != 0) { |
| 219 | 219 | #if defined (_DEBUG) |
| @@ -221,14 +221,14 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line | ||
| 221 | 221 | "ParamValidationExt(), in layer #%d iWidth x iHeight(%d x %d) both should be multiple of 16, can not support with arbitrary size currently!\n", |
| 222 | 222 | i, kiPicWidth, kiPicHeight); |
| 223 | 223 | #endif//#if _DEBUG |
| 224 | − return 1; | |
| 224 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | if (fDlp->sSliceCfg.uiSliceMode >= SM_RESERVED) { |
| 228 | 228 | #if defined (_DEBUG) |
| 229 | 229 | fprintf (stderr, "ParamValidationExt(), invalid uiSliceMode (%d) settings!\n", fDlp->sSliceCfg.uiSliceMode); |
| 230 | 230 | #endif//#if _DEBUG |
| 231 | − return 1; | |
| 231 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | //check pSlice settings under multi-pSlice |
| @@ -257,7 +257,7 @@ int32_t ParamValidationExt (void* pParam) { · 22 unmodified lines | ||
| 257 | 257 | #if defined (_DEBUG) |
| 258 | 258 | fprintf (stderr, "ParamValidationExt(), invalid uiSliceNum (%d) settings!\n", fDlp->sSliceCfg.sSliceArgument.uiSliceNum); |
| 259 | 259 | #endif//#if _DEBUG |
| 260 | − return 1; | |
| 260 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 261 | 261 | } |
| 262 | 262 | if (fDlp->sSliceCfg.sSliceArgument.uiSliceNum == 1) { |
| 263 | 263 | #if defined (_DEBUG) |
| @@ -281,7 +281,7 @@ int32_t ParamValidationExt (void* pParam) { · 17 unmodified lines | ||
| 281 | 281 | fprintf (stderr, "ParamValidationExt(), invalid uiSliceMbNum (%d) settings!\n", |
| 282 | 282 | fDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[0]); |
| 283 | 283 | #endif//#if _DEBUG |
| 284 | − return 1; | |
| 284 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 285 | 285 | } |
| 286 | 286 | // considering the coding efficient and performance, iCountMbNum constraint by MIN_NUM_MB_PER_SLICE condition of multi-pSlice mode settting |
| 287 | 287 | if (iMbNumInFrame <= MIN_NUM_MB_PER_SLICE) { |
| @@ -303,7 +303,7 @@ int32_t ParamValidationExt (void* pParam) { · 15 unmodified lines | ||
| 303 | 303 | fprintf (stderr, "ParamValidationExt(), invalid uiSliceMbNum (%d) settings!\n", |
| 304 | 304 | fDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[0]); |
| 305 | 305 | #endif//#if _DEBUG |
| 306 | − return 1; | |
| 306 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | if (!CheckRasterMultiSliceSetting (iMbNumInFrame, &fDlp->sSliceCfg.sSliceArgument)) { // verify interleave mode settings |
| @@ -311,7 +311,7 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line | ||
| 311 | 311 | fprintf (stderr, "ParamValidationExt(), invalid uiSliceMbNum (%d) settings!\n", |
| 312 | 312 | fDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[0]); |
| 313 | 313 | #endif//#if _DEBUG |
| 314 | − return 1; | |
| 314 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 315 | 315 | } |
| 316 | 316 | if (fDlp->sSliceCfg.sSliceArgument.uiSliceNum <= 0 |
| 317 | 317 | || fDlp->sSliceCfg.sSliceArgument.uiSliceNum > iMaxSliceNum) { // verify interleave mode settings |
| @@ -319,7 +319,7 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line | ||
| 319 | 319 | fprintf (stderr, "ParamValidationExt(), invalid uiSliceNum (%d) in SM_RASTER_SLICE settings!\n", |
| 320 | 320 | fDlp->sSliceCfg.sSliceArgument.uiSliceNum); |
| 321 | 321 | #endif//#if _DEBUG |
| 322 | − return 1; | |
| 322 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 323 | 323 | } |
| 324 | 324 | if (fDlp->sSliceCfg.sSliceArgument.uiSliceNum == 1) { |
| 325 | 325 | #if defined (_DEBUG) |
| @@ -353,7 +353,7 @@ int32_t ParamValidationExt (void* pParam) { · 27 unmodified lines | ||
| 353 | 353 | #if defined (_DEBUG) |
| 354 | 354 | fprintf (stderr, "ParamValidationExt(), invalid uiSliceNum (%d) settings more than MAX!\n", iMbHeight); |
| 355 | 355 | #endif//#if _DEBUG |
| 356 | − return 1; | |
| 356 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 357 | 357 | } |
| 358 | 358 | fDlp->sSliceCfg.sSliceArgument.uiSliceNum = iMbHeight; |
| 359 | 359 | |
| @@ -361,14 +361,14 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line | ||
| 361 | 361 | #if defined (_DEBUG) |
| 362 | 362 | fprintf (stderr, "ParamValidationExt(), invalid uiSliceNum (%d) settings!\n", fDlp->sSliceCfg.sSliceArgument.uiSliceNum); |
| 363 | 363 | #endif//#if _DEBUG |
| 364 | − return 1; | |
| 364 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 365 | 365 | } |
| 366 | 366 | if (!CheckRowMbMultiSliceSetting (iMbWidth, &fDlp->sSliceCfg.sSliceArgument)) { // verify interleave mode settings |
| 367 | 367 | #if defined (_DEBUG) |
| 368 | 368 | fprintf (stderr, "ParamValidationExt(), invalid uiSliceMbNum (%d) settings!\n", |
| 369 | 369 | fDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[0]); |
| 370 | 370 | #endif//#if _DEBUG |
| 371 | − return 1; | |
| 371 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 372 | 372 | } |
| 373 | 373 | } |
| 374 | 374 | break; |
| @@ -380,7 +380,7 @@ int32_t ParamValidationExt (void* pParam) { · 5 unmodified lines | ||
| 380 | 380 | fprintf (stderr, "ParamValidationExt(), invalid iSliceSize (%d) settings!\n", |
| 381 | 381 | fDlp->sSliceCfg.sSliceArgument.uiSliceSizeConstraint); |
| 382 | 382 | #endif//#if _DEBUG |
| 383 | − return 1; | |
| 383 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 384 | 384 | } |
| 385 | 385 | // considering the coding efficient and performance, iCountMbNum constraint by MIN_NUM_MB_PER_SLICE condition of multi-pSlice mode settting |
| 386 | 386 | if (iMbWidth * iMbHeight <= MIN_NUM_MB_PER_SLICE) { |
| @@ -396,7 +396,7 @@ int32_t ParamValidationExt (void* pParam) { · 9 unmodified lines | ||
| 396 | 396 | fprintf (stderr, "ParamValidationExt(), invalid uiSliceMode (%d) settings!\n", |
| 397 | 397 | pCodingParam->sDependencyLayers[0].sSliceCfg.uiSliceMode); |
| 398 | 398 | #endif//#if _DEBUG |
| 399 | − return 1; | |
| 399 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 400 | 400 | |
| 401 | 401 | } |
| 402 | 402 | break; |
| @@ -1322,7 +1322,7 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 919 unmodified lines | ||
| 1322 | 1322 | while (iIndex < pParam->iSpatialLayerNum) { |
| 1323 | 1323 | SDLayerParam* fDlp = &pParam->sDependencyLayers[iIndex]; |
| 1324 | 1324 | |
| 1325 | − fCompressRatioThr = COMPRESS_RATIO_DECIDED_BY_RESOLUTION (fDlp->iFrameWidth, fDlp->iFrameHeight); | |
| 1325 | + fCompressRatioThr = COMPRESS_RATIO_THR; | |
| 1326 | 1326 | |
| 1327 | 1327 | iLayerBsSize = WELS_ROUND (((3 * fDlp->iFrameWidth * fDlp->iFrameHeight) >> 1) * fCompressRatioThr); |
| 1328 | 1328 | iLayerBsSize = WELS_ALIGN (iLayerBsSize, 4); // 4 bytes alinged |
| @@ -1339,9 +1339,9 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 10 unmodified lines | ||
| 1339 | 1339 | // Output |
| 1340 | 1340 | (*ppCtx)->pOut = (SWelsEncoderOutput*)pMa->WelsMalloc (sizeof (SWelsEncoderOutput), "SWelsEncoderOutput"); |
| 1341 | 1341 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pOut), FreeMemorySvc (ppCtx)) |
| 1342 | − (*ppCtx)->pOut->pBsBuffer = (uint8_t*)pMa->WelsMalloc (iCountBsLen, "pOut->pBsBuffer"); | |
| 1342 | + (*ppCtx)->pOut->pBsBuffer = (uint8_t*)pMa->WelsMalloc (iCountBsLen, "pOut->pBsBuffer"); | |
| 1343 | 1343 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pOut->pBsBuffer), FreeMemorySvc (ppCtx)) |
| 1344 | − (*ppCtx)->pOut->uiSize = iCountBsLen; | |
| 1344 | + (*ppCtx)->pOut->uiSize = iCountBsLen; | |
| 1345 | 1345 | (*ppCtx)->pOut->sNalList = (SWelsNalRaw*)pMa->WelsMalloc (iCountNals * sizeof (SWelsNalRaw), "pOut->sNalList"); |
| 1346 | 1346 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pOut->sNalList), FreeMemorySvc (ppCtx)) |
| 1347 | 1347 | (*ppCtx)->pOut->iCountNals = iCountNals; |
| @@ -1349,10 +1349,10 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 1 unmodified line | ||
| 1349 | 1349 | |
| 1350 | 1350 | #ifdef MT_ENABLED |
| 1351 | 1351 | if (pParam->iMultipleThreadIdc > 1) { |
| 1352 | − (*ppCtx)->pFrameBs = (uint8_t*)pMa->WelsMalloc (iCountBsLen + (iTargetSpatialBsSize * ((*ppCtx)->iMaxSliceCount - 1)), | |
| 1353 | − "pFrameBs"); | |
| 1352 | + const int32_t iTotalLength = iCountBsLen + (iTargetSpatialBsSize * ((*ppCtx)->iMaxSliceCount - 1)); | |
| 1353 | + (*ppCtx)->pFrameBs = (uint8_t*)pMa->WelsMalloc (iTotalLength, "pFrameBs"); | |
| 1354 | 1354 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pFrameBs), FreeMemorySvc (ppCtx)) |
| 1355 | − (*ppCtx)->iFrameBsSize = iCountBsLen * (*ppCtx)->iMaxSliceCount; | |
| 1355 | + (*ppCtx)->iFrameBsSize = iTotalLength; | |
| 1356 | 1356 | } else |
| 1357 | 1357 | #endif//MT_ENABLED |
| 1358 | 1358 | { |
| @@ -2081,7 +2081,7 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 722 unmodified lines | ||
| 2081 | 2081 | #if defined(MEMORY_MONITOR) |
| 2082 | 2082 | WelsLog (pCtx, WELS_LOG_INFO, "WelsInitEncoderExt() exit, overall memory usage: %llu bytes\n", |
| 2083 | 2083 | static_cast<unsigned long long> (sizeof (sWelsEncCtx) /* requested size from malloc() or new operator */ |
| 2084 | − + pCtx->pMemAlign->WelsGetMemoryUsage()) /* requested size from CMemoryAlign::WelsMalloc() */ | |
| 2084 | + + pCtx->pMemAlign->WelsGetMemoryUsage()) /* requested size from CMemoryAlign::WelsMalloc() */ | |
| 2085 | 2085 | ); |
| 2086 | 2086 | #endif//MEMORY_MONITOR |
| 2087 | 2087 | |
| @@ -2749,7 +2749,7 @@ void ParasetIdAdditionIdAdjust (SParaSetOffsetVariable* sParaSetOffsetVariable, · 661 unmodified lines | ||
| 2749 | 2749 | |
| 2750 | 2750 | /*! |
| 2751 | 2751 | * \brief write all parameter sets introduced in SVC extension |
| 2752 | − * \return size in bytes of bitstream wrote | |
| 2752 | + * \return writing results, success or error | |
| 2753 | 2753 | */ |
| 2754 | 2754 | int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pNumNal) { |
| 2755 | 2755 | int32_t iSize = 0; |
| @@ -2757,9 +2757,11 @@ int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pN · 1 unmodified line | ||
| 2757 | 2757 | int32_t iIdx = 0; |
| 2758 | 2758 | int32_t iId = 0; |
| 2759 | 2759 | int32_t iCountNal = 0; |
| 2760 | + int32_t iNalLength = 0; | |
| 2761 | + int32_t iReturn = ENC_RETURN_SUCCESS; | |
| 2760 | 2762 | |
| 2761 | 2763 | if (NULL == pCtx || NULL == pNalLen || NULL == pNumNal) |
| 2762 | − return 0; | |
| 2764 | + return ENC_RETURN_UNEXPECTED; | |
| 2763 | 2765 | |
| 2764 | 2766 | /* write all SPS */ |
| 2765 | 2767 | iIdx = 0; |
| @@ -2804,11 +2806,15 @@ int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pN · 38 unmodified lines | ||
| 2804 | 2806 | WelsUnloadNal (pCtx->pOut); |
| 2805 | 2807 | } |
| 2806 | 2808 | |
| 2807 | − pNalLen[iCountNal] = WelsEncodeNal (&pCtx->pOut->sNalList[iNal], pCtx->pFrameBs + pCtx->iPosBsBuffer, | |
| 2808 | − &pNalLen[iCountNal]); | |
| 2809 | + iReturn = WelsEncodeNal (&pCtx->pOut->sNalList[iNal], NULL, | |
| 2810 | + pCtx->iFrameBsSize - pCtx->iPosBsBuffer,//available buffer to be written, so need to substract the used length | |
| 2811 | + pCtx->pFrameBs + pCtx->iPosBsBuffer, | |
| 2812 | + &iNalLength); | |
| 2813 | + WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS) | |
| 2814 | + pNalLen[iCountNal] =iNalLength; | |
| 2809 | 2815 | |
| 2810 | − pCtx->iPosBsBuffer += pNalLen[iCountNal]; | |
| 2811 | − iSize += pNalLen[iCountNal]; | |
| 2816 | + pCtx->iPosBsBuffer += iNalLength; | |
| 2817 | + iSize += iNalLength; | |
| 2812 | 2818 | |
| 2813 | 2819 | ++ iIdx; |
| 2814 | 2820 | ++ iCountNal; |
| @@ -2829,11 +2835,14 @@ int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pN · 14 unmodified lines | ||
| 2829 | 2835 | WelsWritePpsSyntax (&pCtx->pPPSArray[iIdx], &pCtx->pOut->sBsWrite, & (pCtx->sPSOVector)); |
| 2830 | 2836 | WelsUnloadNal (pCtx->pOut); |
| 2831 | 2837 | |
| 2832 | − pNalLen[iCountNal] = WelsEncodeNal (&pCtx->pOut->sNalList[iNal], pCtx->pFrameBs + pCtx->iPosBsBuffer, | |
| 2833 | − &pNalLen[iCountNal]); | |
| 2834 | − | |
| 2835 | − pCtx->iPosBsBuffer += pNalLen[iCountNal]; | |
| 2836 | − iSize += pNalLen[iCountNal]; | |
| 2838 | + iReturn = WelsEncodeNal (&pCtx->pOut->sNalList[iNal], NULL, | |
| 2839 | + pCtx->iFrameBsSize - pCtx->iPosBsBuffer, | |
| 2840 | + pCtx->pFrameBs + pCtx->iPosBsBuffer, | |
| 2841 | + &iNalLength); | |
| 2842 | + WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS) | |
| 2843 | + pNalLen[iCountNal] = iNalLength; | |
| 2844 | + pCtx->iPosBsBuffer += iNalLength; | |
| 2845 | + iSize += iNalLength; | |
| 2837 | 2846 | |
| 2838 | 2847 | ++ iIdx; |
| 2839 | 2848 | ++ iCountNal; |
| @@ -2841,7 +2850,7 @@ int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pN · 1 unmodified line | ||
| 2841 | 2850 | |
| 2842 | 2851 | *pNumNal = iCountNal; |
| 2843 | 2852 | |
| 2844 | − return iSize; | |
| 2853 | + return ENC_RETURN_SUCCESS; | |
| 2845 | 2854 | } |
| 2846 | 2855 | |
| 2847 | 2856 | static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx, |
| @@ -2849,8 +2858,10 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx, · 1 unmodified line | ||
| 2849 | 2858 | int32_t* pNalLen, |
| 2850 | 2859 | int32_t* pNalIdxInLayer, |
| 2851 | 2860 | const EWelsNalUnitType keNalType, |
| 2852 | − const EWelsNalRefIdc keNalRefIdc) { | |
| 2853 | − int32_t iPayloadSize = 0; | |
| 2861 | + const EWelsNalRefIdc keNalRefIdc, | |
| 2862 | + int32_t& iPayloadSize) { | |
| 2863 | + int32_t iReturn = ENC_RETURN_SUCCESS; | |
| 2864 | + iPayloadSize = 0; | |
| 2854 | 2865 | |
| 2855 | 2866 | if (keNalRefIdc != NRI_PRI_LOWEST) { |
| 2856 | 2867 | WelsLoadNal (pCtx->pOut, NAL_UNIT_PREFIX, keNalRefIdc); |
| @@ -2859,10 +2870,13 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx, · 2 unmodified lines | ||
| 2859 | 2870 | |
| 2860 | 2871 | WelsUnloadNal (pCtx->pOut); |
| 2861 | 2872 | |
| 2862 | − iPayloadSize = WelsEncodeNalExt (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1], | |
| 2863 | − &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt, | |
| 2864 | − pCtx->pFrameBs + pCtx->iPosBsBuffer, | |
| 2865 | − &pNalLen[*pNalIdxInLayer]); | |
| 2873 | + iReturn = WelsEncodeNal (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1], | |
| 2874 | + &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt, | |
| 2875 | + pCtx->iFrameBsSize-pCtx->iPosBsBuffer, | |
| 2876 | + pCtx->pFrameBs+pCtx->iPosBsBuffer, | |
| 2877 | + &pNalLen[*pNalIdxInLayer]); | |
| 2878 | + WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS) | |
| 2879 | + iPayloadSize = pNalLen[*pNalIdxInLayer]; | |
| 2866 | 2880 | |
| 2867 | 2881 | pCtx->iPosBsBuffer += iPayloadSize; |
| 2868 | 2882 | pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize; |
| @@ -2873,10 +2887,13 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx, · 4 unmodified lines | ||
| 2873 | 2887 | // No need write any syntax of prefix NAL Unit RBSP here |
| 2874 | 2888 | WelsUnloadNal (pCtx->pOut); |
| 2875 | 2889 | |
| 2876 | − iPayloadSize = WelsEncodeNalExt (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1], | |
| 2877 | − &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt, | |
| 2878 | − pCtx->pFrameBs + pCtx->iPosBsBuffer, | |
| 2879 | − &pNalLen[*pNalIdxInLayer]); | |
| 2890 | + iReturn = WelsEncodeNal (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1], | |
| 2891 | + &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt, | |
| 2892 | + pCtx->iFrameBsSize-pCtx->iPosBsBuffer, | |
| 2893 | + pCtx->pFrameBs+pCtx->iPosBsBuffer, | |
| 2894 | + &pNalLen[*pNalIdxInLayer]); | |
| 2895 | + WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS) | |
| 2896 | + iPayloadSize = pNalLen[*pNalIdxInLayer]; | |
| 2880 | 2897 | |
| 2881 | 2898 | pCtx->iPosBsBuffer += iPayloadSize; |
| 2882 | 2899 | pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize; |
| @@ -2884,16 +2901,16 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx, · 1 unmodified line | ||
| 2884 | 2901 | (*pNalIdxInLayer) ++; |
| 2885 | 2902 | } |
| 2886 | 2903 | |
| 2887 | − return iPayloadSize; | |
| 2904 | + return ENC_RETURN_SUCCESS; | |
| 2888 | 2905 | } |
| 2889 | 2906 | |
| 2890 | −int32_t WritePadding (sWelsEncCtx* pCtx, int32_t iLen) { | |
| 2907 | +int32_t WritePadding (sWelsEncCtx* pCtx, int32_t iLen, int32_t& iSize) { | |
| 2891 | 2908 | int32_t i = 0; |
| 2892 | 2909 | int32_t iNal = 0; |
| 2893 | 2910 | SBitStringAux* pBs = NULL; |
| 2894 | 2911 | int32_t iNalLen; |
| 2895 | − int32_t iSize = 0; | |
| 2896 | 2912 | |
| 2913 | + iSize = 0; | |
| 2897 | 2914 | iNal = pCtx->pOut->iNalIndex; |
| 2898 | 2915 | pBs = &pCtx->pOut->sBsWrite; // SBitStringAux instance for non VCL NALs decoding |
| 2899 | 2916 | |
| @@ -2903,7 +2920,7 @@ int32_t WritePadding (sWelsEncCtx* pCtx, int32_t iLen) { · 3 unmodified lines | ||
| 2903 | 2920 | "[RC] paddingcal pBuffer overflow, bufferlen=%lld, paddinglen=%d, iNalIdx= %d, iCountNals= %d\n", |
| 2904 | 2921 | static_cast<long long int> (pBs->pBufEnd - pBs->pBufPtr), iLen, iNal, pCtx->pOut->iCountNals); |
| 2905 | 2922 | #endif |
| 2906 | − return 0; | |
| 2923 | + return ENC_RETURN_MEMOVERFLOWFOUND; | |
| 2907 | 2924 | } |
| 2908 | 2925 | |
| 2909 | 2926 | WelsLoadNal (pCtx->pOut, NAL_UNIT_FILLER_DATA, NRI_PRI_LOWEST); |
| @@ -2917,12 +2934,16 @@ int32_t WritePadding (sWelsEncCtx* pCtx, int32_t iLen) { · 7 unmodified lines | ||
| 2917 | 2934 | BsFlush (pBs); |
| 2918 | 2935 | |
| 2919 | 2936 | WelsUnloadNal (pCtx->pOut); |
| 2920 | − iNalLen = WelsEncodeNal (&pCtx->pOut->sNalList[iNal], pCtx->pFrameBs + pCtx->iPosBsBuffer, &iNalLen); | |
| 2937 | + int32_t iReturn = WelsEncodeNal (&pCtx->pOut->sNalList[iNal], NULL, | |
| 2938 | + pCtx->iFrameBsSize-pCtx->iPosBsBuffer, | |
| 2939 | + pCtx->pFrameBs + pCtx->iPosBsBuffer, | |
| 2940 | + &iNalLen); | |
| 2941 | + WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS) | |
| 2921 | 2942 | |
| 2922 | 2943 | pCtx->iPosBsBuffer += iNalLen; |
| 2923 | 2944 | iSize += iNalLen; |
| 2924 | 2945 | |
| 2925 | − return iSize; | |
| 2946 | + return ENC_RETURN_SUCCESS; | |
| 2926 | 2947 | } |
| 2927 | 2948 | |
| 2928 | 2949 | /* |
| @@ -3012,7 +3033,8 @@ int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) { · 83 unmodified lines | ||
| 3012 | 3033 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs; |
| 3013 | 3034 | InitBits (&pCtx->pOut->sBsWrite, pCtx->pOut->pBsBuffer, pCtx->pOut->uiSize); |
| 3014 | 3035 | |
| 3015 | − WelsWriteParameterSets (pCtx, &iNalLen[0], &iCountNal); | |
| 3036 | + int32_t iReturn = WelsWriteParameterSets (pCtx, &iNalLen[0], &iCountNal); | |
| 3037 | + WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS) | |
| 3016 | 3038 | |
| 3017 | 3039 | pLayerBsInfo->uiPriorityId = 0; |
| 3018 | 3040 | pLayerBsInfo->uiSpatialId = 0; |
| @@ -3031,7 +3053,7 @@ int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) { · 12 unmodified lines | ||
| 3031 | 3053 | WelsEmms(); |
| 3032 | 3054 | #endif //X86_ASM |
| 3033 | 3055 | |
| 3034 | − return 0; | |
| 3056 | + return ENC_RETURN_SUCCESS; | |
| 3035 | 3057 | } |
| 3036 | 3058 | |
| 3037 | 3059 | /*! |
| @@ -3082,18 +3104,22 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 44 unmodified lines | ||
| 3082 | 3104 | int32_t i = 0, j = 0, k = 0; |
| 3083 | 3105 | #endif//_DEBUG |
| 3084 | 3106 | |
| 3107 | + pCtx->iEncoderError = ENC_RETURN_SUCCESS; | |
| 3085 | 3108 | pFbi->iLayerNum = 0; // for initialization |
| 3086 | 3109 | |
| 3087 | 3110 | // perform csc/denoise/downsample/padding, generate spatial layers |
| 3088 | 3111 | iSpatialNum = pCtx->pVpp->BuildSpatialPicList (pCtx, ppSrcList, iConfiguredLayerNum); |
| 3089 | 3112 | if (iSpatialNum < 1) { // skip due to temporal layer settings (different frame rate) |
| 3090 | 3113 | ++ pCtx->iCodingIndex; |
| 3091 | − return WELS_FRAME_TYPE_SKIP; | |
| 3114 | + pFbi->eOutputFrameType = WELS_FRAME_TYPE_SKIP; | |
| 3115 | + return ENC_RETURN_SUCCESS; | |
| 3092 | 3116 | } |
| 3093 | 3117 | |
| 3094 | 3118 | eFrameType = DecideFrameType (pCtx, iSpatialNum); |
| 3095 | − if (eFrameType == WELS_FRAME_TYPE_SKIP) | |
| 3096 | − return eFrameType; | |
| 3119 | + if (eFrameType == WELS_FRAME_TYPE_SKIP) { | |
| 3120 | + pFbi->eOutputFrameType = eFrameType; | |
| 3121 | + return ENC_RETURN_SUCCESS; | |
| 3122 | + } | |
| 3097 | 3123 | |
| 3098 | 3124 | InitFrameCoding (pCtx, eFrameType); |
| 3099 | 3125 | |
| @@ -3108,7 +3134,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 8 unmodified lines | ||
| 3108 | 3134 | //if ( pSvcParam->bEnableSSEI ) |
| 3109 | 3135 | |
| 3110 | 3136 | // write parameter sets bitstream here |
| 3111 | − WelsWriteParameterSets (pCtx, &iNalLen[0], &iCountNal); | |
| 3137 | + pCtx->iEncoderError = WelsWriteParameterSets (pCtx, &iNalLen[0], &iCountNal); | |
| 3138 | + WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS) | |
| 3112 | 3139 | |
| 3113 | 3140 | pLayerBsInfo->uiPriorityId = 0; |
| 3114 | 3141 | pLayerBsInfo->uiSpatialId = 0; |
| @@ -3177,7 +3204,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 62 unmodified lines | ||
| 3177 | 3204 | if (iLayerNum >= MAX_LAYER_NUM_OF_FRAME) { // check available layer_bs_info writing as follows |
| 3178 | 3205 | WelsLog (pCtx, WELS_LOG_ERROR, "WelsEncoderEncodeExt(), iLayerNum(%d) overflow(max:%d)!", iLayerNum, |
| 3179 | 3206 | MAX_LAYER_NUM_OF_FRAME); |
| 3180 | − return -1; | |
| 3207 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 3181 | 3208 | } |
| 3182 | 3209 | |
| 3183 | 3210 | iNalIdxInLayer = 0; |
| @@ -3215,9 +3242,11 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 31 unmodified lines | ||
| 3215 | 3242 | if (!WelsBuildRefList (pCtx, pCtx->iPOC)) { |
| 3216 | 3243 | // Force coding IDR as followed |
| 3217 | 3244 | ForceCodingIDR (pCtx); |
| 3218 | − WelsLog (pCtx, WELS_LOG_WARNING, "WelsEncoderEncodeExt(), WelsBuildRefList failed for P frames, pCtx->iNumRef0= %d.\n", | |
| 3245 | + WelsLog (pCtx, WELS_LOG_WARNING, "WelsEncoderEncodeExt(), WelsBuildRefList failed for P frames, pCtx->iNumRef0= %d. ForceCodingIDR!\n", | |
| 3219 | 3246 | pCtx->iNumRef0); |
| 3220 | − return -1; | |
| 3247 | + pFbi->eOutputFrameType = WELS_FRAME_TYPE_IDR; | |
| 3248 | + pCtx->iEncoderError = ENC_RETURN_CORRECTED; | |
| 3249 | + return ENC_RETURN_CORRECTED; | |
| 3221 | 3250 | } |
| 3222 | 3251 | #ifdef LONG_TERM_REF_DUMP |
| 3223 | 3252 | dump_ref (pCtx); |
| @@ -3230,23 +3259,32 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 6 unmodified lines | ||
| 3230 | 3259 | PreprocessSliceCoding (pCtx); // MUST be called after pfWelsRcPictureInit() and WelsInitCurrentLayer() |
| 3231 | 3260 | |
| 3232 | 3261 | iLayerSize = 0; |
| 3262 | + | |
| 3233 | 3263 | if (SM_SINGLE_SLICE == param_d->sSliceCfg.uiSliceMode) { // only one slice within a sQualityStat layer |
| 3234 | 3264 | int32_t iSliceSize = 0; |
| 3265 | + int32_t iPayloadSize = 0; | |
| 3235 | 3266 | |
| 3236 | 3267 | if (pCtx->bNeedPrefixNalFlag) { |
| 3237 | − iLayerSize += AddPrefixNal (pCtx, pLayerBsInfo, &iNalLen[0], &iNalIdxInLayer, eNalType, eNalRefIdc); | |
| 3268 | + pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &iNalLen[0], &iNalIdxInLayer, eNalType, eNalRefIdc, iPayloadSize); | |
| 3269 | + WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS) | |
| 3270 | + iLayerSize += iPayloadSize; | |
| 3238 | 3271 | } |
| 3239 | 3272 | |
| 3240 | 3273 | WelsLoadNal (pCtx->pOut, eNalType, eNalRefIdc); |
| 3241 | 3274 | |
| 3242 | − WelsCodeOneSlice (pCtx, 0, eNalType); | |
| 3275 | + pCtx->iEncoderError = WelsCodeOneSlice (pCtx, 0, eNalType); | |
| 3276 | + WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS) | |
| 3243 | 3277 | |
| 3244 | 3278 | WelsUnloadNal (pCtx->pOut); |
| 3245 | 3279 | |
| 3246 | − iSliceSize = WelsEncodeNalExt (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1], | |
| 3247 | − &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt, | |
| 3248 | − pCtx->pFrameBs + pCtx->iPosBsBuffer, | |
| 3249 | − &iNalLen[iNalIdxInLayer]); | |
| 3280 | + pCtx->iEncoderError = WelsEncodeNal (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1], | |
| 3281 | + &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt, | |
| 3282 | + pCtx->iFrameBsSize-pCtx->iPosBsBuffer, | |
| 3283 | + pCtx->pFrameBs+pCtx->iPosBsBuffer, | |
| 3284 | + &iNalLen[iNalIdxInLayer]); | |
| 3285 | + WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS) | |
| 3286 | + iSliceSize = iNalLen[iNalIdxInLayer]; | |
| 3287 | + | |
| 3250 | 3288 | iLayerSize += iSliceSize; |
| 3251 | 3289 | pCtx->iPosBsBuffer += iSliceSize; |
| 3252 | 3290 | pLayerBsInfo->uiLayerType = VIDEO_CODING_LAYER; |
| @@ -3265,7 +3303,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 12 unmodified lines | ||
| 3265 | 3303 | #endif//MT_ENABLED |
| 3266 | 3304 | { |
| 3267 | 3305 | const int32_t kiLastMbInFrame = pCtx->pCurDqLayer->pSliceEncCtx->iMbNumInFrame; |
| 3268 | − WelsCodeOnePicPartition (pCtx, pLayerBsInfo, &iNalIdxInLayer, &iLayerSize, 0, kiLastMbInFrame, 0); | |
| 3306 | + pCtx->iEncoderError = WelsCodeOnePicPartition (pCtx, pLayerBsInfo, &iNalIdxInLayer, &iLayerSize, 0, kiLastMbInFrame, 0); | |
| 3307 | + WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS) | |
| 3269 | 3308 | } else { |
| 3270 | 3309 | //other multi-slice uiSliceMode |
| 3271 | 3310 | #if defined(MT_ENABLED) |
| @@ -3283,13 +3322,13 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 11 unmodified lines | ||
| 3283 | 3322 | WelsLog (pCtx, WELS_LOG_ERROR, |
| 3284 | 3323 | "WelsEncoderEncodeExt(), iLayerNum(%d) overflow(max:%d) at iDid= %d uiSliceMode= %d, iSliceCount= %d!", |
| 3285 | 3324 | iLayerNum, MAX_LAYER_NUM_OF_FRAME, iCurDid, param_d->sSliceCfg.uiSliceMode, iSliceCount); |
| 3286 | − return -1; | |
| 3325 | + return ENC_RETURN_UNSUPPORTED_PARA; | |
| 3287 | 3326 | } |
| 3288 | 3327 | if (iSliceCount <= 1) { |
| 3289 | 3328 | WelsLog (pCtx, WELS_LOG_ERROR, |
| 3290 | 3329 | "WelsEncoderEncodeExt(), iSliceCount(%d) from GetCurrentSliceNum() is untrusted due stack/heap crupted!\n", |
| 3291 | 3330 | iSliceCount); |
| 3292 | − return -1; | |
| 3331 | + return ENC_RETURN_UNEXPECTED; | |
| 3293 | 3332 | } |
| 3294 | 3333 | |
| 3295 | 3334 | if (pSvcParam->iCountThreadsNum >= iSliceCount) { //THREAD_FULLY_FIRE_MODE |
| @@ -3313,13 +3352,15 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 17 unmodified lines | ||
| 3313 | 3352 | WelsLog (pCtx, WELS_LOG_ERROR, |
| 3314 | 3353 | "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!\n", |
| 3315 | 3354 | err, pSvcParam->iCountThreadsNum, iSliceCount, param_d->sSliceCfg.uiSliceMode, pSvcParam->iMultipleThreadIdc); |
| 3316 | − return -1; | |
| 3355 | + return ENC_RETURN_UNEXPECTED; | |
| 3317 | 3356 | } |
| 3318 | 3357 | |
| 3319 | 3358 | WelsMultipleEventsWaitAllBlocking (iSliceCount, &pCtx->pSliceThreading->pSliceCodedEvent[0]); |
| 3320 | 3359 | |
| 3321 | 3360 | |
| 3322 | 3361 | // all slices are finished coding here |
| 3362 | + WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS) | |
| 3363 | + | |
| 3323 | 3364 | // append exclusive slice 0 bs to pFrameBs |
| 3324 | 3365 | #if defined(PACKING_ONE_SLICE_PER_LAYER) |
| 3325 | 3366 | iLayerSize = pCtx->iPosBsBuffer - iOrgSlicePos[0]; |
| @@ -3372,7 +3413,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 46 unmodified lines | ||
| 3372 | 3413 | WelsLog (pCtx, WELS_LOG_ERROR, |
| 3373 | 3414 | "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!\n", |
| 3374 | 3415 | err, pSvcParam->iCountThreadsNum, iSliceCount, param_d->sSliceCfg.uiSliceMode, pSvcParam->iMultipleThreadIdc); |
| 3375 | − return -1; | |
| 3416 | + return ENC_RETURN_UNEXPECTED; | |
| 3376 | 3417 | } |
| 3377 | 3418 | |
| 3378 | 3419 | iIndexOfSliceToBeCoded = iNumThreadsRunning; |
| @@ -3408,6 +3449,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 29 unmodified lines | ||
| 3408 | 3449 | // TODO for pthread platforms |
| 3409 | 3450 | // alternate implementation using blocking due non-blocking with timeout mode not support at wels thread lib, tune back if available |
| 3410 | 3451 | WelsMultipleEventsWaitAllBlocking (iNumThreadsRunning, &pCtx->pSliceThreading->pSliceCodedEvent[0]); |
| 3452 | + WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS) | |
| 3411 | 3453 | if (iIndexOfSliceToBeCoded < iSliceCount) { |
| 3412 | 3454 | int32_t iThreadIdx = 0; |
| 3413 | 3455 | // pick up succeeding slices for threading if left |
| @@ -3464,10 +3506,11 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 50 unmodified lines | ||
| 3464 | 3506 | WelsLog (pCtx, WELS_LOG_ERROR, |
| 3465 | 3507 | "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!\n", |
| 3466 | 3508 | err, pSvcParam->iCountThreadsNum, iSliceCount, param_d->sSliceCfg.uiSliceMode, pSvcParam->iMultipleThreadIdc); |
| 3467 | − return -1; | |
| 3509 | + return ENC_RETURN_UNEXPECTED; | |
| 3468 | 3510 | } |
| 3469 | 3511 | |
| 3470 | 3512 | WelsMultipleEventsWaitAllBlocking (kiPartitionCnt, &pCtx->pSliceThreading->pSliceCodedEvent[0]); |
| 3513 | + WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS) | |
| 3471 | 3514 | |
| 3472 | 3515 | #if defined(PACKING_ONE_SLICE_PER_LAYER) |
| 3473 | 3516 | iSliceCount = PostProcDynamicSlicingBsWriting (pCtx, pLayerBsInfo, &iLayerSize, kiPartitionCnt); |
| @@ -3486,19 +3529,26 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 12 unmodified lines | ||
| 3486 | 3529 | iSliceCount = GetCurrentSliceNum (pCtx->pCurDqLayer->pSliceEncCtx); |
| 3487 | 3530 | while (iSliceIdx < iSliceCount) { |
| 3488 | 3531 | int32_t iSliceSize = 0; |
| 3489 | − | |
| 3532 | + int32_t iPayloadSize = 0; | |
| 3490 | 3533 | if (bNeedPrefix) { |
| 3491 | − iLayerSize += AddPrefixNal (pCtx, pLayerBsInfo, &iNalLen[0], &iNalIdxInLayer, eNalType, eNalRefIdc); | |
| 3534 | + pCtx->iEncoderError = AddPrefixNal (pCtx, pLayerBsInfo, &iNalLen[0], &iNalIdxInLayer, eNalType, eNalRefIdc, iPayloadSize); | |
| 3535 | + WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS) | |
| 3536 | + iLayerSize += iPayloadSize; | |
| 3492 | 3537 | } |
| 3493 | 3538 | |
| 3494 | 3539 | WelsLoadNal (pCtx->pOut, eNalType, eNalRefIdc); |
| 3495 | − WelsCodeOneSlice (pCtx, iSliceIdx, eNalType); | |
| 3540 | + pCtx->iEncoderError = WelsCodeOneSlice (pCtx, iSliceIdx, eNalType); | |
| 3541 | + WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS) | |
| 3542 | + | |
| 3496 | 3543 | WelsUnloadNal (pCtx->pOut); |
| 3497 | 3544 | |
| 3498 | − iSliceSize = WelsEncodeNalExt (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1], | |
| 3499 | − &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt, | |
| 3500 | − pCtx->pFrameBs + pCtx->iPosBsBuffer, | |
| 3501 | − &iNalLen[iNalIdxInLayer]); | |
| 3545 | + pCtx->iEncoderError = WelsEncodeNal (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1], | |
| 3546 | + &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt, | |
| 3547 | + pCtx->iFrameBsSize-pCtx->iPosBsBuffer, | |
| 3548 | + pCtx->pFrameBs+pCtx->iPosBsBuffer, &iNalLen[iNalIdxInLayer]); | |
| 3549 | + WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS) | |
| 3550 | + iSliceSize = iNalLen[iNalIdxInLayer]; | |
| 3551 | + | |
| 3502 | 3552 | pCtx->iPosBsBuffer += iSliceSize; |
| 3503 | 3553 | iLayerSize += iSliceSize; |
| 3504 | 3554 | pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize; |
| @@ -3542,8 +3592,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 37 unmodified lines | ||
| 3542 | 3592 | if (!WelsUpdateRefList (pCtx)) { |
| 3543 | 3593 | // Force coding IDR as followed |
| 3544 | 3594 | ForceCodingIDR (pCtx); |
| 3545 | − WelsLog (pCtx, WELS_LOG_WARNING, "WelsEncoderEncodeExt(), WelsUpdateRefList failed.\n"); | |
| 3546 | − return -1; | |
| 3595 | + WelsLog (pCtx, WELS_LOG_WARNING, "WelsEncoderEncodeExt(), WelsUpdateRefList failed. ForceCodingIDR!\n"); | |
| 3596 | + //the above is to set the next frame to be IDR | |
| 3597 | + pFbi->eOutputFrameType = eFrameType; | |
| 3598 | + return ENC_RETURN_CORRECTED; | |
| 3547 | 3599 | } |
| 3548 | 3600 | } |
| 3549 | 3601 | |
| @@ -3648,14 +3700,16 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 98 unmodified lines | ||
| 3648 | 3700 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer; |
| 3649 | 3701 | |
| 3650 | 3702 | if (pSvcParam->iPaddingFlag && pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingSize > 0) { |
| 3651 | − const int32_t kiPaddingNalSize = WritePadding (pCtx, pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingSize); | |
| 3703 | + int32_t iPaddingNalSize = 0; | |
| 3704 | + pCtx->iEncoderError = WritePadding (pCtx, pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingSize, iPaddingNalSize); | |
| 3705 | + WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS) | |
| 3652 | 3706 | |
| 3653 | 3707 | #if GOM_TRACE_FLAG |
| 3654 | 3708 | WelsLog (pCtx, WELS_LOG_INFO, "[RC] encoding_qp%d Padding: %d\n", pCtx->uiDependencyId, |
| 3655 | 3709 | pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingSize); |
| 3656 | 3710 | #endif |
| 3657 | − if (kiPaddingNalSize <= 0) | |
| 3658 | − return -1; | |
| 3711 | + if (iPaddingNalSize <= 0) | |
| 3712 | + return ENC_RETURN_UNEXPECTED; | |
| 3659 | 3713 | |
| 3660 | 3714 | pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingBitrateStat += pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingSize; |
| 3661 | 3715 | |
| @@ -3667,7 +3721,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 5 unmodified lines | ||
| 3667 | 3721 | pLayerBsInfo->uiQualityId = 0; |
| 3668 | 3722 | pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER; |
| 3669 | 3723 | pLayerBsInfo->iNalCount = 1; |
| 3670 | − pLayerBsInfo->iNalLengthInByte[0] = kiPaddingNalSize; | |
| 3724 | + pLayerBsInfo->iNalLengthInByte[0] = iPaddingNalSize; | |
| 3671 | 3725 | ++ pLayerBsInfo; |
| 3672 | 3726 | pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer; |
| 3673 | 3727 | ++ iLayerNum; |
| @@ -3697,7 +3751,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 23 unmodified lines | ||
| 3697 | 3751 | |
| 3698 | 3752 | if( pCtx->pVpp->UpdateSpatialPictures(pCtx, pSvcParam, iCurTid, d_idx) != 0 ){ |
| 3699 | 3753 | ForceCodingIDR(pCtx); |
| 3700 | − return -1; | |
| 3754 | + WelsLog (pCtx, WELS_LOG_WARNING, "WelsEncoderEncodeExt(), Logic Error Found in temporal level. ForceCodingIDR!\n"); | |
| 3755 | + //the above is to set the next frame IDR | |
| 3756 | + pFbi->eOutputFrameType = eFrameType; | |
| 3757 | + return ENC_RETURN_CORRECTED; | |
| 3701 | 3758 | } |
| 3702 | 3759 | |
| 3703 | 3760 | if (pSvcParam->bEnableLongTermReference && ((pCtx->pLtr[pCtx->uiDependencyId].bLTRMarkingFlag |
| @@ -3734,7 +3791,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 30 unmodified lines | ||
| 3734 | 3791 | WelsEmms(); |
| 3735 | 3792 | #endif //X86_ASM |
| 3736 | 3793 | |
| 3737 | − return eFrameType; | |
| 3794 | + pFbi->eOutputFrameType = eFrameType; | |
| 3795 | + return ENC_RETURN_SUCCESS; | |
| 3738 | 3796 | } |
| 3739 | 3797 | |
| 3740 | 3798 | /*! |
| @@ -3743,7 +3801,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 2 unmodified lines | ||
| 3743 | 3801 | */ |
| 3744 | 3802 | int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewParam) { |
| 3745 | 3803 | SWelsSvcCodingParam* pOldParam = NULL; |
| 3746 | − int32_t iReturn = 0; | |
| 3804 | + int32_t iReturn = ENC_RETURN_SUCCESS; | |
| 3747 | 3805 | int8_t iIndexD = 0; |
| 3748 | 3806 | bool bNeedReset = false; |
| 3749 | 3807 | |
| @@ -3751,7 +3809,7 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa · 1 unmodified line | ||
| 3751 | 3809 | |
| 3752 | 3810 | /* Check validation in new parameters */ |
| 3753 | 3811 | iReturn = ParamValidationExt (pNewParam); |
| 3754 | − if (iReturn != 0) return iReturn; | |
| 3812 | + if (iReturn != ENC_RETURN_SUCCESS) return iReturn; | |
| 3755 | 3813 | |
| 3756 | 3814 | pOldParam = (*ppCtx)->pSvcParam; |
| 3757 | 3815 | |
| @@ -3942,6 +4000,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 184 unmodified lines | ||
| 3942 | 4000 | const EWelsNalUnitType keNalType = pCtx->eNalType; |
| 3943 | 4001 | const EWelsNalRefIdc keNalRefIdc = pCtx->eNalPriority; |
| 3944 | 4002 | const bool kbNeedPrefix = pCtx->bNeedPrefixNalFlag; |
| 4003 | + int32_t iReturn = ENC_RETURN_SUCCESS; | |
| 3945 | 4004 | |
| 3946 | 4005 | //init |
| 3947 | 4006 | { |
| @@ -3953,25 +4012,33 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 5 unmodified lines | ||
| 3953 | 4012 | |
| 3954 | 4013 | while (iAnyMbLeftInPartition > 0) { |
| 3955 | 4014 | int32_t iSliceSize = 0; |
| 4015 | + int32_t iPayloadSize = 0; | |
| 3956 | 4016 | |
| 3957 | 4017 | if (iSliceIdx >= pSliceCtx->iMaxSliceNumConstraint) { // insufficient memory in pSliceInLayer[] |
| 3958 | 4018 | // TODO: need exception handler for not large enough of MAX_SLICES_NUM related memory usage |
| 3959 | 4019 | // No idea about its solution due MAX_SLICES_NUM is fixed lenght in relevent pData structure |
| 3960 | − return 1; | |
| 4020 | + return ENC_RETURN_MEMALLOCERR; | |
| 3961 | 4021 | } |
| 3962 | 4022 | |
| 3963 | 4023 | if (kbNeedPrefix) { |
| 3964 | − iPartitionBsSize += AddPrefixNal (pCtx, pLayerBsInfo, &iNalLen[0], &iNalIdxInLayer, keNalType, keNalRefIdc); | |
| 4024 | + iReturn = AddPrefixNal (pCtx, pLayerBsInfo, &iNalLen[0], &iNalIdxInLayer, keNalType, keNalRefIdc, iPayloadSize); | |
| 4025 | + WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS) | |
| 4026 | + iPartitionBsSize += iPayloadSize; | |
| 3965 | 4027 | } |
| 3966 | 4028 | |
| 3967 | 4029 | WelsLoadNal (pCtx->pOut, keNalType, keNalRefIdc); |
| 3968 | − WelsCodeOneSlice (pCtx, iSliceIdx, keNalType); | |
| 4030 | + iReturn=WelsCodeOneSlice (pCtx, iSliceIdx, keNalType); | |
| 4031 | + WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS) | |
| 3969 | 4032 | WelsUnloadNal (pCtx->pOut); |
| 3970 | 4033 | |
| 3971 | − iSliceSize = WelsEncodeNalExt (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1], | |
| 3972 | − &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt, | |
| 3973 | − pCtx->pFrameBs + pCtx->iPosBsBuffer, | |
| 3974 | − &iNalLen[iNalIdxInLayer]); | |
| 4034 | + iReturn = WelsEncodeNal (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1], | |
| 4035 | + &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt, | |
| 4036 | + pCtx->iFrameBsSize-pCtx->iPosBsBuffer, | |
| 4037 | + pCtx->pFrameBs+pCtx->iPosBsBuffer, | |
| 4038 | + &iNalLen[iNalIdxInLayer]); | |
| 4039 | + WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS) | |
| 4040 | + iSliceSize = iNalLen[iNalIdxInLayer]; | |
| 4041 | + | |
| 3975 | 4042 | pCtx->iPosBsBuffer += iSliceSize; |
| 3976 | 4043 | iPartitionBsSize += iSliceSize; |
| 3977 | 4044 | pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize; |
| @@ -4001,6 +4068,6 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 23 unmodified lines | ||
| 4001 | 4068 | pLayerBsInfo->uiPriorityId = 0; |
| 4002 | 4069 | pLayerBsInfo->iNalCount = iNalIdxInLayer; |
| 4003 | 4070 | |
| 4004 | − return 0; | |
| 4071 | + return ENC_RETURN_SUCCESS; | |
| 4005 | 4072 | } |
| 4006 | 4073 | } // namespace WelsSVCEnc |