summaryrefslogtreecommitdiff
path: root/libs/ffvpx/libavcodec/golomb.h
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2022-06-07 20:20:19 -0500
committerMatt A. Tobin <email@mattatobin.com>2022-06-07 20:20:19 -0500
commit878ab758d5d4c1ef7badf2bc20ebc7c67dc2165b (patch)
tree3683d6df35e3618c0e7b456de7c749ca4c8c21a6 /libs/ffvpx/libavcodec/golomb.h
parenta621951327b0c19c0c24dfd9fd973f7bd13ae68f (diff)
parentcfb9884423faf741de03c5fcc72bf9ac8c6ada4d (diff)
downloadaura-central-878ab758d5d4c1ef7badf2bc20ebc7c67dc2165b.tar.gz
Merge branch 'TRUNK' into ARE-5.0
Diffstat (limited to 'libs/ffvpx/libavcodec/golomb.h')
-rw-r--r--libs/ffvpx/libavcodec/golomb.h163
1 files changed, 160 insertions, 3 deletions
diff --git a/libs/ffvpx/libavcodec/golomb.h b/libs/ffvpx/libavcodec/golomb.h
index efb1eff8a..5cdfa0945 100644
--- a/libs/ffvpx/libavcodec/golomb.h
+++ b/libs/ffvpx/libavcodec/golomb.h
@@ -49,11 +49,30 @@ extern const uint8_t ff_interleaved_dirac_golomb_vlc_code[256];
/**
* Read an unsigned Exp-Golomb code in the range 0 to 8190.
+ *
+ * @returns the read value or a negative error code.
*/
static inline int get_ue_golomb(GetBitContext *gb)
{
unsigned int buf;
+#if 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 +96,7 @@ static inline int get_ue_golomb(GetBitContext *gb)
return buf;
}
+#endif
}
/**
@@ -101,6 +121,13 @@ static inline int get_ue_golomb_31(GetBitContext *gb)
{
unsigned int buf;
+#if 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 +135,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 +144,33 @@ static inline unsigned get_interleaved_ue_golomb(GetBitContext *gb)
{
uint32_t buf;
+#if 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 +202,7 @@ static inline unsigned get_interleaved_ue_golomb(GetBitContext *gb)
CLOSE_READER(re, gb);
return ret - 1;
}
+#endif
}
/**
@@ -184,6 +240,28 @@ static inline int get_se_golomb(GetBitContext *gb)
{
unsigned int buf;
+#if 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 +288,7 @@ static inline int get_se_golomb(GetBitContext *gb)
return buf;
}
+#endif
}
static inline int get_se_golomb_long(GetBitContext *gb)
@@ -223,6 +302,30 @@ static inline int get_interleaved_se_golomb(GetBitContext *gb)
{
unsigned int buf;
+#if 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 +353,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 +377,24 @@ static inline int get_ur_golomb(GetBitContext *gb, int k, int limit,
unsigned int buf;
int log;
+#if 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 +419,7 @@ static inline int get_ur_golomb(GetBitContext *gb, int k, int limit,
return buf + limit - 1;
}
+#endif
}
/**
@@ -308,6 +431,35 @@ static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit,
unsigned int buf;
int log;
+#if 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);
@@ -326,15 +478,19 @@ static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit,
return buf;
} else {
int i;
- for (i = 0; i < limit && SHOW_UBITS(re, gb, 1) == 0; i++) {
+ for (i = 0; i + MIN_CACHE_BITS <= limit && SHOW_UBITS(re, gb, MIN_CACHE_BITS) == 0; i += MIN_CACHE_BITS) {
if (gb->size_in_bits <= re_index) {
CLOSE_READER(re, gb);
return -1;
}
- LAST_SKIP_BITS(re, gb, 1);
+ LAST_SKIP_BITS(re, gb, MIN_CACHE_BITS);
UPDATE_CACHE(re, gb);
}
- SKIP_BITS(re, gb, 1);
+ for (; i < limit && SHOW_UBITS(re, gb, 1) == 0; i++) {
+ SKIP_BITS(re, gb, 1);
+ }
+ LAST_SKIP_BITS(re, gb, 1);
+ UPDATE_CACHE(re, gb);
if (i < limit - 1) {
if (k) {
@@ -364,6 +520,7 @@ static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit,
CLOSE_READER(re, gb);
return buf;
}
+#endif
}
/**