]> git.sesse.net Git - vlc/commitdiff
. moved swab32 from input_ext-dec.h to common.h. We probably won't need
authorSam Hocevar <sam@videolan.org>
Thu, 11 Jan 2001 15:35:35 +0000 (15:35 +0000)
committerSam Hocevar <sam@videolan.org>
Thu, 11 Jan 2001 15:35:35 +0000 (15:35 +0000)
   it anymore really soon, since ntohl() and htonl() seem to be properly
   optimized when gcc is passed the right optimization flags.

 . fixed GetBits32 and RemoveBits32. I know the #ifdefs are useless since
   we only support u32 words, but it's a safe reminder. Comments appreciated
   on this fix since I may have b0rked something -- it runs well here though.

include/common.h
include/input_ext-dec.h

index 7e764bc33f1fa30c29055753816d35186eb47360..c7725dec5649c4b380fedd7a8e8fa593570f9588 100644 (file)
@@ -3,7 +3,7 @@
  * Collection of useful common types and macros definitions
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: common.h,v 1.22 2001/01/09 21:03:47 sam Exp $
+ * $Id: common.h,v 1.23 2001/01/11 15:35:35 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@via.ecp.fr>
  *          Vincent Seguin <seguin@via.ecp.fr>
@@ -145,6 +145,31 @@ typedef struct video_parser_s *         p_video_parser_t;
 #define MIN(a, b)   ( ((a) < (b)) ? (a) : (b) )
 #endif
 
+/*
+ * This is stolen from the livid source who stole it from the kernel
+ */
+
+#if defined(SYS_BEOS)
+#   define swab32(x) B_BENDIAN_TO_HOST_INT32(x)
+#else
+#   ifdef WORDS_BIG_ENDIAN
+#       define swab32(x) (x)
+#   else
+#       if defined (HAVE_X86_BSWAP)
+static __inline__ const u32 __i386_swab32( u32 x )
+{
+    __asm__("bswap %0" : "=r" (x) : "0" (x));
+    return x;
+}
+#           define swab32(x) __i386_swab32(x)
+#       else
+#           define swab32(x)                                                 \
+            ( ( (u32)(((u8*)&x)[0]) << 24 ) | ( (u32)(((u8*)&x)[1]) << 16 ) |\
+              ( (u32)(((u8*)&x)[2]) << 8 )  | ( (u32)(((u8*)&x)[3])) )
+#       endif
+#   endif
+#endif
+
 /* MSB (big endian)/LSB (little endian) conversions - network order is always
  * MSB, and should be used for both network communications and files. Note that
  * byte orders other than little and big endians are not supported, but only
@@ -169,5 +194,6 @@ typedef struct video_parser_s *         p_video_parser_t;
 #endif
 
 /* Macros with automatic casts */
-#define U32_AT(p)   ( ntohl ( *( (u32 *)(p) ) ) )
+#define U32_AT(p)   ( swab32 ( *( (u32 *)(p) ) ) )
 #define U16_AT(p)   ( ntohs ( *( (u16 *)(p) ) ) )
+
index 3f6efdb076eb4eecfd17fae618f6f611b38580d0..3e77c1a64876d510c35b82b00e35fa6108ac9fee 100644 (file)
@@ -2,7 +2,7 @@
  * input_ext-dec.h: structures exported to the VideoLAN decoders
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: input_ext-dec.h,v 1.10 2001/01/10 19:22:10 massiot Exp $
+ * $Id: input_ext-dec.h,v 1.11 2001/01/11 15:35:35 sam Exp $
  *
  * Authors:
  *
@@ -242,33 +242,6 @@ static __inline__ void DumpBits( bit_stream_t * p_bit_stream, int i_bits )
 #   error Not supported word
 #endif
 
-/*
- * This is stolen from the livid source who stole it from the kernel
- * FIXME: The macro swab32 for little endian machines does
- *        not seem to work correctly
- */
-
-#if defined(SYS_BEOS)
-#   define swab32(x) B_BENDIAN_TO_HOST_INT32(x)
-#else
-#   ifdef WORDS_BIG_ENDIAN
-#       define swab32(x) (x)
-#   else
-#       if defined (HAVE_X86_BSWAP)
-static __inline__ const u32 __i386_swab32( u32 x )
-{
-    __asm__("bswap %0" : "=r" (x) : "0" (x));
-    return x;
-}
-#           define swab32(x) __i386_swab32(x)
-#       else
-#           define swab32(x)                                                 \
-            ( ( (u32)(((u8*)&x)[0]) << 24 ) | ( (u32)(((u8*)&x)[1]) << 16 ) |\
-              ( (u32)(((u8*)&x)[2]) << 8 )  | ( (u32)(((u8*)&x)[3])) )
-#       endif
-#   endif
-#endif
-
 /*****************************************************************************
  * ShowBits : return i_bits bits from the bit stream
  *****************************************************************************/
@@ -313,6 +286,7 @@ static __inline__ WORD_TYPE GetWord( bit_stream_t * p_bit_stream )
 
 /*****************************************************************************
  * RemoveBits : removes i_bits bits from the bit buffer
+ *              XXX: do not use for 32 bits, see RemoveBits32
  *****************************************************************************/
 static __inline__ void RemoveBits( bit_stream_t * p_bit_stream, int i_bits )
 {
@@ -330,17 +304,31 @@ static __inline__ void RemoveBits( bit_stream_t * p_bit_stream, int i_bits )
 
 /*****************************************************************************
  * RemoveBits32 : removes 32 bits from the bit buffer (and as a side effect,
- *                refill it). This should be faster than RemoveBits, though
- *                RemoveBits will work, too.
+ *                refill it)
  *****************************************************************************/
 static __inline__ void RemoveBits32( bit_stream_t * p_bit_stream )
 {
+#if (WORD_TYPE == u32)
+    /* If we are word aligned, do not touch the buffer */
+    if( p_bit_stream->fifo.i_available == 0 )
+    {
+        if( p_bit_stream->p_byte > p_bit_stream->p_end - sizeof(WORD_TYPE) )
+        {
+            p_bit_stream->pf_next_data_packet( p_bit_stream );
+        }
+
+        ((WORD_TYPE *)p_bit_stream->p_byte)++;
+        return;
+    }
+#endif
+
     p_bit_stream->fifo.buffer = GetWord( p_bit_stream )
                         << (32 - p_bit_stream->fifo.i_available);
 }
 
 /*****************************************************************************
  * GetBits : returns i_bits bits from the bit stream and removes them
+ *           XXX: do not use for 32 bits, see GetBits32
  *****************************************************************************/
 static __inline__ WORD_TYPE GetBits( bit_stream_t * p_bit_stream, int i_bits )
 {
@@ -372,13 +360,21 @@ static __inline__ WORD_TYPE GetBits32( bit_stream_t * p_bit_stream )
 {
     WORD_TYPE               i_result;
 
+#if (WORD_TYPE == u32)
+    /* If we are word aligned, do not touch the buffer */
+    if( p_bit_stream->fifo.i_available == 0 )
+    {
+        return( GetWord( p_bit_stream ) );
+    }
+#endif
+
     i_result = p_bit_stream->fifo.buffer;
     p_bit_stream->fifo.buffer = GetWord( p_bit_stream );
+
     i_result |= p_bit_stream->fifo.buffer
                              >> (p_bit_stream->fifo.i_available);
     p_bit_stream->fifo.buffer <<= (8 * sizeof(WORD_TYPE)
                                     - p_bit_stream->fifo.i_available);
-    
     return( i_result );
 }