Showing the changes to codec/decoder/core/src/decoder.cpp (1 of 1 file). Show all
Unified · Split
| @@ -94,6 +94,119 @@ static int32_t CreatePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, cons · 93 unmodified lines | ||
| 94 | 94 | return 0; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | +static int32_t IncreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, const int32_t kiOldSize, | |
| 98 | + const int32_t kiPicWidth, const int32_t kiPicHeight, const int32_t kiNewSize) { | |
| 99 | + PPicBuff pPicOldBuf = *ppPicBuf; | |
| 100 | + PPicBuff pPicNewBuf = NULL; | |
| 101 | + int32_t iPicIdx = 0; | |
| 102 | + if (kiOldSize<=0 || kiNewSize <= 0 || kiPicWidth <= 0 || kiPicHeight <= 0) { | |
| 103 | + return 1; | |
| 104 | + } | |
| 105 | + | |
| 106 | + pPicNewBuf = (PPicBuff)WelsMalloc (sizeof (SPicBuff), "PPicBuff"); | |
| 107 | + | |
| 108 | + if (NULL == pPicNewBuf) { | |
| 109 | + return 1; | |
| 110 | + } | |
| 111 | + | |
| 112 | + pPicNewBuf->ppPic = (PPicture*)WelsMalloc (kiNewSize * sizeof (PPicture), "PPicture*"); | |
| 113 | + | |
| 114 | + if (NULL == pPicNewBuf->ppPic) { | |
| 115 | + return 1; | |
| 116 | + } | |
| 117 | + // copy old PicBuf to new PicBuf | |
| 118 | + memcpy(pPicNewBuf->ppPic, pPicOldBuf->ppPic, kiOldSize * sizeof(PPicture)); | |
| 119 | + // initialize context in queue | |
| 120 | + pPicNewBuf->iCapacity = kiNewSize; | |
| 121 | + pPicNewBuf->iCurrentIdx = pPicOldBuf->iCurrentIdx; | |
| 122 | + *ppPicBuf = pPicNewBuf; | |
| 123 | + | |
| 124 | + // increase new PicBuf | |
| 125 | + for (iPicIdx = kiOldSize; iPicIdx < kiNewSize; ++ iPicIdx) { | |
| 126 | + PPicture pPic = AllocPicture (pCtx, kiPicWidth, kiPicHeight); | |
| 127 | + if (NULL == pPic) { | |
| 128 | + return 1; | |
| 129 | + } | |
| 130 | + pPicNewBuf->ppPic[iPicIdx] = pPic; | |
| 131 | + } | |
| 132 | + | |
| 133 | + // remove old PicBuf | |
| 134 | + if (pPicOldBuf->ppPic != NULL) { | |
| 135 | + WelsFree (pPicOldBuf->ppPic, "pPicOldBuf->queue"); | |
| 136 | + pPicOldBuf->ppPic = NULL; | |
| 137 | + } | |
| 138 | + pPicOldBuf->iCapacity = 0; | |
| 139 | + pPicOldBuf->iCurrentIdx = 0; | |
| 140 | + WelsFree (pPicOldBuf, "pPicOldBuf"); | |
| 141 | + | |
| 142 | + return 0; | |
| 143 | +} | |
| 144 | + | |
| 145 | +static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, const int32_t kiOldSize, | |
| 146 | + const int32_t kiPicWidth, const int32_t kiPicHeight, const int32_t kiNewSize) { | |
| 147 | + PPicBuff pPicOldBuf = *ppPicBuf; | |
| 148 | + PPicBuff pPicNewBuf = NULL; | |
| 149 | + int32_t iPicIdx = 0; | |
| 150 | + if (kiOldSize<=0 || kiNewSize <= 0 || kiPicWidth <= 0 || kiPicHeight <= 0) { | |
| 151 | + return 1; | |
| 152 | + } | |
| 153 | + | |
| 154 | + pPicNewBuf = (PPicBuff)WelsMalloc (sizeof (SPicBuff), "PPicBuff"); | |
| 155 | + | |
| 156 | + if (NULL == pPicNewBuf) { | |
| 157 | + return 1; | |
| 158 | + } | |
| 159 | + | |
| 160 | + pPicNewBuf->ppPic = (PPicture*)WelsMalloc (kiNewSize * sizeof (PPicture), "PPicture*"); | |
| 161 | + | |
| 162 | + if (NULL == pPicNewBuf->ppPic) { | |
| 163 | + return 1; | |
| 164 | + } | |
| 165 | + | |
| 166 | + int32_t iPrevPicIdx = -1; | |
| 167 | + for (iPrevPicIdx = 0; iPrevPicIdx < kiOldSize; ++iPrevPicIdx) { | |
| 168 | + if(pCtx->pPreviousDecodedPictureInDpb == pPicOldBuf->ppPic[iPrevPicIdx]) { | |
| 169 | + break; | |
| 170 | + } | |
| 171 | + } | |
| 172 | + int32_t iDelIdx; | |
| 173 | + if(iPrevPicIdx < kiOldSize && iPrevPicIdx >= kiNewSize) { | |
| 174 | + // found pPreviousDecodedPictureInDpb, | |
| 175 | + pPicNewBuf->ppPic[0] = pPicOldBuf->ppPic[iPrevPicIdx]; | |
| 176 | + pPicNewBuf->iCurrentIdx = 0; | |
| 177 | + memcpy(pPicNewBuf->ppPic + 1, pPicOldBuf->ppPic, (kiNewSize - 1) * sizeof(PPicture)); | |
| 178 | + iDelIdx = kiNewSize - 1; | |
| 179 | + } else { | |
| 180 | + memcpy(pPicNewBuf->ppPic, pPicOldBuf->ppPic, kiNewSize * sizeof(PPicture)); | |
| 181 | + pPicNewBuf->iCurrentIdx = iPrevPicIdx < kiNewSize? iPrevPicIdx : 0; | |
| 182 | + iDelIdx = kiNewSize; | |
| 183 | + } | |
| 184 | + | |
| 185 | + for(iPicIdx = iDelIdx; iPicIdx < kiOldSize; iPicIdx++) { | |
| 186 | + if(iPrevPicIdx != iPicIdx) { | |
| 187 | + if (pPicOldBuf->ppPic[iPicIdx] != NULL) { | |
| 188 | + FreePicture (pPicOldBuf->ppPic[iPicIdx]); | |
| 189 | + pPicOldBuf->ppPic[iPicIdx] = NULL; | |
| 190 | + } | |
| 191 | + } | |
| 192 | + } | |
| 193 | + | |
| 194 | + // initialize context in queue | |
| 195 | + pPicNewBuf->iCapacity = kiNewSize; | |
| 196 | + *ppPicBuf = pPicNewBuf; | |
| 197 | + | |
| 198 | + // remove old PicBuf | |
| 199 | + if (pPicOldBuf->ppPic != NULL) { | |
| 200 | + WelsFree (pPicOldBuf->ppPic, "pPicOldBuf->queue"); | |
| 201 | + pPicOldBuf->ppPic = NULL; | |
| 202 | + } | |
| 203 | + pPicOldBuf->iCapacity = 0; | |
| 204 | + pPicOldBuf->iCurrentIdx = 0; | |
| 205 | + WelsFree (pPicOldBuf, "pPicOldBuf"); | |
| 206 | + | |
| 207 | + return 0; | |
| 208 | +} | |
| 209 | + | |
| 97 | 210 | static void DestroyPicBuff (PPicBuff* ppPicBuf) { |
| 98 | 211 | PPicBuff pPicBuf = NULL; |
| 99 | 212 | |
| @@ -225,18 +338,29 @@ int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const · 125 unmodified lines | ||
| 225 | 338 | // sync update pRefList |
| 226 | 339 | WelsResetRefPic (pCtx); // added to sync update ref list due to pictures are free |
| 227 | 340 | |
| 228 | − // for Recycled_Pic_Queue | |
| 229 | − for (iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx) { | |
| 230 | − PPicBuff* ppPic = &pCtx->pPicBuff[iListIdx]; | |
| 231 | − if (NULL != ppPic && NULL != *ppPic) { | |
| 232 | − DestroyPicBuff (ppPic); | |
| 341 | + if(pCtx->bHaveGotMemory && (kiPicWidth == pCtx->iImgWidthInPixel && kiPicHeight == pCtx->iImgHeightInPixel) | |
| 342 | + && pCtx->pPicBuff[LIST_0] != NULL && pCtx->pPicBuff[LIST_0]->iCapacity != iPicQueueSize) { | |
| 343 | + // currently only active for LIST_0 due to have no B frames | |
| 344 | + if (pCtx->pPicBuff[LIST_0]->iCapacity < iPicQueueSize) { | |
| 345 | + iErr = IncreasePicBuff (pCtx, &pCtx->pPicBuff[LIST_0], pCtx->pPicBuff[LIST_0]->iCapacity, kiPicWidth, kiPicHeight, iPicQueueSize); | |
| 346 | + } else { | |
| 347 | + iErr = DecreasePicBuff (pCtx, &pCtx->pPicBuff[LIST_0], pCtx->pPicBuff[LIST_0]->iCapacity, kiPicWidth, kiPicHeight, iPicQueueSize); | |
| 233 | 348 | } |
| 234 | − } | |
| 349 | + } else { | |
| 350 | + // for Recycled_Pic_Queue | |
| 351 | + for (iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx) { | |
| 352 | + PPicBuff* ppPic = &pCtx->pPicBuff[iListIdx]; | |
| 353 | + if (NULL != ppPic && NULL != *ppPic) { | |
| 354 | + DestroyPicBuff (ppPic); | |
| 355 | + } | |
| 356 | + } | |
| 235 | 357 | |
| 236 | − pCtx->pPreviousDecodedPictureInDpb = NULL; | |
| 358 | + pCtx->pPreviousDecodedPictureInDpb = NULL; | |
| 359 | + | |
| 360 | + // currently only active for LIST_0 due to have no B frames | |
| 361 | + iErr = CreatePicBuff (pCtx, &pCtx->pPicBuff[LIST_0], iPicQueueSize, kiPicWidth, kiPicHeight); | |
| 362 | + } | |
| 237 | 363 | |
| 238 | − // currently only active for LIST_0 due to have no B frames | |
| 239 | − iErr = CreatePicBuff (pCtx, &pCtx->pPicBuff[LIST_0], iPicQueueSize, kiPicWidth, kiPicHeight); | |
| 240 | 364 | if (iErr != ERR_NONE) |
| 241 | 365 | return iErr; |
| 242 | 366 | |