X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=wmadec_filter.c;h=13f1946402ad3295faa06637f9ec9e434d0f67a4;hb=a0f64807fb22318ef6d610ae89f72da8940bcf78;hp=4c7c047a482e2b3f256cfb8c12dcd6b4de3a7500;hpb=21c6e0b09b42e61e72b741bd726856ab0bcd1d64;p=paraslash.git diff --git a/wmadec_filter.c b/wmadec_filter.c index 4c7c047a..13f19464 100644 --- a/wmadec_filter.c +++ b/wmadec_filter.c @@ -24,11 +24,11 @@ #include "para.h" #include "error.h" #include "list.h" -#include "ggo.h" #include "string.h" #include "sched.h" #include "buffer_tree.h" #include "filter.h" +#include "portable_io.h" #include "bitstream.h" #include "imdct.h" #include "wma.h" @@ -159,23 +159,6 @@ static void sine_window_init(float *window, int n) window[i] = sinf((i + 0.5) * (M_PI / (2.0 * n))); } -static void wmadec_cleanup(struct private_wmadec_data *pwd) -{ - int i; - - for (i = 0; i < pwd->nb_block_sizes; i++) - imdct_end(pwd->mdct_ctx[i]); - if (pwd->ahi.use_exp_vlc) - free_vlc(&pwd->exp_vlc); - if (pwd->use_noise_coding) - free_vlc(&pwd->hgain_vlc); - for (i = 0; i < 2; i++) { - free_vlc(&pwd->coef_vlc[i]); - free(pwd->run_table[i]); - free(pwd->level_table[i]); - } -} - static void init_coef_vlc(struct vlc *vlc, uint16_t **prun_table, uint16_t **plevel_table, const struct coef_vlc_table *vlc_table) { @@ -581,7 +564,7 @@ static int decode_exp_vlc(struct private_wmadec_data *pwd, int ch) last_exp = 36; while (q < q_end) { - code = get_vlc(&pwd->gb, pwd->exp_vlc.table, EXPVLCBITS); + code = get_vlc(&pwd->gb, &pwd->exp_vlc); if (code < 0) return code; /* NOTE: this offset is the same as MPEG4 AAC ! */ @@ -708,8 +691,7 @@ static int compute_high_band_values(struct private_wmadec_data *pwd, if (val == (int)0x80000000) val = get_bits(&pwd->gb, 7) - 19; else { - int code = get_vlc(&pwd->gb, - pwd->hgain_vlc.table, HGAINVLCBITS); + int code = get_vlc(&pwd->gb, &pwd->hgain_vlc); if (code < 0) return code; val += code - 18; @@ -940,7 +922,7 @@ static int wma_decode_block(struct private_wmadec_data *pwd) eptr = ptr + nb_coefs[ch]; memset(ptr, 0, pwd->block_len * sizeof(int16_t)); for (;;) { - code = get_vlc(&pwd->gb, coef_vlc->table, VLCBITS); + code = get_vlc(&pwd->gb, coef_vlc); if (code < 0) return code; if (code == 1) /* EOB */ @@ -1058,24 +1040,13 @@ static int wma_decode_frame(struct private_wmadec_data *pwd, int16_t *samples) return 0; } -static int wma_decode_superframe(struct private_wmadec_data *pwd, void *data, - int *data_size, const uint8_t *buf, int buf_size) +static int wma_decode_superframe(struct private_wmadec_data *pwd, void *out, + int *out_size, const uint8_t *in) { - int ret; - int16_t *samples; + int ret, in_size = pwd->ahi.packet_size - WMA_FRAME_SKIP; + int16_t *samples = out; - if (buf_size == 0) { - pwd->last_superframe_len = 0; - *data_size = 0; - return 0; - } - if (buf_size < pwd->ahi.block_align) { - *data_size = 0; - return 0; - } - buf_size = pwd->ahi.block_align; - samples = data; - init_get_bits(&pwd->gb, buf, buf_size); + init_get_bits(&pwd->gb, in, in_size); if (pwd->ahi.use_bit_reservoir) { int i, nb_frames, bit_offset, pos, len; uint8_t *q; @@ -1086,7 +1057,7 @@ static int wma_decode_superframe(struct private_wmadec_data *pwd, void *data, // PARA_DEBUG_LOG("have %d frames\n", nb_frames); ret = -E_WMA_OUTPUT_SPACE; if ((nb_frames + 1) * pwd->ahi.channels * pwd->frame_len - * sizeof(int16_t) > *data_size) + * sizeof(int16_t) > *out_size) goto fail; bit_offset = get_bits(&pwd->gb, pwd->byte_offset_bits + 3); @@ -1124,7 +1095,7 @@ static int wma_decode_superframe(struct private_wmadec_data *pwd, void *data, /* read each frame starting from bit_offset */ pos = bit_offset + 4 + 4 + pwd->byte_offset_bits + 3; - init_get_bits(&pwd->gb, buf + (pos >> 3), + init_get_bits(&pwd->gb, in + (pos >> 3), (MAX_CODED_SUPERFRAME_SIZE - (pos >> 3))); len = pos & 7; if (len > 0) @@ -1143,16 +1114,16 @@ static int wma_decode_superframe(struct private_wmadec_data *pwd, void *data, ((bit_offset + 4 + 4 + pwd->byte_offset_bits + 3) & ~7); pwd->last_bitoffset = pos & 7; pos >>= 3; - len = buf_size - pos; + len = in_size - pos; ret = -E_WMA_BAD_SUPERFRAME; if (len > MAX_CODED_SUPERFRAME_SIZE || len < 0) goto fail; pwd->last_superframe_len = len; - memcpy(pwd->last_superframe, buf + pos, len); + memcpy(pwd->last_superframe, in + pos, len); } else { PARA_DEBUG_LOG("not using bit reservoir\n"); ret = -E_WMA_OUTPUT_SPACE; - if (pwd->ahi.channels * pwd->frame_len * sizeof(int16_t) > *data_size) + if (pwd->ahi.channels * pwd->frame_len * sizeof(int16_t) > *out_size) goto fail; /* single frame decode */ ret = wma_decode_frame(pwd, samples); @@ -1162,8 +1133,8 @@ static int wma_decode_superframe(struct private_wmadec_data *pwd, void *data, } PARA_DEBUG_LOG("frame_len: %d, block_len: %d, outbytes: %d, eaten: %d\n", pwd->frame_len, pwd->block_len, - (int)((int8_t *)samples - (int8_t *)data), pwd->ahi.block_align); - *data_size = (int8_t *)samples - (int8_t *)data; + (int)((int8_t *)samples - (int8_t *)out), pwd->ahi.block_align); + *out_size = (int8_t *)samples - (int8_t *)out; return pwd->ahi.block_align; fail: /* reset the bit reservoir on errors */ @@ -1174,10 +1145,21 @@ fail: static void wmadec_close(struct filter_node *fn) { struct private_wmadec_data *pwd = fn->private_data; + int i; if (!pwd) return; - wmadec_cleanup(pwd); + for (i = 0; i < pwd->nb_block_sizes; i++) + imdct_end(pwd->mdct_ctx[i]); + if (pwd->ahi.use_exp_vlc) + free_vlc(&pwd->exp_vlc); + if (pwd->use_noise_coding) + free_vlc(&pwd->hgain_vlc); + for (i = 0; i < 2; i++) { + free_vlc(&pwd->coef_vlc[i]); + free(pwd->run_table[i]); + free(pwd->level_table[i]); + } free(fn->private_data); fn->private_data = NULL; } @@ -1233,7 +1215,7 @@ next_buffer: out_size = WMA_OUTPUT_BUFFER_SIZE; out = para_malloc(out_size); ret = wma_decode_superframe(pwd, out, &out_size, - (uint8_t *)in + WMA_FRAME_SKIP, len - WMA_FRAME_SKIP); + (uint8_t *)in + WMA_FRAME_SKIP); if (ret < 0) { free(out); goto err; @@ -1259,16 +1241,10 @@ static void wmadec_open(struct filter_node *fn) fn->min_iqs = 4096; } -/** - * The init function of the wma decoder. - * - * \param f Its fields are filled in by the function. - */ -void wmadec_filter_init(struct filter *f) -{ - f->open = wmadec_open; - f->close = wmadec_close; - f->execute = wmadec_execute; - f->pre_select = generic_filter_pre_select; - f->post_select = wmadec_post_select; -} +const struct filter lsg_filter_cmd_com_wmadec_user_data = { + .open = wmadec_open, + .close = wmadec_close, + .execute = wmadec_execute, + .pre_select = generic_filter_pre_select, + .post_select = wmadec_post_select, +};