annotate liba52/bitstream.h @ 27593:f75481d143ad

Cosmetics: - Convert tabs to spaces - Remove trailing whitespace - Remove useless comments
author syrjala
date Mon, 15 Sep 2008 20:45:17 +0000
parents 2eb96f52529a
children 25337a2147e7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
1 /*
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
2 * bitstream.h
18720
4bad7f00556e sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 14991
diff changeset
3 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
5 *
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
7 * See http://liba52.sourceforge.net/ for updates.
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
8 *
14991
07f1e7669772 Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents: 10489
diff changeset
9 * Modified for use with MPlayer, changes contained in liba52_changes.diff.
18783
0783dd397f74 CVS --> Subversion in copyright notices
diego
parents: 18721
diff changeset
10 * detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/
14991
07f1e7669772 Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents: 10489
diff changeset
11 * $Id$
07f1e7669772 Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents: 10489
diff changeset
12 *
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
13 * a52dec is free software; you can redistribute it and/or modify
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
14 * it under the terms of the GNU General Public License as published by
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
15 * the Free Software Foundation; either version 2 of the License, or
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
16 * (at your option) any later version.
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
17 *
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
18 * a52dec is distributed in the hope that it will be useful,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
21 * GNU General Public License for more details.
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
22 *
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
23 * You should have received a copy of the GNU General Public License
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
24 * along with this program; if not, write to the Free Software
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
26 */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
27
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
28 /* code from ffmpeg/libavcodec */
10067
f9eac474eb74 this is a important patch for hpux 11.00, because it avoid the
diego
parents: 7255
diff changeset
29 #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
30 /*
34b5a0b12558 The ALT_BITSTREAM_READER code does not work on SPARC, because the code accesses
jkeil
parents: 4053
diff changeset
31 * 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
32 * 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
33 */
34b5a0b12558 The ALT_BITSTREAM_READER code does not work on SPARC, because the code accesses
jkeil
parents: 4053
diff changeset
34 #undef ALT_BITSTREAM_READER
34b5a0b12558 The ALT_BITSTREAM_READER code does not work on SPARC, because the code accesses
jkeil
parents: 4053
diff changeset
35 #else
3570
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
36 // alternative (faster) bitstram reader (reades upto 3 bytes over the end of the input)
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
37 #define ALT_BITSTREAM_READER
10082
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
38
23873
49a433e2e78f cosmetics: misc typo fixes
diego
parents: 18783
diff changeset
39 /* used to avoid misaligned exceptions on some archs (alpha, ...) */
27438
29548d0a768a fix for alignment problem on older ARM cores
diego
parents: 23873
diff changeset
40 #if defined (ARCH_X86) || defined(HAVE_ARMV6)
10082
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
41 # define unaligned32(a) (*(uint32_t*)(a))
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
42 #else
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
43 # ifdef __GNUC__
27454
2eb96f52529a Drop av_always_inline definition. It is duplicated from libavutil and
diego
parents: 27453
diff changeset
44 static inline uint32_t unaligned32(const void *v) {
10082
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
45 struct Unaligned {
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
46 uint32_t i;
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
47 } __attribute__((packed));
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
48
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
49 return ((const struct Unaligned *) v)->i;
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
50 }
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
51 # elif defined(__DECC)
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
52 static inline uint32_t unaligned32(const void *v) {
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
53 return *(const __unaligned uint32_t *) v;
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
54 }
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
55 # else
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
56 static inline uint32_t unaligned32(const void *v) {
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
57 return *(const uint32_t *) v;
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
58 }
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
59 # endif
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
60 #endif //!ARCH_X86
1c95e3d5888a fixed alignment bug
michael
parents: 10067
diff changeset
61
7255
34b5a0b12558 The ALT_BITSTREAM_READER code does not work on SPARC, because the code accesses
jkeil
parents: 4053
diff changeset
62 #endif
18721
722ac20fac5f sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 18720
diff changeset
63
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
64 /* (stolen from the kernel) */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
65 #ifdef WORDS_BIGENDIAN
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
66
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
67 # define swab32(x) (x)
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
68
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
69 #else
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
70
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
71 # if defined (__i386__)
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
72
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
73 # define swab32(x) __i386_swab32(x)
18720
4bad7f00556e sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 14991
diff changeset
74 static inline const uint32_t __i386_swab32(uint32_t x)
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
75 {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
76 __asm__("bswap %0" : "=r" (x) : "0" (x));
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
77 return x;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
78 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
79
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
80 # else
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
81
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
82 # define swab32(x) __generic_swab32(x)
27454
2eb96f52529a Drop av_always_inline definition. It is duplicated from libavutil and
diego
parents: 27453
diff changeset
83 static inline const uint32_t __generic_swab32(uint32_t 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
84 {
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 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
86 (((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
87 }
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
88 # endif
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
89 #endif
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
90
3570
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
91 #ifdef ALT_BITSTREAM_READER
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
92 extern int indx;
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
93 #endif
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
94
18720
4bad7f00556e sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 14991
diff changeset
95 void a52_bitstream_set_ptr (a52_state_t * state, uint8_t * buf);
4bad7f00556e sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 14991
diff changeset
96 uint32_t a52_bitstream_get_bh (a52_state_t * state, uint32_t num_bits);
4bad7f00556e sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 14991
diff changeset
97 int32_t a52_bitstream_get_bh_2 (a52_state_t * state, uint32_t num_bits);
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
98
18720
4bad7f00556e sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 14991
diff changeset
99 static inline uint32_t bitstream_get (a52_state_t * state, uint32_t num_bits)
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
100 {
3570
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
101 #ifdef ALT_BITSTREAM_READER
18720
4bad7f00556e sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 14991
diff changeset
102 uint32_t result= swab32( unaligned32(((uint8_t *)state->buffer_start)+(indx>>3)) );
3570
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
103
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
104 result<<= (indx&0x07);
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
105 result>>= 32 - num_bits;
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
106 indx+= num_bits;
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
107
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
108 return result;
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
109 #else
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
110 uint32_t result;
18721
722ac20fac5f sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 18720
diff changeset
111
18720
4bad7f00556e sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 14991
diff changeset
112 if (num_bits < state->bits_left) {
4bad7f00556e sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 14991
diff changeset
113 result = (state->current_word << (32 - state->bits_left)) >> (32 - num_bits);
4bad7f00556e sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 14991
diff changeset
114 state->bits_left -= num_bits;
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
115 return result;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
116 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
117
18720
4bad7f00556e sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 14991
diff changeset
118 return a52_bitstream_get_bh (state, num_bits);
3570
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
119 #endif
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
120 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
121
18720
4bad7f00556e sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 14991
diff changeset
122 static inline void bitstream_skip(a52_state_t * state, int num_bits)
4053
75415651e3b9 bitstream_skip() instead of bitstream_get() if possible
michael
parents: 3570
diff changeset
123 {
75415651e3b9 bitstream_skip() instead of bitstream_get() if possible
michael
parents: 3570
diff changeset
124 #ifdef ALT_BITSTREAM_READER
75415651e3b9 bitstream_skip() instead of bitstream_get() if possible
michael
parents: 3570
diff changeset
125 indx+= num_bits;
75415651e3b9 bitstream_skip() instead of bitstream_get() if possible
michael
parents: 3570
diff changeset
126 #else
18720
4bad7f00556e sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 14991
diff changeset
127 bitstream_get(state, num_bits);
4053
75415651e3b9 bitstream_skip() instead of bitstream_get() if possible
michael
parents: 3570
diff changeset
128 #endif
75415651e3b9 bitstream_skip() instead of bitstream_get() if possible
michael
parents: 3570
diff changeset
129 }
75415651e3b9 bitstream_skip() instead of bitstream_get() if possible
michael
parents: 3570
diff changeset
130
18720
4bad7f00556e sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 14991
diff changeset
131 static inline int32_t bitstream_get_2 (a52_state_t * state, uint32_t num_bits)
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
132 {
3570
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
133 #ifdef ALT_BITSTREAM_READER
18720
4bad7f00556e sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 14991
diff changeset
134 int32_t result= swab32( unaligned32(((uint8_t *)state->buffer_start)+(indx>>3)) );
3570
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
135
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
136 result<<= (indx&0x07);
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
137 result>>= 32 - num_bits;
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
138 indx+= num_bits;
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
139
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
140 return result;
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
141 #else
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
142 int32_t result;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
143
18720
4bad7f00556e sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 14991
diff changeset
144 if (num_bits < state->bits_left) {
4bad7f00556e sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 14991
diff changeset
145 result = (((int32_t)state->current_word) << (32 - state->bits_left)) >> (32 - num_bits);
4bad7f00556e sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 14991
diff changeset
146 state->bits_left -= num_bits;
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
147 return result;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
148 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
149
18720
4bad7f00556e sync with liba52 0.7.4, patch by Emanuele Giaquinta >emanuele.giaquinta ! gmail * com<
rathann
parents: 14991
diff changeset
150 return a52_bitstream_get_bh_2 (state, num_bits);
3570
c03e0bb35c16 faster (and simpler) bitstream reader (in C)
michael
parents: 3394
diff changeset
151 #endif
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
152 }