wmaprodec.c
Go to the documentation of this file.
1 /*
2  * Wmapro compatible decoder
3  * Copyright (c) 2007 Baptiste Coudurier, Benjamin Larsson, Ulion
4  * Copyright (c) 2008 - 2011 Sascha Sommer, Benjamin Larsson
5  *
6  * This file is part of Libav.
7  *
8  * Libav is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * Libav is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with Libav; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
89 #include "libavutil/intfloat.h"
90 #include "libavutil/intreadwrite.h"
91 #include "avcodec.h"
92 #include "internal.h"
93 #include "get_bits.h"
94 #include "put_bits.h"
95 #include "wmaprodata.h"
96 #include "dsputil.h"
97 #include "fmtconvert.h"
98 #include "sinewin.h"
99 #include "wma.h"
100 
102 #define WMAPRO_MAX_CHANNELS 8
103 #define MAX_SUBFRAMES 32
104 #define MAX_BANDS 29
105 #define MAX_FRAMESIZE 32768
106 
107 #define WMAPRO_BLOCK_MIN_BITS 6
108 #define WMAPRO_BLOCK_MAX_BITS 12
109 #define WMAPRO_BLOCK_MIN_SIZE (1 << WMAPRO_BLOCK_MIN_BITS)
110 #define WMAPRO_BLOCK_MAX_SIZE (1 << WMAPRO_BLOCK_MAX_BITS)
111 #define WMAPRO_BLOCK_SIZES (WMAPRO_BLOCK_MAX_BITS - WMAPRO_BLOCK_MIN_BITS + 1)
112 
113 
114 #define VLCBITS 9
115 #define SCALEVLCBITS 8
116 #define VEC4MAXDEPTH ((HUFF_VEC4_MAXBITS+VLCBITS-1)/VLCBITS)
117 #define VEC2MAXDEPTH ((HUFF_VEC2_MAXBITS+VLCBITS-1)/VLCBITS)
118 #define VEC1MAXDEPTH ((HUFF_VEC1_MAXBITS+VLCBITS-1)/VLCBITS)
119 #define SCALEMAXDEPTH ((HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS)
120 #define SCALERLMAXDEPTH ((HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS)
121 
122 static VLC sf_vlc;
123 static VLC sf_rl_vlc;
124 static VLC vec4_vlc;
125 static VLC vec2_vlc;
126 static VLC vec1_vlc;
127 static VLC coef_vlc[2];
128 static float sin64[33];
129 
133 typedef struct {
134  int16_t prev_block_len;
135  uint8_t transmit_coefs;
136  uint8_t num_subframes;
137  uint16_t subframe_len[MAX_SUBFRAMES];
138  uint16_t subframe_offset[MAX_SUBFRAMES];
139  uint8_t cur_subframe;
140  uint16_t decoded_samples;
141  uint8_t grouped;
143  int8_t reuse_sf;
146  int saved_scale_factors[2][MAX_BANDS];
149  uint8_t table_idx;
150  float* coeffs;
151  uint16_t num_vec_coeffs;
154 
158 typedef struct {
159  uint8_t num_channels;
160  int8_t transform;
161  int8_t transform_band[MAX_BANDS];
162  float decorrelation_matrix[WMAPRO_MAX_CHANNELS*WMAPRO_MAX_CHANNELS];
163  float* channel_data[WMAPRO_MAX_CHANNELS];
165 
169 typedef struct WMAProDecodeCtx {
170  /* generic decoder variables */
175  uint8_t frame_data[MAX_FRAMESIZE +
181 
182  /* frame size dependent frame information (set during initialization) */
183  uint32_t decode_flags;
184  uint8_t len_prefix;
186  uint8_t bits_per_sample;
187  uint16_t samples_per_frame;
188  uint16_t log2_frame_size;
189  int8_t num_channels;
190  int8_t lfe_channel;
199 
200  /* packet decode state */
203  uint8_t packet_offset;
208  uint8_t packet_loss;
209  uint8_t packet_done;
210 
211  /* frame decode state */
212  uint32_t frame_num;
215  uint8_t drc_gain;
216  int8_t skip_frame;
218 
219  /* subframe/block decode state */
220  int16_t subframe_len;
223  int8_t num_bands;
225  int16_t* cur_sfb_offsets;
226  uint8_t table_idx;
227  int8_t esc_len;
228 
229  uint8_t num_chgroups;
231 
234 
235 
241 {
242 #define PRINT(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %d\n", a, b);
243 #define PRINT_HEX(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %x\n", a, b);
244 
245  PRINT("ed sample bit depth", s->bits_per_sample);
246  PRINT_HEX("ed decode flags", s->decode_flags);
247  PRINT("samples per frame", s->samples_per_frame);
248  PRINT("log2 frame size", s->log2_frame_size);
249  PRINT("max num subframes", s->max_num_subframes);
250  PRINT("len prefix", s->len_prefix);
251  PRINT("num channels", s->num_channels);
252 }
253 
260 {
261  WMAProDecodeCtx *s = avctx->priv_data;
262  int i;
263 
264  for (i = 0; i < WMAPRO_BLOCK_SIZES; i++)
265  ff_mdct_end(&s->mdct_ctx[i]);
266 
267  return 0;
268 }
269 
276 {
277  WMAProDecodeCtx *s = avctx->priv_data;
278  uint8_t *edata_ptr = avctx->extradata;
279  unsigned int channel_mask;
280  int i;
281  int log2_max_num_subframes;
282  int num_possible_block_sizes;
283 
284  if (!avctx->block_align) {
285  av_log(avctx, AV_LOG_ERROR, "block_align is not set\n");
286  return AVERROR(EINVAL);
287  }
288 
289  s->avctx = avctx;
290  dsputil_init(&s->dsp, avctx);
291  ff_fmt_convert_init(&s->fmt_conv, avctx);
293 
294  avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
295 
296  if (avctx->extradata_size >= 18) {
297  s->decode_flags = AV_RL16(edata_ptr+14);
298  channel_mask = AV_RL32(edata_ptr+2);
299  s->bits_per_sample = AV_RL16(edata_ptr);
301  for (i = 0; i < avctx->extradata_size; i++)
302  av_dlog(avctx, "[%x] ", avctx->extradata[i]);
303  av_dlog(avctx, "\n");
304 
305  } else {
306  av_log_ask_for_sample(avctx, "Unknown extradata size\n");
307  return AVERROR_INVALIDDATA;
308  }
309 
311  s->log2_frame_size = av_log2(avctx->block_align) + 4;
312 
314  s->skip_frame = 1; /* skip first frame */
315  s->packet_loss = 1;
316  s->len_prefix = (s->decode_flags & 0x40);
317 
320  3, s->decode_flags);
321 
323  log2_max_num_subframes = ((s->decode_flags & 0x38) >> 3);
324  s->max_num_subframes = 1 << log2_max_num_subframes;
325  if (s->max_num_subframes == 16 || s->max_num_subframes == 4)
326  s->max_subframe_len_bit = 1;
327  s->subframe_len_bits = av_log2(log2_max_num_subframes) + 1;
328 
329  num_possible_block_sizes = log2_max_num_subframes + 1;
331  s->dynamic_range_compression = (s->decode_flags & 0x80);
332 
333  if (s->max_num_subframes > MAX_SUBFRAMES) {
334  av_log(avctx, AV_LOG_ERROR, "invalid number of subframes %i\n",
335  s->max_num_subframes);
336  return AVERROR_INVALIDDATA;
337  }
338 
340  av_log(avctx, AV_LOG_ERROR, "Invalid minimum block size %i\n",
341  s->max_num_subframes);
342  return AVERROR_INVALIDDATA;
343  }
344 
345  if (s->avctx->sample_rate <= 0) {
346  av_log(avctx, AV_LOG_ERROR, "invalid sample rate\n");
347  return AVERROR_INVALIDDATA;
348  }
349 
350  s->num_channels = avctx->channels;
351 
352  if (s->num_channels < 0) {
353  av_log(avctx, AV_LOG_ERROR, "invalid number of channels %d\n", s->num_channels);
354  return AVERROR_INVALIDDATA;
355  } else if (s->num_channels > WMAPRO_MAX_CHANNELS) {
356  av_log_ask_for_sample(avctx, "unsupported number of channels\n");
357  return AVERROR_PATCHWELCOME;
358  }
359 
361  for (i = 0; i < s->num_channels; i++)
363 
365  s->lfe_channel = -1;
366 
367  if (channel_mask & 8) {
368  unsigned int mask;
369  for (mask = 1; mask < 16; mask <<= 1) {
370  if (channel_mask & mask)
371  ++s->lfe_channel;
372  }
373  }
374 
376  scale_huffbits, 1, 1,
377  scale_huffcodes, 2, 2, 616);
378 
380  scale_rl_huffbits, 1, 1,
381  scale_rl_huffcodes, 4, 4, 1406);
382 
383  INIT_VLC_STATIC(&coef_vlc[0], VLCBITS, HUFF_COEF0_SIZE,
384  coef0_huffbits, 1, 1,
385  coef0_huffcodes, 4, 4, 2108);
386 
387  INIT_VLC_STATIC(&coef_vlc[1], VLCBITS, HUFF_COEF1_SIZE,
388  coef1_huffbits, 1, 1,
389  coef1_huffcodes, 4, 4, 3912);
390 
392  vec4_huffbits, 1, 1,
393  vec4_huffcodes, 2, 2, 604);
394 
396  vec2_huffbits, 1, 1,
397  vec2_huffcodes, 2, 2, 562);
398 
400  vec1_huffbits, 1, 1,
401  vec1_huffcodes, 2, 2, 562);
402 
405  for (i = 0; i < num_possible_block_sizes; i++) {
406  int subframe_len = s->samples_per_frame >> i;
407  int x;
408  int band = 1;
409 
410  s->sfb_offsets[i][0] = 0;
411 
412  for (x = 0; x < MAX_BANDS-1 && s->sfb_offsets[i][band - 1] < subframe_len; x++) {
413  int offset = (subframe_len * 2 * critical_freq[x])
414  / s->avctx->sample_rate + 2;
415  offset &= ~3;
416  if (offset > s->sfb_offsets[i][band - 1])
417  s->sfb_offsets[i][band++] = offset;
418  }
419  s->sfb_offsets[i][band - 1] = subframe_len;
420  s->num_sfb[i] = band - 1;
421  }
422 
423 
429  for (i = 0; i < num_possible_block_sizes; i++) {
430  int b;
431  for (b = 0; b < s->num_sfb[i]; b++) {
432  int x;
433  int offset = ((s->sfb_offsets[i][b]
434  + s->sfb_offsets[i][b + 1] - 1) << i) >> 1;
435  for (x = 0; x < num_possible_block_sizes; x++) {
436  int v = 0;
437  while (s->sfb_offsets[x][v + 1] << x < offset)
438  if (++v >= MAX_BANDS)
439  return AVERROR_INVALIDDATA;
440  s->sf_offsets[i][x][b] = v;
441  }
442  }
443  }
444 
446  for (i = 0; i < WMAPRO_BLOCK_SIZES; i++)
448  1.0 / (1 << (WMAPRO_BLOCK_MIN_BITS + i - 1))
449  / (1 << (s->bits_per_sample - 1)));
450 
452  for (i = 0; i < WMAPRO_BLOCK_SIZES; i++) {
453  const int win_idx = WMAPRO_BLOCK_MAX_BITS - i;
454  ff_init_ff_sine_windows(win_idx);
455  s->windows[WMAPRO_BLOCK_SIZES - i - 1] = ff_sine_windows[win_idx];
456  }
457 
459  for (i = 0; i < num_possible_block_sizes; i++) {
460  int block_size = s->samples_per_frame >> i;
461  int cutoff = (440*block_size + 3 * (s->avctx->sample_rate >> 1) - 1)
462  / s->avctx->sample_rate;
463  s->subwoofer_cutoffs[i] = av_clip(cutoff, 4, block_size);
464  }
465 
467  for (i = 0; i < 33; i++)
468  sin64[i] = sin(i*M_PI / 64.0);
469 
470  if (avctx->debug & FF_DEBUG_BITSTREAM)
471  dump_context(s);
472 
473  avctx->channel_layout = channel_mask;
474 
476  avctx->coded_frame = &s->frame;
477 
478  return 0;
479 }
480 
487 static int decode_subframe_length(WMAProDecodeCtx *s, int offset)
488 {
489  int frame_len_shift = 0;
490  int subframe_len;
491 
493  if (offset == s->samples_per_frame - s->min_samples_per_subframe)
494  return s->min_samples_per_subframe;
495 
497  if (s->max_subframe_len_bit) {
498  if (get_bits1(&s->gb))
499  frame_len_shift = 1 + get_bits(&s->gb, s->subframe_len_bits-1);
500  } else
501  frame_len_shift = get_bits(&s->gb, s->subframe_len_bits);
502 
503  subframe_len = s->samples_per_frame >> frame_len_shift;
504 
506  if (subframe_len < s->min_samples_per_subframe ||
507  subframe_len > s->samples_per_frame) {
508  av_log(s->avctx, AV_LOG_ERROR, "broken frame: subframe_len %i\n",
509  subframe_len);
510  return AVERROR_INVALIDDATA;
511  }
512  return subframe_len;
513 }
514 
536 {
537  uint16_t num_samples[WMAPRO_MAX_CHANNELS];
538  uint8_t contains_subframe[WMAPRO_MAX_CHANNELS];
539  int channels_for_cur_subframe = s->num_channels;
540  int fixed_channel_layout = 0;
541  int min_channel_len = 0;
542  int c;
543 
544  /* Should never consume more than 3073 bits (256 iterations for the
545  * while loop when always the minimum amount of 128 samples is substracted
546  * from missing samples in the 8 channel case).
547  * 1 + BLOCK_MAX_SIZE * MAX_CHANNELS / BLOCK_MIN_SIZE * (MAX_CHANNELS + 4)
548  */
549 
551  for (c = 0; c < s->num_channels; c++)
552  s->channel[c].num_subframes = 0;
553 
554  memset(num_samples, 0, sizeof(num_samples));
555 
556  if (s->max_num_subframes == 1 || get_bits1(&s->gb))
557  fixed_channel_layout = 1;
558 
560  do {
561  int subframe_len;
562 
564  for (c = 0; c < s->num_channels; c++) {
565  if (num_samples[c] == min_channel_len) {
566  if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
567  (min_channel_len == s->samples_per_frame - s->min_samples_per_subframe))
568  contains_subframe[c] = 1;
569  else
570  contains_subframe[c] = get_bits1(&s->gb);
571  } else
572  contains_subframe[c] = 0;
573  }
574 
576  if ((subframe_len = decode_subframe_length(s, min_channel_len)) <= 0)
577  return AVERROR_INVALIDDATA;
578 
580  min_channel_len += subframe_len;
581  for (c = 0; c < s->num_channels; c++) {
582  WMAProChannelCtx* chan = &s->channel[c];
583 
584  if (contains_subframe[c]) {
585  if (chan->num_subframes >= MAX_SUBFRAMES) {
587  "broken frame: num subframes > 31\n");
588  return AVERROR_INVALIDDATA;
589  }
590  chan->subframe_len[chan->num_subframes] = subframe_len;
591  num_samples[c] += subframe_len;
592  ++chan->num_subframes;
593  if (num_samples[c] > s->samples_per_frame) {
594  av_log(s->avctx, AV_LOG_ERROR, "broken frame: "
595  "channel len > samples_per_frame\n");
596  return AVERROR_INVALIDDATA;
597  }
598  } else if (num_samples[c] <= min_channel_len) {
599  if (num_samples[c] < min_channel_len) {
600  channels_for_cur_subframe = 0;
601  min_channel_len = num_samples[c];
602  }
603  ++channels_for_cur_subframe;
604  }
605  }
606  } while (min_channel_len < s->samples_per_frame);
607 
608  for (c = 0; c < s->num_channels; c++) {
609  int i;
610  int offset = 0;
611  for (i = 0; i < s->channel[c].num_subframes; i++) {
612  av_dlog(s->avctx, "frame[%i] channel[%i] subframe[%i]"
613  " len %i\n", s->frame_num, c, i,
614  s->channel[c].subframe_len[i]);
615  s->channel[c].subframe_offset[i] = offset;
616  offset += s->channel[c].subframe_len[i];
617  }
618  }
619 
620  return 0;
621 }
622 
629  WMAProChannelGrp *chgroup)
630 {
631  int i;
632  int offset = 0;
633  int8_t rotation_offset[WMAPRO_MAX_CHANNELS * WMAPRO_MAX_CHANNELS];
634  memset(chgroup->decorrelation_matrix, 0, s->num_channels *
635  s->num_channels * sizeof(*chgroup->decorrelation_matrix));
636 
637  for (i = 0; i < chgroup->num_channels * (chgroup->num_channels - 1) >> 1; i++)
638  rotation_offset[i] = get_bits(&s->gb, 6);
639 
640  for (i = 0; i < chgroup->num_channels; i++)
641  chgroup->decorrelation_matrix[chgroup->num_channels * i + i] =
642  get_bits1(&s->gb) ? 1.0 : -1.0;
643 
644  for (i = 1; i < chgroup->num_channels; i++) {
645  int x;
646  for (x = 0; x < i; x++) {
647  int y;
648  for (y = 0; y < i + 1; y++) {
649  float v1 = chgroup->decorrelation_matrix[x * chgroup->num_channels + y];
650  float v2 = chgroup->decorrelation_matrix[i * chgroup->num_channels + y];
651  int n = rotation_offset[offset + x];
652  float sinv;
653  float cosv;
654 
655  if (n < 32) {
656  sinv = sin64[n];
657  cosv = sin64[32 - n];
658  } else {
659  sinv = sin64[64 - n];
660  cosv = -sin64[n - 32];
661  }
662 
663  chgroup->decorrelation_matrix[y + x * chgroup->num_channels] =
664  (v1 * sinv) - (v2 * cosv);
665  chgroup->decorrelation_matrix[y + i * chgroup->num_channels] =
666  (v1 * cosv) + (v2 * sinv);
667  }
668  }
669  offset += i;
670  }
671 }
672 
679 {
680  int i;
681  /* should never consume more than 1921 bits for the 8 channel case
682  * 1 + MAX_CHANNELS * (MAX_CHANNELS + 2 + 3 * MAX_CHANNELS * MAX_CHANNELS
683  * + MAX_CHANNELS + MAX_BANDS + 1)
684  */
685 
687  s->num_chgroups = 0;
688  if (s->num_channels > 1) {
689  int remaining_channels = s->channels_for_cur_subframe;
690 
691  if (get_bits1(&s->gb)) {
693  "unsupported channel transform bit\n");
694  return AVERROR_INVALIDDATA;
695  }
696 
697  for (s->num_chgroups = 0; remaining_channels &&
699  WMAProChannelGrp* chgroup = &s->chgroup[s->num_chgroups];
700  float** channel_data = chgroup->channel_data;
701  chgroup->num_channels = 0;
702  chgroup->transform = 0;
703 
705  if (remaining_channels > 2) {
706  for (i = 0; i < s->channels_for_cur_subframe; i++) {
707  int channel_idx = s->channel_indexes_for_cur_subframe[i];
708  if (!s->channel[channel_idx].grouped
709  && get_bits1(&s->gb)) {
710  ++chgroup->num_channels;
711  s->channel[channel_idx].grouped = 1;
712  *channel_data++ = s->channel[channel_idx].coeffs;
713  }
714  }
715  } else {
716  chgroup->num_channels = remaining_channels;
717  for (i = 0; i < s->channels_for_cur_subframe; i++) {
718  int channel_idx = s->channel_indexes_for_cur_subframe[i];
719  if (!s->channel[channel_idx].grouped)
720  *channel_data++ = s->channel[channel_idx].coeffs;
721  s->channel[channel_idx].grouped = 1;
722  }
723  }
724 
726  if (chgroup->num_channels == 2) {
727  if (get_bits1(&s->gb)) {
728  if (get_bits1(&s->gb)) {
730  "unsupported channel transform type\n");
731  return AVERROR_PATCHWELCOME;
732  }
733  } else {
734  chgroup->transform = 1;
735  if (s->num_channels == 2) {
736  chgroup->decorrelation_matrix[0] = 1.0;
737  chgroup->decorrelation_matrix[1] = -1.0;
738  chgroup->decorrelation_matrix[2] = 1.0;
739  chgroup->decorrelation_matrix[3] = 1.0;
740  } else {
742  chgroup->decorrelation_matrix[0] = 0.70703125;
743  chgroup->decorrelation_matrix[1] = -0.70703125;
744  chgroup->decorrelation_matrix[2] = 0.70703125;
745  chgroup->decorrelation_matrix[3] = 0.70703125;
746  }
747  }
748  } else if (chgroup->num_channels > 2) {
749  if (get_bits1(&s->gb)) {
750  chgroup->transform = 1;
751  if (get_bits1(&s->gb)) {
752  decode_decorrelation_matrix(s, chgroup);
753  } else {
755  if (chgroup->num_channels > 6) {
757  "coupled channels > 6\n");
758  } else {
759  memcpy(chgroup->decorrelation_matrix,
761  chgroup->num_channels * chgroup->num_channels *
762  sizeof(*chgroup->decorrelation_matrix));
763  }
764  }
765  }
766  }
767 
769  if (chgroup->transform) {
770  if (!get_bits1(&s->gb)) {
771  int i;
773  for (i = 0; i < s->num_bands; i++) {
774  chgroup->transform_band[i] = get_bits1(&s->gb);
775  }
776  } else {
777  memset(chgroup->transform_band, 1, s->num_bands);
778  }
779  }
780  remaining_channels -= chgroup->num_channels;
781  }
782  }
783  return 0;
784 }
785 
792 static int decode_coeffs(WMAProDecodeCtx *s, int c)
793 {
794  /* Integers 0..15 as single-precision floats. The table saves a
795  costly int to float conversion, and storing the values as
796  integers allows fast sign-flipping. */
797  static const uint32_t fval_tab[16] = {
798  0x00000000, 0x3f800000, 0x40000000, 0x40400000,
799  0x40800000, 0x40a00000, 0x40c00000, 0x40e00000,
800  0x41000000, 0x41100000, 0x41200000, 0x41300000,
801  0x41400000, 0x41500000, 0x41600000, 0x41700000,
802  };
803  int vlctable;
804  VLC* vlc;
805  WMAProChannelCtx* ci = &s->channel[c];
806  int rl_mode = 0;
807  int cur_coeff = 0;
808  int num_zeros = 0;
809  const uint16_t* run;
810  const float* level;
811 
812  av_dlog(s->avctx, "decode coefficients for channel %i\n", c);
813 
814  vlctable = get_bits1(&s->gb);
815  vlc = &coef_vlc[vlctable];
816 
817  if (vlctable) {
818  run = coef1_run;
819  level = coef1_level;
820  } else {
821  run = coef0_run;
822  level = coef0_level;
823  }
824 
827  while ((s->transmit_num_vec_coeffs || !rl_mode) &&
828  (cur_coeff + 3 < ci->num_vec_coeffs)) {
829  uint32_t vals[4];
830  int i;
831  unsigned int idx;
832 
833  idx = get_vlc2(&s->gb, vec4_vlc.table, VLCBITS, VEC4MAXDEPTH);
834 
835  if (idx == HUFF_VEC4_SIZE - 1) {
836  for (i = 0; i < 4; i += 2) {
837  idx = get_vlc2(&s->gb, vec2_vlc.table, VLCBITS, VEC2MAXDEPTH);
838  if (idx == HUFF_VEC2_SIZE - 1) {
839  uint32_t v0, v1;
840  v0 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH);
841  if (v0 == HUFF_VEC1_SIZE - 1)
842  v0 += ff_wma_get_large_val(&s->gb);
843  v1 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH);
844  if (v1 == HUFF_VEC1_SIZE - 1)
845  v1 += ff_wma_get_large_val(&s->gb);
846  vals[i ] = av_float2int(v0);
847  vals[i+1] = av_float2int(v1);
848  } else {
849  vals[i] = fval_tab[symbol_to_vec2[idx] >> 4 ];
850  vals[i+1] = fval_tab[symbol_to_vec2[idx] & 0xF];
851  }
852  }
853  } else {
854  vals[0] = fval_tab[ symbol_to_vec4[idx] >> 12 ];
855  vals[1] = fval_tab[(symbol_to_vec4[idx] >> 8) & 0xF];
856  vals[2] = fval_tab[(symbol_to_vec4[idx] >> 4) & 0xF];
857  vals[3] = fval_tab[ symbol_to_vec4[idx] & 0xF];
858  }
859 
861  for (i = 0; i < 4; i++) {
862  if (vals[i]) {
863  uint32_t sign = get_bits1(&s->gb) - 1;
864  AV_WN32A(&ci->coeffs[cur_coeff], vals[i] ^ sign << 31);
865  num_zeros = 0;
866  } else {
867  ci->coeffs[cur_coeff] = 0;
870  rl_mode |= (++num_zeros > s->subframe_len >> 8);
871  }
872  ++cur_coeff;
873  }
874  }
875 
877  if (cur_coeff < s->subframe_len) {
878  memset(&ci->coeffs[cur_coeff], 0,
879  sizeof(*ci->coeffs) * (s->subframe_len - cur_coeff));
880  if (ff_wma_run_level_decode(s->avctx, &s->gb, vlc,
881  level, run, 1, ci->coeffs,
882  cur_coeff, s->subframe_len,
883  s->subframe_len, s->esc_len, 0))
884  return AVERROR_INVALIDDATA;
885  }
886 
887  return 0;
888 }
889 
896 {
897  int i;
898 
903  for (i = 0; i < s->channels_for_cur_subframe; i++) {
904  int c = s->channel_indexes_for_cur_subframe[i];
905  int* sf;
906  int* sf_end;
908  sf_end = s->channel[c].scale_factors + s->num_bands;
909 
915  if (s->channel[c].reuse_sf) {
916  const int8_t* sf_offsets = s->sf_offsets[s->table_idx][s->channel[c].table_idx];
917  int b;
918  for (b = 0; b < s->num_bands; b++)
919  s->channel[c].scale_factors[b] =
920  s->channel[c].saved_scale_factors[s->channel[c].scale_factor_idx][*sf_offsets++];
921  }
922 
923  if (!s->channel[c].cur_subframe || get_bits1(&s->gb)) {
924 
925  if (!s->channel[c].reuse_sf) {
926  int val;
928  s->channel[c].scale_factor_step = get_bits(&s->gb, 2) + 1;
929  val = 45 / s->channel[c].scale_factor_step;
930  for (sf = s->channel[c].scale_factors; sf < sf_end; sf++) {
931  val += get_vlc2(&s->gb, sf_vlc.table, SCALEVLCBITS, SCALEMAXDEPTH) - 60;
932  *sf = val;
933  }
934  } else {
935  int i;
937  for (i = 0; i < s->num_bands; i++) {
938  int idx;
939  int skip;
940  int val;
941  int sign;
942 
943  idx = get_vlc2(&s->gb, sf_rl_vlc.table, VLCBITS, SCALERLMAXDEPTH);
944 
945  if (!idx) {
946  uint32_t code = get_bits(&s->gb, 14);
947  val = code >> 6;
948  sign = (code & 1) - 1;
949  skip = (code & 0x3f) >> 1;
950  } else if (idx == 1) {
951  break;
952  } else {
953  skip = scale_rl_run[idx];
954  val = scale_rl_level[idx];
955  sign = get_bits1(&s->gb)-1;
956  }
957 
958  i += skip;
959  if (i >= s->num_bands) {
961  "invalid scale factor coding\n");
962  return AVERROR_INVALIDDATA;
963  }
964  s->channel[c].scale_factors[i] += (val ^ sign) - sign;
965  }
966  }
969  s->channel[c].table_idx = s->table_idx;
970  s->channel[c].reuse_sf = 1;
971  }
972 
975  for (sf = s->channel[c].scale_factors + 1; sf < sf_end; sf++) {
976  s->channel[c].max_scale_factor =
977  FFMAX(s->channel[c].max_scale_factor, *sf);
978  }
979 
980  }
981  return 0;
982 }
983 
989 {
990  int i;
991 
992  for (i = 0; i < s->num_chgroups; i++) {
993  if (s->chgroup[i].transform) {
994  float data[WMAPRO_MAX_CHANNELS];
995  const int num_channels = s->chgroup[i].num_channels;
996  float** ch_data = s->chgroup[i].channel_data;
997  float** ch_end = ch_data + num_channels;
998  const int8_t* tb = s->chgroup[i].transform_band;
999  int16_t* sfb;
1000 
1002  for (sfb = s->cur_sfb_offsets;
1003  sfb < s->cur_sfb_offsets + s->num_bands; sfb++) {
1004  int y;
1005  if (*tb++ == 1) {
1007  for (y = sfb[0]; y < FFMIN(sfb[1], s->subframe_len); y++) {
1008  const float* mat = s->chgroup[i].decorrelation_matrix;
1009  const float* data_end = data + num_channels;
1010  float* data_ptr = data;
1011  float** ch;
1012 
1013  for (ch = ch_data; ch < ch_end; ch++)
1014  *data_ptr++ = (*ch)[y];
1015 
1016  for (ch = ch_data; ch < ch_end; ch++) {
1017  float sum = 0;
1018  data_ptr = data;
1019  while (data_ptr < data_end)
1020  sum += *data_ptr++ * *mat++;
1021 
1022  (*ch)[y] = sum;
1023  }
1024  }
1025  } else if (s->num_channels == 2) {
1026  int len = FFMIN(sfb[1], s->subframe_len) - sfb[0];
1027  s->dsp.vector_fmul_scalar(ch_data[0] + sfb[0],
1028  ch_data[0] + sfb[0],
1029  181.0 / 128, len);
1030  s->dsp.vector_fmul_scalar(ch_data[1] + sfb[0],
1031  ch_data[1] + sfb[0],
1032  181.0 / 128, len);
1033  }
1034  }
1035  }
1036  }
1037 }
1038 
1044 {
1045  int i;
1046  for (i = 0; i < s->channels_for_cur_subframe; i++) {
1047  int c = s->channel_indexes_for_cur_subframe[i];
1048  float* window;
1049  int winlen = s->channel[c].prev_block_len;
1050  float* start = s->channel[c].coeffs - (winlen >> 1);
1051 
1052  if (s->subframe_len < winlen) {
1053  start += (winlen - s->subframe_len) >> 1;
1054  winlen = s->subframe_len;
1055  }
1056 
1057  window = s->windows[av_log2(winlen) - WMAPRO_BLOCK_MIN_BITS];
1058 
1059  winlen >>= 1;
1060 
1061  s->dsp.vector_fmul_window(start, start, start + winlen,
1062  window, winlen);
1063 
1064  s->channel[c].prev_block_len = s->subframe_len;
1065  }
1066 }
1067 
1074 {
1075  int offset = s->samples_per_frame;
1076  int subframe_len = s->samples_per_frame;
1077  int i;
1078  int total_samples = s->samples_per_frame * s->num_channels;
1079  int transmit_coeffs = 0;
1080  int cur_subwoofer_cutoff;
1081 
1082  s->subframe_offset = get_bits_count(&s->gb);
1083 
1088  for (i = 0; i < s->num_channels; i++) {
1089  s->channel[i].grouped = 0;
1090  if (offset > s->channel[i].decoded_samples) {
1091  offset = s->channel[i].decoded_samples;
1092  subframe_len =
1094  }
1095  }
1096 
1097  av_dlog(s->avctx,
1098  "processing subframe with offset %i len %i\n", offset, subframe_len);
1099 
1102  for (i = 0; i < s->num_channels; i++) {
1103  const int cur_subframe = s->channel[i].cur_subframe;
1105  total_samples -= s->channel[i].decoded_samples;
1106 
1108  if (offset == s->channel[i].decoded_samples &&
1109  subframe_len == s->channel[i].subframe_len[cur_subframe]) {
1110  total_samples -= s->channel[i].subframe_len[cur_subframe];
1111  s->channel[i].decoded_samples +=
1112  s->channel[i].subframe_len[cur_subframe];
1115  }
1116  }
1117 
1120  if (!total_samples)
1121  s->parsed_all_subframes = 1;
1122 
1123 
1124  av_dlog(s->avctx, "subframe is part of %i channels\n",
1126 
1128  s->table_idx = av_log2(s->samples_per_frame/subframe_len);
1129  s->num_bands = s->num_sfb[s->table_idx];
1131  cur_subwoofer_cutoff = s->subwoofer_cutoffs[s->table_idx];
1132 
1134  offset += s->samples_per_frame >> 1;
1135 
1136  for (i = 0; i < s->channels_for_cur_subframe; i++) {
1137  int c = s->channel_indexes_for_cur_subframe[i];
1138 
1139  s->channel[c].coeffs = &s->channel[c].out[offset];
1140  }
1141 
1142  s->subframe_len = subframe_len;
1143  s->esc_len = av_log2(s->subframe_len - 1) + 1;
1144 
1146  if (get_bits1(&s->gb)) {
1147  int num_fill_bits;
1148  if (!(num_fill_bits = get_bits(&s->gb, 2))) {
1149  int len = get_bits(&s->gb, 4);
1150  num_fill_bits = get_bits(&s->gb, len) + 1;
1151  }
1152 
1153  if (num_fill_bits >= 0) {
1154  if (get_bits_count(&s->gb) + num_fill_bits > s->num_saved_bits) {
1155  av_log(s->avctx, AV_LOG_ERROR, "invalid number of fill bits\n");
1156  return AVERROR_INVALIDDATA;
1157  }
1158 
1159  skip_bits_long(&s->gb, num_fill_bits);
1160  }
1161  }
1162 
1164  if (get_bits1(&s->gb)) {
1165  av_log_ask_for_sample(s->avctx, "reserved bit set\n");
1166  return AVERROR_INVALIDDATA;
1167  }
1168 
1169 
1170  if (decode_channel_transform(s) < 0)
1171  return AVERROR_INVALIDDATA;
1172 
1173 
1174  for (i = 0; i < s->channels_for_cur_subframe; i++) {
1175  int c = s->channel_indexes_for_cur_subframe[i];
1176  if ((s->channel[c].transmit_coefs = get_bits1(&s->gb)))
1177  transmit_coeffs = 1;
1178  }
1179 
1180  if (transmit_coeffs) {
1181  int step;
1182  int quant_step = 90 * s->bits_per_sample >> 4;
1183 
1185  if ((s->transmit_num_vec_coeffs = get_bits1(&s->gb))) {
1186  int num_bits = av_log2((s->subframe_len + 3)/4) + 1;
1187  for (i = 0; i < s->channels_for_cur_subframe; i++) {
1188  int c = s->channel_indexes_for_cur_subframe[i];
1189  int num_vec_coeffs = get_bits(&s->gb, num_bits) << 2;
1190  if (num_vec_coeffs + offset > FF_ARRAY_ELEMS(s->channel[c].out)) {
1191  av_log(s->avctx, AV_LOG_ERROR, "num_vec_coeffs %d is too large\n", num_vec_coeffs);
1192  return AVERROR_INVALIDDATA;
1193  }
1194  s->channel[c].num_vec_coeffs = num_vec_coeffs;
1195  }
1196  } else {
1197  for (i = 0; i < s->channels_for_cur_subframe; i++) {
1198  int c = s->channel_indexes_for_cur_subframe[i];
1199  s->channel[c].num_vec_coeffs = s->subframe_len;
1200  }
1201  }
1203  step = get_sbits(&s->gb, 6);
1204  quant_step += step;
1205  if (step == -32 || step == 31) {
1206  const int sign = (step == 31) - 1;
1207  int quant = 0;
1208  while (get_bits_count(&s->gb) + 5 < s->num_saved_bits &&
1209  (step = get_bits(&s->gb, 5)) == 31) {
1210  quant += 31;
1211  }
1212  quant_step += ((quant + step) ^ sign) - sign;
1213  }
1214  if (quant_step < 0) {
1215  av_log(s->avctx, AV_LOG_DEBUG, "negative quant step\n");
1216  }
1217 
1220  if (s->channels_for_cur_subframe == 1) {
1221  s->channel[s->channel_indexes_for_cur_subframe[0]].quant_step = quant_step;
1222  } else {
1223  int modifier_len = get_bits(&s->gb, 3);
1224  for (i = 0; i < s->channels_for_cur_subframe; i++) {
1225  int c = s->channel_indexes_for_cur_subframe[i];
1226  s->channel[c].quant_step = quant_step;
1227  if (get_bits1(&s->gb)) {
1228  if (modifier_len) {
1229  s->channel[c].quant_step += get_bits(&s->gb, modifier_len) + 1;
1230  } else
1231  ++s->channel[c].quant_step;
1232  }
1233  }
1234  }
1235 
1237  if (decode_scale_factors(s) < 0)
1238  return AVERROR_INVALIDDATA;
1239  }
1240 
1241  av_dlog(s->avctx, "BITSTREAM: subframe header length was %i\n",
1242  get_bits_count(&s->gb) - s->subframe_offset);
1243 
1245  for (i = 0; i < s->channels_for_cur_subframe; i++) {
1246  int c = s->channel_indexes_for_cur_subframe[i];
1247  if (s->channel[c].transmit_coefs &&
1248  get_bits_count(&s->gb) < s->num_saved_bits) {
1249  decode_coeffs(s, c);
1250  } else
1251  memset(s->channel[c].coeffs, 0,
1252  sizeof(*s->channel[c].coeffs) * subframe_len);
1253  }
1254 
1255  av_dlog(s->avctx, "BITSTREAM: subframe length was %i\n",
1256  get_bits_count(&s->gb) - s->subframe_offset);
1257 
1258  if (transmit_coeffs) {
1259  FFTContext *mdct = &s->mdct_ctx[av_log2(subframe_len) - WMAPRO_BLOCK_MIN_BITS];
1262  for (i = 0; i < s->channels_for_cur_subframe; i++) {
1263  int c = s->channel_indexes_for_cur_subframe[i];
1264  const int* sf = s->channel[c].scale_factors;
1265  int b;
1266 
1267  if (c == s->lfe_channel)
1268  memset(&s->tmp[cur_subwoofer_cutoff], 0, sizeof(*s->tmp) *
1269  (subframe_len - cur_subwoofer_cutoff));
1270 
1272  for (b = 0; b < s->num_bands; b++) {
1273  const int end = FFMIN(s->cur_sfb_offsets[b+1], s->subframe_len);
1274  const int exp = s->channel[c].quant_step -
1275  (s->channel[c].max_scale_factor - *sf++) *
1276  s->channel[c].scale_factor_step;
1277  const float quant = pow(10.0, exp / 20.0);
1278  int start = s->cur_sfb_offsets[b];
1279  s->dsp.vector_fmul_scalar(s->tmp + start,
1280  s->channel[c].coeffs + start,
1281  quant, end - start);
1282  }
1283 
1285  mdct->imdct_half(mdct, s->channel[c].coeffs, s->tmp);
1286  }
1287  }
1288 
1290  wmapro_window(s);
1291 
1293  for (i = 0; i < s->channels_for_cur_subframe; i++) {
1294  int c = s->channel_indexes_for_cur_subframe[i];
1295  if (s->channel[c].cur_subframe >= s->channel[c].num_subframes) {
1296  av_log(s->avctx, AV_LOG_ERROR, "broken subframe\n");
1297  return AVERROR_INVALIDDATA;
1298  }
1299  ++s->channel[c].cur_subframe;
1300  }
1301 
1302  return 0;
1303 }
1304 
1311 static int decode_frame(WMAProDecodeCtx *s, int *got_frame_ptr)
1312 {
1313  AVCodecContext *avctx = s->avctx;
1314  GetBitContext* gb = &s->gb;
1315  int more_frames = 0;
1316  int len = 0;
1317  int i, ret;
1318  const float *out_ptr[WMAPRO_MAX_CHANNELS];
1319  float *samples;
1320 
1322  if (s->len_prefix)
1323  len = get_bits(gb, s->log2_frame_size);
1324 
1325  av_dlog(s->avctx, "decoding frame with length %x\n", len);
1326 
1328  if (decode_tilehdr(s)) {
1329  s->packet_loss = 1;
1330  return 0;
1331  }
1332 
1334  if (s->num_channels > 1 && get_bits1(gb)) {
1335  if (get_bits1(gb)) {
1336  for (i = 0; i < s->num_channels * s->num_channels; i++)
1337  skip_bits(gb, 4);
1338  }
1339  }
1340 
1342  if (s->dynamic_range_compression) {
1343  s->drc_gain = get_bits(gb, 8);
1344  av_dlog(s->avctx, "drc_gain %i\n", s->drc_gain);
1345  }
1346 
1349  if (get_bits1(gb)) {
1350  int av_unused skip;
1351 
1353  if (get_bits1(gb)) {
1354  skip = get_bits(gb, av_log2(s->samples_per_frame * 2));
1355  av_dlog(s->avctx, "start skip: %i\n", skip);
1356  }
1357 
1359  if (get_bits1(gb)) {
1360  skip = get_bits(gb, av_log2(s->samples_per_frame * 2));
1361  av_dlog(s->avctx, "end skip: %i\n", skip);
1362  }
1363 
1364  }
1365 
1366  av_dlog(s->avctx, "BITSTREAM: frame header length was %i\n",
1367  get_bits_count(gb) - s->frame_offset);
1368 
1370  s->parsed_all_subframes = 0;
1371  for (i = 0; i < s->num_channels; i++) {
1372  s->channel[i].decoded_samples = 0;
1373  s->channel[i].cur_subframe = 0;
1374  s->channel[i].reuse_sf = 0;
1375  }
1376 
1378  while (!s->parsed_all_subframes) {
1379  if (decode_subframe(s) < 0) {
1380  s->packet_loss = 1;
1381  return 0;
1382  }
1383  }
1384 
1385  /* get output buffer */
1387  if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
1388  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
1389  s->packet_loss = 1;
1390  return 0;
1391  }
1392  samples = (float *)s->frame.data[0];
1393 
1395  for (i = 0; i < s->num_channels; i++)
1396  out_ptr[i] = s->channel[i].out;
1397  s->fmt_conv.float_interleave(samples, out_ptr, s->samples_per_frame,
1398  s->num_channels);
1399 
1400  for (i = 0; i < s->num_channels; i++) {
1402  memcpy(&s->channel[i].out[0],
1403  &s->channel[i].out[s->samples_per_frame],
1404  s->samples_per_frame * sizeof(*s->channel[i].out) >> 1);
1405  }
1406 
1407  if (s->skip_frame) {
1408  s->skip_frame = 0;
1409  *got_frame_ptr = 0;
1410  } else {
1411  *got_frame_ptr = 1;
1412  }
1413 
1414  if (s->len_prefix) {
1415  if (len != (get_bits_count(gb) - s->frame_offset) + 2) {
1418  "frame[%i] would have to skip %i bits\n", s->frame_num,
1419  len - (get_bits_count(gb) - s->frame_offset) - 1);
1420  s->packet_loss = 1;
1421  return 0;
1422  }
1423 
1425  skip_bits_long(gb, len - (get_bits_count(gb) - s->frame_offset) - 1);
1426  } else {
1427  while (get_bits_count(gb) < s->num_saved_bits && get_bits1(gb) == 0) {
1428  }
1429  }
1430 
1432  more_frames = get_bits1(gb);
1433 
1434  ++s->frame_num;
1435  return more_frames;
1436 }
1437 
1445 {
1446  return s->buf_bit_size - get_bits_count(gb);
1447 }
1448 
1456 static void save_bits(WMAProDecodeCtx *s, GetBitContext* gb, int len,
1457  int append)
1458 {
1459  int buflen;
1460 
1465  if (!append) {
1466  s->frame_offset = get_bits_count(gb) & 7;
1467  s->num_saved_bits = s->frame_offset;
1469  }
1470 
1471  buflen = (s->num_saved_bits + len + 8) >> 3;
1472 
1473  if (len <= 0 || buflen > MAX_FRAMESIZE) {
1474  av_log_ask_for_sample(s->avctx, "input buffer too small\n");
1475  s->packet_loss = 1;
1476  return;
1477  }
1478 
1479  if (len > put_bits_left(&s->pb)) {
1481  "Cannot append %d bits, only %d bits available.\n",
1482  len, put_bits_left(&s->pb));
1483  s->packet_loss = 1;
1484  return;
1485  }
1486 
1487  s->num_saved_bits += len;
1488  if (!append) {
1489  avpriv_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3),
1490  s->num_saved_bits);
1491  } else {
1492  int align = 8 - (get_bits_count(gb) & 7);
1493  align = FFMIN(align, len);
1494  put_bits(&s->pb, align, get_bits(gb, align));
1495  len -= align;
1496  avpriv_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3), len);
1497  }
1498  skip_bits_long(gb, len);
1499 
1500  {
1501  PutBitContext tmp = s->pb;
1502  flush_put_bits(&tmp);
1503  }
1504 
1506  skip_bits(&s->gb, s->frame_offset);
1507 }
1508 
1517 static int decode_packet(AVCodecContext *avctx, void *data,
1518  int *got_frame_ptr, AVPacket* avpkt)
1519 {
1520  WMAProDecodeCtx *s = avctx->priv_data;
1521  GetBitContext* gb = &s->pgb;
1522  const uint8_t* buf = avpkt->data;
1523  int buf_size = avpkt->size;
1524  int num_bits_prev_frame;
1525  int packet_sequence_number;
1526 
1527  *got_frame_ptr = 0;
1528 
1529  if (s->packet_done || s->packet_loss) {
1530  s->packet_done = 0;
1531 
1533  if (buf_size < avctx->block_align) {
1534  av_log(avctx, AV_LOG_ERROR, "Input packet too small (%d < %d)\n",
1535  buf_size, avctx->block_align);
1536  return AVERROR_INVALIDDATA;
1537  }
1538 
1539  s->next_packet_start = buf_size - avctx->block_align;
1540  buf_size = avctx->block_align;
1541  s->buf_bit_size = buf_size << 3;
1542 
1544  init_get_bits(gb, buf, s->buf_bit_size);
1545  packet_sequence_number = get_bits(gb, 4);
1546  skip_bits(gb, 2);
1547 
1549  num_bits_prev_frame = get_bits(gb, s->log2_frame_size);
1550  av_dlog(avctx, "packet[%d]: nbpf %x\n", avctx->frame_number,
1551  num_bits_prev_frame);
1552 
1554  if (!s->packet_loss &&
1555  ((s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) {
1556  s->packet_loss = 1;
1557  av_log(avctx, AV_LOG_ERROR, "Packet loss detected! seq %x vs %x\n",
1558  s->packet_sequence_number, packet_sequence_number);
1559  }
1560  s->packet_sequence_number = packet_sequence_number;
1561 
1562  if (num_bits_prev_frame > 0) {
1563  int remaining_packet_bits = s->buf_bit_size - get_bits_count(gb);
1564  if (num_bits_prev_frame >= remaining_packet_bits) {
1565  num_bits_prev_frame = remaining_packet_bits;
1566  s->packet_done = 1;
1567  }
1568 
1571  save_bits(s, gb, num_bits_prev_frame, 1);
1572  av_dlog(avctx, "accumulated %x bits of frame data\n",
1573  s->num_saved_bits - s->frame_offset);
1574 
1576  if (!s->packet_loss)
1577  decode_frame(s, got_frame_ptr);
1578  } else if (s->num_saved_bits - s->frame_offset) {
1579  av_dlog(avctx, "ignoring %x previously saved bits\n",
1580  s->num_saved_bits - s->frame_offset);
1581  }
1582 
1583  if (s->packet_loss) {
1587  s->num_saved_bits = 0;
1588  s->packet_loss = 0;
1589  }
1590 
1591  } else {
1592  int frame_size;
1593  s->buf_bit_size = (avpkt->size - s->next_packet_start) << 3;
1594  init_get_bits(gb, avpkt->data, s->buf_bit_size);
1595  skip_bits(gb, s->packet_offset);
1596  if (s->len_prefix && remaining_bits(s, gb) > s->log2_frame_size &&
1597  (frame_size = show_bits(gb, s->log2_frame_size)) &&
1598  frame_size <= remaining_bits(s, gb)) {
1599  save_bits(s, gb, frame_size, 0);
1600  s->packet_done = !decode_frame(s, got_frame_ptr);
1601  } else if (!s->len_prefix
1602  && s->num_saved_bits > get_bits_count(&s->gb)) {
1610  s->packet_done = !decode_frame(s, got_frame_ptr);
1611  } else
1612  s->packet_done = 1;
1613  }
1614 
1615  if (s->packet_done && !s->packet_loss &&
1616  remaining_bits(s, gb) > 0) {
1619  save_bits(s, gb, remaining_bits(s, gb), 0);
1620  }
1621 
1622  s->packet_offset = get_bits_count(gb) & 7;
1623  if (s->packet_loss)
1624  return AVERROR_INVALIDDATA;
1625 
1626  if (*got_frame_ptr)
1627  *(AVFrame *)data = s->frame;
1628 
1629  return get_bits_count(gb) >> 3;
1630 }
1631 
1636 static void flush(AVCodecContext *avctx)
1637 {
1638  WMAProDecodeCtx *s = avctx->priv_data;
1639  int i;
1642  for (i = 0; i < s->num_channels; i++)
1643  memset(s->channel[i].out, 0, s->samples_per_frame *
1644  sizeof(*s->channel[i].out));
1645  s->packet_loss = 1;
1646 }
1647 
1648 
1653  .name = "wmapro",
1654  .type = AVMEDIA_TYPE_AUDIO,
1655  .id = CODEC_ID_WMAPRO,
1656  .priv_data_size = sizeof(WMAProDecodeCtx),
1657  .init = decode_init,
1658  .close = decode_end,
1659  .decode = decode_packet,
1660  .capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_DR1,
1661  .flush= flush,
1662  .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 9 Professional"),
1663 };
void(* vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, int len)
Definition: dsputil.h:417
float * channel_data[WMAPRO_MAX_CHANNELS]
transformation coefficients
Definition: wmaprodec.c:163
uint8_t max_num_subframes
Definition: wmaprodec.c:191
static const uint16_t critical_freq[]
frequencies to divide the frequency spectrum into scale factor bands
Definition: wmaprodata.h:37
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
static int decode_tilehdr(WMAProDecodeCtx *s)
Decode how the data in the frame is split into subframes.
Definition: wmaprodec.c:535
int8_t num_channels
number of channels in the stream (same as AVCodecContext.num_channels)
Definition: wmaprodec.c:189
Audio Video Frame.
Definition: avcodec.h:985
#define VEC2MAXDEPTH
Definition: wmaprodec.c:117
int subframe_offset
subframe offset in the bit reservoir
Definition: wmaprodec.c:207
static short * samples
Definition: ffmpeg.c:233
static const uint16_t vec1_huffcodes[HUFF_VEC1_SIZE]
Definition: wmaprodata.h:507
static const float coef0_level[HUFF_COEF0_SIZE]
Definition: wmaprodata.h:355
uint8_t table_idx
index for the num_sfb, sfb_offsets, sf_offsets and subwoofer_cutoffs tables
Definition: wmaprodec.c:226
static const uint32_t scale_rl_huffcodes[HUFF_SCALE_RL_SIZE]
Definition: wmaprodata.h:97
uint16_t num_vec_coeffs
number of vector coded coefficients
Definition: wmaprodec.c:151
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:237
#define WMAPRO_BLOCK_MIN_SIZE
minimum block size
Definition: wmaprodec.c:109
uint16_t min_samples_per_subframe
Definition: wmaprodec.c:194
static void skip_bits_long(GetBitContext *s, int n)
Definition: get_bits.h:197
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2000
AVCodecContext * avctx
codec context for av_log
Definition: wmaprodec.c:171
uint32_t decode_flags
used compression features
Definition: wmaprodec.c:183
#define FF_DEBUG_BITSTREAM
Definition: avcodec.h:2010
int size
Definition: avcodec.h:909
static const uint16_t vec4_huffcodes[HUFF_VEC4_SIZE]
Definition: wmaprodata.h:421
void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
Copy the content of src to the bitstream.
Definition: bitstream.c:59
int8_t scale_factor_step
scaling step for the current subframe
Definition: wmaprodec.c:144
const uint8_t * buffer
Definition: get_bits.h:53
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:55
int ff_wma_run_level_decode(AVCodecContext *avctx, GetBitContext *gb, VLC *vlc, const float *level_table, const uint16_t *run_table, int version, WMACoef *ptr, int offset, int num_coefs, int block_len, int frame_len_bits, int coef_nb_bits)
Decode run level compressed coefficients.
Definition: wma.c:473
uint16_t log2_frame_size
Definition: wmaprodec.c:188
static const uint8_t scale_huffbits[HUFF_SCALE_SIZE]
Definition: wmaprodata.h:70
uint8_t table_idx
index in sf_offsets for the scale factor reference block
Definition: wmaprodec.c:149
#define b
Definition: swscale.c:1335
#define FF_ARRAY_ELEMS(a)
int16_t * cur_sfb_offsets
sfb offsets for the current block
Definition: wmaprodec.c:225
#define VLCBITS
Definition: wmaprodec.c:114
uint8_t run
Definition: svq3.c:123
WMAProChannelGrp chgroup[WMAPRO_MAX_CHANNELS]
channel group information
Definition: wmaprodec.c:230
SINETABLE_CONST float *const ff_sine_windows[13]
PutBitContext pb
context for filling the frame_data buffer
Definition: wmaprodec.c:177
#define SCALEVLCBITS
Definition: wmaprodec.c:115
void(* float_interleave)(float *dst, const float **src, unsigned int len, int channels)
Convert multiple arrays of float to an array of interleaved float.
Definition: fmtconvert.h:83
AVCodec.
Definition: avcodec.h:3189
#define WMAPRO_MAX_CHANNELS
current decoder limitations
Definition: wmaprodec.c:102
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:1751
#define AV_WN32A(p, v)
Definition: intreadwrite.h:458
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:223
static VLC vec1_vlc
1 coefficient per symbol
Definition: wmaprodec.c:126
#define v(n)
Definition: regs.h:34
int av_cold ff_wma_get_frame_len_bits(int sample_rate, int version, unsigned int decode_flags)
Get the samples per frame for this stream.
Definition: wma.c:77
static const uint8_t scale_rl_run[HUFF_SCALE_RL_SIZE]
Definition: wmaprodata.h:140
static int decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Decode a single WMA packet.
Definition: wmaprodec.c:1517
int frame_offset
frame offset in the bit reservoir
Definition: wmaprodec.c:206
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:228
DSPContext dsp
accelerated DSP functions
Definition: wmaprodec.c:173
static const float coef1_level[HUFF_COEF1_SIZE]
Definition: wmaprodata.h:396
uint16_t subframe_offset[MAX_SUBFRAMES]
subframe positions in the current frame
Definition: wmaprodec.c:138
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1464
static void inverse_channel_transform(WMAProDecodeCtx *s)
Reconstruct the individual channel data.
Definition: wmaprodec.c:988
int16_t sfb_offsets[WMAPRO_BLOCK_SIZES][MAX_BANDS]
scale factor band offsets (multiples of 4)
Definition: wmaprodec.c:196
#define av_cold
Definition: attributes.h:71
#define HUFF_COEF1_SIZE
Definition: wmaprodata.h:253
#define HUFF_VEC2_SIZE
Definition: wmaprodata.h:460
#define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size)
Definition: get_bits.h:402
int8_t num_bands
number of scale factor bands
Definition: wmaprodec.c:223
#define SCALEMAXDEPTH
Definition: wmaprodec.c:119
uint8_t frame_data[MAX_FRAMESIZE+FF_INPUT_BUFFER_PADDING_SIZE]
compressed frame data
Definition: wmaprodec.c:176
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1387
uint8_t packet_sequence_number
current packet number
Definition: wmaprodec.c:204
uint8_t drc_gain
gain for the DRC tool
Definition: wmaprodec.c:215
uint8_t dynamic_range_compression
frame contains DRC data
Definition: wmaprodec.c:185
const char data[16]
Definition: mxf.c:60
static uint8_t * append(uint8_t *buf, const uint8_t *src, int size)
#define MAX_FRAMESIZE
maximum compressed frame size
Definition: wmaprodec.c:105
int16_t prev_block_len
length of the previous block
Definition: wmaprodec.c:134
WMAProChannelCtx channel[WMAPRO_MAX_CHANNELS]
per channel data
Definition: wmaprodec.c:232
GetBitContext gb
bitstream reader context
Definition: wmaprodec.c:213
uint8_t * data
Definition: avcodec.h:908
uint8_t grouped
channel is part of a group
Definition: wmaprodec.c:141
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:192
#define WMAPRO_BLOCK_MAX_BITS
log2 of max block size
Definition: wmaprodec.c:108
#define HUFF_COEF0_SIZE
Definition: wmaprodata.h:166
int * scale_factors
pointer to the scale factor values used for decoding
Definition: wmaprodec.c:148
bitstream reader API header.
#define HUFF_VEC1_SIZE
Definition: wmaprodata.h:505
int next_packet_start
start offset of the next wma packet in the demuxer packet
Definition: wmaprodec.c:202
int num_saved_bits
saved number of bits
Definition: wmaprodec.c:205
static const uint16_t scale_huffcodes[HUFF_SCALE_SIZE]
Definition: wmaprodata.h:51
int buf_bit_size
buffer size in bits
Definition: wmaprodec.c:214
static const uint32_t coef1_huffcodes[555]
Definition: wmadata.h:269
av_cold void dsputil_init(DSPContext *c, AVCodecContext *avctx)
Definition: dsputil.c:2789
static int init(AVCodecParserContext *s)
Definition: h264_parser.c:336
#define SCALERLMAXDEPTH
Definition: wmaprodec.c:120
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:719
static VLC vec4_vlc
4 coefficients per symbol
Definition: wmaprodec.c:124
static int decode_subframe(WMAProDecodeCtx *s)
Decode a single subframe (block).
Definition: wmaprodec.c:1073
uint8_t packet_loss
set in case of bitstream error
Definition: wmaprodec.c:208
static int put_bits_left(PutBitContext *s)
Definition: put_bits.h:78
static const uint16_t mask[17]
Definition: lzw.c:36
#define AVERROR(e)
Definition: error.h:43
#define MAX_SUBFRAMES
max number of subframes per channel
Definition: wmaprodec.c:103
#define HUFF_VEC4_SIZE
Definition: wmaprodata.h:419
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:191
AV_RL32
Definition: bytestream.h:89
int8_t channel_indexes_for_cur_subframe[WMAPRO_MAX_CHANNELS]
Definition: wmaprodec.c:222
static const uint8_t coef0_huffbits[666]
Definition: wmadata.h:182
static float sin64[33]
sinus table for decorrelation
Definition: wmaprodec.c:128
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:140
#define HUFF_SCALE_SIZE
Definition: wmaprodata.h:49
int max_scale_factor
maximum scale factor for the current subframe
Definition: wmaprodec.c:145
const char * name
Name of the codec implementation.
Definition: avcodec.h:3196
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
Definition: put_bits.h:136
#define ff_mdct_init
Definition: fft.h:146
int8_t channels_for_cur_subframe
number of channels that contain the subframe
Definition: wmaprodec.c:221
AVCodec ff_wmapro_decoder
wmapro decoder
Definition: wmaprodec.c:1652
#define FFMAX(a, b)
Definition: common.h:53
static int decode_subframe_length(WMAProDecodeCtx *s, int offset)
Decode the subframe length.
Definition: wmaprodec.c:487
static const uint8_t coef1_huffbits[555]
Definition: wmadata.h:342
float out[WMAPRO_BLOCK_MAX_SIZE+WMAPRO_BLOCK_MAX_SIZE/2]
output buffer
Definition: wmaprodec.c:152
int quant_step
quantization step for the current subframe
Definition: wmaprodec.c:142
static const uint16_t coef1_run[HUFF_COEF1_SIZE]
Definition: wmaprodata.h:379
Definition: get_bits.h:63
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2870
frame specific decoder context for a single channel
Definition: wmaprodec.c:133
static VLC sf_vlc
scale factor DPCM vlc
Definition: wmaprodec.c:122
uint8_t bits_per_sample
integer audio sample size for the unscaled IMDCT output (used to scale to [-1.0, 1.0])
Definition: wmaprodec.c:186
static const uint8_t scale_rl_huffbits[HUFF_SCALE_RL_SIZE]
Definition: wmaprodata.h:118
static void flush(AVCodecContext *avctx)
Clear decoder buffers (for seeking).
Definition: wmaprodec.c:1636
static const uint16_t symbol_to_vec4[HUFF_VEC4_SIZE]
Definition: wmaprodata.h:540
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float.
Definition: dsputil.h:428
struct WMAProDecodeCtx WMAProDecodeCtx
main decoder context
static int decode_coeffs(WMAProDecodeCtx *s, int c)
Extract the coefficients from the bitstream.
Definition: wmaprodec.c:792
uint8_t num_subframes
Definition: wmaprodec.c:136
Definition: fft.h:62
#define FFMIN(a, b)
Definition: common.h:55
uint32_t frame_num
current frame number (not used for decoding)
Definition: wmaprodec.c:212
int8_t transform
transform on / off
Definition: wmaprodec.c:160
float tmp[WMAPRO_BLOCK_MAX_SIZE]
IMDCT output buffer.
Definition: wmaprodec.c:179
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Definition: utils.c:1867
main decoder context
Definition: wmaprodec.c:169
int8_t sf_offsets[WMAPRO_BLOCK_SIZES][WMAPRO_BLOCK_SIZES][MAX_BANDS]
scale factor resample matrix
Definition: wmaprodec.c:197
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:251
uint16_t decoded_samples
number of already processed samples
Definition: wmaprodec.c:140
static const float *const default_decorrelation[]
default decorrelation matrix offsets
Definition: wmaprodata.h:594
static void save_bits(WMAProDecodeCtx *s, GetBitContext *gb, int len, int append)
Fill the bit reservoir with a (partial) frame.
Definition: wmaprodec.c:1456
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:481
int8_t transmit_num_vec_coeffs
number of vector coded coefficients is part of the bitstream
Definition: wmaprodec.c:224
#define MAX_BANDS
max number of scale factor bands
Definition: wmaprodec.c:104
#define av_dlog(pctx,...)
av_dlog macros Useful to print debug messages that shouldn't get compiled in normally.
Definition: log.h:158
uint8_t subframe_len_bits
number of bits used for the subframe length
Definition: wmaprodec.c:192
int8_t transform_band[MAX_BANDS]
controls if the transform is enabled for a certain band
Definition: wmaprodec.c:161
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
Definition: error.h:57
int8_t lfe_channel
lfe channel index
Definition: wmaprodec.c:190
int16_t subwoofer_cutoffs[WMAPRO_BLOCK_SIZES]
subwoofer cutoff values
Definition: wmaprodec.c:198
static VLC vec2_vlc
2 coefficients per symbol
Definition: wmaprodec.c:125
int8_t parsed_all_subframes
all subframes decoded?
Definition: wmaprodec.c:217
external API header
channel group for channel transformations
Definition: wmaprodec.c:158
#define VEC1MAXDEPTH
Definition: wmaprodec.c:118
int16_t subframe_len
current subframe length
Definition: wmaprodec.c:220
int sample_rate
samples per second
Definition: avcodec.h:1456
#define WMAPRO_BLOCK_SIZES
possible block sizes
Definition: wmaprodec.c:111
int debug
debug
Definition: avcodec.h:2007
static const uint8_t vec4_huffbits[HUFF_VEC4_SIZE]
Definition: wmaprodata.h:440
void av_log_ask_for_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message asking for a sample.
main external API structure.
Definition: avcodec.h:1329
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:327
static const uint8_t symbol_to_vec2[HUFF_VEC2_SIZE]
Definition: wmaprodata.h:557
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:111
tables for wmapro decoding
#define VEC4MAXDEPTH
Definition: wmaprodec.c:116
void(* imdct_half)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
Definition: fft.h:82
int extradata_size
Definition: avcodec.h:1388
static VLC coef_vlc[2]
coefficient run length vlc codes
Definition: wmaprodec.c:127
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:268
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:260
int8_t reuse_sf
share scale factors between subframes
Definition: wmaprodec.c:143
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:354
uint8_t packet_offset
frame offset in the packet
Definition: wmaprodec.c:203
static int decode_scale_factors(WMAProDecodeCtx *s)
Extract scale factors from the bitstream.
Definition: wmaprodec.c:895
int saved_scale_factors[2][MAX_BANDS]
resampled and (previously) transmitted scale factor values
Definition: wmaprodec.c:146
uint8_t num_channels
number of channels in the group
Definition: wmaprodec.c:159
uint8_t transmit_coefs
Definition: wmaprodec.c:135
static VLC sf_rl_vlc
scale factor run length vlc
Definition: wmaprodec.c:123
float * coeffs
pointer to the subframe decode buffer
Definition: wmaprodec.c:150
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:497
static int step
Definition: avplay.c:244
float * windows[WMAPRO_BLOCK_SIZES]
windows for the different block sizes
Definition: wmaprodec.c:180
uint8_t cur_subframe
current subframe number
Definition: wmaprodec.c:139
static av_always_inline uint32_t av_float2int(float f)
Reinterpret a float as a 32-bit integer.
Definition: intfloat.h:49
static int remaining_bits(WMAProDecodeCtx *s, GetBitContext *gb)
Calculate remaining input buffer length.
Definition: wmaprodec.c:1444
const uint8_t * quant
static int decode_channel_transform(WMAProDecodeCtx *s)
Decode channel transformation parameters.
Definition: wmaprodec.c:678
FFTContext mdct_ctx[WMAPRO_BLOCK_SIZES]
MDCT context per block size.
Definition: wmaprodec.c:178
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: avcodec.h:997
FmtConvertContext fmt_conv
Definition: wmaprodec.c:174
int8_t scale_factor_idx
index for the transmitted scale factor values (used for resampling)
Definition: wmaprodec.c:147
uint8_t level
Definition: svq3.c:123
#define PRINT(a, b)
#define WMAPRO_BLOCK_MAX_SIZE
maximum block size
Definition: wmaprodec.c:110
static av_cold int decode_init(AVCodecContext *avctx)
Initialize the decoder.
Definition: wmaprodec.c:275
#define v0
Definition: regdef.h:26
#define PRINT_HEX(a, b)
uint16_t subframe_len[MAX_SUBFRAMES]
subframe length in samples
Definition: wmaprodec.c:137
int8_t num_sfb[WMAPRO_BLOCK_SIZES]
scale factor bands per block size
Definition: wmaprodec.c:195
AV_WL32 AV_WL24 AV_RL16
Definition: bytestream.h:89
common internal api header.
static void decode_decorrelation_matrix(WMAProDecodeCtx *s, WMAProChannelGrp *chgroup)
Calculate a decorrelation matrix from the bitstream parameters.
Definition: wmaprodec.c:628
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:125
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:86
#define ff_mdct_end
Definition: fft.h:147
static int decode_frame(WMAProDecodeCtx *s, int *got_frame_ptr)
Decode one WMA frame.
Definition: wmaprodec.c:1311
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:52
static void wmapro_window(WMAProDecodeCtx *s)
Apply sine window and reconstruct the output buffer.
Definition: wmaprodec.c:1043
DSP utils.
#define WMAPRO_BLOCK_MIN_BITS
log2 of min block size
Definition: wmaprodec.c:107
static const uint8_t scale_rl_level[HUFF_SCALE_RL_SIZE]
Definition: wmaprodata.h:150
void * priv_data
Definition: avcodec.h:1531
static void av_cold dump_context(WMAProDecodeCtx *s)
helper function to print the most important members of the context
Definition: wmaprodec.c:240
av_cold void ff_fmt_convert_init(FmtConvertContext *c, AVCodecContext *avctx)
Definition: fmtconvert.c:78
int len
GetBitContext pgb
bitstream reader context for the packet
Definition: wmaprodec.c:201
int channels
number of audio channels
Definition: avcodec.h:1457
#define CODEC_CAP_SUBFRAMES
Codec can output multiple frames per AVPacket Normally demuxers return one frame at a time...
Definition: avcodec.h:771
VLC_TYPE(* table)[2]
code, bits
Definition: get_bits.h:65
unsigned int ff_wma_get_large_val(GetBitContext *gb)
Decode an uncompressed coefficient.
Definition: wma.c:440
static const uint32_t coef0_huffcodes[666]
Definition: wmadata.h:95
int frame_number
audio or video frame number
Definition: avcodec.h:1471
uint16_t samples_per_frame
number of samples to output
Definition: wmaprodec.c:187
static const uint8_t vec1_huffbits[HUFF_VEC1_SIZE]
Definition: wmaprodata.h:523
static const uint16_t coef0_run[HUFF_COEF0_SIZE]
Definition: wmaprodata.h:332
static const uint16_t vec2_huffcodes[HUFF_VEC2_SIZE]
Definition: wmaprodata.h:462
int8_t esc_len
length of escaped coefficients
Definition: wmaprodec.c:227
void avcodec_get_frame_defaults(AVFrame *pic)
Set the fields of the given AVFrame to default values.
Definition: utils.c:609
uint8_t len_prefix
frame is prefixed with its length
Definition: wmaprodec.c:184
float decorrelation_matrix[WMAPRO_MAX_CHANNELS *WMAPRO_MAX_CHANNELS]
Definition: wmaprodec.c:162
static av_cold int decode_end(AVCodecContext *avctx)
Uninitialize the decoder and free all resources.
Definition: wmaprodec.c:259
AVFrame frame
AVFrame for decoded output.
Definition: wmaprodec.c:172
#define HUFF_SCALE_RL_SIZE
Definition: wmaprodata.h:95
uint8_t max_subframe_len_bit
flag indicating that the subframe is of maximum size when the first subframe length bit is 1 ...
Definition: wmaprodec.c:193
int nb_samples
number of audio samples (per channel) described by this frame
Definition: avcodec.h:1265
#define M_PI
Definition: cos_tablegen.c:28
int8_t skip_frame
skip output step
Definition: wmaprodec.c:216
for(j=16;j >0;--j)
void ff_init_ff_sine_windows(int index)
initialize the specified entry of ff_sine_windows
#define av_unused
Definition: attributes.h:95
static const uint8_t vec2_huffbits[HUFF_VEC2_SIZE]
Definition: wmaprodata.h:483
DSPContext.
Definition: dsputil.h:226
uint8_t num_chgroups
number of channel groups
Definition: wmaprodec.c:229
uint8_t packet_done
set when a packet is fully decoded
Definition: wmaprodec.c:209
bitstream writer API