X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fwmadec.c;h=e0788375fae7ff4b17e016f08216f1d32777bb84;hb=160d679c075e9f575f96ea2c2c000545a49916a0;hp=d3aff0a67fabc890fa82e8d74af188d78a0dd1ca;hpb=0c1a9edad463bd6e22b30c19b700b099c7093fc1;p=ffmpeg diff --git a/libavcodec/wmadec.c b/libavcodec/wmadec.c index d3aff0a67fa..e0788375fae 100644 --- a/libavcodec/wmadec.c +++ b/libavcodec/wmadec.c @@ -16,12 +16,25 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/** + * @file wmadec.c + * WMA compatible decoder. + * This decoder handles Microsoft Windows Media Audio data, versions 1 & 2. + * WMA v1 is identified by audio format 0x160 in Microsoft media files + * (ASF/AVI/WAV). WMA v2 is identified by audio format 0x161. + * + * To use this decoder, a calling application must supply the extra data + * bytes provided with the WMA data. These are the extra, codec-specific + * bytes at the end of a WAVEFORMATEX data structure. Transmit these bytes + * to the decoder using the extradata[_size] fields in AVCodecContext. There + * should be 4 extra bytes for v1 data and 6 extra bytes for v2 data. + */ + #include "avcodec.h" +#include "bitstream.h" #include "dsputil.h" -//#define DEBUG_PARAMS -//#define DEBUG_TRACE - /* size of blocks */ #define BLOCK_MIN_BITS 7 #define BLOCK_MAX_BITS 11 @@ -108,6 +121,10 @@ typedef struct WMADecodeContext { float lsp_pow_e_table[256]; float lsp_pow_m_table1[(1 << LSP_POW_BITS)]; float lsp_pow_m_table2[(1 << LSP_POW_BITS)]; + +#ifdef TRACE + int frame_count; +#endif } WMADecodeContext; typedef struct CoefVLCTable { @@ -121,57 +138,18 @@ static void wma_lsp_to_curve_init(WMADecodeContext *s, int frame_len); #include "wmadata.h" -#ifdef DEBUG_TRACE -#include -int frame_count; - -static FILE *flog; - -void trace(const char *fmt, ...) -{ - va_list ap; - - - if (!flog) { - flog = fopen("/tmp/out.log", "w"); - setlinebuf(flog); - } - - va_start(ap, fmt); - vfprintf(flog, fmt, ap); - va_end(ap); -} - -#define get_bits(s, n) get_bits_trace(s, n) -#define get_vlc(s, vlc) get_vlc_trace(s, vlc) - -unsigned int get_bits_trace(GetBitContext *s, int n) -{ - unsigned int val; - val = (get_bits)(s, n); - trace("get_bits(%d) : 0x%x\n", n, val); - return val; -} - -static int get_vlc_trace(GetBitContext *s, VLC *vlc) -{ - int code; - code = (get_vlc)(s, vlc); - trace("get_vlc() : %d\n", code); - return code; -} - +#ifdef TRACE static void dump_shorts(const char *name, const short *tab, int n) { int i; - trace("%s[%d]:\n", name, n); + tprintf("%s[%d]:\n", name, n); for(i=0;iversion, s->nb_channels, s->sample_rate, s->bit_rate, s->block_align); - printf("bps=%f bps1=%f high_freq=%f bitoffset=%d\n", + dprintf("bps=%f bps1=%f high_freq=%f bitoffset=%d\n", bps, bps1, high_freq, s->byte_offset_bits); - printf("use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n", + dprintf("use_noise_coding=%d use_exp_vlc=%d nb_block_sizes=%d\n", s->use_noise_coding, s->use_exp_vlc, s->nb_block_sizes); -#endif /* compute the scale factor band sizes for each MDCT block size */ { @@ -452,28 +424,28 @@ static int wma_decode_init(AVCodecContext * avctx) } s->exponent_high_sizes[k] = j; #if 0 - trace("%5d: coefs_end=%d high_band_start=%d nb_high_bands=%d: ", + tprintf("%5d: coefs_end=%d high_band_start=%d nb_high_bands=%d: ", s->frame_len >> k, s->coefs_end[k], s->high_band_start[k], s->exponent_high_sizes[k]); for(j=0;jexponent_high_sizes[k];j++) - trace(" %d", s->exponent_high_bands[k][j]); - trace("\n"); + tprintf(" %d", s->exponent_high_bands[k][j]); + tprintf("\n"); #endif } } -#ifdef DEBUG_TRACE +#ifdef TRACE { int i, j; for(i = 0; i < s->nb_block_sizes; i++) { - trace("%5d: n=%2d:", + tprintf("%5d: n=%2d:", s->frame_len >> i, s->exponent_sizes[i]); for(j=0;jexponent_sizes[i];j++) - trace(" %d", s->exponent_bands[i][j]); - trace("\n"); + tprintf(" %d", s->exponent_bands[i][j]); + tprintf("\n"); } } #endif @@ -505,7 +477,7 @@ static int wma_decode_init(AVCodecContext * avctx) else s->noise_mult = 0.04; -#if defined(DEBUG_TRACE) +#ifdef TRACE for(i=0;inoise_table[i] = 1.0 * s->noise_mult; #else @@ -522,13 +494,13 @@ static int wma_decode_init(AVCodecContext * avctx) #endif init_vlc(&s->hgain_vlc, 9, sizeof(hgain_huffbits), hgain_huffbits, 1, 1, - hgain_huffcodes, 2, 2); + hgain_huffcodes, 2, 2, 0); } if (s->use_exp_vlc) { init_vlc(&s->exp_vlc, 9, sizeof(scale_huffbits), scale_huffbits, 1, 1, - scale_huffcodes, 4, 4); + scale_huffcodes, 4, 4, 0); } else { wma_lsp_to_curve_init(s, s->frame_len); } @@ -732,10 +704,17 @@ static int wma_decode_block(WMADecodeContext *s) int n, v, a, ch, code, bsize; int coef_nb_bits, total_gain, parse_exponents; float window[BLOCK_MAX_SIZE * 2]; +// XXX: FIXME!! there's a bug somewhere which makes this mandatory under altivec +#ifdef HAVE_ALTIVEC + volatile int nb_coefs[MAX_CHANNELS] __attribute__((aligned(16))); +#else int nb_coefs[MAX_CHANNELS]; +#endif float mdct_norm; - trace("***decode_block: %d:%d\n", frame_count - 1, s->block_num); +#ifdef TRACE + tprintf("***decode_block: %d:%d\n", s->frame_count - 1, s->block_num); +#endif /* compute current block length */ if (s->use_variable_block_len) { @@ -981,7 +960,7 @@ static int wma_decode_block(WMADecodeContext *s) } exp_power[j] = e2 / n; last_high_band = j; - trace("%d: power=%f (%d)\n", j, exp_power[j], n); + tprintf("%d: power=%f (%d)\n", j, exp_power[j], n); } exp_ptr += n; } @@ -1039,7 +1018,7 @@ static int wma_decode_block(WMADecodeContext *s) } } -#ifdef DEBUG_TRACE +#ifdef TRACE for(ch = 0; ch < s->nb_channels; ch++) { if (s->channel_coded[ch]) { dump_floats("exponents", 3, s->exponents[ch], s->block_len); @@ -1056,9 +1035,7 @@ static int wma_decode_block(WMADecodeContext *s) /* no need to optimize this case because it should almost never happen */ if (!s->channel_coded[0]) { -#ifdef DEBUG_TRACE - trace("rare ms-stereo case happened\n"); -#endif + tprintf("rare ms-stereo case happened\n"); memset(s->coefs[0], 0, sizeof(float) * s->block_len); s->channel_coded[0] = 1; } @@ -1170,7 +1147,9 @@ static int wma_decode_frame(WMADecodeContext *s, int16_t *samples) int16_t *ptr; float *iptr; - trace("***decode_frame: %d size=%d\n", frame_count++, s->frame_len); +#ifdef TRACE + tprintf("***decode_frame: %d size=%d\n", s->frame_count++, s->frame_len); +#endif /* read each block */ s->block_num = 0; @@ -1207,7 +1186,7 @@ static int wma_decode_frame(WMADecodeContext *s, int16_t *samples) s->frame_len * sizeof(float)); } -#ifdef DEBUG_TRACE +#ifdef TRACE dump_shorts("samples", samples, n * s->nb_channels); #endif return 0; @@ -1222,8 +1201,13 @@ static int wma_decode_superframe(AVCodecContext *avctx, uint8_t *q; int16_t *samples; - trace("***decode_superframe:\n"); + tprintf("***decode_superframe:\n"); + if(buf_size==0){ + s->last_superframe_len = 0; + return 0; + } + samples = data; init_get_bits(&s->gb, buf, buf_size*8);