summaryrefslogtreecommitdiffstats
path: root/libFDK/include/FDK_bitstream.h
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2017-07-21 14:31:41 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2017-07-21 14:31:41 +0200
commit89639e36b29a622c641c3de3a4737a4c848dc365 (patch)
tree2eadccdf7e7eb39cdc8c0087a7bf933150a412d5 /libFDK/include/FDK_bitstream.h
parentd450e652c5f963a2ef3a9392f55ca07c7e06dc6c (diff)
parentaf5863a78efdfccd003dd6bea68c4a2cd2ad9f37 (diff)
downloadfdk-aac-89639e36b29a622c641c3de3a4737a4c848dc365.tar.gz
fdk-aac-89639e36b29a622c641c3de3a4737a4c848dc365.tar.bz2
fdk-aac-89639e36b29a622c641c3de3a4737a4c848dc365.zip
Merge 'mstorjo/master' into dabplus
This adds support for AArch64 and other improvements listed in the ChangeLog
Diffstat (limited to 'libFDK/include/FDK_bitstream.h')
-rw-r--r--libFDK/include/FDK_bitstream.h63
1 files changed, 51 insertions, 12 deletions
diff --git a/libFDK/include/FDK_bitstream.h b/libFDK/include/FDK_bitstream.h
index fc8d7de..d47a750 100644
--- a/libFDK/include/FDK_bitstream.h
+++ b/libFDK/include/FDK_bitstream.h
@@ -212,9 +212,28 @@ FDK_INLINE UINT FDKreadBits(HANDLE_FDK_BITSTREAM hBitStream,
INT missingBits = numberOfBits - hBitStream->BitsInCache;
if (missingBits > 0)
{
- UINT bits = hBitStream->CacheWord << missingBits;
- hBitStream->CacheWord = FDK_get32 (&hBitStream->hBitBuf) ;
- hBitStream->BitsInCache = CACHE_BITS - missingBits;
+ const UINT bits = hBitStream->CacheWord << missingBits;
+ const UINT validBits = FDK_getValidBits (&hBitStream->hBitBuf);
+
+ if (validBits >= 32)
+ {
+ hBitStream->CacheWord = FDK_get32 (&hBitStream->hBitBuf) ;
+ hBitStream->BitsInCache = CACHE_BITS - missingBits;
+ }
+ else
+ {
+ hBitStream->CacheWord = FDK_get (&hBitStream->hBitBuf,validBits) ;
+ if (validBits >= missingBits)
+ {
+ hBitStream->BitsInCache = validBits - missingBits;
+ }
+ else
+ {
+ hBitStream->BitsInCache = 0;
+ hBitStream->CacheWord <<= missingBits - validBits;
+ }
+ }
+
return ( bits | (hBitStream->CacheWord >> hBitStream->BitsInCache)) & BitMask[numberOfBits];
}
@@ -226,10 +245,18 @@ FDK_INLINE UINT FDKreadBits(HANDLE_FDK_BITSTREAM hBitStream,
if (hBitStream->BitsInCache <= numberOfBits)
{
- const INT freeBits = (CACHE_BITS-1) - hBitStream->BitsInCache ;
-
- hBitStream->CacheWord = (hBitStream->CacheWord << freeBits) | FDK_get (&hBitStream->hBitBuf,freeBits) ;
- hBitStream->BitsInCache += freeBits ;
+ const UINT validBits = FDK_getValidBits (&hBitStream->hBitBuf) ;
+ const INT freeBits = (CACHE_BITS-1) - hBitStream->BitsInCache ;
+ const INT bitsToRead = (freeBits <= validBits) ? freeBits : validBits ;
+
+ 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 ;
@@ -243,8 +270,18 @@ FDK_INLINE UINT FDKreadBit(HANDLE_FDK_BITSTREAM hBitStream)
#ifdef OPTIMIZE_FDKREADBITS
if (!hBitStream->BitsInCache)
{
- hBitStream->CacheWord = FDK_get32 (&hBitStream->hBitBuf);
- hBitStream->BitsInCache = CACHE_BITS;
+ const UINT validBits = FDK_getValidBits (&hBitStream->hBitBuf);
+
+ if (validBits >= 32)
+ {
+ hBitStream->CacheWord = FDK_get32 (&hBitStream->hBitBuf);
+ hBitStream->BitsInCache = CACHE_BITS;
+ }
+ else
+ {
+ hBitStream->CacheWord = FDK_get (&hBitStream->hBitBuf,validBits);
+ hBitStream->BitsInCache = validBits;
+ }
}
hBitStream->BitsInCache--;
@@ -268,10 +305,12 @@ inline UINT FDKread2Bits(HANDLE_FDK_BITSTREAM hBitStream)
UINT BitsInCache = hBitStream->BitsInCache;
if (BitsInCache < 2) /* Comparison changed from 'less-equal' to 'less' */
{
- const INT freeBits = (CACHE_BITS-1) - BitsInCache ;
+ const UINT validBits = FDK_getValidBits (&hBitStream->hBitBuf) ;
+ const INT freeBits = (CACHE_BITS-1) - BitsInCache ;
+ const INT bitsToRead = (freeBits <= validBits) ? freeBits : validBits ;
- hBitStream->CacheWord = (hBitStream->CacheWord << freeBits) | FDK_get (&hBitStream->hBitBuf,freeBits) ;
- BitsInCache += freeBits;
+ hBitStream->CacheWord = (hBitStream->CacheWord << bitsToRead) | FDK_get (&hBitStream->hBitBuf,bitsToRead) ;
+ BitsInCache += bitsToRead;
}
hBitStream->BitsInCache = BitsInCache - 2;
return (hBitStream->CacheWord >> hBitStream->BitsInCache) & 0x3;