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
295 if (NULL == (*ppCtx)->pSliceBs) {295 if (NULL == (*ppCtx)->pSliceBs) {
296 return ENC_RETURN_MEMALLOCERR;296 return ENC_RETURN_MEMALLOCERR;
297 }297 }
298
298 if (iSlice0Len <= 0) {299 if (iSlice0Len <= 0) {
299 return ENC_RETURN_UNEXPECTED;300 return ENC_RETURN_UNEXPECTED;
300 }301 }
@@ -310,19 +311,19 @@ int32_t SetMultiSliceBuffer (sWelsEncCtx** ppCtx, CMemoryAlign* pMa, SSliceThrea · 9 unmodified lines
310 if (iSlice1Len <= 0) {311 if (iSlice1Len <= 0) {
311 return ENC_RETURN_UNEXPECTED;312 return ENC_RETURN_UNEXPECTED;
312 }313 }
314 if ((*ppCtx)->iFrameBsSize < (iSlice0Len + (iMaxSliceNum - 1)*iSlice1Len)) {
315 return ENC_RETURN_MEMALLOCERR;
316 }
313 for (int32_t k = 1; k < iMaxSliceNum; k++) {317 for (int32_t k = 1; k < iMaxSliceNum; k++) {
314 (*ppCtx)->pSliceBs[k].uiSize = iSlice1Len;318 (*ppCtx)->pSliceBs[k].uiSize = iSlice1Len;
315 (*ppCtx)->pSliceBs[k].pBs = (*ppCtx)->pSliceBs[k - 1].pBs + (*ppCtx)->pSliceBs[k - 1].uiSize;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 return ENC_RETURN_SUCCESS;321 return ENC_RETURN_SUCCESS;
321 322
322}323}
323 324
324int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingParam, const int32_t iCountBsLen,325int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingParam, const int32_t iCountBsLen,
325 const int32_t iTargetSpatialBsSize) {326 const int32_t iMaxSliceBufferSize, bool bDynamicSlice) {
326 CMemoryAlign* pMa = NULL;327 CMemoryAlign* pMa = NULL;
327 SWelsSvcCodingParam* pPara = NULL;328 SWelsSvcCodingParam* pPara = NULL;
328 SSliceThreading* pSmt = NULL;329 SSliceThreading* pSmt = NULL;
@@ -331,8 +332,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 2 unmodified lines
331 int32_t iIdx = 0;332 int32_t iIdx = 0;
332 int16_t iMaxSliceNum = 1;333 int16_t iMaxSliceNum = 1;
333 int32_t iReturn = ENC_RETURN_SUCCESS;334 int32_t iReturn = ENC_RETURN_SUCCESS;
334 bool bDynamicSlice = false;
335 uint32_t uiMaxSliceSizeConstraint = 0;
336 335
337 if (NULL == ppCtx || NULL == pCodingParam || NULL == *ppCtx || iCountBsLen <= 0)336 if (NULL == ppCtx || NULL == pCodingParam || NULL == *ppCtx || iCountBsLen <= 0)
338 return 1;337 return 1;
@@ -372,13 +371,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 33 unmodified lines
372 pSmt->pSliceConsumeTime[iIdx] = NULL;371 pSmt->pSliceConsumeTime[iIdx] = NULL;
373 pSmt->pSliceComplexRatio[iIdx] = NULL;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 ++ iIdx;374 ++ iIdx;
383 }375 }
384 // NULL for pSliceConsumeTime[iIdx]: iIdx from iNumSpatialLayers to MAX_DEPENDENCY_LAYERS376 // 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 MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pReadySliceCodingEvent%d = 0x%p named(%s) ret%d err%d", iIdx,420 MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pReadySliceCodingEvent%d = 0x%p named(%s) ret%d err%d", iIdx,
429 (void*)pSmt->pReadySliceCodingEvent[iIdx], name, err, errno);421 (void*)pSmt->pReadySliceCodingEvent[iIdx], name, err, errno);
430 422
431 423 pSmt->pThreadBsBuffer[iIdx] = (uint8_t*)pMa->WelsMalloc (iCountBsLen, "pSmt->pThreadBsBuffer");
432 pSmt->pThreadBsBuffer[iIdx] = (uint8_t*)pMa->WelsMalloc (iTargetSpatialBsSize, "pSmt->pThreadBsBuffer");
433 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pThreadBsBuffer[iIdx]), FreeMemorySvc (ppCtx))424 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pThreadBsBuffer[iIdx]), FreeMemorySvc (ppCtx))
434 425
435 ++ iIdx;426 ++ iIdx;
@@ -442,8 +433,9 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 6 unmodified lines
442 err = WelsEventOpen (&pSmt->pSliceCodedMasterEvent, name);433 err = WelsEventOpen (&pSmt->pSliceCodedMasterEvent, name);
443 MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pSliceCodedMasterEvent named(%s) ret%d err%d", name, err, errno);434 MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pSliceCodedMasterEvent named(%s) ret%d err%d", name, err, errno);
444 435
436
445 iReturn = SetMultiSliceBuffer (ppCtx, pMa, pSmt, iMaxSliceNum,437 iReturn = SetMultiSliceBuffer (ppCtx, pMa, pSmt, iMaxSliceNum,
446 iTargetSpatialBsSize, //TODO: may use uiMaxSliceSizeConstraint<<1 when bDynamicSlice, but need more twist438 iMaxSliceBufferSize,
447 iCountBsLen,439 iCountBsLen,
448 bDynamicSlice);440 bDynamicSlice);
449 WELS_VERIFY_RETURN_PROC_IF (iReturn, (ENC_RETURN_SUCCESS != iReturn), FreeMemorySvc (ppCtx))441 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