Mercurial > mplayer.hg
annotate liba52/bitstream.h @ 10509:d9d24093db2e
Export flags needed for softpulldown filter.
author | ranma |
---|---|
date | Sun, 03 Aug 2003 12:04:57 +0000 |
parents | b7a6edb6100e |
children | 07f1e7669772 |
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 | |
10489
b7a6edb6100e
Changed swab32 from macro to inline function, this fixes compilation on alpha (with gcc2.95). Based on patch by KotH
alex
parents:
10313
diff
changeset
|
24 /* code from ffmpeg/libavcodec */ |
b7a6edb6100e
Changed swab32 from macro to inline function, this fixes compilation on alpha (with gcc2.95). Based on patch by KotH
alex
parents:
10313
diff
changeset
|
25 #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC_ == 3 && __GNUC_MINOR__ > 0) |
b7a6edb6100e
Changed swab32 from macro to inline function, this fixes compilation on alpha (with gcc2.95). Based on patch by KotH
alex
parents:
10313
diff
changeset
|
26 # define always_inline __attribute__((always_inline)) inline |
b7a6edb6100e
Changed swab32 from macro to inline function, this fixes compilation on alpha (with gcc2.95). Based on patch by KotH
alex
parents:
10313
diff
changeset
|
27 #else |
b7a6edb6100e
Changed swab32 from macro to inline function, this fixes compilation on alpha (with gcc2.95). Based on patch by KotH
alex
parents:
10313
diff
changeset
|
28 # define always_inline inline |
b7a6edb6100e
Changed swab32 from macro to inline function, this fixes compilation on alpha (with gcc2.95). Based on patch by KotH
alex
parents:
10313
diff
changeset
|
29 #endif |
b7a6edb6100e
Changed swab32 from macro to inline function, this fixes compilation on alpha (with gcc2.95). Based on patch by KotH
alex
parents:
10313
diff
changeset
|
30 |
10067
f9eac474eb74
this is a important patch for hpux 11.00, because it avoid the
diego
parents:
7255
diff
changeset
|
31 #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
|
32 /* |
34b5a0b12558
The ALT_BITSTREAM_READER code does not work on SPARC, because the code accesses
jkeil
parents:
4053
diff
changeset
|
33 * 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
|
34 * 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
|
35 */ |
34b5a0b12558
The ALT_BITSTREAM_READER code does not work on SPARC, because the code accesses
jkeil
parents:
4053
diff
changeset
|
36 #undef ALT_BITSTREAM_READER |
34b5a0b12558
The ALT_BITSTREAM_READER code does not work on SPARC, because the code accesses
jkeil
parents:
4053
diff
changeset
|
37 #else |
3570 | 38 // alternative (faster) bitstram reader (reades upto 3 bytes over the end of the input) |
39 #define ALT_BITSTREAM_READER | |
10082 | 40 |
41 /* used to avoid missaligned exceptions on some archs (alpha, ...) */ | |
10313
b479b224d435
arm support by armin.gerritsen@philips.com (also seen a patch like this on openzaurus' mplayer port)
alex
parents:
10082
diff
changeset
|
42 #if defined (ARCH_X86) || defined(ARCH_ARMV4L) |
10082 | 43 # define unaligned32(a) (*(uint32_t*)(a)) |
44 #else | |
45 # ifdef __GNUC__ | |
10489
b7a6edb6100e
Changed swab32 from macro to inline function, this fixes compilation on alpha (with gcc2.95). Based on patch by KotH
alex
parents:
10313
diff
changeset
|
46 static always_inline uint32_t unaligned32(const void *v) { |
10082 | 47 struct Unaligned { |
48 uint32_t i; | |
49 } __attribute__((packed)); | |
50 | |
51 return ((const struct Unaligned *) v)->i; | |
52 } | |
53 # elif defined(__DECC) | |
54 static inline uint32_t unaligned32(const void *v) { | |
55 return *(const __unaligned uint32_t *) v; | |
56 } | |
57 # else | |
58 static inline uint32_t unaligned32(const void *v) { | |
59 return *(const uint32_t *) v; | |
60 } | |
61 # endif | |
62 #endif //!ARCH_X86 | |
63 | |
7255
34b5a0b12558
The ALT_BITSTREAM_READER code does not work on SPARC, because the code accesses
jkeil
parents:
4053
diff
changeset
|
64 #endif |
3570 | 65 |
3394 | 66 /* (stolen from the kernel) */ |
67 #ifdef WORDS_BIGENDIAN | |
68 | |
69 # define swab32(x) (x) | |
70 | |
71 #else | |
72 | |
73 # if defined (__i386__) | |
74 | |
75 # define swab32(x) __i386_swab32(x) | |
10489
b7a6edb6100e
Changed swab32 from macro to inline function, this fixes compilation on alpha (with gcc2.95). Based on patch by KotH
alex
parents:
10313
diff
changeset
|
76 static always_inline const uint32_t __i386_swab32(uint32_t x) |
3394 | 77 { |
78 __asm__("bswap %0" : "=r" (x) : "0" (x)); | |
79 return x; | |
80 } | |
81 | |
82 # else | |
83 | |
10489
b7a6edb6100e
Changed swab32 from macro to inline function, this fixes compilation on alpha (with gcc2.95). Based on patch by KotH
alex
parents:
10313
diff
changeset
|
84 # define swab32(x) __generic_swab32(x) |
b7a6edb6100e
Changed swab32 from macro to inline function, this fixes compilation on alpha (with gcc2.95). Based on patch by KotH
alex
parents:
10313
diff
changeset
|
85 static always_inline const uint32_t __generic_swab32(uint32_t x) |
b7a6edb6100e
Changed swab32 from macro to inline function, this fixes compilation on alpha (with gcc2.95). Based on patch by KotH
alex
parents:
10313
diff
changeset
|
86 { |
b7a6edb6100e
Changed swab32 from macro to inline function, this fixes compilation on alpha (with gcc2.95). Based on patch by KotH
alex
parents:
10313
diff
changeset
|
87 return ((((uint8_t*)&x)[0] << 24) | (((uint8_t*)&x)[1] << 16) | |
b7a6edb6100e
Changed swab32 from macro to inline function, this fixes compilation on alpha (with gcc2.95). Based on patch by KotH
alex
parents:
10313
diff
changeset
|
88 (((uint8_t*)&x)[2] << 8) | (((uint8_t*)&x)[3])); |
b7a6edb6100e
Changed swab32 from macro to inline function, this fixes compilation on alpha (with gcc2.95). Based on patch by KotH
alex
parents:
10313
diff
changeset
|
89 } |
3394 | 90 # endif |
91 #endif | |
92 | |
3570 | 93 #ifdef ALT_BITSTREAM_READER |
94 extern uint32_t *buffer_start; | |
95 extern int indx; | |
96 #else | |
3394 | 97 extern uint32_t bits_left; |
98 extern uint32_t current_word; | |
3570 | 99 #endif |
3394 | 100 |
101 void bitstream_set_ptr (uint8_t * buf); | |
102 uint32_t bitstream_get_bh(uint32_t num_bits); | |
103 int32_t bitstream_get_bh_2(uint32_t num_bits); | |
104 | |
3570 | 105 |
3394 | 106 static inline uint32_t |
3570 | 107 bitstream_get(uint32_t num_bits) // note num_bits is practically a constant due to inlineing |
3394 | 108 { |
3570 | 109 #ifdef ALT_BITSTREAM_READER |
10082 | 110 uint32_t result= swab32( unaligned32(((uint8_t *)buffer_start)+(indx>>3)) ); |
3570 | 111 |
112 result<<= (indx&0x07); | |
113 result>>= 32 - num_bits; | |
114 indx+= num_bits; | |
115 | |
116 return result; | |
117 #else | |
3394 | 118 uint32_t result; |
3570 | 119 |
3394 | 120 if(num_bits < bits_left) { |
121 result = (current_word << (32 - bits_left)) >> (32 - num_bits); | |
122 bits_left -= num_bits; | |
123 return result; | |
124 } | |
125 | |
126 return bitstream_get_bh(num_bits); | |
3570 | 127 #endif |
3394 | 128 } |
129 | |
4053
75415651e3b9
bitstream_skip() instead of bitstream_get() if possible
michael
parents:
3570
diff
changeset
|
130 static inline void bitstream_skip(int num_bits) |
75415651e3b9
bitstream_skip() instead of bitstream_get() if possible
michael
parents:
3570
diff
changeset
|
131 { |
75415651e3b9
bitstream_skip() instead of bitstream_get() if possible
michael
parents:
3570
diff
changeset
|
132 #ifdef ALT_BITSTREAM_READER |
75415651e3b9
bitstream_skip() instead of bitstream_get() if possible
michael
parents:
3570
diff
changeset
|
133 indx+= num_bits; |
75415651e3b9
bitstream_skip() instead of bitstream_get() if possible
michael
parents:
3570
diff
changeset
|
134 #else |
75415651e3b9
bitstream_skip() instead of bitstream_get() if possible
michael
parents:
3570
diff
changeset
|
135 bitstream_get(num_bits); |
75415651e3b9
bitstream_skip() instead of bitstream_get() if possible
michael
parents:
3570
diff
changeset
|
136 #endif |
75415651e3b9
bitstream_skip() instead of bitstream_get() if possible
michael
parents:
3570
diff
changeset
|
137 } |
75415651e3b9
bitstream_skip() instead of bitstream_get() if possible
michael
parents:
3570
diff
changeset
|
138 |
3394 | 139 static inline int32_t |
140 bitstream_get_2(uint32_t num_bits) | |
141 { | |
3570 | 142 #ifdef ALT_BITSTREAM_READER |
10082 | 143 int32_t result= swab32( unaligned32(((uint8_t *)buffer_start)+(indx>>3)) ); |
3570 | 144 |
145 result<<= (indx&0x07); | |
146 result>>= 32 - num_bits; | |
147 indx+= num_bits; | |
148 | |
149 return result; | |
150 #else | |
3394 | 151 int32_t result; |
152 | |
153 if(num_bits < bits_left) { | |
154 result = (((int32_t)current_word) << (32 - bits_left)) >> (32 - num_bits); | |
155 bits_left -= num_bits; | |
156 return result; | |
157 } | |
158 | |
159 return bitstream_get_bh_2(num_bits); | |
3570 | 160 #endif |
3394 | 161 } |