FFmpeg
wmadec.c
Go to the documentation of this file.
1 /*
2  * WMA compatible decoder
3  * Copyright (c) 2002 The FFmpeg Project
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * WMA compatible decoder.
25  * This decoder handles Microsoft Windows Media Audio data, versions 1 & 2.
26  * WMA v1 is identified by audio format 0x160 in Microsoft media files
27  * (ASF/AVI/WAV). WMA v2 is identified by audio format 0x161.
28  *
29  * To use this decoder, a calling application must supply the extra data
30  * bytes provided with the WMA data. These are the extra, codec-specific
31  * bytes at the end of a WAVEFORMATEX data structure. Transmit these bytes
32  * to the decoder using the extradata[_size] fields in AVCodecContext. There
33  * should be 4 extra bytes for v1 data and 6 extra bytes for v2 data.
34  */
35 
36 #include "config_components.h"
37 
38 #include "libavutil/attributes.h"
39 #include "libavutil/avassert.h"
40 #include "libavutil/ffmath.h"
41 
42 #include "avcodec.h"
43 #include "codec_internal.h"
44 #include "decode.h"
45 #include "internal.h"
46 #include "wma.h"
47 
48 #define EXPVLCBITS 8
49 #define EXPMAX ((19 + EXPVLCBITS - 1) / EXPVLCBITS)
50 
51 #define HGAINVLCBITS 9
52 #define HGAINMAX ((13 + HGAINVLCBITS - 1) / HGAINVLCBITS)
53 
54 static void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len);
55 
56 #ifdef TRACE
57 static void dump_floats(WMACodecContext *s, const char *name,
58  int prec, const float *tab, int n)
59 {
60  int i;
61 
62  ff_tlog(s->avctx, "%s[%d]:\n", name, n);
63  for (i = 0; i < n; i++) {
64  if ((i & 7) == 0)
65  ff_tlog(s->avctx, "%4d: ", i);
66  ff_tlog(s->avctx, " %8.*f", prec, tab[i]);
67  if ((i & 7) == 7)
68  ff_tlog(s->avctx, "\n");
69  }
70  if ((i & 7) != 0)
71  ff_tlog(s->avctx, "\n");
72 }
73 #endif /* TRACE */
74 
76 {
77  WMACodecContext *s = avctx->priv_data;
78  int i, flags2, ret;
79  uint8_t *extradata;
80 
81  if (!avctx->block_align) {
82  av_log(avctx, AV_LOG_ERROR, "block_align is not set\n");
83  return AVERROR(EINVAL);
84  }
85 
86  s->avctx = avctx;
87 
88  /* extract flag info */
89  flags2 = 0;
90  extradata = avctx->extradata;
91  if (avctx->codec->id == AV_CODEC_ID_WMAV1 && avctx->extradata_size >= 4)
92  flags2 = AV_RL16(extradata + 2);
93  else if (avctx->codec->id == AV_CODEC_ID_WMAV2 && avctx->extradata_size >= 6)
94  flags2 = AV_RL16(extradata + 4);
95 
96  s->use_exp_vlc = flags2 & 0x0001;
97  s->use_bit_reservoir = flags2 & 0x0002;
98  s->use_variable_block_len = flags2 & 0x0004;
99 
100  if (avctx->codec->id == AV_CODEC_ID_WMAV2 && avctx->extradata_size >= 8){
101  if (AV_RL16(extradata+4)==0xd && s->use_variable_block_len){
102  av_log(avctx, AV_LOG_WARNING, "Disabling use_variable_block_len, if this fails contact the ffmpeg developers and send us the file\n");
103  s->use_variable_block_len= 0; // this fixes issue1503
104  }
105  }
106 
107  for (i=0; i<MAX_CHANNELS; i++)
108  s->max_exponent[i] = 1.0;
109 
110  if ((ret = ff_wma_init(avctx, flags2)) < 0)
111  return ret;
112 
113  /* init MDCT */
114  for (i = 0; i < s->nb_block_sizes; i++) {
115  float scale = 1.0 / 32768.0;
116  ret = av_tx_init(&s->mdct_ctx[i], &s->mdct_fn[i], AV_TX_FLOAT_MDCT,
117  1, 1 << (s->frame_len_bits - i), &scale, AV_TX_FULL_IMDCT);
118  if (ret < 0)
119  return ret;
120  }
121 
122  if (s->use_noise_coding) {
125  &ff_wma_hgain_hufftab[0][1], 2,
126  &ff_wma_hgain_hufftab[0][0], 2, 1,
127  -18, 0, avctx);
128  if (ret < 0)
129  return ret;
130  }
131 
132  if (s->use_exp_vlc) {
133  // FIXME move out of context
134  ret = vlc_init(&s->exp_vlc, EXPVLCBITS, sizeof(ff_aac_scalefactor_bits),
136  ff_aac_scalefactor_code, 4, 4, 0);
137  if (ret < 0)
138  return ret;
139  } else
140  wma_lsp_to_curve_init(s, s->frame_len);
141 
143 
144  avctx->delay = s->frame_len * 2;
145 
146  return 0;
147 }
148 
149 /**
150  * compute x^-0.25 with an exponent and mantissa table. We use linear
151  * interpolation to reduce the mantissa table size at a small speed
152  * expense (linear interpolation approximately doubles the number of
153  * bits of precision).
154  */
155 static inline float pow_m1_4(WMACodecContext *s, float x)
156 {
157  union {
158  float f;
159  unsigned int v;
160  } u, t;
161  unsigned int e, m;
162  float a, b;
163 
164  u.f = x;
165  e = u.v >> 23;
166  m = (u.v >> (23 - LSP_POW_BITS)) & ((1 << LSP_POW_BITS) - 1);
167  /* build interpolation scale: 1 <= t < 2. */
168  t.v = ((u.v << LSP_POW_BITS) & ((1 << 23) - 1)) | (127 << 23);
169  a = s->lsp_pow_m_table1[m];
170  b = s->lsp_pow_m_table2[m];
171  return s->lsp_pow_e_table[e] * (a + b * t.f);
172 }
173 
174 static av_cold void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len)
175 {
176  float wdel, a, b;
177  int i, e, m;
178 
179  wdel = M_PI / frame_len;
180  for (i = 0; i < frame_len; i++)
181  s->lsp_cos_table[i] = 2.0f * cos(wdel * i);
182 
183  /* tables for x^-0.25 computation */
184  for (i = 0; i < 256; i++) {
185  e = i - 126;
186  s->lsp_pow_e_table[i] = exp2f(e * -0.25);
187  }
188 
189  /* NOTE: these two tables are needed to avoid two operations in
190  * pow_m1_4 */
191  b = 1.0;
192  for (i = (1 << LSP_POW_BITS) - 1; i >= 0; i--) {
193  m = (1 << LSP_POW_BITS) + i;
194  a = (float) m * (0.5 / (1 << LSP_POW_BITS));
195  a = 1/sqrt(sqrt(a));
196  s->lsp_pow_m_table1[i] = 2 * a - b;
197  s->lsp_pow_m_table2[i] = b - a;
198  b = a;
199  }
200 }
201 
202 /**
203  * NOTE: We use the same code as Vorbis here
204  * @todo optimize it further with SSE/3Dnow
205  */
206 static void wma_lsp_to_curve(WMACodecContext *s, float *out, float *val_max_ptr,
207  int n, float *lsp)
208 {
209  int i, j;
210  float p, q, w, v, val_max;
211 
212  val_max = 0;
213  for (i = 0; i < n; i++) {
214  p = 0.5f;
215  q = 0.5f;
216  w = s->lsp_cos_table[i];
217  for (j = 1; j < NB_LSP_COEFS; j += 2) {
218  q *= w - lsp[j - 1];
219  p *= w - lsp[j];
220  }
221  p *= p * (2.0f - w);
222  q *= q * (2.0f + w);
223  v = p + q;
224  v = pow_m1_4(s, v);
225  if (v > val_max)
226  val_max = v;
227  out[i] = v;
228  }
229  *val_max_ptr = val_max;
230 }
231 
232 /**
233  * decode exponents coded with LSP coefficients (same idea as Vorbis)
234  */
235 static void decode_exp_lsp(WMACodecContext *s, int ch)
236 {
237  float lsp_coefs[NB_LSP_COEFS];
238  int val, i;
239 
240  for (i = 0; i < NB_LSP_COEFS; i++) {
241  if (i == 0 || i >= 8)
242  val = get_bits(&s->gb, 3);
243  else
244  val = get_bits(&s->gb, 4);
245  lsp_coefs[i] = ff_wma_lsp_codebook[i][val];
246  }
247 
248  wma_lsp_to_curve(s, s->exponents[ch], &s->max_exponent[ch],
249  s->block_len, lsp_coefs);
250 }
251 
252 /** pow(10, i / 16.0) for i in -60..95 */
253 static const float pow_tab[] = {
254  1.7782794100389e-04, 2.0535250264571e-04,
255  2.3713737056617e-04, 2.7384196342644e-04,
256  3.1622776601684e-04, 3.6517412725484e-04,
257  4.2169650342858e-04, 4.8696752516586e-04,
258  5.6234132519035e-04, 6.4938163157621e-04,
259  7.4989420933246e-04, 8.6596432336006e-04,
260  1.0000000000000e-03, 1.1547819846895e-03,
261  1.3335214321633e-03, 1.5399265260595e-03,
262  1.7782794100389e-03, 2.0535250264571e-03,
263  2.3713737056617e-03, 2.7384196342644e-03,
264  3.1622776601684e-03, 3.6517412725484e-03,
265  4.2169650342858e-03, 4.8696752516586e-03,
266  5.6234132519035e-03, 6.4938163157621e-03,
267  7.4989420933246e-03, 8.6596432336006e-03,
268  1.0000000000000e-02, 1.1547819846895e-02,
269  1.3335214321633e-02, 1.5399265260595e-02,
270  1.7782794100389e-02, 2.0535250264571e-02,
271  2.3713737056617e-02, 2.7384196342644e-02,
272  3.1622776601684e-02, 3.6517412725484e-02,
273  4.2169650342858e-02, 4.8696752516586e-02,
274  5.6234132519035e-02, 6.4938163157621e-02,
275  7.4989420933246e-02, 8.6596432336007e-02,
276  1.0000000000000e-01, 1.1547819846895e-01,
277  1.3335214321633e-01, 1.5399265260595e-01,
278  1.7782794100389e-01, 2.0535250264571e-01,
279  2.3713737056617e-01, 2.7384196342644e-01,
280  3.1622776601684e-01, 3.6517412725484e-01,
281  4.2169650342858e-01, 4.8696752516586e-01,
282  5.6234132519035e-01, 6.4938163157621e-01,
283  7.4989420933246e-01, 8.6596432336007e-01,
284  1.0000000000000e+00, 1.1547819846895e+00,
285  1.3335214321633e+00, 1.5399265260595e+00,
286  1.7782794100389e+00, 2.0535250264571e+00,
287  2.3713737056617e+00, 2.7384196342644e+00,
288  3.1622776601684e+00, 3.6517412725484e+00,
289  4.2169650342858e+00, 4.8696752516586e+00,
290  5.6234132519035e+00, 6.4938163157621e+00,
291  7.4989420933246e+00, 8.6596432336007e+00,
292  1.0000000000000e+01, 1.1547819846895e+01,
293  1.3335214321633e+01, 1.5399265260595e+01,
294  1.7782794100389e+01, 2.0535250264571e+01,
295  2.3713737056617e+01, 2.7384196342644e+01,
296  3.1622776601684e+01, 3.6517412725484e+01,
297  4.2169650342858e+01, 4.8696752516586e+01,
298  5.6234132519035e+01, 6.4938163157621e+01,
299  7.4989420933246e+01, 8.6596432336007e+01,
300  1.0000000000000e+02, 1.1547819846895e+02,
301  1.3335214321633e+02, 1.5399265260595e+02,
302  1.7782794100389e+02, 2.0535250264571e+02,
303  2.3713737056617e+02, 2.7384196342644e+02,
304  3.1622776601684e+02, 3.6517412725484e+02,
305  4.2169650342858e+02, 4.8696752516586e+02,
306  5.6234132519035e+02, 6.4938163157621e+02,
307  7.4989420933246e+02, 8.6596432336007e+02,
308  1.0000000000000e+03, 1.1547819846895e+03,
309  1.3335214321633e+03, 1.5399265260595e+03,
310  1.7782794100389e+03, 2.0535250264571e+03,
311  2.3713737056617e+03, 2.7384196342644e+03,
312  3.1622776601684e+03, 3.6517412725484e+03,
313  4.2169650342858e+03, 4.8696752516586e+03,
314  5.6234132519035e+03, 6.4938163157621e+03,
315  7.4989420933246e+03, 8.6596432336007e+03,
316  1.0000000000000e+04, 1.1547819846895e+04,
317  1.3335214321633e+04, 1.5399265260595e+04,
318  1.7782794100389e+04, 2.0535250264571e+04,
319  2.3713737056617e+04, 2.7384196342644e+04,
320  3.1622776601684e+04, 3.6517412725484e+04,
321  4.2169650342858e+04, 4.8696752516586e+04,
322  5.6234132519035e+04, 6.4938163157621e+04,
323  7.4989420933246e+04, 8.6596432336007e+04,
324  1.0000000000000e+05, 1.1547819846895e+05,
325  1.3335214321633e+05, 1.5399265260595e+05,
326  1.7782794100389e+05, 2.0535250264571e+05,
327  2.3713737056617e+05, 2.7384196342644e+05,
328  3.1622776601684e+05, 3.6517412725484e+05,
329  4.2169650342858e+05, 4.8696752516586e+05,
330  5.6234132519035e+05, 6.4938163157621e+05,
331  7.4989420933246e+05, 8.6596432336007e+05,
332 };
333 
334 /**
335  * decode exponents coded with VLC codes
336  */
337 static int decode_exp_vlc(WMACodecContext *s, int ch)
338 {
339  int last_exp, n, code;
340  const uint16_t *ptr;
341  float v, max_scale;
342  uint32_t *q, *q_end, iv;
343  const float *ptab = pow_tab + 60;
344  const uint32_t *iptab = (const uint32_t *) ptab;
345 
346  ptr = s->exponent_bands[s->frame_len_bits - s->block_len_bits];
347  q = (uint32_t *) s->exponents[ch];
348  q_end = q + s->block_len;
349  max_scale = 0;
350  if (s->version == 1) {
351  last_exp = get_bits(&s->gb, 5) + 10;
352  v = ptab[last_exp];
353  iv = iptab[last_exp];
354  max_scale = v;
355  n = *ptr++;
356  switch (n & 3) do {
358  case 0: *q++ = iv; av_fallthrough;
359  case 3: *q++ = iv; av_fallthrough;
360  case 2: *q++ = iv; av_fallthrough;
361  case 1: *q++ = iv;
362  } while ((n -= 4) > 0);
363  } else
364  last_exp = 36;
365 
366  while (q < q_end) {
367  code = get_vlc2(&s->gb, s->exp_vlc.table, EXPVLCBITS, EXPMAX);
368  /* NOTE: this offset is the same as MPEG-4 AAC! */
369  last_exp += code - 60;
370  if ((unsigned) last_exp + 60 >= FF_ARRAY_ELEMS(pow_tab)) {
371  av_log(s->avctx, AV_LOG_ERROR, "Exponent out of range: %d\n",
372  last_exp);
373  return AVERROR_INVALIDDATA;
374  }
375  v = ptab[last_exp];
376  iv = iptab[last_exp];
377  if (v > max_scale)
378  max_scale = v;
379  n = *ptr++;
380  switch (n & 3) do {
382  case 0: *q++ = iv; av_fallthrough;
383  case 3: *q++ = iv; av_fallthrough;
384  case 2: *q++ = iv; av_fallthrough;
385  case 1: *q++ = iv;
386  } while ((n -= 4) > 0);
387  }
388  s->max_exponent[ch] = max_scale;
389  return 0;
390 }
391 
392 /**
393  * Apply MDCT window and add into output.
394  *
395  * We ensure that when the windows overlap their squared sum
396  * is always 1 (MDCT reconstruction rule).
397  */
398 static void wma_window(WMACodecContext *s, float *out)
399 {
400  float *in = s->output;
401  int block_len, bsize, n;
402 
403  /* left part */
404  if (s->block_len_bits <= s->prev_block_len_bits) {
405  block_len = s->block_len;
406  bsize = s->frame_len_bits - s->block_len_bits;
407 
408  s->fdsp->vector_fmul_add(out, in, s->windows[bsize],
409  out, block_len);
410  } else {
411  block_len = 1 << s->prev_block_len_bits;
412  n = (s->block_len - block_len) / 2;
413  bsize = s->frame_len_bits - s->prev_block_len_bits;
414 
415  s->fdsp->vector_fmul_add(out + n, in + n, s->windows[bsize],
416  out + n, block_len);
417 
418  memcpy(out + n + block_len, in + n + block_len, n * sizeof(float));
419  }
420 
421  out += s->block_len;
422  in += s->block_len;
423 
424  /* right part */
425  if (s->block_len_bits <= s->next_block_len_bits) {
426  block_len = s->block_len;
427  bsize = s->frame_len_bits - s->block_len_bits;
428 
429  s->fdsp->vector_fmul_reverse(out, in, s->windows[bsize], block_len);
430  } else {
431  block_len = 1 << s->next_block_len_bits;
432  n = (s->block_len - block_len) / 2;
433  bsize = s->frame_len_bits - s->next_block_len_bits;
434 
435  memcpy(out, in, n * sizeof(float));
436 
437  s->fdsp->vector_fmul_reverse(out + n, in + n, s->windows[bsize],
438  block_len);
439 
440  memset(out + n + block_len, 0, n * sizeof(float));
441  }
442 }
443 
444 /**
445  * @return
446  * 0 if OK.
447  * 1 if last block of frame.
448  * AVERROR if unrecoverable error.
449  */
451 {
452  int channels = s->avctx->ch_layout.nb_channels;
453  int n, v, a, bsize;
454  int coef_nb_bits, total_gain;
455  int nb_coefs[MAX_CHANNELS];
456  float mdct_norm;
457  AVTXContext *mdct;
458  av_tx_fn mdct_fn;
459 
461 
462 #ifdef TRACE
463  ff_tlog(s->avctx, "***decode_block: %d:%d\n",
464  s->frame_count - 1, s->block_num);
465 #endif /* TRACE */
466 
467  /* compute current block length */
468  if (s->use_variable_block_len) {
469  n = av_log2(s->nb_block_sizes - 1) + 1;
470 
471  if (s->reset_block_lengths) {
472  s->reset_block_lengths = 0;
473  v = get_bits(&s->gb, n);
474  if (v >= s->nb_block_sizes) {
475  av_log(s->avctx, AV_LOG_ERROR,
476  "prev_block_len_bits %d out of range\n",
477  s->frame_len_bits - v);
478  return AVERROR_INVALIDDATA;
479  }
480  s->prev_block_len_bits = s->frame_len_bits - v;
481  v = get_bits(&s->gb, n);
482  if (v >= s->nb_block_sizes) {
483  av_log(s->avctx, AV_LOG_ERROR,
484  "block_len_bits %d out of range\n",
485  s->frame_len_bits - v);
486  return AVERROR_INVALIDDATA;
487  }
488  s->block_len_bits = s->frame_len_bits - v;
489  } else {
490  /* update block lengths */
491  s->prev_block_len_bits = s->block_len_bits;
492  s->block_len_bits = s->next_block_len_bits;
493  }
494  v = get_bits(&s->gb, n);
495  if (v >= s->nb_block_sizes) {
496  av_log(s->avctx, AV_LOG_ERROR,
497  "next_block_len_bits %d out of range\n",
498  s->frame_len_bits - v);
499  return AVERROR_INVALIDDATA;
500  }
501  s->next_block_len_bits = s->frame_len_bits - v;
502  } else {
503  /* fixed block len */
504  s->next_block_len_bits = s->frame_len_bits;
505  s->prev_block_len_bits = s->frame_len_bits;
506  s->block_len_bits = s->frame_len_bits;
507  }
508 
509  if (s->frame_len_bits - s->block_len_bits >= s->nb_block_sizes){
510  av_log(s->avctx, AV_LOG_ERROR, "block_len_bits not initialized to a valid value\n");
511  return AVERROR_INVALIDDATA;
512  }
513 
514  /* now check if the block length is coherent with the frame length */
515  s->block_len = 1 << s->block_len_bits;
516  if ((s->block_pos + s->block_len) > s->frame_len) {
517  av_log(s->avctx, AV_LOG_ERROR, "frame_len overflow\n");
518  return AVERROR_INVALIDDATA;
519  }
520 
521  if (channels == 2)
522  s->ms_stereo = get_bits1(&s->gb);
523  v = 0;
524  for (int ch = 0; ch < channels; ch++) {
525  a = get_bits1(&s->gb);
526  s->channel_coded[ch] = a;
527  v |= a;
528  }
529 
530  bsize = s->frame_len_bits - s->block_len_bits;
531 
532  /* if no channel coded, no need to go further */
533  /* XXX: fix potential framing problems */
534  if (!v)
535  goto next;
536 
537  /* read total gain and extract corresponding number of bits for
538  * coef escape coding */
539  total_gain = 1;
540  for (;;) {
541  if (get_bits_left(&s->gb) < 7) {
542  av_log(s->avctx, AV_LOG_ERROR, "total_gain overread\n");
543  return AVERROR_INVALIDDATA;
544  }
545  a = get_bits(&s->gb, 7);
546  total_gain += a;
547  if (a != 127)
548  break;
549  }
550 
551  coef_nb_bits = ff_wma_total_gain_to_bits(total_gain);
552 
553  /* compute number of coefficients */
554  n = s->coefs_end[bsize] - s->coefs_start;
555  for (int ch = 0; ch < channels; ch++)
556  nb_coefs[ch] = n;
557 
558  /* complex coding */
559  if (s->use_noise_coding) {
560  for (int ch = 0; ch < channels; ch++) {
561  if (s->channel_coded[ch]) {
562  int n;
563  n = s->exponent_high_sizes[bsize];
564  for (int i = 0; i < n; i++) {
565  const unsigned a = get_bits1(&s->gb);
566  s->high_band_coded[ch][i] = a;
567  /* if noise coding, the coefficients are not transmitted */
568  if (a)
569  nb_coefs[ch] -= s->exponent_high_bands[bsize][i];
570  }
571  }
572  }
573  for (int ch = 0; ch < channels; ch++) {
574  if (s->channel_coded[ch]) {
575  int n, val;
576 
577  n = s->exponent_high_sizes[bsize];
578  val = (int) 0x80000000;
579  for (int i = 0; i < n; i++) {
580  if (s->high_band_coded[ch][i]) {
581  if (val == (int) 0x80000000) {
582  val = get_bits(&s->gb, 7) - 19;
583  } else {
584  val += get_vlc2(&s->gb, s->hgain_vlc.table,
586  }
587  s->high_band_values[ch][i] = val;
588  }
589  }
590  }
591  }
592  }
593 
594  /* exponents can be reused in short blocks. */
595  if ((s->block_len_bits == s->frame_len_bits) || get_bits1(&s->gb)) {
596  for (int ch = 0; ch < channels; ch++) {
597  if (s->channel_coded[ch]) {
598  if (s->use_exp_vlc) {
599  if (decode_exp_vlc(s, ch) < 0)
600  return AVERROR_INVALIDDATA;
601  } else {
602  decode_exp_lsp(s, ch);
603  }
604  s->exponents_bsize[ch] = bsize;
605  s->exponents_initialized[ch] = 1;
606  }
607  }
608  }
609 
610  for (int ch = 0; ch < channels; ch++) {
611  if (s->channel_coded[ch] && !s->exponents_initialized[ch])
612  return AVERROR_INVALIDDATA;
613  }
614 
615  /* parse spectral coefficients : just RLE encoding */
616  for (int ch = 0; ch < channels; ch++) {
617  if (s->channel_coded[ch]) {
618  int tindex;
619  WMACoef *ptr = &s->coefs1[ch][0];
620  int ret;
621 
622  /* special VLC tables are used for ms stereo because
623  * there is potentially less energy there */
624  tindex = (ch == 1 && s->ms_stereo);
625  memset(ptr, 0, s->block_len * sizeof(WMACoef));
626  ret = ff_wma_run_level_decode(s->avctx, &s->gb, s->coef_vlc[tindex].table,
627  s->level_table[tindex], s->run_table[tindex],
628  0, ptr, 0, nb_coefs[ch],
629  s->block_len, s->frame_len_bits, coef_nb_bits);
630  if (ret < 0)
631  return ret;
632  }
633  if (s->version == 1 && channels >= 2)
634  align_get_bits(&s->gb);
635  }
636 
637  /* normalize */
638  {
639  int n4 = s->block_len / 2;
640  mdct_norm = 1.0 / (float) n4;
641  if (s->version == 1)
642  mdct_norm *= sqrt(n4);
643  }
644 
645  /* finally compute the MDCT coefficients */
646  for (int ch = 0; ch < channels; ch++) {
647  if (s->channel_coded[ch]) {
648  WMACoef *coefs1;
649  float *coefs, *exponents, mult, mult1, noise;
650  int n, n1, last_high_band, esize;
651  float exp_power[HIGH_BAND_MAX_SIZE];
652 
653  coefs1 = s->coefs1[ch];
654  exponents = s->exponents[ch];
655  esize = s->exponents_bsize[ch];
656  mult = ff_exp10(total_gain * 0.05) / s->max_exponent[ch];
657  mult *= mdct_norm;
658  coefs = s->coefs[ch];
659  if (s->use_noise_coding) {
660  mult1 = mult;
661  /* very low freqs : noise */
662  for (int i = 0; i < s->coefs_start; i++) {
663  *coefs++ = s->noise_table[s->noise_index] *
664  exponents[i << bsize >> esize] * mult1;
665  s->noise_index = (s->noise_index + 1) &
666  (NOISE_TAB_SIZE - 1);
667  }
668 
669  n1 = s->exponent_high_sizes[bsize];
670 
671  /* compute power of high bands */
672  exponents = s->exponents[ch] +
673  (s->high_band_start[bsize] << bsize >> esize);
674  last_high_band = 0; /* avoid warning */
675  for (int j = 0; j < n1; j++) {
676  n = s->exponent_high_bands[s->frame_len_bits -
677  s->block_len_bits][j];
678  if (s->high_band_coded[ch][j]) {
679  float e2, v;
680  e2 = 0;
681  for (int i = 0; i < n; i++) {
682  v = exponents[i << bsize >> esize];
683  e2 += v * v;
684  }
685  exp_power[j] = e2 / n;
686  last_high_band = j;
687  ff_tlog(s->avctx, "%d: power=%f (%d)\n", j, exp_power[j], n);
688  }
689  exponents += n << bsize >> esize;
690  }
691 
692  /* main freqs and high freqs */
693  exponents = s->exponents[ch] + (s->coefs_start << bsize >> esize);
694  for (int j = -1; j < n1; j++) {
695  if (j < 0)
696  n = s->high_band_start[bsize] - s->coefs_start;
697  else
698  n = s->exponent_high_bands[s->frame_len_bits -
699  s->block_len_bits][j];
700  if (j >= 0 && s->high_band_coded[ch][j]) {
701  /* use noise with specified power */
702  mult1 = sqrt(exp_power[j] / exp_power[last_high_band]);
703  /* XXX: use a table */
704  mult1 = mult1 * ff_exp10(s->high_band_values[ch][j] * 0.05);
705  mult1 = mult1 / (s->max_exponent[ch] * s->noise_mult);
706  mult1 *= mdct_norm;
707  for (int i = 0; i < n; i++) {
708  noise = s->noise_table[s->noise_index];
709  s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
710  *coefs++ = noise * exponents[i << bsize >> esize] * mult1;
711  }
712  exponents += n << bsize >> esize;
713  } else {
714  /* coded values + small noise */
715  for (int i = 0; i < n; i++) {
716  noise = s->noise_table[s->noise_index];
717  s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
718  *coefs++ = ((*coefs1++) + noise) *
719  exponents[i << bsize >> esize] * mult;
720  }
721  exponents += n << bsize >> esize;
722  }
723  }
724 
725  /* very high freqs : noise */
726  n = s->block_len - s->coefs_end[bsize];
727  mult1 = mult * exponents[(-(1 << bsize)) >> esize];
728  for (int i = 0; i < n; i++) {
729  *coefs++ = s->noise_table[s->noise_index] * mult1;
730  s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
731  }
732  } else {
733  /* XXX: optimize more */
734  for (int i = 0; i < s->coefs_start; i++)
735  *coefs++ = 0.0;
736  n = nb_coefs[ch];
737  for (int i = 0; i < n; i++)
738  *coefs++ = coefs1[i] * exponents[i << bsize >> esize] * mult;
739  n = s->block_len - s->coefs_end[bsize];
740  for (int i = 0; i < n; i++)
741  *coefs++ = 0.0;
742  }
743  }
744  }
745 
746 #ifdef TRACE
747  for (int ch = 0; ch < channels; ch++) {
748  if (s->channel_coded[ch]) {
749  dump_floats(s, "exponents", 3, s->exponents[ch], s->block_len);
750  dump_floats(s, "coefs", 1, s->coefs[ch], s->block_len);
751  }
752  }
753 #endif /* TRACE */
754 
755  if (s->ms_stereo && s->channel_coded[1]) {
756  /* nominal case for ms stereo: we do it before mdct */
757  /* no need to optimize this case because it should almost
758  * never happen */
759  if (!s->channel_coded[0]) {
760  ff_tlog(s->avctx, "rare ms-stereo case happened\n");
761  memset(s->coefs[0], 0, sizeof(float) * s->block_len);
762  s->channel_coded[0] = 1;
763  }
764 
765  s->fdsp->butterflies_float(s->coefs[0], s->coefs[1], s->block_len);
766  }
767 
768 next:
769  mdct = s->mdct_ctx[bsize];
770  mdct_fn = s->mdct_fn[bsize];
771 
772  for (int ch = 0; ch < channels; ch++) {
773  int n4, index;
774 
775  n4 = s->block_len / 2;
776  if (s->channel_coded[ch])
777  mdct_fn(mdct, s->output, s->coefs[ch], sizeof(float));
778  else if (!(s->ms_stereo && ch == 1))
779  memset(s->output, 0, sizeof(s->output));
780 
781  /* multiply by the window and add in the frame */
782  index = (s->frame_len / 2) + s->block_pos - n4;
783  wma_window(s, &s->frame_out[ch][index]);
784  }
785 
786  /* update block number */
787  s->block_num++;
788  s->block_pos += s->block_len;
789  if (s->block_pos >= s->frame_len)
790  return 1;
791  else
792  return 0;
793 }
794 
795 /* decode a frame of frame_len samples */
797  int samples_offset)
798 {
799 #ifdef TRACE
800  ff_tlog(s->avctx, "***decode_frame: %d size=%d\n",
801  s->frame_count++, s->frame_len);
802 #endif /* TRACE */
803 
804  /* read each block */
805  s->block_num = 0;
806  s->block_pos = 0;
807  for (;;) {
808  int ret = wma_decode_block(s);
809  if (ret < 0)
810  return ret;
811  if (ret)
812  break;
813  }
814 
815  for (int ch = 0; ch < s->avctx->ch_layout.nb_channels; ch++) {
816  /* copy current block to output */
817  memcpy(samples[ch] + samples_offset, s->frame_out[ch],
818  s->frame_len * sizeof(*s->frame_out[ch]));
819  /* prepare for next block */
820  memmove(&s->frame_out[ch][0], &s->frame_out[ch][s->frame_len],
821  s->frame_len * sizeof(*s->frame_out[ch]));
822 
823 #ifdef TRACE
824  dump_floats(s, "samples", 6, samples[ch] + samples_offset,
825  s->frame_len);
826 #endif /* TRACE */
827  }
828 
829  return 0;
830 }
831 
833  int *got_frame_ptr, AVPacket *avpkt)
834 {
835  const uint8_t *buf = avpkt->data;
836  int buf_size = avpkt->size;
837  WMACodecContext *s = avctx->priv_data;
838  int nb_frames, bit_offset, pos, len, ret;
839  uint8_t *q;
840  float **samples;
841  int samples_offset;
842 
843  ff_tlog(avctx, "***decode_superframe:\n");
844 
845  if (buf_size == 0) {
846  if (s->eof_done)
847  return 0;
848 
849  frame->nb_samples = s->frame_len;
850  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
851  return ret;
852 
853  frame->pts = AV_NOPTS_VALUE;
854  for (int i = 0; i < s->avctx->ch_layout.nb_channels; i++)
855  memcpy(frame->extended_data[i], &s->frame_out[i][0],
856  frame->nb_samples * sizeof(s->frame_out[i][0]));
857 
858  s->last_superframe_len = 0;
859  s->eof_done = 1;
860  *got_frame_ptr = 1;
861  return 0;
862  }
863  if (buf_size < avctx->block_align) {
864  av_log(avctx, AV_LOG_ERROR,
865  "Input packet size too small (%d < %d)\n",
866  buf_size, avctx->block_align);
867  return AVERROR_INVALIDDATA;
868  }
869  if (avctx->block_align)
870  buf_size = avctx->block_align;
871 
872  init_get_bits(&s->gb, buf, buf_size * 8);
873 
874  if (s->use_bit_reservoir) {
875  /* read super frame header */
876  skip_bits(&s->gb, 4); /* super frame index */
877  nb_frames = get_bits(&s->gb, 4) - (s->last_superframe_len <= 0);
878  if (nb_frames <= 0) {
879  int is_error = nb_frames < 0 || get_bits_left(&s->gb) <= 8;
880  av_log(avctx, is_error ? AV_LOG_ERROR : AV_LOG_WARNING,
881  "nb_frames is %d bits left %d\n",
882  nb_frames, get_bits_left(&s->gb));
883  if (is_error)
884  return AVERROR_INVALIDDATA;
885 
886  if ((s->last_superframe_len + buf_size - 1) >
889  goto fail;
890  }
891 
892  q = s->last_superframe + s->last_superframe_len;
893  len = buf_size - 1;
894  while (len > 0) {
895  *q++ = get_bits (&s->gb, 8);
896  len --;
897  }
898  memset(q, 0, AV_INPUT_BUFFER_PADDING_SIZE);
899 
900  s->last_superframe_len += 8*buf_size - 8;
901 // s->reset_block_lengths = 1; //XXX is this needed ?
902  *got_frame_ptr = 0;
903  return buf_size;
904  }
905  } else
906  nb_frames = 1;
907 
908  /* get output buffer */
909  frame->nb_samples = nb_frames * s->frame_len;
910  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
911  return ret;
912  samples = (float **) frame->extended_data;
913  samples_offset = 0;
914 
915  if (s->use_bit_reservoir) {
916  bit_offset = get_bits(&s->gb, s->byte_offset_bits + 3);
917  if (bit_offset > get_bits_left(&s->gb)) {
918  av_log(avctx, AV_LOG_ERROR,
919  "Invalid last frame bit offset %d > buf size %d (%d)\n",
920  bit_offset, get_bits_left(&s->gb), buf_size);
922  goto fail;
923  }
924 
925  if (s->last_superframe_len > 0) {
926  /* add bit_offset bits to last frame */
927  if ((s->last_superframe_len + ((bit_offset + 7) >> 3)) >
930  goto fail;
931  }
932  q = s->last_superframe + s->last_superframe_len;
933  len = bit_offset;
934  while (len > 7) {
935  *q++ = get_bits(&s->gb, 8);
936  len -= 8;
937  }
938  if (len > 0)
939  *q++ = get_bits(&s->gb, len) << (8 - len);
940  memset(q, 0, AV_INPUT_BUFFER_PADDING_SIZE);
941 
942  /* XXX: bit_offset bits into last frame */
943  init_get_bits(&s->gb, s->last_superframe,
944  s->last_superframe_len * 8 + bit_offset);
945  /* skip unused bits */
946  if (s->last_bitoffset > 0)
947  skip_bits(&s->gb, s->last_bitoffset);
948  /* this frame is stored in the last superframe and in the
949  * current one */
950  if ((ret = wma_decode_frame(s, samples, samples_offset)) < 0)
951  goto fail;
952  samples_offset += s->frame_len;
953  nb_frames--;
954  }
955 
956  /* read each frame starting from bit_offset */
957  pos = bit_offset + 4 + 4 + s->byte_offset_bits + 3;
958  if (pos >= MAX_CODED_SUPERFRAME_SIZE * 8 || pos > buf_size * 8)
959  return AVERROR_INVALIDDATA;
960  init_get_bits(&s->gb, buf + (pos >> 3), (buf_size - (pos >> 3)) * 8);
961  len = pos & 7;
962  if (len > 0)
963  skip_bits(&s->gb, len);
964 
965  s->reset_block_lengths = 1;
966  for (int i = 0; i < nb_frames; i++) {
967  if ((ret = wma_decode_frame(s, samples, samples_offset)) < 0)
968  goto fail;
969  samples_offset += s->frame_len;
970  }
971 
972  /* we copy the end of the frame in the last frame buffer */
973  pos = get_bits_count(&s->gb) +
974  ((bit_offset + 4 + 4 + s->byte_offset_bits + 3) & ~7);
975  s->last_bitoffset = pos & 7;
976  pos >>= 3;
977  len = buf_size - pos;
978  if (len > MAX_CODED_SUPERFRAME_SIZE || len < 0) {
979  av_log(s->avctx, AV_LOG_ERROR, "len %d invalid\n", len);
981  goto fail;
982  }
983  s->last_superframe_len = len;
984  memcpy(s->last_superframe, buf + pos, len);
985  } else {
986  /* single frame decode */
987  if ((ret = wma_decode_frame(s, samples, samples_offset)) < 0)
988  goto fail;
989  samples_offset += s->frame_len;
990  }
991 
992  ff_dlog(s->avctx, "%d %d %d %d eaten:%d\n",
993  s->frame_len_bits, s->block_len_bits, s->frame_len, s->block_len,
994  avctx->block_align);
995 
996  *got_frame_ptr = 1;
997 
998  return buf_size;
999 
1000 fail:
1001  /* when error, we reset the bit reservoir */
1002  s->last_superframe_len = 0;
1003  return ret;
1004 }
1005 
1006 static av_cold void flush(AVCodecContext *avctx)
1007 {
1008  WMACodecContext *s = avctx->priv_data;
1009 
1010  s->last_bitoffset =
1011  s->last_superframe_len = 0;
1012 
1013  s->eof_done = 0;
1014  avctx->internal->skip_samples = s->frame_len * 2;
1015 }
1016 
1017 #if CONFIG_WMAV1_DECODER
1018 const FFCodec ff_wmav1_decoder = {
1019  .p.name = "wmav1",
1020  CODEC_LONG_NAME("Windows Media Audio 1"),
1021  .p.type = AVMEDIA_TYPE_AUDIO,
1022  .p.id = AV_CODEC_ID_WMAV1,
1023  .priv_data_size = sizeof(WMACodecContext),
1024  .init = wma_decode_init,
1025  .close = ff_wma_end,
1027  .flush = flush,
1028  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
1029  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1030 };
1031 #endif
1032 #if CONFIG_WMAV2_DECODER
1033 const FFCodec ff_wmav2_decoder = {
1034  .p.name = "wmav2",
1035  CODEC_LONG_NAME("Windows Media Audio 2"),
1036  .p.type = AVMEDIA_TYPE_AUDIO,
1037  .p.id = AV_CODEC_ID_WMAV2,
1038  .priv_data_size = sizeof(WMACodecContext),
1039  .init = wma_decode_init,
1040  .close = ff_wma_end,
1042  .flush = flush,
1043  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
1044  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1045 };
1046 #endif
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
nb_coefs
static int nb_coefs(int length, int level, uint64_t sn)
Definition: af_afwtdn.c:515
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
ff_vlc_init_from_lengths
int ff_vlc_init_from_lengths(VLC *vlc, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags, void *logctx)
Build VLC decoding tables suitable for use with get_vlc2()
Definition: vlc.c:306
ff_exp10
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
Definition: ffmath.h:42
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:43
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:688
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
out
static FILE * out
Definition: movenc.c:55
flush
static av_cold void flush(AVCodecContext *avctx)
Definition: wmadec.c:1006
AVTXContext
Definition: tx_priv.h:235
AVCodecInternal::skip_samples
int skip_samples
Number of audio samples to skip at the start of the next decoded frame.
Definition: internal.h:125
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:254
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:435
u
#define u(width, name, range_min, range_max)
Definition: cbs_apv.c:68
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:595
wma_lsp_to_curve_init
static void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len)
Definition: wmadec.c:174
b
#define b
Definition: input.c:43
FFCodec
Definition: codec_internal.h:127
ff_wma_run_level_decode
int ff_wma_run_level_decode(AVCodecContext *avctx, GetBitContext *gb, const VLCElem *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:427
AV_CODEC_ID_WMAV2
@ AV_CODEC_ID_WMAV2
Definition: codec_id.h:468
ff_wmav2_decoder
const FFCodec ff_wmav2_decoder
wma_decode_frame
static int wma_decode_frame(WMACodecContext *s, float **samples, int samples_offset)
Definition: wmadec.c:796
AVCodecContext::delay
int delay
Codec delay.
Definition: avcodec.h:583
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:517
av_tx_init
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
Definition: tx.c:903
ff_wma_hgain_hufftab
const uint8_t ff_wma_hgain_hufftab[37][2]
Definition: wmadata.h:54
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:383
close
static av_cold void close(AVCodecParserContext *s)
Definition: apv_parser.c:197
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:337
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
HIGH_BAND_MAX_SIZE
#define HIGH_BAND_MAX_SIZE
Definition: wma.h:41
decode_exp_lsp
static void decode_exp_lsp(WMACodecContext *s, int ch)
decode exponents coded with LSP coefficients (same idea as Vorbis)
Definition: wmadec.c:235
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:448
WMACoef
float WMACoef
type for decoded coefficients, int16_t would be enough for wma 1/2
Definition: wma.h:58
fail
#define fail()
Definition: checkasm.h:224
tab
static const struct twinvq_data tab
Definition: twinvq_data.h:10345
noise
static int noise(AVBSFContext *ctx, AVPacket *pkt)
Definition: noise.c:124
val
static double val(void *priv, double ch)
Definition: aeval.c:77
WMACodecContext
Definition: wma.h:68
mult
static int16_t mult(Float11 *f1, Float11 *f2)
Definition: g726.c:60
AV_CODEC_ID_WMAV1
@ AV_CODEC_ID_WMAV1
Definition: codec_id.h:467
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:119
av_tx_fn
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition: tx.h:151
float
float
Definition: af_crystalizer.c:122
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:523
AV_TX_FLOAT_MDCT
@ AV_TX_FLOAT_MDCT
Standard MDCT with a sample data type of float, double or int32_t, respectively.
Definition: tx.h:68
EXPVLCBITS
#define EXPVLCBITS
Definition: wmadec.c:48
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:347
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:201
vlc_init
#define vlc_init(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
Definition: vlc.h:70
exp2f
#define exp2f(x)
Definition: libm.h:295
channels
channels
Definition: aptx.h:31
decode.h
AV_RL16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
Definition: bytestream.h:94
wma.h
ff_wma_total_gain_to_bits
int ff_wma_total_gain_to_bits(int total_gain)
Definition: wma.c:353
av_fallthrough
#define av_fallthrough
Definition: attributes.h:67
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:332
if
if(ret)
Definition: filter_design.txt:179
AV_TX_FULL_IMDCT
@ AV_TX_FULL_IMDCT
Performs a full inverse MDCT rather than leaving out samples that can be derived through symmetry.
Definition: tx.h:175
HGAINMAX
#define HGAINMAX
Definition: wmadec.c:52
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:474
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:391
get_vlc2
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:645
index
int index
Definition: gxfenc.c:90
ff_wma_end
av_cold int ff_wma_end(AVCodecContext *avctx)
Definition: wma.c:367
MAX_CODED_SUPERFRAME_SIZE
#define MAX_CODED_SUPERFRAME_SIZE
Definition: wma.h:46
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
ff_aac_scalefactor_bits
const uint8_t ff_aac_scalefactor_bits[121]
Definition: aactab.c:200
f
f
Definition: af_crystalizer.c:122
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1765
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:551
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:596
ff_wmav1_decoder
const FFCodec ff_wmav1_decoder
codec_internal.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
wma_lsp_to_curve
static void wma_lsp_to_curve(WMACodecContext *s, float *out, float *val_max_ptr, int n, float *lsp)
NOTE: We use the same code as Vorbis here.
Definition: wmadec.c:206
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1043
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:247
ff_wma_init
av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
Definition: wma.c:79
NOISE_TAB_SIZE
#define NOISE_TAB_SIZE
Definition: wma.h:50
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
attributes.h
MAX_CHANNELS
#define MAX_CHANNELS
Definition: aac.h:33
wma_decode_block
static int wma_decode_block(WMACodecContext *s)
Definition: wmadec.c:450
M_PI
#define M_PI
Definition: mathematics.h:67
pow_tab
static const float pow_tab[]
pow(10, i / 16.0) for i in -60..95
Definition: wmadec.c:253
AVCodec::id
enum AVCodecID id
Definition: codec.h:186
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:68
LSP_POW_BITS
#define LSP_POW_BITS
Definition: wma.h:52
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
AVCodecContext::extradata
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition: avcodec.h:522
wma_window
static void wma_window(WMACodecContext *s, float *out)
Apply MDCT window and add into output.
Definition: wmadec.c:398
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:179
len
int len
Definition: vorbis_enc_data.h:426
avcodec.h
ret
ret
Definition: filter_design.txt:187
AVCodecContext::block_align
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
Definition: avcodec.h:1069
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
wma_decode_superframe
static int wma_decode_superframe(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: wmadec.c:832
HGAINVLCBITS
#define HGAINVLCBITS
Definition: wmadec.c:51
align_get_bits
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:560
pos
unsigned int pos
Definition: spdifenc.c:414
EXPMAX
#define EXPMAX
Definition: wmadec.c:49
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
AVCodecContext
main external API structure.
Definition: avcodec.h:439
decode_exp_vlc
static int decode_exp_vlc(WMACodecContext *s, int ch)
decode exponents coded with VLC codes
Definition: wmadec.c:337
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:76
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
ffmath.h
ff_wma_lsp_codebook
const float ff_wma_lsp_codebook[NB_LSP_COEFS][16]
Definition: wmadata.h:64
w
uint8_t w
Definition: llvidencdsp.c:39
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:278
ff_tlog
#define ff_tlog(a,...)
Definition: tableprint_vlc.h:29
AVPacket
This structure stores compressed data.
Definition: packet.h:572
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:466
NB_LSP_COEFS
#define NB_LSP_COEFS
Definition: wma.h:43
wma_decode_init
static av_cold int wma_decode_init(AVCodecContext *avctx)
Definition: wmadec.c:75
pow_m1_4
static float pow_m1_4(WMACodecContext *s, float x)
compute x^-0.25 with an exponent and mantissa table.
Definition: wmadec.c:155
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
ff_aac_scalefactor_code
const uint32_t ff_aac_scalefactor_code[121]
Definition: aactab.c:181