Mercurial > libavcodec.hg
comparison common.c @ 192:1e5f64be86fc libavcodec
another bitstream reader code (faster on intel cpus) - patch by Michael Niedermayer <michaelni@gmx.at>
| author | uid46427 |
|---|---|
| date | Thu, 10 Jan 2002 00:56:05 +0000 |
| parents | cb5dabd00ba2 |
| children | b691dd3e9088 |
comparison
equal
deleted
inserted
replaced
| 191:883f184537e6 | 192:1e5f64be86fc |
|---|---|
| 13 * GNU General Public License for more details. | 13 * GNU General Public License for more details. |
| 14 * | 14 * |
| 15 * You should have received a copy of the GNU General Public License | 15 * You should have received a copy of the GNU General Public License |
| 16 * along with this program; if not, write to the Free Software | 16 * along with this program; if not, write to the Free Software |
| 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 * | |
| 19 * alternative bitstream reader by Michael Niedermayer <michaelni@gmx.at> | |
| 18 */ | 20 */ |
| 19 #include "common.h" | 21 #include "common.h" |
| 20 #include <math.h> | 22 #include <math.h> |
| 21 | 23 |
| 22 void init_put_bits(PutBitContext *s, | 24 void init_put_bits(PutBitContext *s, |
| 172 /* bit input functions */ | 174 /* bit input functions */ |
| 173 | 175 |
| 174 void init_get_bits(GetBitContext *s, | 176 void init_get_bits(GetBitContext *s, |
| 175 UINT8 *buffer, int buffer_size) | 177 UINT8 *buffer, int buffer_size) |
| 176 { | 178 { |
| 179 #ifdef ALT_BITSTREAM_READER | |
| 180 s->index=0; | |
| 181 s->buffer= buffer; | |
| 182 #else | |
| 177 s->buf = buffer; | 183 s->buf = buffer; |
| 178 s->buf_ptr = buffer; | 184 s->buf_ptr = buffer; |
| 179 s->buf_end = buffer + buffer_size; | 185 s->buf_end = buffer + buffer_size; |
| 180 s->bit_cnt = 0; | 186 s->bit_cnt = 0; |
| 181 s->bit_buf = 0; | 187 s->bit_buf = 0; |
| 182 while (s->buf_ptr < s->buf_end && | 188 while (s->buf_ptr < s->buf_end && |
| 183 s->bit_cnt < 32) { | 189 s->bit_cnt < 32) { |
| 184 s->bit_buf |= (*s->buf_ptr++ << (24 - s->bit_cnt)); | 190 s->bit_buf |= (*s->buf_ptr++ << (24 - s->bit_cnt)); |
| 185 s->bit_cnt += 8; | 191 s->bit_cnt += 8; |
| 186 } | 192 } |
| 187 } | 193 #endif |
| 188 | 194 } |
| 195 | |
| 196 #ifndef ALT_BITSTREAM_READER | |
| 189 /* n must be >= 1 and <= 32 */ | 197 /* n must be >= 1 and <= 32 */ |
| 190 /* also true: n > s->bit_cnt */ | 198 /* also true: n > s->bit_cnt */ |
| 191 unsigned int get_bits_long(GetBitContext *s, int n) | 199 unsigned int get_bits_long(GetBitContext *s, int n) |
| 192 { | 200 { |
| 193 unsigned int val; | 201 unsigned int val; |
| 239 } | 247 } |
| 240 s->bit_buf = bit_buf; | 248 s->bit_buf = bit_buf; |
| 241 s->bit_cnt = bit_cnt; | 249 s->bit_cnt = bit_cnt; |
| 242 return val; | 250 return val; |
| 243 } | 251 } |
| 252 #endif | |
| 244 | 253 |
| 245 void align_get_bits(GetBitContext *s) | 254 void align_get_bits(GetBitContext *s) |
| 246 { | 255 { |
| 256 #ifdef ALT_BITSTREAM_READER | |
| 257 s->index= (s->index + 7) & (~7); | |
| 258 #else | |
| 247 int n; | 259 int n; |
| 248 n = s->bit_cnt & 7; | 260 n = s->bit_cnt & 7; |
| 249 if (n > 0) { | 261 if (n > 0) { |
| 250 get_bits(s, n); | 262 get_bits(s, n); |
| 251 } | 263 } |
| 252 } | 264 #endif |
| 265 } | |
| 266 | |
| 267 #ifndef ALT_BITSTREAM_READER | |
| 253 /* This function is identical to get_bits_long(), the */ | 268 /* This function is identical to get_bits_long(), the */ |
| 254 /* only diference is that it doesn't touch the buffer */ | 269 /* only diference is that it doesn't touch the buffer */ |
| 255 /* it is usefull to see the buffer. */ | 270 /* it is usefull to see the buffer. */ |
| 256 | 271 |
| 257 unsigned int show_bits_long(GetBitContext *s, int n) | 272 unsigned int show_bits_long(GetBitContext *s, int n) |
| 294 bit_buf <<= - bit_cnt; | 309 bit_buf <<= - bit_cnt; |
| 295 bit_cnt += 32; | 310 bit_cnt += 32; |
| 296 | 311 |
| 297 return val; | 312 return val; |
| 298 } | 313 } |
| 314 #endif | |
| 299 | 315 |
| 300 /* VLC decoding */ | 316 /* VLC decoding */ |
| 301 | 317 |
| 302 //#define DEBUG_VLC | 318 //#define DEBUG_VLC |
| 303 | 319 |
