annotate bitstream.h @ 3649:3335f51b6cd3 libavcodec

force usage of ALT_BITSTREAM_READER where needed
author aurel
date Mon, 28 Aug 2006 18:46:01 +0000
parents c44d798b06b5
children a74c0aaf9832
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1083
diff changeset
1 /**
2398
582e635cfa08 common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents: 2391
diff changeset
2 * @file bitstream.h
582e635cfa08 common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents: 2391
diff changeset
3 * bitstream api header.
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1083
diff changeset
4 */
1e39f273ecd6 per file doxy
michaelni
parents: 1083
diff changeset
5
2398
582e635cfa08 common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents: 2391
diff changeset
6 #ifndef BITSTREAM_H
582e635cfa08 common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents: 2391
diff changeset
7 #define BITSTREAM_H
64
5aa6292a1660 win32 fixes
glantau
parents: 21
diff changeset
8
3648
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
9 #include "log.h"
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
10
3649
3335f51b6cd3 force usage of ALT_BITSTREAM_READER where needed
aurel
parents: 3648
diff changeset
11 #if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER)
3335f51b6cd3 force usage of ALT_BITSTREAM_READER where needed
aurel
parents: 3648
diff changeset
12 #define ALT_BITSTREAM_READER
3335f51b6cd3 force usage of ALT_BITSTREAM_READER where needed
aurel
parents: 3648
diff changeset
13 #endif
3335f51b6cd3 force usage of ALT_BITSTREAM_READER where needed
aurel
parents: 3648
diff changeset
14
234
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
15 //#define ALT_BITSTREAM_WRITER
235
41f0ef2cd942 aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents: 234
diff changeset
16 //#define ALIGNED_BITSTREAM_WRITER
3628
ce878aa023fe prevent bitstream reader to be overriden
michael
parents: 3454
diff changeset
17 #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER)
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
18 #define ALT_BITSTREAM_READER
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
19 //#define LIBMPEG2_BITSTREAM_READER
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
20 //#define A32_BITSTREAM_READER
3628
ce878aa023fe prevent bitstream reader to be overriden
michael
parents: 3454
diff changeset
21 #endif
1254
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
22 #define LIBMPEG2_BITSTREAM_READER_HACK //add BERO
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2894
diff changeset
23
2578
91e094c9dcdc make reverse[] non static
michael
parents: 2502
diff changeset
24 extern const uint8_t ff_reverse[256];
91e094c9dcdc make reverse[] non static
michael
parents: 2502
diff changeset
25
2293
15cfba1b97b5 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2288
diff changeset
26 #if defined(ARCH_X86) || defined(ARCH_X86_64)
525
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
27 // avoid +32 for shift optimization (gcc should do that ...)
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
28 static inline int32_t NEG_SSR32( int32_t a, int8_t s){
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
29 asm ("sarl %1, %0\n\t"
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
30 : "+r" (a)
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
31 : "ic" ((uint8_t)(-s))
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
32 );
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
33 return a;
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
34 }
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
35 static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
36 asm ("shrl %1, %0\n\t"
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
37 : "+r" (a)
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
38 : "ic" ((uint8_t)(-s))
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
39 );
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
40 return a;
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
41 }
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
42 #else
708
1aa1cbb8c3c1 indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents: 706
diff changeset
43 # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
1aa1cbb8c3c1 indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents: 706
diff changeset
44 # define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
45 #endif
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
46
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
47 /* bit output */
986e461dc072 Initial revision
glantau
parents:
diff changeset
48
1895
e5687117cc7f * removing casualties of battle of the wits and English language
romansh
parents: 1886
diff changeset
49 /* buf and buf_end must be present and used by every alternative writer. */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
50 typedef struct PutBitContext {
234
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
51 #ifdef ALT_BITSTREAM_WRITER
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1059
diff changeset
52 uint8_t *buf, *buf_end;
234
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
53 int index;
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
54 #else
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1059
diff changeset
55 uint32_t bit_buf;
238
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
56 int bit_left;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1059
diff changeset
57 uint8_t *buf, *buf_ptr, *buf_end;
234
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
58 #endif
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
59 } PutBitContext;
986e461dc072 Initial revision
glantau
parents:
diff changeset
60
1875
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
61 static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
62 {
2894
26f8974c3d66 fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents: 2889
diff changeset
63 if(buffer_size < 0) {
26f8974c3d66 fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents: 2889
diff changeset
64 buffer_size = 0;
26f8974c3d66 fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents: 2889
diff changeset
65 buffer = NULL;
26f8974c3d66 fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents: 2889
diff changeset
66 }
2889
64231191674b precautionary checks
michael
parents: 2885
diff changeset
67
1875
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
68 s->buf = buffer;
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
69 s->buf_end = s->buf + buffer_size;
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
70 #ifdef ALT_BITSTREAM_WRITER
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
71 s->index=0;
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
72 ((uint32_t*)(s->buf))[0]=0;
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
73 // memset(buffer, 0, buffer_size);
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
74 #else
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
75 s->buf_ptr = s->buf;
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
76 s->bit_left=32;
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
77 s->bit_buf=0;
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
78 #endif
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
79 }
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
80
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
81 /* return the number of bits output */
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
82 static inline int put_bits_count(PutBitContext *s)
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
83 {
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
84 #ifdef ALT_BITSTREAM_WRITER
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
85 return s->index;
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
86 #else
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
87 return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left;
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
88 #endif
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
89 }
234
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
90
1875
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
91 /* pad the end of the output stream with zeros */
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
92 static inline void flush_put_bits(PutBitContext *s)
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
93 {
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
94 #ifdef ALT_BITSTREAM_WRITER
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
95 align_put_bits(s);
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
96 #else
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
97 s->bit_buf<<= s->bit_left;
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
98 while (s->bit_left < 32) {
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
99 /* XXX: should test end of buffer */
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
100 *s->buf_ptr++=s->bit_buf >> 24;
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
101 s->bit_buf<<=8;
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
102 s->bit_left+=8;
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
103 }
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
104 s->bit_left=32;
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
105 s->bit_buf=0;
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
106 #endif
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
107 }
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
108
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
109 void align_put_bits(PutBitContext *s);
2885
5dfb90019814 Rename put_string to ff_put_string to avoid a symbol clash on Mac OS X.
diego
parents: 2764
diff changeset
110 void ff_put_string(PutBitContext * pbc, char *s, int put_zero);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
111
986e461dc072 Initial revision
glantau
parents:
diff changeset
112 /* bit input */
1895
e5687117cc7f * removing casualties of battle of the wits and English language
romansh
parents: 1886
diff changeset
113 /* buffer, buffer_end and size_in_bits must be present and used by every reader */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
114 typedef struct GetBitContext {
1083
b923be2fc4b5 * using const buffers for reading
kabi
parents: 1079
diff changeset
115 const uint8_t *buffer, *buffer_end;
192
1e5f64be86fc another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents: 151
diff changeset
116 #ifdef ALT_BITSTREAM_READER
1e5f64be86fc another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents: 151
diff changeset
117 int index;
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
118 #elif defined LIBMPEG2_BITSTREAM_READER
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1059
diff changeset
119 uint8_t *buffer_ptr;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1059
diff changeset
120 uint32_t cache;
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
121 int bit_count;
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
122 #elif defined A32_BITSTREAM_READER
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1059
diff changeset
123 uint32_t *buffer_ptr;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1059
diff changeset
124 uint32_t cache0;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1059
diff changeset
125 uint32_t cache1;
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
126 int bit_count;
192
1e5f64be86fc another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents: 151
diff changeset
127 #endif
1025
1f9afd8b9131 GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents: 994
diff changeset
128 int size_in_bits;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
129 } GetBitContext;
986e461dc072 Initial revision
glantau
parents:
diff changeset
130
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1059
diff changeset
131 #define VLC_TYPE int16_t
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
132
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
133 typedef struct VLC {
986e461dc072 Initial revision
glantau
parents:
diff changeset
134 int bits;
1112
54be6aece1be more cosmetics so that doxygen output is readable ...
michaelni
parents: 1106
diff changeset
135 VLC_TYPE (*table)[2]; ///< code, bits
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
136 int table_size, table_allocated;
986e461dc072 Initial revision
glantau
parents:
diff changeset
137 } VLC;
986e461dc072 Initial revision
glantau
parents:
diff changeset
138
542
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
139 typedef struct RL_VLC_ELEM {
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
140 int16_t level;
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
141 int8_t len;
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
142 uint8_t run;
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
143 } RL_VLC_ELEM;
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
144
3342
ff5bed27d7ca MIPS doesn't like unaligned accesses
mru
parents: 3302
diff changeset
145 #if defined(ARCH_SPARC) || defined(ARCH_ARMV4L) || defined(ARCH_MIPS)
891
d3fc77a6d57e Add some rudimentary support for sparc64
philipjsg
parents: 880
diff changeset
146 #define UNALIGNED_STORES_ARE_BAD
d3fc77a6d57e Add some rudimentary support for sparc64
philipjsg
parents: 880
diff changeset
147 #endif
d3fc77a6d57e Add some rudimentary support for sparc64
philipjsg
parents: 880
diff changeset
148
193
b691dd3e9088 aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents: 192
diff changeset
149 /* used to avoid missaligned exceptions on some archs (alpha, ...) */
2293
15cfba1b97b5 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2288
diff changeset
150 #if defined(ARCH_X86) || defined(ARCH_X86_64)
3302
cb356bfc7e22 add unaligned16() and unaligned64()
mru
parents: 3244
diff changeset
151 # define unaligned16(a) (*(const uint16_t*)(a))
2288
3d4a1f8e6a27 * fixing a few of gcc 'clean-code' warnings
kabi
parents: 2140
diff changeset
152 # define unaligned32(a) (*(const uint32_t*)(a))
3302
cb356bfc7e22 add unaligned16() and unaligned64()
mru
parents: 3244
diff changeset
153 # define unaligned64(a) (*(const uint64_t*)(a))
193
b691dd3e9088 aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents: 192
diff changeset
154 #else
708
1aa1cbb8c3c1 indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents: 706
diff changeset
155 # ifdef __GNUC__
3302
cb356bfc7e22 add unaligned16() and unaligned64()
mru
parents: 3244
diff changeset
156 # define unaligned(x) \
cb356bfc7e22 add unaligned16() and unaligned64()
mru
parents: 3244
diff changeset
157 static inline uint##x##_t unaligned##x(const void *v) { \
cb356bfc7e22 add unaligned16() and unaligned64()
mru
parents: 3244
diff changeset
158 struct Unaligned { \
cb356bfc7e22 add unaligned16() and unaligned64()
mru
parents: 3244
diff changeset
159 uint##x##_t i; \
cb356bfc7e22 add unaligned16() and unaligned64()
mru
parents: 3244
diff changeset
160 } __attribute__((packed)); \
cb356bfc7e22 add unaligned16() and unaligned64()
mru
parents: 3244
diff changeset
161 \
cb356bfc7e22 add unaligned16() and unaligned64()
mru
parents: 3244
diff changeset
162 return ((const struct Unaligned *) v)->i; \
193
b691dd3e9088 aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents: 192
diff changeset
163 }
708
1aa1cbb8c3c1 indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents: 706
diff changeset
164 # elif defined(__DECC)
3302
cb356bfc7e22 add unaligned16() and unaligned64()
mru
parents: 3244
diff changeset
165 # define unaligned(x) \
cb356bfc7e22 add unaligned16() and unaligned64()
mru
parents: 3244
diff changeset
166 static inline uint##x##_t unaligned##x##(const void *v) { \
cb356bfc7e22 add unaligned16() and unaligned64()
mru
parents: 3244
diff changeset
167 return *(const __unaligned uint##x##_t *) v; \
193
b691dd3e9088 aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents: 192
diff changeset
168 }
708
1aa1cbb8c3c1 indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents: 706
diff changeset
169 # else
3302
cb356bfc7e22 add unaligned16() and unaligned64()
mru
parents: 3244
diff changeset
170 # define unaligned(x) \
cb356bfc7e22 add unaligned16() and unaligned64()
mru
parents: 3244
diff changeset
171 static inline uint##x##_t unaligned##x##(const void *v) { \
cb356bfc7e22 add unaligned16() and unaligned64()
mru
parents: 3244
diff changeset
172 return *(const uint##x##_t *) v; \
193
b691dd3e9088 aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents: 192
diff changeset
173 }
708
1aa1cbb8c3c1 indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents: 706
diff changeset
174 # endif
3302
cb356bfc7e22 add unaligned16() and unaligned64()
mru
parents: 3244
diff changeset
175 unaligned(16)
cb356bfc7e22 add unaligned16() and unaligned64()
mru
parents: 3244
diff changeset
176 unaligned(32)
cb356bfc7e22 add unaligned16() and unaligned64()
mru
parents: 3244
diff changeset
177 unaligned(64)
cb356bfc7e22 add unaligned16() and unaligned64()
mru
parents: 3244
diff changeset
178 #undef unaligned
193
b691dd3e9088 aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents: 192
diff changeset
179 #endif //!ARCH_X86
b691dd3e9088 aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents: 192
diff changeset
180
238
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
181 #ifndef ALT_BITSTREAM_WRITER
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
182 static inline void put_bits(PutBitContext *s, int n, unsigned int value)
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
183 {
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
184 unsigned int bit_buf;
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
185 int bit_left;
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
186
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
187 // printf("put_bits=%d %x\n", n, value);
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
188 assert(n == 32 || value < (1U << n));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2894
diff changeset
189
238
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
190 bit_buf = s->bit_buf;
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
191 bit_left = s->bit_left;
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
192
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
193 // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf);
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
194 /* XXX: optimize */
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
195 if (n < bit_left) {
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
196 bit_buf = (bit_buf<<n) | value;
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
197 bit_left-=n;
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
198 } else {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
199 bit_buf<<=bit_left;
238
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
200 bit_buf |= value >> (n - bit_left);
891
d3fc77a6d57e Add some rudimentary support for sparc64
philipjsg
parents: 880
diff changeset
201 #ifdef UNALIGNED_STORES_ARE_BAD
1965
f74f306c30b5 vis detection patch by (James Morrison <ja2morri at csclub dot uwaterloo dot ca>)
michael
parents: 1964
diff changeset
202 if (3 & (intptr_t) s->buf_ptr) {
891
d3fc77a6d57e Add some rudimentary support for sparc64
philipjsg
parents: 880
diff changeset
203 s->buf_ptr[0] = bit_buf >> 24;
d3fc77a6d57e Add some rudimentary support for sparc64
philipjsg
parents: 880
diff changeset
204 s->buf_ptr[1] = bit_buf >> 16;
d3fc77a6d57e Add some rudimentary support for sparc64
philipjsg
parents: 880
diff changeset
205 s->buf_ptr[2] = bit_buf >> 8;
d3fc77a6d57e Add some rudimentary support for sparc64
philipjsg
parents: 880
diff changeset
206 s->buf_ptr[3] = bit_buf ;
d3fc77a6d57e Add some rudimentary support for sparc64
philipjsg
parents: 880
diff changeset
207 } else
d3fc77a6d57e Add some rudimentary support for sparc64
philipjsg
parents: 880
diff changeset
208 #endif
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1059
diff changeset
209 *(uint32_t *)s->buf_ptr = be2me_32(bit_buf);
238
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
210 //printf("bitbuf = %08x\n", bit_buf);
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
211 s->buf_ptr+=4;
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
212 bit_left+=32 - n;
238
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
213 bit_buf = value;
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
214 }
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
215
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
216 s->bit_buf = bit_buf;
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
217 s->bit_left = bit_left;
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
218 }
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
219 #endif
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
220
99a9f903f0e3 optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents: 235
diff changeset
221
234
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
222 #ifdef ALT_BITSTREAM_WRITER
235
41f0ef2cd942 aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents: 234
diff changeset
223 static inline void put_bits(PutBitContext *s, int n, unsigned int value)
234
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
224 {
708
1aa1cbb8c3c1 indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents: 706
diff changeset
225 # ifdef ALIGNED_BITSTREAM_WRITER
2293
15cfba1b97b5 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2288
diff changeset
226 # if defined(ARCH_X86) || defined(ARCH_X86_64)
235
41f0ef2cd942 aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents: 234
diff changeset
227 asm volatile(
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
228 "movl %0, %%ecx \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
229 "xorl %%eax, %%eax \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
230 "shrdl %%cl, %1, %%eax \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
231 "shrl %%cl, %1 \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
232 "movl %0, %%ecx \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
233 "shrl $3, %%ecx \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
234 "andl $0xFFFFFFFC, %%ecx \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
235 "bswapl %1 \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
236 "orl %1, (%2, %%ecx) \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
237 "bswapl %%eax \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
238 "addl %3, %0 \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
239 "movl %%eax, 4(%2, %%ecx) \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
240 : "=&r" (s->index), "=&r" (value)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
241 : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n))
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
242 : "%eax", "%ecx"
235
41f0ef2cd942 aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents: 234
diff changeset
243 );
708
1aa1cbb8c3c1 indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents: 706
diff changeset
244 # else
235
41f0ef2cd942 aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents: 234
diff changeset
245 int index= s->index;
41f0ef2cd942 aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents: 234
diff changeset
246 uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2894
diff changeset
247
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2894
diff changeset
248 value<<= 32-n;
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2894
diff changeset
249
235
41f0ef2cd942 aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents: 234
diff changeset
250 ptr[0] |= be2me_32(value>>(index&31));
41f0ef2cd942 aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents: 234
diff changeset
251 ptr[1] = be2me_32(value<<(32-(index&31)));
41f0ef2cd942 aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents: 234
diff changeset
252 //if(n>24) printf("%d %d\n", n, value);
41f0ef2cd942 aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents: 234
diff changeset
253 index+= n;
41f0ef2cd942 aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents: 234
diff changeset
254 s->index= index;
708
1aa1cbb8c3c1 indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents: 706
diff changeset
255 # endif
1aa1cbb8c3c1 indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents: 706
diff changeset
256 # else //ALIGNED_BITSTREAM_WRITER
2293
15cfba1b97b5 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2288
diff changeset
257 # if defined(ARCH_X86) || defined(ARCH_X86_64)
234
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
258 asm volatile(
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
259 "movl $7, %%ecx \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
260 "andl %0, %%ecx \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
261 "addl %3, %%ecx \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
262 "negl %%ecx \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
263 "shll %%cl, %1 \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
264 "bswapl %1 \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
265 "movl %0, %%ecx \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
266 "shrl $3, %%ecx \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
267 "orl %1, (%%ecx, %2) \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
268 "addl %3, %0 \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
269 "movl $0, 4(%%ecx, %2) \n\t"
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
270 : "=&r" (s->index), "=&r" (value)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
271 : "r" (s->buf), "r" (n), "0" (s->index), "1" (value)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
272 : "%ecx"
234
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
273 );
708
1aa1cbb8c3c1 indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents: 706
diff changeset
274 # else
234
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
275 int index= s->index;
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
276 uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2894
diff changeset
277
234
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
278 ptr[0] |= be2me_32(value<<(32-n-(index&7) ));
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
279 ptr[1] = 0;
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
280 //if(n>24) printf("%d %d\n", n, value);
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
281 index+= n;
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
282 s->index= index;
708
1aa1cbb8c3c1 indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents: 706
diff changeset
283 # endif
1aa1cbb8c3c1 indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents: 706
diff changeset
284 # endif //!ALIGNED_BITSTREAM_WRITER
234
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
285 }
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
286 #endif
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
287
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
288
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
289 static inline uint8_t* pbBufPtr(PutBitContext *s)
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
290 {
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
291 #ifdef ALT_BITSTREAM_WRITER
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
292 return s->buf + (s->index>>3);
234
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
293 #else
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
294 return s->buf_ptr;
234
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
295 #endif
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
296 }
5fc0c3af3fe4 alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents: 213
diff changeset
297
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1795
diff changeset
298 /**
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1795
diff changeset
299 *
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1795
diff changeset
300 * PutBitContext must be flushed & aligned to a byte boundary before calling this.
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1795
diff changeset
301 */
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1795
diff changeset
302 static inline void skip_put_bytes(PutBitContext *s, int n){
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1795
diff changeset
303 assert((put_bits_count(s)&7)==0);
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1795
diff changeset
304 #ifdef ALT_BITSTREAM_WRITER
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1795
diff changeset
305 FIXME may need some cleaning of the buffer
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
306 s->index += n<<3;
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1795
diff changeset
307 #else
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1795
diff changeset
308 assert(s->bit_left==32);
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
309 s->buf_ptr += n;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2894
diff changeset
310 #endif
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1795
diff changeset
311 }
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1795
diff changeset
312
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1795
diff changeset
313 /**
2502
f5fe61bd08ac support skiping some bitstream encoding
michael
parents: 2467
diff changeset
314 * skips the given number of bits.
f5fe61bd08ac support skiping some bitstream encoding
michael
parents: 2467
diff changeset
315 * must only be used if the actual values in the bitstream dont matter
f5fe61bd08ac support skiping some bitstream encoding
michael
parents: 2467
diff changeset
316 */
f5fe61bd08ac support skiping some bitstream encoding
michael
parents: 2467
diff changeset
317 static inline void skip_put_bits(PutBitContext *s, int n){
f5fe61bd08ac support skiping some bitstream encoding
michael
parents: 2467
diff changeset
318 #ifdef ALT_BITSTREAM_WRITER
f5fe61bd08ac support skiping some bitstream encoding
michael
parents: 2467
diff changeset
319 s->index += n;
f5fe61bd08ac support skiping some bitstream encoding
michael
parents: 2467
diff changeset
320 #else
f5fe61bd08ac support skiping some bitstream encoding
michael
parents: 2467
diff changeset
321 s->bit_left -= n;
f5fe61bd08ac support skiping some bitstream encoding
michael
parents: 2467
diff changeset
322 s->buf_ptr-= s->bit_left>>5;
f5fe61bd08ac support skiping some bitstream encoding
michael
parents: 2467
diff changeset
323 s->bit_left &= 31;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2894
diff changeset
324 #endif
2502
f5fe61bd08ac support skiping some bitstream encoding
michael
parents: 2467
diff changeset
325 }
f5fe61bd08ac support skiping some bitstream encoding
michael
parents: 2467
diff changeset
326
f5fe61bd08ac support skiping some bitstream encoding
michael
parents: 2467
diff changeset
327 /**
1799
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1795
diff changeset
328 * Changes the end of the buffer.
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1795
diff changeset
329 */
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1795
diff changeset
330 static inline void set_put_bits_buffer_size(PutBitContext *s, int size){
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1795
diff changeset
331 s->buf_end= s->buf + size;
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1795
diff changeset
332 }
95612d423fde multithreaded/SMP motion estimation
michael
parents: 1795
diff changeset
333
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
334 /* Bitstream reader API docs:
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
335 name
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
336 abritary name which is used as prefix for the internal variables
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
337
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
338 gb
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
339 getbitcontext
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
340
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
341 OPEN_READER(name, gb)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
342 loads gb into local variables
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
343
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
344 CLOSE_READER(name, gb)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
345 stores local vars in gb
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
346
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
347 UPDATE_CACHE(name, gb)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
348 refills the internal cache from the bitstream
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
349 after this call at least MIN_CACHE_BITS will be available,
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
350
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
351 GET_CACHE(name, gb)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
352 will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
353
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
354 SHOW_UBITS(name, gb, num)
2764
2b37bcabe608 spelling fixes
diego
parents: 2672
diff changeset
355 will return the next num bits
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
356
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
357 SHOW_SBITS(name, gb, num)
2764
2b37bcabe608 spelling fixes
diego
parents: 2672
diff changeset
358 will return the next num bits and do sign extension
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
359
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
360 SKIP_BITS(name, gb, num)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
361 will skip over the next num bits
2764
2b37bcabe608 spelling fixes
diego
parents: 2672
diff changeset
362 note, this is equivalent to SKIP_CACHE; SKIP_COUNTER
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
363
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
364 SKIP_CACHE(name, gb, num)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
365 will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
366
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
367 SKIP_COUNTER(name, gb, num)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
368 will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
369
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
370 LAST_SKIP_CACHE(name, gb, num)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
371 will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
372
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
373 LAST_SKIP_BITS(name, gb, num)
2764
2b37bcabe608 spelling fixes
diego
parents: 2672
diff changeset
374 is equivalent to SKIP_LAST_CACHE; SKIP_COUNTER
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
375
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
376 for examples see get_bits, show_bits, skip_bits, get_vlc
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
377 */
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
378
1254
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
379 static inline int unaligned32_be(const void *v)
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
380 {
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
381 #ifdef CONFIG_ALIGN
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
382 const uint8_t *p=v;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
383 return (((p[0]<<8) | p[1])<<16) | (p[2]<<8) | (p[3]);
1254
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
384 #else
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
385 return be2me_32( unaligned32(v)); //original
1254
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
386 #endif
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
387 }
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
388
2663
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
389 static inline int unaligned32_le(const void *v)
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
390 {
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
391 #ifdef CONFIG_ALIGN
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
392 const uint8_t *p=v;
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
393 return (((p[3]<<8) | p[2])<<16) | (p[1]<<8) | (p[0]);
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
394 #else
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
395 return le2me_32( unaligned32(v)); //original
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
396 #endif
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
397 }
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
398
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
399 #ifdef ALT_BITSTREAM_READER
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
400 # define MIN_CACHE_BITS 25
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
401
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
402 # define OPEN_READER(name, gb)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
403 int name##_index= (gb)->index;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
404 int name##_cache= 0;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
405
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
406 # define CLOSE_READER(name, gb)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
407 (gb)->index= name##_index;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
408
2663
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
409 # ifdef ALT_BITSTREAM_READER_LE
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
410 # define UPDATE_CACHE(name, gb)\
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
411 name##_cache= unaligned32_le( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
412
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
413 # define SKIP_CACHE(name, gb, num)\
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
414 name##_cache >>= (num);
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
415 # else
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
416 # define UPDATE_CACHE(name, gb)\
2288
3d4a1f8e6a27 * fixing a few of gcc 'clean-code' warnings
kabi
parents: 2140
diff changeset
417 name##_cache= unaligned32_be( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
418
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
419 # define SKIP_CACHE(name, gb, num)\
2663
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
420 name##_cache <<= (num);
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
421 # endif
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
422
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
423 // FIXME name?
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
424 # define SKIP_COUNTER(name, gb, num)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
425 name##_index += (num);\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
426
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
427 # define SKIP_BITS(name, gb, num)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
428 {\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
429 SKIP_CACHE(name, gb, num)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
430 SKIP_COUNTER(name, gb, num)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
431 }\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
432
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
433 # define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
434 # define LAST_SKIP_CACHE(name, gb, num) ;
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
435
2663
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
436 # ifdef ALT_BITSTREAM_READER_LE
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
437 # define SHOW_UBITS(name, gb, num)\
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
438 ((name##_cache) & (NEG_USR32(0xffffffff,num)))
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
439 # else
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
440 # define SHOW_UBITS(name, gb, num)\
525
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
441 NEG_USR32(name##_cache, num)
2663
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
442 # endif
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
443
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
444 # define SHOW_SBITS(name, gb, num)\
525
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
445 NEG_SSR32(name##_cache, num)
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
446
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
447 # define GET_CACHE(name, gb)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
448 ((uint32_t)name##_cache)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
449
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
450 static inline int get_bits_count(GetBitContext *s){
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
451 return s->index;
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
452 }
3629
2ab6ec6259b1 move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents: 3628
diff changeset
453
2ab6ec6259b1 move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents: 3628
diff changeset
454 static inline void skip_bits_long(GetBitContext *s, int n){
3633
f9660d3a9975 2nd try of skip_bits_long() for the ALT reader
michael
parents: 3632
diff changeset
455 s->index += n;
3629
2ab6ec6259b1 move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents: 3628
diff changeset
456 }
2ab6ec6259b1 move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents: 3628
diff changeset
457
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
458 #elif defined LIBMPEG2_BITSTREAM_READER
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
459 //libmpeg2 like reader
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
460
1263
9fce515e9894 libmpeg2 style bitstream reader 17 vs 16 bit bugfix
michaelni
parents: 1261
diff changeset
461 # define MIN_CACHE_BITS 17
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
462
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
463 # define OPEN_READER(name, gb)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
464 int name##_bit_count=(gb)->bit_count;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
465 int name##_cache= (gb)->cache;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
466 uint8_t * name##_buffer_ptr=(gb)->buffer_ptr;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
467
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
468 # define CLOSE_READER(name, gb)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
469 (gb)->bit_count= name##_bit_count;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
470 (gb)->cache= name##_cache;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
471 (gb)->buffer_ptr= name##_buffer_ptr;\
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
472
1254
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
473 #ifdef LIBMPEG2_BITSTREAM_READER_HACK
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
474
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
475 # define UPDATE_CACHE(name, gb)\
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
476 if(name##_bit_count >= 0){\
1257
6defe392d5d2 libmpeg2 style bitstream reader fixes
michaelni
parents: 1254
diff changeset
477 name##_cache+= (int)be2me_16(*(uint16_t*)name##_buffer_ptr) << name##_bit_count;\
2614
5e24800ab329 various fixes related to the non alt_bitstream_reader
michael
parents: 2578
diff changeset
478 name##_buffer_ptr += 2;\
1254
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
479 name##_bit_count-= 16;\
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
480 }\
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
481
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
482 #else
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
483
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
484 # define UPDATE_CACHE(name, gb)\
1263
9fce515e9894 libmpeg2 style bitstream reader 17 vs 16 bit bugfix
michaelni
parents: 1261
diff changeset
485 if(name##_bit_count >= 0){\
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
486 name##_cache+= ((name##_buffer_ptr[0]<<8) + name##_buffer_ptr[1]) << name##_bit_count;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
487 name##_buffer_ptr+=2;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
488 name##_bit_count-= 16;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
489 }\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
490
1254
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
491 #endif
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
492
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
493 # define SKIP_CACHE(name, gb, num)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
494 name##_cache <<= (num);\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
495
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
496 # define SKIP_COUNTER(name, gb, num)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
497 name##_bit_count += (num);\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
498
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
499 # define SKIP_BITS(name, gb, num)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
500 {\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
501 SKIP_CACHE(name, gb, num)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
502 SKIP_COUNTER(name, gb, num)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
503 }\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
504
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
505 # define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
506 # define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
507
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
508 # define SHOW_UBITS(name, gb, num)\
525
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
509 NEG_USR32(name##_cache, num)
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
510
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
511 # define SHOW_SBITS(name, gb, num)\
525
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
512 NEG_SSR32(name##_cache, num)
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
513
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
514 # define GET_CACHE(name, gb)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
515 ((uint32_t)name##_cache)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
516
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
517 static inline int get_bits_count(GetBitContext *s){
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
518 return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count;
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
519 }
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
520
3633
f9660d3a9975 2nd try of skip_bits_long() for the ALT reader
michael
parents: 3632
diff changeset
521 static inline void skip_bits_long(GetBitContext *s, int n){
f9660d3a9975 2nd try of skip_bits_long() for the ALT reader
michael
parents: 3632
diff changeset
522 OPEN_READER(re, s)
f9660d3a9975 2nd try of skip_bits_long() for the ALT reader
michael
parents: 3632
diff changeset
523 re_bit_count += n;
f9660d3a9975 2nd try of skip_bits_long() for the ALT reader
michael
parents: 3632
diff changeset
524 re_buffer_ptr += 2*(re_bit_count>>4);
f9660d3a9975 2nd try of skip_bits_long() for the ALT reader
michael
parents: 3632
diff changeset
525 re_bit_count &= 15;
f9660d3a9975 2nd try of skip_bits_long() for the ALT reader
michael
parents: 3632
diff changeset
526 re_cache = ((re_buffer_ptr[-2]<<8) + re_buffer_ptr[-1]) << (16+re_bit_count);
f9660d3a9975 2nd try of skip_bits_long() for the ALT reader
michael
parents: 3632
diff changeset
527 UPDATE_CACHE(re, s)
f9660d3a9975 2nd try of skip_bits_long() for the ALT reader
michael
parents: 3632
diff changeset
528 CLOSE_READER(re, s)
f9660d3a9975 2nd try of skip_bits_long() for the ALT reader
michael
parents: 3632
diff changeset
529 }
f9660d3a9975 2nd try of skip_bits_long() for the ALT reader
michael
parents: 3632
diff changeset
530
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
531 #elif defined A32_BITSTREAM_READER
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
532
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
533 # define MIN_CACHE_BITS 32
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
534
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
535 # define OPEN_READER(name, gb)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
536 int name##_bit_count=(gb)->bit_count;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
537 uint32_t name##_cache0= (gb)->cache0;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
538 uint32_t name##_cache1= (gb)->cache1;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
539 uint32_t * name##_buffer_ptr=(gb)->buffer_ptr;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
540
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
541 # define CLOSE_READER(name, gb)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
542 (gb)->bit_count= name##_bit_count;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
543 (gb)->cache0= name##_cache0;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
544 (gb)->cache1= name##_cache1;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
545 (gb)->buffer_ptr= name##_buffer_ptr;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
546
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
547 # define UPDATE_CACHE(name, gb)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
548 if(name##_bit_count > 0){\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
549 const uint32_t next= be2me_32( *name##_buffer_ptr );\
525
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
550 name##_cache0 |= NEG_USR32(next,name##_bit_count);\
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
551 name##_cache1 |= next<<name##_bit_count;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
552 name##_buffer_ptr++;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
553 name##_bit_count-= 32;\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
554 }\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
555
2293
15cfba1b97b5 adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents: 2288
diff changeset
556 #if defined(ARCH_X86) || defined(ARCH_X86_64)
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
557 # define SKIP_CACHE(name, gb, num)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
558 asm(\
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
559 "shldl %2, %1, %0 \n\t"\
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
560 "shll %2, %1 \n\t"\
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
561 : "+r" (name##_cache0), "+r" (name##_cache1)\
3638
62b3b622f798 Fix A32_BITSTREAM_READER compilation on x86
aurel
parents: 3633
diff changeset
562 : "Ic" ((uint8_t)(num))\
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
563 );
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
564 #else
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
565 # define SKIP_CACHE(name, gb, num)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
566 name##_cache0 <<= (num);\
525
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
567 name##_cache0 |= NEG_USR32(name##_cache1,num);\
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
568 name##_cache1 <<= (num);
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
569 #endif
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
570
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
571 # define SKIP_COUNTER(name, gb, num)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
572 name##_bit_count += (num);\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
573
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
574 # define SKIP_BITS(name, gb, num)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
575 {\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
576 SKIP_CACHE(name, gb, num)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
577 SKIP_COUNTER(name, gb, num)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
578 }\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
579
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
580 # define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
581 # define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
582
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
583 # define SHOW_UBITS(name, gb, num)\
525
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
584 NEG_USR32(name##_cache0, num)
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
585
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
586 # define SHOW_SBITS(name, gb, num)\
525
985187bc2fa3 c std doesnt like negative shifts -> use asm
michaelni
parents: 522
diff changeset
587 NEG_SSR32(name##_cache0, num)
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
588
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
589 # define GET_CACHE(name, gb)\
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
590 (name##_cache0)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
591
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
592 static inline int get_bits_count(GetBitContext *s){
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
593 return ((uint8_t*)s->buffer_ptr - s->buffer)*8 - 32 + s->bit_count;
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
594 }
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
595
3629
2ab6ec6259b1 move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents: 3628
diff changeset
596 static inline void skip_bits_long(GetBitContext *s, int n){
2ab6ec6259b1 move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents: 3628
diff changeset
597 OPEN_READER(re, s)
2ab6ec6259b1 move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents: 3628
diff changeset
598 re_bit_count += n;
3631
40f753fc46a4 3rd try :)
michael
parents: 3630
diff changeset
599 re_buffer_ptr += re_bit_count>>5;
3629
2ab6ec6259b1 move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents: 3628
diff changeset
600 re_bit_count &= 31;
3630
8e284a5ec5e1 2nd try for a skip_bits_long() for the A32 reader
michael
parents: 3629
diff changeset
601 re_cache0 = be2me_32( re_buffer_ptr[-1] ) << re_bit_count;
8e284a5ec5e1 2nd try for a skip_bits_long() for the A32 reader
michael
parents: 3629
diff changeset
602 re_cache1 = 0;
3629
2ab6ec6259b1 move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents: 3628
diff changeset
603 UPDATE_CACHE(re, s)
2ab6ec6259b1 move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents: 3628
diff changeset
604 CLOSE_READER(re, s)
2ab6ec6259b1 move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents: 3628
diff changeset
605 }
2ab6ec6259b1 move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents: 3628
diff changeset
606
192
1e5f64be86fc another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents: 151
diff changeset
607 #endif
20
907b67420d84 inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents: 10
diff changeset
608
1257
6defe392d5d2 libmpeg2 style bitstream reader fixes
michaelni
parents: 1254
diff changeset
609 /**
6defe392d5d2 libmpeg2 style bitstream reader fixes
michaelni
parents: 1254
diff changeset
610 * read mpeg1 dc style vlc (sign bit + mantisse with no MSB).
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2894
diff changeset
611 * if MSB not set it is negative
1257
6defe392d5d2 libmpeg2 style bitstream reader fixes
michaelni
parents: 1254
diff changeset
612 * @param n length in bits
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2894
diff changeset
613 * @author BERO
1257
6defe392d5d2 libmpeg2 style bitstream reader fixes
michaelni
parents: 1254
diff changeset
614 */
1254
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
615 static inline int get_xbits(GetBitContext *s, int n){
3244
b9a0ca749833 get_xbits() optimization
michael
parents: 3024
diff changeset
616 register int sign;
1254
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
617 register int32_t cache;
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
618 OPEN_READER(re, s)
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
619 UPDATE_CACHE(re, s)
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
620 cache = GET_CACHE(re,s);
3244
b9a0ca749833 get_xbits() optimization
michael
parents: 3024
diff changeset
621 sign=(~cache)>>31;
1254
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
622 LAST_SKIP_BITS(re, s, n)
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
623 CLOSE_READER(re, s)
3244
b9a0ca749833 get_xbits() optimization
michael
parents: 3024
diff changeset
624 return (NEG_USR32(sign ^ cache, n) ^ sign) - sign;
1254
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
625 }
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
626
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
627 static inline int get_sbits(GetBitContext *s, int n){
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
628 register int tmp;
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
629 OPEN_READER(re, s)
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
630 UPDATE_CACHE(re, s)
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
631 tmp= SHOW_SBITS(re, s, n);
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
632 LAST_SKIP_BITS(re, s, n)
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
633 CLOSE_READER(re, s)
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
634 return tmp;
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
635 }
604661d34c68 bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents: 1226
diff changeset
636
1257
6defe392d5d2 libmpeg2 style bitstream reader fixes
michaelni
parents: 1254
diff changeset
637 /**
6defe392d5d2 libmpeg2 style bitstream reader fixes
michaelni
parents: 1254
diff changeset
638 * reads 0-17 bits.
2764
2b37bcabe608 spelling fixes
diego
parents: 2672
diff changeset
639 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
1257
6defe392d5d2 libmpeg2 style bitstream reader fixes
michaelni
parents: 1254
diff changeset
640 */
20
907b67420d84 inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents: 10
diff changeset
641 static inline unsigned int get_bits(GetBitContext *s, int n){
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
642 register int tmp;
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
643 OPEN_READER(re, s)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
644 UPDATE_CACHE(re, s)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
645 tmp= SHOW_UBITS(re, s, n);
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
646 LAST_SKIP_BITS(re, s, n)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
647 CLOSE_READER(re, s)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
648 return tmp;
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
649 }
192
1e5f64be86fc another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents: 151
diff changeset
650
1257
6defe392d5d2 libmpeg2 style bitstream reader fixes
michaelni
parents: 1254
diff changeset
651 /**
6defe392d5d2 libmpeg2 style bitstream reader fixes
michaelni
parents: 1254
diff changeset
652 * shows 0-17 bits.
2764
2b37bcabe608 spelling fixes
diego
parents: 2672
diff changeset
653 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't
1257
6defe392d5d2 libmpeg2 style bitstream reader fixes
michaelni
parents: 1254
diff changeset
654 */
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
655 static inline unsigned int show_bits(GetBitContext *s, int n){
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
656 register int tmp;
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
657 OPEN_READER(re, s)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
658 UPDATE_CACHE(re, s)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
659 tmp= SHOW_UBITS(re, s, n);
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
660 // CLOSE_READER(re, s)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
661 return tmp;
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
662 }
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
663
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
664 static inline void skip_bits(GetBitContext *s, int n){
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
665 //Note gcc seems to optimize this to s->index+=n for the ALT_READER :))
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
666 OPEN_READER(re, s)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
667 UPDATE_CACHE(re, s)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
668 LAST_SKIP_BITS(re, s, n)
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
669 CLOSE_READER(re, s)
20
907b67420d84 inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents: 10
diff changeset
670 }
907b67420d84 inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents: 10
diff changeset
671
21
20e680e7a490 get_bits() specialization, gives 4\speedup
arpi_esp
parents: 20
diff changeset
672 static inline unsigned int get_bits1(GetBitContext *s){
192
1e5f64be86fc another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents: 151
diff changeset
673 #ifdef ALT_BITSTREAM_READER
1e5f64be86fc another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents: 151
diff changeset
674 int index= s->index;
193
b691dd3e9088 aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents: 192
diff changeset
675 uint8_t result= s->buffer[ index>>3 ];
2663
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
676 #ifdef ALT_BITSTREAM_READER_LE
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
677 result>>= (index&0x07);
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
678 result&= 1;
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
679 #else
199
0f1dba8fc617 (commited by michael / arpi was crazy enough to give me his password)
arpi_esp
parents: 193
diff changeset
680 result<<= (index&0x07);
0f1dba8fc617 (commited by michael / arpi was crazy enough to give me his password)
arpi_esp
parents: 193
diff changeset
681 result>>= 8 - 1;
2663
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
682 #endif
192
1e5f64be86fc another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents: 151
diff changeset
683 index++;
1e5f64be86fc another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents: 151
diff changeset
684 s->index= index;
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
685
192
1e5f64be86fc another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents: 151
diff changeset
686 return result;
1e5f64be86fc another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents: 151
diff changeset
687 #else
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
688 return get_bits(s, 1);
192
1e5f64be86fc another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents: 151
diff changeset
689 #endif
21
20e680e7a490 get_bits() specialization, gives 4\speedup
arpi_esp
parents: 20
diff changeset
690 }
20e680e7a490 get_bits() specialization, gives 4\speedup
arpi_esp
parents: 20
diff changeset
691
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
692 static inline unsigned int show_bits1(GetBitContext *s){
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
693 return show_bits(s, 1);
21
20e680e7a490 get_bits() specialization, gives 4\speedup
arpi_esp
parents: 20
diff changeset
694 }
20e680e7a490 get_bits() specialization, gives 4\speedup
arpi_esp
parents: 20
diff changeset
695
20e680e7a490 get_bits() specialization, gives 4\speedup
arpi_esp
parents: 20
diff changeset
696 static inline void skip_bits1(GetBitContext *s){
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 517
diff changeset
697 skip_bits(s, 1);
21
20e680e7a490 get_bits() specialization, gives 4\speedup
arpi_esp
parents: 20
diff changeset
698 }
20e680e7a490 get_bits() specialization, gives 4\speedup
arpi_esp
parents: 20
diff changeset
699
1875
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
700 /**
3648
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
701 * reads 0-32 bits.
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
702 */
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
703 static inline unsigned int get_bits_long(GetBitContext *s, int n){
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
704 if(n<=17) return get_bits(s, n);
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
705 else{
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
706 int ret= get_bits(s, 16) << (n-16);
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
707 return ret | get_bits(s, n-16);
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
708 }
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
709 }
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
710
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
711 /**
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
712 * shows 0-32 bits.
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
713 */
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
714 static inline unsigned int show_bits_long(GetBitContext *s, int n){
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
715 if(n<=17) return show_bits(s, n);
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
716 else{
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
717 GetBitContext gb= *s;
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
718 int ret= get_bits_long(s, n);
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
719 *s= gb;
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
720 return ret;
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
721 }
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
722 }
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
723
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
724 static inline int check_marker(GetBitContext *s, const char *msg)
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
725 {
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
726 int bit= get_bits1(s);
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
727 if(!bit)
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
728 av_log(NULL, AV_LOG_INFO, "Marker bit missing %s\n", msg);
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
729
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
730 return bit;
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
731 }
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
732
c44d798b06b5 move some functions to bitstream.h to avoid conflicts
aurel
parents: 3638
diff changeset
733 /**
1875
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
734 * init GetBitContext.
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
735 * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
736 * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
737 * @param bit_size the size of the buffer in bits
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
738 */
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
739 static inline void init_get_bits(GetBitContext *s,
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
740 const uint8_t *buffer, int bit_size)
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
741 {
2889
64231191674b precautionary checks
michael
parents: 2885
diff changeset
742 int buffer_size= (bit_size+7)>>3;
2894
26f8974c3d66 fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents: 2889
diff changeset
743 if(buffer_size < 0 || bit_size < 0) {
26f8974c3d66 fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents: 2889
diff changeset
744 buffer_size = bit_size = 0;
26f8974c3d66 fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents: 2889
diff changeset
745 buffer = NULL;
26f8974c3d66 fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents: 2889
diff changeset
746 }
1875
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
747
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
748 s->buffer= buffer;
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
749 s->size_in_bits= bit_size;
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
750 s->buffer_end= buffer + buffer_size;
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
751 #ifdef ALT_BITSTREAM_READER
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
752 s->index=0;
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
753 #elif defined LIBMPEG2_BITSTREAM_READER
3633
f9660d3a9975 2nd try of skip_bits_long() for the ALT reader
michael
parents: 3632
diff changeset
754 s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1));
f9660d3a9975 2nd try of skip_bits_long() for the ALT reader
michael
parents: 3632
diff changeset
755 s->bit_count = 16 + 8*((intptr_t)buffer&1);
f9660d3a9975 2nd try of skip_bits_long() for the ALT reader
michael
parents: 3632
diff changeset
756 skip_bits_long(s, 0);
3632
25ceb2cc950d make A32 reader align its ptr during init no matter what missaligned mess is given to it
michael
parents: 3631
diff changeset
757 #elif defined A32_BITSTREAM_READER
25ceb2cc950d make A32 reader align its ptr during init no matter what missaligned mess is given to it
michael
parents: 3631
diff changeset
758 s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3));
25ceb2cc950d make A32 reader align its ptr during init no matter what missaligned mess is given to it
michael
parents: 3631
diff changeset
759 s->bit_count = 32 + 8*((intptr_t)buffer&3);
25ceb2cc950d make A32 reader align its ptr during init no matter what missaligned mess is given to it
michael
parents: 3631
diff changeset
760 skip_bits_long(s, 0);
1875
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
761 #endif
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
762 }
45a1592dadca * moving some of the commonly used bit reading/writing functions
romansh
parents: 1845
diff changeset
763
3629
2ab6ec6259b1 move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents: 3628
diff changeset
764 static void align_get_bits(GetBitContext *s)
2ab6ec6259b1 move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents: 3628
diff changeset
765 {
2ab6ec6259b1 move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents: 3628
diff changeset
766 int n= (-get_bits_count(s)) & 7;
2ab6ec6259b1 move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents: 3628
diff changeset
767 if(n) skip_bits(s, n);
2ab6ec6259b1 move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents: 3628
diff changeset
768 }
2ab6ec6259b1 move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents: 3628
diff changeset
769
862
058194d7ade6 * fixing some minor const warnings
kabi
parents: 847
diff changeset
770 int check_marker(GetBitContext *s, const char *msg);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
771 int init_vlc(VLC *vlc, int nb_bits, int nb_codes,
986e461dc072 Initial revision
glantau
parents:
diff changeset
772 const void *bits, int bits_wrap, int bits_size,
2370
26560d4fdb1f Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents: 2318
diff changeset
773 const void *codes, int codes_wrap, int codes_size,
2663
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
774 int flags);
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
775 #define INIT_VLC_USE_STATIC 1
b33be8b00488 LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents: 2615
diff changeset
776 #define INIT_VLC_LE 2
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
777 void free_vlc(VLC *vlc);
986e461dc072 Initial revision
glantau
parents:
diff changeset
778
1025
1f9afd8b9131 GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents: 994
diff changeset
779 /**
1f9afd8b9131 GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents: 994
diff changeset
780 *
1f9afd8b9131 GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents: 994
diff changeset
781 * if the vlc code is invalid and max_depth=1 than no bits will be removed
1f9afd8b9131 GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents: 994
diff changeset
782 * if the vlc code is invalid and max_depth>1 than the number of bits removed
1f9afd8b9131 GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents: 994
diff changeset
783 * is undefined
1f9afd8b9131 GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents: 994
diff changeset
784 */
529
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
785 #define GET_VLC(code, name, gb, table, bits, max_depth)\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
786 {\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
787 int n, index, nb_bits;\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
788 \
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
789 index= SHOW_UBITS(name, gb, bits);\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
790 code = table[index][0];\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
791 n = table[index][1];\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
792 \
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
793 if(max_depth > 1 && n < 0){\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
794 LAST_SKIP_BITS(name, gb, bits)\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
795 UPDATE_CACHE(name, gb)\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
796 \
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
797 nb_bits = -n;\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
798 \
535
7f1b09bb34c6 dont trash table in GET_VLC
michaelni
parents: 534
diff changeset
799 index= SHOW_UBITS(name, gb, nb_bits) + code;\
529
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
800 code = table[index][0];\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
801 n = table[index][1];\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
802 if(max_depth > 2 && n < 0){\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
803 LAST_SKIP_BITS(name, gb, nb_bits)\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
804 UPDATE_CACHE(name, gb)\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
805 \
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
806 nb_bits = -n;\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
807 \
535
7f1b09bb34c6 dont trash table in GET_VLC
michaelni
parents: 534
diff changeset
808 index= SHOW_UBITS(name, gb, nb_bits) + code;\
529
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
809 code = table[index][0];\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
810 n = table[index][1];\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
811 }\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
812 }\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
813 SKIP_BITS(name, gb, n)\
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
814 }
f1f4d3d755f8 get_vlc() optimization
michaelni
parents: 525
diff changeset
815
2615
0d88e3f89379 avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents: 2614
diff changeset
816 #define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\
542
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
817 {\
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
818 int n, index, nb_bits;\
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
819 \
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
820 index= SHOW_UBITS(name, gb, bits);\
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
821 level = table[index].level;\
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
822 n = table[index].len;\
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
823 \
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
824 if(max_depth > 1 && n < 0){\
2615
0d88e3f89379 avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents: 2614
diff changeset
825 SKIP_BITS(name, gb, bits)\
0d88e3f89379 avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents: 2614
diff changeset
826 if(need_update){\
0d88e3f89379 avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents: 2614
diff changeset
827 UPDATE_CACHE(name, gb)\
0d88e3f89379 avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents: 2614
diff changeset
828 }\
542
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
829 \
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
830 nb_bits = -n;\
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
831 \
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
832 index= SHOW_UBITS(name, gb, nb_bits) + level;\
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
833 level = table[index].level;\
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
834 n = table[index].len;\
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
835 }\
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
836 run= table[index].run;\
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
837 SKIP_BITS(name, gb, n)\
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
838 }
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
839
193
b691dd3e9088 aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents: 192
diff changeset
840
1079
89e233c2ef45 get_vlc2() "docs"
michaelni
parents: 1064
diff changeset
841 /**
89e233c2ef45 get_vlc2() "docs"
michaelni
parents: 1064
diff changeset
842 * parses a vlc code, faster then get_vlc()
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2894
diff changeset
843 * @param bits is the number of bits which will be read at once, must be
1079
89e233c2ef45 get_vlc2() "docs"
michaelni
parents: 1064
diff changeset
844 * identical to nb_bits in init_vlc()
89e233c2ef45 get_vlc2() "docs"
michaelni
parents: 1064
diff changeset
845 * @param max_depth is the number of times bits bits must be readed to completly
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2894
diff changeset
846 * read the longest vlc code
1079
89e233c2ef45 get_vlc2() "docs"
michaelni
parents: 1064
diff changeset
847 * = (max_vlc_length + bits - 1) / bits
89e233c2ef45 get_vlc2() "docs"
michaelni
parents: 1064
diff changeset
848 */
550
b746a7d75ce6 Force inlining on get_vlc2.
mellum
parents: 542
diff changeset
849 static always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2],
b746a7d75ce6 Force inlining on get_vlc2.
mellum
parents: 542
diff changeset
850 int bits, int max_depth)
531
f5d7fcc81787 get_vlc() optimizations
michaelni
parents: 529
diff changeset
851 {
f5d7fcc81787 get_vlc() optimizations
michaelni
parents: 529
diff changeset
852 int code;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2894
diff changeset
853
531
f5d7fcc81787 get_vlc() optimizations
michaelni
parents: 529
diff changeset
854 OPEN_READER(re, s)
f5d7fcc81787 get_vlc() optimizations
michaelni
parents: 529
diff changeset
855 UPDATE_CACHE(re, s)
f5d7fcc81787 get_vlc() optimizations
michaelni
parents: 529
diff changeset
856
f5d7fcc81787 get_vlc() optimizations
michaelni
parents: 529
diff changeset
857 GET_VLC(code, re, s, table, bits, max_depth)
f5d7fcc81787 get_vlc() optimizations
michaelni
parents: 529
diff changeset
858
f5d7fcc81787 get_vlc() optimizations
michaelni
parents: 529
diff changeset
859 CLOSE_READER(re, s)
f5d7fcc81787 get_vlc() optimizations
michaelni
parents: 529
diff changeset
860 return code;
f5d7fcc81787 get_vlc() optimizations
michaelni
parents: 529
diff changeset
861 }
f5d7fcc81787 get_vlc() optimizations
michaelni
parents: 529
diff changeset
862
1147
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
863 //#define TRACE
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
864
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
865 #ifdef TRACE
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
866 static inline void print_bin(int bits, int n){
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
867 int i;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2894
diff changeset
868
1147
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
869 for(i=n-1; i>=0; i--){
2438
e98b5e0de86b compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents: 2398
diff changeset
870 av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1);
1147
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
871 }
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
872 for(i=n; i<24; i++)
2438
e98b5e0de86b compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents: 2398
diff changeset
873 av_log(NULL, AV_LOG_DEBUG, " ");
1147
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
874 }
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
875
2438
e98b5e0de86b compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents: 2398
diff changeset
876 static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
1147
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
877 int r= get_bits(s, n);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2894
diff changeset
878
1147
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
879 print_bin(r, n);
2438
e98b5e0de86b compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents: 2398
diff changeset
880 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line);
1147
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
881 return r;
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
882 }
2438
e98b5e0de86b compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents: 2398
diff changeset
883 static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){
1147
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
884 int show= show_bits(s, 24);
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
885 int pos= get_bits_count(s);
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
886 int r= get_vlc2(s, table, bits, max_depth);
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
887 int len= get_bits_count(s) - pos;
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
888 int bits2= show>>(24-len);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2894
diff changeset
889
1147
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
890 print_bin(bits2, len);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2894
diff changeset
891
2438
e98b5e0de86b compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents: 2398
diff changeset
892 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line);
1147
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
893 return r;
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
894 }
2438
e98b5e0de86b compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents: 2398
diff changeset
895 static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){
1273
a979fab41ed8 ASV1 codec
michaelni
parents: 1263
diff changeset
896 int show= show_bits(s, n);
a979fab41ed8 ASV1 codec
michaelni
parents: 1263
diff changeset
897 int r= get_xbits(s, n);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2894
diff changeset
898
1273
a979fab41ed8 ASV1 codec
michaelni
parents: 1263
diff changeset
899 print_bin(show, n);
2438
e98b5e0de86b compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents: 2398
diff changeset
900 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line);
1273
a979fab41ed8 ASV1 codec
michaelni
parents: 1263
diff changeset
901 return r;
a979fab41ed8 ASV1 codec
michaelni
parents: 1263
diff changeset
902 }
1147
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
903
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
904 #define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
905 #define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__)
1273
a979fab41ed8 ASV1 codec
michaelni
parents: 1263
diff changeset
906 #define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__)
1152
michaelni
parents: 1147
diff changeset
907 #define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__)
1147
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
908 #define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__)
dcb20b7598ed bitstream tracing support
michaelni
parents: 1139
diff changeset
909
1940
2511d3e4513e t/dprintf printf -> av_log
michael
parents: 1921
diff changeset
910 #define tprintf(...) av_log(NULL, AV_LOG_DEBUG, __VA_ARGS__)
1170
4710976004a5 #ifdef TRACE printf() -> tprintf()
michaelni
parents: 1152
diff changeset
911
4710976004a5 #ifdef TRACE printf() -> tprintf()
michaelni
parents: 1152
diff changeset
912 #else //TRACE
1824
michael
parents: 1823
diff changeset
913 #define tprintf(...) {}
1170
4710976004a5 #ifdef TRACE printf() -> tprintf()
michaelni
parents: 1152
diff changeset
914 #endif
542
d55978a3c369 rl vlc decoding optimizations
michaelni
parents: 535
diff changeset
915
2467
0b3697268285 make decode012() static inline
michael
parents: 2464
diff changeset
916 static inline int decode012(GetBitContext *gb){
2464
ab390f13c7f5 dont duplicate decode012()
michael
parents: 2438
diff changeset
917 int n;
ab390f13c7f5 dont duplicate decode012()
michael
parents: 2438
diff changeset
918 n = get_bits1(gb);
ab390f13c7f5 dont duplicate decode012()
michael
parents: 2438
diff changeset
919 if (n == 0)
ab390f13c7f5 dont duplicate decode012()
michael
parents: 2438
diff changeset
920 return 0;
ab390f13c7f5 dont duplicate decode012()
michael
parents: 2438
diff changeset
921 else
ab390f13c7f5 dont duplicate decode012()
michael
parents: 2438
diff changeset
922 return get_bits1(gb) + 1;
ab390f13c7f5 dont duplicate decode012()
michael
parents: 2438
diff changeset
923 }
ab390f13c7f5 dont duplicate decode012()
michael
parents: 2438
diff changeset
924
2398
582e635cfa08 common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents: 2391
diff changeset
925 #endif /* BITSTREAM_H */