History

add dec memory check

huili2 committed 11 years ago

Commit 3cb417f1 parent 9ecc67112 files · +196 −141Browse files

Showing the changes to codec/decoder/core/src/decoder.cpp (1 of 12 files). Show all

Unified · Split

codec/decoder/core/src/decoder.cpp+42−29
@@ -57,7 +57,7 @@ namespace WelsDec { · 56 unmodified lines
5757
5858 extern PPicture AllocPicture (PWelsDecoderContext pCtx, const int32_t kiPicWidth, const int32_t kiPicHeight);
5959
60−extern void FreePicture (PPicture pPic);
60+extern void FreePicture (PPicture pPic, CMemoryAlign* pMa);
6161
6262 static int32_t CreatePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, const int32_t kiSize,
6363 const int32_t kiPicWidth, const int32_t kiPicHeight) {
@@ -67,17 +67,19 @@ static int32_t CreatePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, cons · 3 unmodified lines
6767 return 1;
6868 }
6969
70− pPicBuf = (PPicBuff)WelsMallocz (sizeof (SPicBuff), "PPicBuff");
70+ CMemoryAlign* pMa = pCtx->pMemAlign;
71+
72+ pPicBuf = (PPicBuff)pMa->WelsMallocz (sizeof (SPicBuff), "PPicBuff");
7173
7274 if (NULL == pPicBuf) {
7375 return 1;
7476 }
7577
76− pPicBuf->ppPic = (PPicture*)WelsMallocz (kiSize * sizeof (PPicture), "PPicture*");
78+ pPicBuf->ppPic = (PPicture*)pMa->WelsMallocz (kiSize * sizeof (PPicture), "PPicture*");
7779
7880 if (NULL == pPicBuf->ppPic) {
7981 pPicBuf->iCapacity = 0;
80− DestroyPicBuff (&pPicBuf);
82+ DestroyPicBuff (&pPicBuf, pMa);
8183 return 1;
8284 }
8385
@@ -86,7 +88,7 @@ static int32_t CreatePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, cons · 2 unmodified lines
8688 if (NULL == pPic) {
8789 // init capacity first for free memory
8890 pPicBuf->iCapacity = iPicIdx;
89− DestroyPicBuff (&pPicBuf);
91+ DestroyPicBuff (&pPicBuf, pMa);
9092 return 1;
9193 }
9294 pPicBuf->ppPic[iPicIdx] = pPic;
@@ -109,17 +111,18 @@ static int32_t IncreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 16 unmodified lines
109111 return 1;
110112 }
111113
112− pPicNewBuf = (PPicBuff)WelsMallocz (sizeof (SPicBuff), "PPicBuff");
114+ CMemoryAlign* pMa = pCtx->pMemAlign;
115+ pPicNewBuf = (PPicBuff)pMa->WelsMallocz (sizeof (SPicBuff), "PPicBuff");
113116
114117 if (NULL == pPicNewBuf) {
115118 return 1;
116119 }
117120
118− pPicNewBuf->ppPic = (PPicture*)WelsMallocz (kiNewSize * sizeof (PPicture), "PPicture*");
121+ pPicNewBuf->ppPic = (PPicture*)pMa->WelsMallocz (kiNewSize * sizeof (PPicture), "PPicture*");
119122
120123 if (NULL == pPicNewBuf->ppPic) {
121124 pPicNewBuf->iCapacity = 0;
122− DestroyPicBuff (&pPicNewBuf);
125+ DestroyPicBuff (&pPicNewBuf, pMa);
123126 return 1;
124127 }
125128
@@ -129,7 +132,7 @@ static int32_t IncreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 3 unmodified lines
129132 if (NULL == pPic) {
130133 // Set maximum capacity as the new malloc memory at the tail
131134 pPicNewBuf->iCapacity = iPicIdx;
132− DestroyPicBuff (&pPicNewBuf);
135+ DestroyPicBuff (&pPicNewBuf, pMa);
133136 return 1;
134137 }
135138 pPicNewBuf->ppPic[iPicIdx] = pPic;
@@ -152,12 +155,12 @@ static int32_t IncreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 16 unmodified lines
152155 }
153156 // remove old PicBuf
154157 if (pPicOldBuf->ppPic != NULL) {
155− WelsFree (pPicOldBuf->ppPic, "pPicOldBuf->queue");
158+ pMa->WelsFree (pPicOldBuf->ppPic, "pPicOldBuf->queue");
156159 pPicOldBuf->ppPic = NULL;
157160 }
158161 pPicOldBuf->iCapacity = 0;
159162 pPicOldBuf->iCurrentIdx = 0;
160− WelsFree (pPicOldBuf, "pPicOldBuf");
163+ pMa->WelsFree (pPicOldBuf, "pPicOldBuf");
161164 pPicOldBuf = NULL;
162165 return 0;
163166 }
@@ -171,17 +174,19 @@ static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 7 unmodified lines
171174 return 1;
172175 }
173176
174− pPicNewBuf = (PPicBuff)WelsMallocz (sizeof (SPicBuff), "PPicBuff");
177+ CMemoryAlign* pMa = pCtx->pMemAlign;
178+
179+ pPicNewBuf = (PPicBuff)pMa->WelsMallocz (sizeof (SPicBuff), "PPicBuff");
175180
176181 if (NULL == pPicNewBuf) {
177182 return 1;
178183 }
179184
180− pPicNewBuf->ppPic = (PPicture*)WelsMallocz (kiNewSize * sizeof (PPicture), "PPicture*");
185+ pPicNewBuf->ppPic = (PPicture*)pMa->WelsMallocz (kiNewSize * sizeof (PPicture), "PPicture*");
181186
182187 if (NULL == pPicNewBuf->ppPic) {
183188 pPicNewBuf->iCapacity = 0;
184− DestroyPicBuff (&pPicNewBuf);
189+ DestroyPicBuff (&pPicNewBuf, pMa);
185190 return 1;
186191 }
187192
@@ -207,7 +212,7 @@ static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 19 unmodified lines
207212 for (iPicIdx = iDelIdx; iPicIdx < kiOldSize; iPicIdx++) {
208213 if (iPrevPicIdx != iPicIdx) {
209214 if (pPicOldBuf->ppPic[iPicIdx] != NULL) {
210− FreePicture (pPicOldBuf->ppPic[iPicIdx]);
215+ FreePicture (pPicOldBuf->ppPic[iPicIdx], pMa);
211216 pPicOldBuf->ppPic[iPicIdx] = NULL;
212217 }
213218 }
@@ -226,18 +231,18 @@ static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 12 unmodified lines
226231 }
227232 // remove old PicBuf
228233 if (pPicOldBuf->ppPic != NULL) {
229− WelsFree (pPicOldBuf->ppPic, "pPicOldBuf->queue");
234+ pMa->WelsFree (pPicOldBuf->ppPic, "pPicOldBuf->queue");
230235 pPicOldBuf->ppPic = NULL;
231236 }
232237 pPicOldBuf->iCapacity = 0;
233238 pPicOldBuf->iCurrentIdx = 0;
234− WelsFree (pPicOldBuf, "pPicOldBuf");
239+ pMa->WelsFree (pPicOldBuf, "pPicOldBuf");
235240 pPicOldBuf = NULL;
236241
237242 return 0;
238243 }
239244
240−void DestroyPicBuff (PPicBuff* ppPicBuf) {
245+void DestroyPicBuff (PPicBuff* ppPicBuf, CMemoryAlign* pMa) {
241246 PPicBuff pPicBuf = NULL;
242247
243248 if (NULL == ppPicBuf || NULL == *ppPicBuf)
@@ -249,20 +254,20 @@ void DestroyPicBuff (PPicBuff* ppPicBuf) { · 5 unmodified lines
249254 while (iPicIdx < pPicBuf->iCapacity) {
250255 PPicture pPic = pPicBuf->ppPic[iPicIdx];
251256 if (pPic != NULL) {
252− FreePicture (pPic);
257+ FreePicture (pPic, pMa);
253258 }
254259 pPic = NULL;
255260 ++ iPicIdx;
256261 }
257262
258− WelsFree (pPicBuf->ppPic, "pPicBuf->queue");
263+ pMa->WelsFree (pPicBuf->ppPic, "pPicBuf->queue");
259264
260265 pPicBuf->ppPic = NULL;
261266 }
262267 pPicBuf->iCapacity = 0;
263268 pPicBuf->iCurrentIdx = 0;
264269
265− WelsFree (pPicBuf, "pPicBuf");
270+ pMa->WelsFree (pPicBuf, "pPicBuf");
266271
267272 pPicBuf = NULL;
268273 *ppPicBuf = NULL;
@@ -270,10 +275,11 @@ void DestroyPicBuff (PPicBuff* ppPicBuf) { · 1 unmodified line
270275 /*
271276 * fill data fields in default for decoder context
272277 */
273−void WelsDecoderDefaults (PWelsDecoderContext pCtx, SLogContext* pLogCtx) {
278+void WelsDecoderDefaults (PWelsDecoderContext pCtx, SLogContext* pLogCtx, CMemoryAlign* pMa) {
274279 int32_t iCpuCores = 1;
275280 memset (pCtx, 0, sizeof (SWelsDecoderContext)); // fill zero first
276281 pCtx->sLogCtx = *pLogCtx;
282+ pCtx->pMemAlign = pMa;
277283
278284 pCtx->pArgDec = NULL;
279285
@@ -360,6 +366,7 @@ int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const · 80 unmodified lines
360366 int32_t iListIdx = 0; //, mb_blocks = 0;
361367 int32_t iPicQueueSize = 0; // adaptive size of picture queue, = (pSps->iNumRefFrames x 2)
362368 bool bNeedChangePicQueue = true;
369+ CMemoryAlign* pMa = pCtx->pMemAlign;
363370
364371 WELS_VERIFY_RETURN_IF (ERR_INFO_INVALID_PARAM, (NULL == pCtx || kiPicWidth <= 0 || kiPicHeight <= 0))
365372
@@ -404,7 +411,7 @@ int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const · 38 unmodified lines
404411 for (iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx) {
405412 PPicBuff* ppPic = &pCtx->pPicBuff[iListIdx];
406413 if (NULL != ppPic && NULL != *ppPic) {
407− DestroyPicBuff (ppPic);
414+ DestroyPicBuff (ppPic, pMa);
408415 }
409416 }
410417
@@ -425,7 +432,7 @@ int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const · 14 unmodified lines
425432 pCtx->pDec = NULL; // need prefetch a new pic due to spatial size changed
426433
427434 if (pCtx->pCabacDecEngine == NULL)
428− pCtx->pCabacDecEngine = (SWelsCabacDecEngine*) WelsMallocz (sizeof (SWelsCabacDecEngine), "pCtx->pCabacDecEngine");
435+ pCtx->pCabacDecEngine = (SWelsCabacDecEngine*) pMa->WelsMallocz (sizeof (SWelsCabacDecEngine), "pCtx->pCabacDecEngine");
429436 WELS_VERIFY_RETURN_IF (ERR_INFO_OUT_OF_MEMORY, (NULL == pCtx->pCabacDecEngine))
430437 return ERR_NONE;
431438 }
@@ -435,6 +442,7 @@ int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const · 3 unmodified lines
435442 */
436443 void WelsFreeMem (PWelsDecoderContext pCtx) {
437444 int32_t iListIdx = 0;
445+ CMemoryAlign* pMa = pCtx->pMemAlign;
438446
439447 /* TODO: free memory blocks introduced in avc */
440448 ResetFmoList (pCtx);
@@ -445,7 +453,7 @@ void WelsFreeMem (PWelsDecoderContext pCtx) { · 4 unmodified lines
445453 for (iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx) {
446454 PPicBuff* pPicBuff = &pCtx->pPicBuff[iListIdx];
447455 if (NULL != pPicBuff && NULL != *pPicBuff) {
448− DestroyPicBuff (pPicBuff);
456+ DestroyPicBuff (pPicBuff, pMa);
449457 }
450458 }
451459
@@ -456,7 +464,7 @@ void WelsFreeMem (PWelsDecoderContext pCtx) { · 4 unmodified lines
456464 pCtx->iLastImgHeightInPixel = 0;
457465 pCtx->bFreezeOutput = true;
458466 pCtx->bHaveGotMemory = false;
459− WelsFree (pCtx->pCabacDecEngine, "pCtx->pCabacDecEngine");
467+ pMa->WelsFree (pCtx->pCabacDecEngine, "pCtx->pCabacDecEngine");
460468 }
461469
462470 /*!
@@ -517,7 +525,9 @@ int32_t DecoderConfigParam (PWelsDecoderContext pCtx, const SDecodingParam* kpPa · 54 unmodified lines
517525 if (NULL == pCtx || NULL == kpParam)
518526 return 1;
519527
520− pCtx->pParam = (SDecodingParam*)WelsMallocz (sizeof (SDecodingParam), "SDecodingParam");
528+ CMemoryAlign* pMa = pCtx->pMemAlign;
529+
530+ pCtx->pParam = (SDecodingParam*)pMa->WelsMallocz (sizeof (SDecodingParam), "SDecodingParam");
521531
522532 if (NULL == pCtx->pParam)
523533 return 1;
@@ -565,7 +575,7 @@ int32_t WelsInitDecoder (PWelsDecoderContext pCtx, const bool bParseOnly, SLogCo · 41 unmodified lines
565575 }
566576
567577 // default
568− WelsDecoderDefaults (pCtx, pLogCtx);
578+ WelsDecoderDefaults (pCtx, pLogCtx, pCtx->pMemAlign);
569579
570580 pCtx->bParseOnly = bParseOnly;
571581 // open decoder
@@ -834,7 +844,10 @@ int32_t SyncPictureResolutionExt (PWelsDecoderContext pCtx, const int32_t kiMbWi · 262 unmodified lines
834844 "SyncPictureResolutionExt()::InitialDqLayersContext--buffer allocated failure.");
835845 pCtx->iErrorCode = dsOutOfMemory;
836846 }
837−
847+#if defined(MEMORY_MONITOR)
848+ WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO, "SyncPictureResolutionExt(), overall memory usage: %llu bytes",
849+ static_cast<unsigned long long> (sizeof (SWelsDecoderContext) + pCtx->pMemAlign->WelsGetMemoryUsage()));
850+#endif//MEMORY_MONITOR
838851 return iErr;
839852 }
840853

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