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
248 pCurDqLayer->bNeedAdjustingSlicing = !DynamicAdjustSlicePEncCtxAll (pCurDqLayer, iRunLen);248 pCurDqLayer->bNeedAdjustingSlicing = !DynamicAdjustSlicePEncCtxAll (pCurDqLayer, iRunLen);
249}249}
250 250
251int32_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
284int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingParam, const int32_t iCountBsLen,251int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingParam, const int32_t iCountBsLen,
285 const int32_t iMaxSliceBufferSize, bool bDynamicSlice) {252 const int32_t iMaxSliceBufferSize, bool bDynamicSlice) {
286 CMemoryAlign* pMa = NULL;253 CMemoryAlign* pMa = NULL;
@@ -289,7 +256,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 2 unmodified lines
289 int32_t iNumSpatialLayers = 0;256 int32_t iNumSpatialLayers = 0;
290 int32_t iThreadNum = 0;257 int32_t iThreadNum = 0;
291 int32_t iIdx = 0;258 int32_t iIdx = 0;
292 int16_t iMaxSliceNum = 1;
293 int32_t iReturn = ENC_RETURN_SUCCESS;259 int32_t iReturn = ENC_RETURN_SUCCESS;
294 bool bWillUseTaskManage = false;260 bool bWillUseTaskManage = false;
295 261
@@ -300,7 +266,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 4 unmodified lines
300 pPara = pCodingParam;266 pPara = pCodingParam;
301 iNumSpatialLayers = pPara->iSpatialLayerNum;267 iNumSpatialLayers = pPara->iSpatialLayerNum;
302 iThreadNum = pPara->iMultipleThreadIdc;268 iThreadNum = pPara->iMultipleThreadIdc;
303 iMaxSliceNum = (*ppCtx)->iMaxSliceCount;
304 269
305 pSmt = (SSliceThreading*)pMa->WelsMalloc (sizeof (SSliceThreading), "SSliceThreading");270 pSmt = (SSliceThreading*)pMa->WelsMalloc (sizeof (SSliceThreading), "SSliceThreading");
306 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt), FreeMemorySvc (ppCtx))271 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt), FreeMemorySvc (ppCtx))
@@ -385,12 +350,6 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 78 unmodified lines
385 MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pSliceCodedMasterEvent named(%s) ret%d err%d", name, err, errno);350 MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "[MT] Open pSliceCodedMasterEvent named(%s) ret%d err%d", name, err, errno);
386 //previous conflict ends351 //previous conflict ends
387 352
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
394 iReturn = WelsMutexInit (&pSmt->mutexSliceNumUpdate);353 iReturn = WelsMutexInit (&pSmt->mutexSliceNumUpdate);
395 WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx))354 WELS_VERIFY_RETURN_PROC_IF (1, (WELS_THREAD_ERROR_OK != iReturn), FreeMemorySvc (ppCtx))
396 355
@@ -408,24 +367,20 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 11 unmodified lines
408 367
409 MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "RequestMtResource(), iThreadNum=%d, iMultipleThreadIdc= %d",368 MT_TRACE_LOG (*ppCtx, WELS_LOG_INFO, "RequestMtResource(), iThreadNum=%d, iMultipleThreadIdc= %d",
410 pPara->iMultipleThreadIdc,369 pPara->iMultipleThreadIdc,
411 iMaxSliceNum);370 (*ppCtx)->iMaxSliceCount);
412
413 return 0;371 return 0;
414}372}
415 373
416void ReleaseMtResource (sWelsEncCtx** ppCtx) {374void ReleaseMtResource (sWelsEncCtx** ppCtx) {
417 SWelsSliceBs* pSliceB = NULL;
418 SSliceThreading* pSmt = NULL;375 SSliceThreading* pSmt = NULL;
419 CMemoryAlign* pMa = NULL;376 CMemoryAlign* pMa = NULL;
420 int32_t iIdx = 0;377 int32_t iIdx = 0;
421 int32_t iThreadNum = 0;378 int32_t iThreadNum = 0;
422 int16_t uiSliceNum = 0;
423 379
424 if (NULL == ppCtx || NULL == *ppCtx)380 if (NULL == ppCtx || NULL == *ppCtx)
425 return;381 return;
426 382
427 pMa = (*ppCtx)->pMemAlign;383 pMa = (*ppCtx)->pMemAlign;
428 uiSliceNum = (*ppCtx)->iMaxSliceCount;
429 iThreadNum = (*ppCtx)->pSvcParam->iMultipleThreadIdc;384 iThreadNum = (*ppCtx)->pSvcParam->iMultipleThreadIdc;
430 pSmt = (*ppCtx)->pSliceThreading;385 pSmt = (*ppCtx)->pSliceThreading;
431 386
@@ -470,20 +425,6 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 38 unmodified lines
470 }425 }
471 memset (&pSmt->bThreadBsBufferUsage, 0, MAX_THREADS_NUM * sizeof (bool));426 memset (&pSmt->bThreadBsBufferUsage, 0, MAX_THREADS_NUM * sizeof (bool));
472 427
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
487 if ((*ppCtx)->pTaskManage != NULL) {428 if ((*ppCtx)->pTaskManage != NULL) {
488 delete (*ppCtx)->pTaskManage;429 delete (*ppCtx)->pTaskManage;
489 (*ppCtx)->pTaskManage = NULL;430 (*ppCtx)->pTaskManage = NULL;
@@ -503,6 +444,7 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 13 unmodified lines
503int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32_t iSliceCount) {444int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32_t iSliceCount) {
504 SWelsSvcCodingParam* pCodingParam = pCtx->pSvcParam;445 SWelsSvcCodingParam* pCodingParam = pCtx->pSvcParam;
505 SSpatialLayerConfig* pDlp = &pCodingParam->sSpatialLayers[pCtx->uiDependencyId];446 SSpatialLayerConfig* pDlp = &pCodingParam->sSpatialLayers[pCtx->uiDependencyId];
447 SSlice* pSliceInlayer = pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer;
506 SWelsSliceBs* pSliceBs = NULL;448 SWelsSliceBs* pSliceBs = NULL;
507 const bool kbIsDynamicSlicingMode = (pDlp->sSliceArgument.uiSliceMode == SM_SIZELIMITED_SLICE);449 const bool kbIsDynamicSlicingMode = (pDlp->sSliceArgument.uiSliceMode == SM_SIZELIMITED_SLICE);
508 450
@@ -511,9 +453,9 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 2 unmodified lines
511 int32_t iSliceIdx = 0;453 int32_t iSliceIdx = 0;
512 454
513 if (!kbIsDynamicSlicingMode) {455 if (!kbIsDynamicSlicingMode) {
514 pSliceBs = &pCtx->pSliceBs[0];
515 iNalIdxBase = pLbi->iNalCount = 0;456 iNalIdxBase = pLbi->iNalCount = 0;
516 while (iSliceIdx < iSliceCount) {457 while (iSliceIdx < iSliceCount) {
458 pSliceBs = &pSliceInlayer[iSliceIdx].sSliceBs;
517 if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) {459 if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) {
518 int32_t iNalIdx = 0;460 int32_t iNalIdx = 0;
519 const int32_t iCountNal = pSliceBs->iNalIndex;461 const int32_t iCountNal = pSliceBs->iNalIndex;
@@ -535,7 +477,6 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 15 unmodified lines
535 iNalIdxBase += iCountNal;477 iNalIdxBase += iCountNal;
536 }478 }
537 ++ iSliceIdx;479 ++ iSliceIdx;
538 ++ pSliceBs;
539 }480 }
540 } else { // for SM_SIZELIMITED_SLICE481 } else { // for SM_SIZELIMITED_SLICE
541 const int32_t kiPartitionCnt = iSliceCount;482 const int32_t kiPartitionCnt = iSliceCount;
@@ -549,7 +490,7 @@ int32_t AppendSliceToFrameBs (sWelsEncCtx* pCtx, SLayerBSInfo* pLbi, const int32 · 7 unmodified lines
549 490
550 iSliceIdx = iPartitionIdx;491 iSliceIdx = iPartitionIdx;
551 while (iIdx < kiCountSlicesCoded) {492 while (iIdx < kiCountSlicesCoded) {
552 pSliceBs = &pCtx->pSliceBs[iSliceIdx];493 pSliceBs = &pSliceInlayer[iSliceIdx].sSliceBs;
553 if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) {494 if (pSliceBs != NULL && pSliceBs->uiBsPos > 0) {
554 memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage495 memmove (pCtx->pFrameBs + pCtx->iPosBsBuffer, pSliceBs->pBs, pSliceBs->uiBsPos); // confirmed_safe_unsafe_usage
555 pCtx->iPosBsBuffer += pSliceBs->uiBsPos;496 pCtx->iPosBsBuffer += pSliceBs->uiBsPos;
@@ -665,7 +606,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 109 unmodified lines
665 bool bDsaFlag = false;606 bool bDsaFlag = false;
666 iSliceIdx = pPrivateData->iSliceIndex;607 iSliceIdx = pPrivateData->iSliceIndex;
667 pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx];608 pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx];
668 pSliceBs = &pEncPEncCtx->pSliceBs[iSliceIdx];609 pSliceBs = &pSlice->sSliceBs;
669 610
670 bDsaFlag = ((pParamD->sSliceArgument.uiSliceMode == SM_FIXEDSLCNUM_SLICE) &&611 bDsaFlag = ((pParamD->sSliceArgument.uiSliceMode == SM_FIXEDSLCNUM_SLICE) &&
671 pCodingParam->iMultipleThreadIdc > 1 &&612 pCodingParam->iMultipleThreadIdc > 1 &&
@@ -777,7 +718,7 @@ WELS_THREAD_ROUTINE_TYPE CodingSliceThreadProc (void* arg) { · 105 unmodified lines
777 718
778 SetOneSliceBsBufferUnderMultithread (pEncPEncCtx, kiPartitionId, iSliceIdx);719 SetOneSliceBsBufferUnderMultithread (pEncPEncCtx, kiPartitionId, iSliceIdx);
779 pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx];720 pSlice = &pCurDq->sLayerInfo.pSliceInLayer[iSliceIdx];
780 pSliceBs = &pEncPEncCtx->pSliceBs[iSliceIdx];721 pSliceBs = &pSlice->sSliceBs;
781 722
782 pSliceBs->uiBsPos = 0;723 pSliceBs->uiBsPos = 0;
783 pSliceBs->iNalIndex = 0;724 pSliceBs->iNalIndex = 0;
@@ -1086,9 +1027,9 @@ void TrackSliceConsumeTime (sWelsEncCtx* pCtx, int32_t* pDidList, const int32_t · 302 unmodified lines
1086#endif//#if defined(MT_DEBUG)1027#endif//#if defined(MT_DEBUG)
1087 1028
1088void SetOneSliceBsBufferUnderMultithread (sWelsEncCtx* pCtx, const int32_t kiThreadIdx, const int32_t iSliceIdx) {1029void SetOneSliceBsBufferUnderMultithread (sWelsEncCtx* pCtx, const int32_t kiThreadIdx, const int32_t iSliceIdx) {
1089 pCtx->pSliceBs[iSliceIdx].pBsBuffer = pCtx->pSliceThreading->pThreadBsBuffer[kiThreadIdx];1030 SWelsSliceBs* pSliceBs = &pCtx->pCurDqLayer->sLayerInfo.pSliceInLayer[iSliceIdx].sSliceBs;
1090 pCtx->pSliceBs[iSliceIdx].uiBsPos = 0;1031 pSliceBs->pBsBuffer = pCtx->pSliceThreading->pThreadBsBuffer[kiThreadIdx];
1091 //printf("SetOneSliceBsBufferUnderMultithread, thread %d, slice %d, buffer=%x\n", kiThreadIdx, iSliceIdx, pCtx->pSliceBs[iSliceIdx].pBsBuffer);1032 pSliceBs->uiBsPos = 0;
1092}1033}
1093}1034}
1094 1035

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