History

add thread-based slice buffer and refact reallocate process for futher change

huade committed 10 years ago

Commit 5e8a7161 parent 3e538613 files · +70 −12Browse files

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

Unified · Split

codec/encoder/core/src/slice_multi_threading.cpp+36−11
@@ -251,21 +251,26 @@ void DynamicAdjustSlicing (sWelsEncCtx* pCtx, · 250 unmodified lines
251251 int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingParam, const int32_t iCountBsLen,
252252 const int32_t iMaxSliceBufferSize, bool bDynamicSlice) {
253253 CMemoryAlign* pMa = NULL;
254− SWelsSvcCodingParam* pPara = NULL;
254+ SWelsSvcCodingParam* pPara = NULL;
255255 SSliceThreading* pSmt = NULL;
256256 int32_t iNumSpatialLayers = 0;
257257 int32_t iThreadNum = 0;
258258 int32_t iIdx = 0;
259− int32_t iReturn = ENC_RETURN_SUCCESS;
259+ int32_t iReturn = ENC_RETURN_SUCCESS;
260+ int32_t iMaxSliceNumInThread = 0;
261+
260262 if (NULL == ppCtx || NULL == pCodingParam || NULL == *ppCtx || iCountBsLen <= 0)
261263 return 1;
262264 #if defined(ENABLE_TRACE_MT)
263265 SLogContext* pLogCtx = & ((*ppCtx)->sLogCtx);
264266 #endif
265− pMa = (*ppCtx)->pMemAlign;
266− pPara = pCodingParam;
267− iNumSpatialLayers = pPara->iSpatialLayerNum;
268− iThreadNum = pPara->iMultipleThreadIdc;
267+ pMa = (*ppCtx)->pMemAlign;
268+ pPara = pCodingParam;
269+ iNumSpatialLayers = pPara->iSpatialLayerNum;
270+ iThreadNum = pPara->iMultipleThreadIdc;
271+
272+ assert (iThreadNum > 0);
273+ iMaxSliceNumInThread = ((*ppCtx)->iMaxSliceCount / iThreadNum + 1) * 2;
269274
270275 pSmt = (SSliceThreading*)pMa->WelsMalloc (sizeof (SSliceThreading), "SSliceThreading");
271276 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt), FreeMemorySvc (ppCtx))
@@ -299,10 +304,12 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 27 unmodified lines
299304
300305 iIdx = 0;
301306 while (iIdx < iThreadNum) {
302− pSmt->pThreadPEncCtx[iIdx].pWelsPEncCtx = (void*) *ppCtx;
303− pSmt->pThreadPEncCtx[iIdx].iSliceIndex = iIdx;
304− pSmt->pThreadPEncCtx[iIdx].iThreadIndex = iIdx;
305− pSmt->pThreadHandles[iIdx] = 0;
307+ pSmt->pThreadPEncCtx[iIdx].pWelsPEncCtx = (void*) *ppCtx;
308+ pSmt->pThreadPEncCtx[iIdx].iSliceIndex = iIdx;
309+ pSmt->pThreadPEncCtx[iIdx].iThreadIndex = iIdx;
310+ pSmt->iMaxSliceNumInThread[iIdx] = iMaxSliceNumInThread;
311+ pSmt->iEncodedSliceNumInThread[iIdx] = 0;
312+ pSmt->pThreadHandles[iIdx] = 0;
306313
307314 WelsSnprintf (name, SEM_NAME_MAX, "ee%d%s", iIdx, pSmt->eventNamespace);
308315 err = WelsEventOpen (&pSmt->pExitEncodeEvent[iIdx], name);
@@ -329,10 +336,18 @@ int32_t RequestMtResource (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPara · 20 unmodified lines
329336 pSmt->pThreadBsBuffer[iIdx] = (uint8_t*)pMa->WelsMalloc (iCountBsLen, "pSmt->pThreadBsBuffer");
330337 WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pThreadBsBuffer[iIdx]), FreeMemorySvc (ppCtx))
331338
339+ pSmt->pSliceInThread[iIdx] = (SSlice*)pMa->WelsMalloc (sizeof (SSlice)*iMaxSliceNumInThread, "pSmt->pSliceInThread");
340+ WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->pSliceInThread[iIdx]), FreeMemorySvc (ppCtx))
341+
342+ pSmt->piSliceIndexInThread[iIdx] = (int32_t *)pMa->WelsMalloc (iMaxSliceNumInThread, "pSmt->piSliceIndexInThread");
343+ WELS_VERIFY_RETURN_PROC_IF (1, (NULL == pSmt->piSliceIndexInThread[iIdx]), FreeMemorySvc (ppCtx))
344+
332345 ++ iIdx;
333346 }
334347 for (; iIdx < MAX_THREADS_NUM; iIdx++) {
335− pSmt->pThreadBsBuffer[iIdx] = NULL;
348+ pSmt->pThreadBsBuffer[iIdx] = NULL;
349+ pSmt->pSliceInThread[iIdx] = NULL;
350+ pSmt->piSliceIndexInThread[iIdx] = NULL;
336351 }
337352
338353 WelsSnprintf (name, SEM_NAME_MAX, "scm%s", pSmt->eventNamespace);
@@ -409,6 +424,16 @@ void ReleaseMtResource (sWelsEncCtx** ppCtx) { · 70 unmodified lines
409424 pMa->WelsFree (pSmt->pThreadBsBuffer[i], "pSmt->pThreadBsBuffer");
410425 pSmt->pThreadBsBuffer[i] = NULL;
411426 }
427+
428+ if (pSmt->pSliceInThread[i]) {
429+ pMa->WelsFree (pSmt->pSliceInThread[i], "pSmt->pSliceInThread");
430+ pSmt->pSliceInThread[i] = NULL;
431+ }
432+
433+ if (pSmt->piSliceIndexInThread[i]) {
434+ pMa->WelsFree (pSmt->piSliceIndexInThread[i], "pSmt->piSliceIndexInThread");
435+ pSmt->piSliceIndexInThread[i] = NULL;
436+ }
412437 }
413438 memset (&pSmt->bThreadBsBufferUsage, 0, MAX_THREADS_NUM * sizeof (bool));
414439

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