| 168 | } |
| 169 | |
| 170 | static int32_t DecreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, const int32_t kiOldSize, |
| 171 | const int32_t kiPicWidth, const int32_t kiPicHeight, const int32_t kiNewSize) { |
| 172 | PPicBuff pPicOldBuf = *ppPicBuf; |
| 173 | PPicBuff pPicNewBuf = NULL; |
| 174 | int32_t iPicIdx = 0; |
| 175 | if (kiOldSize <= 0 || kiNewSize <= 0 || kiPicWidth <= 0 || kiPicHeight <= 0) { |
| 176 | return ERR_INFO_INVALID_PARAM; |
| 177 | } |
| 178 | |
| 179 | CMemoryAlign* pMa = pCtx->pMemAlign; |
| 180 | |
| 181 | pPicNewBuf = (PPicBuff)pMa->WelsMallocz (sizeof (SPicBuff), "PPicBuff"); |
| 182 | |
| 183 | if (NULL == pPicNewBuf) { |
| 184 | return ERR_INFO_OUT_OF_MEMORY; |
| 185 | } |
| 186 | |
| 187 | pPicNewBuf->ppPic = (PPicture*)pMa->WelsMallocz (kiNewSize * sizeof (PPicture), "PPicture*"); |
| 188 | |
| 189 | if (NULL == pPicNewBuf->ppPic) { |
| 190 | pPicNewBuf->iCapacity = 0; |
| 191 | DestroyPicBuff (pCtx, &pPicNewBuf, pMa); |
| 192 | return ERR_INFO_OUT_OF_MEMORY; |
| 193 | } |
| 194 | |
| 195 | ResetReorderingPictureBuffers (pCtx->pPictReoderingStatus, pCtx->pPictInfoList, false); |
| 196 | |
| 197 | int32_t iPrevPicIdx = -1; |
| 198 | for (iPrevPicIdx = 0; iPrevPicIdx < kiOldSize; ++iPrevPicIdx) { |
| 199 | if (pCtx->pLastDecPicInfo->pPreviousDecodedPictureInDpb == pPicOldBuf->ppPic[iPrevPicIdx]) { |
| 200 | break; |
| 201 | } |
| 202 | } |
| 203 | int32_t iDelIdx; |
| 204 | if (iPrevPicIdx < kiOldSize && iPrevPicIdx >= kiNewSize) { |
| 205 | // found pPreviousDecodedPictureInDpb, |
| 206 | pPicNewBuf->ppPic[0] = pPicOldBuf->ppPic[iPrevPicIdx]; |
| 207 | pPicNewBuf->iCurrentIdx = 0; |
| 208 | memcpy (pPicNewBuf->ppPic + 1, pPicOldBuf->ppPic, (kiNewSize - 1) * sizeof (PPicture)); |
| 209 | iDelIdx = kiNewSize - 1; |
| 210 | } else { |
| 211 | memcpy (pPicNewBuf->ppPic, pPicOldBuf->ppPic, kiNewSize * sizeof (PPicture)); |
| 212 | pPicNewBuf->iCurrentIdx = iPrevPicIdx < kiNewSize ? iPrevPicIdx : 0; |
| 213 | iDelIdx = kiNewSize; |
| 214 | } |
| 215 | |
| 216 | //update references due to allocation changes |
| 217 | //all references' references have to be reset oss-buzz 14423 |
| 218 | for (int32_t i = 0; i < kiNewSize; i++) { |
| 219 | for (int32_t listIdx = LIST_0; listIdx < LIST_A; ++listIdx) { |
| 220 | int32_t j = -1; |
| 221 | while (++j < MAX_DPB_COUNT && pPicNewBuf->ppPic[i]->pRefPic[listIdx][j] != NULL) { |
| 222 | pPicNewBuf->ppPic[i]->pRefPic[listIdx][j] = NULL; |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | for (iPicIdx = iDelIdx; iPicIdx < kiOldSize; iPicIdx++) { |
no test coverage detected