Mercurial > libavcodec.hg
annotate bitstream.h @ 9396:bb9f74aa37ee libavcodec
Get rid of INIT_VLC_USE_STATIC in msmpeg4
| author | michael |
|---|---|
| date | Sat, 11 Apr 2009 13:29:05 +0000 |
| parents | 14e8350b27b4 |
| children | 9a1c34f662e4 |
| 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 /** |
|
8718
e9d9d946f213
Use full internal pathname in doxygen @file directives.
diego
parents:
8666
diff
changeset
|
22 * @file libavcodec/bitstream.h |
|
2398
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 | |
| 7760 | 26 #ifndef AVCODEC_BITSTREAM_H |
| 27 #define AVCODEC_BITSTREAM_H | |
| 64 | 28 |
| 5162 | 29 #include <stdint.h> |
| 30 #include <stdlib.h> | |
| 31 #include <assert.h> | |
| 6763 | 32 #include "libavutil/bswap.h" |
| 33 #include "libavutil/common.h" | |
| 34 #include "libavutil/intreadwrite.h" | |
| 35 #include "libavutil/log.h" | |
| 9098 | 36 #include "mathops.h" |
|
3648
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
37 |
| 3649 | 38 #if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER) |
| 5462 | 39 # define ALT_BITSTREAM_READER |
| 3649 | 40 #endif |
| 41 | |
|
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
|
42 //#define ALT_BITSTREAM_WRITER |
|
235
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
43 //#define ALIGNED_BITSTREAM_WRITER |
| 3628 | 44 #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER) |
| 8590 | 45 # if ARCH_ARM |
|
3650
a74c0aaf9832
use the A32_BITSTREAM_READER by default on ARM (faster)
aurel
parents:
3649
diff
changeset
|
46 # define A32_BITSTREAM_READER |
|
a74c0aaf9832
use the A32_BITSTREAM_READER by default on ARM (faster)
aurel
parents:
3649
diff
changeset
|
47 # else |
| 5462 | 48 # define ALT_BITSTREAM_READER |
|
520
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
49 //#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
|
50 //#define A32_BITSTREAM_READER |
|
3650
a74c0aaf9832
use the A32_BITSTREAM_READER by default on ARM (faster)
aurel
parents:
3649
diff
changeset
|
51 # endif |
| 3628 | 52 #endif |
| 2967 | 53 |
| 2578 | 54 extern const uint8_t ff_reverse[256]; |
| 55 | |
| 8590 | 56 #if ARCH_X86 |
| 525 | 57 // avoid +32 for shift optimization (gcc should do that ...) |
| 58 static inline int32_t NEG_SSR32( int32_t a, int8_t s){ | |
| 8031 | 59 __asm__ ("sarl %1, %0\n\t" |
| 525 | 60 : "+r" (a) |
| 61 : "ic" ((uint8_t)(-s)) | |
| 62 ); | |
| 63 return a; | |
| 64 } | |
| 65 static inline uint32_t NEG_USR32(uint32_t a, int8_t s){ | |
| 8031 | 66 __asm__ ("shrl %1, %0\n\t" |
| 525 | 67 : "+r" (a) |
| 68 : "ic" ((uint8_t)(-s)) | |
| 69 ); | |
| 70 return a; | |
| 71 } | |
|
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
|
72 #else |
|
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
73 # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s))) |
|
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
74 # 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
|
75 #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
|
76 |
| 0 | 77 /* bit output */ |
| 78 | |
|
1895
e5687117cc7f
* removing casualties of battle of the wits and English language
romansh
parents:
1886
diff
changeset
|
79 /* buf and buf_end must be present and used by every alternative writer. */ |
| 0 | 80 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
|
81 #ifdef ALT_BITSTREAM_WRITER |
| 1064 | 82 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
|
83 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
|
84 #else |
| 1064 | 85 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
|
86 int bit_left; |
| 1064 | 87 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
|
88 #endif |
| 8746 | 89 int size_in_bits; |
| 0 | 90 } PutBitContext; |
| 91 | |
| 9389 | 92 /** |
| 93 * Initializes the PutBitContext \p s. | |
| 94 * | |
| 95 * @param buffer the buffer where to put bits | |
| 96 * @param buffer_size the size in bytes of \p buffer | |
| 97 */ | |
|
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
98 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
|
99 { |
|
2894
26f8974c3d66
fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents:
2889
diff
changeset
|
100 if(buffer_size < 0) { |
|
26f8974c3d66
fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents:
2889
diff
changeset
|
101 buffer_size = 0; |
|
26f8974c3d66
fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents:
2889
diff
changeset
|
102 buffer = NULL; |
|
26f8974c3d66
fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents:
2889
diff
changeset
|
103 } |
| 2889 | 104 |
| 8746 | 105 s->size_in_bits= 8*buffer_size; |
|
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
106 s->buf = buffer; |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
107 s->buf_end = s->buf + buffer_size; |
|
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 s->index=0; |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
110 ((uint32_t*)(s->buf))[0]=0; |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
111 // memset(buffer, 0, buffer_size); |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
112 #else |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
113 s->buf_ptr = s->buf; |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
114 s->bit_left=32; |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
115 s->bit_buf=0; |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
116 #endif |
|
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 |
| 9390 | 119 /** |
| 9395 | 120 * Returns the total number of bits written to the bitstream. |
| 9390 | 121 */ |
|
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
122 static inline int put_bits_count(PutBitContext *s) |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
123 { |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
124 #ifdef ALT_BITSTREAM_WRITER |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
125 return s->index; |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
126 #else |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
127 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
|
128 #endif |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
129 } |
|
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
|
130 |
| 9391 | 131 /** |
| 132 * Pads the end of the output stream with zeros. | |
| 133 */ | |
|
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
134 static inline void flush_put_bits(PutBitContext *s) |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
135 { |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
136 #ifdef ALT_BITSTREAM_WRITER |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
137 align_put_bits(s); |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
138 #else |
| 7690 | 139 #ifndef BITSTREAM_WRITER_LE |
|
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
140 s->bit_buf<<= s->bit_left; |
| 7690 | 141 #endif |
|
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
142 while (s->bit_left < 32) { |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
143 /* XXX: should test end of buffer */ |
| 7690 | 144 #ifdef BITSTREAM_WRITER_LE |
| 145 *s->buf_ptr++=s->bit_buf; | |
| 146 s->bit_buf>>=8; | |
| 147 #else | |
|
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
148 *s->buf_ptr++=s->bit_buf >> 24; |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
149 s->bit_buf<<=8; |
| 7690 | 150 #endif |
|
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
151 s->bit_left+=8; |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
152 } |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
153 s->bit_left=32; |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
154 s->bit_buf=0; |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
155 #endif |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
156 } |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
157 |
| 9392 | 158 /** |
| 159 * Pads the bitstream with zeros up to the next byte boundary. | |
| 160 */ | |
| 0 | 161 void align_put_bits(PutBitContext *s); |
| 6325 | 162 void ff_put_string(PutBitContext * pbc, const char *s, int put_zero); |
| 163 void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length); | |
| 0 | 164 |
| 165 /* bit input */ | |
|
1895
e5687117cc7f
* removing casualties of battle of the wits and English language
romansh
parents:
1886
diff
changeset
|
166 /* buffer, buffer_end and size_in_bits must be present and used by every reader */ |
| 0 | 167 typedef struct GetBitContext { |
| 1083 | 168 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
|
169 #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
|
170 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
|
171 #elif defined LIBMPEG2_BITSTREAM_READER |
| 1064 | 172 uint8_t *buffer_ptr; |
| 173 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
|
174 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
|
175 #elif defined A32_BITSTREAM_READER |
| 1064 | 176 uint32_t *buffer_ptr; |
| 177 uint32_t cache0; | |
| 178 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
|
179 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
|
180 #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
|
181 int size_in_bits; |
| 0 | 182 } GetBitContext; |
| 183 | |
| 1064 | 184 #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
|
185 |
| 0 | 186 typedef struct VLC { |
| 187 int bits; | |
|
1112
54be6aece1be
more cosmetics so that doxygen output is readable ...
michaelni
parents:
1106
diff
changeset
|
188 VLC_TYPE (*table)[2]; ///< code, bits |
| 0 | 189 int table_size, table_allocated; |
| 190 } VLC; | |
| 191 | |
| 542 | 192 typedef struct RL_VLC_ELEM { |
| 193 int16_t level; | |
| 194 int8_t len; | |
| 195 uint8_t run; | |
| 196 } RL_VLC_ELEM; | |
| 197 | |
|
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
|
198 #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
|
199 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
|
200 { |
|
99a9f903f0e3
optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents:
235
diff
changeset
|
201 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
|
202 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
|
203 |
|
99a9f903f0e3
optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents:
235
diff
changeset
|
204 // 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
|
205 assert(n == 32 || value < (1U << n)); |
| 2967 | 206 |
|
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
|
207 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
|
208 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
|
209 |
|
99a9f903f0e3
optimized the normal bitstream writer, its faster than the alternative one on p3 now ... lets hope its at least not slower on p4 & k7
michaelni
parents:
235
diff
changeset
|
210 // printf("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
|
211 /* XXX: optimize */ |
| 7690 | 212 #ifdef BITSTREAM_WRITER_LE |
| 213 bit_buf |= value << (32 - bit_left); | |
| 214 if (n >= bit_left) { | |
| 8590 | 215 #if !HAVE_FAST_UNALIGNED |
| 7690 | 216 if (3 & (intptr_t) s->buf_ptr) { |
| 8666 | 217 AV_WL32(s->buf_ptr, bit_buf); |
| 7690 | 218 } else |
| 219 #endif | |
| 220 *(uint32_t *)s->buf_ptr = le2me_32(bit_buf); | |
| 221 s->buf_ptr+=4; | |
| 222 bit_buf = (bit_left==32)?0:value >> bit_left; | |
| 223 bit_left+=32; | |
| 224 } | |
| 225 bit_left-=n; | |
| 226 #else | |
|
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
|
227 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
|
228 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
|
229 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
|
230 } else { |
| 2979 | 231 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
|
232 bit_buf |= value >> (n - bit_left); |
| 8590 | 233 #if !HAVE_FAST_UNALIGNED |
|
1965
f74f306c30b5
vis detection patch by (James Morrison <ja2morri at csclub dot uwaterloo dot ca>)
michael
parents:
1964
diff
changeset
|
234 if (3 & (intptr_t) s->buf_ptr) { |
| 8666 | 235 AV_WB32(s->buf_ptr, bit_buf); |
| 891 | 236 } else |
| 237 #endif | |
| 1064 | 238 *(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
|
239 //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
|
240 s->buf_ptr+=4; |
| 2979 | 241 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
|
242 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
|
243 } |
| 7690 | 244 #endif |
|
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
|
245 |
|
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
|
246 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
|
247 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
|
248 } |
|
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
|
249 #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
|
250 |
|
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
|
251 |
|
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
|
252 #ifdef ALT_BITSTREAM_WRITER |
|
235
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
253 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
|
254 { |
|
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
255 # ifdef ALIGNED_BITSTREAM_WRITER |
| 8590 | 256 # if ARCH_X86 |
| 8031 | 257 __asm__ volatile( |
| 2979 | 258 "movl %0, %%ecx \n\t" |
| 259 "xorl %%eax, %%eax \n\t" | |
| 260 "shrdl %%cl, %1, %%eax \n\t" | |
| 261 "shrl %%cl, %1 \n\t" | |
| 262 "movl %0, %%ecx \n\t" | |
| 263 "shrl $3, %%ecx \n\t" | |
| 264 "andl $0xFFFFFFFC, %%ecx \n\t" | |
| 265 "bswapl %1 \n\t" | |
| 266 "orl %1, (%2, %%ecx) \n\t" | |
| 267 "bswapl %%eax \n\t" | |
| 268 "addl %3, %0 \n\t" | |
| 269 "movl %%eax, 4(%2, %%ecx) \n\t" | |
| 270 : "=&r" (s->index), "=&r" (value) | |
| 271 : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n)) | |
| 272 : "%eax", "%ecx" | |
|
235
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
273 ); |
|
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
274 # else |
|
235
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
275 int index= s->index; |
|
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
276 uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5); |
| 2967 | 277 |
| 278 value<<= 32-n; | |
| 279 | |
|
235
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
280 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
|
281 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
|
282 //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
|
283 index+= n; |
|
41f0ef2cd942
aligned bitstream writer (1% slower on p3 but perhaps its faster on p4?)
michaelni
parents:
234
diff
changeset
|
284 s->index= index; |
|
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
285 # endif |
|
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
286 # else //ALIGNED_BITSTREAM_WRITER |
| 8590 | 287 # if ARCH_X86 |
| 8031 | 288 __asm__ volatile( |
| 2979 | 289 "movl $7, %%ecx \n\t" |
| 290 "andl %0, %%ecx \n\t" | |
| 291 "addl %3, %%ecx \n\t" | |
| 292 "negl %%ecx \n\t" | |
| 293 "shll %%cl, %1 \n\t" | |
| 294 "bswapl %1 \n\t" | |
| 295 "movl %0, %%ecx \n\t" | |
| 296 "shrl $3, %%ecx \n\t" | |
| 297 "orl %1, (%%ecx, %2) \n\t" | |
| 298 "addl %3, %0 \n\t" | |
| 299 "movl $0, 4(%%ecx, %2) \n\t" | |
| 300 : "=&r" (s->index), "=&r" (value) | |
| 301 : "r" (s->buf), "r" (n), "0" (s->index), "1" (value) | |
| 302 : "%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
|
303 ); |
|
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
304 # 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
|
305 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
|
306 uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3)); |
| 2967 | 307 |
|
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
|
308 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
|
309 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
|
310 //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
|
311 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
|
312 s->index= index; |
|
708
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
313 # endif |
|
1aa1cbb8c3c1
indenting preprocessor stuff, as its completly unreadable otherwise
michaelni
parents:
706
diff
changeset
|
314 # 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
|
315 } |
|
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
|
316 #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
|
317 |
|
7260
3ec34b551aae
bitstream: move put_sbits() from flacenc.c to bitstream.h and use it
ramiro
parents:
7254
diff
changeset
|
318 static inline void put_sbits(PutBitContext *pb, int bits, int32_t val) |
|
3ec34b551aae
bitstream: move put_sbits() from flacenc.c to bitstream.h and use it
ramiro
parents:
7254
diff
changeset
|
319 { |
|
3ec34b551aae
bitstream: move put_sbits() from flacenc.c to bitstream.h and use it
ramiro
parents:
7254
diff
changeset
|
320 assert(bits >= 0 && bits <= 31); |
|
3ec34b551aae
bitstream: move put_sbits() from flacenc.c to bitstream.h and use it
ramiro
parents:
7254
diff
changeset
|
321 |
|
3ec34b551aae
bitstream: move put_sbits() from flacenc.c to bitstream.h and use it
ramiro
parents:
7254
diff
changeset
|
322 put_bits(pb, bits, val & ((1<<bits)-1)); |
|
3ec34b551aae
bitstream: move put_sbits() from flacenc.c to bitstream.h and use it
ramiro
parents:
7254
diff
changeset
|
323 } |
|
3ec34b551aae
bitstream: move put_sbits() from flacenc.c to bitstream.h and use it
ramiro
parents:
7254
diff
changeset
|
324 |
|
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
|
325 |
|
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
|
326 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
|
327 { |
|
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
|
328 #ifdef ALT_BITSTREAM_WRITER |
| 2979 | 329 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
|
330 #else |
| 2979 | 331 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
|
332 #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
|
333 } |
|
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
|
334 |
| 1799 | 335 /** |
| 336 * | |
| 337 * PutBitContext must be flushed & aligned to a byte boundary before calling this. | |
| 338 */ | |
| 339 static inline void skip_put_bytes(PutBitContext *s, int n){ | |
| 340 assert((put_bits_count(s)&7)==0); | |
| 341 #ifdef ALT_BITSTREAM_WRITER | |
| 342 FIXME may need some cleaning of the buffer | |
| 2979 | 343 s->index += n<<3; |
| 1799 | 344 #else |
| 345 assert(s->bit_left==32); | |
| 2979 | 346 s->buf_ptr += n; |
| 2967 | 347 #endif |
| 1799 | 348 } |
| 349 | |
| 350 /** | |
| 5127 | 351 * Skips the given number of bits. |
| 352 * Must only be used if the actual values in the bitstream do not matter. | |
|
9320
fec13de9a1f2
Add a notice telling that the behavior of skip_put_bits() is undefined
stefano
parents:
9098
diff
changeset
|
353 * If \p n is 0 the behavior is undefined. |
| 2502 | 354 */ |
| 355 static inline void skip_put_bits(PutBitContext *s, int n){ | |
| 356 #ifdef ALT_BITSTREAM_WRITER | |
| 357 s->index += n; | |
| 358 #else | |
| 359 s->bit_left -= n; | |
| 360 s->buf_ptr-= s->bit_left>>5; | |
| 361 s->bit_left &= 31; | |
| 2967 | 362 #endif |
| 2502 | 363 } |
| 364 | |
| 365 /** | |
| 1799 | 366 * Changes the end of the buffer. |
| 367 */ | |
| 368 static inline void set_put_bits_buffer_size(PutBitContext *s, int size){ | |
| 369 s->buf_end= s->buf + size; | |
| 370 } | |
| 371 | |
|
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
|
372 /* 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
|
373 name |
| 7731 | 374 arbitrary name which is used as prefix for the internal variables |
|
520
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
375 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
376 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
|
377 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
|
378 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
379 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
|
380 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
|
381 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
382 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
|
383 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
|
384 |
|
19a5e2a81e1a
new bitstream reader 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 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
|
386 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
|
387 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
|
388 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
389 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
|
390 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
|
391 |
|
19a5e2a81e1a
new bitstream reader 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 SHOW_UBITS(name, gb, num) |
| 2764 | 393 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
|
394 |
|
19a5e2a81e1a
new bitstream reader 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 SHOW_SBITS(name, gb, num) |
| 2764 | 396 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
|
397 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
398 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
|
399 will skip over the next num bits |
| 2764 | 400 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
|
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 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
|
403 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
|
404 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
405 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
|
406 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
|
407 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
408 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
|
409 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
|
410 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
411 LAST_SKIP_BITS(name, gb, num) |
| 2764 | 412 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
|
413 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
414 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
|
415 */ |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
416 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
417 #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
|
418 # 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
|
419 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
420 # define 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
|
421 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
|
422 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
|
423 |
|
19a5e2a81e1a
new bitstream reader 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 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
|
425 (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
|
426 |
|
2663
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
427 # ifdef ALT_BITSTREAM_READER_LE |
|
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
428 # define UPDATE_CACHE(name, gb)\ |
| 5512 | 429 name##_cache= AV_RL32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\ |
|
2663
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
430 |
|
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
431 # 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
|
432 name##_cache >>= (num); |
|
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
433 # 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
|
434 # define UPDATE_CACHE(name, gb)\ |
| 5512 | 435 name##_cache= AV_RB32( ((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
|
436 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
437 # 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
|
438 name##_cache <<= (num); |
|
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
439 # 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
|
440 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
441 // 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
|
442 # 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
|
443 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
|
444 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
445 # define 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
|
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 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
|
448 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 }\ |
|
19a5e2a81e1a
new bitstream reader 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 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
|
452 # 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
|
453 |
|
2663
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
454 # ifdef ALT_BITSTREAM_READER_LE |
|
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
455 # 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
|
456 ((name##_cache) & (NEG_USR32(0xffffffff,num))) |
|
4005
3ccdff1e5221
fix SHOW_SBITS for ALT_BITSTREAM_READER_LE, patch by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
3947
diff
changeset
|
457 |
|
3ccdff1e5221
fix SHOW_SBITS for ALT_BITSTREAM_READER_LE, patch by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
3947
diff
changeset
|
458 # define SHOW_SBITS(name, gb, num)\ |
|
3ccdff1e5221
fix SHOW_SBITS for ALT_BITSTREAM_READER_LE, patch by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
3947
diff
changeset
|
459 NEG_SSR32((name##_cache)<<(32-(num)), num) |
|
2663
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
460 # 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
|
461 # define SHOW_UBITS(name, gb, num)\ |
| 525 | 462 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
|
463 |
|
19a5e2a81e1a
new bitstream reader 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_SBITS(name, gb, num)\ |
| 525 | 465 NEG_SSR32(name##_cache, num) |
|
4005
3ccdff1e5221
fix SHOW_SBITS for ALT_BITSTREAM_READER_LE, patch by Gregory Montoir %cyx A users P sourceforge P net%
bcoudurier
parents:
3947
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 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
|
469 ((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
|
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 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
|
472 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
|
473 } |
|
3629
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
474 |
|
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
475 static inline void skip_bits_long(GetBitContext *s, int n){ |
| 3633 | 476 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
|
477 } |
|
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
478 |
|
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
|
479 #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
|
480 //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
|
481 |
|
1263
9fce515e9894
libmpeg2 style bitstream reader 17 vs 16 bit bugfix
michaelni
parents:
1261
diff
changeset
|
482 # 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
|
483 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
484 # define 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
|
485 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
|
486 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
|
487 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
|
488 |
|
19a5e2a81e1a
new bitstream reader 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 # 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
|
490 (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
|
491 (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
|
492 (gb)->buffer_ptr= name##_buffer_ptr;\ |
| 0 | 493 |
|
1254
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
494 # define UPDATE_CACHE(name, gb)\ |
|
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
495 if(name##_bit_count >= 0){\ |
| 7254 | 496 name##_cache+= AV_RB16(name##_buffer_ptr) << 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
|
497 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
|
498 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
|
499 }\ |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
500 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
501 # 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
|
502 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
|
503 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
504 # 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
|
505 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
|
506 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
507 # define 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
|
508 {\ |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
509 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
|
510 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
|
511 }\ |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
512 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
513 # define 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
|
514 # 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
|
515 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
516 # define SHOW_UBITS(name, gb, num)\ |
| 525 | 517 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
|
518 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
519 # define SHOW_SBITS(name, gb, num)\ |
| 525 | 520 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
|
521 |
|
19a5e2a81e1a
new bitstream reader 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 # 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
|
523 ((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
|
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 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
|
526 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
|
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 |
| 3633 | 529 static inline void skip_bits_long(GetBitContext *s, int n){ |
| 530 OPEN_READER(re, s) | |
| 531 re_bit_count += n; | |
| 532 re_buffer_ptr += 2*(re_bit_count>>4); | |
| 533 re_bit_count &= 15; | |
| 534 re_cache = ((re_buffer_ptr[-2]<<8) + re_buffer_ptr[-1]) << (16+re_bit_count); | |
| 535 UPDATE_CACHE(re, s) | |
| 536 CLOSE_READER(re, s) | |
| 537 } | |
| 538 | |
|
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
|
539 #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
|
540 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
541 # define 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
|
542 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
543 # define 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
|
544 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
|
545 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
|
546 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
|
547 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
|
548 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
549 # 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
|
550 (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
|
551 (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
|
552 (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
|
553 (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
|
554 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
555 # define 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
|
556 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
|
557 const uint32_t next= be2me_32( *name##_buffer_ptr );\ |
| 525 | 558 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
|
559 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
|
560 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
|
561 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
|
562 }\ |
|
19a5e2a81e1a
new bitstream reader 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 |
| 8590 | 564 #if ARCH_X86 |
|
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
|
565 # define SKIP_CACHE(name, gb, num)\ |
| 8031 | 566 __asm__(\ |
| 2979 | 567 "shldl %2, %1, %0 \n\t"\ |
| 568 "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
|
569 : "+r" (name##_cache0), "+r" (name##_cache1)\ |
| 3638 | 570 : "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
|
571 ); |
|
19a5e2a81e1a
new bitstream reader 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 #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
|
573 # 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
|
574 name##_cache0 <<= (num);\ |
| 525 | 575 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
|
576 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
|
577 #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
|
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 # 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
|
580 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
|
581 |
|
19a5e2a81e1a
new bitstream reader 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 # 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
|
583 {\ |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
584 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
|
585 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
|
586 }\ |
|
19a5e2a81e1a
new bitstream reader 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 # 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
|
589 # 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
|
590 |
|
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
591 # define SHOW_UBITS(name, gb, num)\ |
| 525 | 592 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
|
593 |
|
19a5e2a81e1a
new bitstream reader 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 # define SHOW_SBITS(name, gb, num)\ |
| 525 | 595 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
|
596 |
|
19a5e2a81e1a
new bitstream reader 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 # 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
|
598 (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
|
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 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
|
601 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
|
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 |
|
3629
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
604 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
|
605 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
|
606 re_bit_count += n; |
| 3631 | 607 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
|
608 re_bit_count &= 31; |
| 3630 | 609 re_cache0 = be2me_32( re_buffer_ptr[-1] ) << re_bit_count; |
| 610 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
|
611 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
|
612 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
|
613 } |
|
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
614 |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
615 #endif |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
616 |
| 1257 | 617 /** |
| 618 * read mpeg1 dc style vlc (sign bit + mantisse with no MSB). | |
| 2967 | 619 * if MSB not set it is negative |
| 1257 | 620 * @param n length in bits |
| 2967 | 621 * @author BERO |
| 1257 | 622 */ |
|
1254
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
623 static inline int get_xbits(GetBitContext *s, int n){ |
| 3244 | 624 register int sign; |
|
1254
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
625 register int32_t cache; |
|
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
626 OPEN_READER(re, s) |
|
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
627 UPDATE_CACHE(re, s) |
|
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
628 cache = GET_CACHE(re,s); |
| 3244 | 629 sign=(~cache)>>31; |
|
1254
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
630 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
|
631 CLOSE_READER(re, s) |
| 3244 | 632 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
|
633 } |
|
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
634 |
|
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
635 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
|
636 register int tmp; |
|
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
637 OPEN_READER(re, s) |
|
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
638 UPDATE_CACHE(re, s) |
|
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
639 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
|
640 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
|
641 CLOSE_READER(re, s) |
|
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
642 return tmp; |
|
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
643 } |
|
604661d34c68
bitstream reader optimize patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1226
diff
changeset
|
644 |
| 1257 | 645 /** |
| 4548 | 646 * reads 1-17 bits. |
| 2764 | 647 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't |
| 1257 | 648 */ |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
649 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
|
650 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
|
651 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
|
652 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
|
653 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
|
654 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
|
655 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
|
656 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
|
657 } |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
658 |
| 1257 | 659 /** |
| 4548 | 660 * shows 1-17 bits. |
| 2764 | 661 * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't |
| 1257 | 662 */ |
|
520
19a5e2a81e1a
new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents:
517
diff
changeset
|
663 static inline unsigned int show_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
|
664 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
|
665 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
|
666 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
|
667 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
|
668 // 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
|
669 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
|
670 } |
|
19a5e2a81e1a
new bitstream reader 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 |
|
19a5e2a81e1a
new bitstream reader 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 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
|
673 //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
|
674 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
|
675 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
|
676 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
|
677 CLOSE_READER(re, s) |
|
20
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
678 } |
|
907b67420d84
inlineing common case of get_bits() -> gives 2speedup. more optim coming soon...
arpi_esp
parents:
10
diff
changeset
|
679 |
| 21 | 680 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
|
681 #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
|
682 int index= s->index; |
|
193
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
683 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
|
684 #ifdef ALT_BITSTREAM_READER_LE |
|
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
685 result>>= (index&0x07); |
|
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
686 result&= 1; |
|
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
687 #else |
|
199
0f1dba8fc617
(commited by michael / arpi was crazy enough to give me his password)
arpi_esp
parents:
193
diff
changeset
|
688 result<<= (index&0x07); |
|
0f1dba8fc617
(commited by michael / arpi was crazy enough to give me his password)
arpi_esp
parents:
193
diff
changeset
|
689 result>>= 8 - 1; |
|
2663
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
690 #endif |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
691 index++; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
692 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
|
693 |
|
192
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
694 return result; |
|
1e5f64be86fc
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
151
diff
changeset
|
695 #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
|
696 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
|
697 #endif |
| 21 | 698 } |
| 699 | |
|
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
|
700 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
|
701 return show_bits(s, 1); |
| 21 | 702 } |
| 703 | |
| 704 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
|
705 skip_bits(s, 1); |
| 21 | 706 } |
| 707 | |
|
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
708 /** |
|
3648
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
709 * reads 0-32 bits. |
|
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
710 */ |
|
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
711 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
|
712 if(n<=17) return get_bits(s, n); |
|
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
713 else{ |
|
3760
dbe7b99efdbf
Fix get_bits_long to work with ALT_BITSTREAM_READER_LE.
reimar
parents:
3699
diff
changeset
|
714 #ifdef ALT_BITSTREAM_READER_LE |
|
dbe7b99efdbf
Fix get_bits_long to work with ALT_BITSTREAM_READER_LE.
reimar
parents:
3699
diff
changeset
|
715 int ret= get_bits(s, 16); |
|
dbe7b99efdbf
Fix get_bits_long to work with ALT_BITSTREAM_READER_LE.
reimar
parents:
3699
diff
changeset
|
716 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
|
717 #else |
|
3648
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
718 int ret= get_bits(s, 16) << (n-16); |
|
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
719 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
|
720 #endif |
|
3648
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
721 } |
|
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
722 } |
|
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
723 |
|
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
724 /** |
| 9098 | 725 * reads 0-32 bits as a signed integer. |
| 726 */ | |
| 727 static inline int get_sbits_long(GetBitContext *s, int n) { | |
| 728 return sign_extend(get_bits_long(s, n), n); | |
| 729 } | |
| 730 | |
| 731 /** | |
|
3648
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
732 * shows 0-32 bits. |
|
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
733 */ |
|
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
734 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
|
735 if(n<=17) return show_bits(s, n); |
|
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
736 else{ |
|
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
737 GetBitContext gb= *s; |
|
9095
50e847b72cdd
Simplify show_bits_long and copy the GetBitsContext around only once instead of twice.
reimar
parents:
8746
diff
changeset
|
738 return get_bits_long(&gb, n); |
|
3648
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 |
|
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
742 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
|
743 { |
|
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
744 int bit= get_bits1(s); |
|
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
745 if(!bit) |
|
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
746 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
|
747 |
|
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
748 return bit; |
|
c44d798b06b5
move some functions to bitstream.h to avoid conflicts
aurel
parents:
3638
diff
changeset
|
749 } |
|
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 /** |
|
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
752 * init GetBitContext. |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
753 * @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
|
754 * 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
|
755 * @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
|
756 */ |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
757 static inline void init_get_bits(GetBitContext *s, |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
758 const uint8_t *buffer, int bit_size) |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
759 { |
| 2889 | 760 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
|
761 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
|
762 buffer_size = bit_size = 0; |
|
26f8974c3d66
fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents:
2889
diff
changeset
|
763 buffer = NULL; |
|
26f8974c3d66
fix some pointer to intger without cast warnings (patch by Michel Bardiaux)
aurel
parents:
2889
diff
changeset
|
764 } |
|
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
765 |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
766 s->buffer= buffer; |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
767 s->size_in_bits= bit_size; |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
768 s->buffer_end= buffer + buffer_size; |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
769 #ifdef ALT_BITSTREAM_READER |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
770 s->index=0; |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
771 #elif defined LIBMPEG2_BITSTREAM_READER |
| 3633 | 772 s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1)); |
| 773 s->bit_count = 16 + 8*((intptr_t)buffer&1); | |
| 774 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
|
775 #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
|
776 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
|
777 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
|
778 skip_bits_long(s, 0); |
|
1875
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
779 #endif |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
780 } |
|
45a1592dadca
* moving some of the commonly used bit reading/writing functions
romansh
parents:
1845
diff
changeset
|
781 |
| 3675 | 782 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
|
783 { |
|
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
784 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
|
785 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
|
786 } |
|
2ab6ec6259b1
move align_get_bits() to .h to avoid conflicts between different bitstream readers in different codecs
michael
parents:
3628
diff
changeset
|
787 |
|
5071
0d503c12092b
add init_vlc_sparse(). faster than init_vlc() if there are lots of holes in the tables.
lorenm
parents:
4875
diff
changeset
|
788 #define init_vlc(vlc, nb_bits, nb_codes,\ |
|
0d503c12092b
add init_vlc_sparse(). faster than init_vlc() if there are lots of holes in the tables.
lorenm
parents:
4875
diff
changeset
|
789 bits, bits_wrap, bits_size,\ |
|
0d503c12092b
add init_vlc_sparse(). faster than init_vlc() if there are lots of holes in the tables.
lorenm
parents:
4875
diff
changeset
|
790 codes, codes_wrap, codes_size,\ |
|
0d503c12092b
add init_vlc_sparse(). faster than init_vlc() if there are lots of holes in the tables.
lorenm
parents:
4875
diff
changeset
|
791 flags)\ |
|
0d503c12092b
add init_vlc_sparse(). faster than init_vlc() if there are lots of holes in the tables.
lorenm
parents:
4875
diff
changeset
|
792 init_vlc_sparse(vlc, nb_bits, nb_codes,\ |
|
0d503c12092b
add init_vlc_sparse(). faster than init_vlc() if there are lots of holes in the tables.
lorenm
parents:
4875
diff
changeset
|
793 bits, bits_wrap, bits_size,\ |
|
0d503c12092b
add init_vlc_sparse(). faster than init_vlc() if there are lots of holes in the tables.
lorenm
parents:
4875
diff
changeset
|
794 codes, codes_wrap, codes_size,\ |
|
0d503c12092b
add init_vlc_sparse(). faster than init_vlc() if there are lots of holes in the tables.
lorenm
parents:
4875
diff
changeset
|
795 NULL, 0, 0, flags) |
|
0d503c12092b
add init_vlc_sparse(). faster than init_vlc() if there are lots of holes in the tables.
lorenm
parents:
4875
diff
changeset
|
796 |
|
0d503c12092b
add init_vlc_sparse(). faster than init_vlc() if there are lots of holes in the tables.
lorenm
parents:
4875
diff
changeset
|
797 int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, |
| 0 | 798 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
|
799 const void *codes, int codes_wrap, int codes_size, |
|
5071
0d503c12092b
add init_vlc_sparse(). faster than init_vlc() if there are lots of holes in the tables.
lorenm
parents:
4875
diff
changeset
|
800 const void *symbols, int symbols_wrap, int symbols_size, |
|
2663
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
801 int flags); |
|
6935
24e01f7cc819
Make init_vlc* support proper static tables instead of this broken beyond
michael
parents:
6763
diff
changeset
|
802 #define INIT_VLC_USE_STATIC 1 ///< VERY strongly deprecated and forbidden |
|
2663
b33be8b00488
LE bitstream reader based upon a patch by (Balatoni Denes <dbalatoni programozo hu)
michael
parents:
2615
diff
changeset
|
803 #define INIT_VLC_LE 2 |
|
6935
24e01f7cc819
Make init_vlc* support proper static tables instead of this broken beyond
michael
parents:
6763
diff
changeset
|
804 #define INIT_VLC_USE_NEW_STATIC 4 |
| 0 | 805 void free_vlc(VLC *vlc); |
| 806 | |
|
6936
97798862a414
Little helper macro to make the use of INIT_VLC_USE_NEW_STATIC easier.
michael
parents:
6935
diff
changeset
|
807 #define INIT_VLC_STATIC(vlc, bits, a,b,c,d,e,f,g, static_size)\ |
|
97798862a414
Little helper macro to make the use of INIT_VLC_USE_NEW_STATIC easier.
michael
parents:
6935
diff
changeset
|
808 {\ |
|
97798862a414
Little helper macro to make the use of INIT_VLC_USE_NEW_STATIC easier.
michael
parents:
6935
diff
changeset
|
809 static VLC_TYPE table[static_size][2];\ |
|
97798862a414
Little helper macro to make the use of INIT_VLC_USE_NEW_STATIC easier.
michael
parents:
6935
diff
changeset
|
810 (vlc)->table= table;\ |
|
97798862a414
Little helper macro to make the use of INIT_VLC_USE_NEW_STATIC easier.
michael
parents:
6935
diff
changeset
|
811 (vlc)->table_allocated= static_size;\ |
|
97798862a414
Little helper macro to make the use of INIT_VLC_USE_NEW_STATIC easier.
michael
parents:
6935
diff
changeset
|
812 init_vlc(vlc, bits, a,b,c,d,e,f,g, INIT_VLC_USE_NEW_STATIC);\ |
|
97798862a414
Little helper macro to make the use of INIT_VLC_USE_NEW_STATIC easier.
michael
parents:
6935
diff
changeset
|
813 } |
|
97798862a414
Little helper macro to make the use of INIT_VLC_USE_NEW_STATIC easier.
michael
parents:
6935
diff
changeset
|
814 |
|
97798862a414
Little helper macro to make the use of INIT_VLC_USE_NEW_STATIC easier.
michael
parents:
6935
diff
changeset
|
815 |
|
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
|
816 /** |
|
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
|
817 * |
|
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
|
818 * 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
|
819 * 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
|
820 * 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
|
821 */ |
| 529 | 822 #define GET_VLC(code, name, gb, table, bits, max_depth)\ |
| 823 {\ | |
| 824 int n, index, nb_bits;\ | |
| 825 \ | |
| 826 index= SHOW_UBITS(name, gb, bits);\ | |
| 827 code = table[index][0];\ | |
| 828 n = table[index][1];\ | |
| 829 \ | |
| 830 if(max_depth > 1 && n < 0){\ | |
| 831 LAST_SKIP_BITS(name, gb, 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 if(max_depth > 2 && n < 0){\ | |
| 840 LAST_SKIP_BITS(name, gb, nb_bits)\ | |
| 841 UPDATE_CACHE(name, gb)\ | |
| 842 \ | |
| 843 nb_bits = -n;\ | |
| 844 \ | |
| 535 | 845 index= SHOW_UBITS(name, gb, nb_bits) + code;\ |
| 529 | 846 code = table[index][0];\ |
| 847 n = table[index][1];\ | |
| 848 }\ | |
| 849 }\ | |
| 850 SKIP_BITS(name, gb, n)\ | |
| 851 } | |
| 852 | |
|
2615
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2614
diff
changeset
|
853 #define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\ |
| 542 | 854 {\ |
| 855 int n, index, nb_bits;\ | |
| 856 \ | |
| 857 index= SHOW_UBITS(name, gb, bits);\ | |
| 858 level = table[index].level;\ | |
| 859 n = table[index].len;\ | |
| 860 \ | |
| 861 if(max_depth > 1 && n < 0){\ | |
|
2615
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2614
diff
changeset
|
862 SKIP_BITS(name, gb, bits)\ |
|
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2614
diff
changeset
|
863 if(need_update){\ |
|
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2614
diff
changeset
|
864 UPDATE_CACHE(name, gb)\ |
|
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2614
diff
changeset
|
865 }\ |
| 542 | 866 \ |
| 867 nb_bits = -n;\ | |
| 868 \ | |
| 869 index= SHOW_UBITS(name, gb, nb_bits) + level;\ | |
| 870 level = table[index].level;\ | |
| 871 n = table[index].len;\ | |
| 872 }\ | |
| 873 run= table[index].run;\ | |
| 874 SKIP_BITS(name, gb, n)\ | |
| 875 } | |
| 876 | |
|
193
b691dd3e9088
aligned bitstream support (optional) - patch by ichael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
192
diff
changeset
|
877 |
| 1079 | 878 /** |
| 879 * parses a vlc code, faster then get_vlc() | |
| 2967 | 880 * @param bits is the number of bits which will be read at once, must be |
| 1079 | 881 * identical to nb_bits in init_vlc() |
| 4795 | 882 * @param max_depth is the number of times bits bits must be read to completely |
| 2967 | 883 * read the longest vlc code |
| 1079 | 884 * = (max_vlc_length + bits - 1) / bits |
| 885 */ | |
|
4283
d6f83e2f8804
rename always_inline to av_always_inline and move to common.h
mru
parents:
4116
diff
changeset
|
886 static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2], |
| 550 | 887 int bits, int max_depth) |
| 531 | 888 { |
| 889 int code; | |
| 2967 | 890 |
| 531 | 891 OPEN_READER(re, s) |
| 892 UPDATE_CACHE(re, s) | |
| 893 | |
| 894 GET_VLC(code, re, s, table, bits, max_depth) | |
| 895 | |
| 896 CLOSE_READER(re, s) | |
| 897 return code; | |
| 898 } | |
| 899 | |
| 1147 | 900 //#define TRACE |
| 901 | |
| 902 #ifdef TRACE | |
| 903 static inline void print_bin(int bits, int n){ | |
| 904 int i; | |
| 2967 | 905 |
| 1147 | 906 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
|
907 av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1); |
| 1147 | 908 } |
| 909 for(i=n; i<24; i++) | |
|
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
910 av_log(NULL, AV_LOG_DEBUG, " "); |
| 1147 | 911 } |
| 912 | |
|
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
913 static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ |
| 1147 | 914 int r= get_bits(s, n); |
| 2967 | 915 |
| 1147 | 916 print_bin(r, n); |
|
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
917 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 | 918 return r; |
| 919 } | |
|
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
920 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 | 921 int show= show_bits(s, 24); |
| 922 int pos= get_bits_count(s); | |
| 923 int r= get_vlc2(s, table, bits, max_depth); | |
| 924 int len= get_bits_count(s) - pos; | |
| 925 int bits2= show>>(24-len); | |
| 2967 | 926 |
| 1147 | 927 print_bin(bits2, len); |
| 2967 | 928 |
|
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
929 av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line); |
| 1147 | 930 return r; |
| 931 } | |
|
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
932 static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ |
| 1273 | 933 int show= show_bits(s, n); |
| 934 int r= get_xbits(s, n); | |
| 2967 | 935 |
| 1273 | 936 print_bin(show, n); |
|
2438
e98b5e0de86b
compile with TRACE define patch by (Loic <lll+ffmpeg m4x org>)
michael
parents:
2398
diff
changeset
|
937 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 | 938 return r; |
| 939 } | |
| 1147 | 940 |
| 941 #define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
| 942 #define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__) | |
| 1273 | 943 #define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__) |
| 1152 | 944 #define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__) |
| 1147 | 945 #define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__) |
| 946 | |
| 4600 | 947 #define tprintf(p, ...) av_log(p, AV_LOG_DEBUG, __VA_ARGS__) |
| 1170 | 948 |
| 949 #else //TRACE | |
| 4600 | 950 #define tprintf(p, ...) {} |
| 1170 | 951 #endif |
| 542 | 952 |
| 2467 | 953 static inline int decode012(GetBitContext *gb){ |
| 2464 | 954 int n; |
| 955 n = get_bits1(gb); | |
| 956 if (n == 0) | |
| 957 return 0; | |
| 958 else | |
| 959 return get_bits1(gb) + 1; | |
| 960 } | |
| 961 | |
| 6099 | 962 static inline int decode210(GetBitContext *gb){ |
| 963 if (get_bits1(gb)) | |
| 964 return 0; | |
| 965 else | |
| 966 return 2 - get_bits1(gb); | |
| 967 } | |
| 968 | |
| 7760 | 969 #endif /* AVCODEC_BITSTREAM_H */ |
