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