! ************************************************************************************* * \brief First entrance to decoding core interface. * * \param pCtx decoder context * \param pBufBs bit streaming buffer * \param kBsLen size in bytes length of bit streaming buffer input * \param ppDst picture payload data to be output * \param pDstBuf
| 738 | ************************************************************************************* |
| 739 | */ |
| 740 | int32_t WelsDecodeBs (PWelsDecoderContext pCtx, const uint8_t* kpBsBuf, const int32_t kiBsLen, |
| 741 | uint8_t** ppDst, SBufferInfo* pDstBufInfo, SParserBsInfo* pDstBsInfo) { |
| 742 | if (!pCtx->bEndOfStreamFlag) { |
| 743 | SDataBuffer* pRawData = &pCtx->sRawData; |
| 744 | SDataBuffer* pSavedData = NULL; |
| 745 | |
| 746 | int32_t iSrcIdx = 0; //the index of source bit-stream till now after parsing one or more NALs |
| 747 | int32_t iSrcConsumed = 0; // consumed bit count of source bs |
| 748 | int32_t iDstIdx = 0; //the size of current NAL after 0x03 removal and 00 00 01 removal |
| 749 | int32_t iSrcLength = 0; //the total size of current AU or NAL |
| 750 | int32_t iRet = 0; |
| 751 | int32_t iConsumedBytes = 0; |
| 752 | int32_t iOffset = 0; |
| 753 | |
| 754 | uint8_t* pSrcNal = NULL; |
| 755 | uint8_t* pDstNal = NULL; |
| 756 | uint8_t* pNalPayload = NULL; |
| 757 | |
| 758 | |
| 759 | if (NULL == DetectStartCodePrefix (kpBsBuf, &iOffset, |
| 760 | kiBsLen)) { //CAN'T find the 00 00 01 start prefix from the source buffer |
| 761 | pCtx->iErrorCode |= dsBitstreamError; |
| 762 | return dsBitstreamError; |
| 763 | } |
| 764 | |
| 765 | pSrcNal = const_cast<uint8_t*> (kpBsBuf) + iOffset; |
| 766 | iSrcLength = kiBsLen - iOffset; |
| 767 | |
| 768 | if ((kiBsLen + 4) > (pRawData->pEnd - pRawData->pCurPos)) { |
| 769 | pRawData->pCurPos = pRawData->pHead; |
| 770 | } |
| 771 | |
| 772 | if (pCtx->pParam->bParseOnly) { |
| 773 | pSavedData = &pCtx->sSavedData; |
| 774 | if ((kiBsLen + 4) > (pSavedData->pEnd - pSavedData->pCurPos)) { |
| 775 | pSavedData->pCurPos = pSavedData->pHead; |
| 776 | } |
| 777 | } |
| 778 | //copy raw data from source buffer (application) to raw data buffer (codec inside) |
| 779 | //0x03 removal and extract all of NAL Unit from current raw data |
| 780 | pDstNal = pRawData->pCurPos; |
| 781 | |
| 782 | bool bNalStartBytes = false; |
| 783 | |
| 784 | while (iSrcConsumed < iSrcLength) { |
| 785 | if ((2 + iSrcConsumed < iSrcLength) && (0 == LD16 (pSrcNal + iSrcIdx)) && (pSrcNal[2 + iSrcIdx] <= 0x03)) { |
| 786 | if (bNalStartBytes && (pSrcNal[2 + iSrcIdx] != 0x00 && pSrcNal[2 + iSrcIdx] != 0x01)) { |
| 787 | pCtx->iErrorCode |= dsBitstreamError; |
| 788 | return pCtx->iErrorCode; |
| 789 | } |
| 790 | |
| 791 | if (pSrcNal[2 + iSrcIdx] == 0x02) { |
| 792 | pCtx->iErrorCode |= dsBitstreamError; |
| 793 | return pCtx->iErrorCode; |
| 794 | } else if (pSrcNal[2 + iSrcIdx] == 0x00) { |
| 795 | pDstNal[iDstIdx++] = pSrcNal[iSrcIdx++]; |
| 796 | iSrcConsumed++; |
| 797 | bNalStartBytes = true; |
no test coverage detected