| 646 | } |
| 647 | |
| 648 | int32_t ExpandBsBuffer (PWelsDecoderContext pCtx, const int kiSrcLen) { |
| 649 | if (pCtx == NULL) |
| 650 | return ERR_INFO_INVALID_PTR; |
| 651 | int32_t iExpandStepShift = 1; |
| 652 | int32_t iNewBuffLen = WELS_MAX ((kiSrcLen * MAX_BUFFERED_NUM), (pCtx->iMaxBsBufferSizeInByte << iExpandStepShift)); |
| 653 | //allocate new bs buffer |
| 654 | CMemoryAlign* pMa = pCtx->pMemAlign; |
| 655 | |
| 656 | //Realloc sRawData |
| 657 | uint8_t* pNewBsBuff = static_cast<uint8_t*> (pMa->WelsMallocz (iNewBuffLen, "pCtx->sRawData.pHead")); |
| 658 | if (pNewBsBuff == NULL) { |
| 659 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "ExpandBsBuffer() Failed for malloc pNewBsBuff (%d)", iNewBuffLen); |
| 660 | pCtx->iErrorCode |= dsOutOfMemory; |
| 661 | return ERR_INFO_OUT_OF_MEMORY; |
| 662 | } |
| 663 | |
| 664 | //Calculate and set the bs start and end position |
| 665 | for (uint32_t i = 0; i <= pCtx->pAccessUnitList->uiActualUnitsNum; i++) { |
| 666 | PBitStringAux pSliceBitsRead = &pCtx->pAccessUnitList->pNalUnitsList[i]->sNalData.sVclNal.sSliceBitsRead; |
| 667 | pSliceBitsRead->pStartBuf = pSliceBitsRead->pStartBuf - pCtx->sRawData.pHead + pNewBsBuff; |
| 668 | pSliceBitsRead->pEndBuf = pSliceBitsRead->pEndBuf - pCtx->sRawData.pHead + pNewBsBuff; |
| 669 | pSliceBitsRead->pCurBuf = pSliceBitsRead->pCurBuf - pCtx->sRawData.pHead + pNewBsBuff; |
| 670 | } |
| 671 | |
| 672 | //Copy current buffer status to new buffer |
| 673 | memcpy (pNewBsBuff, pCtx->sRawData.pHead, pCtx->iMaxBsBufferSizeInByte); |
| 674 | pCtx->sRawData.pStartPos = pNewBsBuff + (pCtx->sRawData.pStartPos - pCtx->sRawData.pHead); |
| 675 | pCtx->sRawData.pCurPos = pNewBsBuff + (pCtx->sRawData.pCurPos - pCtx->sRawData.pHead); |
| 676 | pCtx->sRawData.pEnd = pNewBsBuff + iNewBuffLen; |
| 677 | pMa->WelsFree (pCtx->sRawData.pHead, "pCtx->sRawData.pHead"); |
| 678 | pCtx->sRawData.pHead = pNewBsBuff; |
| 679 | |
| 680 | if (pCtx->pParam->bParseOnly) { |
| 681 | //Realloc sSavedData |
| 682 | uint8_t* pNewSavedBsBuff = static_cast<uint8_t*> (pMa->WelsMallocz (iNewBuffLen, "pCtx->sSavedData.pHead")); |
| 683 | if (pNewSavedBsBuff == NULL) { |
| 684 | WelsLog (& (pCtx->sLogCtx), WELS_LOG_ERROR, "ExpandBsBuffer() Failed for malloc pNewSavedBsBuff (%d)", iNewBuffLen); |
| 685 | pCtx->iErrorCode |= dsOutOfMemory; |
| 686 | return ERR_INFO_OUT_OF_MEMORY; |
| 687 | } |
| 688 | |
| 689 | //Copy current buffer status to new buffer |
| 690 | memcpy (pNewSavedBsBuff, pCtx->sSavedData.pHead, pCtx->iMaxBsBufferSizeInByte); |
| 691 | pCtx->sSavedData.pStartPos = pNewSavedBsBuff + (pCtx->sSavedData.pStartPos - pCtx->sSavedData.pHead); |
| 692 | pCtx->sSavedData.pCurPos = pNewSavedBsBuff + (pCtx->sSavedData.pCurPos - pCtx->sSavedData.pHead); |
| 693 | pCtx->sSavedData.pEnd = pNewSavedBsBuff + iNewBuffLen; |
| 694 | pMa->WelsFree (pCtx->sSavedData.pHead, "pCtx->sSavedData.pHead"); |
| 695 | pCtx->sSavedData.pHead = pNewSavedBsBuff; |
| 696 | } |
| 697 | |
| 698 | pCtx->iMaxBsBufferSizeInByte = iNewBuffLen; |
| 699 | return ERR_NONE; |
| 700 | } |
| 701 | |
| 702 | int32_t ExpandBsLenBuffer (PWelsDecoderContext pCtx, const int kiCurrLen) { |
| 703 | SParserBsInfo* pParser = pCtx->pParserBsInfo; |
no test coverage detected