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
57 57
58extern PPicture AllocPicture (PWelsDecoderContext pCtx, const int32_t kiPicWidth, const int32_t kiPicHeight);58extern PPicture AllocPicture (PWelsDecoderContext pCtx, const int32_t kiPicWidth, const int32_t kiPicHeight);
59 59
60extern void FreePicture (PPicture pPic);60extern void FreePicture (PPicture pPic, CMemoryAlign* pMa);
61 61
62static int32_t CreatePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, const int32_t kiSize,62static int32_t CreatePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, const int32_t kiSize,
63 const int32_t kiPicWidth, const int32_t kiPicHeight) {63 const int32_t kiPicWidth, const int32_t kiPicHeight) {
@@ -67,17 +67,19 @@ static int32_t CreatePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, cons · 3 unmodified lines
67 return 1;67 return 1;
68 }68 }
69 69
70 pPicBuf = (PPicBuff)WelsMallocz (sizeof (SPicBuff), "PPicBuff");70 CMemoryAlign* pMa = pCtx->pMemAlign;
71
72 pPicBuf = (PPicBuff)pMa->WelsMallocz (sizeof (SPicBuff), "PPicBuff");
71 73
72 if (NULL == pPicBuf) {74 if (NULL == pPicBuf) {
73 return 1;75 return 1;
74 }76 }
75 77
76 pPicBuf->ppPic = (PPicture*)WelsMallocz (kiSize * sizeof (PPicture), "PPicture*");78 pPicBuf->ppPic = (PPicture*)pMa->WelsMallocz (kiSize * sizeof (PPicture), "PPicture*");
77 79
78 if (NULL == pPicBuf->ppPic) {80 if (NULL == pPicBuf->ppPic) {
79 pPicBuf->iCapacity = 0;81 pPicBuf->iCapacity = 0;
80 DestroyPicBuff (&pPicBuf);82 DestroyPicBuff (&pPicBuf, pMa);
81 return 1;83 return 1;
82 }84 }
83 85
@@ -86,7 +88,7 @@ static int32_t CreatePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, cons · 2 unmodified lines
86 if (NULL == pPic) {88 if (NULL == pPic) {
87 // init capacity first for free memory89 // init capacity first for free memory
88 pPicBuf->iCapacity = iPicIdx;90 pPicBuf->iCapacity = iPicIdx;
89 DestroyPicBuff (&pPicBuf);91 DestroyPicBuff (&pPicBuf, pMa);
90 return 1;92 return 1;
91 }93 }
92 pPicBuf->ppPic[iPicIdx] = pPic;94 pPicBuf->ppPic[iPicIdx] = pPic;
@@ -109,17 +111,18 @@ static int32_t IncreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 16 unmodified lines
109 return 1;111 return 1;
110 }112 }
111 113
112 pPicNewBuf = (PPicBuff)WelsMallocz (sizeof (SPicBuff), "PPicBuff");114 CMemoryAlign* pMa = pCtx->pMemAlign;
115 pPicNewBuf = (PPicBuff)pMa->WelsMallocz (sizeof (SPicBuff), "PPicBuff");
113 116
114 if (NULL == pPicNewBuf) {117 if (NULL == pPicNewBuf) {
115 return 1;118 return 1;
116 }119 }
117 120
118 pPicNewBuf->ppPic = (PPicture*)WelsMallocz (kiNewSize * sizeof (PPicture), "PPicture*");121 pPicNewBuf->ppPic = (PPicture*)pMa->WelsMallocz (kiNewSize * sizeof (PPicture), "PPicture*");
119 122
120 if (NULL == pPicNewBuf->ppPic) {123 if (NULL == pPicNewBuf->ppPic) {
121 pPicNewBuf->iCapacity = 0;124 pPicNewBuf->iCapacity = 0;
122 DestroyPicBuff (&pPicNewBuf);125 DestroyPicBuff (&pPicNewBuf, pMa);
123 return 1;126 return 1;
124 }127 }
125 128
@@ -129,7 +132,7 @@ static int32_t IncreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 3 unmodified lines
129 if (NULL == pPic) {132 if (NULL == pPic) {
130 // Set maximum capacity as the new malloc memory at the tail133 // Set maximum capacity as the new malloc memory at the tail
131 pPicNewBuf->iCapacity = iPicIdx;134 pPicNewBuf->iCapacity = iPicIdx;
132 DestroyPicBuff (&pPicNewBuf);135 DestroyPicBuff (&pPicNewBuf, pMa);
133 return 1;136 return 1;
134 }137 }
135 pPicNewBuf->ppPic[iPicIdx] = pPic;138 pPicNewBuf->ppPic[iPicIdx] = pPic;
@@ -152,12 +155,12 @@ static int32_t IncreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 16 unmodified lines
152 }155 }
153// remove old PicBuf156// remove old PicBuf
154 if (pPicOldBuf->ppPic != NULL) {157 if (pPicOldBuf->ppPic != NULL) {
155 WelsFree (pPicOldBuf->ppPic, "pPicOldBuf->queue");158 pMa->WelsFree (pPicOldBuf->ppPic, "pPicOldBuf->queue");
156 pPicOldBuf->ppPic = NULL;159 pPicOldBuf->ppPic = NULL;
157 }160 }
158 pPicOldBuf->iCapacity = 0;161 pPicOldBuf->iCapacity = 0;
159 pPicOldBuf->iCurrentIdx = 0;162 pPicOldBuf->iCurrentIdx = 0;
160 WelsFree (pPicOldBuf, "pPicOldBuf");163 pMa->WelsFree (pPicOldBuf, "pPicOldBuf");
161 pPicOldBuf = NULL;164 pPicOldBuf = NULL;
162 return 0;165 return 0;
163}166}
@@ -171,17 +174,19 @@ static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 7 unmodified lines
171 return 1;174 return 1;
172 }175 }
173 176
174 pPicNewBuf = (PPicBuff)WelsMallocz (sizeof (SPicBuff), "PPicBuff");177 CMemoryAlign* pMa = pCtx->pMemAlign;
178
179 pPicNewBuf = (PPicBuff)pMa->WelsMallocz (sizeof (SPicBuff), "PPicBuff");
175 180
176 if (NULL == pPicNewBuf) {181 if (NULL == pPicNewBuf) {
177 return 1;182 return 1;
178 }183 }
179 184
180 pPicNewBuf->ppPic = (PPicture*)WelsMallocz (kiNewSize * sizeof (PPicture), "PPicture*");185 pPicNewBuf->ppPic = (PPicture*)pMa->WelsMallocz (kiNewSize * sizeof (PPicture), "PPicture*");
181 186
182 if (NULL == pPicNewBuf->ppPic) {187 if (NULL == pPicNewBuf->ppPic) {
183 pPicNewBuf->iCapacity = 0;188 pPicNewBuf->iCapacity = 0;
184 DestroyPicBuff (&pPicNewBuf);189 DestroyPicBuff (&pPicNewBuf, pMa);
185 return 1;190 return 1;
186 }191 }
187 192
@@ -207,7 +212,7 @@ static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 19 unmodified lines
207 for (iPicIdx = iDelIdx; iPicIdx < kiOldSize; iPicIdx++) {212 for (iPicIdx = iDelIdx; iPicIdx < kiOldSize; iPicIdx++) {
208 if (iPrevPicIdx != iPicIdx) {213 if (iPrevPicIdx != iPicIdx) {
209 if (pPicOldBuf->ppPic[iPicIdx] != NULL) {214 if (pPicOldBuf->ppPic[iPicIdx] != NULL) {
210 FreePicture (pPicOldBuf->ppPic[iPicIdx]);215 FreePicture (pPicOldBuf->ppPic[iPicIdx], pMa);
211 pPicOldBuf->ppPic[iPicIdx] = NULL;216 pPicOldBuf->ppPic[iPicIdx] = NULL;
212 }217 }
213 }218 }
@@ -226,18 +231,18 @@ static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 12 unmodified lines
226 }231 }
227 // remove old PicBuf232 // remove old PicBuf
228 if (pPicOldBuf->ppPic != NULL) {233 if (pPicOldBuf->ppPic != NULL) {
229 WelsFree (pPicOldBuf->ppPic, "pPicOldBuf->queue");234 pMa->WelsFree (pPicOldBuf->ppPic, "pPicOldBuf->queue");
230 pPicOldBuf->ppPic = NULL;235 pPicOldBuf->ppPic = NULL;
231 }236 }
232 pPicOldBuf->iCapacity = 0;237 pPicOldBuf->iCapacity = 0;
233 pPicOldBuf->iCurrentIdx = 0;238 pPicOldBuf->iCurrentIdx = 0;
234 WelsFree (pPicOldBuf, "pPicOldBuf");239 pMa->WelsFree (pPicOldBuf, "pPicOldBuf");
235 pPicOldBuf = NULL;240 pPicOldBuf = NULL;
236 241
237 return 0;242 return 0;
238}243}
239 244
240void DestroyPicBuff (PPicBuff* ppPicBuf) {245void DestroyPicBuff (PPicBuff* ppPicBuf, CMemoryAlign* pMa) {
241 PPicBuff pPicBuf = NULL;246 PPicBuff pPicBuf = NULL;
242 247
243 if (NULL == ppPicBuf || NULL == *ppPicBuf)248 if (NULL == ppPicBuf || NULL == *ppPicBuf)
@@ -249,20 +254,20 @@ void DestroyPicBuff (PPicBuff* ppPicBuf) { · 5 unmodified lines
249 while (iPicIdx < pPicBuf->iCapacity) {254 while (iPicIdx < pPicBuf->iCapacity) {
250 PPicture pPic = pPicBuf->ppPic[iPicIdx];255 PPicture pPic = pPicBuf->ppPic[iPicIdx];
251 if (pPic != NULL) {256 if (pPic != NULL) {
252 FreePicture (pPic);257 FreePicture (pPic, pMa);
253 }258 }
254 pPic = NULL;259 pPic = NULL;
255 ++ iPicIdx;260 ++ iPicIdx;
256 }261 }
257 262
258 WelsFree (pPicBuf->ppPic, "pPicBuf->queue");263 pMa->WelsFree (pPicBuf->ppPic, "pPicBuf->queue");
259 264
260 pPicBuf->ppPic = NULL;265 pPicBuf->ppPic = NULL;
261 }266 }
262 pPicBuf->iCapacity = 0;267 pPicBuf->iCapacity = 0;
263 pPicBuf->iCurrentIdx = 0;268 pPicBuf->iCurrentIdx = 0;
264 269
265 WelsFree (pPicBuf, "pPicBuf");270 pMa->WelsFree (pPicBuf, "pPicBuf");
266 271
267 pPicBuf = NULL;272 pPicBuf = NULL;
268 *ppPicBuf = NULL;273 *ppPicBuf = NULL;
@@ -270,10 +275,11 @@ void DestroyPicBuff (PPicBuff* ppPicBuf) { · 1 unmodified line
270/*275/*
271 * fill data fields in default for decoder context276 * fill data fields in default for decoder context
272 */277 */
273void WelsDecoderDefaults (PWelsDecoderContext pCtx, SLogContext* pLogCtx) {278void WelsDecoderDefaults (PWelsDecoderContext pCtx, SLogContext* pLogCtx, CMemoryAlign* pMa) {
274 int32_t iCpuCores = 1;279 int32_t iCpuCores = 1;
275 memset (pCtx, 0, sizeof (SWelsDecoderContext)); // fill zero first280 memset (pCtx, 0, sizeof (SWelsDecoderContext)); // fill zero first
276 pCtx->sLogCtx = *pLogCtx;281 pCtx->sLogCtx = *pLogCtx;
282 pCtx->pMemAlign = pMa;
277 283
278 pCtx->pArgDec = NULL;284 pCtx->pArgDec = NULL;
279 285
@@ -360,6 +366,7 @@ int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const · 80 unmodified lines
360 int32_t iListIdx = 0; //, mb_blocks = 0;366 int32_t iListIdx = 0; //, mb_blocks = 0;
361 int32_t iPicQueueSize = 0; // adaptive size of picture queue, = (pSps->iNumRefFrames x 2)367 int32_t iPicQueueSize = 0; // adaptive size of picture queue, = (pSps->iNumRefFrames x 2)
362 bool bNeedChangePicQueue = true;368 bool bNeedChangePicQueue = true;
369 CMemoryAlign* pMa = pCtx->pMemAlign;
363 370
364 WELS_VERIFY_RETURN_IF (ERR_INFO_INVALID_PARAM, (NULL == pCtx || kiPicWidth <= 0 || kiPicHeight <= 0))371 WELS_VERIFY_RETURN_IF (ERR_INFO_INVALID_PARAM, (NULL == pCtx || kiPicWidth <= 0 || kiPicHeight <= 0))
365 372
@@ -404,7 +411,7 @@ int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const · 38 unmodified lines
404 for (iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx) {411 for (iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx) {
405 PPicBuff* ppPic = &pCtx->pPicBuff[iListIdx];412 PPicBuff* ppPic = &pCtx->pPicBuff[iListIdx];
406 if (NULL != ppPic && NULL != *ppPic) {413 if (NULL != ppPic && NULL != *ppPic) {
407 DestroyPicBuff (ppPic);414 DestroyPicBuff (ppPic, pMa);
408 }415 }
409 }416 }
410 417
@@ -425,7 +432,7 @@ int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const · 14 unmodified lines
425 pCtx->pDec = NULL; // need prefetch a new pic due to spatial size changed432 pCtx->pDec = NULL; // need prefetch a new pic due to spatial size changed
426 433
427 if (pCtx->pCabacDecEngine == NULL)434 if (pCtx->pCabacDecEngine == NULL)
428 pCtx->pCabacDecEngine = (SWelsCabacDecEngine*) WelsMallocz (sizeof (SWelsCabacDecEngine), "pCtx->pCabacDecEngine");435 pCtx->pCabacDecEngine = (SWelsCabacDecEngine*) pMa->WelsMallocz (sizeof (SWelsCabacDecEngine), "pCtx->pCabacDecEngine");
429 WELS_VERIFY_RETURN_IF (ERR_INFO_OUT_OF_MEMORY, (NULL == pCtx->pCabacDecEngine))436 WELS_VERIFY_RETURN_IF (ERR_INFO_OUT_OF_MEMORY, (NULL == pCtx->pCabacDecEngine))
430 return ERR_NONE;437 return ERR_NONE;
431}438}
@@ -435,6 +442,7 @@ int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const · 3 unmodified lines
435 */442 */
436void WelsFreeMem (PWelsDecoderContext pCtx) {443void WelsFreeMem (PWelsDecoderContext pCtx) {
437 int32_t iListIdx = 0;444 int32_t iListIdx = 0;
445 CMemoryAlign* pMa = pCtx->pMemAlign;
438 446
439 /* TODO: free memory blocks introduced in avc */447 /* TODO: free memory blocks introduced in avc */
440 ResetFmoList (pCtx);448 ResetFmoList (pCtx);
@@ -445,7 +453,7 @@ void WelsFreeMem (PWelsDecoderContext pCtx) { · 4 unmodified lines
445 for (iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx) {453 for (iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx) {
446 PPicBuff* pPicBuff = &pCtx->pPicBuff[iListIdx];454 PPicBuff* pPicBuff = &pCtx->pPicBuff[iListIdx];
447 if (NULL != pPicBuff && NULL != *pPicBuff) {455 if (NULL != pPicBuff && NULL != *pPicBuff) {
448 DestroyPicBuff (pPicBuff);456 DestroyPicBuff (pPicBuff, pMa);
449 }457 }
450 }458 }
451 459
@@ -456,7 +464,7 @@ void WelsFreeMem (PWelsDecoderContext pCtx) { · 4 unmodified lines
456 pCtx->iLastImgHeightInPixel = 0;464 pCtx->iLastImgHeightInPixel = 0;
457 pCtx->bFreezeOutput = true;465 pCtx->bFreezeOutput = true;
458 pCtx->bHaveGotMemory = false;466 pCtx->bHaveGotMemory = false;
459 WelsFree (pCtx->pCabacDecEngine, "pCtx->pCabacDecEngine");467 pMa->WelsFree (pCtx->pCabacDecEngine, "pCtx->pCabacDecEngine");
460}468}
461 469
462/*!470/*!
@@ -517,7 +525,9 @@ int32_t DecoderConfigParam (PWelsDecoderContext pCtx, const SDecodingParam* kpPa · 54 unmodified lines
517 if (NULL == pCtx || NULL == kpParam)525 if (NULL == pCtx || NULL == kpParam)
518 return 1;526 return 1;
519 527
520 pCtx->pParam = (SDecodingParam*)WelsMallocz (sizeof (SDecodingParam), "SDecodingParam");528 CMemoryAlign* pMa = pCtx->pMemAlign;
529
530 pCtx->pParam = (SDecodingParam*)pMa->WelsMallocz (sizeof (SDecodingParam), "SDecodingParam");
521 531
522 if (NULL == pCtx->pParam)532 if (NULL == pCtx->pParam)
523 return 1;533 return 1;
@@ -565,7 +575,7 @@ int32_t WelsInitDecoder (PWelsDecoderContext pCtx, const bool bParseOnly, SLogCo · 41 unmodified lines
565 }575 }
566 576
567 // default577 // default
568 WelsDecoderDefaults (pCtx, pLogCtx);578 WelsDecoderDefaults (pCtx, pLogCtx, pCtx->pMemAlign);
569 579
570 pCtx->bParseOnly = bParseOnly;580 pCtx->bParseOnly = bParseOnly;
571 // open decoder581 // open decoder
@@ -834,7 +844,10 @@ int32_t SyncPictureResolutionExt (PWelsDecoderContext pCtx, const int32_t kiMbWi · 262 unmodified lines
834 "SyncPictureResolutionExt()::InitialDqLayersContext--buffer allocated failure.");844 "SyncPictureResolutionExt()::InitialDqLayersContext--buffer allocated failure.");
835 pCtx->iErrorCode = dsOutOfMemory;845 pCtx->iErrorCode = dsOutOfMemory;
836 }846 }
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
838 return iErr;851 return iErr;
839}852}
840 853

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