Mercurial > audlegacy
diff Plugins/Input/wma/libffwma/common.c @ 210:12004b385a96 trunk
[svn] Sync with xmms-wma instead of bmp-wma & GThreadify. Does not explode, but does not play either.
author | chainsaw |
---|---|
date | Sat, 19 Nov 2005 14:42:28 -0800 |
parents | b8d4c1faa6d7 |
children | 0bea7509d6ba |
line wrap: on
line diff
--- a/Plugins/Input/wma/libffwma/common.c Sat Nov 19 05:49:16 2005 -0800 +++ b/Plugins/Input/wma/libffwma/common.c Sat Nov 19 14:42:28 2005 -0800 @@ -2,7 +2,6 @@ * Common bit i/o utils * Copyright (c) 2000, 2001 Fabrice Bellard. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> - * Copyright (c) 2004 Roman Bogorodskiy (bmp-wma specific stuff) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -50,11 +49,74 @@ { 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 } +//#ifdef CONFIG_ENCODERS +#if 1 + +/* return the number of bits output */ +int get_bit_count(PutBitContext *s) +{ +#ifdef ALT_BITSTREAM_WRITER + return s->index; +#else + return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left; +#endif +} + +void align_put_bits(PutBitContext *s) +{ +#ifdef ALT_BITSTREAM_WRITER + put_bits(s,( - s->index) & 7,0); +#else + put_bits(s,s->bit_left & 7,0); +#endif +} + +#endif //CONFIG_ENCODERS + +/* pad the end of the output stream with zeros */ +void flush_put_bits(PutBitContext *s) +{ +#ifdef ALT_BITSTREAM_WRITER + align_put_bits(s); +#else + s->bit_buf<<= s->bit_left; + while (s->bit_left < 32) { + /* XXX: should test end of buffer */ + *s->buf_ptr++=s->bit_buf >> 24; + s->bit_buf<<=8; + s->bit_left+=8; + } + s->bit_left=32; + s->bit_buf=0; +#endif +} + +#ifdef CONFIG_ENCODERS + +void put_string(PutBitContext * pbc, char *s) +{ + while(*s){ + put_bits(pbc, 8, *s); + s++; + } + put_bits(pbc, 8, 0); +} + +/* bit input functions */ + +#endif //CONFIG_ENCODERS + /** * init GetBitContext. * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits @@ -169,7 +231,7 @@ vlc->table_size += size; if (vlc->table_size > vlc->table_allocated) { vlc->table_allocated += (1 << vlc->bits); - vlc->table = realloc(vlc->table, + vlc->table = av_realloc(vlc->table, sizeof(VLC_TYPE) * 2 * vlc->table_allocated); if (!vlc->table) return -1; @@ -189,7 +251,10 @@ table_size = 1 << table_nb_bits; table_index = alloc_table(vlc, table_size); - +#ifdef DEBUG_VLC + printf("new table index=%d size=%d code_prefix=%x n=%d\n", + table_index, table_size, code_prefix, n_prefix); +#endif if (table_index < 0) return -1; table = &vlc->table[table_index]; @@ -206,6 +271,9 @@ /* we accept tables with holes */ if (n <= 0) continue; +#if defined(DEBUG_VLC) && 0 + printf("i=%d n=%d code=0x%x\n", i, n, code); +#endif /* if code matches the prefix, it is in the table */ n -= n_prefix; if (n > 0 && (code >> n) == code_prefix) { @@ -214,6 +282,10 @@ j = (code << (table_nb_bits - n)) & (table_size - 1); nb = 1 << (table_nb_bits - n); for(k=0;k<nb;k++) { +#ifdef DEBUG_VLC + av_log(NULL, AV_LOG_DEBUG, "%4x: code=%d n=%d\n", + j, i, n); +#endif if (table[j][1] /*bits*/ != 0) { av_log(NULL, AV_LOG_ERROR, "incorrect codes\n"); av_abort(); @@ -225,6 +297,10 @@ } else { n -= table_nb_bits; j = (code >> n) & ((1 << table_nb_bits) - 1); +#ifdef DEBUG_VLC + printf("%4x: n=%d (subtable)\n", + j, n); +#endif /* compute table size */ n1 = -table[j][1]; //bits if (n > n1) @@ -288,12 +364,15 @@ vlc->table = NULL; vlc->table_allocated = 0; vlc->table_size = 0; +#ifdef DEBUG_VLC + printf("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, 0, 0) < 0) { - free(vlc->table); + av_free(vlc->table); return -1; } return 0; @@ -302,7 +381,7 @@ void free_vlc(VLC *vlc) { - free(vlc->table); + av_free(vlc->table); } int64_t ff_gcd(int64_t a, int64_t b){