History

Squashed merge from writenal_refactor2

sijchen committed 12 years ago

Commit e45e8591 parent a921bc616 files · +431 −263Browse files

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

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+167−100
@@ -140,7 +140,7 @@ int32_t ParamValidationExt (void* pParam) { · 139 unmodified lines
140140
141141 assert (pCodingParam != NULL);
142142 if (NULL == pCodingParam)
143− return 1;
143+ return ENC_RETURN_INVALIDINPUT;
144144
145145 if (pCodingParam->iSpatialLayerNum < 1 || pCodingParam->iSpatialLayerNum > MAX_DEPENDENCY_LAYER) {
146146 #if defined (_DEBUG)
@@ -148,7 +148,7 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line
148148 pCodingParam->iSpatialLayerNum);
149149 #endif//#if _DEBUG
150150
151− return 1;
151+ return ENC_RETURN_UNSUPPORTED_PARA;
152152 }
153153
154154 if (pCodingParam->iTemporalLayerNum < 1 || pCodingParam->iTemporalLayerNum > MAX_TEMPORAL_LEVEL) {
@@ -156,14 +156,14 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line
156156 fprintf (stderr, "ParamValidationExt(), monitor invalid pCodingParam->iTemporalLayerNum: %d!\n",
157157 pCodingParam->iTemporalLayerNum);
158158 #endif//#if _DEBUG
159− return 1;
159+ return ENC_RETURN_UNSUPPORTED_PARA;
160160 }
161161
162162 if (pCodingParam->uiGopSize < 1 || pCodingParam->uiGopSize > MAX_GOP_SIZE) {
163163 #if defined (_DEBUG)
164164 fprintf (stderr, "ParamValidationExt(), monitor invalid pCodingParam->uiGopSize: %d!\n", pCodingParam->uiGopSize);
165165 #endif//#if _DEBUG
166− return 1;
166+ return ENC_RETURN_UNSUPPORTED_PARA;
167167 }
168168
169169
@@ -173,7 +173,7 @@ int32_t ParamValidationExt (void* pParam) { · 3 unmodified lines
173173 "ParamValidationExt(), uiIntraPeriod(%d) should be not less than that of uiGopSize(%d) or -1 specified!\n",
174174 pCodingParam->uiIntraPeriod, pCodingParam->uiGopSize);
175175 #endif//#if _DEBUG
176− return 1;
176+ return ENC_RETURN_UNSUPPORTED_PARA;
177177 }
178178
179179 if (pCodingParam->uiIntraPeriod && (pCodingParam->uiIntraPeriod & (pCodingParam->uiGopSize - 1)) != 0) {
@@ -181,7 +181,7 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line
181181 fprintf (stderr, "ParamValidationExt(), uiIntraPeriod(%d) should be multiple of uiGopSize(%d) or -1 specified!\n",
182182 pCodingParam->uiIntraPeriod, pCodingParam->uiGopSize);
183183 #endif//#if _DEBUG
184− return 1;
184+ return ENC_RETURN_UNSUPPORTED_PARA;
185185 }
186186
187187
@@ -213,7 +213,7 @@ int32_t ParamValidationExt (void* pParam) { · 25 unmodified lines
213213 #if defined (_DEBUG)
214214 fprintf (stderr, "ParamValidationExt(), invalid %d x %d in dependency layer settings!\n", kiPicWidth, kiPicHeight);
215215 #endif//#if _DEBUG
216− return 1;
216+ return ENC_RETURN_UNSUPPORTED_PARA;
217217 }
218218 if ((kiPicWidth & 0x0F) != 0 || (kiPicHeight & 0x0F) != 0) {
219219 #if defined (_DEBUG)
@@ -221,14 +221,14 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line
221221 "ParamValidationExt(), in layer #%d iWidth x iHeight(%d x %d) both should be multiple of 16, can not support with arbitrary size currently!\n",
222222 i, kiPicWidth, kiPicHeight);
223223 #endif//#if _DEBUG
224− return 1;
224+ return ENC_RETURN_UNSUPPORTED_PARA;
225225 }
226226
227227 if (fDlp->sSliceCfg.uiSliceMode >= SM_RESERVED) {
228228 #if defined (_DEBUG)
229229 fprintf (stderr, "ParamValidationExt(), invalid uiSliceMode (%d) settings!\n", fDlp->sSliceCfg.uiSliceMode);
230230 #endif//#if _DEBUG
231− return 1;
231+ return ENC_RETURN_UNSUPPORTED_PARA;
232232 }
233233
234234 //check pSlice settings under multi-pSlice
@@ -257,7 +257,7 @@ int32_t ParamValidationExt (void* pParam) { · 22 unmodified lines
257257 #if defined (_DEBUG)
258258 fprintf (stderr, "ParamValidationExt(), invalid uiSliceNum (%d) settings!\n", fDlp->sSliceCfg.sSliceArgument.uiSliceNum);
259259 #endif//#if _DEBUG
260− return 1;
260+ return ENC_RETURN_UNSUPPORTED_PARA;
261261 }
262262 if (fDlp->sSliceCfg.sSliceArgument.uiSliceNum == 1) {
263263 #if defined (_DEBUG)
@@ -281,7 +281,7 @@ int32_t ParamValidationExt (void* pParam) { · 17 unmodified lines
281281 fprintf (stderr, "ParamValidationExt(), invalid uiSliceMbNum (%d) settings!\n",
282282 fDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[0]);
283283 #endif//#if _DEBUG
284− return 1;
284+ return ENC_RETURN_UNSUPPORTED_PARA;
285285 }
286286 // considering the coding efficient and performance, iCountMbNum constraint by MIN_NUM_MB_PER_SLICE condition of multi-pSlice mode settting
287287 if (iMbNumInFrame <= MIN_NUM_MB_PER_SLICE) {
@@ -303,7 +303,7 @@ int32_t ParamValidationExt (void* pParam) { · 15 unmodified lines
303303 fprintf (stderr, "ParamValidationExt(), invalid uiSliceMbNum (%d) settings!\n",
304304 fDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[0]);
305305 #endif//#if _DEBUG
306− return 1;
306+ return ENC_RETURN_UNSUPPORTED_PARA;
307307 }
308308
309309 if (!CheckRasterMultiSliceSetting (iMbNumInFrame, &fDlp->sSliceCfg.sSliceArgument)) { // verify interleave mode settings
@@ -311,7 +311,7 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line
311311 fprintf (stderr, "ParamValidationExt(), invalid uiSliceMbNum (%d) settings!\n",
312312 fDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[0]);
313313 #endif//#if _DEBUG
314− return 1;
314+ return ENC_RETURN_UNSUPPORTED_PARA;
315315 }
316316 if (fDlp->sSliceCfg.sSliceArgument.uiSliceNum <= 0
317317 || fDlp->sSliceCfg.sSliceArgument.uiSliceNum > iMaxSliceNum) { // verify interleave mode settings
@@ -319,7 +319,7 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line
319319 fprintf (stderr, "ParamValidationExt(), invalid uiSliceNum (%d) in SM_RASTER_SLICE settings!\n",
320320 fDlp->sSliceCfg.sSliceArgument.uiSliceNum);
321321 #endif//#if _DEBUG
322− return 1;
322+ return ENC_RETURN_UNSUPPORTED_PARA;
323323 }
324324 if (fDlp->sSliceCfg.sSliceArgument.uiSliceNum == 1) {
325325 #if defined (_DEBUG)
@@ -353,7 +353,7 @@ int32_t ParamValidationExt (void* pParam) { · 27 unmodified lines
353353 #if defined (_DEBUG)
354354 fprintf (stderr, "ParamValidationExt(), invalid uiSliceNum (%d) settings more than MAX!\n", iMbHeight);
355355 #endif//#if _DEBUG
356− return 1;
356+ return ENC_RETURN_UNSUPPORTED_PARA;
357357 }
358358 fDlp->sSliceCfg.sSliceArgument.uiSliceNum = iMbHeight;
359359
@@ -361,14 +361,14 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line
361361 #if defined (_DEBUG)
362362 fprintf (stderr, "ParamValidationExt(), invalid uiSliceNum (%d) settings!\n", fDlp->sSliceCfg.sSliceArgument.uiSliceNum);
363363 #endif//#if _DEBUG
364− return 1;
364+ return ENC_RETURN_UNSUPPORTED_PARA;
365365 }
366366 if (!CheckRowMbMultiSliceSetting (iMbWidth, &fDlp->sSliceCfg.sSliceArgument)) { // verify interleave mode settings
367367 #if defined (_DEBUG)
368368 fprintf (stderr, "ParamValidationExt(), invalid uiSliceMbNum (%d) settings!\n",
369369 fDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[0]);
370370 #endif//#if _DEBUG
371− return 1;
371+ return ENC_RETURN_UNSUPPORTED_PARA;
372372 }
373373 }
374374 break;
@@ -380,7 +380,7 @@ int32_t ParamValidationExt (void* pParam) { · 5 unmodified lines
380380 fprintf (stderr, "ParamValidationExt(), invalid iSliceSize (%d) settings!\n",
381381 fDlp->sSliceCfg.sSliceArgument.uiSliceSizeConstraint);
382382 #endif//#if _DEBUG
383− return 1;
383+ return ENC_RETURN_UNSUPPORTED_PARA;
384384 }
385385 // considering the coding efficient and performance, iCountMbNum constraint by MIN_NUM_MB_PER_SLICE condition of multi-pSlice mode settting
386386 if (iMbWidth * iMbHeight <= MIN_NUM_MB_PER_SLICE) {
@@ -396,7 +396,7 @@ int32_t ParamValidationExt (void* pParam) { · 9 unmodified lines
396396 fprintf (stderr, "ParamValidationExt(), invalid uiSliceMode (%d) settings!\n",
397397 pCodingParam->sDependencyLayers[0].sSliceCfg.uiSliceMode);
398398 #endif//#if _DEBUG
399− return 1;
399+ return ENC_RETURN_UNSUPPORTED_PARA;
400400
401401 }
402402 break;
@@ -1322,7 +1322,7 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 919 unmodified lines
13221322 while (iIndex < pParam->iSpatialLayerNum) {
13231323 SDLayerParam* fDlp = &pParam->sDependencyLayers[iIndex];
13241324
1325− fCompressRatioThr = COMPRESS_RATIO_DECIDED_BY_RESOLUTION (fDlp->iFrameWidth, fDlp->iFrameHeight);
1325+ fCompressRatioThr = COMPRESS_RATIO_THR;
13261326
13271327 iLayerBsSize = WELS_ROUND (((3 * fDlp->iFrameWidth * fDlp->iFrameHeight) >> 1) * fCompressRatioThr);
13281328 iLayerBsSize = WELS_ALIGN (iLayerBsSize, 4); // 4 bytes alinged
@@ -1339,9 +1339,9 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 10 unmodified lines
13391339 // Output
13401340 (*ppCtx)->pOut = (SWelsEncoderOutput*)pMa->WelsMalloc (sizeof (SWelsEncoderOutput), "SWelsEncoderOutput");
13411341 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");
13431343 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pOut->pBsBuffer), FreeMemorySvc (ppCtx))
1344− (*ppCtx)->pOut->uiSize = iCountBsLen;
1344+ (*ppCtx)->pOut->uiSize = iCountBsLen;
13451345 (*ppCtx)->pOut->sNalList = (SWelsNalRaw*)pMa->WelsMalloc (iCountNals * sizeof (SWelsNalRaw), "pOut->sNalList");
13461346 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pOut->sNalList), FreeMemorySvc (ppCtx))
13471347 (*ppCtx)->pOut->iCountNals = iCountNals;
@@ -1349,10 +1349,10 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 1 unmodified line
13491349
13501350 #ifdef MT_ENABLED
13511351 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");
13541354 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pFrameBs), FreeMemorySvc (ppCtx))
1355− (*ppCtx)->iFrameBsSize = iCountBsLen * (*ppCtx)->iMaxSliceCount;
1355+ (*ppCtx)->iFrameBsSize = iTotalLength;
13561356 } else
13571357 #endif//MT_ENABLED
13581358 {
@@ -2081,7 +2081,7 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 722 unmodified lines
20812081 #if defined(MEMORY_MONITOR)
20822082 WelsLog (pCtx, WELS_LOG_INFO, "WelsInitEncoderExt() exit, overall memory usage: %llu bytes\n",
20832083 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() */
20852085 );
20862086 #endif//MEMORY_MONITOR
20872087
@@ -2749,7 +2749,7 @@ void ParasetIdAdditionIdAdjust (SParaSetOffsetVariable* sParaSetOffsetVariable, · 661 unmodified lines
27492749
27502750 /*!
27512751 * \brief write all parameter sets introduced in SVC extension
2752− * \return size in bytes of bitstream wrote
2752+ * \return writing results, success or error
27532753 */
27542754 int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pNumNal) {
27552755 int32_t iSize = 0;
@@ -2757,9 +2757,11 @@ int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pN · 1 unmodified line
27572757 int32_t iIdx = 0;
27582758 int32_t iId = 0;
27592759 int32_t iCountNal = 0;
2760+ int32_t iNalLength = 0;
2761+ int32_t iReturn = ENC_RETURN_SUCCESS;
27602762
27612763 if (NULL == pCtx || NULL == pNalLen || NULL == pNumNal)
2762− return 0;
2764+ return ENC_RETURN_UNEXPECTED;
27632765
27642766 /* write all SPS */
27652767 iIdx = 0;
@@ -2804,11 +2806,15 @@ int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pN · 38 unmodified lines
28042806 WelsUnloadNal (pCtx->pOut);
28052807 }
28062808
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;
28092815
2810− pCtx->iPosBsBuffer += pNalLen[iCountNal];
2811− iSize += pNalLen[iCountNal];
2816+ pCtx->iPosBsBuffer += iNalLength;
2817+ iSize += iNalLength;
28122818
28132819 ++ iIdx;
28142820 ++ iCountNal;
@@ -2829,11 +2835,14 @@ int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pN · 14 unmodified lines
28292835 WelsWritePpsSyntax (&pCtx->pPPSArray[iIdx], &pCtx->pOut->sBsWrite, & (pCtx->sPSOVector));
28302836 WelsUnloadNal (pCtx->pOut);
28312837
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;
28372846
28382847 ++ iIdx;
28392848 ++ iCountNal;
@@ -2841,7 +2850,7 @@ int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pN · 1 unmodified line
28412850
28422851 *pNumNal = iCountNal;
28432852
2844− return iSize;
2853+ return ENC_RETURN_SUCCESS;
28452854 }
28462855
28472856 static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx,
@@ -2849,8 +2858,10 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx, · 1 unmodified line
28492858 int32_t* pNalLen,
28502859 int32_t* pNalIdxInLayer,
28512860 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;
28542865
28552866 if (keNalRefIdc != NRI_PRI_LOWEST) {
28562867 WelsLoadNal (pCtx->pOut, NAL_UNIT_PREFIX, keNalRefIdc);
@@ -2859,10 +2870,13 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx, · 2 unmodified lines
28592870
28602871 WelsUnloadNal (pCtx->pOut);
28612872
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];
28662880
28672881 pCtx->iPosBsBuffer += iPayloadSize;
28682882 pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize;
@@ -2873,10 +2887,13 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx, · 4 unmodified lines
28732887 // No need write any syntax of prefix NAL Unit RBSP here
28742888 WelsUnloadNal (pCtx->pOut);
28752889
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];
28802897
28812898 pCtx->iPosBsBuffer += iPayloadSize;
28822899 pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize;
@@ -2884,16 +2901,16 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx, · 1 unmodified line
28842901 (*pNalIdxInLayer) ++;
28852902 }
28862903
2887− return iPayloadSize;
2904+ return ENC_RETURN_SUCCESS;
28882905 }
28892906
2890−int32_t WritePadding (sWelsEncCtx* pCtx, int32_t iLen) {
2907+int32_t WritePadding (sWelsEncCtx* pCtx, int32_t iLen, int32_t& iSize) {
28912908 int32_t i = 0;
28922909 int32_t iNal = 0;
28932910 SBitStringAux* pBs = NULL;
28942911 int32_t iNalLen;
2895− int32_t iSize = 0;
28962912
2913+ iSize = 0;
28972914 iNal = pCtx->pOut->iNalIndex;
28982915 pBs = &pCtx->pOut->sBsWrite; // SBitStringAux instance for non VCL NALs decoding
28992916
@@ -2903,7 +2920,7 @@ int32_t WritePadding (sWelsEncCtx* pCtx, int32_t iLen) { · 3 unmodified lines
29032920 "[RC] paddingcal pBuffer overflow, bufferlen=%lld, paddinglen=%d, iNalIdx= %d, iCountNals= %d\n",
29042921 static_cast<long long int> (pBs->pBufEnd - pBs->pBufPtr), iLen, iNal, pCtx->pOut->iCountNals);
29052922 #endif
2906− return 0;
2923+ return ENC_RETURN_MEMOVERFLOWFOUND;
29072924 }
29082925
29092926 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
29172934 BsFlush (pBs);
29182935
29192936 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)
29212942
29222943 pCtx->iPosBsBuffer += iNalLen;
29232944 iSize += iNalLen;
29242945
2925− return iSize;
2946+ return ENC_RETURN_SUCCESS;
29262947 }
29272948
29282949 /*
@@ -3012,7 +3033,8 @@ int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) { · 83 unmodified lines
30123033 pLayerBsInfo->pBsBuf = pCtx->pFrameBs;
30133034 InitBits (&pCtx->pOut->sBsWrite, pCtx->pOut->pBsBuffer, pCtx->pOut->uiSize);
30143035
3015− WelsWriteParameterSets (pCtx, &iNalLen[0], &iCountNal);
3036+ int32_t iReturn = WelsWriteParameterSets (pCtx, &iNalLen[0], &iCountNal);
3037+ WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS)
30163038
30173039 pLayerBsInfo->uiPriorityId = 0;
30183040 pLayerBsInfo->uiSpatialId = 0;
@@ -3031,7 +3053,7 @@ int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) { · 12 unmodified lines
30313053 WelsEmms();
30323054 #endif //X86_ASM
30333055
3034− return 0;
3056+ return ENC_RETURN_SUCCESS;
30353057 }
30363058
30373059 /*!
@@ -3082,18 +3104,22 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 44 unmodified lines
30823104 int32_t i = 0, j = 0, k = 0;
30833105 #endif//_DEBUG
30843106
3107+ pCtx->iEncoderError = ENC_RETURN_SUCCESS;
30853108 pFbi->iLayerNum = 0; // for initialization
30863109
30873110 // perform csc/denoise/downsample/padding, generate spatial layers
30883111 iSpatialNum = pCtx->pVpp->BuildSpatialPicList (pCtx, ppSrcList, iConfiguredLayerNum);
30893112 if (iSpatialNum < 1) { // skip due to temporal layer settings (different frame rate)
30903113 ++ pCtx->iCodingIndex;
3091− return WELS_FRAME_TYPE_SKIP;
3114+ pFbi->eOutputFrameType = WELS_FRAME_TYPE_SKIP;
3115+ return ENC_RETURN_SUCCESS;
30923116 }
30933117
30943118 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+ }
30973123
30983124 InitFrameCoding (pCtx, eFrameType);
30993125
@@ -3108,7 +3134,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 8 unmodified lines
31083134 //if ( pSvcParam->bEnableSSEI )
31093135
31103136 // 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)
31123139
31133140 pLayerBsInfo->uiPriorityId = 0;
31143141 pLayerBsInfo->uiSpatialId = 0;
@@ -3177,7 +3204,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 62 unmodified lines
31773204 if (iLayerNum >= MAX_LAYER_NUM_OF_FRAME) { // check available layer_bs_info writing as follows
31783205 WelsLog (pCtx, WELS_LOG_ERROR, "WelsEncoderEncodeExt(), iLayerNum(%d) overflow(max:%d)!", iLayerNum,
31793206 MAX_LAYER_NUM_OF_FRAME);
3180− return -1;
3207+ return ENC_RETURN_UNSUPPORTED_PARA;
31813208 }
31823209
31833210 iNalIdxInLayer = 0;
@@ -3215,9 +3242,11 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 31 unmodified lines
32153242 if (!WelsBuildRefList (pCtx, pCtx->iPOC)) {
32163243 // Force coding IDR as followed
32173244 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",
32193246 pCtx->iNumRef0);
3220− return -1;
3247+ pFbi->eOutputFrameType = WELS_FRAME_TYPE_IDR;
3248+ pCtx->iEncoderError = ENC_RETURN_CORRECTED;
3249+ return ENC_RETURN_CORRECTED;
32213250 }
32223251 #ifdef LONG_TERM_REF_DUMP
32233252 dump_ref (pCtx);
@@ -3230,23 +3259,32 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 6 unmodified lines
32303259 PreprocessSliceCoding (pCtx); // MUST be called after pfWelsRcPictureInit() and WelsInitCurrentLayer()
32313260
32323261 iLayerSize = 0;
3262+
32333263 if (SM_SINGLE_SLICE == param_d->sSliceCfg.uiSliceMode) { // only one slice within a sQualityStat layer
32343264 int32_t iSliceSize = 0;
3265+ int32_t iPayloadSize = 0;
32353266
32363267 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;
32383271 }
32393272
32403273 WelsLoadNal (pCtx->pOut, eNalType, eNalRefIdc);
32413274
3242− WelsCodeOneSlice (pCtx, 0, eNalType);
3275+ pCtx->iEncoderError = WelsCodeOneSlice (pCtx, 0, eNalType);
3276+ WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS)
32433277
32443278 WelsUnloadNal (pCtx->pOut);
32453279
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+
32503288 iLayerSize += iSliceSize;
32513289 pCtx->iPosBsBuffer += iSliceSize;
32523290 pLayerBsInfo->uiLayerType = VIDEO_CODING_LAYER;
@@ -3265,7 +3303,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 12 unmodified lines
32653303 #endif//MT_ENABLED
32663304 {
32673305 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)
32693308 } else {
32703309 //other multi-slice uiSliceMode
32713310 #if defined(MT_ENABLED)
@@ -3283,13 +3322,13 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 11 unmodified lines
32833322 WelsLog (pCtx, WELS_LOG_ERROR,
32843323 "WelsEncoderEncodeExt(), iLayerNum(%d) overflow(max:%d) at iDid= %d uiSliceMode= %d, iSliceCount= %d!",
32853324 iLayerNum, MAX_LAYER_NUM_OF_FRAME, iCurDid, param_d->sSliceCfg.uiSliceMode, iSliceCount);
3286− return -1;
3325+ return ENC_RETURN_UNSUPPORTED_PARA;
32873326 }
32883327 if (iSliceCount <= 1) {
32893328 WelsLog (pCtx, WELS_LOG_ERROR,
32903329 "WelsEncoderEncodeExt(), iSliceCount(%d) from GetCurrentSliceNum() is untrusted due stack/heap crupted!\n",
32913330 iSliceCount);
3292− return -1;
3331+ return ENC_RETURN_UNEXPECTED;
32933332 }
32943333
32953334 if (pSvcParam->iCountThreadsNum >= iSliceCount) { //THREAD_FULLY_FIRE_MODE
@@ -3313,13 +3352,15 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 17 unmodified lines
33133352 WelsLog (pCtx, WELS_LOG_ERROR,
33143353 "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!\n",
33153354 err, pSvcParam->iCountThreadsNum, iSliceCount, param_d->sSliceCfg.uiSliceMode, pSvcParam->iMultipleThreadIdc);
3316− return -1;
3355+ return ENC_RETURN_UNEXPECTED;
33173356 }
33183357
33193358 WelsMultipleEventsWaitAllBlocking (iSliceCount, &pCtx->pSliceThreading->pSliceCodedEvent[0]);
33203359
33213360
33223361 // all slices are finished coding here
3362+ WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS)
3363+
33233364 // append exclusive slice 0 bs to pFrameBs
33243365 #if defined(PACKING_ONE_SLICE_PER_LAYER)
33253366 iLayerSize = pCtx->iPosBsBuffer - iOrgSlicePos[0];
@@ -3372,7 +3413,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 46 unmodified lines
33723413 WelsLog (pCtx, WELS_LOG_ERROR,
33733414 "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!\n",
33743415 err, pSvcParam->iCountThreadsNum, iSliceCount, param_d->sSliceCfg.uiSliceMode, pSvcParam->iMultipleThreadIdc);
3375− return -1;
3416+ return ENC_RETURN_UNEXPECTED;
33763417 }
33773418
33783419 iIndexOfSliceToBeCoded = iNumThreadsRunning;
@@ -3408,6 +3449,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 29 unmodified lines
34083449 // TODO for pthread platforms
34093450 // alternate implementation using blocking due non-blocking with timeout mode not support at wels thread lib, tune back if available
34103451 WelsMultipleEventsWaitAllBlocking (iNumThreadsRunning, &pCtx->pSliceThreading->pSliceCodedEvent[0]);
3452+ WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS)
34113453 if (iIndexOfSliceToBeCoded < iSliceCount) {
34123454 int32_t iThreadIdx = 0;
34133455 // pick up succeeding slices for threading if left
@@ -3464,10 +3506,11 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 50 unmodified lines
34643506 WelsLog (pCtx, WELS_LOG_ERROR,
34653507 "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!\n",
34663508 err, pSvcParam->iCountThreadsNum, iSliceCount, param_d->sSliceCfg.uiSliceMode, pSvcParam->iMultipleThreadIdc);
3467− return -1;
3509+ return ENC_RETURN_UNEXPECTED;
34683510 }
34693511
34703512 WelsMultipleEventsWaitAllBlocking (kiPartitionCnt, &pCtx->pSliceThreading->pSliceCodedEvent[0]);
3513+ WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS)
34713514
34723515 #if defined(PACKING_ONE_SLICE_PER_LAYER)
34733516 iSliceCount = PostProcDynamicSlicingBsWriting (pCtx, pLayerBsInfo, &iLayerSize, kiPartitionCnt);
@@ -3486,19 +3529,26 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 12 unmodified lines
34863529 iSliceCount = GetCurrentSliceNum (pCtx->pCurDqLayer->pSliceEncCtx);
34873530 while (iSliceIdx < iSliceCount) {
34883531 int32_t iSliceSize = 0;
3489−
3532+ int32_t iPayloadSize = 0;
34903533 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;
34923537 }
34933538
34943539 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+
34963543 WelsUnloadNal (pCtx->pOut);
34973544
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+
35023552 pCtx->iPosBsBuffer += iSliceSize;
35033553 iLayerSize += iSliceSize;
35043554 pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize;
@@ -3542,8 +3592,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 37 unmodified lines
35423592 if (!WelsUpdateRefList (pCtx)) {
35433593 // Force coding IDR as followed
35443594 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;
35473599 }
35483600 }
35493601
@@ -3648,14 +3700,16 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 98 unmodified lines
36483700 pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
36493701
36503702 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)
36523706
36533707 #if GOM_TRACE_FLAG
36543708 WelsLog (pCtx, WELS_LOG_INFO, "[RC] encoding_qp%d Padding: %d\n", pCtx->uiDependencyId,
36553709 pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingSize);
36563710 #endif
3657− if (kiPaddingNalSize <= 0)
3658− return -1;
3711+ if (iPaddingNalSize <= 0)
3712+ return ENC_RETURN_UNEXPECTED;
36593713
36603714 pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingBitrateStat += pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingSize;
36613715
@@ -3667,7 +3721,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 5 unmodified lines
36673721 pLayerBsInfo->uiQualityId = 0;
36683722 pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER;
36693723 pLayerBsInfo->iNalCount = 1;
3670− pLayerBsInfo->iNalLengthInByte[0] = kiPaddingNalSize;
3724+ pLayerBsInfo->iNalLengthInByte[0] = iPaddingNalSize;
36713725 ++ pLayerBsInfo;
36723726 pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
36733727 ++ iLayerNum;
@@ -3697,7 +3751,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 23 unmodified lines
36973751
36983752 if( pCtx->pVpp->UpdateSpatialPictures(pCtx, pSvcParam, iCurTid, d_idx) != 0 ){
36993753 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;
37013758 }
37023759
37033760 if (pSvcParam->bEnableLongTermReference && ((pCtx->pLtr[pCtx->uiDependencyId].bLTRMarkingFlag
@@ -3734,7 +3791,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 30 unmodified lines
37343791 WelsEmms();
37353792 #endif //X86_ASM
37363793
3737− return eFrameType;
3794+ pFbi->eOutputFrameType = eFrameType;
3795+ return ENC_RETURN_SUCCESS;
37383796 }
37393797
37403798 /*!
@@ -3743,7 +3801,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 2 unmodified lines
37433801 */
37443802 int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewParam) {
37453803 SWelsSvcCodingParam* pOldParam = NULL;
3746− int32_t iReturn = 0;
3804+ int32_t iReturn = ENC_RETURN_SUCCESS;
37473805 int8_t iIndexD = 0;
37483806 bool bNeedReset = false;
37493807
@@ -3751,7 +3809,7 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa · 1 unmodified line
37513809
37523810 /* Check validation in new parameters */
37533811 iReturn = ParamValidationExt (pNewParam);
3754− if (iReturn != 0) return iReturn;
3812+ if (iReturn != ENC_RETURN_SUCCESS) return iReturn;
37553813
37563814 pOldParam = (*ppCtx)->pSvcParam;
37573815
@@ -3942,6 +4000,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 184 unmodified lines
39424000 const EWelsNalUnitType keNalType = pCtx->eNalType;
39434001 const EWelsNalRefIdc keNalRefIdc = pCtx->eNalPriority;
39444002 const bool kbNeedPrefix = pCtx->bNeedPrefixNalFlag;
4003+ int32_t iReturn = ENC_RETURN_SUCCESS;
39454004
39464005 //init
39474006 {
@@ -3953,25 +4012,33 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 5 unmodified lines
39534012
39544013 while (iAnyMbLeftInPartition > 0) {
39554014 int32_t iSliceSize = 0;
4015+ int32_t iPayloadSize = 0;
39564016
39574017 if (iSliceIdx >= pSliceCtx->iMaxSliceNumConstraint) { // insufficient memory in pSliceInLayer[]
39584018 // TODO: need exception handler for not large enough of MAX_SLICES_NUM related memory usage
39594019 // No idea about its solution due MAX_SLICES_NUM is fixed lenght in relevent pData structure
3960− return 1;
4020+ return ENC_RETURN_MEMALLOCERR;
39614021 }
39624022
39634023 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;
39654027 }
39664028
39674029 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)
39694032 WelsUnloadNal (pCtx->pOut);
39704033
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+
39754042 pCtx->iPosBsBuffer += iSliceSize;
39764043 iPartitionBsSize += iSliceSize;
39774044 pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize;
@@ -4001,6 +4068,6 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 23 unmodified lines
40014068 pLayerBsInfo->uiPriorityId = 0;
40024069 pLayerBsInfo->iNalCount = iNalIdxInLayer;
40034070
4004− return 0;
4071+ return ENC_RETURN_SUCCESS;
40054072 }
40064073 } // namespace WelsSVCEnc

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