diff options
author | michael <michael@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2003-05-07 23:25:25 +0000 |
---|---|---|
committer | michael <michael@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2003-05-07 23:25:25 +0000 |
commit | 9109cc8d20a18fef2304808c5600c62a6414b1c4 (patch) | |
tree | 7fb953b875fb288690e873fd63fcc05a96ff7cd5 /liba52/bitstream.h | |
parent | 3f5313a9e542d60fae69775b29cdf4929cbf7f40 (diff) | |
download | mpv-9109cc8d20a18fef2304808c5600c62a6414b1c4.tar.bz2 mpv-9109cc8d20a18fef2304808c5600c62a6414b1c4.tar.xz |
fixed alignment bug
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@10083 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'liba52/bitstream.h')
-rw-r--r-- | liba52/bitstream.h | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/liba52/bitstream.h b/liba52/bitstream.h index e59e4e9dcd..a62fbbf09e 100644 --- a/liba52/bitstream.h +++ b/liba52/bitstream.h @@ -30,6 +30,30 @@ #else // alternative (faster) bitstram reader (reades upto 3 bytes over the end of the input) #define ALT_BITSTREAM_READER + +/* used to avoid missaligned exceptions on some archs (alpha, ...) */ +#ifdef ARCH_X86 +# define unaligned32(a) (*(uint32_t*)(a)) +#else +# ifdef __GNUC__ +static inline uint32_t unaligned32(const void *v) { + struct Unaligned { + uint32_t i; + } __attribute__((packed)); + + return ((const struct Unaligned *) v)->i; +} +# elif defined(__DECC) +static inline uint32_t unaligned32(const void *v) { + return *(const __unaligned uint32_t *) v; +} +# else +static inline uint32_t unaligned32(const void *v) { + return *(const uint32_t *) v; +} +# endif +#endif //!ARCH_X86 + #endif /* (stolen from the kernel) */ @@ -74,7 +98,7 @@ static inline uint32_t bitstream_get(uint32_t num_bits) // note num_bits is practically a constant due to inlineing { #ifdef ALT_BITSTREAM_READER - uint32_t result= swab32( *(uint32_t *)(((uint8_t *)buffer_start)+(indx>>3)) ); + uint32_t result= swab32( unaligned32(((uint8_t *)buffer_start)+(indx>>3)) ); result<<= (indx&0x07); result>>= 32 - num_bits; @@ -107,7 +131,7 @@ static inline int32_t bitstream_get_2(uint32_t num_bits) { #ifdef ALT_BITSTREAM_READER - int32_t result= swab32( *(uint32_t *)(((uint8_t *)buffer_start)+(indx>>3)) ); + int32_t result= swab32( unaligned32(((uint8_t *)buffer_start)+(indx>>3)) ); result<<= (indx&0x07); result>>= 32 - num_bits; |