Showing the changes to codec/decoder/core/src/decoder.cpp (1 of 5 files). Show all
Unified · Split
| @@ -76,20 +76,26 @@ static int32_t CreatePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, cons · 75 unmodified lines | |||
| 76 | pPicBuf->ppPic = (PPicture*)WelsMalloc (kiSize * sizeof (PPicture), "PPicture*"); | 76 | pPicBuf->ppPic = (PPicture*)WelsMalloc (kiSize * sizeof (PPicture), "PPicture*"); |
| 77 | 77 | ||
| 78 | if (NULL == pPicBuf->ppPic) { | 78 | if (NULL == pPicBuf->ppPic) { |
| 79 | pPicBuf->iCapacity = 0; | ||
| 80 | DestroyPicBuff (&pPicBuf); | ||
| 79 | return 1; | 81 | return 1; |
| 80 | } | 82 | } |
| 83 | |||
| 81 | for (iPicIdx = 0; iPicIdx < kiSize; ++ iPicIdx) { | 84 | for (iPicIdx = 0; iPicIdx < kiSize; ++ iPicIdx) { |
| 82 | PPicture pPic = AllocPicture (pCtx, kiPicWidth, kiPicHeight); | 85 | PPicture pPic = AllocPicture (pCtx, kiPicWidth, kiPicHeight); |
| 83 | if (NULL == pPic) { | 86 | if (NULL == pPic) { |
| 87 | // init capacity first for free memory | ||
| 88 | pPicBuf->iCapacity = iPicIdx; | ||
| 89 | DestroyPicBuff (&pPicBuf); | ||
| 84 | return 1; | 90 | return 1; |
| 85 | } | 91 | } |
| 86 | pPicBuf->ppPic[iPicIdx] = pPic; | 92 | pPicBuf->ppPic[iPicIdx] = pPic; |
| 87 | } | 93 | } |
| 88 | 94 | ||
| 89 | // initialize context in queue | 95 | // initialize context in queue |
| 90 | pPicBuf->iCapacity = kiSize; | 96 | pPicBuf->iCapacity = kiSize; |
| 91 | pPicBuf->iCurrentIdx = 0; | 97 | pPicBuf->iCurrentIdx = 0; |
| 92 | *ppPicBuf = pPicBuf; | 98 | * ppPicBuf = pPicBuf; |
| 93 | 99 | ||
| 94 | return 0; | 100 | return 0; |
| 95 | } | 101 | } |
| @@ -112,33 +118,39 @@ static int32_t IncreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 16 unmodified lines | |||
| 112 | pPicNewBuf->ppPic = (PPicture*)WelsMalloc (kiNewSize * sizeof (PPicture), "PPicture*"); | 118 | pPicNewBuf->ppPic = (PPicture*)WelsMalloc (kiNewSize * sizeof (PPicture), "PPicture*"); |
| 113 | 119 | ||
| 114 | if (NULL == pPicNewBuf->ppPic) { | 120 | if (NULL == pPicNewBuf->ppPic) { |
| 121 | pPicNewBuf->iCapacity = 0; | ||
| 122 | DestroyPicBuff (&pPicNewBuf); | ||
| 115 | return 1; | 123 | return 1; |
| 116 | } | 124 | } |
| 117 | // copy old PicBuf to new PicBuf | ||
| 118 | memcpy (pPicNewBuf->ppPic, pPicOldBuf->ppPic, kiOldSize * sizeof (PPicture)); | ||
| 119 | |||
| 120 | 125 | ||
| 121 | // increase new PicBuf | 126 | // increase new PicBuf |
| 122 | for (iPicIdx = kiOldSize; iPicIdx < kiNewSize; ++ iPicIdx) { | 127 | for (iPicIdx = kiOldSize; iPicIdx < kiNewSize; ++ iPicIdx) { |
| 123 | PPicture pPic = AllocPicture (pCtx, kiPicWidth, kiPicHeight); | 128 | PPicture pPic = AllocPicture (pCtx, kiPicWidth, kiPicHeight); |
| 124 | if (NULL == pPic) { | 129 | if (NULL == pPic) { |
| 130 | // Set maximum capacity as the new malloc memory at the tail | ||
| 131 | pPicNewBuf->iCapacity = iPicIdx; | ||
| 132 | DestroyPicBuff (&pPicNewBuf); | ||
| 125 | return 1; | 133 | return 1; |
| 126 | } | 134 | } |
| 127 | pPicNewBuf->ppPic[iPicIdx] = pPic; | 135 | pPicNewBuf->ppPic[iPicIdx] = pPic; |
| 128 | } | 136 | } |
| 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 | ||
| 130 | pPicNewBuf->iCapacity = kiNewSize; | 142 | pPicNewBuf->iCapacity = kiNewSize; |
| 131 | pPicNewBuf->iCurrentIdx = pPicOldBuf->iCurrentIdx; | 143 | pPicNewBuf->iCurrentIdx = pPicOldBuf->iCurrentIdx; |
| 132 | *ppPicBuf = pPicNewBuf; | 144 | * ppPicBuf = pPicNewBuf; |
| 133 | 145 | ||
| 134 | for(int32_t i = 0; i < pPicNewBuf->iCapacity; i++) { | 146 | for (int32_t i = 0; i < pPicNewBuf->iCapacity; i++) { |
| 135 | pPicNewBuf->ppPic[i]->bUsedAsRef = false; | 147 | pPicNewBuf->ppPic[i]->bUsedAsRef = false; |
| 136 | pPicNewBuf->ppPic[i]->bIsLongRef = false; | 148 | pPicNewBuf->ppPic[i]->bIsLongRef = false; |
| 137 | pPicNewBuf->ppPic[i]->uiRefCount = 0; | 149 | pPicNewBuf->ppPic[i]->uiRefCount = 0; |
| 138 | pPicNewBuf->ppPic[i]->bAvailableFlag = true; | 150 | pPicNewBuf->ppPic[i]->bAvailableFlag = true; |
| 139 | pPicNewBuf->ppPic[i]->bIsComplete = false; | 151 | pPicNewBuf->ppPic[i]->bIsComplete = false; |
| 140 | } | 152 | } |
| 141 | // remove old PicBuf | 153 | // remove old PicBuf |
| 142 | if (pPicOldBuf->ppPic != NULL) { | 154 | if (pPicOldBuf->ppPic != NULL) { |
| 143 | WelsFree (pPicOldBuf->ppPic, "pPicOldBuf->queue"); | 155 | WelsFree (pPicOldBuf->ppPic, "pPicOldBuf->queue"); |
| 144 | pPicOldBuf->ppPic = NULL; | 156 | pPicOldBuf->ppPic = NULL; |
| @@ -168,6 +180,8 @@ static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 23 unmodified lines | |||
| 168 | pPicNewBuf->ppPic = (PPicture*)WelsMalloc (kiNewSize * sizeof (PPicture), "PPicture*"); | 180 | pPicNewBuf->ppPic = (PPicture*)WelsMalloc (kiNewSize * sizeof (PPicture), "PPicture*"); |
| 169 | 181 | ||
| 170 | if (NULL == pPicNewBuf->ppPic) { | 182 | if (NULL == pPicNewBuf->ppPic) { |
| 183 | pPicNewBuf->iCapacity = 0; | ||
| 184 | DestroyPicBuff (&pPicNewBuf); | ||
| 171 | return 1; | 185 | return 1; |
| 172 | } | 186 | } |
| 173 | 187 | ||
| @@ -203,7 +217,7 @@ static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 29 unmodified lines | |||
| 203 | pPicNewBuf->iCapacity = kiNewSize; | 217 | pPicNewBuf->iCapacity = kiNewSize; |
| 204 | *ppPicBuf = pPicNewBuf; | 218 | *ppPicBuf = pPicNewBuf; |
| 205 | 219 | ||
| 206 | for(int32_t i = 0; i < pPicNewBuf->iCapacity; i++) { | 220 | for (int32_t i = 0; i < pPicNewBuf->iCapacity; i++) { |
| 207 | pPicNewBuf->ppPic[i]->bUsedAsRef = false; | 221 | pPicNewBuf->ppPic[i]->bUsedAsRef = false; |
| 208 | pPicNewBuf->ppPic[i]->bIsLongRef = false; | 222 | pPicNewBuf->ppPic[i]->bIsLongRef = false; |
| 209 | pPicNewBuf->ppPic[i]->uiRefCount = 0; | 223 | pPicNewBuf->ppPic[i]->uiRefCount = 0; |
| @@ -223,7 +237,7 @@ static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 13 unmodified lines | |||
| 223 | return 0; | 237 | return 0; |
| 224 | } | 238 | } |
| 225 | 239 | ||
| 226 | static void DestroyPicBuff (PPicBuff* ppPicBuf) { | 240 | void DestroyPicBuff (PPicBuff* ppPicBuf) { |
| 227 | PPicBuff pPicBuf = NULL; | 241 | PPicBuff pPicBuf = NULL; |
| 228 | 242 | ||
| 229 | if (NULL == ppPicBuf || NULL == *ppPicBuf) | 243 | if (NULL == ppPicBuf || NULL == *ppPicBuf) |