Mercurial > libavcodec.hg
annotate bitstream.h @ 3976:27e90123b346 libavcodec
reverse remainder of the failed attempt to optimize *state=c->mps_state[s]
author | michael |
---|---|
date | Mon, 09 Oct 2006 21:14:16 +0000 |
parents | c8c591fe26f8 |
children | 3ccdff1e5221 |
rev | line source |
---|---|
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3675
diff
changeset
|
1 /* |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3675
diff
changeset
|
2 * copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at> |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3675
diff
changeset
|
3 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3760
diff
changeset
|
4 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3760
diff
changeset
|
5 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3760
diff
changeset
|
6 * FFmpeg is free software; you can redistribute it and/or |
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3675
diff
changeset
|
7 * modify it under the terms of the GNU Lesser General Public |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3675
diff
changeset
|
8 * License as published by the Free Software Foundation; either |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3760
diff
changeset
|
9 * version 2.1 of the License, or (at your option) any later version. |
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3675
diff
changeset
|
10 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3760
diff
changeset
|
11 * FFmpeg is distributed in the hope that it will be useful, |
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3675
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3675
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3675
diff
changeset
|
14 * Lesser General Public License for more details. |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3675
diff
changeset
|
15 * |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3675
diff
changeset
|
16 * You should have received a copy of the GNU Lesser General Public |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3760
diff
changeset
|
17 * License along with FFmpeg; if not, write to the Free Software |
3699
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3675
diff
changeset
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3675
diff
changeset
|
19 */ |
c537a97eec66
Add official LGPL license headers to the files that were missing them.
diego
parents:
3675
diff
changeset
|
20 |
1106 | 21 /** |
2398
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2391
diff
changeset
|
22 * @file bitstream.h |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2391
diff
changeset
|
23 * bitstream api header. |
1106 | 24 */ |
25 | |
2398
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2391
diff
changeset
|
26 #ifndef BITSTREAM_H |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2391
diff
changeset
|
27 #define BITSTREAM_H |
64 | 28 |
3648
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
29 #include "log.h" |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
30 |
3649 | 31 #if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER) |
32 #define ALT_BITSTREAM_READER | |
33 #endif | |
34 | |
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
|
35 //#define ALT_BITSTREAM_WRITER |
235
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
36 //#define ALIGNED_BITSTREAM_WRITER |
3628 | 37 #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER) |
3650
a74c0aaf9832
use the A32_BITSTREAM_READER by default on ARM (faster)
aurel
parents:
3649
diff
changeset
|
38 # ifdef ARCH_ARMV4L |
a74c0aaf9832
use the A32_BITSTREAM_READER by default on ARM (faster)
aurel
parents:
3649
diff
changeset
|
39 # define A32_BITSTREAM_READER |
a74c0aaf9832
use the A32_BITSTREAM_READER by default on ARM (faster)
aurel
parents:
3649
diff
changeset
|
40 # 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
|
41 #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
|
42 //#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
|
43 //#define A32_BITSTREAM_READER |
3650
a74c0aaf9832
use the A32_BITSTREAM_READER by default on ARM (faster)
aurel
parents:
3649
diff
changeset
|
44 # endif |
3628 | 45 #endif |
1254
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
46 #define LIBMPEG2_BITSTREAM_READER_HACK //add BERO |
2967 | 47 |
2578 | 48 extern const uint8_t ff_reverse[256]; |
49 | |
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
|
50 #if defined(ARCH_X86) || defined(ARCH_X86_64) |
525 | 51 // avoid +32 for shift optimization (gcc should do that ...) |
52 static inline int32_t NEG_SSR32( int32_t a, int8_t s){ | |
53 asm ("sarl %1, %0\n\t" | |
54 : "+r" (a) | |
55 : "ic" ((uint8_t)(-s)) | |
56 ); | |
57 return a; | |
58 } | |
59 static inline uint32_t NEG_USR32(uint32_t a, int8_t s){ | |
60 asm ("shrl %1, %0\n\t" | |
61 : "+r" (a) | |
62 : "ic" ((uint8_t)(-s)) | |
63 ); | |
64 return a; | |
65 } | |
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
|
66 #else |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
67 # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s))) |
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
68 # 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
|
69 #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
|
70 |
0 | 71 /* bit output */ |
72 | |
1895
e5687117cc7f
* removing casualties of battle of the wits and English language
romansh
parents:
1886
diff
changeset
|
73 /* buf and buf_end must be present and used by every alternative writer. */ |
0 | 74 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
|
75 #ifdef ALT_BITSTREAM_WRITER |
1064 | 76 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
|
77 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
|
78 #else |
1064 | 79 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
|
80 int bit_left; |
1064 | 81 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
|
82 #endif |
0 | 83 } PutBitContext; |
84 | |
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
85 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
|
86 { |
2894
26f8974c3d66
fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents:
2889
diff
changeset
|
87 if(buffer_size < 0) { |
26f8974c3d66
fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents:
2889
diff
changeset
|
88 buffer_size = 0; |
26f8974c3d66
fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents:
2889
diff
changeset
|
89 buffer = NULL; |
26f8974c3d66
fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents:
2889
diff
changeset
|
90 } |
2889 | 91 |
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
92 s->buf = buffer; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
93 s->buf_end = s->buf + buffer_size; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
94 #ifdef ALT_BITSTREAM_WRITER |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
95 s->index=0; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
96 ((uint32_t*)(s->buf))[0]=0; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
97 // memset(buffer, 0, buffer_size); |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
98 #else |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
99 s->buf_ptr = s->buf; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
100 s->bit_left=32; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
101 s->bit_buf=0; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
102 #endif |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
103 } |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
104 |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
105 /* return the number of bits output */ |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
106 static inline int put_bits_count(PutBitContext *s) |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
107 { |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
108 #ifdef ALT_BITSTREAM_WRITER |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
109 return s->index; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
110 #else |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
111 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
|
112 #endif |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
113 } |
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
|
114 |
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
115 /* 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
|
116 static inline void flush_put_bits(PutBitContext *s) |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
117 { |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
118 #ifdef ALT_BITSTREAM_WRITER |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
119 align_put_bits(s); |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
120 #else |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
121 s->bit_buf<<= s->bit_left; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
122 while (s->bit_left < 32) { |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
123 /* XXX: should test end of buffer */ |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
124 *s->buf_ptr++=s->bit_buf >> 24; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
125 s->bit_buf<<=8; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
126 s->bit_left+=8; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
127 } |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
128 s->bit_left=32; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
129 s->bit_buf=0; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
130 #endif |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
131 } |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
132 |
0 | 133 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
|
134 void ff_put_string(PutBitContext * pbc, char *s, int put_zero); |
0 | 135 |
136 /* bit input */ | |
1895
e5687117cc7f
* removing casualties of battle of the wits and English language
romansh
parents:
1886
diff
changeset
|
137 /* buffer, buffer_end and size_in_bits must be present and used by every reader */ |
0 | 138 typedef struct GetBitContext { |
1083 | 139 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
|
140 #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
|
141 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
|
142 #elif defined LIBMPEG2_BITSTREAM_READER |
1064 | 143 uint8_t *buffer_ptr; |
144 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
|
145 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
|
146 #elif defined A32_BITSTREAM_READER |
1064 | 147 uint32_t *buffer_ptr; |
148 uint32_t cache0; | |
149 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
|
150 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
|
151 #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
|
152 int size_in_bits; |
0 | 153 } GetBitContext; |
154 | |
1064 | 155 #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
|
156 |
0 | 157 typedef struct VLC { |
158 int bits; | |
1112
54be6aece1be
more cosmetics so that doxygen output is readable ...
michaelni
parents:
1106
diff
changeset
|
159 VLC_TYPE (*table)[2]; ///< code, bits |
0 | 160 int table_size, table_allocated; |
161 } VLC; | |
162 | |
542 | 163 typedef struct RL_VLC_ELEM { |
164 int16_t level; | |
165 int8_t len; | |
166 uint8_t run; | |
167 } RL_VLC_ELEM; | |
168 | |
3342 | 169 #if defined(ARCH_SPARC) || defined(ARCH_ARMV4L) || defined(ARCH_MIPS) |
891 | 170 #define UNALIGNED_STORES_ARE_BAD |
171 #endif | |
172 | |
193
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
173 /* 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
|
174 #if defined(ARCH_X86) || defined(ARCH_X86_64) |
3302 | 175 # define unaligned16(a) (*(const uint16_t*)(a)) |
2288 | 176 # define unaligned32(a) (*(const uint32_t*)(a)) |
3302 | 177 # define unaligned64(a) (*(const uint64_t*)(a)) |
193
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
178 #else |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
179 # ifdef __GNUC__ |
3302 | 180 # define unaligned(x) \ |
181 static inline uint##x##_t unaligned##x(const void *v) { \ | |
182 struct Unaligned { \ | |
183 uint##x##_t i; \ | |
184 } __attribute__((packed)); \ | |
185 \ | |
186 return ((const struct Unaligned *) v)->i; \ | |
193
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
187 } |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
188 # elif defined(__DECC) |
3302 | 189 # define unaligned(x) \ |
190 static inline uint##x##_t unaligned##x##(const void *v) { \ | |
191 return *(const __unaligned uint##x##_t *) v; \ | |
193
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
192 } |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
193 # else |
3302 | 194 # define unaligned(x) \ |
195 static inline uint##x##_t unaligned##x##(const void *v) { \ | |
196 return *(const uint##x##_t *) v; \ | |
193
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
197 } |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
198 # endif |
3302 | 199 unaligned(16) |
200 unaligned(32) | |
201 unaligned(64) | |
202 #undef unaligned | |
193
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
203 #endif //!ARCH_X86 |
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
204 |
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
|
205 #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
|
206 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
|
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 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
|
209 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
|
210 |
99a9f903f0e3
optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents:
235
diff
changeset
|
211 // 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
|
212 assert(n == 32 || value < (1U << n)); |
2967 | 213 |
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
|
214 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
|
215 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
|
216 |
99a9f903f0e3
optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents:
235
diff
changeset
|
217 // 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
|
218 /* 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
|
219 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
|
220 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
|
221 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
|
222 } else { |
2979 | 223 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
|
224 bit_buf |= value >> (n - bit_left); |
891 | 225 #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
|
226 if (3 & (intptr_t) s->buf_ptr) { |
891 | 227 s->buf_ptr[0] = bit_buf >> 24; |
228 s->buf_ptr[1] = bit_buf >> 16; | |
229 s->buf_ptr[2] = bit_buf >> 8; | |
230 s->buf_ptr[3] = bit_buf ; | |
231 } else | |
232 #endif | |
1064 | 233 *(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
|
234 //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
|
235 s->buf_ptr+=4; |
2979 | 236 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
|
237 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
|
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
|
239 |
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
|
240 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
|
241 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
|
242 } |
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
|
243 #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
|
244 |
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
|
245 |
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
|
246 #ifdef ALT_BITSTREAM_WRITER |
235
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
247 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
|
248 { |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
249 # 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
|
250 # 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
|
251 asm volatile( |
2979 | 252 "movl %0, %%ecx \n\t" |
253 "xorl %%eax, %%eax \n\t" | |
254 "shrdl %%cl, %1, %%eax \n\t" | |
255 "shrl %%cl, %1 \n\t" | |
256 "movl %0, %%ecx \n\t" | |
257 "shrl $3, %%ecx \n\t" | |
258 "andl $0xFFFFFFFC, %%ecx \n\t" | |
259 "bswapl %1 \n\t" | |
260 "orl %1, (%2, %%ecx) \n\t" | |
261 "bswapl %%eax \n\t" | |
262 "addl %3, %0 \n\t" | |
263 "movl %%eax, 4(%2, %%ecx) \n\t" | |
264 : "=&r" (s->index), "=&r" (value) | |
265 : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n)) | |
266 : "%eax", "%ecx" | |
235
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
267 ); |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
268 # else |
235
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
269 int index= s->index; |
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
270 uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5); |
2967 | 271 |
272 value<<= 32-n; | |
273 | |
235
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
274 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
|
275 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
|
276 //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
|
277 index+= n; |
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
278 s->index= index; |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
279 # endif |
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
280 # 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
|
281 # 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
|
282 asm volatile( |
2979 | 283 "movl $7, %%ecx \n\t" |
284 "andl %0, %%ecx \n\t" | |
285 "addl %3, %%ecx \n\t" | |
286 "negl %%ecx \n\t" | |
287 "shll %%cl, %1 \n\t" | |
288 "bswapl %1 \n\t" | |
289 "movl %0, %%ecx \n\t" | |
290 "shrl $3, %%ecx \n\t" | |
291 "orl %1, (%%ecx, %2) \n\t" | |
292 "addl %3, %0 \n\t" | |
293 "movl $0, 4(%%ecx, %2) \n\t" | |
294 : "=&r" (s->index), "=&r" (value) | |
295 : "r" (s->buf), "r" (n), "0" (s->index), "1" (value) | |
296 : "%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
|
297 ); |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
298 # 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
|
299 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
|
300 uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3)); |
2967 | 301 |
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
|
302 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
|
303 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
|
304 //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
|
305 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
|
306 s->index= index; |
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
307 # endif |
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
308 # 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
|
309 } |
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
|
310 #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
|
311 |
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
|
312 |
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
|
313 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
|
314 { |
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
|
315 #ifdef ALT_BITSTREAM_WRITER |
2979 | 316 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
|
317 #else |
2979 | 318 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
|
319 #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
|
320 } |
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
|
321 |
1799 | 322 /** |
323 * | |
324 * PutBitContext must be flushed & aligned to a byte boundary before calling this. | |
325 */ | |
326 static inline void skip_put_bytes(PutBitContext *s, int n){ | |
327 assert((put_bits_count(s)&7)==0); | |
328 #ifdef ALT_BITSTREAM_WRITER | |
329 FIXME may need some cleaning of the buffer | |
2979 | 330 s->index += n<<3; |
1799 | 331 #else |
332 assert(s->bit_left==32); | |
2979 | 333 s->buf_ptr += n; |
2967 | 334 #endif |
1799 | 335 } |
336 | |
337 /** | |
2502 | 338 * skips the given number of bits. |
339 * must only be used if the actual values in the bitstream dont matter | |
340 */ | |
341 static inline void skip_put_bits(PutBitContext *s, int n){ | |
342 #ifdef ALT_BITSTREAM_WRITER | |
343 s->index += n; | |
344 #else | |
345 s->bit_left -= n; | |
346 s->buf_ptr-= s->bit_left>>5; | |
347 s->bit_left &= 31; | |
2967 | 348 #endif |
2502 | 349 } |
350 | |
351 /** | |
1799 | 352 * Changes the end of the buffer. |
353 */ | |
354 static inline void set_put_bits_buffer_size(PutBitContext *s, int size){ | |
355 s->buf_end= s->buf + size; | |
356 } | |
357 | |
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
|
358 /* 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
|
359 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
|
360 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
|
361 |
19a5e2a81e1a
new bitstream reader 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 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
|
363 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
|
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 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
|
366 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
|
367 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
368 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
|
369 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
|
370 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
371 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
|
372 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
|
373 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
|
374 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
375 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
|
376 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
|
377 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
378 SHOW_UBITS(name, gb, num) |
2764 | 379 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
|
380 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
381 SHOW_SBITS(name, gb, num) |
2764 | 382 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
|
383 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
384 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
|
385 will skip over the next num bits |
2764 | 386 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
|
387 |
19a5e2a81e1a
new bitstream reader 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 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
|
389 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
|
390 |
19a5e2a81e1a
new bitstream reader 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 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
|
392 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
|
393 |
19a5e2a81e1a
new bitstream reader 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 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
|
395 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
|
396 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
397 LAST_SKIP_BITS(name, gb, num) |
2764 | 398 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
|
399 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
400 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
|
401 */ |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
402 |
1254
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
403 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
|
404 { |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
405 #ifdef CONFIG_ALIGN |
2979 | 406 const uint8_t *p=v; |
407 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
|
408 #else |
2979 | 409 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
|
410 #endif |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
411 } |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
412 |
2663
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
413 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
|
414 { |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
415 #ifdef CONFIG_ALIGN |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
416 const uint8_t *p=v; |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
417 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
|
418 #else |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
419 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
|
420 #endif |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
421 } |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
422 |
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
|
423 #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
|
424 # 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
|
425 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
426 # 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
|
427 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
|
428 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
|
429 |
19a5e2a81e1a
new bitstream reader 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 # 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
|
431 (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
|
432 |
2663
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
433 # ifdef ALT_BITSTREAM_READER_LE |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
434 # define UPDATE_CACHE(name, gb)\ |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
435 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
|
436 |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
437 # 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
|
438 name##_cache >>= (num); |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
439 # else |
520
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
440 # define UPDATE_CACHE(name, gb)\ |
2288 | 441 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
|
442 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
443 # 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
|
444 name##_cache <<= (num); |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
445 # 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
|
446 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
447 // 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
|
448 # 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
|
449 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
|
450 |
19a5e2a81e1a
new bitstream reader 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 # 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
|
452 {\ |
19a5e2a81e1a
new bitstream reader 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 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
|
454 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
|
455 }\ |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
456 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
457 # 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
|
458 # 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
|
459 |
2663
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
460 # ifdef ALT_BITSTREAM_READER_LE |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
461 # 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
|
462 ((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
|
463 # 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
|
464 # define SHOW_UBITS(name, gb, num)\ |
525 | 465 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
|
466 # 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
|
467 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
468 # define SHOW_SBITS(name, gb, num)\ |
525 | 469 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
|
470 |
19a5e2a81e1a
new bitstream reader 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 # 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
|
472 ((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
|
473 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
474 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
|
475 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
|
476 } |
3629
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
477 |
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
478 static inline void skip_bits_long(GetBitContext *s, int n){ |
3633 | 479 s->index += n; |
3629
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
480 } |
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
481 |
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
|
482 #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
|
483 //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
|
484 |
1263
9fce515e9894
libmpeg2 style bitstream reader 17 vs 16 bit bugfix
michaelni
parents:
1261
diff
changeset
|
485 # 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
|
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 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
|
488 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
|
489 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
|
490 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
|
491 |
19a5e2a81e1a
new bitstream reader 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 # 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
|
493 (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
|
494 (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
|
495 (gb)->buffer_ptr= name##_buffer_ptr;\ |
0 | 496 |
1254
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
497 #ifdef LIBMPEG2_BITSTREAM_READER_HACK |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
498 |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
499 # define UPDATE_CACHE(name, gb)\ |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
500 if(name##_bit_count >= 0){\ |
1257 | 501 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
|
502 name##_buffer_ptr += 2;\ |
1254
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
503 name##_bit_count-= 16;\ |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
504 }\ |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
505 |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
506 #else |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
507 |
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
|
508 # define UPDATE_CACHE(name, gb)\ |
1263
9fce515e9894
libmpeg2 style bitstream reader 17 vs 16 bit bugfix
michaelni
parents:
1261
diff
changeset
|
509 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
|
510 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
|
511 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
|
512 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
|
513 }\ |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
514 |
1254
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
515 #endif |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
516 |
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
|
517 # 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
|
518 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
|
519 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
520 # 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
|
521 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
|
522 |
19a5e2a81e1a
new bitstream reader 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 # 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
|
524 {\ |
19a5e2a81e1a
new bitstream reader 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 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
|
526 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
|
527 }\ |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
528 |
19a5e2a81e1a
new bitstream reader 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 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
|
530 # 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
|
531 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
532 # define SHOW_UBITS(name, gb, num)\ |
525 | 533 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
|
534 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
535 # define SHOW_SBITS(name, gb, num)\ |
525 | 536 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
|
537 |
19a5e2a81e1a
new bitstream reader 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 # 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
|
539 ((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
|
540 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
541 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
|
542 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
|
543 } |
19a5e2a81e1a
new bitstream reader 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 |
3633 | 545 static inline void skip_bits_long(GetBitContext *s, int n){ |
546 OPEN_READER(re, s) | |
547 re_bit_count += n; | |
548 re_buffer_ptr += 2*(re_bit_count>>4); | |
549 re_bit_count &= 15; | |
550 re_cache = ((re_buffer_ptr[-2]<<8) + re_buffer_ptr[-1]) << (16+re_bit_count); | |
551 UPDATE_CACHE(re, s) | |
552 CLOSE_READER(re, s) | |
553 } | |
554 | |
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
|
555 #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
|
556 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
557 # define 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
|
558 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
559 # 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
|
560 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
|
561 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
|
562 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
|
563 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
|
564 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
565 # define 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
|
566 (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
|
567 (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
|
568 (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
|
569 (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
|
570 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
571 # define 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
|
572 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
|
573 const uint32_t next= be2me_32( *name##_buffer_ptr );\ |
525 | 574 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
|
575 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
|
576 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
|
577 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
|
578 }\ |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
579 |
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
|
580 #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
|
581 # 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
|
582 asm(\ |
2979 | 583 "shldl %2, %1, %0 \n\t"\ |
584 "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
|
585 : "+r" (name##_cache0), "+r" (name##_cache1)\ |
3638 | 586 : "Ic" ((uint8_t)(num))\ |
520
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
587 ); |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
588 #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
|
589 # 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
|
590 name##_cache0 <<= (num);\ |
525 | 591 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
|
592 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
|
593 #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
|
594 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
595 # 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
|
596 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
|
597 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
598 # 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
|
599 {\ |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
600 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
|
601 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
|
602 }\ |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
603 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
604 # 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
|
605 # 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
|
606 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
607 # define SHOW_UBITS(name, gb, num)\ |
525 | 608 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
|
609 |
19a5e2a81e1a
new bitstream reader 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 # define SHOW_SBITS(name, gb, num)\ |
525 | 611 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
|
612 |
19a5e2a81e1a
new bitstream reader 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 # 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
|
614 (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
|
615 |
19a5e2a81e1a
new bitstream reader 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 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
|
617 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
|
618 } |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
619 |
3629
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
620 static inline void skip_bits_long(GetBitContext *s, int n){ |
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
621 OPEN_READER(re, s) |
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
622 re_bit_count += n; |
3631 | 623 re_buffer_ptr += re_bit_count>>5; |
3629
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
624 re_bit_count &= 31; |
3630 | 625 re_cache0 = be2me_32( re_buffer_ptr[-1] ) << re_bit_count; |
626 re_cache1 = 0; | |
3629
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
627 UPDATE_CACHE(re, s) |
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
628 CLOSE_READER(re, s) |
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
629 } |
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
630 |
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
631 #endif |
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
632 |
1257 | 633 /** |
634 * read mpeg1 dc style vlc (sign bit + mantisse with no MSB). | |
2967 | 635 * if MSB not set it is negative |
1257 | 636 * @param n length in bits |
2967 | 637 * @author BERO |
1257 | 638 */ |
1254
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
639 static inline int get_xbits(GetBitContext *s, int n){ |
3244 | 640 register int sign; |
1254
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
641 register int32_t cache; |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
642 OPEN_READER(re, s) |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
643 UPDATE_CACHE(re, s) |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
644 cache = GET_CACHE(re,s); |
3244 | 645 sign=(~cache)>>31; |
1254
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
646 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
|
647 CLOSE_READER(re, s) |
3244 | 648 return (NEG_USR32(sign ^ cache, n) ^ sign) - sign; |
1254
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
649 } |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
650 |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
651 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
|
652 register int tmp; |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
653 OPEN_READER(re, s) |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
654 UPDATE_CACHE(re, s) |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
655 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
|
656 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
|
657 CLOSE_READER(re, s) |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
658 return tmp; |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
659 } |
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
660 |
1257 | 661 /** |
662 * reads 0-17 bits. | |
2764 | 663 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't |
1257 | 664 */ |
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
665 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
|
666 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
|
667 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
|
668 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
|
669 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
|
670 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
|
671 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
|
672 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
|
673 } |
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
674 |
1257 | 675 /** |
676 * shows 0-17 bits. | |
2764 | 677 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't |
1257 | 678 */ |
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
|
679 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
|
680 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
|
681 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
|
682 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
|
683 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
|
684 // 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
|
685 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
|
686 } |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
687 |
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
688 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
|
689 //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
|
690 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
|
691 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
|
692 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
|
693 CLOSE_READER(re, s) |
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
694 } |
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
695 |
21 | 696 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
|
697 #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
|
698 int index= s->index; |
193
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
699 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
|
700 #ifdef ALT_BITSTREAM_READER_LE |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
701 result>>= (index&0x07); |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
702 result&= 1; |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
703 #else |
199
0f1dba8fc617
(commited by michael / arpi was crazy enough to give me his password)
arpi_esp
parents:
193
diff
changeset
|
704 result<<= (index&0x07); |
0f1dba8fc617
(commited by michael / arpi was crazy enough to give me his password)
arpi_esp
parents:
193
diff
changeset
|
705 result>>= 8 - 1; |
2663
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
706 #endif |
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
707 index++; |
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
708 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
|
709 |
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
710 return result; |
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
711 #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
|
712 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
|
713 #endif |
21 | 714 } |
715 | |
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
|
716 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
|
717 return show_bits(s, 1); |
21 | 718 } |
719 | |
720 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
|
721 skip_bits(s, 1); |
21 | 722 } |
723 | |
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
724 /** |
3648
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
725 * reads 0-32 bits. |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
726 */ |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
727 static inline unsigned int get_bits_long(GetBitContext *s, int n){ |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
728 if(n<=17) return get_bits(s, n); |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
729 else{ |
3760
dbe7b99efdbf
Fix get_bits_long to work with ALT_BITSTREAM_READER_LE.
reimar
parents:
3699
diff
changeset
|
730 #ifdef ALT_BITSTREAM_READER_LE |
dbe7b99efdbf
Fix get_bits_long to work with ALT_BITSTREAM_READER_LE.
reimar
parents:
3699
diff
changeset
|
731 int ret= get_bits(s, 16); |
dbe7b99efdbf
Fix get_bits_long to work with ALT_BITSTREAM_READER_LE.
reimar
parents:
3699
diff
changeset
|
732 return ret | (get_bits(s, n-16) << 16); |
dbe7b99efdbf
Fix get_bits_long to work with ALT_BITSTREAM_READER_LE.
reimar
parents:
3699
diff
changeset
|
733 #else |
3648
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
734 int ret= get_bits(s, 16) << (n-16); |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
735 return ret | get_bits(s, n-16); |
3760
dbe7b99efdbf
Fix get_bits_long to work with ALT_BITSTREAM_READER_LE.
reimar
parents:
3699
diff
changeset
|
736 #endif |
3648
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
737 } |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
738 } |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
739 |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
740 /** |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
741 * shows 0-32 bits. |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
742 */ |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
743 static inline unsigned int show_bits_long(GetBitContext *s, int n){ |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
744 if(n<=17) return show_bits(s, n); |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
745 else{ |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
746 GetBitContext gb= *s; |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
747 int ret= get_bits_long(s, n); |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
748 *s= gb; |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
749 return ret; |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
750 } |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
751 } |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
752 |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
753 static inline int check_marker(GetBitContext *s, const char *msg) |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
754 { |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
755 int bit= get_bits1(s); |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
756 if(!bit) |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
757 av_log(NULL, AV_LOG_INFO, "Marker bit missing %s\n", msg); |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
758 |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
759 return bit; |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
760 } |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
761 |
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
762 /** |
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
763 * init GetBitContext. |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
764 * @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
|
765 * 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
|
766 * @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
|
767 */ |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
768 static inline void init_get_bits(GetBitContext *s, |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
769 const uint8_t *buffer, int bit_size) |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
770 { |
2889 | 771 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
|
772 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
|
773 buffer_size = bit_size = 0; |
26f8974c3d66
fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents:
2889
diff
changeset
|
774 buffer = NULL; |
26f8974c3d66
fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents:
2889
diff
changeset
|
775 } |
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
776 |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
777 s->buffer= buffer; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
778 s->size_in_bits= bit_size; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
779 s->buffer_end= buffer + buffer_size; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
780 #ifdef ALT_BITSTREAM_READER |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
781 s->index=0; |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
782 #elif defined LIBMPEG2_BITSTREAM_READER |
3633 | 783 s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1)); |
784 s->bit_count = 16 + 8*((intptr_t)buffer&1); | |
785 skip_bits_long(s, 0); | |
3632
25ceb2cc950d
make A32 reader align its ptr during init no matter what missaligned mess is given to it
michael
parents:
3631
diff
changeset
|
786 #elif defined A32_BITSTREAM_READER |
25ceb2cc950d
make A32 reader align its ptr during init no matter what missaligned mess is given to it
michael
parents:
3631
diff
changeset
|
787 s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3)); |
25ceb2cc950d
make A32 reader align its ptr during init no matter what missaligned mess is given to it
michael
parents:
3631
diff
changeset
|
788 s->bit_count = 32 + 8*((intptr_t)buffer&3); |
25ceb2cc950d
make A32 reader align its ptr during init no matter what missaligned mess is given to it
michael
parents:
3631
diff
changeset
|
789 skip_bits_long(s, 0); |
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
790 #endif |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
791 } |
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
792 |
3675 | 793 static inline void align_get_bits(GetBitContext *s) |
3629
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
794 { |
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
795 int n= (-get_bits_count(s)) & 7; |
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
796 if(n) skip_bits(s, n); |
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
797 } |
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
798 |
0 | 799 int init_vlc(VLC *vlc, int nb_bits, int nb_codes, |
800 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
|
801 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
|
802 int flags); |
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
803 #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
|
804 #define INIT_VLC_LE 2 |
0 | 805 void free_vlc(VLC *vlc); |
806 | |
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
|
807 /** |
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
|
808 * |
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
|
809 * 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
|
810 * 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
|
811 * 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
|
812 */ |
529 | 813 #define GET_VLC(code, name, gb, table, bits, max_depth)\ |
814 {\ | |
815 int n, index, nb_bits;\ | |
816 \ | |
817 index= SHOW_UBITS(name, gb, bits);\ | |
818 code = table[index][0];\ | |
819 n = table[index][1];\ | |
820 \ | |
821 if(max_depth > 1 && n < 0){\ | |
822 LAST_SKIP_BITS(name, gb, bits)\ | |
823 UPDATE_CACHE(name, gb)\ | |
824 \ | |
825 nb_bits = -n;\ | |
826 \ | |
535 | 827 index= SHOW_UBITS(name, gb, nb_bits) + code;\ |
529 | 828 code = table[index][0];\ |
829 n = table[index][1];\ | |
830 if(max_depth > 2 && n < 0){\ | |
831 LAST_SKIP_BITS(name, gb, nb_bits)\ | |
832 UPDATE_CACHE(name, gb)\ | |
833 \ | |
834 nb_bits = -n;\ | |
835 \ | |
535 | 836 index= SHOW_UBITS(name, gb, nb_bits) + code;\ |
529 | 837 code = table[index][0];\ |
838 n = table[index][1];\ | |
839 }\ | |
840 }\ | |
841 SKIP_BITS(name, gb, n)\ | |
842 } | |
843 | |
2615
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2614
diff
changeset
|
844 #define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\ |
542 | 845 {\ |
846 int n, index, nb_bits;\ | |
847 \ | |
848 index= SHOW_UBITS(name, gb, bits);\ | |
849 level = table[index].level;\ | |
850 n = table[index].len;\ | |
851 \ | |
852 if(max_depth > 1 && n < 0){\ | |
2615
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2614
diff
changeset
|
853 SKIP_BITS(name, gb, bits)\ |
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2614
diff
changeset
|
854 if(need_update){\ |
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2614
diff
changeset
|
855 UPDATE_CACHE(name, gb)\ |
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2614
diff
changeset
|
856 }\ |
542 | 857 \ |
858 nb_bits = -n;\ | |
859 \ | |
860 index= SHOW_UBITS(name, gb, nb_bits) + level;\ | |
861 level = table[index].level;\ | |
862 n = table[index].len;\ | |
863 }\ | |
864 run= table[index].run;\ | |
865 SKIP_BITS(name, gb, n)\ | |
866 } | |
867 | |
193
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
868 |
1079 | 869 /** |
870 * parses a vlc code, faster then get_vlc() | |
2967 | 871 * @param bits is the number of bits which will be read at once, must be |
1079 | 872 * identical to nb_bits in init_vlc() |
873 * @param max_depth is the number of times bits bits must be readed to completly | |
2967 | 874 * read the longest vlc code |
1079 | 875 * = (max_vlc_length + bits - 1) / bits |
876 */ | |
550 | 877 static always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2], |
878 int bits, int max_depth) | |
531 | 879 { |
880 int code; | |
2967 | 881 |
531 | 882 OPEN_READER(re, s) |
883 UPDATE_CACHE(re, s) | |
884 | |
885 GET_VLC(code, re, s, table, bits, max_depth) | |
886 | |
887 CLOSE_READER(re, s) | |
888 return code; | |
889 } | |
890 | |
1147 | 891 //#define TRACE |
892 | |
893 #ifdef TRACE | |
894 static inline void print_bin(int bits, int n){ | |
895 int i; | |
2967 | 896 |
1147 | 897 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
|
898 av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1); |
1147 | 899 } |
900 for(i=n; i<24; i++) | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
901 av_log(NULL, AV_LOG_DEBUG, " "); |
1147 | 902 } |
903 | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
904 static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ |
1147 | 905 int r= get_bits(s, n); |
2967 | 906 |
1147 | 907 print_bin(r, n); |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
908 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 | 909 return r; |
910 } | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
911 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 | 912 int show= show_bits(s, 24); |
913 int pos= get_bits_count(s); | |
914 int r= get_vlc2(s, table, bits, max_depth); | |
915 int len= get_bits_count(s) - pos; | |
916 int bits2= show>>(24-len); | |
2967 | 917 |
1147 | 918 print_bin(bits2, len); |
2967 | 919 |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
920 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line); |
1147 | 921 return r; |
922 } | |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
923 static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ |
1273 | 924 int show= show_bits(s, n); |
925 int r= get_xbits(s, n); | |
2967 | 926 |
1273 | 927 print_bin(show, n); |
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
928 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 | 929 return r; |
930 } | |
1147 | 931 |
932 #define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
933 #define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
1273 | 934 #define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__) |
1152 | 935 #define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__) |
1147 | 936 #define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__) |
937 | |
1940 | 938 #define tprintf(...) av_log(NULL, AV_LOG_DEBUG, __VA_ARGS__) |
1170 | 939 |
940 #else //TRACE | |
1824 | 941 #define tprintf(...) {} |
1170 | 942 #endif |
542 | 943 |
2467 | 944 static inline int decode012(GetBitContext *gb){ |
2464 | 945 int n; |
946 n = get_bits1(gb); | |
947 if (n == 0) | |
948 return 0; | |
949 else | |
950 return get_bits1(gb) + 1; | |
951 } | |
952 | |
2398
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2391
diff
changeset
|
953 #endif /* BITSTREAM_H */ |