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
140 140
141 assert (pCodingParam != NULL);141 assert (pCodingParam != NULL);
142 if (NULL == pCodingParam)142 if (NULL == pCodingParam)
143 return 1;143 return ENC_RETURN_INVALIDINPUT;
144 144
145 if (pCodingParam->iSpatialLayerNum < 1 || pCodingParam->iSpatialLayerNum > MAX_DEPENDENCY_LAYER) {145 if (pCodingParam->iSpatialLayerNum < 1 || pCodingParam->iSpatialLayerNum > MAX_DEPENDENCY_LAYER) {
146#if defined (_DEBUG)146#if defined (_DEBUG)
@@ -148,7 +148,7 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line
148 pCodingParam->iSpatialLayerNum);148 pCodingParam->iSpatialLayerNum);
149#endif//#if _DEBUG149#endif//#if _DEBUG
150 150
151 return 1;151 return ENC_RETURN_UNSUPPORTED_PARA;
152 }152 }
153 153
154 if (pCodingParam->iTemporalLayerNum < 1 || pCodingParam->iTemporalLayerNum > MAX_TEMPORAL_LEVEL) {154 if (pCodingParam->iTemporalLayerNum < 1 || pCodingParam->iTemporalLayerNum > MAX_TEMPORAL_LEVEL) {
@@ -156,14 +156,14 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line
156 fprintf (stderr, "ParamValidationExt(), monitor invalid pCodingParam->iTemporalLayerNum: %d!\n",156 fprintf (stderr, "ParamValidationExt(), monitor invalid pCodingParam->iTemporalLayerNum: %d!\n",
157 pCodingParam->iTemporalLayerNum);157 pCodingParam->iTemporalLayerNum);
158#endif//#if _DEBUG158#endif//#if _DEBUG
159 return 1;159 return ENC_RETURN_UNSUPPORTED_PARA;
160 }160 }
161 161
162 if (pCodingParam->uiGopSize < 1 || pCodingParam->uiGopSize > MAX_GOP_SIZE) {162 if (pCodingParam->uiGopSize < 1 || pCodingParam->uiGopSize > MAX_GOP_SIZE) {
163#if defined (_DEBUG)163#if defined (_DEBUG)
164 fprintf (stderr, "ParamValidationExt(), monitor invalid pCodingParam->uiGopSize: %d!\n", pCodingParam->uiGopSize);164 fprintf (stderr, "ParamValidationExt(), monitor invalid pCodingParam->uiGopSize: %d!\n", pCodingParam->uiGopSize);
165#endif//#if _DEBUG165#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 "ParamValidationExt(), uiIntraPeriod(%d) should be not less than that of uiGopSize(%d) or -1 specified!\n",173 "ParamValidationExt(), uiIntraPeriod(%d) should be not less than that of uiGopSize(%d) or -1 specified!\n",
174 pCodingParam->uiIntraPeriod, pCodingParam->uiGopSize);174 pCodingParam->uiIntraPeriod, pCodingParam->uiGopSize);
175#endif//#if _DEBUG175#endif//#if _DEBUG
176 return 1;176 return ENC_RETURN_UNSUPPORTED_PARA;
177 }177 }
178 178
179 if (pCodingParam->uiIntraPeriod && (pCodingParam->uiIntraPeriod & (pCodingParam->uiGopSize - 1)) != 0) {179 if (pCodingParam->uiIntraPeriod && (pCodingParam->uiIntraPeriod & (pCodingParam->uiGopSize - 1)) != 0) {
@@ -181,7 +181,7 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line
181 fprintf (stderr, "ParamValidationExt(), uiIntraPeriod(%d) should be multiple of uiGopSize(%d) or -1 specified!\n",181 fprintf (stderr, "ParamValidationExt(), uiIntraPeriod(%d) should be multiple of uiGopSize(%d) or -1 specified!\n",
182 pCodingParam->uiIntraPeriod, pCodingParam->uiGopSize);182 pCodingParam->uiIntraPeriod, pCodingParam->uiGopSize);
183#endif//#if _DEBUG183#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#if defined (_DEBUG)213#if defined (_DEBUG)
214 fprintf (stderr, "ParamValidationExt(), invalid %d x %d in dependency layer settings!\n", kiPicWidth, kiPicHeight);214 fprintf (stderr, "ParamValidationExt(), invalid %d x %d in dependency layer settings!\n", kiPicWidth, kiPicHeight);
215#endif//#if _DEBUG215#endif//#if _DEBUG
216 return 1;216 return ENC_RETURN_UNSUPPORTED_PARA;
217 }217 }
218 if ((kiPicWidth & 0x0F) != 0 || (kiPicHeight & 0x0F) != 0) {218 if ((kiPicWidth & 0x0F) != 0 || (kiPicHeight & 0x0F) != 0) {
219#if defined (_DEBUG)219#if defined (_DEBUG)
@@ -221,14 +221,14 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line
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",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 i, kiPicWidth, kiPicHeight);222 i, kiPicWidth, kiPicHeight);
223#endif//#if _DEBUG223#endif//#if _DEBUG
224 return 1;224 return ENC_RETURN_UNSUPPORTED_PARA;
225 }225 }
226 226
227 if (fDlp->sSliceCfg.uiSliceMode >= SM_RESERVED) {227 if (fDlp->sSliceCfg.uiSliceMode >= SM_RESERVED) {
228#if defined (_DEBUG)228#if defined (_DEBUG)
229 fprintf (stderr, "ParamValidationExt(), invalid uiSliceMode (%d) settings!\n", fDlp->sSliceCfg.uiSliceMode);229 fprintf (stderr, "ParamValidationExt(), invalid uiSliceMode (%d) settings!\n", fDlp->sSliceCfg.uiSliceMode);
230#endif//#if _DEBUG230#endif//#if _DEBUG
231 return 1;231 return ENC_RETURN_UNSUPPORTED_PARA;
232 }232 }
233 233
234 //check pSlice settings under multi-pSlice234 //check pSlice settings under multi-pSlice
@@ -257,7 +257,7 @@ int32_t ParamValidationExt (void* pParam) { · 22 unmodified lines
257#if defined (_DEBUG)257#if defined (_DEBUG)
258 fprintf (stderr, "ParamValidationExt(), invalid uiSliceNum (%d) settings!\n", fDlp->sSliceCfg.sSliceArgument.uiSliceNum);258 fprintf (stderr, "ParamValidationExt(), invalid uiSliceNum (%d) settings!\n", fDlp->sSliceCfg.sSliceArgument.uiSliceNum);
259#endif//#if _DEBUG259#endif//#if _DEBUG
260 return 1;260 return ENC_RETURN_UNSUPPORTED_PARA;
261 }261 }
262 if (fDlp->sSliceCfg.sSliceArgument.uiSliceNum == 1) {262 if (fDlp->sSliceCfg.sSliceArgument.uiSliceNum == 1) {
263#if defined (_DEBUG)263#if defined (_DEBUG)
@@ -281,7 +281,7 @@ int32_t ParamValidationExt (void* pParam) { · 17 unmodified lines
281 fprintf (stderr, "ParamValidationExt(), invalid uiSliceMbNum (%d) settings!\n",281 fprintf (stderr, "ParamValidationExt(), invalid uiSliceMbNum (%d) settings!\n",
282 fDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[0]);282 fDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[0]);
283#endif//#if _DEBUG283#endif//#if _DEBUG
284 return 1;284 return ENC_RETURN_UNSUPPORTED_PARA;
285 }285 }
286 // considering the coding efficient and performance, iCountMbNum constraint by MIN_NUM_MB_PER_SLICE condition of multi-pSlice mode settting286 // considering the coding efficient and performance, iCountMbNum constraint by MIN_NUM_MB_PER_SLICE condition of multi-pSlice mode settting
287 if (iMbNumInFrame <= MIN_NUM_MB_PER_SLICE) {287 if (iMbNumInFrame <= MIN_NUM_MB_PER_SLICE) {
@@ -303,7 +303,7 @@ int32_t ParamValidationExt (void* pParam) { · 15 unmodified lines
303 fprintf (stderr, "ParamValidationExt(), invalid uiSliceMbNum (%d) settings!\n",303 fprintf (stderr, "ParamValidationExt(), invalid uiSliceMbNum (%d) settings!\n",
304 fDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[0]);304 fDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[0]);
305#endif//#if _DEBUG305#endif//#if _DEBUG
306 return 1;306 return ENC_RETURN_UNSUPPORTED_PARA;
307 }307 }
308 308
309 if (!CheckRasterMultiSliceSetting (iMbNumInFrame, &fDlp->sSliceCfg.sSliceArgument)) { // verify interleave mode settings309 if (!CheckRasterMultiSliceSetting (iMbNumInFrame, &fDlp->sSliceCfg.sSliceArgument)) { // verify interleave mode settings
@@ -311,7 +311,7 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line
311 fprintf (stderr, "ParamValidationExt(), invalid uiSliceMbNum (%d) settings!\n",311 fprintf (stderr, "ParamValidationExt(), invalid uiSliceMbNum (%d) settings!\n",
312 fDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[0]);312 fDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[0]);
313#endif//#if _DEBUG313#endif//#if _DEBUG
314 return 1;314 return ENC_RETURN_UNSUPPORTED_PARA;
315 }315 }
316 if (fDlp->sSliceCfg.sSliceArgument.uiSliceNum <= 0316 if (fDlp->sSliceCfg.sSliceArgument.uiSliceNum <= 0
317 || fDlp->sSliceCfg.sSliceArgument.uiSliceNum > iMaxSliceNum) { // verify interleave mode settings317 || fDlp->sSliceCfg.sSliceArgument.uiSliceNum > iMaxSliceNum) { // verify interleave mode settings
@@ -319,7 +319,7 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line
319 fprintf (stderr, "ParamValidationExt(), invalid uiSliceNum (%d) in SM_RASTER_SLICE settings!\n",319 fprintf (stderr, "ParamValidationExt(), invalid uiSliceNum (%d) in SM_RASTER_SLICE settings!\n",
320 fDlp->sSliceCfg.sSliceArgument.uiSliceNum);320 fDlp->sSliceCfg.sSliceArgument.uiSliceNum);
321#endif//#if _DEBUG321#endif//#if _DEBUG
322 return 1;322 return ENC_RETURN_UNSUPPORTED_PARA;
323 }323 }
324 if (fDlp->sSliceCfg.sSliceArgument.uiSliceNum == 1) {324 if (fDlp->sSliceCfg.sSliceArgument.uiSliceNum == 1) {
325#if defined (_DEBUG)325#if defined (_DEBUG)
@@ -353,7 +353,7 @@ int32_t ParamValidationExt (void* pParam) { · 27 unmodified lines
353#if defined (_DEBUG)353#if defined (_DEBUG)
354 fprintf (stderr, "ParamValidationExt(), invalid uiSliceNum (%d) settings more than MAX!\n", iMbHeight);354 fprintf (stderr, "ParamValidationExt(), invalid uiSliceNum (%d) settings more than MAX!\n", iMbHeight);
355#endif//#if _DEBUG355#endif//#if _DEBUG
356 return 1;356 return ENC_RETURN_UNSUPPORTED_PARA;
357 }357 }
358 fDlp->sSliceCfg.sSliceArgument.uiSliceNum = iMbHeight;358 fDlp->sSliceCfg.sSliceArgument.uiSliceNum = iMbHeight;
359 359
@@ -361,14 +361,14 @@ int32_t ParamValidationExt (void* pParam) { · 1 unmodified line
361#if defined (_DEBUG)361#if defined (_DEBUG)
362 fprintf (stderr, "ParamValidationExt(), invalid uiSliceNum (%d) settings!\n", fDlp->sSliceCfg.sSliceArgument.uiSliceNum);362 fprintf (stderr, "ParamValidationExt(), invalid uiSliceNum (%d) settings!\n", fDlp->sSliceCfg.sSliceArgument.uiSliceNum);
363#endif//#if _DEBUG363#endif//#if _DEBUG
364 return 1;364 return ENC_RETURN_UNSUPPORTED_PARA;
365 }365 }
366 if (!CheckRowMbMultiSliceSetting (iMbWidth, &fDlp->sSliceCfg.sSliceArgument)) { // verify interleave mode settings366 if (!CheckRowMbMultiSliceSetting (iMbWidth, &fDlp->sSliceCfg.sSliceArgument)) { // verify interleave mode settings
367#if defined (_DEBUG)367#if defined (_DEBUG)
368 fprintf (stderr, "ParamValidationExt(), invalid uiSliceMbNum (%d) settings!\n",368 fprintf (stderr, "ParamValidationExt(), invalid uiSliceMbNum (%d) settings!\n",
369 fDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[0]);369 fDlp->sSliceCfg.sSliceArgument.uiSliceMbNum[0]);
370#endif//#if _DEBUG370#endif//#if _DEBUG
371 return 1;371 return ENC_RETURN_UNSUPPORTED_PARA;
372 }372 }
373 }373 }
374 break;374 break;
@@ -380,7 +380,7 @@ int32_t ParamValidationExt (void* pParam) { · 5 unmodified lines
380 fprintf (stderr, "ParamValidationExt(), invalid iSliceSize (%d) settings!\n",380 fprintf (stderr, "ParamValidationExt(), invalid iSliceSize (%d) settings!\n",
381 fDlp->sSliceCfg.sSliceArgument.uiSliceSizeConstraint);381 fDlp->sSliceCfg.sSliceArgument.uiSliceSizeConstraint);
382#endif//#if _DEBUG382#endif//#if _DEBUG
383 return 1;383 return ENC_RETURN_UNSUPPORTED_PARA;
384 }384 }
385 // considering the coding efficient and performance, iCountMbNum constraint by MIN_NUM_MB_PER_SLICE condition of multi-pSlice mode settting385 // considering the coding efficient and performance, iCountMbNum constraint by MIN_NUM_MB_PER_SLICE condition of multi-pSlice mode settting
386 if (iMbWidth * iMbHeight <= MIN_NUM_MB_PER_SLICE) {386 if (iMbWidth * iMbHeight <= MIN_NUM_MB_PER_SLICE) {
@@ -396,7 +396,7 @@ int32_t ParamValidationExt (void* pParam) { · 9 unmodified lines
396 fprintf (stderr, "ParamValidationExt(), invalid uiSliceMode (%d) settings!\n",396 fprintf (stderr, "ParamValidationExt(), invalid uiSliceMode (%d) settings!\n",
397 pCodingParam->sDependencyLayers[0].sSliceCfg.uiSliceMode);397 pCodingParam->sDependencyLayers[0].sSliceCfg.uiSliceMode);
398#endif//#if _DEBUG398#endif//#if _DEBUG
399 return 1;399 return ENC_RETURN_UNSUPPORTED_PARA;
400 400
401 }401 }
402 break;402 break;
@@ -1322,7 +1322,7 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 919 unmodified lines
1322 while (iIndex < pParam->iSpatialLayerNum) {1322 while (iIndex < pParam->iSpatialLayerNum) {
1323 SDLayerParam* fDlp = &pParam->sDependencyLayers[iIndex];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 iLayerBsSize = WELS_ROUND (((3 * fDlp->iFrameWidth * fDlp->iFrameHeight) >> 1) * fCompressRatioThr);1327 iLayerBsSize = WELS_ROUND (((3 * fDlp->iFrameWidth * fDlp->iFrameHeight) >> 1) * fCompressRatioThr);
1328 iLayerBsSize = WELS_ALIGN (iLayerBsSize, 4); // 4 bytes alinged1328 iLayerBsSize = WELS_ALIGN (iLayerBsSize, 4); // 4 bytes alinged
@@ -1339,9 +1339,9 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 10 unmodified lines
1339 // Output1339 // Output
1340 (*ppCtx)->pOut = (SWelsEncoderOutput*)pMa->WelsMalloc (sizeof (SWelsEncoderOutput), "SWelsEncoderOutput");1340 (*ppCtx)->pOut = (SWelsEncoderOutput*)pMa->WelsMalloc (sizeof (SWelsEncoderOutput), "SWelsEncoderOutput");
1341 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pOut), FreeMemorySvc (ppCtx))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 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pOut->pBsBuffer), FreeMemorySvc (ppCtx))1343 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pOut->pBsBuffer), FreeMemorySvc (ppCtx))
1344 (*ppCtx)->pOut->uiSize = iCountBsLen;1344 (*ppCtx)->pOut->uiSize = iCountBsLen;
1345 (*ppCtx)->pOut->sNalList = (SWelsNalRaw*)pMa->WelsMalloc (iCountNals * sizeof (SWelsNalRaw), "pOut->sNalList");1345 (*ppCtx)->pOut->sNalList = (SWelsNalRaw*)pMa->WelsMalloc (iCountNals * sizeof (SWelsNalRaw), "pOut->sNalList");
1346 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pOut->sNalList), FreeMemorySvc (ppCtx))1346 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pOut->sNalList), FreeMemorySvc (ppCtx))
1347 (*ppCtx)->pOut->iCountNals = iCountNals;1347 (*ppCtx)->pOut->iCountNals = iCountNals;
@@ -1349,10 +1349,10 @@ int32_t RequestMemorySvc (sWelsEncCtx** ppCtx) { · 1 unmodified line
1349 1349
1350#ifdef MT_ENABLED1350#ifdef MT_ENABLED
1351 if (pParam->iMultipleThreadIdc > 1) {1351 if (pParam->iMultipleThreadIdc > 1) {
1352 (*ppCtx)->pFrameBs = (uint8_t*)pMa->WelsMalloc (iCountBsLen + (iTargetSpatialBsSize * ((*ppCtx)->iMaxSliceCount - 1)),1352 const int32_t iTotalLength = iCountBsLen + (iTargetSpatialBsSize * ((*ppCtx)->iMaxSliceCount - 1));
1353 "pFrameBs");1353 (*ppCtx)->pFrameBs = (uint8_t*)pMa->WelsMalloc (iTotalLength, "pFrameBs");
1354 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pFrameBs), FreeMemorySvc (ppCtx))1354 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == (*ppCtx)->pFrameBs), FreeMemorySvc (ppCtx))
1355 (*ppCtx)->iFrameBsSize = iCountBsLen * (*ppCtx)->iMaxSliceCount;1355 (*ppCtx)->iFrameBsSize = iTotalLength;
1356 } else1356 } else
1357#endif//MT_ENABLED1357#endif//MT_ENABLED
1358 {1358 {
@@ -2081,7 +2081,7 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 722 unmodified lines
2081#if defined(MEMORY_MONITOR)2081#if defined(MEMORY_MONITOR)
2082 WelsLog (pCtx, WELS_LOG_INFO, "WelsInitEncoderExt() exit, overall memory usage: %llu bytes\n",2082 WelsLog (pCtx, WELS_LOG_INFO, "WelsInitEncoderExt() exit, overall memory usage: %llu bytes\n",
2083 static_cast<unsigned long long> (sizeof (sWelsEncCtx) /* requested size from malloc() or new operator */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#endif//MEMORY_MONITOR2086#endif//MEMORY_MONITOR
2087 2087
@@ -2749,7 +2749,7 @@ void ParasetIdAdditionIdAdjust (SParaSetOffsetVariable* sParaSetOffsetVariable, · 661 unmodified lines
2749 2749
2750/*!2750/*!
2751 * \brief write all parameter sets introduced in SVC extension2751 * \brief write all parameter sets introduced in SVC extension
2752 * \return size in bytes of bitstream wrote2752 * \return writing results, success or error
2753 */2753 */
2754int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pNumNal) {2754int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pNumNal) {
2755 int32_t iSize = 0;2755 int32_t iSize = 0;
@@ -2757,9 +2757,11 @@ int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pN · 1 unmodified line
2757 int32_t iIdx = 0;2757 int32_t iIdx = 0;
2758 int32_t iId = 0;2758 int32_t iId = 0;
2759 int32_t iCountNal = 0;2759 int32_t iCountNal = 0;
2760 int32_t iNalLength = 0;
2761 int32_t iReturn = ENC_RETURN_SUCCESS;
2760 2762
2761 if (NULL == pCtx || NULL == pNalLen || NULL == pNumNal)2763 if (NULL == pCtx || NULL == pNalLen || NULL == pNumNal)
2762 return 0;2764 return ENC_RETURN_UNEXPECTED;
2763 2765
2764 /* write all SPS */2766 /* write all SPS */
2765 iIdx = 0;2767 iIdx = 0;
@@ -2804,11 +2806,15 @@ int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pN · 38 unmodified lines
2804 WelsUnloadNal (pCtx->pOut);2806 WelsUnloadNal (pCtx->pOut);
2805 }2807 }
2806 2808
2807 pNalLen[iCountNal] = WelsEncodeNal (&pCtx->pOut->sNalList[iNal], pCtx->pFrameBs + pCtx->iPosBsBuffer,2809 iReturn = WelsEncodeNal (&pCtx->pOut->sNalList[iNal], NULL,
2808 &pNalLen[iCountNal]);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];2816 pCtx->iPosBsBuffer += iNalLength;
2811 iSize += pNalLen[iCountNal];2817 iSize += iNalLength;
2812 2818
2813 ++ iIdx;2819 ++ iIdx;
2814 ++ iCountNal;2820 ++ iCountNal;
@@ -2829,11 +2835,14 @@ int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pN · 14 unmodified lines
2829 WelsWritePpsSyntax (&pCtx->pPPSArray[iIdx], &pCtx->pOut->sBsWrite, & (pCtx->sPSOVector));2835 WelsWritePpsSyntax (&pCtx->pPPSArray[iIdx], &pCtx->pOut->sBsWrite, & (pCtx->sPSOVector));
2830 WelsUnloadNal (pCtx->pOut);2836 WelsUnloadNal (pCtx->pOut);
2831 2837
2832 pNalLen[iCountNal] = WelsEncodeNal (&pCtx->pOut->sNalList[iNal], pCtx->pFrameBs + pCtx->iPosBsBuffer,2838 iReturn = WelsEncodeNal (&pCtx->pOut->sNalList[iNal], NULL,
2833 &pNalLen[iCountNal]);2839 pCtx->iFrameBsSize - pCtx->iPosBsBuffer,
2834 2840 pCtx->pFrameBs + pCtx->iPosBsBuffer,
2835 pCtx->iPosBsBuffer += pNalLen[iCountNal];2841 &iNalLength);
2836 iSize += pNalLen[iCountNal];2842 WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS)
2843 pNalLen[iCountNal] = iNalLength;
2844 pCtx->iPosBsBuffer += iNalLength;
2845 iSize += iNalLength;
2837 2846
2838 ++ iIdx;2847 ++ iIdx;
2839 ++ iCountNal;2848 ++ iCountNal;
@@ -2841,7 +2850,7 @@ int32_t WelsWriteParameterSets (sWelsEncCtx* pCtx, int32_t* pNalLen, int32_t* pN · 1 unmodified line
2841 2850
2842 *pNumNal = iCountNal;2851 *pNumNal = iCountNal;
2843 2852
2844 return iSize;2853 return ENC_RETURN_SUCCESS;
2845}2854}
2846 2855
2847static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx,2856static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx,
@@ -2849,8 +2858,10 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx, · 1 unmodified line
2849 int32_t* pNalLen,2858 int32_t* pNalLen,
2850 int32_t* pNalIdxInLayer,2859 int32_t* pNalIdxInLayer,
2851 const EWelsNalUnitType keNalType,2860 const EWelsNalUnitType keNalType,
2852 const EWelsNalRefIdc keNalRefIdc) {2861 const EWelsNalRefIdc keNalRefIdc,
2853 int32_t iPayloadSize = 0;2862 int32_t& iPayloadSize) {
2863 int32_t iReturn = ENC_RETURN_SUCCESS;
2864 iPayloadSize = 0;
2854 2865
2855 if (keNalRefIdc != NRI_PRI_LOWEST) {2866 if (keNalRefIdc != NRI_PRI_LOWEST) {
2856 WelsLoadNal (pCtx->pOut, NAL_UNIT_PREFIX, keNalRefIdc);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 WelsUnloadNal (pCtx->pOut);2871 WelsUnloadNal (pCtx->pOut);
2861 2872
2862 iPayloadSize = WelsEncodeNalExt (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1],2873 iReturn = WelsEncodeNal (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1],
2863 &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt,2874 &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt,
2864 pCtx->pFrameBs + pCtx->iPosBsBuffer,2875 pCtx->iFrameBsSize-pCtx->iPosBsBuffer,
2865 &pNalLen[*pNalIdxInLayer]);2876 pCtx->pFrameBs+pCtx->iPosBsBuffer,
2877 &pNalLen[*pNalIdxInLayer]);
2878 WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS)
2879 iPayloadSize = pNalLen[*pNalIdxInLayer];
2866 2880
2867 pCtx->iPosBsBuffer += iPayloadSize;2881 pCtx->iPosBsBuffer += iPayloadSize;
2868 pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize;2882 pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize;
@@ -2873,10 +2887,13 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx, · 4 unmodified lines
2873 // No need write any syntax of prefix NAL Unit RBSP here2887 // No need write any syntax of prefix NAL Unit RBSP here
2874 WelsUnloadNal (pCtx->pOut);2888 WelsUnloadNal (pCtx->pOut);
2875 2889
2876 iPayloadSize = WelsEncodeNalExt (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1],2890 iReturn = WelsEncodeNal (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1],
2877 &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt,2891 &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt,
2878 pCtx->pFrameBs + pCtx->iPosBsBuffer,2892 pCtx->iFrameBsSize-pCtx->iPosBsBuffer,
2879 &pNalLen[*pNalIdxInLayer]);2893 pCtx->pFrameBs+pCtx->iPosBsBuffer,
2894 &pNalLen[*pNalIdxInLayer]);
2895 WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS)
2896 iPayloadSize = pNalLen[*pNalIdxInLayer];
2880 2897
2881 pCtx->iPosBsBuffer += iPayloadSize;2898 pCtx->iPosBsBuffer += iPayloadSize;
2882 pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize;2899 pLayerBsInfo->iNalLengthInByte[*pNalIdxInLayer] = iPayloadSize;
@@ -2884,16 +2901,16 @@ static inline int32_t AddPrefixNal (sWelsEncCtx* pCtx, · 1 unmodified line
2884 (*pNalIdxInLayer) ++;2901 (*pNalIdxInLayer) ++;
2885 }2902 }
2886 2903
2887 return iPayloadSize;2904 return ENC_RETURN_SUCCESS;
2888}2905}
2889 2906
2890int32_t WritePadding (sWelsEncCtx* pCtx, int32_t iLen) {2907int32_t WritePadding (sWelsEncCtx* pCtx, int32_t iLen, int32_t& iSize) {
2891 int32_t i = 0;2908 int32_t i = 0;
2892 int32_t iNal = 0;2909 int32_t iNal = 0;
2893 SBitStringAux* pBs = NULL;2910 SBitStringAux* pBs = NULL;
2894 int32_t iNalLen;2911 int32_t iNalLen;
2895 int32_t iSize = 0;
2896 2912
2913 iSize = 0;
2897 iNal = pCtx->pOut->iNalIndex;2914 iNal = pCtx->pOut->iNalIndex;
2898 pBs = &pCtx->pOut->sBsWrite; // SBitStringAux instance for non VCL NALs decoding2915 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 "[RC] paddingcal pBuffer overflow, bufferlen=%lld, paddinglen=%d, iNalIdx= %d, iCountNals= %d\n",2920 "[RC] paddingcal pBuffer overflow, bufferlen=%lld, paddinglen=%d, iNalIdx= %d, iCountNals= %d\n",
2904 static_cast<long long int> (pBs->pBufEnd - pBs->pBufPtr), iLen, iNal, pCtx->pOut->iCountNals);2921 static_cast<long long int> (pBs->pBufEnd - pBs->pBufPtr), iLen, iNal, pCtx->pOut->iCountNals);
2905#endif2922#endif
2906 return 0;2923 return ENC_RETURN_MEMOVERFLOWFOUND;
2907 }2924 }
2908 2925
2909 WelsLoadNal (pCtx->pOut, NAL_UNIT_FILLER_DATA, NRI_PRI_LOWEST);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 BsFlush (pBs);2934 BsFlush (pBs);
2918 2935
2919 WelsUnloadNal (pCtx->pOut);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 pCtx->iPosBsBuffer += iNalLen;2943 pCtx->iPosBsBuffer += iNalLen;
2923 iSize += iNalLen;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 pLayerBsInfo->pBsBuf = pCtx->pFrameBs;3033 pLayerBsInfo->pBsBuf = pCtx->pFrameBs;
3013 InitBits (&pCtx->pOut->sBsWrite, pCtx->pOut->pBsBuffer, pCtx->pOut->uiSize);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 pLayerBsInfo->uiPriorityId = 0;3039 pLayerBsInfo->uiPriorityId = 0;
3018 pLayerBsInfo->uiSpatialId = 0;3040 pLayerBsInfo->uiSpatialId = 0;
@@ -3031,7 +3053,7 @@ int32_t WelsEncoderEncodeParameterSets (sWelsEncCtx* pCtx, void* pDst) { · 12 unmodified lines
3031 WelsEmms();3053 WelsEmms();
3032#endif //X86_ASM3054#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 int32_t i = 0, j = 0, k = 0;3104 int32_t i = 0, j = 0, k = 0;
3083#endif//_DEBUG3105#endif//_DEBUG
3084 3106
3107 pCtx->iEncoderError = ENC_RETURN_SUCCESS;
3085 pFbi->iLayerNum = 0; // for initialization3108 pFbi->iLayerNum = 0; // for initialization
3086 3109
3087 // perform csc/denoise/downsample/padding, generate spatial layers3110 // perform csc/denoise/downsample/padding, generate spatial layers
3088 iSpatialNum = pCtx->pVpp->BuildSpatialPicList (pCtx, ppSrcList, iConfiguredLayerNum);3111 iSpatialNum = pCtx->pVpp->BuildSpatialPicList (pCtx, ppSrcList, iConfiguredLayerNum);
3089 if (iSpatialNum < 1) { // skip due to temporal layer settings (different frame rate)3112 if (iSpatialNum < 1) { // skip due to temporal layer settings (different frame rate)
3090 ++ pCtx->iCodingIndex;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 eFrameType = DecideFrameType (pCtx, iSpatialNum);3118 eFrameType = DecideFrameType (pCtx, iSpatialNum);
3095 if (eFrameType == WELS_FRAME_TYPE_SKIP)3119 if (eFrameType == WELS_FRAME_TYPE_SKIP) {
3096 return eFrameType;3120 pFbi->eOutputFrameType = eFrameType;
3121 return ENC_RETURN_SUCCESS;
3122 }
3097 3123
3098 InitFrameCoding (pCtx, eFrameType);3124 InitFrameCoding (pCtx, eFrameType);
3099 3125
@@ -3108,7 +3134,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 8 unmodified lines
3108 //if ( pSvcParam->bEnableSSEI )3134 //if ( pSvcParam->bEnableSSEI )
3109 3135
3110 // write parameter sets bitstream here3136 // 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 pLayerBsInfo->uiPriorityId = 0;3140 pLayerBsInfo->uiPriorityId = 0;
3114 pLayerBsInfo->uiSpatialId = 0;3141 pLayerBsInfo->uiSpatialId = 0;
@@ -3177,7 +3204,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 62 unmodified lines
3177 if (iLayerNum >= MAX_LAYER_NUM_OF_FRAME) { // check available layer_bs_info writing as follows3204 if (iLayerNum >= MAX_LAYER_NUM_OF_FRAME) { // check available layer_bs_info writing as follows
3178 WelsLog (pCtx, WELS_LOG_ERROR, "WelsEncoderEncodeExt(), iLayerNum(%d) overflow(max:%d)!", iLayerNum,3205 WelsLog (pCtx, WELS_LOG_ERROR, "WelsEncoderEncodeExt(), iLayerNum(%d) overflow(max:%d)!", iLayerNum,
3179 MAX_LAYER_NUM_OF_FRAME);3206 MAX_LAYER_NUM_OF_FRAME);
3180 return -1;3207 return ENC_RETURN_UNSUPPORTED_PARA;
3181 }3208 }
3182 3209
3183 iNalIdxInLayer = 0;3210 iNalIdxInLayer = 0;
@@ -3215,9 +3242,11 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 31 unmodified lines
3215 if (!WelsBuildRefList (pCtx, pCtx->iPOC)) {3242 if (!WelsBuildRefList (pCtx, pCtx->iPOC)) {
3216 // Force coding IDR as followed3243 // Force coding IDR as followed
3217 ForceCodingIDR (pCtx);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 pCtx->iNumRef0);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#ifdef LONG_TERM_REF_DUMP3251#ifdef LONG_TERM_REF_DUMP
3223 dump_ref (pCtx);3252 dump_ref (pCtx);
@@ -3230,23 +3259,32 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 6 unmodified lines
3230 PreprocessSliceCoding (pCtx); // MUST be called after pfWelsRcPictureInit() and WelsInitCurrentLayer()3259 PreprocessSliceCoding (pCtx); // MUST be called after pfWelsRcPictureInit() and WelsInitCurrentLayer()
3231 3260
3232 iLayerSize = 0;3261 iLayerSize = 0;
3262
3233 if (SM_SINGLE_SLICE == param_d->sSliceCfg.uiSliceMode) { // only one slice within a sQualityStat layer3263 if (SM_SINGLE_SLICE == param_d->sSliceCfg.uiSliceMode) { // only one slice within a sQualityStat layer
3234 int32_t iSliceSize = 0;3264 int32_t iSliceSize = 0;
3265 int32_t iPayloadSize = 0;
3235 3266
3236 if (pCtx->bNeedPrefixNalFlag) {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 WelsLoadNal (pCtx->pOut, eNalType, eNalRefIdc);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 WelsUnloadNal (pCtx->pOut);3278 WelsUnloadNal (pCtx->pOut);
3245 3279
3246 iSliceSize = WelsEncodeNalExt (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1],3280 pCtx->iEncoderError = WelsEncodeNal (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1],
3247 &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt,3281 &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt,
3248 pCtx->pFrameBs + pCtx->iPosBsBuffer,3282 pCtx->iFrameBsSize-pCtx->iPosBsBuffer,
3249 &iNalLen[iNalIdxInLayer]);3283 pCtx->pFrameBs+pCtx->iPosBsBuffer,
3284 &iNalLen[iNalIdxInLayer]);
3285 WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS)
3286 iSliceSize = iNalLen[iNalIdxInLayer];
3287
3250 iLayerSize += iSliceSize;3288 iLayerSize += iSliceSize;
3251 pCtx->iPosBsBuffer += iSliceSize;3289 pCtx->iPosBsBuffer += iSliceSize;
3252 pLayerBsInfo->uiLayerType = VIDEO_CODING_LAYER;3290 pLayerBsInfo->uiLayerType = VIDEO_CODING_LAYER;
@@ -3265,7 +3303,8 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 12 unmodified lines
3265#endif//MT_ENABLED3303#endif//MT_ENABLED
3266 {3304 {
3267 const int32_t kiLastMbInFrame = pCtx->pCurDqLayer->pSliceEncCtx->iMbNumInFrame;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 } else {3308 } else {
3270 //other multi-slice uiSliceMode3309 //other multi-slice uiSliceMode
3271#if defined(MT_ENABLED)3310#if defined(MT_ENABLED)
@@ -3283,13 +3322,13 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 11 unmodified lines
3283 WelsLog (pCtx, WELS_LOG_ERROR,3322 WelsLog (pCtx, WELS_LOG_ERROR,
3284 "WelsEncoderEncodeExt(), iLayerNum(%d) overflow(max:%d) at iDid= %d uiSliceMode= %d, iSliceCount= %d!",3323 "WelsEncoderEncodeExt(), iLayerNum(%d) overflow(max:%d) at iDid= %d uiSliceMode= %d, iSliceCount= %d!",
3285 iLayerNum, MAX_LAYER_NUM_OF_FRAME, iCurDid, param_d->sSliceCfg.uiSliceMode, iSliceCount);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 if (iSliceCount <= 1) {3327 if (iSliceCount <= 1) {
3289 WelsLog (pCtx, WELS_LOG_ERROR,3328 WelsLog (pCtx, WELS_LOG_ERROR,
3290 "WelsEncoderEncodeExt(), iSliceCount(%d) from GetCurrentSliceNum() is untrusted due stack/heap crupted!\n",3329 "WelsEncoderEncodeExt(), iSliceCount(%d) from GetCurrentSliceNum() is untrusted due stack/heap crupted!\n",
3291 iSliceCount);3330 iSliceCount);
3292 return -1;3331 return ENC_RETURN_UNEXPECTED;
3293 }3332 }
3294 3333
3295 if (pSvcParam->iCountThreadsNum >= iSliceCount) { //THREAD_FULLY_FIRE_MODE3334 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 WelsLog (pCtx, WELS_LOG_ERROR,3352 WelsLog (pCtx, WELS_LOG_ERROR,
3314 "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!\n",3353 "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!\n",
3315 err, pSvcParam->iCountThreadsNum, iSliceCount, param_d->sSliceCfg.uiSliceMode, pSvcParam->iMultipleThreadIdc);3354 err, pSvcParam->iCountThreadsNum, iSliceCount, param_d->sSliceCfg.uiSliceMode, pSvcParam->iMultipleThreadIdc);
3316 return -1;3355 return ENC_RETURN_UNEXPECTED;
3317 }3356 }
3318 3357
3319 WelsMultipleEventsWaitAllBlocking (iSliceCount, &pCtx->pSliceThreading->pSliceCodedEvent[0]);3358 WelsMultipleEventsWaitAllBlocking (iSliceCount, &pCtx->pSliceThreading->pSliceCodedEvent[0]);
3320 3359
3321 3360
3322 // all slices are finished coding here3361 // all slices are finished coding here
3362 WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS)
3363
3323 // append exclusive slice 0 bs to pFrameBs3364 // append exclusive slice 0 bs to pFrameBs
3324#if defined(PACKING_ONE_SLICE_PER_LAYER)3365#if defined(PACKING_ONE_SLICE_PER_LAYER)
3325 iLayerSize = pCtx->iPosBsBuffer - iOrgSlicePos[0];3366 iLayerSize = pCtx->iPosBsBuffer - iOrgSlicePos[0];
@@ -3372,7 +3413,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 46 unmodified lines
3372 WelsLog (pCtx, WELS_LOG_ERROR,3413 WelsLog (pCtx, WELS_LOG_ERROR,
3373 "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!\n",3414 "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!\n",
3374 err, pSvcParam->iCountThreadsNum, iSliceCount, param_d->sSliceCfg.uiSliceMode, pSvcParam->iMultipleThreadIdc);3415 err, pSvcParam->iCountThreadsNum, iSliceCount, param_d->sSliceCfg.uiSliceMode, pSvcParam->iMultipleThreadIdc);
3375 return -1;3416 return ENC_RETURN_UNEXPECTED;
3376 }3417 }
3377 3418
3378 iIndexOfSliceToBeCoded = iNumThreadsRunning;3419 iIndexOfSliceToBeCoded = iNumThreadsRunning;
@@ -3408,6 +3449,7 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 29 unmodified lines
3408 // TODO for pthread platforms3449 // TODO for pthread platforms
3409 // alternate implementation using blocking due non-blocking with timeout mode not support at wels thread lib, tune back if available3450 // alternate implementation using blocking due non-blocking with timeout mode not support at wels thread lib, tune back if available
3410 WelsMultipleEventsWaitAllBlocking (iNumThreadsRunning, &pCtx->pSliceThreading->pSliceCodedEvent[0]);3451 WelsMultipleEventsWaitAllBlocking (iNumThreadsRunning, &pCtx->pSliceThreading->pSliceCodedEvent[0]);
3452 WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS)
3411 if (iIndexOfSliceToBeCoded < iSliceCount) {3453 if (iIndexOfSliceToBeCoded < iSliceCount) {
3412 int32_t iThreadIdx = 0;3454 int32_t iThreadIdx = 0;
3413 // pick up succeeding slices for threading if left3455 // 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 WelsLog (pCtx, WELS_LOG_ERROR,3506 WelsLog (pCtx, WELS_LOG_ERROR,
3465 "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!\n",3507 "[MT] WelsEncoderEncodeExt(), FiredSliceThreads return(%d) failed and exit encoding frame, iCountThreadsNum= %d, iSliceCount= %d, uiSliceMode= %d, iMultipleThreadIdc= %d!!\n",
3466 err, pSvcParam->iCountThreadsNum, iSliceCount, param_d->sSliceCfg.uiSliceMode, pSvcParam->iMultipleThreadIdc);3508 err, pSvcParam->iCountThreadsNum, iSliceCount, param_d->sSliceCfg.uiSliceMode, pSvcParam->iMultipleThreadIdc);
3467 return -1;3509 return ENC_RETURN_UNEXPECTED;
3468 }3510 }
3469 3511
3470 WelsMultipleEventsWaitAllBlocking (kiPartitionCnt, &pCtx->pSliceThreading->pSliceCodedEvent[0]);3512 WelsMultipleEventsWaitAllBlocking (kiPartitionCnt, &pCtx->pSliceThreading->pSliceCodedEvent[0]);
3513 WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS)
3471 3514
3472#if defined(PACKING_ONE_SLICE_PER_LAYER)3515#if defined(PACKING_ONE_SLICE_PER_LAYER)
3473 iSliceCount = PostProcDynamicSlicingBsWriting (pCtx, pLayerBsInfo, &iLayerSize, kiPartitionCnt);3516 iSliceCount = PostProcDynamicSlicingBsWriting (pCtx, pLayerBsInfo, &iLayerSize, kiPartitionCnt);
@@ -3486,19 +3529,26 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 12 unmodified lines
3486 iSliceCount = GetCurrentSliceNum (pCtx->pCurDqLayer->pSliceEncCtx);3529 iSliceCount = GetCurrentSliceNum (pCtx->pCurDqLayer->pSliceEncCtx);
3487 while (iSliceIdx < iSliceCount) {3530 while (iSliceIdx < iSliceCount) {
3488 int32_t iSliceSize = 0;3531 int32_t iSliceSize = 0;
3489 3532 int32_t iPayloadSize = 0;
3490 if (bNeedPrefix) {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 WelsLoadNal (pCtx->pOut, eNalType, eNalRefIdc);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 WelsUnloadNal (pCtx->pOut);3543 WelsUnloadNal (pCtx->pOut);
3497 3544
3498 iSliceSize = WelsEncodeNalExt (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1],3545 pCtx->iEncoderError = WelsEncodeNal (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1],
3499 &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt,3546 &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt,
3500 pCtx->pFrameBs + pCtx->iPosBsBuffer,3547 pCtx->iFrameBsSize-pCtx->iPosBsBuffer,
3501 &iNalLen[iNalIdxInLayer]);3548 pCtx->pFrameBs+pCtx->iPosBsBuffer, &iNalLen[iNalIdxInLayer]);
3549 WELS_VERIFY_RETURN_IFNEQ(pCtx->iEncoderError, ENC_RETURN_SUCCESS)
3550 iSliceSize = iNalLen[iNalIdxInLayer];
3551
3502 pCtx->iPosBsBuffer += iSliceSize;3552 pCtx->iPosBsBuffer += iSliceSize;
3503 iLayerSize += iSliceSize;3553 iLayerSize += iSliceSize;
3504 pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize;3554 pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize;
@@ -3542,8 +3592,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 37 unmodified lines
3542 if (!WelsUpdateRefList (pCtx)) {3592 if (!WelsUpdateRefList (pCtx)) {
3543 // Force coding IDR as followed3593 // Force coding IDR as followed
3544 ForceCodingIDR (pCtx);3594 ForceCodingIDR (pCtx);
3545 WelsLog (pCtx, WELS_LOG_WARNING, "WelsEncoderEncodeExt(), WelsUpdateRefList failed.\n");3595 WelsLog (pCtx, WELS_LOG_WARNING, "WelsEncoderEncodeExt(), WelsUpdateRefList failed. ForceCodingIDR!\n");
3546 return -1;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 pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;3700 pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
3649 3701
3650 if (pSvcParam->iPaddingFlag && pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingSize > 0) {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#if GOM_TRACE_FLAG3707#if GOM_TRACE_FLAG
3654 WelsLog (pCtx, WELS_LOG_INFO, "[RC] encoding_qp%d Padding: %d\n", pCtx->uiDependencyId,3708 WelsLog (pCtx, WELS_LOG_INFO, "[RC] encoding_qp%d Padding: %d\n", pCtx->uiDependencyId,
3655 pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingSize);3709 pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingSize);
3656#endif3710#endif
3657 if (kiPaddingNalSize <= 0)3711 if (iPaddingNalSize <= 0)
3658 return -1;3712 return ENC_RETURN_UNEXPECTED;
3659 3713
3660 pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingBitrateStat += pCtx->pWelsSvcRc[pCtx->uiDependencyId].iPaddingSize;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 pLayerBsInfo->uiQualityId = 0;3721 pLayerBsInfo->uiQualityId = 0;
3668 pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER;3722 pLayerBsInfo->uiLayerType = NON_VIDEO_CODING_LAYER;
3669 pLayerBsInfo->iNalCount = 1;3723 pLayerBsInfo->iNalCount = 1;
3670 pLayerBsInfo->iNalLengthInByte[0] = kiPaddingNalSize;3724 pLayerBsInfo->iNalLengthInByte[0] = iPaddingNalSize;
3671 ++ pLayerBsInfo;3725 ++ pLayerBsInfo;
3672 pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;3726 pLayerBsInfo->pBsBuf = pCtx->pFrameBs + pCtx->iPosBsBuffer;
3673 ++ iLayerNum;3727 ++ iLayerNum;
@@ -3697,7 +3751,10 @@ int32_t WelsEncoderEncodeExt (sWelsEncCtx* pCtx, void* pDst, const SSourcePictur · 23 unmodified lines
3697 3751
3698 if( pCtx->pVpp->UpdateSpatialPictures(pCtx, pSvcParam, iCurTid, d_idx) != 0 ){3752 if( pCtx->pVpp->UpdateSpatialPictures(pCtx, pSvcParam, iCurTid, d_idx) != 0 ){
3699 ForceCodingIDR(pCtx);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 if (pSvcParam->bEnableLongTermReference && ((pCtx->pLtr[pCtx->uiDependencyId].bLTRMarkingFlag3760 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 WelsEmms();3791 WelsEmms();
3735#endif //X86_ASM3792#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 */
3744int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewParam) {3802int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewParam) {
3745 SWelsSvcCodingParam* pOldParam = NULL;3803 SWelsSvcCodingParam* pOldParam = NULL;
3746 int32_t iReturn = 0;3804 int32_t iReturn = ENC_RETURN_SUCCESS;
3747 int8_t iIndexD = 0;3805 int8_t iIndexD = 0;
3748 bool bNeedReset = false;3806 bool bNeedReset = false;
3749 3807
@@ -3751,7 +3809,7 @@ int32_t WelsEncoderParamAdjust (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pNewPa · 1 unmodified line
3751 3809
3752 /* Check validation in new parameters */3810 /* Check validation in new parameters */
3753 iReturn = ParamValidationExt (pNewParam);3811 iReturn = ParamValidationExt (pNewParam);
3754 if (iReturn != 0) return iReturn;3812 if (iReturn != ENC_RETURN_SUCCESS) return iReturn;
3755 3813
3756 pOldParam = (*ppCtx)->pSvcParam;3814 pOldParam = (*ppCtx)->pSvcParam;
3757 3815
@@ -3942,6 +4000,7 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 184 unmodified lines
3942 const EWelsNalUnitType keNalType = pCtx->eNalType;4000 const EWelsNalUnitType keNalType = pCtx->eNalType;
3943 const EWelsNalRefIdc keNalRefIdc = pCtx->eNalPriority;4001 const EWelsNalRefIdc keNalRefIdc = pCtx->eNalPriority;
3944 const bool kbNeedPrefix = pCtx->bNeedPrefixNalFlag;4002 const bool kbNeedPrefix = pCtx->bNeedPrefixNalFlag;
4003 int32_t iReturn = ENC_RETURN_SUCCESS;
3945 4004
3946 //init4005 //init
3947 {4006 {
@@ -3953,25 +4012,33 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 5 unmodified lines
3953 4012
3954 while (iAnyMbLeftInPartition > 0) {4013 while (iAnyMbLeftInPartition > 0) {
3955 int32_t iSliceSize = 0;4014 int32_t iSliceSize = 0;
4015 int32_t iPayloadSize = 0;
3956 4016
3957 if (iSliceIdx >= pSliceCtx->iMaxSliceNumConstraint) { // insufficient memory in pSliceInLayer[]4017 if (iSliceIdx >= pSliceCtx->iMaxSliceNumConstraint) { // insufficient memory in pSliceInLayer[]
3958 // TODO: need exception handler for not large enough of MAX_SLICES_NUM related memory usage4018 // TODO: need exception handler for not large enough of MAX_SLICES_NUM related memory usage
3959 // No idea about its solution due MAX_SLICES_NUM is fixed lenght in relevent pData structure4019 // 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 if (kbNeedPrefix) {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 WelsLoadNal (pCtx->pOut, keNalType, keNalRefIdc);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 WelsUnloadNal (pCtx->pOut);4032 WelsUnloadNal (pCtx->pOut);
3970 4033
3971 iSliceSize = WelsEncodeNalExt (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1],4034 iReturn = WelsEncodeNal (&pCtx->pOut->sNalList[pCtx->pOut->iNalIndex - 1],
3972 &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt,4035 &pCtx->pCurDqLayer->sLayerInfo.sNalHeaderExt,
3973 pCtx->pFrameBs + pCtx->iPosBsBuffer,4036 pCtx->iFrameBsSize-pCtx->iPosBsBuffer,
3974 &iNalLen[iNalIdxInLayer]);4037 pCtx->pFrameBs+pCtx->iPosBsBuffer,
4038 &iNalLen[iNalIdxInLayer]);
4039 WELS_VERIFY_RETURN_IFNEQ(iReturn, ENC_RETURN_SUCCESS)
4040 iSliceSize = iNalLen[iNalIdxInLayer];
4041
3975 pCtx->iPosBsBuffer += iSliceSize;4042 pCtx->iPosBsBuffer += iSliceSize;
3976 iPartitionBsSize += iSliceSize;4043 iPartitionBsSize += iSliceSize;
3977 pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize;4044 pLayerBsInfo->iNalLengthInByte[iNalIdxInLayer] = iSliceSize;
@@ -4001,6 +4068,6 @@ int32_t WelsCodeOnePicPartition (sWelsEncCtx* pCtx, · 23 unmodified lines
4001 pLayerBsInfo->uiPriorityId = 0;4068 pLayerBsInfo->uiPriorityId = 0;
4002 pLayerBsInfo->iNalCount = iNalIdxInLayer;4069 pLayerBsInfo->iNalCount = iNalIdxInLayer;
4003 4070
4004 return 0;4071 return ENC_RETURN_SUCCESS;
4005}4072}
4006} // namespace WelsSVCEnc4073} // 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