mirror of
https://github.com/mstorsjo/fdk-aac.git
synced 2025-03-13 06:10:03 +01:00
Try to properly handle the case when the bitstream reader runs out of bits to read
This commit is contained in:
parent
6b0d8201b1
commit
50922e3dbd
@ -223,7 +223,15 @@ FDK_INLINE UINT FDKreadBits(HANDLE_FDK_BITSTREAM hBitStream,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
hBitStream->CacheWord = FDK_get (&hBitStream->hBitBuf,validBits) ;
|
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];
|
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->CacheWord = (hBitStream->CacheWord << bitsToRead) | FDK_get (&hBitStream->hBitBuf,bitsToRead) ;
|
||||||
hBitStream->BitsInCache += 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 ;
|
hBitStream->BitsInCache -= numberOfBits ;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user