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