Commit ca079b09 authored by Paul B Mahol's avatar Paul B Mahol

avcodec/get_bits: add cached bitstream reader

Signed-off-by: 's avatarPaul B Mahol <onemda@gmail.com>
parent a3c6b7ff
This diff is collapsed.
......@@ -54,6 +54,23 @@ static inline int get_ue_golomb(GetBitContext *gb)
{
unsigned int buf;
#ifdef CACHED_BITSTREAM_READER
buf = show_bits_long(gb, 32);
if (buf >= (1 << 27)) {
buf >>= 32 - 9;
skip_bits_long(gb, ff_golomb_vlc_len[buf]);
return ff_ue_golomb_vlc_code[buf];
} else {
int log = 2 * av_log2(buf) - 31;
buf >>= log;
buf--;
skip_bits_long(gb, 32 - log);
return buf;
}
#else
OPEN_READER(re, gb);
UPDATE_CACHE(re, gb);
buf = GET_CACHE(re, gb);
......@@ -77,6 +94,7 @@ static inline int get_ue_golomb(GetBitContext *gb)
return buf;
}
#endif
}
/**
......@@ -101,6 +119,13 @@ static inline int get_ue_golomb_31(GetBitContext *gb)
{
unsigned int buf;
#ifdef CACHED_BITSTREAM_READER
buf = show_bits_long(gb, 32);
buf >>= 32 - 9;
skip_bits_long(gb, ff_golomb_vlc_len[buf]);
#else
OPEN_READER(re, gb);
UPDATE_CACHE(re, gb);
buf = GET_CACHE(re, gb);
......@@ -108,6 +133,7 @@ static inline int get_ue_golomb_31(GetBitContext *gb)
buf >>= 32 - 9;
LAST_SKIP_BITS(re, gb, ff_golomb_vlc_len[buf]);
CLOSE_READER(re, gb);
#endif
return ff_ue_golomb_vlc_code[buf];
}
......@@ -116,6 +142,33 @@ static inline unsigned get_interleaved_ue_golomb(GetBitContext *gb)
{
uint32_t buf;
#ifdef CACHED_BITSTREAM_READER
buf = show_bits_long(gb, 32);
if (buf & 0xAA800000) {
buf >>= 32 - 8;
skip_bits_long(gb, ff_interleaved_golomb_vlc_len[buf]);
return ff_interleaved_ue_golomb_vlc_code[buf];
} else {
unsigned ret = 1;
do {
buf >>= 32 - 8;
skip_bits_long(gb, FFMIN(ff_interleaved_golomb_vlc_len[buf], 8));
if (ff_interleaved_golomb_vlc_len[buf] != 9) {
ret <<= (ff_interleaved_golomb_vlc_len[buf] - 1) >> 1;
ret |= ff_interleaved_dirac_golomb_vlc_code[buf];
break;
}
ret = (ret << 4) | ff_interleaved_dirac_golomb_vlc_code[buf];
buf = show_bits_long(gb, 32);
} while (get_bits_left(gb) > 0);
return ret - 1;
}
#else
OPEN_READER(re, gb);
UPDATE_CACHE(re, gb);
buf = GET_CACHE(re, gb);
......@@ -147,6 +200,7 @@ static inline unsigned get_interleaved_ue_golomb(GetBitContext *gb)
CLOSE_READER(re, gb);
return ret - 1;
}
#endif
}
/**
......@@ -184,6 +238,28 @@ static inline int get_se_golomb(GetBitContext *gb)
{
unsigned int buf;
#ifdef CACHED_BITSTREAM_READER
buf = show_bits_long(gb, 32);
if (buf >= (1 << 27)) {
buf >>= 32 - 9;
skip_bits_long(gb, ff_golomb_vlc_len[buf]);
return ff_se_golomb_vlc_code[buf];
} else {
int log = 2 * av_log2(buf) - 31;
buf >>= log;
skip_bits_long(gb, 32 - log);
if (buf & 1)
buf = -(buf >> 1);
else
buf = (buf >> 1);
return buf;
}
#else
OPEN_READER(re, gb);
UPDATE_CACHE(re, gb);
buf = GET_CACHE(re, gb);
......@@ -210,6 +286,7 @@ static inline int get_se_golomb(GetBitContext *gb)
return buf;
}
#endif
}
static inline int get_se_golomb_long(GetBitContext *gb)
......@@ -223,6 +300,30 @@ static inline int get_interleaved_se_golomb(GetBitContext *gb)
{
unsigned int buf;
#ifdef CACHED_BITSTREAM_READER
buf = show_bits_long(gb, 32);
if (buf & 0xAA800000) {
buf >>= 32 - 8;
skip_bits_long(gb, ff_interleaved_golomb_vlc_len[buf]);
return ff_interleaved_se_golomb_vlc_code[buf];
} else {
int log;
skip_bits(gb, 8);
buf |= 1 | show_bits_long(gb, 24);
if ((buf & 0xAAAAAAAA) == 0)
return INVALID_VLC;
for (log = 31; (buf & 0x80000000) == 0; log--)
buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30);
skip_bits_long(gb, 63 - 2 * log - 8);
return (signed) (((((buf << log) >> log) - 1) ^ -(buf & 0x1)) + 1) >> 1;
}
#else
OPEN_READER(re, gb);
UPDATE_CACHE(re, gb);
buf = GET_CACHE(re, gb);
......@@ -250,6 +351,7 @@ static inline int get_interleaved_se_golomb(GetBitContext *gb)
return (signed) (((((buf << log) >> log) - 1) ^ -(buf & 0x1)) + 1) >> 1;
}
#endif
}
static inline int dirac_get_se_golomb(GetBitContext *gb)
......@@ -273,6 +375,24 @@ static inline int get_ur_golomb(GetBitContext *gb, int k, int limit,
unsigned int buf;
int log;
#ifdef CACHED_BITSTREAM_READER
buf = show_bits_long(gb, 32);
log = av_log2(buf);
if (log > 31 - limit) {
buf >>= log - k;
buf += (30 - log) << k;
skip_bits_long(gb, 32 + k - log);
return buf;
} else {
skip_bits_long(gb, limit);
buf = get_bits_long(gb, esc_len);
return buf + limit - 1;
}
#else
OPEN_READER(re, gb);
UPDATE_CACHE(re, gb);
buf = GET_CACHE(re, gb);
......@@ -297,6 +417,7 @@ static inline int get_ur_golomb(GetBitContext *gb, int k, int limit,
return buf + limit - 1;
}
#endif
}
/**
......@@ -308,6 +429,35 @@ static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit,
unsigned int buf;
int log;
#ifdef CACHED_BITSTREAM_READER
buf = show_bits_long(gb, 32);
log = av_log2(buf);
if (log - k >= 1 && 32 - log < limit) {
buf >>= log - k;
buf += (30 - log) << k;
skip_bits_long(gb, 32 + k - log);
return buf;
} else {
int i;
for (i = 0;
i < limit && get_bits1(gb) == 0 && get_bits_left(gb) > 0;
i++);
if (i < limit - 1) {
buf = get_bits_long(gb, k);
return buf + (i << k);
} else if (i == limit - 1) {
buf = get_bits_long(gb, esc_len);
return buf + 1;
} else
return -1;
}
#else
OPEN_READER(re, gb);
UPDATE_CACHE(re, gb);
buf = GET_CACHE(re, gb);
......@@ -364,6 +514,7 @@ static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit,
CLOSE_READER(re, gb);
return buf;
}
#endif
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment