diff --git a/apps/codecs/lib/SOURCES b/apps/codecs/lib/SOURCES index 49e744721d..f9b2447efe 100644 --- a/apps/codecs/lib/SOURCES +++ b/apps/codecs/lib/SOURCES @@ -1,6 +1,7 @@ #if CONFIG_CODEC == SWCODEC /* software codec platforms */ codeclib.c fixedpoint.c +ffmpeg_bitstream.c /* OLD MDCT */ /* (when all other codecs are remediated this can be remoed) */ diff --git a/apps/codecs/lib/ffmpeg_bitstream.c b/apps/codecs/lib/ffmpeg_bitstream.c index 88e3cbfe3a..c879661c47 100644 --- a/apps/codecs/lib/ffmpeg_bitstream.c +++ b/apps/codecs/lib/ffmpeg_bitstream.c @@ -2,6 +2,7 @@ * Common bit i/o utils * Copyright (c) 2000, 2001 Fabrice Bellard * Copyright (c) 2002-2004 Michael Niedermayer + * Copyright (c) 2010 Loren Merritt * * alternative bitstream reader & writer by Michael Niedermayer * @@ -22,7 +23,16 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "ffmpeg_bitstream.h" +/** + * @file + * bitstream api. + */ + +//#include "avcodec.h" +#include "ffmpeg_get_bits.h" +//#include "put_bits.h" + +#define av_log(...) #ifdef ROCKBOX #undef DEBUGF @@ -36,27 +46,47 @@ const uint8_t ff_log2_run[32]={ 8, 9,10,11,12,13,14,15 }; -/** - * Same as av_mallocz_static(), but does a realloc. - * - * @param[in] ptr The block of memory to reallocate. - * @param[in] size The requested size. - * @return Block of memory of requested size. - * @deprecated. Code which uses ff_realloc_static is broken/misdesigned - * and should correctly use static arrays - */ - - -void ff_put_string(PutBitContext * pbc, const char *s, int put_zero) +#if 0 // unused in rockbox +void align_put_bits(PutBitContext *s) { - while(*s){ - put_bits(pbc, 8, *s); - s++; - } - if(put_zero) - put_bits(pbc, 8, 0); +#ifdef ALT_BITSTREAM_WRITER + put_bits(s,( - s->index) & 7,0); +#else + put_bits(s,s->bit_left & 7,0); +#endif } +void ff_put_string(PutBitContext *pb, const char *string, int terminate_string) +{ + while(*string){ + put_bits(pb, 8, *string); + string++; + } + if(terminate_string) + put_bits(pb, 8, 0); +} + +void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length) +{ + int words= length>>4; + int bits= length&15; + int i; + + if(length==0) return; + + if(CONFIG_SMALL || words < 16 || put_bits_count(pb)&7){ + for(i=0; i>(16-bits)); +} +#endif /* VLC decoding */ //#define DEBUG_VLC @@ -84,118 +114,143 @@ static int alloc_table(VLC *vlc, int size, int use_static) index = vlc->table_size; vlc->table_size += size; if (vlc->table_size > vlc->table_allocated) { - if(use_static>1){ + if(use_static) + { DEBUGF("init_vlc() used with too little memory : table_size > allocated_memory\n"); + return -1; } - +// abort(); //cant do anything, init_vlc() is used with too little memory +// vlc->table_allocated += (1 << vlc->bits); +// vlc->table = av_realloc(vlc->table, +// sizeof(VLC_TYPE) * 2 * vlc->table_allocated); if (!vlc->table) return -1; } return index; } -static int build_table(VLC *vlc, int table_nb_bits, - int nb_codes, - const void *bits, int bits_wrap, int bits_size, - const void *codes, int codes_wrap, int codes_size, - const void *symbols, int symbols_wrap, int symbols_size, - uint32_t code_prefix, int n_prefix, int flags) -{ - int i, j, k, n, table_size, table_index, nb, n1, index, code_prefix2, symbol; +/* +static av_always_inline uint32_t bitswap_32(uint32_t x) { + return av_reverse[x&0xFF]<<24 + | av_reverse[(x>>8)&0xFF]<<16 + | av_reverse[(x>>16)&0xFF]<<8 + | av_reverse[x>>24]; +} +*/ + +typedef struct { + uint8_t bits; + uint16_t symbol; + /** codeword, with the first bit-to-be-read in the msb + * (even if intended for a little-endian bitstream reader) */ uint32_t code; +} VLCcode; + +static int compare_vlcspec(const void *a, const void *b) +{ + const VLCcode *sa=a, *sb=b; + return (sa->code >> 1) - (sb->code >> 1); +} + +/** + * Build VLC decoding tables suitable for use with get_vlc(). + * + * @param vlc the context to be initted + * + * @param table_nb_bits max length of vlc codes to store directly in this table + * (Longer codes are delegated to subtables.) + * + * @param nb_codes number of elements in codes[] + * + * @param codes descriptions of the vlc codes + * These must be ordered such that codes going into the same subtable are contiguous. + * Sorting by VLCcode.code is sufficient, though not necessary. + */ +static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, + VLCcode *codes, int flags) +{ + int table_size, table_index, index, symbol, subtable_bits; + int i, j, k, n, nb, inc; + uint32_t code, code_prefix; VLC_TYPE (*table)[2]; table_size = 1 << table_nb_bits; - table_index = alloc_table(vlc, table_size, flags & (INIT_VLC_USE_STATIC|INIT_VLC_USE_NEW_STATIC)); + table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_NEW_STATIC); #ifdef DEBUG_VLC - DEBUGF("new table index=%d size=%d code_prefix=%x n=%d\n", - table_index, table_size, code_prefix, n_prefix); + av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d\n", + table_index, table_size); #endif if (table_index < 0) return -1; table = &vlc->table[table_index]; - for(i=0;i=32 ? (int)0xffffffff : (1 << n_prefix)-1); - else - code_prefix2= code >> n; - if (n > 0 && code_prefix2 == (int)code_prefix) { - if (n <= table_nb_bits) { - /* no need to add another table */ - j = (code << (table_nb_bits - n)) & (table_size - 1); - nb = 1 << (table_nb_bits - n); - for(k=0;k> n_prefix) + (k<> (32 - table_nb_bits); + nb = 1 << (table_nb_bits - n); + inc = 1; +/* if (flags & INIT_VLC_LE) { + j = bitswap_32(code); + inc = 1 << n; + } */ + for (k = 0; k < nb; k++) { #ifdef DEBUG_VLC - DEBUGF("%4x: code=%d n=%d\n", - j, i, n); + av_log(NULL, AV_LOG_DEBUG, "%4x: code=%d n=%d\n", + j, i, n); #endif - if (table[j][1] /*bits*/ != 0) { - DEBUGF("incorrect codes\n"); - return -1; - } - table[j][1] = n; //bits - table[j][0] = symbol; - j++; + if (table[j][1] /*bits*/ != 0) { + av_log(NULL, AV_LOG_ERROR, "incorrect codes\n"); + return -1; } - } else { - n -= table_nb_bits; - j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1); + table[j][1] = n; //bits + table[j][0] = symbol; + j += inc; + } + } else { + /* fill auxiliary table recursively */ + n -= table_nb_bits; + code_prefix = code >> (32 - table_nb_bits); + subtable_bits = n; + codes[i].bits = n; + codes[i].code = code << table_nb_bits; + for (k = i+1; k < nb_codes; k++) { + n = codes[k].bits - table_nb_bits; + if (n <= 0) + break; + code = codes[k].code; + if (code >> (32 - table_nb_bits) != code_prefix) + break; + codes[k].bits = n; + codes[k].code = code << table_nb_bits; + subtable_bits = FFMAX(subtable_bits, n); + } + subtable_bits = FFMIN(subtable_bits, table_nb_bits); + j = /*(flags & INIT_VLC_LE) ? bitswap_32(code_prefix) >> (32 - table_nb_bits) :*/ code_prefix; + table[j][1] = -subtable_bits; #ifdef DEBUG_VLC - DEBUGF("%4x: n=%d (subtable)\n", - j, n); + av_log(NULL,AV_LOG_DEBUG,"%4x: n=%d (subtable)\n", + j, codes[i].bits + table_nb_bits); #endif - /* compute table size */ - n1 = -table[j][1]; //bits - if (n > n1) - n1 = n; - table[j][1] = -n1; //bits - } - } - } - - /* second pass : fill auxillary tables recursively */ - for(i=0;i table_nb_bits) { - n = table_nb_bits; - table[i][1] = -n; //bits - } - index = build_table(vlc, n, nb_codes, - bits, bits_wrap, bits_size, - codes, codes_wrap, codes_size, - symbols, symbols_wrap, symbols_size, - (flags & INIT_VLC_LE) ? (code_prefix | (i << n_prefix)) : ((code_prefix << table_nb_bits) | i), - n_prefix + table_nb_bits, flags); + index = build_table(vlc, subtable_bits, k-i, codes+i, flags); if (index < 0) return -1; /* note: realloc has been done, so reload tables */ table = &vlc->table[table_index]; - table[i][0] = index; //code + table[j][0] = index; //code + i = k-1; } } return table_index; @@ -228,49 +283,83 @@ static int build_table(VLC *vlc, int table_nb_bits, 'use_static' should be set to 1 for tables, which should be freed with av_free_static(), 0 if free_vlc() will be used. */ + +/* Rockbox: support for INIT_VLC_LE is currently disabled since none of our + codecs use it, there's a LUT based bit reverse function for this commented + out above (bitswap_32) and an inline asm version in libtremor/codebook.c + if we ever want this */ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags) { + VLCcode buf[nb_codes+1]; /* worst case from cook seems to be nb_codes == 607 + which would make this about 4.8k... */ + int i, j, ret; + vlc->bits = nb_bits; if(flags & INIT_VLC_USE_NEW_STATIC){ if(vlc->table_size && vlc->table_size == vlc->table_allocated){ return 0; }else if(vlc->table_size){ - return -1; // fatal error, we are called on a partially initialized table + DEBUGF("fatal error, we are called on a partially initialized table\n"); + return -1; +// abort(); // fatal error, we are called on a partially initialized table } - }else if(!(flags & INIT_VLC_USE_STATIC)) { + }else { vlc->table = NULL; vlc->table_allocated = 0; vlc->table_size = 0; - } else { - /* Static tables are initially always NULL, return - if vlc->table != NULL to avoid double allocation */ - if(vlc->table) - return 0; } #ifdef DEBUG_VLC - DEBUGF("build table nb_codes=%d\n", nb_codes); + av_log(NULL,AV_LOG_DEBUG,"build table nb_codes=%d\n", nb_codes); #endif - if (build_table(vlc, nb_bits, nb_codes, - bits, bits_wrap, bits_size, - codes, codes_wrap, codes_size, - symbols, symbols_wrap, symbols_size, - 0, 0, flags) < 0) { - //free(&vlc->table); +// buf = av_malloc((nb_codes+1)*sizeof(VLCcode)); + +// assert(symbols_size <= 2 || !symbols); + j = 0; +#define COPY(condition)\ + for (i = 0; i < nb_codes; i++) {\ + GET_DATA(buf[j].bits, bits, i, bits_wrap, bits_size);\ + if (!(condition))\ + continue;\ + GET_DATA(buf[j].code, codes, i, codes_wrap, codes_size);\ +/* if (flags & INIT_VLC_LE)*/\ +/* buf[j].code = bitswap_32(buf[j].code);*/\ +/* else*/\ + buf[j].code <<= 32 - buf[j].bits;\ + if (symbols)\ + GET_DATA(buf[j].symbol, symbols, i, symbols_wrap, symbols_size)\ + else\ + buf[j].symbol = i;\ + j++;\ + } + COPY(buf[j].bits > nb_bits); + // qsort is the slowest part of init_vlc, and could probably be improved or avoided + qsort(buf, j, sizeof(VLCcode), compare_vlcspec); + COPY(buf[j].bits && buf[j].bits <= nb_bits); + nb_codes = j; + + ret = build_table(vlc, nb_bits, nb_codes, buf, flags); + +// av_free(buf); + if (ret < 0) { +// av_freep(&vlc->table); return -1; } - /* Changed the following condition to be true if table_size > table_allocated. * - * This would be more sensible for static tables since we want warnings for * - * memory shortages only. */ -#ifdef TEST - if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size > vlc->table_allocated) - DEBUGF("needed %d had %d\n", vlc->table_size, vlc->table_allocated); -#endif + if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size != vlc->table_allocated) { + av_log(NULL, AV_LOG_ERROR, "needed %d had %d\n", vlc->table_size, vlc->table_allocated); + } return 0; } +/* not used in rockbox +void free_vlc(VLC *vlc) +{ + av_freep(&vlc->table); +} +*/ + diff --git a/apps/codecs/lib/ffmpeg_bitstream.h b/apps/codecs/lib/ffmpeg_get_bits.h similarity index 66% rename from apps/codecs/lib/ffmpeg_bitstream.h rename to apps/codecs/lib/ffmpeg_get_bits.h index f0105a4afe..1a461e9e25 100644 --- a/apps/codecs/lib/ffmpeg_bitstream.h +++ b/apps/codecs/lib/ffmpeg_get_bits.h @@ -18,140 +18,93 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef BITSTREAM_H -#define BITSTREAM_H +/** + * @file + * bitstream reader API header. + */ -#include +#ifndef AVCODEC_GET_BITS_H +#define AVCODEC_GET_BITS_H + +#include #include //#include -#include -#include -#include "ffmpeg_bswap.h" +//#include "libavutil/bswap.h" +//#include "libavutil/common.h" +//#include "libavutil/intreadwrite.h" +//#include "libavutil/log.h" +//#include "mathops.h" -/* The following 2 defines are taken from libavutil/intreadwrite.h */ +#include "codecs.h" + +/* rockbox' optimised inline functions */ +#define bswap_16(x) swap16(x) +#define bswap_32(x) swap32(x) + +#ifdef ROCKBOX_BIG_ENDIAN +#define be2me_16(x) (x) +#define be2me_32(x) (x) +#define le2me_16(x) bswap_16(x) +#define le2me_32(x) bswap_32(x) +#else +#define be2me_16(x) bswap_16(x) +#define be2me_32(x) bswap_32(x) +#define le2me_16(x) (x) +#define le2me_32(x) (x) +#endif + +#define av_const __attribute__((const)) +#define av_always_inline inline __attribute__((always_inline)) + +/* Coldfire cpu's support unaligned long reads */ +#ifdef CPU_COLDFIRE +#define AV_RB32(x) (*(const uint32_t*)(x)) +#else +/* The following define is taken from libavutil/intreadwrite.h */ #define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \ (((const uint8_t*)(x))[1] << 16) | \ (((const uint8_t*)(x))[2] << 8) | \ ((const uint8_t*)(x))[3]) -#define AV_WB32(p, d) do { \ - ((uint8_t*)(p))[3] = (d); \ - ((uint8_t*)(p))[2] = (d)>>8; \ - ((uint8_t*)(p))[1] = (d)>>16; \ - ((uint8_t*)(p))[0] = (d)>>24; } while(0) +#endif +/* The following is taken from mathops.h */ + +#ifndef sign_extend +static inline av_const int sign_extend(int val, unsigned bits) +{ + return (val << ((8 * sizeof(int)) - bits)) >> ((8 * sizeof(int)) - bits); +} +#endif + +#ifndef NEG_SSR32 +# define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s))) +#endif + +#ifndef NEG_USR32 +# define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s))) +#endif + +/* these 2 are from libavutil/common.h */ + +#define FFMAX(a,b) ((a) > (b) ? (a) : (b)) +#define FFMIN(a,b) ((a) > (b) ? (b) : (a)) #if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER) # define ALT_BITSTREAM_READER #endif -//#define ALT_BITSTREAM_WRITER -//#define ALIGNED_BITSTREAM_WRITER +/* #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER) -# if defined(ARCH_ARM) +# if ARCH_ARM && !HAVE_FAST_UNALIGNED # define A32_BITSTREAM_READER # else +*/ # define ALT_BITSTREAM_READER +/* //#define LIBMPEG2_BITSTREAM_READER //#define A32_BITSTREAM_READER # endif #endif - -extern const uint8_t ff_reverse[256]; - -#if defined(ARCH_X86) -// avoid +32 for shift optimization (gcc should do that ...) -static inline int32_t NEG_SSR32( int32_t a, int8_t s){ - __asm__ ("sarl %1, %0\n\t" - : "+r" (a) - : "ic" ((uint8_t)(-s)) - ); - return a; -} -static inline uint32_t NEG_USR32(uint32_t a, int8_t s){ - __asm__ ("shrl %1, %0\n\t" - : "+r" (a) - : "ic" ((uint8_t)(-s)) - ); - return a; -} -#else -# define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s))) -# define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s))) -#endif - -/* bit output */ - -/* buf and buf_end must be present and used by every alternative writer. */ -typedef struct PutBitContext { -#ifdef ALT_BITSTREAM_WRITER - uint8_t *buf, *buf_end; - int index; -#else - uint32_t bit_buf; - int bit_left; - uint8_t *buf, *buf_ptr, *buf_end; -#endif - int size_in_bits; -} PutBitContext; - -static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size) -{ - if(buffer_size < 0) { - buffer_size = 0; - buffer = NULL; - } - - s->size_in_bits= 8*buffer_size; - s->buf = buffer; - s->buf_end = s->buf + buffer_size; -#ifdef ALT_BITSTREAM_WRITER - s->index=0; - ((uint32_t*)(s->buf))[0]=0; -// memset(buffer, 0, buffer_size); -#else - s->buf_ptr = s->buf; - s->bit_left=32; - s->bit_buf=0; -#endif -} - -/* return the number of bits output */ -static inline int put_bits_count(PutBitContext *s) -{ -#ifdef ALT_BITSTREAM_WRITER - return s->index; -#else - return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left; -#endif -} - -/* pad the end of the output stream with zeros */ -static inline void flush_put_bits(PutBitContext *s) -{ -#ifdef ALT_BITSTREAM_WRITER - align_put_bits(s); -#else -#ifndef BITSTREAM_WRITER_LE - s->bit_buf<<= s->bit_left; -#endif - while (s->bit_left < 32) { - /* XXX: should test end of buffer */ -#ifdef BITSTREAM_WRITER_LE - *s->buf_ptr++=s->bit_buf; - s->bit_buf>>=8; -#else - *s->buf_ptr++=s->bit_buf >> 24; - s->bit_buf<<=8; -#endif - s->bit_left+=8; - } - s->bit_left=32; - s->bit_buf=0; -#endif -} - -void align_put_bits(PutBitContext *s); -void ff_put_string(PutBitContext * pbc, const char *s, int put_zero); -void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length); +*/ /* bit input */ /* buffer, buffer_end and size_in_bits must be present and used by every reader */ @@ -186,179 +139,6 @@ typedef struct RL_VLC_ELEM { uint8_t run; } RL_VLC_ELEM; -#ifndef ALT_BITSTREAM_WRITER -static inline void put_bits(PutBitContext *s, int n, unsigned int value) -{ - unsigned int bit_buf; - int bit_left; - - // printf("put_bits=%d %x\n", n, value); - //assert(n == 32 || value < (1U << n)); - - bit_buf = s->bit_buf; - bit_left = s->bit_left; - - // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf); - /* XXX: optimize */ -#ifdef BITSTREAM_WRITER_LE - bit_buf |= value << (32 - bit_left); - if (n >= bit_left) { -#if !HAVE_FAST_UNALIGNED - if (3 & (intptr_t) s->buf_ptr) { - AV_WL32(s->buf_ptr, bit_buf); - } else -#endif - *(uint32_t *)s->buf_ptr = le2me_32(bit_buf); - s->buf_ptr+=4; - bit_buf = (bit_left==32)?0:value >> bit_left; - bit_left+=32; - } - bit_left-=n; -#else - if (n < bit_left) { - bit_buf = (bit_buf<> (n - bit_left); -#if !defined(HAVE_FAST_UNALIGNED) - if (3 & (intptr_t) s->buf_ptr) { - AV_WB32(s->buf_ptr, bit_buf); - } else -#endif - *(uint32_t *)s->buf_ptr = be2me_32(bit_buf); - //printf("bitbuf = %08x\n", bit_buf); - s->buf_ptr+=4; - bit_left+=32 - n; - bit_buf = value; - } -#endif - - s->bit_buf = bit_buf; - s->bit_left = bit_left; -} -#endif - - -#ifdef ALT_BITSTREAM_WRITER -static inline void put_bits(PutBitContext *s, int n, unsigned int value) -{ -# ifdef ALIGNED_BITSTREAM_WRITER -# if ARCH_X86 - __asm__ volatile( - "movl %0, %%ecx \n\t" - "xorl %%eax, %%eax \n\t" - "shrdl %%cl, %1, %%eax \n\t" - "shrl %%cl, %1 \n\t" - "movl %0, %%ecx \n\t" - "shrl $3, %%ecx \n\t" - "andl $0xFFFFFFFC, %%ecx \n\t" - "bswapl %1 \n\t" - "orl %1, (%2, %%ecx) \n\t" - "bswapl %%eax \n\t" - "addl %3, %0 \n\t" - "movl %%eax, 4(%2, %%ecx) \n\t" - : "=&r" (s->index), "=&r" (value) - : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n)) - : "%eax", "%ecx" - ); -# else - int index= s->index; - uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5); - - value<<= 32-n; - - ptr[0] |= be2me_32(value>>(index&31)); - ptr[1] = be2me_32(value<<(32-(index&31))); -//if(n>24) printf("%d %d\n", n, value); - index+= n; - s->index= index; -# endif -# else //ALIGNED_BITSTREAM_WRITER -# if ARCH_X86 - __asm__ volatile( - "movl $7, %%ecx \n\t" - "andl %0, %%ecx \n\t" - "addl %3, %%ecx \n\t" - "negl %%ecx \n\t" - "shll %%cl, %1 \n\t" - "bswapl %1 \n\t" - "movl %0, %%ecx \n\t" - "shrl $3, %%ecx \n\t" - "orl %1, (%%ecx, %2) \n\t" - "addl %3, %0 \n\t" - "movl $0, 4(%%ecx, %2) \n\t" - : "=&r" (s->index), "=&r" (value) - : "r" (s->buf), "r" (n), "0" (s->index), "1" (value) - : "%ecx" - ); -# else - int index= s->index; - uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3)); - - ptr[0] |= be2me_32(value<<(32-n-(index&7) )); - ptr[1] = 0; -//if(n>24) printf("%d %d\n", n, value); - index+= n; - s->index= index; -# endif -# endif //!ALIGNED_BITSTREAM_WRITER -} -#endif - -static inline void put_sbits(PutBitContext *pb, int bits, int32_t val) -{ - //assert(bits >= 0 && bits <= 31); - - put_bits(pb, bits, val & ((1<buf + (s->index>>3); -#else - return s->buf_ptr; -#endif -} - -/** - * - * PutBitContext must be flushed & aligned to a byte boundary before calling this. - */ -static inline void skip_put_bytes(PutBitContext *s, int n){ - //assert((put_bits_count(s)&7)==0); -#ifdef ALT_BITSTREAM_WRITER - FIXME may need some cleaning of the buffer - s->index += n<<3; -#else - //assert(s->bit_left==32); - s->buf_ptr += n; -#endif -} - -/** - * Skips the given number of bits. - * Must only be used if the actual values in the bitstream do not matter. - */ -static inline void skip_put_bits(PutBitContext *s, int n){ -#ifdef ALT_BITSTREAM_WRITER - s->index += n; -#else - s->bit_left -= n; - s->buf_ptr-= s->bit_left>>5; - s->bit_left &= 31; -#endif -} - -/** - * Changes the end of the buffer. - */ -static inline void set_put_bits_buffer_size(PutBitContext *s, int size){ - s->buf_end= s->buf + size; -} - /* Bitstream reader API docs: name arbitrary name which is used as prefix for the internal variables @@ -399,7 +179,7 @@ LAST_SKIP_CACHE(name, gb, num) will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing LAST_SKIP_BITS(name, gb, num) - is equivalent to SKIP_LAST_CACHE; SKIP_COUNTER + is equivalent to LAST_SKIP_CACHE; SKIP_COUNTER for examples see get_bits, show_bits, skip_bits, get_vlc */ @@ -408,7 +188,7 @@ for examples see get_bits, show_bits, skip_bits, get_vlc # define MIN_CACHE_BITS 25 # define OPEN_READER(name, gb)\ - int name##_index= (gb)->index;\ + unsigned int name##_index= (gb)->index;\ int name##_cache= 0;\ # define CLOSE_READER(name, gb)\ @@ -443,10 +223,10 @@ for examples see get_bits, show_bits, skip_bits, get_vlc # ifdef ALT_BITSTREAM_READER_LE # define SHOW_UBITS(name, gb, num)\ - ((name##_cache) & (NEG_USR32(0xffffffff,num))) + zero_extend(name##_cache, num) # define SHOW_SBITS(name, gb, num)\ - NEG_SSR32((name##_cache)<<(32-(num)), num) + sign_extend(name##_cache, num) # else # define SHOW_UBITS(name, gb, num)\ NEG_USR32(name##_cache, num) @@ -458,7 +238,7 @@ for examples see get_bits, show_bits, skip_bits, get_vlc # define GET_CACHE(name, gb)\ ((uint32_t)name##_cache) -static inline int get_bits_count(GetBitContext *s){ +static inline int get_bits_count(const GetBitContext *s){ return s->index; } @@ -512,7 +292,7 @@ static inline void skip_bits_long(GetBitContext *s, int n){ # define GET_CACHE(name, gb)\ ((uint32_t)name##_cache) -static inline int get_bits_count(GetBitContext *s){ +static inline int get_bits_count(const GetBitContext *s){ return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count; } @@ -544,7 +324,7 @@ static inline void skip_bits_long(GetBitContext *s, int n){ # define UPDATE_CACHE(name, gb)\ if(name##_bit_count > 0){\ - const uint32_t next= be2me_32( *name##_buffer_ptr );\ + const uint32_t next= av_be2ne32( *name##_buffer_ptr );\ name##_cache0 |= NEG_USR32(next,name##_bit_count);\ name##_cache1 |= next<buffer_ptr - s->buffer)*8 - 32 + s->bit_count; } @@ -596,7 +376,7 @@ static inline void skip_bits_long(GetBitContext *s, int n){ re_bit_count += n; re_buffer_ptr += re_bit_count>>5; re_bit_count &= 31; - re_cache0 = be2me_32( re_buffer_ptr[-1] ) << re_bit_count; + re_cache0 = av_be2ne32( re_buffer_ptr[-1] ) << re_bit_count; re_cache1 = 0; UPDATE_CACHE(re, s) CLOSE_READER(re, s) @@ -669,7 +449,7 @@ static inline void skip_bits(GetBitContext *s, int n){ static inline unsigned int get_bits1(GetBitContext *s){ #ifdef ALT_BITSTREAM_READER - int index= s->index; + unsigned int index= s->index; uint8_t result= s->buffer[ index>>3 ]; #ifdef ALT_BITSTREAM_READER_LE result>>= (index&0x07); @@ -699,7 +479,7 @@ static inline void skip_bits1(GetBitContext *s){ * reads 0-32 bits. */ static inline unsigned int get_bits_long(GetBitContext *s, int n){ - if(n<=17) return get_bits(s, n); + if(n<=MIN_CACHE_BITS) return get_bits(s, n); else{ #ifdef ALT_BITSTREAM_READER_LE int ret= get_bits(s, 16); @@ -711,42 +491,43 @@ static inline unsigned int get_bits_long(GetBitContext *s, int n){ } } -#if 0 /** * reads 0-32 bits as a signed integer. */ static inline int get_sbits_long(GetBitContext *s, int n) { return sign_extend(get_bits_long(s, n), n); } -#endif /** * shows 0-32 bits. */ static inline unsigned int show_bits_long(GetBitContext *s, int n){ - if(n<=17) return show_bits(s, n); + if(n<=MIN_CACHE_BITS) return show_bits(s, n); else{ GetBitContext gb= *s; return get_bits_long(&gb, n); } } -#if 0 +/* not used static inline int check_marker(GetBitContext *s, const char *msg) { int bit= get_bits1(s); if(!bit) - printf("Marker bit missing %s\n", msg); + av_log(NULL, AV_LOG_INFO, "Marker bit missing %s\n", msg); return bit; } -#endif +*/ /** * init GetBitContext. * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end * @param bit_size the size of the buffer in bits + * + * While GetBitContext stores the buffer size, for performance reasons you are + * responsible for checking for the buffer end yourself (take advantage of the padding)! */ static inline void init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size) @@ -793,7 +574,6 @@ int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags); -#define INIT_VLC_USE_STATIC 1 ///< VERY strongly deprecated and forbidden #define INIT_VLC_LE 2 #define INIT_VLC_USE_NEW_STATIC 4 void free_vlc(VLC *vlc); @@ -809,13 +589,14 @@ void free_vlc(VLC *vlc); /** * - * if the vlc code is invalid and max_depth=1 than no bits will be removed - * if the vlc code is invalid and max_depth>1 than the number of bits removed - * is undefined + * If the vlc code is invalid and max_depth=1, then no bits will be removed. + * If the vlc code is invalid and max_depth>1, then the number of bits removed + * is undefined. */ #define GET_VLC(code, name, gb, table, bits, max_depth)\ {\ - int n, index, nb_bits;\ + int n, nb_bits;\ + unsigned int index;\ \ index= SHOW_UBITS(name, gb, bits);\ code = table[index][0];\ @@ -846,7 +627,8 @@ void free_vlc(VLC *vlc); #define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\ {\ - int n, index, nb_bits;\ + int n, nb_bits;\ + unsigned int index;\ \ index= SHOW_UBITS(name, gb, bits);\ level = table[index].level;\ @@ -877,7 +659,7 @@ void free_vlc(VLC *vlc); * read the longest vlc code * = (max_vlc_length + bits - 1) / bits */ -static inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2], +static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth) { int code; @@ -898,17 +680,17 @@ static inline void print_bin(int bits, int n){ int i; for(i=n-1; i>=0; i--){ - printf("%d", (bits>>i)&1); + av_log(NULL, AV_LOG_DEBUG, "%d", (bits>>i)&1); } for(i=n; i<24; i++) - printf(" "); + av_log(NULL, AV_LOG_DEBUG, " "); } static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ int r= get_bits(s, n); print_bin(r, n); - printf("%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line); + av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line); return r; } static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){ @@ -920,7 +702,7 @@ static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits print_bin(bits2, len); - printf("%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line); + av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line); return r; } static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ @@ -928,7 +710,7 @@ static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const cha int r= get_xbits(s, n); print_bin(show, n); - printf("%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line); + av_log(NULL, AV_LOG_DEBUG, "%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line); return r; } @@ -938,7 +720,7 @@ static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const cha #define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__) #define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__) -#define tprintf(p, ...) printf +#define tprintf(p, ...) av_log(p, AV_LOG_DEBUG, __VA_ARGS__) #else //TRACE #define tprintf(p, ...) {} @@ -960,4 +742,9 @@ static inline int decode210(GetBitContext *gb){ return 2 - get_bits1(gb); } -#endif /* BITSTREAM_H */ +static inline int get_bits_left(GetBitContext *gb) +{ + return gb->size_in_bits - get_bits_count(gb); +} + +#endif /* AVCODEC_GET_BITS_H */ diff --git a/apps/codecs/libatrac/SOURCES b/apps/codecs/libatrac/SOURCES index 5a033c1732..3eaf4c9c3b 100644 --- a/apps/codecs/libatrac/SOURCES +++ b/apps/codecs/libatrac/SOURCES @@ -2,4 +2,4 @@ atrac3.c #if defined(CPU_ARM) atrac3_arm.S #endif -../lib/ffmpeg_bitstream.c + diff --git a/apps/codecs/libatrac/atrac3.h b/apps/codecs/libatrac/atrac3.h index d3fdc5056a..74dd992e1b 100644 --- a/apps/codecs/libatrac/atrac3.h +++ b/apps/codecs/libatrac/atrac3.h @@ -19,7 +19,7 @@ * ****************************************************************************/ -#include "ffmpeg_bitstream.h" +#include "ffmpeg_get_bits.h" #include "../librm/rm.h" #include "codeclib.h" diff --git a/apps/codecs/libcook/SOURCES b/apps/codecs/libcook/SOURCES index d093173aea..b656fdd2f7 100644 --- a/apps/codecs/libcook/SOURCES +++ b/apps/codecs/libcook/SOURCES @@ -1,2 +1,2 @@ cook.c -../lib/ffmpeg_bitstream.c + diff --git a/apps/codecs/libcook/cook.h b/apps/codecs/libcook/cook.h index 93abf9a52d..51d6fd34f2 100644 --- a/apps/codecs/libcook/cook.h +++ b/apps/codecs/libcook/cook.h @@ -23,7 +23,7 @@ #define _COOK_H #include -#include "ffmpeg_bitstream.h" +#include "ffmpeg_get_bits.h" #include "../librm/rm.h" #include "cookdata_fixpoint.h" diff --git a/apps/codecs/libffmpegFLAC/SOURCES b/apps/codecs/libffmpegFLAC/SOURCES index deed19bcec..63094b30a6 100644 --- a/apps/codecs/libffmpegFLAC/SOURCES +++ b/apps/codecs/libffmpegFLAC/SOURCES @@ -1,4 +1,3 @@ -bitstream.c decoder.c shndec.c #if defined(CPU_COLDFIRE) diff --git a/apps/codecs/libffmpegFLAC/bitstream.c b/apps/codecs/libffmpegFLAC/bitstream.c deleted file mode 100644 index e53ec0fd46..0000000000 --- a/apps/codecs/libffmpegFLAC/bitstream.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Common bit i/o utils - * Copyright (c) 2000, 2001 Fabrice Bellard. - * Copyright (c) 2002-2004 Michael Niedermayer - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * alternative bitstream reader & writer by Michael Niedermayer - */ - -/** - * @file bitstream.c - * bitstream api. - */ - -#include -#include "bitstream.h" - -/* bit input functions */ - -/** - * reads 0-32 bits. - */ -unsigned int get_bits_long(GetBitContext *s, int n){ - if(n<=17) return get_bits(s, n); - else{ - int ret= get_bits(s, 16) << (n-16); - return ret | get_bits(s, n-16); - } -} - -/** - * shows 0-32 bits. - */ -unsigned int show_bits_long(GetBitContext *s, int n){ - if(n<=17) return show_bits(s, n); - else{ - GetBitContext gb= *s; - int ret= get_bits_long(s, n); - *s= gb; - return ret; - } -} - -void align_get_bits(GetBitContext *s) -{ - int n= (-get_bits_count(s)) & 7; - if(n) skip_bits(s, n); -} - diff --git a/apps/codecs/libffmpegFLAC/bitstream.h b/apps/codecs/libffmpegFLAC/bitstream.h index 9a8c548d95..1333b9f4b8 100644 --- a/apps/codecs/libffmpegFLAC/bitstream.h +++ b/apps/codecs/libffmpegFLAC/bitstream.h @@ -7,6 +7,7 @@ #define BITSTREAM_H #include +#include "ffmpeg_get_bits.h" #ifndef BUILD_STANDALONE #include @@ -61,281 +62,4 @@ } #endif -/* FLAC files are big-endian */ -#define ALT_BITSTREAM_READER_BE - -#define NEG_SSR32(a,s) (((int32_t)(a))>>(32-(s))) -#define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s))) - -/* bit input */ -/* buffer, buffer_end and size_in_bits must be present and used by every reader */ -typedef struct GetBitContext { - const uint8_t *buffer, *buffer_end; - int index; - int size_in_bits; -} GetBitContext; - -#define VLC_TYPE int16_t - -typedef struct VLC { - int bits; - VLC_TYPE (*table)[2]; ///< code, bits - int table_size, table_allocated; -} VLC; - -typedef struct RL_VLC_ELEM { - int16_t level; - int8_t len; - uint8_t run; -} RL_VLC_ELEM; - -#if defined(ARCH_SPARC) || defined(ARCH_ARMV4L) -#define UNALIGNED_STORES_ARE_BAD -#endif - -/* used to avoid missaligned exceptions on some archs (alpha, ...) */ -#if defined(ARCH_X86) || defined(ARCH_X86_64) -# define unaligned32(a) (*(const 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 - - -/* Bitstream reader API docs: -name - abritary name which is used as prefix for the internal variables - -gb - getbitcontext - -OPEN_READER(name, gb) - loads gb into local variables - -CLOSE_READER(name, gb) - stores local vars in gb - -UPDATE_CACHE(name, gb) - refills the internal cache from the bitstream - after this call at least MIN_CACHE_BITS will be available, - -GET_CACHE(name, gb) - will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit) - -SHOW_UBITS(name, gb, num) - will return the next num bits - -SHOW_SBITS(name, gb, num) - will return the next num bits and do sign extension - -SKIP_BITS(name, gb, num) - will skip over the next num bits - note, this is equivalent to SKIP_CACHE; SKIP_COUNTER - -SKIP_CACHE(name, gb, num) - will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER) - -SKIP_COUNTER(name, gb, num) - will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS) - -LAST_SKIP_CACHE(name, gb, num) - will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing - -LAST_SKIP_BITS(name, gb, num) - is equivalent to SKIP_LAST_CACHE; SKIP_COUNTER - -for examples see get_bits, show_bits, skip_bits, get_vlc -*/ - -static inline int unaligned32_be(const void *v) -{ -#ifdef CONFIG_ALIGN - const uint8_t *p=v; - return (((p[0]<<8) | p[1])<<16) | (p[2]<<8) | (p[3]); -#else - return betoh32( unaligned32(v)); //original -#endif -} - -static inline int unaligned32_le(const void *v) -{ -#ifdef CONFIG_ALIGN - const uint8_t *p=v; - return (((p[3]<<8) | p[2])<<16) | (p[1]<<8) | (p[0]); -#else - return letoh32( unaligned32(v)); //original -#endif -} - -# define MIN_CACHE_BITS 25 - -# define OPEN_READER(name, gb)\ - int name##_index= (gb)->index;\ - int name##_cache= 0;\ - -# define CLOSE_READER(name, gb)\ - (gb)->index= name##_index;\ - -# ifdef ALT_BITSTREAM_READER_LE -# define UPDATE_CACHE(name, gb)\ - name##_cache= unaligned32_le( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\ - -# define SKIP_CACHE(name, gb, num)\ - name##_cache >>= (num); -# else -# define UPDATE_CACHE(name, gb)\ - name##_cache= unaligned32_be( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\ - -# define SKIP_CACHE(name, gb, num)\ - name##_cache <<= (num); -# endif - -// FIXME name? -# define SKIP_COUNTER(name, gb, num)\ - name##_index += (num);\ - -# define SKIP_BITS(name, gb, num)\ - {\ - SKIP_CACHE(name, gb, num)\ - SKIP_COUNTER(name, gb, num)\ - }\ - -# define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num) -# define LAST_SKIP_CACHE(name, gb, num) ; - -# ifdef ALT_BITSTREAM_READER_LE -# define SHOW_UBITS(name, gb, num)\ - ((name##_cache) & (NEG_USR32(0xffffffff,num))) -# else -# define SHOW_UBITS(name, gb, num)\ - NEG_USR32(name##_cache, num) -# endif - -# define SHOW_SBITS(name, gb, num)\ - NEG_SSR32(name##_cache, num) - -# define GET_CACHE(name, gb)\ - ((uint32_t)name##_cache) - -static inline int get_bits_count(GetBitContext *s){ - return s->index; -} - -static inline int get_sbits(GetBitContext *s, int n){ - register int tmp; - OPEN_READER(re, s) - UPDATE_CACHE(re, s) - tmp= SHOW_SBITS(re, s, n); - LAST_SKIP_BITS(re, s, n) - CLOSE_READER(re, s) - return tmp; -} - -/** - * reads 0-17 bits. - * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't - */ -static inline unsigned int get_bits(GetBitContext *s, int n){ - register int tmp; - OPEN_READER(re, s) - UPDATE_CACHE(re, s) - tmp= SHOW_UBITS(re, s, n); - LAST_SKIP_BITS(re, s, n) - CLOSE_READER(re, s) - return tmp; -} - -unsigned int get_bits_long(GetBitContext *s, int n) ICODE_ATTR_FLAC; - -/** - * shows 0-17 bits. - * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't - */ -static inline unsigned int show_bits(GetBitContext *s, int n){ - register int tmp; - OPEN_READER(re, s) - UPDATE_CACHE(re, s) - tmp= SHOW_UBITS(re, s, n); -// CLOSE_READER(re, s) - return tmp; -} - -unsigned int show_bits_long(GetBitContext *s, int n) ICODE_ATTR_FLAC; - -static inline void skip_bits(GetBitContext *s, int n){ - //Note gcc seems to optimize this to s->index+=n for the ALT_READER :)) - OPEN_READER(re, s) - UPDATE_CACHE(re, s) - LAST_SKIP_BITS(re, s, n) - CLOSE_READER(re, s) -} - -static inline unsigned int get_bits1(GetBitContext *s){ - int index= s->index; - uint8_t result= s->buffer[ index>>3 ]; -#ifdef ALT_BITSTREAM_READER_LE - result>>= (index&0x07); - result&= 1; -#else - result<<= (index&0x07); - result>>= 8 - 1; -#endif - index++; - s->index= index; - - return result; -} - -static inline unsigned int show_bits1(GetBitContext *s){ - return show_bits(s, 1); -} - -static inline void skip_bits1(GetBitContext *s){ - skip_bits(s, 1); -} - -/** - * init GetBitContext. - * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits - * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end - * @param bit_size the size of the buffer in bits - */ -static inline void init_get_bits(GetBitContext *s, - const uint8_t *buffer, int bit_size) -{ - int buffer_size= (bit_size+7)>>3; - if(buffer_size < 0 || bit_size < 0) { - buffer_size = bit_size = 0; - buffer = 0; - } - - s->buffer= buffer; - s->size_in_bits= bit_size; - s->buffer_end= buffer + buffer_size; - s->index=0; - { - OPEN_READER(re, s) - UPDATE_CACHE(re, s) - UPDATE_CACHE(re, s) - CLOSE_READER(re, s) - } -} - -void align_get_bits(GetBitContext *s) ICODE_ATTR_FLAC; - #endif /* BITSTREAM_H */ diff --git a/apps/codecs/libffmpegFLAC/shndec.c b/apps/codecs/libffmpegFLAC/shndec.c index fb11f77bfa..b107b356d7 100644 --- a/apps/codecs/libffmpegFLAC/shndec.c +++ b/apps/codecs/libffmpegFLAC/shndec.c @@ -54,22 +54,11 @@ #define VERBATIM_BYTE_SIZE 8 #define CANONICAL_HEADER_SIZE 44 -#define FFMAX(a,b) ((a) > (b) ? (a) : (b)) -#define FFMIN(a,b) ((a) > (b) ? (b) : (a)) #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24)) #define get_le16(gb) bswap_16(get_bits_long(gb, 16)) #define get_le32(gb) bswap_32(get_bits_long(gb, 32)) -static uint32_t bswap_32(uint32_t x){ - x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); - return (x>>16) | (x<<16); -} - -static uint16_t bswap_16(uint16_t x){ - return (x>>8) | (x<<8); -} - /* converts fourcc string to int */ static int ff_get_fourcc(const char *s){ //assert( strlen(s)==4 );