diff --git a/libs/getbits/gstgetbits.c b/libs/getbits/gstgetbits.c index 738f95e0b6..53640c99d2 100644 --- a/libs/getbits/gstgetbits.c +++ b/libs/getbits/gstgetbits.c @@ -2,6 +2,7 @@ #include "gstgetbits.h" +/* Defined in gstgetbits_i386.s */ extern unsigned long _gst_get1bit_i386(gst_getbits_t *gb, unsigned long bits); extern unsigned long _gst_getbits_i386(gst_getbits_t *gb, unsigned long bits); extern unsigned long _gst_getbits_fast_i386(gst_getbits_t *gb, unsigned long bits); @@ -9,29 +10,15 @@ extern unsigned long _gst_showbits_i386(gst_getbits_t *gb, unsigned long bits); extern void _gst_flushbits_i386(gst_getbits_t *gb, unsigned long bits); extern void _gst_getbits_back_i386(gst_getbits_t *gb, unsigned long bits); -//#define DEBUG_ENABLED -#ifdef DEBUG_ENABLED -#define DEBUG(format, args...) g_print("DEBUG:(%d) " format, getpid() , ##args) -#else -#define DEBUG(format, args...) -#endif +/* Defined in gstgetbits_generic.c */ +extern unsigned long _gst_getbits_int_cb(gst_getbits_t *gb, unsigned long bits); +extern unsigned long _gst_get1bit_int(gst_getbits_t *gb, unsigned long bits); +extern unsigned long _gst_getbits_int(gst_getbits_t *gb, unsigned long bits); +extern unsigned long _gst_getbits_fast_int(gst_getbits_t *gb, unsigned long bits); +extern unsigned long _gst_showbits_int(gst_getbits_t *gb, unsigned long bits); +extern void _gst_flushbits_int(gst_getbits_t *gb, unsigned long bits); +extern void _gst_getbits_back_int(gst_getbits_t *gb, unsigned long bits); -#ifdef WORDS_BIGENDIAN -# define swab32(x) (x) -#else -# if defined (__i386__) -# define swab32(x) __i386_swab32(x) - static inline const guint32 __i386_swab32(guint32 x) - { - __asm__("bswap %0" : "=r" (x) : "0" (x)); - return x; - } -# else -# define swab32(x)\ - ((((guint8*)&x)[0] << 24) | (((guint8*)&x)[1] << 16) | \ - (((guint8*)&x)[2] << 8) | (((guint8*)&x)[3])) -# endif -#endif unsigned long gst_getbits_nBitMask[] = { 0x00000000, 0x80000000, 0xc0000000, 0xe0000000, @@ -162,115 +149,10 @@ unsigned long _gst_getbits_mmx(gst_getbits_t *gb,unsigned long bits) { } #endif /* HAVE_LIBMMX */ -unsigned long _gst_getbits_int_cb(gst_getbits_t *gb, unsigned long bits) { - int result; - int bitsleft; - - //printf("gst_getbits%lu %ld %p %08x\n", bits, gb->bits, gb->ptr, gb->dword); - - if (!bits) return 0; - - gb->bits -= bits; - result = gb->dword >> (32-bits); - - if (gb->bits < 0) { - - gb->ptr += 4; - - bitsleft = (gb->endptr - gb->ptr)*8; - bits = -gb->bits; - gb->bits += (bitsleft>32? 32 : bitsleft); - - if (gb->endptr <= gb->ptr) { - (gb->callback)(gb, gb->data); - gb->bits -= bits; - } - gb->dword = swab32(*((unsigned long *)(gb->ptr))); - - result |= (gb->dword >> (32-bits)); - } - gb->dword <<= bits; - - return result; -} - -void _gst_getbits_back_int(gst_getbits_t *gb, unsigned long bits) { - gb->bits -= bits; - gb->ptr += (gb->bits>>3); - gb->bits &= 0x7; -} - -unsigned long _gst_showbits_int(gst_getbits_t *gb, unsigned long bits) { - unsigned long rval; - - if (bits == 0) return 0; - - rval = swab32(*((unsigned long *)(gb->ptr))); - rval <<= gb->bits; - rval >>= (32-bits); - - DEBUG("showbits%d, %08x\n", bits, rval); - return rval; -} - unsigned long _gst_getbyte(gst_getbits_t *gb, unsigned long bits) { return *gb->ptr++; } -unsigned long _gst_get1bit_int(gst_getbits_t *gb, unsigned long bits) { - unsigned char rval; - - rval = *gb->ptr << gb->bits; - - gb->bits++; - gb->ptr += (gb->bits>>3); - gb->bits &= 0x7; - - DEBUG("getbits%d, %08x\n", bits, rval); - return rval>>7; -} - -unsigned long _gst_getbits_fast_int(gst_getbits_t *gb, unsigned long bits) { - unsigned long rval; - - rval = (unsigned char) (gb->ptr[0] << gb->bits); - rval |= ((unsigned int) gb->ptr[1] << gb->bits)>>8; - rval <<= bits; - rval >>= 8; - - gb->bits += bits; - gb->ptr += (gb->bits>>3); - gb->bits &= 0x7; - - DEBUG("getbits%d, %08x\n", bits, rval); - return rval; -} - -unsigned long _gst_getbits_int(gst_getbits_t *gb, unsigned long bits) { - unsigned long rval; - - if (bits == 0) return 0; - - rval = swab32(*((unsigned long *)(gb->ptr))); - rval <<= gb->bits; - - gb->bits += bits; - - rval >>= (32-bits); - gb->ptr += (gb->bits>>3); - gb->bits &= 0x7; - - DEBUG("getbits%d, %08x\n", bits, rval); - return rval; -} - -void _gst_flushbits_int(gst_getbits_t *gb, unsigned long bits) { - gb->bits += bits; - gb->ptr += (gb->bits>>3); - gb->bits &= 0x7; - DEBUG("flushbits%d\n", bits); -} - /* initialize the getbits structure with the proper getbits func */ void gst_getbits_init(gst_getbits_t *gb, GstGetbitsCallback callback, void *data) { gb->ptr = NULL; diff --git a/libs/getbits/gstgetbits.h b/libs/getbits/gstgetbits.h index 259bffa557..bac0032ed7 100644 --- a/libs/getbits/gstgetbits.h +++ b/libs/getbits/gstgetbits.h @@ -4,6 +4,7 @@ #include #include +// FIXME - remove this HAVE_LIBMMX - let configure set it. #undef HAVE_LIBMMX #include @@ -15,6 +16,32 @@ #include #endif /* HAVE_LIBSSE */ +// FIXME - let configure set DEBUG_ENABLED. +//#define DEBUG_ENABLED +#ifdef DEBUG_ENABLED +#define DEBUG(format, args...) g_print("DEBUG:(%d) " format, getpid() , ##args) +#else +#define DEBUG(format, args...) +#endif + + +#ifdef WORDS_BIGENDIAN +# define swab32(x) (x) +#else +# if defined (__i386__) +# define swab32(x) __i386_swab32(x) + static inline const guint32 __i386_swab32(guint32 x) + { + __asm__("bswap %0" : "=r" (x) : "0" (x)); + return x; + } +# else +# define swab32(x)\ + ((((guint8*)&x)[0] << 24) | (((guint8*)&x)[1] << 16) | \ + (((guint8*)&x)[2] << 8) | (((guint8*)&x)[3])) +# endif +#endif + typedef struct _gst_getbits_t gst_getbits_t; typedef void (*GstGetbitsCallback) (gst_getbits_t *gb, void *data); diff --git a/libs/getbits/gstgetbits_generic.c b/libs/getbits/gstgetbits_generic.c index dc5e810cd7..a94a71a204 100644 --- a/libs/getbits/gstgetbits_generic.c +++ b/libs/getbits/gstgetbits_generic.c @@ -1,2 +1,118 @@ +#include + +#include "gstgetbits.h" + +unsigned long _gst_getbits_int_cb(gst_getbits_t *gb, unsigned long bits); +unsigned long _gst_get1bit_int(gst_getbits_t *gb, unsigned long bits); +unsigned long _gst_getbits_int(gst_getbits_t *gb, unsigned long bits); +unsigned long _gst_getbits_fast_int(gst_getbits_t *gb, unsigned long bits); +unsigned long _gst_showbits_int(gst_getbits_t *gb, unsigned long bits); +void _gst_flushbits_int(gst_getbits_t *gb, unsigned long bits); +void _gst_getbits_back_int(gst_getbits_t *gb, unsigned long bits); + + +unsigned long _gst_getbits_int_cb(gst_getbits_t *gb, unsigned long bits) { + int result; + int bitsleft; + + //printf("gst_getbits%lu %ld %p %08x\n", bits, gb->bits, gb->ptr, gb->dword); + + if (!bits) return 0; + + gb->bits -= bits; + result = gb->dword >> (32-bits); + + if (gb->bits < 0) { + + gb->ptr += 4; + + bitsleft = (gb->endptr - gb->ptr)*8; + bits = -gb->bits; + gb->bits += (bitsleft>32? 32 : bitsleft); + + if (gb->endptr <= gb->ptr) { + (gb->callback)(gb, gb->data); + gb->bits -= bits; + } + gb->dword = swab32(*((unsigned long *)(gb->ptr))); + + result |= (gb->dword >> (32-bits)); + } + gb->dword <<= bits; + + return result; +} + +unsigned long _gst_get1bit_int(gst_getbits_t *gb, unsigned long bits) { + unsigned char rval; + + rval = *gb->ptr << gb->bits; + + gb->bits++; + gb->ptr += (gb->bits>>3); + gb->bits &= 0x7; + + DEBUG("getbits%d, %08x\n", bits, rval); + return rval>>7; +} + +unsigned long _gst_getbits_int(gst_getbits_t *gb, unsigned long bits) { + unsigned long rval; + + if (bits == 0) return 0; + + rval = swab32(*((unsigned long *)(gb->ptr))); + rval <<= gb->bits; + + gb->bits += bits; + + rval >>= (32-bits); + gb->ptr += (gb->bits>>3); + gb->bits &= 0x7; + + DEBUG("getbits%d, %08x\n", bits, rval); + return rval; +} + +unsigned long _gst_getbits_fast_int(gst_getbits_t *gb, unsigned long bits) { + unsigned long rval; + + rval = (unsigned char) (gb->ptr[0] << gb->bits); + rval |= ((unsigned int) gb->ptr[1] << gb->bits)>>8; + rval <<= bits; + rval >>= 8; + + gb->bits += bits; + gb->ptr += (gb->bits>>3); + gb->bits &= 0x7; + + DEBUG("getbits%d, %08x\n", bits, rval); + return rval; +} + +unsigned long _gst_showbits_int(gst_getbits_t *gb, unsigned long bits) { + unsigned long rval; + + if (bits == 0) return 0; + + rval = swab32(*((unsigned long *)(gb->ptr))); + rval <<= gb->bits; + rval >>= (32-bits); + + DEBUG("showbits%d, %08x\n", bits, rval); + return rval; +} + +void _gst_flushbits_int(gst_getbits_t *gb, unsigned long bits) { + gb->bits += bits; + gb->ptr += (gb->bits>>3); + gb->bits &= 0x7; + DEBUG("flushbits%d\n", bits); +} + +void _gst_getbits_back_int(gst_getbits_t *gb, unsigned long bits) { + gb->bits -= bits; + gb->ptr += (gb->bits>>3); + gb->bits &= 0x7; +} -#error Need an implementation of the functions in gstgetbits_i386.s