History

use WelsUninitEncoderExt rather than FreeMemorySvc which correctly deals with release of vpp memory

sijchen committed 10 years ago

Commit 408b7ca1 parent 8b120601 file · +48 −47Browse files

Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 1 file). Show all

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+48−47
@@ -2433,6 +2433,51 @@ int32_t GetMultipleThreadIdc (SLogContext* pLogCtx, SWelsSvcCodingParam* pCoding · 2432 unmodified lines
24332433 return 0;
24342434 }
24352435
2436+/*!
2437+ * \brief uninitialize Wels encoder core library
2438+ * \pParam pEncCtx sWelsEncCtx*
2439+ * \return none
2440+ */
2441+void WelsUninitEncoderExt (sWelsEncCtx** ppCtx) {
2442+ if (NULL == ppCtx || NULL == *ppCtx)
2443+ return;
2444+
2445+ WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO,
2446+ "WelsUninitEncoderExt(), pCtx= %p, iMultipleThreadIdc= %d.",
2447+ (void*) (*ppCtx), (*ppCtx)->pSvcParam->iMultipleThreadIdc);
2448+
2449+#if defined(STAT_OUTPUT)
2450+ StatOverallEncodingExt (*ppCtx);
2451+#endif
2452+
2453+ if ((*ppCtx)->pSvcParam->iMultipleThreadIdc > 1 && (*ppCtx)->pSliceThreading != NULL) {
2454+ const int32_t iThreadCount = (*ppCtx)->pSvcParam->iMultipleThreadIdc;
2455+ int32_t iThreadIdx = 0;
2456+
2457+ while (iThreadIdx < iThreadCount) {
2458+ int res = 0;
2459+ if ((*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx]) {
2460+ WelsEventSignal (& (*ppCtx)->pSliceThreading->pExitEncodeEvent[iThreadIdx]);
2461+ WelsEventSignal (& (*ppCtx)->pSliceThreading->pThreadMasterEvent[iThreadIdx]);
2462+ res = WelsThreadJoin ((*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx]); // waiting thread exit
2463+ WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO, "WelsUninitEncoderExt(), pthread_join(pThreadHandles%d) return %d..",
2464+ iThreadIdx,
2465+ res);
2466+ (*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx] = 0;
2467+ }
2468+ ++ iThreadIdx;
2469+ }
2470+ }
2471+
2472+ if ((*ppCtx)->pVpp) {
2473+ (*ppCtx)->pVpp->FreeSpatialPictures (*ppCtx);
2474+ delete (*ppCtx)->pVpp;
2475+ (*ppCtx)->pVpp = NULL;
2476+ }
2477+ FreeMemorySvc (ppCtx);
2478+ *ppCtx = NULL;
2479+}
2480+
24362481 /*!
24372482 * \brief initialize Wels avc encoder core library
24382483 * \pParam ppCtx sWelsEncCtx**
@@ -2502,7 +2547,7 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 63 unmodified lines
25022547 iRet = RequestMemorySvc (&pCtx, pExistingParasetList);
25032548 if (iRet != 0) {
25042549 WelsLog (pLogCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), RequestMemorySvc failed return %d.", iRet);
2505− FreeMemorySvc (&pCtx);
2550+ WelsUninitEncoderExt (&pCtx);
25062551 return iRet;
25072552 }
25082553
@@ -2514,12 +2559,12 @@ int32_t WelsInitEncoderExt (sWelsEncCtx** ppCtx, SWelsSvcCodingParam* pCodingPar · 5 unmodified lines
25142559 if (pCtx->pVpp == NULL) {
25152560 iRet = 1;
25162561 WelsLog (pLogCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), pOut of memory in case new CWelsPreProcess().");
2517− FreeMemorySvc (&pCtx);
2562+ WelsUninitEncoderExt (&pCtx);
25182563 return iRet;
25192564 }
25202565 if ((iRet = pCtx->pVpp->AllocSpatialPictures (pCtx, pCtx->pSvcParam)) != 0) {
25212566 WelsLog (pLogCtx, WELS_LOG_ERROR, "WelsInitEncoderExt(), pVPP alloc spatial pictures failed");
2522− FreeMemorySvc (&pCtx);
2567+ WelsUninitEncoderExt (&pCtx);
25232568 return iRet;
25242569 }
25252570
@@ -2618,50 +2663,6 @@ void StatOverallEncodingExt (sWelsEncCtx* pCtx) { · 92 unmodified lines
26182663 }
26192664 }
26202665 #endif
2621−/*!
2622− * \brief uninitialize Wels encoder core library
2623− * \pParam pEncCtx sWelsEncCtx*
2624− * \return none
2625− */
2626−void WelsUninitEncoderExt (sWelsEncCtx** ppCtx) {
2627− if (NULL == ppCtx || NULL == *ppCtx)
2628− return;
2629−
2630− WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO,
2631− "WelsUninitEncoderExt(), pCtx= %p, iMultipleThreadIdc= %d.",
2632− (void*) (*ppCtx), (*ppCtx)->pSvcParam->iMultipleThreadIdc);
2633−
2634−#if defined(STAT_OUTPUT)
2635− StatOverallEncodingExt (*ppCtx);
2636−#endif
2637−
2638− if ((*ppCtx)->pSvcParam->iMultipleThreadIdc > 1 && (*ppCtx)->pSliceThreading != NULL) {
2639− const int32_t iThreadCount = (*ppCtx)->pSvcParam->iMultipleThreadIdc;
2640− int32_t iThreadIdx = 0;
2641−
2642− while (iThreadIdx < iThreadCount) {
2643− int res = 0;
2644− if ((*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx]) {
2645− WelsEventSignal (& (*ppCtx)->pSliceThreading->pExitEncodeEvent[iThreadIdx]);
2646− WelsEventSignal (& (*ppCtx)->pSliceThreading->pThreadMasterEvent[iThreadIdx]);
2647− res = WelsThreadJoin ((*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx]); // waiting thread exit
2648− WelsLog (& (*ppCtx)->sLogCtx, WELS_LOG_INFO, "WelsUninitEncoderExt(), pthread_join(pThreadHandles%d) return %d..",
2649− iThreadIdx,
2650− res);
2651− (*ppCtx)->pSliceThreading->pThreadHandles[iThreadIdx] = 0;
2652− }
2653− ++ iThreadIdx;
2654− }
2655− }
2656−
2657− if ((*ppCtx)->pVpp) {
2658− (*ppCtx)->pVpp->FreeSpatialPictures (*ppCtx);
2659− delete (*ppCtx)->pVpp;
2660− (*ppCtx)->pVpp = NULL;
2661− }
2662− FreeMemorySvc (ppCtx);
2663− *ppCtx = NULL;
2664−}
26652666
26662667 /*!
26672668 * \brief get temporal level due to configuration and coding context

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