Mercurial > libavcodec.hg
annotate bitstream.h @ 3036:0b546eab515d libavcodec
Update licensing information: The FSF changed postal address.
author | diego |
---|---|
date | Thu, 12 Jan 2006 22:43:26 +0000 |
parents | 67d3bb5a4ce1 |
children | b9a0ca749833 |
rev | line source |
---|---|
1106 | 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 | 4 */ |
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 | 8 |
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
|
9 //#define ALT_BITSTREAM_WRITER |
235
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
10 //#define ALIGNED_BITSTREAM_WRITER |
512
ba67fefada47
Activate ALT_BITSTREAM_READER by default on Alpha, since it seems to
mellum
parents:
496
diff
changeset
|
11 |
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
|
12 #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
|
13 //#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
|
14 //#define A32_BITSTREAM_READER |
1254
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
15 #define LIBMPEG2_BITSTREAM_READER_HACK //add BERO |
2967 | 16 |
2578 | 17 extern const uint8_t ff_reverse[256]; |
18 | |
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
|
19 #if defined(ARCH_X86) || defined(ARCH_X86_64) |
525 | 20 // avoid +32 for shift optimization (gcc should do that ...) |
21 static inline int32_t NEG_SSR32( int32_t a, int8_t s){ | |
22 asm ("sarl %1, %0\n\t" | |
23 : "+r" (a) | |
24 : "ic" ((uint8_t)(-s)) | |
25 ); | |
26 return a; | |
27 } | |
28 static inline uint32_t NEG_USR32(uint32_t a, int8_t s){ | |
29 asm ("shrl %1, %0\n\t" | |
30 : "+r" (a) | |
31 : "ic" ((uint8_t)(-s)) | |
32 ); | |
33 return a; | |
34 } | |
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
|
35 #else |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
36 # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s))) |
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
37 # 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
|
38 #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
|
39 |
0 | 40 /* bit output */ |
41 | |
1895
e5687117cc7f
* removing casualties of battle of the wits and English language
romansh
parents:
1886
diff
changeset
|
42 /* buf and buf_end must be present and used by every alternative writer. */ |
0 | 43 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
|
44 #ifdef ALT_BITSTREAM_WRITER |
1064 | 45 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
|
46 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
|
47 #else |
1064 | 48 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
|
49 int bit_left; |
1064 | 50 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
|
51 #endif |
0 | 52 } PutBitContext; |
53 | |
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
54 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
|
55 { |
2894
26f8974c3d66
fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents:
2889
diff
changeset
|
56 if(buffer_size < 0) { |
26f8974c3d66
fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents:
2889
diff
changeset
|
57 buffer_size = 0; |
26f8974c3d66
fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents:
2889
diff
changeset
|
58 buffer = NULL; |
26f8974c3d66
fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents:
2889
diff
changeset
|
59 } |
2889 | 60 |
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
61 s->buf = buffer; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
62 s->buf_end = s->buf + buffer_size; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
63 #ifdef ALT_BITSTREAM_WRITER |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
64 s->index=0; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
65 ((uint32_t*)(s->buf))[0]=0; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
66 // memset(buffer, 0, buffer_size); |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
67 #else |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
68 s->buf_ptr = s->buf; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
69 s->bit_left=32; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
70 s->bit_buf=0; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
71 #endif |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
72 } |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
73 |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
74 /* return the number of bits output */ |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
75 static inline int put_bits_count(PutBitContext *s) |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
76 { |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
77 #ifdef ALT_BITSTREAM_WRITER |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
78 return s->index; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
79 #else |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
80 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
|
81 #endif |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
82 } |
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
|
83 |
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
84 /* 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
|
85 static inline void flush_put_bits(PutBitContext *s) |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
86 { |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
87 #ifdef ALT_BITSTREAM_WRITER |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
88 align_put_bits(s); |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
89 #else |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
90 s->bit_buf<<= s->bit_left; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
91 while (s->bit_left < 32) { |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
92 /* XXX: should test end of buffer */ |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
93 *s->buf_ptr++=s->bit_buf >> 24; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
94 s->bit_buf<<=8; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
95 s->bit_left+=8; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
96 } |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
97 s->bit_left=32; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
98 s->bit_buf=0; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
99 #endif |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
100 } |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
101 |
0 | 102 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
|
103 void ff_put_string(PutBitContext * pbc, char *s, int put_zero); |
0 | 104 |
105 /* bit input */ | |
1895
e5687117cc7f
* removing casualties of battle of the wits and English language
romansh
parents:
1886
diff
changeset
|
106 /* buffer, buffer_end and size_in_bits must be present and used by every reader */ |
0 | 107 typedef struct GetBitContext { |
1083 | 108 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
|
109 #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
|
110 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
|
111 #elif defined LIBMPEG2_BITSTREAM_READER |
1064 | 112 uint8_t *buffer_ptr; |
113 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
|
114 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
|
115 #elif defined A32_BITSTREAM_READER |
1064 | 116 uint32_t *buffer_ptr; |
117 uint32_t cache0; | |
118 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
|
119 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
|
120 #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
|
121 int size_in_bits; |
0 | 122 } GetBitContext; |
123 | |
1064 | 124 #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
|
125 |
0 | 126 typedef struct VLC { |
127 int bits; | |
1112
54be6aece1be
more cosmetics so that doxygen output is readable ...
michaelni
parents:
1106
diff
changeset
|
128 VLC_TYPE (*table)[2]; ///< code, bits |
0 | 129 int table_size, table_allocated; |
130 } VLC; | |
131 | |
542 | 132 typedef struct RL_VLC_ELEM { |
133 int16_t level; | |
134 int8_t len; | |
135 uint8_t run; | |
136 } RL_VLC_ELEM; | |
137 | |
2672 | 138 #if defined(ARCH_SPARC) || defined(ARCH_ARMV4L) |
891 | 139 #define UNALIGNED_STORES_ARE_BAD |
140 #endif | |
141 | |
193
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
142 /* 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
|
143 #if defined(ARCH_X86) || defined(ARCH_X86_64) |
2288 | 144 # define unaligned32(a) (*(const uint32_t*)(a)) |
193
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
145 #else |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
146 # ifdef __GNUC__ |
193
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
147 static inline uint32_t unaligned32(const void *v) { |
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
148 struct Unaligned { |
2979 | 149 uint32_t i; |
193
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
150 } __attribute__((packed)); |
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
151 |
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
152 return ((const struct Unaligned *) v)->i; |
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
153 } |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
154 # elif defined(__DECC) |
193
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
155 static inline uint32_t unaligned32(const void *v) { |
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
156 return *(const __unaligned uint32_t *) v; |
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
157 } |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
158 # else |
193
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
159 static inline uint32_t unaligned32(const void *v) { |
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
160 return *(const uint32_t *) v; |
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
161 } |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
162 # endif |
193
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
163 #endif //!ARCH_X86 |
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
164 |
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
|
165 #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
|
166 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
|
167 { |
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
|
168 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
|
169 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
|
170 |
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
|
171 #ifdef STATS |
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
|
172 st_out_bit_counts[st_current_index] += 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
|
173 #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
|
174 // 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
|
175 assert(n == 32 || value < (1U << n)); |
2967 | 176 |
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
|
177 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
|
178 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
|
179 |
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
|
180 // 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
|
181 /* 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
|
182 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
|
183 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
|
184 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
|
185 } else { |
2979 | 186 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
|
187 bit_buf |= value >> (n - bit_left); |
891 | 188 #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
|
189 if (3 & (intptr_t) s->buf_ptr) { |
891 | 190 s->buf_ptr[0] = bit_buf >> 24; |
191 s->buf_ptr[1] = bit_buf >> 16; | |
192 s->buf_ptr[2] = bit_buf >> 8; | |
193 s->buf_ptr[3] = bit_buf ; | |
194 } else | |
195 #endif | |
1064 | 196 *(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
|
197 //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
|
198 s->buf_ptr+=4; |
2979 | 199 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
|
200 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
|
201 } |
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
|
202 |
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
|
203 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
|
204 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
|
205 } |
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
|
206 #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
|
207 |
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
|
208 |
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
|
209 #ifdef ALT_BITSTREAM_WRITER |
235
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
210 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
|
211 { |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
212 # 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
|
213 # 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
|
214 asm volatile( |
2979 | 215 "movl %0, %%ecx \n\t" |
216 "xorl %%eax, %%eax \n\t" | |
217 "shrdl %%cl, %1, %%eax \n\t" | |
218 "shrl %%cl, %1 \n\t" | |
219 "movl %0, %%ecx \n\t" | |
220 "shrl $3, %%ecx \n\t" | |
221 "andl $0xFFFFFFFC, %%ecx \n\t" | |
222 "bswapl %1 \n\t" | |
223 "orl %1, (%2, %%ecx) \n\t" | |
224 "bswapl %%eax \n\t" | |
225 "addl %3, %0 \n\t" | |
226 "movl %%eax, 4(%2, %%ecx) \n\t" | |
227 : "=&r" (s->index), "=&r" (value) | |
228 : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n)) | |
229 : "%eax", "%ecx" | |
235
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
230 ); |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
231 # else |
235
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
232 int index= s->index; |
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
233 uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5); |
2967 | 234 |
235 value<<= 32-n; | |
236 | |
235
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
237 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
|
238 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
|
239 //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
|
240 index+= n; |
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
241 s->index= index; |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
242 # endif |
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
243 # 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
|
244 # 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
|
245 asm volatile( |
2979 | 246 "movl $7, %%ecx \n\t" |
247 "andl %0, %%ecx \n\t" | |
248 "addl %3, %%ecx \n\t" | |
249 "negl %%ecx \n\t" | |
250 "shll %%cl, %1 \n\t" | |
251 "bswapl %1 \n\t" | |
252 "movl %0, %%ecx \n\t" | |
253 "shrl $3, %%ecx \n\t" | |
254 "orl %1, (%%ecx, %2) \n\t" | |
255 "addl %3, %0 \n\t" | |
256 "movl $0, 4(%%ecx, %2) \n\t" | |
257 : "=&r" (s->index), "=&r" (value) | |
258 : "r" (s->buf), "r" (n), "0" (s->index), "1" (value) | |
259 : "%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
|
260 ); |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
261 # 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
|
262 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
|
263 uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3)); |
2967 | 264 |
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
|
265 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
|
266 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
|
267 //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
|
268 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
|
269 s->index= index; |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
270 # endif |
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
271 # 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
|
272 } |
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 #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
|
274 |
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 |
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 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
|
277 { |
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 #ifdef ALT_BITSTREAM_WRITER |
2979 | 279 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
|
280 #else |
2979 | 281 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
|
282 #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
|
283 } |
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
|
284 |
1799 | 285 /** |
286 * | |
287 * PutBitContext must be flushed & aligned to a byte boundary before calling this. | |
288 */ | |
289 static inline void skip_put_bytes(PutBitContext *s, int n){ | |
290 assert((put_bits_count(s)&7)==0); | |
291 #ifdef ALT_BITSTREAM_WRITER | |
292 FIXME may need some cleaning of the buffer | |
2979 | 293 s->index += n<<3; |
1799 | 294 #else |
295 assert(s->bit_left==32); | |
2979 | 296 s->buf_ptr += n; |
2967 | 297 #endif |
1799 | 298 } |
299 | |
300 /** | |
2502 | 301 * skips the given number of bits. |
302 * must only be used if the actual values in the bitstream dont matter | |
303 */ | |
304 static inline void skip_put_bits(PutBitContext *s, int n){ | |
305 #ifdef ALT_BITSTREAM_WRITER | |
306 s->index += n; | |
307 #else | |
308 s->bit_left -= n; | |
309 s->buf_ptr-= s->bit_left>>5; | |
310 s->bit_left &= 31; | |
2967 | 311 #endif |
2502 | 312 } |
313 | |
314 /** | |
1799 | 315 * Changes the end of the buffer. |
316 */ | |
317 static inline void set_put_bits_buffer_size(PutBitContext *s, int size){ | |
318 s->buf_end= s->buf + size; | |
319 } | |
320 | |
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
|
321 /* 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
|
322 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
|
323 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
|
324 |
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
|
325 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
|
326 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
|
327 |
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
|
328 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
|
329 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
|
330 |
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
|
331 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
|
332 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
|
333 |
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 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
|
335 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
|
336 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
|
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 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
|
339 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
|
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 SHOW_UBITS(name, gb, num) |
2764 | 342 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
|
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 SHOW_SBITS(name, gb, num) |
2764 | 345 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
|
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 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
|
348 will skip over the next num bits |
2764 | 349 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
|
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 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
|
352 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
|
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 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
|
355 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
|
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 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
|
358 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
|
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 LAST_SKIP_BITS(name, gb, num) |
2764 | 361 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
|
362 |
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 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
|
364 */ |
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 |
1254
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
366 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
|
367 { |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
368 #ifdef CONFIG_ALIGN |
2979 | 369 const uint8_t *p=v; |
370 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
|
371 #else |
2979 | 372 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
|
373 #endif |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
374 } |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
375 |
2663
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
376 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
|
377 { |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
378 #ifdef CONFIG_ALIGN |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
379 const uint8_t *p=v; |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
380 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
|
381 #else |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
382 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
|
383 #endif |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
384 } |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
385 |
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
|
386 #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
|
387 # 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
|
388 |
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
|
389 # 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
|
390 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
|
391 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
|
392 |
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
|
393 # 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
|
394 (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
|
395 |
2663
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
396 # ifdef ALT_BITSTREAM_READER_LE |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
397 # define UPDATE_CACHE(name, gb)\ |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
398 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
|
399 |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
400 # 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
|
401 name##_cache >>= (num); |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
402 # 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
|
403 # define UPDATE_CACHE(name, gb)\ |
2288 | 404 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
|
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 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
|
407 name##_cache <<= (num); |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
408 # 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
|
409 |
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
|
410 // 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
|
411 # 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
|
412 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
|
413 |
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
|
414 # 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
|
415 {\ |
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 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
|
417 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
|
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 |
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
|
420 # 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
|
421 # 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
|
422 |
2663
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
423 # ifdef ALT_BITSTREAM_READER_LE |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
424 # 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
|
425 ((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
|
426 # 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
|
427 # define SHOW_UBITS(name, gb, num)\ |
525 | 428 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
|
429 # 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
|
430 |
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 # define SHOW_SBITS(name, gb, num)\ |
525 | 432 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
|
433 |
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 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
|
435 ((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
|
436 |
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
|
437 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
|
438 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
|
439 } |
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 #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
|
441 //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
|
442 |
1263
9fce515e9894
libmpeg2 style bitstream reader 17 vs 16 bit bugfix
michaelni
parents:
1261
diff
changeset
|
443 # 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
|
444 |
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
|
445 # 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
|
446 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
|
447 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
|
448 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
|
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 # 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
|
451 (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
|
452 (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
|
453 (gb)->buffer_ptr= name##_buffer_ptr;\ |
0 | 454 |
1254
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
455 #ifdef LIBMPEG2_BITSTREAM_READER_HACK |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
456 |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
457 # define UPDATE_CACHE(name, gb)\ |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
458 if(name##_bit_count >= 0){\ |
1257 | 459 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
|
460 name##_buffer_ptr += 2;\ |
1254
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
461 name##_bit_count-= 16;\ |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
462 }\ |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
463 |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
464 #else |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
465 |
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
|
466 # define UPDATE_CACHE(name, gb)\ |
1263
9fce515e9894
libmpeg2 style bitstream reader 17 vs 16 bit bugfix
michaelni
parents:
1261
diff
changeset
|
467 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
|
468 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
|
469 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
|
470 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
|
471 }\ |
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
|
472 |
1254
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
473 #endif |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
474 |
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
|
475 # 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
|
476 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
|
477 |
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
|
478 # 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
|
479 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
|
480 |
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
|
481 # 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
|
482 {\ |
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
|
483 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
|
484 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
|
485 }\ |
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 |
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 # 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
|
488 # 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
|
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 # define SHOW_UBITS(name, gb, num)\ |
525 | 491 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
|
492 |
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 SHOW_SBITS(name, gb, num)\ |
525 | 494 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
|
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 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
|
497 ((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
|
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 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
|
500 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
|
501 } |
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 |
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 #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
|
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 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
|
506 |
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 # 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
|
508 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
|
509 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
|
510 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
|
511 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
|
512 |
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 # 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
|
514 (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
|
515 (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
|
516 (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
|
517 (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
|
518 |
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 # 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
|
520 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
|
521 const uint32_t next= be2me_32( *name##_buffer_ptr );\ |
525 | 522 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
|
523 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
|
524 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
|
525 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
|
526 }\ |
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
|
527 |
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
|
528 #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
|
529 # 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
|
530 asm(\ |
2979 | 531 "shldl %2, %1, %0 \n\t"\ |
532 "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
|
533 : "+r" (name##_cache0), "+r" (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
|
534 : "Ic" ((uint8_t)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
|
535 ); |
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 #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
|
537 # 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
|
538 name##_cache0 <<= (num);\ |
525 | 539 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
|
540 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
|
541 #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
|
542 |
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 # 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
|
544 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
|
545 |
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 # 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
|
547 {\ |
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 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
|
549 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
|
550 }\ |
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 |
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 # 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
|
553 # 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
|
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 # define SHOW_UBITS(name, gb, num)\ |
525 | 556 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
|
557 |
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 # define SHOW_SBITS(name, gb, num)\ |
525 | 559 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
|
560 |
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 # 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
|
562 (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
|
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 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
|
565 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
|
566 } |
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
|
567 |
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
568 #endif |
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
569 |
1257 | 570 /** |
571 * read mpeg1 dc style vlc (sign bit + mantisse with no MSB). | |
2967 | 572 * if MSB not set it is negative |
1257 | 573 * @param n length in bits |
2967 | 574 * @author BERO |
1257 | 575 */ |
1254
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
576 static inline int get_xbits(GetBitContext *s, int n){ |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
577 register int tmp; |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
578 register int32_t cache; |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
579 OPEN_READER(re, s) |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
580 UPDATE_CACHE(re, s) |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
581 cache = GET_CACHE(re,s); |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
582 if ((int32_t)cache<0) { //MSB=1 |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
583 tmp = NEG_USR32(cache,n); |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
584 } else { |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
585 // tmp = (-1<<n) | NEG_USR32(cache,n) + 1; mpeg12.c algo |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
586 // tmp = - (NEG_USR32(cache,n) ^ ((1 << n) - 1)); h263.c algo |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
587 tmp = - NEG_USR32(~cache,n); |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
588 } |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
589 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
|
590 CLOSE_READER(re, s) |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
591 return tmp; |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
592 } |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
593 |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
594 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
|
595 register int tmp; |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
596 OPEN_READER(re, s) |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
597 UPDATE_CACHE(re, s) |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
598 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
|
599 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
|
600 CLOSE_READER(re, s) |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
601 return tmp; |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
602 } |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
603 |
1257 | 604 /** |
605 * reads 0-17 bits. | |
2764 | 606 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't |
1257 | 607 */ |
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
608 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
|
609 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
|
610 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
|
611 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
|
612 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
|
613 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
|
614 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
|
615 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
|
616 } |
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
617 |
1257 | 618 unsigned int get_bits_long(GetBitContext *s, int n); |
619 | |
620 /** | |
621 * shows 0-17 bits. | |
2764 | 622 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't |
1257 | 623 */ |
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
|
624 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
|
625 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
|
626 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
|
627 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
|
628 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
|
629 // 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
|
630 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
|
631 } |
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
|
632 |
1257 | 633 unsigned int show_bits_long(GetBitContext *s, int n); |
634 | |
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
|
635 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
|
636 //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
|
637 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
|
638 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
|
639 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
|
640 CLOSE_READER(re, s) |
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
641 } |
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
642 |
21 | 643 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
|
644 #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
|
645 int index= s->index; |
193
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
646 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
|
647 #ifdef ALT_BITSTREAM_READER_LE |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
648 result>>= (index&0x07); |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
649 result&= 1; |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
650 #else |
199
0f1dba8fc617
(commited by michael / arpi was crazy enough to give me his password)
arpi_esp
parents:
193
diff
changeset
|
651 result<<= (index&0x07); |
0f1dba8fc617
(commited by michael / arpi was crazy enough to give me his password)
arpi_esp
parents:
193
diff
changeset
|
652 result>>= 8 - 1; |
2663
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
653 #endif |
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
654 index++; |
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
655 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
|
656 |
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
657 return result; |
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
658 #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
|
659 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
|
660 #endif |
21 | 661 } |
662 | |
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
|
663 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
|
664 return show_bits(s, 1); |
21 | 665 } |
666 | |
667 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
|
668 skip_bits(s, 1); |
21 | 669 } |
670 | |
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
671 /** |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
672 * init GetBitContext. |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
673 * @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
|
674 * 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
|
675 * @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
|
676 */ |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
677 static inline void init_get_bits(GetBitContext *s, |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
678 const uint8_t *buffer, int bit_size) |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
679 { |
2889 | 680 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
|
681 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
|
682 buffer_size = bit_size = 0; |
26f8974c3d66
fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents:
2889
diff
changeset
|
683 buffer = NULL; |
26f8974c3d66
fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents:
2889
diff
changeset
|
684 } |
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
685 |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
686 s->buffer= buffer; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
687 s->size_in_bits= bit_size; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
688 s->buffer_end= buffer + buffer_size; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
689 #ifdef ALT_BITSTREAM_READER |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
690 s->index=0; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
691 #elif defined LIBMPEG2_BITSTREAM_READER |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
692 #ifdef LIBMPEG2_BITSTREAM_READER_HACK |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
693 if ((int)buffer&1) { |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
694 /* word alignment */ |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
695 s->cache = (*buffer++)<<24; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
696 s->buffer_ptr = buffer; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
697 s->bit_count = 16-8; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
698 } else |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
699 #endif |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
700 { |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
701 s->buffer_ptr = buffer; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
702 s->bit_count = 16; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
703 s->cache = 0; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
704 } |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
705 #elif defined A32_BITSTREAM_READER |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
706 s->buffer_ptr = (uint32_t*)buffer; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
707 s->bit_count = 32; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
708 s->cache0 = 0; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
709 s->cache1 = 0; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
710 #endif |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
711 { |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
712 OPEN_READER(re, s) |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
713 UPDATE_CACHE(re, s) |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
714 UPDATE_CACHE(re, s) |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
715 CLOSE_READER(re, s) |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
716 } |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
717 #ifdef A32_BITSTREAM_READER |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
718 s->cache1 = 0; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
719 #endif |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
720 } |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
721 |
862 | 722 int check_marker(GetBitContext *s, const char *msg); |
0 | 723 void align_get_bits(GetBitContext *s); |
724 int init_vlc(VLC *vlc, int nb_bits, int nb_codes, | |
725 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
|
726 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
|
727 int flags); |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
728 #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
|
729 #define INIT_VLC_LE 2 |
0 | 730 void free_vlc(VLC *vlc); |
731 | |
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
|
732 /** |
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
|
733 * |
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
|
734 * 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
|
735 * 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
|
736 * 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
|
737 */ |
529 | 738 #define GET_VLC(code, name, gb, table, bits, max_depth)\ |
739 {\ | |
740 int n, index, nb_bits;\ | |
741 \ | |
742 index= SHOW_UBITS(name, gb, bits);\ | |
743 code = table[index][0];\ | |
744 n = table[index][1];\ | |
745 \ | |
746 if(max_depth > 1 && n < 0){\ | |
747 LAST_SKIP_BITS(name, gb, bits)\ | |
748 UPDATE_CACHE(name, gb)\ | |
749 \ | |
750 nb_bits = -n;\ | |
751 \ | |
535 | 752 index= SHOW_UBITS(name, gb, nb_bits) + code;\ |
529 | 753 code = table[index][0];\ |
754 n = table[index][1];\ | |
755 if(max_depth > 2 && n < 0){\ | |
756 LAST_SKIP_BITS(name, gb, nb_bits)\ | |
757 UPDATE_CACHE(name, gb)\ | |
758 \ | |
759 nb_bits = -n;\ | |
760 \ | |
535 | 761 index= SHOW_UBITS(name, gb, nb_bits) + code;\ |
529 | 762 code = table[index][0];\ |
763 n = table[index][1];\ | |
764 }\ | |
765 }\ | |
766 SKIP_BITS(name, gb, n)\ | |
767 } | |
768 | |
2615
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2614
diff
changeset
|
769 #define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\ |
542 | 770 {\ |
771 int n, index, nb_bits;\ | |
772 \ | |
773 index= SHOW_UBITS(name, gb, bits);\ | |
774 level = table[index].level;\ | |
775 n = table[index].len;\ | |
776 \ | |
777 if(max_depth > 1 && n < 0){\ | |
2615
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2614
diff
changeset
|
778 SKIP_BITS(name, gb, bits)\ |
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2614
diff
changeset
|
779 if(need_update){\ |
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2614
diff
changeset
|
780 UPDATE_CACHE(name, gb)\ |
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2614
diff
changeset
|
781 }\ |
542 | 782 \ |
783 nb_bits = -n;\ | |
784 \ | |
785 index= SHOW_UBITS(name, gb, nb_bits) + level;\ | |
786 level = table[index].level;\ | |
787 n = table[index].len;\ | |
788 }\ | |
789 run= table[index].run;\ | |
790 SKIP_BITS(name, gb, n)\ | |
791 } | |
792 | |
193
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
793 |
1079 | 794 /** |
795 * parses a vlc code, faster then get_vlc() | |
2967 | 796 * @param bits is the number of bits which will be read at once, must be |
1079 | 797 * identical to nb_bits in init_vlc() |
798 * @param max_depth is the number of times bits bits must be readed to completly | |
2967 | 799 * read the longest vlc code |
1079 | 800 * = (max_vlc_length + bits - 1) / bits |
801 */ | |
550 | 802 static always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2], |
803 int bits, int max_depth) | |
531 | 804 { |
805 int code; | |
2967 | 806 |
531 | 807 OPEN_READER(re, s) |
808 UPDATE_CACHE(re, s) | |
809 | |
810 GET_VLC(code, re, s, table, bits, max_depth) | |
811 | |
812 CLOSE_READER(re, s) | |
813 return code; | |
814 } | |
815 | |
1147 | 816 //#define TRACE |
817 | |
818 #ifdef TRACE | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
819 #include "avcodec.h" |
1147 | 820 static inline void print_bin(int bits, int n){ |
821 int i; | |
2967 | 822 |
1147 | 823 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
|
824 av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1); |
1147 | 825 } |
826 for(i=n; i<24; i++) | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
827 av_log(NULL, AV_LOG_DEBUG, " "); |
1147 | 828 } |
829 | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
830 static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ |
1147 | 831 int r= get_bits(s, n); |
2967 | 832 |
1147 | 833 print_bin(r, n); |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
834 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 | 835 return r; |
836 } | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
837 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 | 838 int show= show_bits(s, 24); |
839 int pos= get_bits_count(s); | |
840 int r= get_vlc2(s, table, bits, max_depth); | |
841 int len= get_bits_count(s) - pos; | |
842 int bits2= show>>(24-len); | |
2967 | 843 |
1147 | 844 print_bin(bits2, len); |
2967 | 845 |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
846 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line); |
1147 | 847 return r; |
848 } | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
849 static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ |
1273 | 850 int show= show_bits(s, n); |
851 int r= get_xbits(s, n); | |
2967 | 852 |
1273 | 853 print_bin(show, n); |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
854 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 | 855 return r; |
856 } | |
1147 | 857 |
858 #define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
859 #define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
1273 | 860 #define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__) |
1152 | 861 #define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__) |
1147 | 862 #define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__) |
863 | |
1940 | 864 #define tprintf(...) av_log(NULL, AV_LOG_DEBUG, __VA_ARGS__) |
1170 | 865 |
866 #else //TRACE | |
1824 | 867 #define tprintf(...) {} |
1170 | 868 #endif |
542 | 869 |
2467 | 870 static inline int decode012(GetBitContext *gb){ |
2464 | 871 int n; |
872 n = get_bits1(gb); | |
873 if (n == 0) | |
874 return 0; | |
875 else | |
876 return get_bits1(gb) + 1; | |
877 } | |
878 | |
2398
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2391
diff
changeset
|
879 #endif /* BITSTREAM_H */ |