| 105 | } |
| 106 | |
| 107 | static int32_t IncreasePicBuff (PWelsDecoderContext pCtx, PPicBuff* ppPicBuf, const int32_t kiOldSize, |
| 108 | const int32_t kiPicWidth, const int32_t kiPicHeight, const int32_t kiNewSize) { |
| 109 | PPicBuff pPicOldBuf = *ppPicBuf; |
| 110 | PPicBuff pPicNewBuf = NULL; |
| 111 | int32_t iPicIdx = 0; |
| 112 | if (kiOldSize <= 0 || kiNewSize <= 0 || kiPicWidth <= 0 || kiPicHeight <= 0) { |
| 113 | return ERR_INFO_INVALID_PARAM; |
| 114 | } |
| 115 | |
| 116 | CMemoryAlign* pMa = pCtx->pMemAlign; |
| 117 | pPicNewBuf = (PPicBuff)pMa->WelsMallocz (sizeof (SPicBuff), "PPicBuff"); |
| 118 | |
| 119 | if (NULL == pPicNewBuf) { |
| 120 | return ERR_INFO_OUT_OF_MEMORY; |
| 121 | } |
| 122 | |
| 123 | pPicNewBuf->ppPic = (PPicture*)pMa->WelsMallocz (kiNewSize * sizeof (PPicture), "PPicture*"); |
| 124 | |
| 125 | if (NULL == pPicNewBuf->ppPic) { |
| 126 | pPicNewBuf->iCapacity = 0; |
| 127 | DestroyPicBuff (pCtx, &pPicNewBuf, pMa); |
| 128 | return ERR_INFO_OUT_OF_MEMORY; |
| 129 | } |
| 130 | |
| 131 | // increase new PicBuf |
| 132 | for (iPicIdx = kiOldSize; iPicIdx < kiNewSize; ++ iPicIdx) { |
| 133 | PPicture pPic = AllocPicture (pCtx, kiPicWidth, kiPicHeight); |
| 134 | if (NULL == pPic) { |
| 135 | // Set maximum capacity as the new malloc memory at the tail |
| 136 | pPicNewBuf->iCapacity = iPicIdx; |
| 137 | DestroyPicBuff (pCtx, &pPicNewBuf, pMa); |
| 138 | return ERR_INFO_OUT_OF_MEMORY; |
| 139 | } |
| 140 | pPicNewBuf->ppPic[iPicIdx] = pPic; |
| 141 | } |
| 142 | |
| 143 | // copy old PicBuf to new PicBuf |
| 144 | memcpy (pPicNewBuf->ppPic, pPicOldBuf->ppPic, kiOldSize * sizeof (PPicture)); |
| 145 | |
| 146 | // initialize context in queue |
| 147 | pPicNewBuf->iCapacity = kiNewSize; |
| 148 | pPicNewBuf->iCurrentIdx = pPicOldBuf->iCurrentIdx; |
| 149 | * ppPicBuf = pPicNewBuf; |
| 150 | |
| 151 | for (int32_t i = 0; i < pPicNewBuf->iCapacity; i++) { |
| 152 | pPicNewBuf->ppPic[i]->bUsedAsRef = false; |
| 153 | pPicNewBuf->ppPic[i]->bIsLongRef = false; |
| 154 | pPicNewBuf->ppPic[i]->iRefCount = 0; |
| 155 | pPicNewBuf->ppPic[i]->pSetUnRef = NULL; |
| 156 | pPicNewBuf->ppPic[i]->bIsComplete = false; |
| 157 | } |
| 158 | // remove old PicBuf |
| 159 | if (pPicOldBuf->ppPic != NULL) { |
| 160 | pMa->WelsFree (pPicOldBuf->ppPic, "pPicOldBuf->queue"); |
| 161 | pPicOldBuf->ppPic = NULL; |
| 162 | } |
| 163 | pPicOldBuf->iCapacity = 0; |
| 164 | pPicOldBuf->iCurrentIdx = 0; |
no test coverage detected