diff options
author | Martin Storsjo <martin@martin.st> | 2017-04-26 23:37:11 +0300 |
---|---|---|
committer | Martin Storsjo <martin@martin.st> | 2017-04-26 23:37:11 +0300 |
commit | 50922e3dbd5d099a67d879c4ec1d7535ebfa30a8 (patch) | |
tree | 8fd82f6533d5b5c9d4459c8bb896e2c58bba40aa /libFDK | |
parent | 6b0d8201b1ef4be11b028e7c635dfe6a9c919380 (diff) | |
download | fdk-aac-50922e3dbd5d099a67d879c4ec1d7535ebfa30a8.tar.gz fdk-aac-50922e3dbd5d099a67d879c4ec1d7535ebfa30a8.tar.bz2 fdk-aac-50922e3dbd5d099a67d879c4ec1d7535ebfa30a8.zip |
Try to properly handle the case when the bitstream reader runs out of bits to read
Diffstat (limited to 'libFDK')
-rw-r--r-- | libFDK/include/FDK_bitstream.h | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/libFDK/include/FDK_bitstream.h b/libFDK/include/FDK_bitstream.h index d2a7e7d..d47a750 100644 --- a/libFDK/include/FDK_bitstream.h +++ b/libFDK/include/FDK_bitstream.h @@ -223,7 +223,15 @@ FDK_INLINE UINT FDKreadBits(HANDLE_FDK_BITSTREAM hBitStream, else { hBitStream->CacheWord = FDK_get (&hBitStream->hBitBuf,validBits) ; - hBitStream->BitsInCache = validBits - missingBits; + if (validBits >= missingBits) + { + hBitStream->BitsInCache = validBits - missingBits; + } + else + { + hBitStream->BitsInCache = 0; + hBitStream->CacheWord <<= missingBits - validBits; + } } return ( bits | (hBitStream->CacheWord >> hBitStream->BitsInCache)) & BitMask[numberOfBits]; @@ -243,6 +251,12 @@ FDK_INLINE UINT FDKreadBits(HANDLE_FDK_BITSTREAM hBitStream, hBitStream->CacheWord = (hBitStream->CacheWord << bitsToRead) | FDK_get (&hBitStream->hBitBuf,bitsToRead) ; hBitStream->BitsInCache += bitsToRead ; + if (hBitStream->BitsInCache < numberOfBits) + { + hBitStream->CacheWord <<= numberOfBits - hBitStream->BitsInCache; + hBitStream->BitsInCache = 0; + return (hBitStream->CacheWord >> hBitStream->BitsInCache) & validMask ; + } } hBitStream->BitsInCache -= numberOfBits ; |