Mercurial > libavcodec.hg
comparison libac3/bitstream.h @ 0:986e461dc072 libavcodec
Initial revision
| author | glantau |
|---|---|
| date | Sun, 22 Jul 2001 14:18:56 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:986e461dc072 |
|---|---|
| 1 /* | |
| 2 * bitstream.h | |
| 3 * | |
| 4 * Copyright (C) Aaron Holtzman - Dec 1999 | |
| 5 * | |
| 6 * This file is part of ac3dec, a free AC-3 audio decoder | |
| 7 * | |
| 8 * ac3dec is free software; you can redistribute it and/or modify | |
| 9 * it under the terms of the GNU General Public License as published by | |
| 10 * the Free Software Foundation; either version 2, or (at your option) | |
| 11 * any later version. | |
| 12 * | |
| 13 * ac3dec is distributed in the hope that it will be useful, | |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 * GNU General Public License for more details. | |
| 17 * | |
| 18 * You should have received a copy of the GNU General Public License | |
| 19 * along with GNU Make; see the file COPYING. If not, write to | |
| 20 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
| 21 * | |
| 22 */ | |
| 23 | |
| 24 //My new and improved vego-matic endian swapping routine | |
| 25 //(stolen from the kernel) | |
| 26 #ifdef WORDS_BIGENDIAN | |
| 27 | |
| 28 # define swab32(x) (x) | |
| 29 | |
| 30 #else | |
| 31 | |
| 32 # if defined (__i386__) | |
| 33 | |
| 34 # define swab32(x) __i386_swab32(x) | |
| 35 static inline const uint32_t __i386_swab32(uint32_t x) | |
| 36 { | |
| 37 __asm__("bswap %0" : "=r" (x) : "0" (x)); | |
| 38 return x; | |
| 39 } | |
| 40 | |
| 41 # else | |
| 42 | |
| 43 # define swab32(x)\ | |
| 44 ((((uint8_t*)&x)[0] << 24) | (((uint8_t*)&x)[1] << 16) | \ | |
| 45 (((uint8_t*)&x)[2] << 8) | (((uint8_t*)&x)[3])) | |
| 46 | |
| 47 # endif | |
| 48 #endif | |
| 49 | |
| 50 extern uint32_t bits_left; | |
| 51 extern uint32_t current_word; | |
| 52 | |
| 53 void bitstream_set_ptr (uint8_t * buf); | |
| 54 uint32_t bitstream_get_bh(uint32_t num_bits); | |
| 55 | |
| 56 static inline uint32_t | |
| 57 bitstream_get(uint32_t num_bits) | |
| 58 { | |
| 59 uint32_t result; | |
| 60 | |
| 61 if(num_bits < bits_left) { | |
| 62 result = (current_word << (32 - bits_left)) >> (32 - num_bits); | |
| 63 bits_left -= num_bits; | |
| 64 return result; | |
| 65 } | |
| 66 | |
| 67 return bitstream_get_bh(num_bits); | |
| 68 } |
