[Encoder] save memory usage and improve error return logic under VLCOVERFLOW
Showing the changes to codec/encoder/core/src/slice_multi_threading.cpp (1 of 7 files). Show all
Unified · Split
| @@ -295,6 +295,7 @@ int32_t SetMultiSliceBuffer (sWelsEncCtx** ppCtx, CMemoryAlign* pMa, SSliceThrea · 294 unmodified lines | ||
| 295 | 295 | if (NULL == (*ppCtx)->pSliceBs) { |
| 296 | 296 | return ENC_RETURN_MEMALLOCERR; |
| 297 | 297 | } |
| 298 | + | |
| 298 | 299 | if (iSlice0Len <= 0) { |
| 299 | 300 | return ENC_RETURN_UNEXPECTED; |
| 300 | 301 | } |
| @@ -310,19 +311,19 @@ int32_t SetMultiSliceBuffer (sWelsEncCtx** ppCtx, CMemoryAlign* pMa, SSliceThrea · 9 unmodified lines | ||
| 310 | 311 | if (iSlice1Len <= 0) { |
| 311 | 312 | return ENC_RETURN_UNEXPECTED; |
| 312 | 313 | } |
| 314 | + if ((*ppCtx)->iFrameBsSize < (iSlice0Len + (iMaxSliceNum - 1)*iSlice1Len)) { | |
| 315 | + return ENC_RETURN_MEMALLOCERR; | |
| 316 | + } | |
| 313 | 317 | for (int32_t k = 1; k < iMaxSliceNum; k++) { |
| 314 | 318 | (*ppCtx)->pSliceBs[k].uiSize = iSlice1Len; |
| 315 | 319 | (*ppCtx)->pSliceBs[k].pBs = (*ppCtx)->pSliceBs[k - 1].pBs + (*ppCtx)->pSliceBs[k - 1].uiSize; |
| 316 | 320 | } |
| 317 | − if ((*ppCtx)->iFrameBsSize < (iSlice0Len + (iMaxSliceNum - 1)*iSlice1Len)) { | |
| 318 | − return ENC_RETURN_MEMALLOCERR; | |
| 319 | − } | |
| 320 | 321 | return ENC_RETURN_SUCCESS; |
| 321 | 322 | |
| 322 | 323 | } |
| 323 | 324 | |
| 324 | 325 | int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingParam, const int32_t iCountBsLen, |
| 325 | − const int32_t iTargetSpatialBsSize) { | |
| 326 | + const int32_t iMaxSliceBufferSize, bool bDynamicSlice) { | |
| 326 | 327 | CMemoryAlign* pMa = NULL; |
| 327 | 328 | SWelsSvcCodingParam* pPara = NULL; |
| 328 | 329 | SSliceThreading* pSmt = NULL; |
| @@ -331,8 +332,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 2 unmodified lines | ||
| 331 | 332 | int32_t iIdx = 0; |
| 332 | 333 | int16_t iMaxSliceNum = 1; |
| 333 | 334 | int32_t iReturn = ENC_RETURN_SUCCESS; |
| 334 | − bool bDynamicSlice = false; | |
| 335 | − uint32_t uiMaxSliceSizeConstraint = 0; | |
| 336 | 335 | |
| 337 | 336 | if (NULL == ppCtx || NULL == pCodingParam || NULL == *ppCtx || iCountBsLen <= 0) |
| 338 | 337 | return 1; |
| @@ -372,13 +371,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 33 unmodified lines | ||
| 372 | 371 | pSmt->pSliceConsumeTime[iIdx] = NULL; |
| 373 | 372 | pSmt->pSliceComplexRatio[iIdx] = NULL; |
| 374 | 373 | } |
| 375 | − | |
| 376 | − if (pMso->uiSliceMode == SM_DYN_SLICE) { | |
| 377 | − bDynamicSlice = true; | |
| 378 | − if (uiMaxSliceSizeConstraint < pMso->sSliceArgument.uiSliceSizeConstraint) { | |
| 379 | − uiMaxSliceSizeConstraint = pMso->sSliceArgument.uiSliceSizeConstraint; | |
| 380 | − } | |
| 381 | − } | |
| 382 | 374 | ++ iIdx; |
| 383 | 375 | } |
| 384 | 376 | // NULL for pSliceConsumeTime[iIdx]: iIdx from iNumSpatialLayers to MAX_DEPENDENCY_LAYERS |
| @@ -428,8 +420,7 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 43 unmodified lines | ||
| 428 | 420 | MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pReadySliceCodingEvent%d = 0x%p named(%s) ret%d err%d", iIdx, |
| 429 | 421 | (void*)pSmt->pReadySliceCodingEvent[iIdx], name, err, errno); |
| 430 | 422 | |
| 431 | − | |
| 432 | − pSmt->pThreadBsBuffer[iIdx] = (uint8_t*)pMa->WelsMalloc (iTargetSpatialBsSize, "pSmt->pThreadBsBuffer"); | |
| 423 | + pSmt->pThreadBsBuffer[iIdx] = (uint8_t*)pMa->WelsMalloc (iCountBsLen, "pSmt->pThreadBsBuffer"); | |
| 433 | 424 | WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pThreadBsBuffer[iIdx]), FreeMemorySvc (ppCtx)) |
| 434 | 425 | |
| 435 | 426 | ++ iIdx; |
| @@ -442,8 +433,9 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 6 unmodified lines | ||
| 442 | 433 | err = WelsEventOpen (&pSmt->pSliceCodedMasterEvent, name); |
| 443 | 434 | MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pSliceCodedMasterEvent named(%s) ret%d err%d", name, err, errno); |
| 444 | 435 | |
| 436 | + | |
| 445 | 437 | iReturn = SetMultiSliceBuffer (ppCtx, pMa, pSmt, iMaxSliceNum, |
| 446 | − iTargetSpatialBsSize, //TODO: may use uiMaxSliceSizeConstraint<<1 when bDynamicSlice, but need more twist | |
| 438 | + iMaxSliceBufferSize, | |
| 447 | 439 | iCountBsLen, |
| 448 | 440 | bDynamicSlice); |
| 449 | 441 | WELS_VERIFY_RETURN_PROC_IF (iReturn, (ENC_RETURN_SUCCESS != iReturn), FreeMemorySvc (ppCtx)) |