History

(1) Reset parameter set status and clear AU list when out of memory (2) Free un-complete malloc memory, keep the original state, special when increase memory

Haibo Zhu committed 11 years ago

Commit 57043d11 parent 091e5cb5 files · +59 −17Browse files

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

Unified · Split

codec/decoder/core/src/decoder.cpp+26−12
@@ -76,20 +76,26 @@ static int32_t CreatePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, cons · 75 unmodified lines
7676 pPicBuf->ppPic = (PPicture*)WelsMalloc (kiSize * sizeof (PPicture), "PPicture*");
7777
7878 if (NULL == pPicBuf->ppPic) {
79+ pPicBuf->iCapacity = 0;
80+ DestroyPicBuff (&pPicBuf);
7981 return 1;
8082 }
83+
8184 for (iPicIdx = 0; iPicIdx < kiSize; ++ iPicIdx) {
8285 PPicture pPic = AllocPicture (pCtx, kiPicWidth, kiPicHeight);
8386 if (NULL == pPic) {
87+ // init capacity first for free memory
88+ pPicBuf->iCapacity = iPicIdx;
89+ DestroyPicBuff (&pPicBuf);
8490 return 1;
8591 }
8692 pPicBuf->ppPic[iPicIdx] = pPic;
8793 }
8894
89− // initialize context in queue
95+// initialize context in queue
9096 pPicBuf->iCapacity = kiSize;
9197 pPicBuf->iCurrentIdx = 0;
92− *ppPicBuf = pPicBuf;
98+ * ppPicBuf = pPicBuf;
9399
94100 return 0;
95101 }
@@ -112,33 +118,39 @@ static int32_t IncreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 16 unmodified lines
112118 pPicNewBuf->ppPic = (PPicture*)WelsMalloc (kiNewSize * sizeof (PPicture), "PPicture*");
113119
114120 if (NULL == pPicNewBuf->ppPic) {
121+ pPicNewBuf->iCapacity = 0;
122+ DestroyPicBuff (&pPicNewBuf);
115123 return 1;
116124 }
117− // copy old PicBuf to new PicBuf
118− memcpy (pPicNewBuf->ppPic, pPicOldBuf->ppPic, kiOldSize * sizeof (PPicture));
119−
120125
121126 // increase new PicBuf
122127 for (iPicIdx = kiOldSize; iPicIdx < kiNewSize; ++ iPicIdx) {
123128 PPicture pPic = AllocPicture (pCtx, kiPicWidth, kiPicHeight);
124129 if (NULL == pPic) {
130+ // Set maximum capacity as the new malloc memory at the tail
131+ pPicNewBuf->iCapacity = iPicIdx;
132+ DestroyPicBuff (&pPicNewBuf);
125133 return 1;
126134 }
127135 pPicNewBuf->ppPic[iPicIdx] = pPic;
128136 }
129− // initialize context in queue
137+
138+ // copy old PicBuf to new PicBuf
139+ memcpy (pPicNewBuf->ppPic, pPicOldBuf->ppPic, kiOldSize * sizeof (PPicture));
140+
141+// initialize context in queue
130142 pPicNewBuf->iCapacity = kiNewSize;
131143 pPicNewBuf->iCurrentIdx = pPicOldBuf->iCurrentIdx;
132− *ppPicBuf = pPicNewBuf;
133−
134− for(int32_t i = 0; i < pPicNewBuf->iCapacity; i++) {
144+ * ppPicBuf = pPicNewBuf;
145+
146+ for (int32_t i = 0; i < pPicNewBuf->iCapacity; i++) {
135147 pPicNewBuf->ppPic[i]->bUsedAsRef = false;
136148 pPicNewBuf->ppPic[i]->bIsLongRef = false;
137149 pPicNewBuf->ppPic[i]->uiRefCount = 0;
138150 pPicNewBuf->ppPic[i]->bAvailableFlag = true;
139151 pPicNewBuf->ppPic[i]->bIsComplete = false;
140152 }
141− // remove old PicBuf
153+// remove old PicBuf
142154 if (pPicOldBuf->ppPic != NULL) {
143155 WelsFree (pPicOldBuf->ppPic, "pPicOldBuf->queue");
144156 pPicOldBuf->ppPic = NULL;
@@ -168,6 +180,8 @@ static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 23 unmodified lines
168180 pPicNewBuf->ppPic = (PPicture*)WelsMalloc (kiNewSize * sizeof (PPicture), "PPicture*");
169181
170182 if (NULL == pPicNewBuf->ppPic) {
183+ pPicNewBuf->iCapacity = 0;
184+ DestroyPicBuff (&pPicNewBuf);
171185 return 1;
172186 }
173187
@@ -203,7 +217,7 @@ static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 29 unmodified lines
203217 pPicNewBuf->iCapacity = kiNewSize;
204218 *ppPicBuf = pPicNewBuf;
205219
206− for(int32_t i = 0; i < pPicNewBuf->iCapacity; i++) {
220+ for (int32_t i = 0; i < pPicNewBuf->iCapacity; i++) {
207221 pPicNewBuf->ppPic[i]->bUsedAsRef = false;
208222 pPicNewBuf->ppPic[i]->bIsLongRef = false;
209223 pPicNewBuf->ppPic[i]->uiRefCount = 0;
@@ -223,7 +237,7 @@ static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 13 unmodified lines
223237 return 0;
224238 }
225239
226−static void DestroyPicBuff (PPicBuff* ppPicBuf) {
240+void DestroyPicBuff (PPicBuff* ppPicBuf) {
227241 PPicBuff pPicBuf = NULL;
228242
229243 if (NULL == ppPicBuf || NULL == *ppPicBuf)

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