Showing the changes to codec/decoder/core/src/bit_stream.cpp (1 of 32 files). Show all
Unified · Split
| @@ -38,6 +38,7 @@ · 37 unmodified lines | |||
| 38 | ************************************************************************************* | 38 | ************************************************************************************* |
| 39 | */ | 39 | */ |
| 40 | #include "bit_stream.h" | 40 | #include "bit_stream.h" |
| 41 | #include "error_code.h" | ||
| 41 | 42 | ||
| 42 | namespace WelsDec { | 43 | namespace WelsDec { |
| 43 | 44 | ||
| @@ -47,10 +48,14 @@ inline uint32_t GetValue4Bytes (uint8_t* pDstNal) { · 3 unmodified lines | |||
| 47 | return uiValue; | 48 | return uiValue; |
| 48 | } | 49 | } |
| 49 | 50 | ||
| 50 | void InitReadBits (PBitStringAux pBitString) { | 51 | int32_t InitReadBits (PBitStringAux pBitString, intX_t iEndOffset) { |
| 52 | if(pBitString->pCurBuf>=(pBitString->pEndBuf - iEndOffset)) { | ||
| 53 | return ERR_INFO_INVALID_ACCESS; | ||
| 54 | } | ||
| 51 | pBitString->uiCurBits = GetValue4Bytes (pBitString->pCurBuf); | 55 | pBitString->uiCurBits = GetValue4Bytes (pBitString->pCurBuf); |
| 52 | pBitString->pCurBuf += 4; | 56 | pBitString->pCurBuf += 4; |
| 53 | pBitString->iLeftBits = -16; | 57 | pBitString->iLeftBits = -16; |
| 58 | return ERR_NONE; | ||
| 54 | } | 59 | } |
| 55 | 60 | ||
| 56 | /*! | 61 | /*! |
| @@ -60,23 +65,24 @@ void InitReadBits (PBitStringAux pBitString) { · 3 unmodified lines | |||
| 60 | * \param kpBuf bit-stream buffer | 65 | * \param kpBuf bit-stream buffer |
| 61 | * \param kiSize size in bits for decoder; size in bytes for encoder | 66 | * \param kiSize size in bits for decoder; size in bytes for encoder |
| 62 | * | 67 | * |
| 63 | * \return size of buffer data in byte; failed in -1 return | 68 | * \return 0: success, other: fail |
| 64 | */ | 69 | */ |
| 65 | int32_t InitBits (PBitStringAux pBitString, const uint8_t* kpBuf, const int32_t kiSize) { | 70 | int32_t InitBits (PBitStringAux pBitString, const uint8_t* kpBuf, const int32_t kiSize) { |
| 66 | const int32_t kiSizeBuf = (kiSize + 7) >> 3; | 71 | const int32_t kiSizeBuf = (kiSize + 7) >> 3; |
| 67 | uint8_t* pTmp = (uint8_t*)kpBuf; | 72 | uint8_t* pTmp = (uint8_t*)kpBuf; |
| 68 | 73 | ||
| 69 | if (NULL == pTmp) | 74 | if (NULL == pTmp) |
| 70 | return -1; | 75 | return ERR_INFO_INVALID_ACCESS; |
| 71 | 76 | ||
| 72 | pBitString->pStartBuf = pTmp; // buffer to start position | 77 | pBitString->pStartBuf = pTmp; // buffer to start position |
| 73 | pBitString->pEndBuf = pTmp + kiSizeBuf; // buffer + length | 78 | pBitString->pEndBuf = pTmp + kiSizeBuf; // buffer + length |
| 74 | pBitString->iBits = kiSize; // count bits of overall bitstreaming inputindex; | 79 | pBitString->iBits = kiSize; // count bits of overall bitstreaming inputindex; |
| 75 | |||
| 76 | pBitString->pCurBuf = pBitString->pStartBuf; | 80 | pBitString->pCurBuf = pBitString->pStartBuf; |
| 77 | InitReadBits (pBitString); | 81 | int32_t iErr = InitReadBits (pBitString, 0); |
| 78 | 82 | if(iErr) { | |
| 79 | return kiSizeBuf; | 83 | return iErr; |
| 84 | } | ||
| 85 | return ERR_NONE; | ||
| 80 | } | 86 | } |
| 81 | 87 | ||
| 82 | } // namespace WelsDec | 88 | } // namespace WelsDec |