History

remove pSliceBs from ctx

huade committed 10 years ago

Commit f1615661 parent 04bfacd5 files · +54 −89Browse files

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

Unified · Split

codec/encoder/core/src/slice_multi_threading.cpp+9−68
@@ -248,39 +248,6 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 247 unmodified lines
248248 pCurDqLayer->bNeedAdjustingSlicing = !DynamicAdjustSlicePEncCtxAll (pCurDqLayer, iRunLen);
249249 }
250250
251−int32_t SetMultiSliceBuffer (sWelsEncCtx** ppCtx, CMemoryAlign* pMa, SSliceThreading* pSmt,
252− int32_t iMaxSliceNum, int32_t iSlice1Len, int32_t iSlice0Len, bool bDynamicSlice) {
253− (*ppCtx)->pSliceBs = (SWelsSliceBs*)pMa->WelsMalloc (sizeof (SWelsSliceBs) * iMaxSliceNum, "pSliceBs");
254− if (NULL == (*ppCtx)->pSliceBs) {
255− return ENC_RETURN_MEMALLOCERR;
256− }
257−
258− if (iSlice0Len <= 0) {
259− return ENC_RETURN_UNEXPECTED;
260− }
261− //slice 0
262− (*ppCtx)->pSliceBs[0].uiSize = iSlice1Len;
263− (*ppCtx)->pSliceBs[0].pBs = (*ppCtx)->pFrameBs + iSlice0Len;
264− (*ppCtx)->pSliceBs[0].uiBsPos = 0;
265− (*ppCtx)->pSliceBs[0].pBsBuffer = pSmt->pThreadBsBuffer[0];
266− if ((iMaxSliceNum == 1) && (!bDynamicSlice)) {
267− return ENC_RETURN_SUCCESS;
268− }
269− //slice >0
270− if (iSlice1Len <= 0) {
271− return ENC_RETURN_UNEXPECTED;
272− }
273− if ((*ppCtx)->iFrameBsSize < (iSlice0Len + (iMaxSliceNum - 1)*iSlice1Len)) {
274− return ENC_RETURN_MEMALLOCERR;
275− }
276− for (int32_t k = 1; k < iMaxSliceNum; k++) {
277− (*ppCtx)->pSliceBs[k].uiSize = iSlice1Len;
278− (*ppCtx)->pSliceBs[k].pBs = (*ppCtx)->pSliceBs[k - 1].pBs + (*ppCtx)->pSliceBs[k - 1].uiSize;
279− }
280− return ENC_RETURN_SUCCESS;
281−
282−}
283−
284251 int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingParam, const int32_t iCountBsLen,
285252 const int32_t iMaxSliceBufferSize, bool bDynamicSlice) {
286253 CMemoryAlign* pMa = NULL;
@@ -289,7 +256,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 2 unmodified lines
289256 int32_t iNumSpatialLayers = 0;
290257 int32_t iThreadNum = 0;
291258 int32_t iIdx = 0;
292− int16_t iMaxSliceNum = 1;
293259 int32_t iReturn = ENC_RETURN_SUCCESS;
294260 bool bWillUseTaskManage = false;
295261
@@ -300,7 +266,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 4 unmodified lines
300266 pPara = pCodingParam;
301267 iNumSpatialLayers = pPara->iSpatialLayerNum;
302268 iThreadNum = pPara->iMultipleThreadIdc;
303− iMaxSliceNum = (*ppCtx)->iMaxSliceCount;
304269
305270 pSmt = (SSliceThreading*)pMa->WelsMalloc (sizeof (SSliceThreading), "SSliceThreading");
306271 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt), FreeMemorySvc (ppCtx))
@@ -385,12 +350,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 78 unmodified lines
385350 MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pSliceCodedMasterEvent named(%s) ret%d err%d", name, err, errno);
386351 //previous conflict ends
387352
388− iReturn = SetMultiSliceBuffer (ppCtx, pMa, pSmt, iMaxSliceNum,
389− iMaxSliceBufferSize,
390− iCountBsLen,
391− bDynamicSlice);
392− WELS_VERIFY_RETURN_PROC_IF (iReturn, (ENC_RETURN_SUCCESS != iReturn), FreeMemorySvc (ppCtx))
393−
394353 iReturn = WelsMutexInit (&pSmt->mutexSliceNumUpdate);
395354 WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx))
396355
@@ -408,24 +367,20 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 11 unmodified lines
408367
409368 MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "RequestMtResource(), iThreadNum=%d, iMultipleThreadIdc= %d",
410369 pPara->iMultipleThreadIdc,
411− iMaxSliceNum);
412−
370+ (*ppCtx)->iMaxSliceCount);
413371 return 0;
414372 }
415373
416374 void ReleaseMtResource (sWelsEncCtx** ppCtx) {
417− SWelsSliceBs* pSliceB = NULL;
418375 SSliceThreading* pSmt = NULL;
419376 CMemoryAlign* pMa = NULL;
420377 int32_t iIdx = 0;
421378 int32_t iThreadNum = 0;
422− int16_t uiSliceNum = 0;
423379
424380 if (NULL == ppCtx || NULL == *ppCtx)
425381 return;
426382
427383 pMa = (*ppCtx)->pMemAlign;
428− uiSliceNum = (*ppCtx)->iMaxSliceCount;
429384 iThreadNum = (*ppCtx)->pSvcParam->iMultipleThreadIdc;
430385 pSmt = (*ppCtx)->pSliceThreading;
431386
@@ -470,20 +425,6 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 38 unmodified lines
470425 }
471426 memset (&pSmt->bThreadBsBufferUsage, 0, MAX_THREADS_NUM * sizeof (bool));
472427
473− pSliceB = (*ppCtx)->pSliceBs;
474− iIdx = 0;
475− while (pSliceB != NULL && iIdx < uiSliceNum) {
476− pSliceB->pBsBuffer = NULL;
477− pSliceB->uiSize = 0;
478− pSliceB->uiBsPos = 0;
479− ++ iIdx;
480− ++ pSliceB;
481− }
482− if ((*ppCtx)->pSliceBs != NULL) {
483− pMa->WelsFree ((*ppCtx)->pSliceBs, "pSliceBs");
484− (*ppCtx)->pSliceBs = NULL;
485− }
486−
487428 if ((*ppCtx)->pTaskManage != NULL) {
488429 delete (*ppCtx)->pTaskManage;
489430 (*ppCtx)->pTaskManage = NULL;
@@ -503,6 +444,7 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 13 unmodified lines
503444 int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32_t iSliceCount) {
504445 SWelsSvcCodingParam* pCodingParam = pCtx->pSvcParam;
505446 SSpatialLayerConfig* pDlp = &pCodingParam->sSpatialLayers[pCtx->uiDependencyId];
447+ SSlice* pSliceInlayer = pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
506448 SWelsSliceBs* pSliceBs = NULL;
507449 const bool kbIsDynamicSlicingMode = (pDlp->sSliceArgument.uiSliceMode == SM_SIZELIMITED_SLICE);
508450
@@ -511,9 +453,9 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 2 unmodified lines
511453 int32_t iSliceIdx = 0;
512454
513455 if (!kbIsDynamicSlicingMode) {
514− pSliceBs = &pCtx->pSliceBs[0];
515456 iNalIdxBase = pLbi->iNalCount = 0;
516457 while (iSliceIdx < iSliceCount) {
458+ pSliceBs = &pSliceInlayer[iSliceIdx].sSliceBs;
517459 if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) {
518460 int32_t iNalIdx = 0;
519461 const int32_t iCountNal = pSliceBs->iNalIndex;
@@ -535,7 +477,6 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 15 unmodified lines
535477 iNalIdxBase += iCountNal;
536478 }
537479 ++ iSliceIdx;
538− ++ pSliceBs;
539480 }
540481 } else { // for SM_SIZELIMITED_SLICE
541482 const int32_t kiPartitionCnt = iSliceCount;
@@ -549,7 +490,7 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 7 unmodified lines
549490
550491 iSliceIdx = iPartitionIdx;
551492 while (iIdx < kiCountSlicesCoded) {
552− pSliceBs = &pCtx->pSliceBs[iSliceIdx];
493+ pSliceBs = &pSliceInlayer[iSliceIdx].sSliceBs;
553494 if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) {
554495 memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage
555496 pCtx->iPosBsBuffer += pSliceBs->uiBsPos;
@@ -665,7 +606,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 109 unmodified lines
665606 bool bDsaFlag = false;
666607 iSliceIdx = pPrivateData->iSliceIndex;
667608 pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx];
668− pSliceBs = &pEncPEncCtx->pSliceBs[iSliceIdx];
609+ pSliceBs = &pSlice->sSliceBs;
669610
670611 bDsaFlag = ((pParamD->sSliceArgument.uiSliceMode == SM_FIXEDSLCNUM_SLICE) &&
671612 pCodingParam->iMultipleThreadIdc > 1 &&
@@ -777,7 +718,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 105 unmodified lines
777718
778719 SetOneSliceBsBufferUnderMultithread (pEncPEncCtx, kiPartitionId, iSliceIdx);
779720 pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx];
780− pSliceBs = &pEncPEncCtx->pSliceBs[iSliceIdx];
721+ pSliceBs = &pSlice->sSliceBs;
781722
782723 pSliceBs->uiBsPos = 0;
783724 pSliceBs->iNalIndex = 0;
@@ -1086,9 +1027,9 @@ void TrackSliceConsumeTime (sWelsEncCtx* pCtx, int32_t* pDidList, const int32_t · 302 unmodified lines
10861027 #endif//#if defined(MT_DEBUG)
10871028
10881029 void SetOneSliceBsBufferUnderMultithread (sWelsEncCtx* pCtx, const int32_t kiThreadIdx, const int32_t iSliceIdx) {
1089− pCtx->pSliceBs[iSliceIdx].pBsBuffer = pCtx->pSliceThreading->pThreadBsBuffer[kiThreadIdx];
1090− pCtx->pSliceBs[iSliceIdx].uiBsPos = 0;
1091− //printf("SetOneSliceBsBufferUnderMultithread, thread %d, slice %d, buffer=%x\n", kiThreadIdx, iSliceIdx, pCtx->pSliceBs[iSliceIdx].pBsBuffer);
1030+ SWelsSliceBs* pSliceBs = &pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx].sSliceBs;
1031+ pSliceBs->pBsBuffer = pCtx->pSliceThreading->pThreadBsBuffer[kiThreadIdx];
1032+ pSliceBs->uiBsPos = 0;
10921033 }
10931034 }
10941035

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