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 | 40 | #include "bit_stream.h" |
| 41 | +#include "error_code.h" | |
| 41 | 42 | |
| 42 | 43 | namespace WelsDec { |
| 43 | 44 | |
| @@ -47,10 +48,14 @@ inline uint32_t GetValue4Bytes (uint8_t* pDstNal) { · 3 unmodified lines | ||
| 47 | 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 | 55 | pBitString->uiCurBits = GetValue4Bytes (pBitString->pCurBuf); |
| 52 | 56 | pBitString->pCurBuf += 4; |
| 53 | 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 | 65 | * \param kpBuf bit-stream buffer |
| 61 | 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 | 70 | int32_t InitBits (PBitStringAux pBitString, const uint8_t* kpBuf, const int32_t kiSize) { |
| 66 | 71 | const int32_t kiSizeBuf = (kiSize + 7) >> 3; |
| 67 | 72 | uint8_t* pTmp = (uint8_t*)kpBuf; |
| 68 | 73 | |
| 69 | 74 | if (NULL == pTmp) |
| 70 | − return -1; | |
| 75 | + return ERR_INFO_INVALID_ACCESS; | |
| 71 | 76 | |
| 72 | 77 | pBitString->pStartBuf = pTmp; // buffer to start position |
| 73 | 78 | pBitString->pEndBuf = pTmp + kiSizeBuf; // buffer + length |
| 74 | 79 | pBitString->iBits = kiSize; // count bits of overall bitstreaming inputindex; |
| 75 | − | |
| 76 | 80 | pBitString->pCurBuf = pBitString->pStartBuf; |
| 77 | − InitReadBits (pBitString); | |
| 78 | − | |
| 79 | − return kiSizeBuf; | |
| 81 | + int32_t iErr = InitReadBits (pBitString, 0); | |
| 82 | + if(iErr) { | |
| 83 | + return iErr; | |
| 84 | + } | |
| 85 | + return ERR_NONE; | |
| 80 | 86 | } |
| 81 | 87 | |
| 82 | 88 | } // namespace WelsDec |