History

save memory usage and improve error return logic under VLCOVERFLOW

Sijia Chen committed 11 years ago

Commit e70621c1 parent a8ae1347 files · +63 −45Browse files

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

Unified · Split

codec/encoder/core/src/slice_multi_threading.cpp+8−16
@@ -295,6 +295,7 @@ int32_t SetMultiSliceBuffer (sWelsEncCtx** ppCtx, CMemoryAlign* pMa, SSliceThrea · 294 unmodified lines
295295 if (NULL == (*ppCtx)->pSliceBs) {
296296 return ENC_RETURN_MEMALLOCERR;
297297 }
298+
298299 if (iSlice0Len <= 0) {
299300 return ENC_RETURN_UNEXPECTED;
300301 }
@@ -310,19 +311,19 @@ int32_t SetMultiSliceBuffer (sWelsEncCtx** ppCtx, CMemoryAlign* pMa, SSliceThrea · 9 unmodified lines
310311 if (iSlice1Len <= 0) {
311312 return ENC_RETURN_UNEXPECTED;
312313 }
314+ if ((*ppCtx)->iFrameBsSize < (iSlice0Len + (iMaxSliceNum - 1)*iSlice1Len)) {
315+ return ENC_RETURN_MEMALLOCERR;
316+ }
313317 for (int32_t k = 1; k < iMaxSliceNum; k++) {
314318 (*ppCtx)->pSliceBs[k].uiSize = iSlice1Len;
315319 (*ppCtx)->pSliceBs[k].pBs = (*ppCtx)->pSliceBs[k - 1].pBs + (*ppCtx)->pSliceBs[k - 1].uiSize;
316320 }
317− if ((*ppCtx)->iFrameBsSize < (iSlice0Len + (iMaxSliceNum - 1)*iSlice1Len)) {
318− return ENC_RETURN_MEMALLOCERR;
319− }
320321 return ENC_RETURN_SUCCESS;
321322
322323 }
323324
324325 int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingParam, const int32_t iCountBsLen,
325− const int32_t iTargetSpatialBsSize) {
326+ const int32_t iMaxSliceBufferSize, bool bDynamicSlice) {
326327 CMemoryAlign* pMa = NULL;
327328 SWelsSvcCodingParam* pPara = NULL;
328329 SSliceThreading* pSmt = NULL;
@@ -331,8 +332,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 2 unmodified lines
331332 int32_t iIdx = 0;
332333 int16_t iMaxSliceNum = 1;
333334 int32_t iReturn = ENC_RETURN_SUCCESS;
334− bool bDynamicSlice = false;
335− uint32_t uiMaxSliceSizeConstraint = 0;
336335
337336 if (NULL == ppCtx || NULL == pCodingParam || NULL == *ppCtx || iCountBsLen <= 0)
338337 return 1;
@@ -372,13 +371,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 33 unmodified lines
372371 pSmt->pSliceConsumeTime[iIdx] = NULL;
373372 pSmt->pSliceComplexRatio[iIdx] = NULL;
374373 }
375−
376− if (pMso->uiSliceMode == SM_DYN_SLICE) {
377− bDynamicSlice = true;
378− if (uiMaxSliceSizeConstraint < pMso->sSliceArgument.uiSliceSizeConstraint) {
379− uiMaxSliceSizeConstraint = pMso->sSliceArgument.uiSliceSizeConstraint;
380− }
381− }
382374 ++ iIdx;
383375 }
384376 // 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
428420 MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pReadySliceCodingEvent%d = 0x%p named(%s) ret%d err%d", iIdx,
429421 (void*)pSmt->pReadySliceCodingEvent[iIdx], name, err, errno);
430422
431−
432− pSmt->pThreadBsBuffer[iIdx] = (uint8_t*)pMa->WelsMalloc (iTargetSpatialBsSize, "pSmt->pThreadBsBuffer");
423+ pSmt->pThreadBsBuffer[iIdx] = (uint8_t*)pMa->WelsMalloc (iCountBsLen, "pSmt->pThreadBsBuffer");
433424 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pThreadBsBuffer[iIdx]), FreeMemorySvc (ppCtx))
434425
435426 ++ iIdx;
@@ -442,8 +433,9 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 6 unmodified lines
442433 err = WelsEventOpen (&pSmt->pSliceCodedMasterEvent, name);
443434 MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pSliceCodedMasterEvent named(%s) ret%d err%d", name, err, errno);
444435
436+
445437 iReturn = SetMultiSliceBuffer (ppCtx, pMa, pSmt, iMaxSliceNum,
446− iTargetSpatialBsSize, //TODO: may use uiMaxSliceSizeConstraint<<1 when bDynamicSlice, but need more twist
438+ iMaxSliceBufferSize,
447439 iCountBsLen,
448440 bDynamicSlice);
449441 WELS_VERIFY_RETURN_PROC_IF (iReturn, (ENC_RETURN_SUCCESS != iReturn), FreeMemorySvc (ppCtx))

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