/** \file bitstream.h Bitstream structures and inline functions. */
-#define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \
- (((const uint8_t*)(x))[1] << 16) | \
- (((const uint8_t*)(x))[2] << 8) | \
- ((const uint8_t*)(x))[3])
-
/** Structure for bistream I/O. */
struct getbit_context {
/* Start of the internal buffer. */
static inline uint32_t show_bits(struct getbit_context *gbc, int num)
{
int idx = gbc->index;
- uint32_t x = AV_RB32(gbc->buffer + (idx >> 3)) << (idx & 7);
- return x >> (32 - num);
+ const uint8_t *p = gbc->buffer + (idx >> 3);
+ uint32_t x = ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
+ return (x << (idx & 7)) >> (32 - num);
}
static inline int get_bits_count(struct getbit_context *gbc)
return ret;
}
-static inline unsigned int get_bits1(struct getbit_context *gbc)
+/* This is rather hot, we can do better than get_bits(gbc, 1). */
+static inline unsigned int get_bit(struct getbit_context *gbc)
{
- int idx = gbc->index;
- uint8_t result = gbc->buffer[idx >> 3];
-
- result <<= (idx & 0x07);
- result >>= 8 - 1;
- idx++;
- gbc->index = idx;
- return result;
+ int idx = gbc->index++;
+ uint8_t tmp = gbc->buffer[idx >> 3], mask = (1 << (7 - (idx & 7)));
+ return !!(tmp & mask);
}
/**