Mercurial > mplayer.hg
annotate liba52/bitstream.h @ 10218:f82646fc1431
Moved video filters to a separate section, moved slave mode section to the
tech subdir, random improvements, default indentation reduced.
Straight from the LUG camp Felsberg by Jonas and Diego.
author | jonas |
---|---|
date | Sat, 31 May 2003 16:41:41 +0000 |
parents | 1c95e3d5888a |
children | b479b224d435 |
rev | line source |
---|---|
3394 | 1 /* |
2 * bitstream.h | |
3 * Copyright (C) 2000-2001 Michel Lespinasse <walken@zoy.org> | |
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> | |
5 * | |
6 * This file is part of a52dec, a free ATSC A-52 stream decoder. | |
7 * See http://liba52.sourceforge.net/ for updates. | |
8 * | |
9 * a52dec is free software; you can redistribute it and/or modify | |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * a52dec is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
22 */ | |
23 | |
10067
f9eac474eb74
this is a important patch for hpux 11.00, because it avoid the
diego
parents:
7255
diff
changeset
|
24 #if defined(__sparc__) || defined(hpux) |
7255
34b5a0b12558
The ALT_BITSTREAM_READER code does not work on SPARC, because the code accesses
jkeil
parents:
4053
diff
changeset
|
25 /* |
34b5a0b12558
The ALT_BITSTREAM_READER code does not work on SPARC, because the code accesses
jkeil
parents:
4053
diff
changeset
|
26 * the alt bitstream reader performs unaligned memory accesses; that doesn't work |
10067
f9eac474eb74
this is a important patch for hpux 11.00, because it avoid the
diego
parents:
7255
diff
changeset
|
27 * on sparc/hpux. For now, disable ALT_BITSTREAM_READER. |
7255
34b5a0b12558
The ALT_BITSTREAM_READER code does not work on SPARC, because the code accesses
jkeil
parents:
4053
diff
changeset
|
28 */ |
34b5a0b12558
The ALT_BITSTREAM_READER code does not work on SPARC, because the code accesses
jkeil
parents:
4053
diff
changeset
|
29 #undef ALT_BITSTREAM_READER |
34b5a0b12558
The ALT_BITSTREAM_READER code does not work on SPARC, because the code accesses
jkeil
parents:
4053
diff
changeset
|
30 #else |
3570 | 31 // alternative (faster) bitstram reader (reades upto 3 bytes over the end of the input) |
32 #define ALT_BITSTREAM_READER | |
10082 | 33 |
34 /* used to avoid missaligned exceptions on some archs (alpha, ...) */ | |
35 #ifdef ARCH_X86 | |
36 # define unaligned32(a) (*(uint32_t*)(a)) | |
37 #else | |
38 # ifdef __GNUC__ | |
39 static inline uint32_t unaligned32(const void *v) { | |
40 struct Unaligned { | |
41 uint32_t i; | |
42 } __attribute__((packed)); | |
43 | |
44 return ((const struct Unaligned *) v)->i; | |
45 } | |
46 # elif defined(__DECC) | |
47 static inline uint32_t unaligned32(const void *v) { | |
48 return *(const __unaligned uint32_t *) v; | |
49 } | |
50 # else | |
51 static inline uint32_t unaligned32(const void *v) { | |
52 return *(const uint32_t *) v; | |
53 } | |
54 # endif | |
55 #endif //!ARCH_X86 | |
56 | |
7255
34b5a0b12558
The ALT_BITSTREAM_READER code does not work on SPARC, because the code accesses
jkeil
parents:
4053
diff
changeset
|
57 #endif |
3570 | 58 |
3394 | 59 /* (stolen from the kernel) */ |
60 #ifdef WORDS_BIGENDIAN | |
61 | |
62 # define swab32(x) (x) | |
63 | |
64 #else | |
65 | |
66 # if defined (__i386__) | |
67 | |
68 # define swab32(x) __i386_swab32(x) | |
69 static inline const uint32_t __i386_swab32(uint32_t x) | |
70 { | |
71 __asm__("bswap %0" : "=r" (x) : "0" (x)); | |
72 return x; | |
73 } | |
74 | |
75 # else | |
76 | |
77 # define swab32(x)\ | |
78 ((((uint8_t*)&x)[0] << 24) | (((uint8_t*)&x)[1] << 16) | \ | |
79 (((uint8_t*)&x)[2] << 8) | (((uint8_t*)&x)[3])) | |
80 | |
81 # endif | |
82 #endif | |
83 | |
3570 | 84 #ifdef ALT_BITSTREAM_READER |
85 extern uint32_t *buffer_start; | |
86 extern int indx; | |
87 #else | |
3394 | 88 extern uint32_t bits_left; |
89 extern uint32_t current_word; | |
3570 | 90 #endif |
3394 | 91 |
92 void bitstream_set_ptr (uint8_t * buf); | |
93 uint32_t bitstream_get_bh(uint32_t num_bits); | |
94 int32_t bitstream_get_bh_2(uint32_t num_bits); | |
95 | |
3570 | 96 |
3394 | 97 static inline uint32_t |
3570 | 98 bitstream_get(uint32_t num_bits) // note num_bits is practically a constant due to inlineing |
3394 | 99 { |
3570 | 100 #ifdef ALT_BITSTREAM_READER |
10082 | 101 uint32_t result= swab32( unaligned32(((uint8_t *)buffer_start)+(indx>>3)) ); |
3570 | 102 |
103 result<<= (indx&0x07); | |
104 result>>= 32 - num_bits; | |
105 indx+= num_bits; | |
106 | |
107 return result; | |
108 #else | |
3394 | 109 uint32_t result; |
3570 | 110 |
3394 | 111 if(num_bits < bits_left) { |
112 result = (current_word << (32 - bits_left)) >> (32 - num_bits); | |
113 bits_left -= num_bits; | |
114 return result; | |
115 } | |
116 | |
117 return bitstream_get_bh(num_bits); | |
3570 | 118 #endif |
3394 | 119 } |
120 | |
4053
75415651e3b9
bitstream_skip() instead of bitstream_get() if possible
michael
parents:
3570
diff
changeset
|
121 static inline void bitstream_skip(int num_bits) |
75415651e3b9
bitstream_skip() instead of bitstream_get() if possible
michael
parents:
3570
diff
changeset
|
122 { |
75415651e3b9
bitstream_skip() instead of bitstream_get() if possible
michael
parents:
3570
diff
changeset
|
123 #ifdef ALT_BITSTREAM_READER |
75415651e3b9
bitstream_skip() instead of bitstream_get() if possible
michael
parents:
3570
diff
changeset
|
124 indx+= num_bits; |
75415651e3b9
bitstream_skip() instead of bitstream_get() if possible
michael
parents:
3570
diff
changeset
|
125 #else |
75415651e3b9
bitstream_skip() instead of bitstream_get() if possible
michael
parents:
3570
diff
changeset
|
126 bitstream_get(num_bits); |
75415651e3b9
bitstream_skip() instead of bitstream_get() if possible
michael
parents:
3570
diff
changeset
|
127 #endif |
75415651e3b9
bitstream_skip() instead of bitstream_get() if possible
michael
parents:
3570
diff
changeset
|
128 } |
75415651e3b9
bitstream_skip() instead of bitstream_get() if possible
michael
parents:
3570
diff
changeset
|
129 |
3394 | 130 static inline int32_t |
131 bitstream_get_2(uint32_t num_bits) | |
132 { | |
3570 | 133 #ifdef ALT_BITSTREAM_READER |
10082 | 134 int32_t result= swab32( unaligned32(((uint8_t *)buffer_start)+(indx>>3)) ); |
3570 | 135 |
136 result<<= (indx&0x07); | |
137 result>>= 32 - num_bits; | |
138 indx+= num_bits; | |
139 | |
140 return result; | |
141 #else | |
3394 | 142 int32_t result; |
143 | |
144 if(num_bits < bits_left) { | |
145 result = (((int32_t)current_word) << (32 - bits_left)) >> (32 - num_bits); | |
146 bits_left -= num_bits; | |
147 return result; | |
148 } | |
149 | |
150 return bitstream_get_bh_2(num_bits); | |
3570 | 151 #endif |
3394 | 152 } |