*/
/**
- * @file bitstream.h
+ * @file libavcodec/bitstream.h
* bitstream api header.
*/
-#ifndef FFMPEG_BITSTREAM_H
-#define FFMPEG_BITSTREAM_H
+#ifndef AVCODEC_BITSTREAM_H
+#define AVCODEC_BITSTREAM_H
#include <stdint.h>
#include <stdlib.h>
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/log.h"
+#include "mathops.h"
#if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER)
# define ALT_BITSTREAM_READER
//#define ALT_BITSTREAM_WRITER
//#define ALIGNED_BITSTREAM_WRITER
#if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER)
-# ifdef ARCH_ARMV4L
+# if ARCH_ARM
# define A32_BITSTREAM_READER
# else
# define ALT_BITSTREAM_READER
extern const uint8_t ff_reverse[256];
-#if defined(ARCH_X86)
+#if ARCH_X86
// avoid +32 for shift optimization (gcc should do that ...)
static inline int32_t NEG_SSR32( int32_t a, int8_t s){
- asm ("sarl %1, %0\n\t"
+ __asm__ ("sarl %1, %0\n\t"
: "+r" (a)
: "ic" ((uint8_t)(-s))
);
return a;
}
static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
- asm ("shrl %1, %0\n\t"
+ __asm__ ("shrl %1, %0\n\t"
: "+r" (a)
: "ic" ((uint8_t)(-s))
);
int bit_left;
uint8_t *buf, *buf_ptr, *buf_end;
#endif
+ int size_in_bits;
} PutBitContext;
static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
buffer = NULL;
}
+ s->size_in_bits= 8*buffer_size;
s->buf = buffer;
s->buf_end = s->buf + buffer_size;
#ifdef ALT_BITSTREAM_WRITER
uint8_t run;
} RL_VLC_ELEM;
-#if defined(ARCH_SPARC) || defined(ARCH_ARMV4L) || defined(ARCH_MIPS) || defined(ARCH_BFIN)
-#define UNALIGNED_STORES_ARE_BAD
-#endif
-
#ifndef ALT_BITSTREAM_WRITER
static inline void put_bits(PutBitContext *s, int n, unsigned int value)
{
#ifdef BITSTREAM_WRITER_LE
bit_buf |= value << (32 - bit_left);
if (n >= bit_left) {
-#ifdef UNALIGNED_STORES_ARE_BAD
+#if !HAVE_FAST_UNALIGNED
if (3 & (intptr_t) s->buf_ptr) {
- s->buf_ptr[0] = bit_buf ;
- s->buf_ptr[1] = bit_buf >> 8;
- s->buf_ptr[2] = bit_buf >> 16;
- s->buf_ptr[3] = bit_buf >> 24;
+ AV_WL32(s->buf_ptr, bit_buf);
} else
#endif
*(uint32_t *)s->buf_ptr = le2me_32(bit_buf);
} else {
bit_buf<<=bit_left;
bit_buf |= value >> (n - bit_left);
-#ifdef UNALIGNED_STORES_ARE_BAD
+#if !HAVE_FAST_UNALIGNED
if (3 & (intptr_t) s->buf_ptr) {
- s->buf_ptr[0] = bit_buf >> 24;
- s->buf_ptr[1] = bit_buf >> 16;
- s->buf_ptr[2] = bit_buf >> 8;
- s->buf_ptr[3] = bit_buf ;
+ AV_WB32(s->buf_ptr, bit_buf);
} else
#endif
*(uint32_t *)s->buf_ptr = be2me_32(bit_buf);
static inline void put_bits(PutBitContext *s, int n, unsigned int value)
{
# ifdef ALIGNED_BITSTREAM_WRITER
-# if defined(ARCH_X86)
- asm volatile(
+# if ARCH_X86
+ __asm__ volatile(
"movl %0, %%ecx \n\t"
"xorl %%eax, %%eax \n\t"
"shrdl %%cl, %1, %%eax \n\t"
s->index= index;
# endif
# else //ALIGNED_BITSTREAM_WRITER
-# if defined(ARCH_X86)
- asm volatile(
+# if ARCH_X86
+ __asm__ volatile(
"movl $7, %%ecx \n\t"
"andl %0, %%ecx \n\t"
"addl %3, %%ecx \n\t"
/**
* Skips the given number of bits.
* Must only be used if the actual values in the bitstream do not matter.
+ * If \p n is 0 the behavior is undefined.
*/
static inline void skip_put_bits(PutBitContext *s, int n){
#ifdef ALT_BITSTREAM_WRITER
/* Bitstream reader API docs:
name
- abritary name which is used as prefix for the internal variables
+ arbitrary name which is used as prefix for the internal variables
gb
getbitcontext
name##_bit_count-= 32;\
}\
-#if defined(ARCH_X86)
+#if ARCH_X86
# define SKIP_CACHE(name, gb, num)\
- asm(\
+ __asm__(\
"shldl %2, %1, %0 \n\t"\
"shll %2, %1 \n\t"\
: "+r" (name##_cache0), "+r" (name##_cache1)\
}
}
+/**
+ * reads 0-32 bits as a signed integer.
+ */
+static inline int get_sbits_long(GetBitContext *s, int n) {
+ return sign_extend(get_bits_long(s, n), n);
+}
+
/**
* shows 0-32 bits.
*/
if(n<=17) return show_bits(s, n);
else{
GetBitContext gb= *s;
- int ret= get_bits_long(s, n);
- *s= gb;
- return ret;
+ return get_bits_long(&gb, n);
}
}
return 2 - get_bits1(gb);
}
-#endif /* FFMPEG_BITSTREAM_H */
+#endif /* AVCODEC_BITSTREAM_H */