mirror of https://git.ffmpeg.org/ffmpeg.git
avcodec/get_bits: actually make cached reader correctly disabled
This commit is contained in:
parent
6b1b5af024
commit
9305bdc68f
|
@ -54,9 +54,13 @@
|
||||||
#define UNCHECKED_BITSTREAM_READER !CONFIG_SAFE_BITSTREAM_READER
|
#define UNCHECKED_BITSTREAM_READER !CONFIG_SAFE_BITSTREAM_READER
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef CACHED_BITSTREAM_READER
|
||||||
|
#define CACHED_BITSTREAM_READER 0
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct GetBitContext {
|
typedef struct GetBitContext {
|
||||||
const uint8_t *buffer, *buffer_end;
|
const uint8_t *buffer, *buffer_end;
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
uint64_t cache;
|
uint64_t cache;
|
||||||
unsigned bits_left;
|
unsigned bits_left;
|
||||||
#endif
|
#endif
|
||||||
|
@ -116,7 +120,7 @@ static inline unsigned int show_bits(GetBitContext *s, int n);
|
||||||
* For examples see get_bits, show_bits, skip_bits, get_vlc.
|
* For examples see get_bits, show_bits, skip_bits, get_vlc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
# define MIN_CACHE_BITS 64
|
# define MIN_CACHE_BITS 64
|
||||||
#elif defined LONG_BITSTREAM_READER
|
#elif defined LONG_BITSTREAM_READER
|
||||||
# define MIN_CACHE_BITS 32
|
# define MIN_CACHE_BITS 32
|
||||||
|
@ -124,7 +128,7 @@ static inline unsigned int show_bits(GetBitContext *s, int n);
|
||||||
# define MIN_CACHE_BITS 25
|
# define MIN_CACHE_BITS 25
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CACHED_BITSTREAM_READER
|
#if !CACHED_BITSTREAM_READER
|
||||||
|
|
||||||
#define OPEN_READER_NOSIZE(name, gb) \
|
#define OPEN_READER_NOSIZE(name, gb) \
|
||||||
unsigned int name ## _index = (gb)->index; \
|
unsigned int name ## _index = (gb)->index; \
|
||||||
|
@ -214,14 +218,14 @@ static inline unsigned int show_bits(GetBitContext *s, int n);
|
||||||
|
|
||||||
static inline int get_bits_count(const GetBitContext *s)
|
static inline int get_bits_count(const GetBitContext *s)
|
||||||
{
|
{
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
return s->index - s->bits_left;
|
return s->index - s->bits_left;
|
||||||
#else
|
#else
|
||||||
return s->index;
|
return s->index;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
static inline void refill_32(GetBitContext *s)
|
static inline void refill_32(GetBitContext *s)
|
||||||
{
|
{
|
||||||
#if !UNCHECKED_BITSTREAM_READER
|
#if !UNCHECKED_BITSTREAM_READER
|
||||||
|
@ -288,7 +292,7 @@ static inline unsigned show_val(const GetBitContext *s, unsigned n)
|
||||||
*/
|
*/
|
||||||
static inline void skip_bits_long(GetBitContext *s, int n)
|
static inline void skip_bits_long(GetBitContext *s, int n)
|
||||||
{
|
{
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
skip_bits(s, n);
|
skip_bits(s, n);
|
||||||
#else
|
#else
|
||||||
#if UNCHECKED_BITSTREAM_READER
|
#if UNCHECKED_BITSTREAM_READER
|
||||||
|
@ -299,7 +303,7 @@ static inline void skip_bits_long(GetBitContext *s, int n)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
static inline void skip_remaining(GetBitContext *s, unsigned n)
|
static inline void skip_remaining(GetBitContext *s, unsigned n)
|
||||||
{
|
{
|
||||||
#ifdef BITSTREAM_READER_LE
|
#ifdef BITSTREAM_READER_LE
|
||||||
|
@ -318,7 +322,7 @@ static inline void skip_remaining(GetBitContext *s, unsigned n)
|
||||||
*/
|
*/
|
||||||
static inline int get_xbits(GetBitContext *s, int n)
|
static inline int get_xbits(GetBitContext *s, int n)
|
||||||
{
|
{
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
int32_t cache = show_bits(s, 32);
|
int32_t cache = show_bits(s, 32);
|
||||||
int sign = ~cache >> 31;
|
int sign = ~cache >> 31;
|
||||||
skip_remaining(s, n);
|
skip_remaining(s, n);
|
||||||
|
@ -338,7 +342,7 @@ static inline int get_xbits(GetBitContext *s, int n)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef CACHED_BITSTREAM_READER
|
#if !CACHED_BITSTREAM_READER
|
||||||
static inline int get_xbits_le(GetBitContext *s, int n)
|
static inline int get_xbits_le(GetBitContext *s, int n)
|
||||||
{
|
{
|
||||||
register int sign;
|
register int sign;
|
||||||
|
@ -357,7 +361,7 @@ static inline int get_xbits_le(GetBitContext *s, int n)
|
||||||
static inline int get_sbits(GetBitContext *s, int n)
|
static inline int get_sbits(GetBitContext *s, int n)
|
||||||
{
|
{
|
||||||
register int tmp;
|
register int tmp;
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
av_assert2(n>0 && n<=25);
|
av_assert2(n>0 && n<=25);
|
||||||
tmp = sign_extend(get_bits(s, n), n);
|
tmp = sign_extend(get_bits(s, n), n);
|
||||||
#else
|
#else
|
||||||
|
@ -377,7 +381,7 @@ static inline int get_sbits(GetBitContext *s, int n)
|
||||||
static inline unsigned int get_bits(GetBitContext *s, int n)
|
static inline unsigned int get_bits(GetBitContext *s, int n)
|
||||||
{
|
{
|
||||||
register int tmp;
|
register int tmp;
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
|
|
||||||
av_assert2(n>0 && n<=32);
|
av_assert2(n>0 && n<=32);
|
||||||
if (n > s->bits_left) {
|
if (n > s->bits_left) {
|
||||||
|
@ -412,7 +416,7 @@ static av_always_inline int get_bitsz(GetBitContext *s, int n)
|
||||||
|
|
||||||
static inline unsigned int get_bits_le(GetBitContext *s, int n)
|
static inline unsigned int get_bits_le(GetBitContext *s, int n)
|
||||||
{
|
{
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
av_assert2(n>0 && n<=32);
|
av_assert2(n>0 && n<=32);
|
||||||
if (n > s->bits_left) {
|
if (n > s->bits_left) {
|
||||||
refill_32(s);
|
refill_32(s);
|
||||||
|
@ -439,7 +443,7 @@ static inline unsigned int get_bits_le(GetBitContext *s, int n)
|
||||||
static inline unsigned int show_bits(GetBitContext *s, int n)
|
static inline unsigned int show_bits(GetBitContext *s, int n)
|
||||||
{
|
{
|
||||||
register int tmp;
|
register int tmp;
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
if (n > s->bits_left)
|
if (n > s->bits_left)
|
||||||
refill_32(s);
|
refill_32(s);
|
||||||
|
|
||||||
|
@ -455,7 +459,7 @@ static inline unsigned int show_bits(GetBitContext *s, int n)
|
||||||
|
|
||||||
static inline void skip_bits(GetBitContext *s, int n)
|
static inline void skip_bits(GetBitContext *s, int n)
|
||||||
{
|
{
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
if (n < s->bits_left)
|
if (n < s->bits_left)
|
||||||
skip_remaining(s, n);
|
skip_remaining(s, n);
|
||||||
else {
|
else {
|
||||||
|
@ -482,7 +486,7 @@ static inline void skip_bits(GetBitContext *s, int n)
|
||||||
|
|
||||||
static inline unsigned int get_bits1(GetBitContext *s)
|
static inline unsigned int get_bits1(GetBitContext *s)
|
||||||
{
|
{
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
if (!s->bits_left)
|
if (!s->bits_left)
|
||||||
refill_64(s);
|
refill_64(s);
|
||||||
|
|
||||||
|
@ -529,7 +533,7 @@ static inline unsigned int get_bits_long(GetBitContext *s, int n)
|
||||||
av_assert2(n>=0 && n<=32);
|
av_assert2(n>=0 && n<=32);
|
||||||
if (!n) {
|
if (!n) {
|
||||||
return 0;
|
return 0;
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
}
|
}
|
||||||
return get_bits(s, n);
|
return get_bits(s, n);
|
||||||
#else
|
#else
|
||||||
|
@ -628,7 +632,7 @@ static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,
|
||||||
s->buffer_end = buffer + buffer_size;
|
s->buffer_end = buffer + buffer_size;
|
||||||
s->index = 0;
|
s->index = 0;
|
||||||
|
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
refill_64(s);
|
refill_64(s);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -758,7 +762,7 @@ static inline int set_idx(GetBitContext *s, int code, int *n, int *nb_bits,
|
||||||
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
|
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
|
||||||
int bits, int max_depth)
|
int bits, int max_depth)
|
||||||
{
|
{
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
int nb_bits;
|
int nb_bits;
|
||||||
unsigned idx = show_bits(s, bits);
|
unsigned idx = show_bits(s, bits);
|
||||||
int code = table[idx][0];
|
int code = table[idx][0];
|
||||||
|
|
|
@ -54,7 +54,7 @@ static inline int get_ue_golomb(GetBitContext *gb)
|
||||||
{
|
{
|
||||||
unsigned int buf;
|
unsigned int buf;
|
||||||
|
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
buf = show_bits_long(gb, 32);
|
buf = show_bits_long(gb, 32);
|
||||||
|
|
||||||
if (buf >= (1 << 27)) {
|
if (buf >= (1 << 27)) {
|
||||||
|
@ -119,7 +119,7 @@ static inline int get_ue_golomb_31(GetBitContext *gb)
|
||||||
{
|
{
|
||||||
unsigned int buf;
|
unsigned int buf;
|
||||||
|
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
buf = show_bits_long(gb, 32);
|
buf = show_bits_long(gb, 32);
|
||||||
|
|
||||||
buf >>= 32 - 9;
|
buf >>= 32 - 9;
|
||||||
|
@ -142,7 +142,7 @@ static inline unsigned get_interleaved_ue_golomb(GetBitContext *gb)
|
||||||
{
|
{
|
||||||
uint32_t buf;
|
uint32_t buf;
|
||||||
|
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
buf = show_bits_long(gb, 32);
|
buf = show_bits_long(gb, 32);
|
||||||
|
|
||||||
if (buf & 0xAA800000) {
|
if (buf & 0xAA800000) {
|
||||||
|
@ -238,7 +238,7 @@ static inline int get_se_golomb(GetBitContext *gb)
|
||||||
{
|
{
|
||||||
unsigned int buf;
|
unsigned int buf;
|
||||||
|
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
buf = show_bits_long(gb, 32);
|
buf = show_bits_long(gb, 32);
|
||||||
|
|
||||||
if (buf >= (1 << 27)) {
|
if (buf >= (1 << 27)) {
|
||||||
|
@ -300,7 +300,7 @@ static inline int get_interleaved_se_golomb(GetBitContext *gb)
|
||||||
{
|
{
|
||||||
unsigned int buf;
|
unsigned int buf;
|
||||||
|
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
buf = show_bits_long(gb, 32);
|
buf = show_bits_long(gb, 32);
|
||||||
|
|
||||||
if (buf & 0xAA800000) {
|
if (buf & 0xAA800000) {
|
||||||
|
@ -375,7 +375,7 @@ static inline int get_ur_golomb(GetBitContext *gb, int k, int limit,
|
||||||
unsigned int buf;
|
unsigned int buf;
|
||||||
int log;
|
int log;
|
||||||
|
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
buf = show_bits_long(gb, 32);
|
buf = show_bits_long(gb, 32);
|
||||||
|
|
||||||
log = av_log2(buf);
|
log = av_log2(buf);
|
||||||
|
@ -429,7 +429,7 @@ static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit,
|
||||||
unsigned int buf;
|
unsigned int buf;
|
||||||
int log;
|
int log;
|
||||||
|
|
||||||
#ifdef CACHED_BITSTREAM_READER
|
#if CACHED_BITSTREAM_READER
|
||||||
buf = show_bits_long(gb, 32);
|
buf = show_bits_long(gb, 32);
|
||||||
|
|
||||||
log = av_log2(buf);
|
log = av_log2(buf);
|
||||||
|
|
Loading…
Reference in New Issue