Showing the changes to codec/decoder/core/src/decoder.cpp (1 of 1 file). Show all
Unified · Split
| @@ -95,11 +95,11 @@ static int32_t CreatePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, cons · 94 unmodified lines | |||
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | static int32_t IncreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, const int32_t kiOldSize, | 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) { | 98 | const int32_t kiPicWidth, const int32_t kiPicHeight, const int32_t kiNewSize) { |
| 99 | PPicBuff pPicOldBuf = *ppPicBuf; | 99 | PPicBuff pPicOldBuf = *ppPicBuf; |
| 100 | PPicBuff pPicNewBuf = NULL; | 100 | PPicBuff pPicNewBuf = NULL; |
| 101 | int32_t iPicIdx = 0; | 101 | int32_t iPicIdx = 0; |
| 102 | if (kiOldSize<=0 || kiNewSize <= 0 || kiPicWidth <= 0 || kiPicHeight <= 0) { | 102 | if (kiOldSize <= 0 || kiNewSize <= 0 || kiPicWidth <= 0 || kiPicHeight <= 0) { |
| 103 | return 1; | 103 | return 1; |
| 104 | } | 104 | } |
| 105 | 105 | ||
| @@ -115,7 +115,7 @@ static int32_t IncreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 9 unmodified lines | |||
| 115 | return 1; | 115 | return 1; |
| 116 | } | 116 | } |
| 117 | // copy old PicBuf to new PicBuf | 117 | // copy old PicBuf to new PicBuf |
| 118 | memcpy(pPicNewBuf->ppPic, pPicOldBuf->ppPic, kiOldSize * sizeof(PPicture)); | 118 | memcpy (pPicNewBuf->ppPic, pPicOldBuf->ppPic, kiOldSize * sizeof (PPicture)); |
| 119 | // initialize context in queue | 119 | // initialize context in queue |
| 120 | pPicNewBuf->iCapacity = kiNewSize; | 120 | pPicNewBuf->iCapacity = kiNewSize; |
| 121 | pPicNewBuf->iCurrentIdx = pPicOldBuf->iCurrentIdx; | 121 | pPicNewBuf->iCurrentIdx = pPicOldBuf->iCurrentIdx; |
| @@ -143,11 +143,11 @@ static int32_t IncreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 21 unmodified lines | |||
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, const int32_t kiOldSize, | 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) { | 146 | const int32_t kiPicWidth, const int32_t kiPicHeight, const int32_t kiNewSize) { |
| 147 | PPicBuff pPicOldBuf = *ppPicBuf; | 147 | PPicBuff pPicOldBuf = *ppPicBuf; |
| 148 | PPicBuff pPicNewBuf = NULL; | 148 | PPicBuff pPicNewBuf = NULL; |
| 149 | int32_t iPicIdx = 0; | 149 | int32_t iPicIdx = 0; |
| 150 | if (kiOldSize<=0 || kiNewSize <= 0 || kiPicWidth <= 0 || kiPicHeight <= 0) { | 150 | if (kiOldSize <= 0 || kiNewSize <= 0 || kiPicWidth <= 0 || kiPicHeight <= 0) { |
| 151 | return 1; | 151 | return 1; |
| 152 | } | 152 | } |
| 153 | 153 | ||
| @@ -165,29 +165,29 @@ static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, co · 11 unmodified lines | |||
| 165 | 165 | ||
| 166 | int32_t iPrevPicIdx = -1; | 166 | int32_t iPrevPicIdx = -1; |
| 167 | for (iPrevPicIdx = 0; iPrevPicIdx < kiOldSize; ++iPrevPicIdx) { | 167 | for (iPrevPicIdx = 0; iPrevPicIdx < kiOldSize; ++iPrevPicIdx) { |
| 168 | if(pCtx->pPreviousDecodedPictureInDpb == pPicOldBuf->ppPic[iPrevPicIdx]) { | 168 | if (pCtx->pPreviousDecodedPictureInDpb == pPicOldBuf->ppPic[iPrevPicIdx]) { |
| 169 | break; | 169 | break; |
| 170 | } | 170 | } |
| 171 | } | 171 | } |
| 172 | int32_t iDelIdx; | 172 | int32_t iDelIdx; |
| 173 | if(iPrevPicIdx < kiOldSize && iPrevPicIdx >= kiNewSize) { | 173 | if (iPrevPicIdx < kiOldSize && iPrevPicIdx >= kiNewSize) { |
| 174 | // found pPreviousDecodedPictureInDpb, | 174 | // found pPreviousDecodedPictureInDpb, |
| 175 | pPicNewBuf->ppPic[0] = pPicOldBuf->ppPic[iPrevPicIdx]; | 175 | pPicNewBuf->ppPic[0] = pPicOldBuf->ppPic[iPrevPicIdx]; |
| 176 | pPicNewBuf->iCurrentIdx = 0; | 176 | pPicNewBuf->iCurrentIdx = 0; |
| 177 | memcpy(pPicNewBuf->ppPic + 1, pPicOldBuf->ppPic, (kiNewSize - 1) * sizeof(PPicture)); | 177 | memcpy (pPicNewBuf->ppPic + 1, pPicOldBuf->ppPic, (kiNewSize - 1) * sizeof (PPicture)); |
| 178 | iDelIdx = kiNewSize - 1; | 178 | iDelIdx = kiNewSize - 1; |
| 179 | } else { | 179 | } else { |
| 180 | memcpy(pPicNewBuf->ppPic, pPicOldBuf->ppPic, kiNewSize * sizeof(PPicture)); | 180 | memcpy (pPicNewBuf->ppPic, pPicOldBuf->ppPic, kiNewSize * sizeof (PPicture)); |
| 181 | pPicNewBuf->iCurrentIdx = iPrevPicIdx < kiNewSize? iPrevPicIdx : 0; | 181 | pPicNewBuf->iCurrentIdx = iPrevPicIdx < kiNewSize ? iPrevPicIdx : 0; |
| 182 | iDelIdx = kiNewSize; | 182 | iDelIdx = kiNewSize; |
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | for(iPicIdx = iDelIdx; iPicIdx < kiOldSize; iPicIdx++) { | 185 | for (iPicIdx = iDelIdx; iPicIdx < kiOldSize; iPicIdx++) { |
| 186 | if(iPrevPicIdx != iPicIdx) { | 186 | if (iPrevPicIdx != iPicIdx) { |
| 187 | if (pPicOldBuf->ppPic[iPicIdx] != NULL) { | 187 | if (pPicOldBuf->ppPic[iPicIdx] != NULL) { |
| 188 | FreePicture (pPicOldBuf->ppPic[iPicIdx]); | 188 | FreePicture (pPicOldBuf->ppPic[iPicIdx]); |
| 189 | pPicOldBuf->ppPic[iPicIdx] = NULL; | 189 | pPicOldBuf->ppPic[iPicIdx] = NULL; |
| 190 | } | 190 | } |
| 191 | } | 191 | } |
| 192 | } | 192 | } |
| 193 | 193 | ||
| @@ -338,27 +338,40 @@ int32_t WelsRequestMem (PWelsDecoderContext pCtx, const int32_t kiMbWidth, const · 144 unmodified lines | |||
| 338 | // sync update pRefList | 338 | // sync update pRefList |
| 339 | WelsResetRefPic (pCtx); // added to sync update ref list due to pictures are free | 339 | WelsResetRefPic (pCtx); // added to sync update ref list due to pictures are free |
| 340 | 340 | ||
| 341 | if(pCtx->bHaveGotMemory && (kiPicWidth == pCtx->iImgWidthInPixel && kiPicHeight == pCtx->iImgHeightInPixel) | 341 | if (pCtx->bHaveGotMemory && (kiPicWidth == pCtx->iImgWidthInPixel && kiPicHeight == pCtx->iImgHeightInPixel) |
| 342 | && pCtx->pPicBuff[LIST_0] != NULL && pCtx->pPicBuff[LIST_0]->iCapacity != iPicQueueSize) { | 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 | 343 | // currently only active for LIST_0 due to have no B frames |
| 344 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO, | ||
| 345 | "WelsRequestMem(): memory re-alloc for no resolution change (size = %d * %d), ref list size change from %d to %d", | ||
| 346 | kiPicWidth, kiPicHeight, pCtx->pPicBuff[LIST_0]->iCapacity, iPicQueueSize); | ||
| 344 | if (pCtx->pPicBuff[LIST_0]->iCapacity < iPicQueueSize) { | 347 | if (pCtx->pPicBuff[LIST_0]->iCapacity < iPicQueueSize) { |
| 345 | iErr = IncreasePicBuff (pCtx, &pCtx->pPicBuff[LIST_0], pCtx->pPicBuff[LIST_0]->iCapacity, kiPicWidth, kiPicHeight, iPicQueueSize); | 348 | iErr = IncreasePicBuff (pCtx, &pCtx->pPicBuff[LIST_0], pCtx->pPicBuff[LIST_0]->iCapacity, kiPicWidth, kiPicHeight, |
| 349 | iPicQueueSize); | ||
| 346 | } else { | 350 | } else { |
| 347 | iErr = DecreasePicBuff (pCtx, &pCtx->pPicBuff[LIST_0], pCtx->pPicBuff[LIST_0]->iCapacity, kiPicWidth, kiPicHeight, iPicQueueSize); | 351 | iErr = DecreasePicBuff (pCtx, &pCtx->pPicBuff[LIST_0], pCtx->pPicBuff[LIST_0]->iCapacity, kiPicWidth, kiPicHeight, |
| 352 | iPicQueueSize); | ||
| 348 | } | 353 | } |
| 349 | } else { | 354 | } else { |
| 350 | // for Recycled_Pic_Queue | 355 | if (pCtx->bHaveGotMemory) |
| 351 | for (iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx) { | 356 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO, |
| 352 | PPicBuff* ppPic = &pCtx->pPicBuff[iListIdx]; | 357 | "WelsRequestMem(): memory re-alloc for resolution change, size change from %d * %d to %d * %d, ref list size change from %d to %d", |
| 353 | if (NULL != ppPic && NULL != *ppPic) { | 358 | pCtx->iImgWidthInPixel, pCtx->iImgHeightInPixel, kiPicWidth, kiPicHeight, pCtx->pPicBuff[LIST_0]->iCapacity, |
| 354 | DestroyPicBuff (ppPic); | 359 | iPicQueueSize); |
| 355 | } | 360 | else |
| 361 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_INFO, "WelsRequestMem(): memory alloc size = %d * %d, ref list size = %d", | ||
| 362 | kiPicWidth, kiPicHeight, iPicQueueSize); | ||
| 363 | // for Recycled_Pic_Queue | ||
| 364 | for (iListIdx = LIST_0; iListIdx < LIST_A; ++ iListIdx) { | ||
| 365 | PPicBuff* ppPic = &pCtx->pPicBuff[iListIdx]; | ||
| 366 | if (NULL != ppPic && NULL != *ppPic) { | ||
| 367 | DestroyPicBuff (ppPic); | ||
| 356 | } | 368 | } |
| 369 | } | ||
| 357 | 370 | ||
| 358 | pCtx->pPreviousDecodedPictureInDpb = NULL; | 371 | pCtx->pPreviousDecodedPictureInDpb = NULL; |
| 359 | 372 | ||
| 360 | // currently only active for LIST_0 due to have no B frames | 373 | // currently only active for LIST_0 due to have no B frames |
| 361 | iErr = CreatePicBuff (pCtx, &pCtx->pPicBuff[LIST_0], iPicQueueSize, kiPicWidth, kiPicHeight); | 374 | iErr = CreatePicBuff (pCtx, &pCtx->pPicBuff[LIST_0], iPicQueueSize, kiPicWidth, kiPicHeight); |
| 362 | } | 375 | } |
| 363 | 376 | ||
| 364 | if (iErr != ERR_NONE) | 377 | if (iErr != ERR_NONE) |