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