History

Multi-thread-fixed:RBC#1751:Dynamic slice mode under multiThread reallocate feature enable

huade committed 9 years ago

Commit 095f0b61 parent 623599014 files · +325 −336Browse files

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

Unified · Split

codec/encoder/core/src/slice_multi_threading.cpp+38−81
@@ -99,6 +99,7 @@ void CalcSliceComplexRatio (SDqLayer* pCurDq) { · 98 unmodified lines
9999 int32_t iSliceIdx = 0;
100100 int32_t iAvI[MAX_SLICES_NUM];
101101
102+ assert(kiSliceCount <= MAX_SLICES_NUM);
102103 WelsEmms();
103104
104105 while (iSliceIdx < kiSliceCount) {
@@ -354,9 +355,14 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 249 unmodified lines
354355 WELS_VERIFY_RETURN_IF (1, (NULL == pSmt->pThreadBsBuffer[iIdx]))
355356 }
356357 iReturn = WelsMutexInit (&pSmt->mutexThreadBsBufferUsage);
357− WELS_VERIFY_RETURN_IF (1, (WELS_THREAD_ERROR_OK != iReturn))
358+ WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx))
359+
358360 iReturn = WelsMutexInit (&pSmt->mutexEvent);
359− WELS_VERIFY_RETURN_IF (1, (WELS_THREAD_ERROR_OK != iReturn))
361+ WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx));
362+
363+ iReturn = WelsMutexInit (&pSmt->mutexThreadSlcBuffReallocate);
364+ WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx))
365+
360366 iReturn = WelsMutexInit (& (*ppCtx)->mutexEncoderError);
361367 WELS_VERIFY_RETURN_IF (1, (WELS_THREAD_ERROR_OK != iReturn))
362368
@@ -405,6 +411,7 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 42 unmodified lines
405411
406412 WelsMutexDestroy (&pSmt->mutexSliceNumUpdate);
407413 WelsMutexDestroy (&pSmt->mutexThreadBsBufferUsage);
414+ WelsMutexDestroy (&pSmt->mutexThreadSlcBuffReallocate);
408415 WelsMutexDestroy (& ((*ppCtx)->mutexEncoderError));
409416 WelsMutexDestroy (&pSmt->mutexEvent);
410417 if (pSmt->pThreadPEncCtx != NULL) {
@@ -436,75 +443,36 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 25 unmodified lines
436443 }
437444
438445 int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32_t iSliceCount) {
439− SWelsSvcCodingParam* pCodingParam = pCtx->pSvcParam;
440− SSpatialLayerConfig* pDlp = &pCodingParam->sSpatialLayers[pCtx->uiDependencyId];
441− SSlice** ppSliceInlayer = pCtx->pCurDqLayer->ppSliceInLayer;
442− SWelsSliceBs* pSliceBs = NULL;
443− const bool kbIsDynamicSlicingMode = (pDlp->sSliceArgument.uiSliceMode == SM_SIZELIMITED_SLICE);
444−
445− int32_t iLayerSize = 0;
446− int32_t iNalIdxBase = pLbi->iNalCount;
447− int32_t iSliceIdx = 0;
448−
449− if (!kbIsDynamicSlicingMode) {
450− iNalIdxBase = pLbi->iNalCount = 0;
451− while (iSliceIdx < iSliceCount) {
452− pSliceBs = &ppSliceInlayer[iSliceIdx]->sSliceBs;
453− if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) {
454− int32_t iNalIdx = 0;
455− const int32_t iCountNal = pSliceBs->iNalIndex;
446+ SSlice** ppSliceInlayer = pCtx->pCurDqLayer->ppSliceInLayer;
447+ SWelsSliceBs* pSliceBs = NULL;
448+ int32_t iLayerSize = 0;
449+ int32_t iNalIdxBase = pLbi->iNalCount;
450+ int32_t iSliceIdx = 0;
451+
452+ iNalIdxBase = pLbi->iNalCount = 0;
453+ while (iSliceIdx < iSliceCount) {
454+ pSliceBs = &ppSliceInlayer[iSliceIdx]->sSliceBs;
455+ if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) {
456+ int32_t iNalIdx = 0;
457+ const int32_t iCountNal = pSliceBs->iNalIndex;
456458
457459 #if MT_DEBUG_BS_WR
458− assert (pSliceBs->bSliceCodedFlag);
460+ assert (pSliceBs->bSliceCodedFlag);
459461 #endif//MT_DEBUG_BS_WR
460462
461− memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage
462− pCtx->iPosBsBuffer += pSliceBs->uiBsPos;
463+ memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage
464+ pCtx->iPosBsBuffer += pSliceBs->uiBsPos;
463465
464− iLayerSize += pSliceBs->uiBsPos;
466+ iLayerSize += pSliceBs->uiBsPos;
465467
466− while (iNalIdx < iCountNal) {
467− pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx];
468− ++ iNalIdx;
469− }
470− pLbi->iNalCount += iCountNal;
471− iNalIdxBase += iCountNal;
472− }
473− ++ iSliceIdx;
468+ while (iNalIdx < iCountNal) {
469+ pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx];
470+ ++ iNalIdx;
474471 }
475− } else { // for SM_SIZELIMITED_SLICE
476− const int32_t kiPartitionCnt = iSliceCount;
477− int32_t iPartitionIdx = 0;
478−
479− // due partition_0 has been written to pFrameBsBuffer
480− // so iLayerSize need add it
481− while (iPartitionIdx < kiPartitionCnt) {
482− const int32_t kiCountSlicesCoded = pCtx->pCurDqLayer->pNumSliceCodedOfPartition[iPartitionIdx];
483− int32_t iIdx = 0;
484−
485− iSliceIdx = iPartitionIdx;
486− while (iIdx < kiCountSlicesCoded) {
487− pSliceBs = &ppSliceInlayer[iSliceIdx]->sSliceBs;
488− if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) {
489− memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage
490− pCtx->iPosBsBuffer += pSliceBs->uiBsPos;
491−
492− const int32_t iCountNal = pSliceBs->iNalIndex;
493− iLayerSize += pSliceBs->uiBsPos;
494− int32_t iNalIdx = 0;
495− while (iNalIdx < iCountNal) {
496− pLbi->pNalLengthInByte[iNalIdxBase + iNalIdx] = pSliceBs->iNalLen[iNalIdx];
497− ++ iNalIdx;
498− }
499− pLbi->iNalCount += iCountNal;
500− iNalIdxBase += iCountNal;
501− }
502−
503− iSliceIdx += kiPartitionCnt;
504− ++ iIdx;
505− }
506− ++ iPartitionIdx;
472+ pLbi->iNalCount += iCountNal;
473+ iNalIdxBase += iCountNal;
507474 }
475+ ++ iSliceIdx;
508476 }
509477
510478 return iLayerSize;
@@ -650,14 +618,6 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 139 unmodified lines
650618 iEventIdx);
651619 }
652620
653− iReturn = SetSliceBoundaryInfo(pEncPEncCtx->pCurDqLayer, pSlice, iSliceIdx);
654− if (ENC_RETURN_SUCCESS != iReturn) {
655− uiThrdRet = iReturn;
656− WELS_THREAD_SIGNAL_AND_BREAK (pEncPEncCtx->pSliceThreading->pSliceCodedEvent,
657− pEncPEncCtx->pSliceThreading->pSliceCodedMasterEvent,
658− iEventIdx);
659− }
660−
661621 assert (iSliceIdx == pSlice->iSliceIdx);
662622 iReturn = WelsCodeOneSlice (pEncPEncCtx, pSlice, eNalType);
663623 if (ENC_RETURN_SUCCESS != iReturn) {
@@ -677,7 +637,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 13 unmodified lines
677637 iEventIdx);
678638 }
679639
680− pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx);
640+ pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, pSlice);
681641
682642 if (bDsaFlag) {
683643 pSlice->uiSliceConsumeTime = (uint32_t) (WelsTime() - iSliceStart);
@@ -710,16 +670,13 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 26 unmodified lines
710670 } else { // for SM_SIZELIMITED_SLICE parallelization
711671 const int32_t kiPartitionId = iThreadIdx;
712672 const int32_t kiSliceIdxStep = pEncPEncCtx->iActiveThreadsNum;
713− const int32_t kiFirstMbInPartition = pCurDq->pFirstMbIdxOfPartition[kiPartitionId];
714− const int32_t kiEndMbIdxInPartition = pCurDq->pEndMbIdxOfPartition[kiPartitionId];
673+ const int32_t kiFirstMbInPartition = pCurDq->FirstMbIdxOfPartition[kiPartitionId];
674+ const int32_t kiEndMbIdxInPartition = pCurDq->EndMbIdxOfPartition[kiPartitionId];
715675 int32_t iAnyMbLeftInPartition = kiEndMbIdxInPartition - kiFirstMbInPartition + 1;
716676 SSpatialLayerInternal *pParamInternal = &pCodingParam->sDependencyLayers[kiCurDid];
717677 iSliceIdx = pPrivateData->iSliceIndex;
718678 SSlice* pStartSlice = &pCurDq->sSliceThreadInfo.pSliceInThread[iThreadIdx][iSliceIdx];
719679 pStartSlice->sSliceHeaderExt.sSliceHeader.iFirstMbInSlice = kiFirstMbInPartition;
720− pCurDq->pNumSliceCodedOfPartition[kiPartitionId] = 1;
721− pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId] = 0;
722−
723680 while (iAnyMbLeftInPartition > 0) {
724681 if (iSliceIdx >= pCurDq->iMaxSliceNum) {
725682 // TODO: need exception handler for not large enough of MAX_SLICES_NUM related memory usage
@@ -778,7 +735,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 52 unmodified lines
778735 iEventIdx);
779736 }
780737
781− pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, iSliceIdx);
738+ pEncPEncCtx->pFuncList->pfDeblocking.pfDeblockingFilterSlice (pCurDq, pEncPEncCtx->pFuncList, pSlice);
782739
783740 #if defined(SLICE_INFO_OUTPUT)
784741 fprintf (stderr,
@@ -791,12 +748,12 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 6 unmodified lines
791748 #endif//SLICE_INFO_OUTPUT
792749
793750 MT_TRACE_LOG (&(pEncPEncCtx->sLogCtx), WELS_LOG_INFO,
794− "[MT] CodingSliceThreadProc(), coding_idx %d, iPartitionId %d, iSliceIdx %d, iSliceSize %d, count_mb_slice %d, iEndMbInPartition %d, pCurDq->pLastCodedMbIdxOfPartition[%d] %d\n",
751+ "[MT] CodingSliceThreadProc(), coding_idx %d, iPartitionId %d, iSliceIdx %d, iSliceSize %d, count_mb_slice %d, iEndMbInPartition %d, pCurDq->LastCodedMbIdxOfPartition[%d] %d\n",
795752 pEncPEncCtx->iCodingIndex, kiPartitionId, iSliceIdx, iSliceSize,
796753 pSlice->iCountMbNumInSlice,
797− kiEndMbIdxInPartition, kiPartitionId, pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId]);
754+ kiEndMbIdxInPartition, kiPartitionId, pCurDq->LastCodedMbIdxOfPartition[kiPartitionId]);
798755
799− iAnyMbLeftInPartition = kiEndMbIdxInPartition - pCurDq->pLastCodedMbIdxOfPartition[kiPartitionId];
756+ iAnyMbLeftInPartition = kiEndMbIdxInPartition - pCurDq->LastCodedMbIdxOfPartition[kiPartitionId];
800757 iSliceIdx += kiSliceIdxStep;
801758 }
802759

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