FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/wmadec.c
Date: 2022-07-07 01:21:54
Exec Total Coverage
Lines: 236 462 51.1%
Branches: 127 276 46.0%

Line Branch Exec Source
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/ffmath.h"
40
41 #include "avcodec.h"
42 #include "codec_internal.h"
43 #include "internal.h"
44 #include "wma.h"
45
46 #define EXPVLCBITS 8
47 #define EXPMAX ((19 + EXPVLCBITS - 1) / EXPVLCBITS)
48
49 #define HGAINVLCBITS 9
50 #define HGAINMAX ((13 + HGAINVLCBITS - 1) / HGAINVLCBITS)
51
52 static void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len);
53
54 #ifdef TRACE
55 static void dump_floats(WMACodecContext *s, const char *name,
56 int prec, const float *tab, int n)
57 {
58 int i;
59
60 ff_tlog(s->avctx, "%s[%d]:\n", name, n);
61 for (i = 0; i < n; i++) {
62 if ((i & 7) == 0)
63 ff_tlog(s->avctx, "%4d: ", i);
64 ff_tlog(s->avctx, " %8.*f", prec, tab[i]);
65 if ((i & 7) == 7)
66 ff_tlog(s->avctx, "\n");
67 }
68 if ((i & 7) != 0)
69 ff_tlog(s->avctx, "\n");
70 }
71 #endif /* TRACE */
72
73 14 static av_cold int wma_decode_init(AVCodecContext *avctx)
74 {
75 14 WMACodecContext *s = avctx->priv_data;
76 int i, flags2, ret;
77 uint8_t *extradata;
78
79
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (!avctx->block_align) {
80 av_log(avctx, AV_LOG_ERROR, "block_align is not set\n");
81 return AVERROR(EINVAL);
82 }
83
84 14 s->avctx = avctx;
85
86 /* extract flag info */
87 14 flags2 = 0;
88 14 extradata = avctx->extradata;
89
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
14 if (avctx->codec->id == AV_CODEC_ID_WMAV1 && avctx->extradata_size >= 4)
90 2 flags2 = AV_RL16(extradata + 2);
91
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 else if (avctx->codec->id == AV_CODEC_ID_WMAV2 && avctx->extradata_size >= 6)
92 12 flags2 = AV_RL16(extradata + 4);
93
94 14 s->use_exp_vlc = flags2 & 0x0001;
95 14 s->use_bit_reservoir = flags2 & 0x0002;
96 14 s->use_variable_block_len = flags2 & 0x0004;
97
98
4/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 1 times.
14 if (avctx->codec->id == AV_CODEC_ID_WMAV2 && avctx->extradata_size >= 8){
99
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11 if (AV_RL16(extradata+4)==0xd && s->use_variable_block_len){
100 av_log(avctx, AV_LOG_WARNING, "Disabling use_variable_block_len, if this fails contact the ffmpeg developers and send us the file\n");
101 s->use_variable_block_len= 0; // this fixes issue1503
102 }
103 }
104
105
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 14 times.
42 for (i=0; i<MAX_CHANNELS; i++)
106 28 s->max_exponent[i] = 1.0;
107
108
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
14 if ((ret = ff_wma_init(avctx, flags2)) < 0)
109 return ret;
110
111 /* init MDCT */
112
2/2
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 14 times.
51 for (i = 0; i < s->nb_block_sizes; i++) {
113 37 ret = ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1,
114 1, 1.0 / 32768.0);
115
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
37 if (ret < 0)
116 return ret;
117 }
118
119
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 12 times.
14 if (s->use_noise_coding) {
120 2 ret = ff_init_vlc_from_lengths(&s->hgain_vlc, HGAINVLCBITS,
121 FF_ARRAY_ELEMS(ff_wma_hgain_hufftab),
122 &ff_wma_hgain_hufftab[0][1], 2,
123 &ff_wma_hgain_hufftab[0][0], 2, 1,
124 -18, 0, avctx);
125
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (ret < 0)
126 return ret;
127 }
128
129
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 3 times.
14 if (s->use_exp_vlc) {
130 // FIXME move out of context
131 11 ret = init_vlc(&s->exp_vlc, EXPVLCBITS, sizeof(ff_aac_scalefactor_bits),
132 ff_aac_scalefactor_bits, 1, 1,
133 ff_aac_scalefactor_code, 4, 4, 0);
134
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (ret < 0)
135 return ret;
136 } else
137 3 wma_lsp_to_curve_init(s, s->frame_len);
138
139 14 avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
140
141 14 avctx->internal->skip_samples = s->frame_len * 2;
142
143 14 return 0;
144 }
145
146 /**
147 * compute x^-0.25 with an exponent and mantissa table. We use linear
148 * interpolation to reduce the mantissa table size at a small speed
149 * expense (linear interpolation approximately doubles the number of
150 * bits of precision).
151 */
152 static inline float pow_m1_4(WMACodecContext *s, float x)
153 {
154 union {
155 float f;
156 unsigned int v;
157 } u, t;
158 unsigned int e, m;
159 float a, b;
160
161 u.f = x;
162 e = u.v >> 23;
163 m = (u.v >> (23 - LSP_POW_BITS)) & ((1 << LSP_POW_BITS) - 1);
164 /* build interpolation scale: 1 <= t < 2. */
165 t.v = ((u.v << LSP_POW_BITS) & ((1 << 23) - 1)) | (127 << 23);
166 a = s->lsp_pow_m_table1[m];
167 b = s->lsp_pow_m_table2[m];
168 return s->lsp_pow_e_table[e] * (a + b * t.f);
169 }
170
171 3 static av_cold void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len)
172 {
173 float wdel, a, b;
174 int i, e, m;
175
176 3 wdel = M_PI / frame_len;
177
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 3 times.
1539 for (i = 0; i < frame_len; i++)
178 1536 s->lsp_cos_table[i] = 2.0f * cos(wdel * i);
179
180 /* tables for x^-0.25 computation */
181
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 3 times.
771 for (i = 0; i < 256; i++) {
182 768 e = i - 126;
183 768 s->lsp_pow_e_table[i] = exp2f(e * -0.25);
184 }
185
186 /* NOTE: these two tables are needed to avoid two operations in
187 * pow_m1_4 */
188 3 b = 1.0;
189
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 3 times.
387 for (i = (1 << LSP_POW_BITS) - 1; i >= 0; i--) {
190 384 m = (1 << LSP_POW_BITS) + i;
191 384 a = (float) m * (0.5 / (1 << LSP_POW_BITS));
192 384 a = 1/sqrt(sqrt(a));
193 384 s->lsp_pow_m_table1[i] = 2 * a - b;
194 384 s->lsp_pow_m_table2[i] = b - a;
195 384 b = a;
196 }
197 3 }
198
199 /**
200 * NOTE: We use the same code as Vorbis here
201 * @todo optimize it further with SSE/3Dnow
202 */
203 static void wma_lsp_to_curve(WMACodecContext *s, float *out, float *val_max_ptr,
204 int n, float *lsp)
205 {
206 int i, j;
207 float p, q, w, v, val_max;
208
209 val_max = 0;
210 for (i = 0; i < n; i++) {
211 p = 0.5f;
212 q = 0.5f;
213 w = s->lsp_cos_table[i];
214 for (j = 1; j < NB_LSP_COEFS; j += 2) {
215 q *= w - lsp[j - 1];
216 p *= w - lsp[j];
217 }
218 p *= p * (2.0f - w);
219 q *= q * (2.0f + w);
220 v = p + q;
221 v = pow_m1_4(s, v);
222 if (v > val_max)
223 val_max = v;
224 out[i] = v;
225 }
226 *val_max_ptr = val_max;
227 }
228
229 /**
230 * decode exponents coded with LSP coefficients (same idea as Vorbis)
231 */
232 static void decode_exp_lsp(WMACodecContext *s, int ch)
233 {
234 float lsp_coefs[NB_LSP_COEFS];
235 int val, i;
236
237 for (i = 0; i < NB_LSP_COEFS; i++) {
238 if (i == 0 || i >= 8)
239 val = get_bits(&s->gb, 3);
240 else
241 val = get_bits(&s->gb, 4);
242 lsp_coefs[i] = ff_wma_lsp_codebook[i][val];
243 }
244
245 wma_lsp_to_curve(s, s->exponents[ch], &s->max_exponent[ch],
246 s->block_len, lsp_coefs);
247 }
248
249 /** pow(10, i / 16.0) for i in -60..95 */
250 static const float pow_tab[] = {
251 1.7782794100389e-04, 2.0535250264571e-04,
252 2.3713737056617e-04, 2.7384196342644e-04,
253 3.1622776601684e-04, 3.6517412725484e-04,
254 4.2169650342858e-04, 4.8696752516586e-04,
255 5.6234132519035e-04, 6.4938163157621e-04,
256 7.4989420933246e-04, 8.6596432336006e-04,
257 1.0000000000000e-03, 1.1547819846895e-03,
258 1.3335214321633e-03, 1.5399265260595e-03,
259 1.7782794100389e-03, 2.0535250264571e-03,
260 2.3713737056617e-03, 2.7384196342644e-03,
261 3.1622776601684e-03, 3.6517412725484e-03,
262 4.2169650342858e-03, 4.8696752516586e-03,
263 5.6234132519035e-03, 6.4938163157621e-03,
264 7.4989420933246e-03, 8.6596432336006e-03,
265 1.0000000000000e-02, 1.1547819846895e-02,
266 1.3335214321633e-02, 1.5399265260595e-02,
267 1.7782794100389e-02, 2.0535250264571e-02,
268 2.3713737056617e-02, 2.7384196342644e-02,
269 3.1622776601684e-02, 3.6517412725484e-02,
270 4.2169650342858e-02, 4.8696752516586e-02,
271 5.6234132519035e-02, 6.4938163157621e-02,
272 7.4989420933246e-02, 8.6596432336007e-02,
273 1.0000000000000e-01, 1.1547819846895e-01,
274 1.3335214321633e-01, 1.5399265260595e-01,
275 1.7782794100389e-01, 2.0535250264571e-01,
276 2.3713737056617e-01, 2.7384196342644e-01,
277 3.1622776601684e-01, 3.6517412725484e-01,
278 4.2169650342858e-01, 4.8696752516586e-01,
279 5.6234132519035e-01, 6.4938163157621e-01,
280 7.4989420933246e-01, 8.6596432336007e-01,
281 1.0000000000000e+00, 1.1547819846895e+00,
282 1.3335214321633e+00, 1.5399265260595e+00,
283 1.7782794100389e+00, 2.0535250264571e+00,
284 2.3713737056617e+00, 2.7384196342644e+00,
285 3.1622776601684e+00, 3.6517412725484e+00,
286 4.2169650342858e+00, 4.8696752516586e+00,
287 5.6234132519035e+00, 6.4938163157621e+00,
288 7.4989420933246e+00, 8.6596432336007e+00,
289 1.0000000000000e+01, 1.1547819846895e+01,
290 1.3335214321633e+01, 1.5399265260595e+01,
291 1.7782794100389e+01, 2.0535250264571e+01,
292 2.3713737056617e+01, 2.7384196342644e+01,
293 3.1622776601684e+01, 3.6517412725484e+01,
294 4.2169650342858e+01, 4.8696752516586e+01,
295 5.6234132519035e+01, 6.4938163157621e+01,
296 7.4989420933246e+01, 8.6596432336007e+01,
297 1.0000000000000e+02, 1.1547819846895e+02,
298 1.3335214321633e+02, 1.5399265260595e+02,
299 1.7782794100389e+02, 2.0535250264571e+02,
300 2.3713737056617e+02, 2.7384196342644e+02,
301 3.1622776601684e+02, 3.6517412725484e+02,
302 4.2169650342858e+02, 4.8696752516586e+02,
303 5.6234132519035e+02, 6.4938163157621e+02,
304 7.4989420933246e+02, 8.6596432336007e+02,
305 1.0000000000000e+03, 1.1547819846895e+03,
306 1.3335214321633e+03, 1.5399265260595e+03,
307 1.7782794100389e+03, 2.0535250264571e+03,
308 2.3713737056617e+03, 2.7384196342644e+03,
309 3.1622776601684e+03, 3.6517412725484e+03,
310 4.2169650342858e+03, 4.8696752516586e+03,
311 5.6234132519035e+03, 6.4938163157621e+03,
312 7.4989420933246e+03, 8.6596432336007e+03,
313 1.0000000000000e+04, 1.1547819846895e+04,
314 1.3335214321633e+04, 1.5399265260595e+04,
315 1.7782794100389e+04, 2.0535250264571e+04,
316 2.3713737056617e+04, 2.7384196342644e+04,
317 3.1622776601684e+04, 3.6517412725484e+04,
318 4.2169650342858e+04, 4.8696752516586e+04,
319 5.6234132519035e+04, 6.4938163157621e+04,
320 7.4989420933246e+04, 8.6596432336007e+04,
321 1.0000000000000e+05, 1.1547819846895e+05,
322 1.3335214321633e+05, 1.5399265260595e+05,
323 1.7782794100389e+05, 2.0535250264571e+05,
324 2.3713737056617e+05, 2.7384196342644e+05,
325 3.1622776601684e+05, 3.6517412725484e+05,
326 4.2169650342858e+05, 4.8696752516586e+05,
327 5.6234132519035e+05, 6.4938163157621e+05,
328 7.4989420933246e+05, 8.6596432336007e+05,
329 };
330
331 /**
332 * decode exponents coded with VLC codes
333 */
334 1136 static int decode_exp_vlc(WMACodecContext *s, int ch)
335 {
336 int last_exp, n, code;
337 const uint16_t *ptr;
338 float v, max_scale;
339 uint32_t *q, *q_end, iv;
340 1136 const float *ptab = pow_tab + 60;
341 1136 const uint32_t *iptab = (const uint32_t *) ptab;
342
343 1136 ptr = s->exponent_bands[s->frame_len_bits - s->block_len_bits];
344 1136 q = (uint32_t *) s->exponents[ch];
345 1136 q_end = q + s->block_len;
346 1136 max_scale = 0;
347
2/2
✓ Branch 0 taken 410 times.
✓ Branch 1 taken 726 times.
1136 if (s->version == 1) {
348 410 last_exp = get_bits(&s->gb, 5) + 10;
349 410 v = ptab[last_exp];
350 410 iv = iptab[last_exp];
351 410 max_scale = v;
352 410 n = *ptr++;
353
1/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 410 times.
✗ Branch 4 not taken.
410 switch (n & 3) do {
354 820 case 0: *q++ = iv;
355 820 case 3: *q++ = iv;
356 820 case 2: *q++ = iv;
357 1230 case 1: *q++ = iv;
358
2/2
✓ Branch 0 taken 820 times.
✓ Branch 1 taken 410 times.
1230 } while ((n -= 4) > 0);
359 } else
360 726 last_exp = 36;
361
362
2/2
✓ Branch 0 taken 27990 times.
✓ Branch 1 taken 1136 times.
29126 while (q < q_end) {
363 27990 code = get_vlc2(&s->gb, s->exp_vlc.table, EXPVLCBITS, EXPMAX);
364 /* NOTE: this offset is the same as MPEG-4 AAC! */
365 27990 last_exp += code - 60;
366
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27990 times.
27990 if ((unsigned) last_exp + 60 >= FF_ARRAY_ELEMS(pow_tab)) {
367 av_log(s->avctx, AV_LOG_ERROR, "Exponent out of range: %d\n",
368 last_exp);
369 return -1;
370 }
371 27990 v = ptab[last_exp];
372 27990 iv = iptab[last_exp];
373
2/2
✓ Branch 0 taken 1141 times.
✓ Branch 1 taken 26849 times.
27990 if (v > max_scale)
374 1141 max_scale = v;
375 27990 n = *ptr++;
376
4/5
✓ Branch 0 taken 19380 times.
✓ Branch 1 taken 2460 times.
✓ Branch 2 taken 2460 times.
✓ Branch 3 taken 3690 times.
✗ Branch 4 not taken.
27990 switch (n & 3) do {
377 576712 case 0: *q++ = iv;
378 579172 case 3: *q++ = iv;
379 581632 case 2: *q++ = iv;
380 585322 case 1: *q++ = iv;
381
2/2
✓ Branch 0 taken 557332 times.
✓ Branch 1 taken 27990 times.
585322 } while ((n -= 4) > 0);
382 }
383 1136 s->max_exponent[ch] = max_scale;
384 1136 return 0;
385 }
386
387 /**
388 * Apply MDCT window and add into output.
389 *
390 * We ensure that when the windows overlap their squared sum
391 * is always 1 (MDCT reconstruction rule).
392 */
393 1172 static void wma_window(WMACodecContext *s, float *out)
394 {
395 1172 float *in = s->output;
396 int block_len, bsize, n;
397
398 /* left part */
399
1/2
✓ Branch 0 taken 1172 times.
✗ Branch 1 not taken.
1172 if (s->block_len_bits <= s->prev_block_len_bits) {
400 1172 block_len = s->block_len;
401 1172 bsize = s->frame_len_bits - s->block_len_bits;
402
403 1172 s->fdsp->vector_fmul_add(out, in, s->windows[bsize],
404 out, block_len);
405 } else {
406 block_len = 1 << s->prev_block_len_bits;
407 n = (s->block_len - block_len) / 2;
408 bsize = s->frame_len_bits - s->prev_block_len_bits;
409
410 s->fdsp->vector_fmul_add(out + n, in + n, s->windows[bsize],
411 out + n, block_len);
412
413 memcpy(out + n + block_len, in + n + block_len, n * sizeof(float));
414 }
415
416 1172 out += s->block_len;
417 1172 in += s->block_len;
418
419 /* right part */
420
1/2
✓ Branch 0 taken 1172 times.
✗ Branch 1 not taken.
1172 if (s->block_len_bits <= s->next_block_len_bits) {
421 1172 block_len = s->block_len;
422 1172 bsize = s->frame_len_bits - s->block_len_bits;
423
424 1172 s->fdsp->vector_fmul_reverse(out, in, s->windows[bsize], block_len);
425 } else {
426 block_len = 1 << s->next_block_len_bits;
427 n = (s->block_len - block_len) / 2;
428 bsize = s->frame_len_bits - s->next_block_len_bits;
429
430 memcpy(out, in, n * sizeof(float));
431
432 s->fdsp->vector_fmul_reverse(out + n, in + n, s->windows[bsize],
433 block_len);
434
435 memset(out + n + block_len, 0, n * sizeof(float));
436 }
437 1172 }
438
439 /**
440 * @return 0 if OK. 1 if last block of frame. return -1 if
441 * unrecoverable error.
442 */
443 586 static int wma_decode_block(WMACodecContext *s)
444 {
445 586 int channels = s->avctx->ch_layout.nb_channels;
446 int n, v, a, ch, bsize;
447 int coef_nb_bits, total_gain;
448 int nb_coefs[MAX_CHANNELS];
449 float mdct_norm;
450 FFTContext *mdct;
451
452 #ifdef TRACE
453 ff_tlog(s->avctx, "***decode_block: %d:%d\n",
454 s->frame_count - 1, s->block_num);
455 #endif /* TRACE */
456
457 /* compute current block length */
458
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 586 times.
586 if (s->use_variable_block_len) {
459 n = av_log2(s->nb_block_sizes - 1) + 1;
460
461 if (s->reset_block_lengths) {
462 s->reset_block_lengths = 0;
463 v = get_bits(&s->gb, n);
464 if (v >= s->nb_block_sizes) {
465 av_log(s->avctx, AV_LOG_ERROR,
466 "prev_block_len_bits %d out of range\n",
467 s->frame_len_bits - v);
468 return -1;
469 }
470 s->prev_block_len_bits = s->frame_len_bits - v;
471 v = get_bits(&s->gb, n);
472 if (v >= s->nb_block_sizes) {
473 av_log(s->avctx, AV_LOG_ERROR,
474 "block_len_bits %d out of range\n",
475 s->frame_len_bits - v);
476 return -1;
477 }
478 s->block_len_bits = s->frame_len_bits - v;
479 } else {
480 /* update block lengths */
481 s->prev_block_len_bits = s->block_len_bits;
482 s->block_len_bits = s->next_block_len_bits;
483 }
484 v = get_bits(&s->gb, n);
485 if (v >= s->nb_block_sizes) {
486 av_log(s->avctx, AV_LOG_ERROR,
487 "next_block_len_bits %d out of range\n",
488 s->frame_len_bits - v);
489 return -1;
490 }
491 s->next_block_len_bits = s->frame_len_bits - v;
492 } else {
493 /* fixed block len */
494 586 s->next_block_len_bits = s->frame_len_bits;
495 586 s->prev_block_len_bits = s->frame_len_bits;
496 586 s->block_len_bits = s->frame_len_bits;
497 }
498
499
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 586 times.
586 if (s->frame_len_bits - s->block_len_bits >= s->nb_block_sizes){
500 av_log(s->avctx, AV_LOG_ERROR, "block_len_bits not initialized to a valid value\n");
501 return -1;
502 }
503
504 /* now check if the block length is coherent with the frame length */
505 586 s->block_len = 1 << s->block_len_bits;
506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 586 times.
586 if ((s->block_pos + s->block_len) > s->frame_len) {
507 av_log(s->avctx, AV_LOG_ERROR, "frame_len overflow\n");
508 return -1;
509 }
510
511
1/2
✓ Branch 0 taken 586 times.
✗ Branch 1 not taken.
586 if (channels == 2)
512 586 s->ms_stereo = get_bits1(&s->gb);
513 586 v = 0;
514
2/2
✓ Branch 0 taken 1172 times.
✓ Branch 1 taken 586 times.
1758 for (ch = 0; ch < channels; ch++) {
515 1172 a = get_bits1(&s->gb);
516 1172 s->channel_coded[ch] = a;
517 1172 v |= a;
518 }
519
520 586 bsize = s->frame_len_bits - s->block_len_bits;
521
522 /* if no channel coded, no need to go further */
523 /* XXX: fix potential framing problems */
524
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 586 times.
586 if (!v)
525 goto next;
526
527 /* read total gain and extract corresponding number of bits for
528 * coef escape coding */
529 586 total_gain = 1;
530 for (;;) {
531
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 586 times.
586 if (get_bits_left(&s->gb) < 7) {
532 av_log(s->avctx, AV_LOG_ERROR, "total_gain overread\n");
533 return AVERROR_INVALIDDATA;
534 }
535 586 a = get_bits(&s->gb, 7);
536 586 total_gain += a;
537
1/2
✓ Branch 0 taken 586 times.
✗ Branch 1 not taken.
586 if (a != 127)
538 586 break;
539 }
540
541 586 coef_nb_bits = ff_wma_total_gain_to_bits(total_gain);
542
543 /* compute number of coefficients */
544 586 n = s->coefs_end[bsize] - s->coefs_start;
545
2/2
✓ Branch 0 taken 1172 times.
✓ Branch 1 taken 586 times.
1758 for (ch = 0; ch < channels; ch++)
546 1172 nb_coefs[ch] = n;
547
548 /* complex coding */
549
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 586 times.
586 if (s->use_noise_coding) {
550 for (ch = 0; ch < channels; ch++) {
551 if (s->channel_coded[ch]) {
552 int i, n, a;
553 n = s->exponent_high_sizes[bsize];
554 for (i = 0; i < n; i++) {
555 a = get_bits1(&s->gb);
556 s->high_band_coded[ch][i] = a;
557 /* if noise coding, the coefficients are not transmitted */
558 if (a)
559 nb_coefs[ch] -= s->exponent_high_bands[bsize][i];
560 }
561 }
562 }
563 for (ch = 0; ch < channels; ch++) {
564 if (s->channel_coded[ch]) {
565 int i, n, val;
566
567 n = s->exponent_high_sizes[bsize];
568 val = (int) 0x80000000;
569 for (i = 0; i < n; i++) {
570 if (s->high_band_coded[ch][i]) {
571 if (val == (int) 0x80000000) {
572 val = get_bits(&s->gb, 7) - 19;
573 } else {
574 val += get_vlc2(&s->gb, s->hgain_vlc.table,
575 HGAINVLCBITS, HGAINMAX);
576 }
577 s->high_band_values[ch][i] = val;
578 }
579 }
580 }
581 }
582 }
583
584 /* exponents can be reused in short blocks. */
585
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 586 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
586 if ((s->block_len_bits == s->frame_len_bits) || get_bits1(&s->gb)) {
586
2/2
✓ Branch 0 taken 1172 times.
✓ Branch 1 taken 586 times.
1758 for (ch = 0; ch < channels; ch++) {
587
2/2
✓ Branch 0 taken 1136 times.
✓ Branch 1 taken 36 times.
1172 if (s->channel_coded[ch]) {
588
1/2
✓ Branch 0 taken 1136 times.
✗ Branch 1 not taken.
1136 if (s->use_exp_vlc) {
589
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1136 times.
1136 if (decode_exp_vlc(s, ch) < 0)
590 return -1;
591 } else {
592 decode_exp_lsp(s, ch);
593 }
594 1136 s->exponents_bsize[ch] = bsize;
595 1136 s->exponents_initialized[ch] = 1;
596 }
597 }
598 }
599
600
2/2
✓ Branch 0 taken 1172 times.
✓ Branch 1 taken 586 times.
1758 for (ch = 0; ch < channels; ch++) {
601
3/4
✓ Branch 0 taken 1136 times.
✓ Branch 1 taken 36 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1136 times.
1172 if (s->channel_coded[ch] && !s->exponents_initialized[ch])
602 return AVERROR_INVALIDDATA;
603 }
604
605 /* parse spectral coefficients : just RLE encoding */
606
2/2
✓ Branch 0 taken 1172 times.
✓ Branch 1 taken 586 times.
1758 for (ch = 0; ch < channels; ch++) {
607
2/2
✓ Branch 0 taken 1136 times.
✓ Branch 1 taken 36 times.
1172 if (s->channel_coded[ch]) {
608 int tindex;
609 1136 WMACoef *ptr = &s->coefs1[ch][0];
610 int ret;
611
612 /* special VLC tables are used for ms stereo because
613 * there is potentially less energy there */
614
4/4
✓ Branch 0 taken 550 times.
✓ Branch 1 taken 586 times.
✓ Branch 2 taken 480 times.
✓ Branch 3 taken 70 times.
1136 tindex = (ch == 1 && s->ms_stereo);
615 1136 memset(ptr, 0, s->block_len * sizeof(WMACoef));
616 1136 ret = ff_wma_run_level_decode(s->avctx, &s->gb, &s->coef_vlc[tindex],
617 1136 s->level_table[tindex], s->run_table[tindex],
618 0, ptr, 0, nb_coefs[ch],
619 s->block_len, s->frame_len_bits, coef_nb_bits);
620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1136 times.
1136 if (ret < 0)
621 return ret;
622 }
623
3/4
✓ Branch 0 taken 410 times.
✓ Branch 1 taken 762 times.
✓ Branch 2 taken 410 times.
✗ Branch 3 not taken.
1172 if (s->version == 1 && channels >= 2)
624 410 align_get_bits(&s->gb);
625 }
626
627 /* normalize */
628 {
629 586 int n4 = s->block_len / 2;
630 586 mdct_norm = 1.0 / (float) n4;
631
2/2
✓ Branch 0 taken 205 times.
✓ Branch 1 taken 381 times.
586 if (s->version == 1)
632 205 mdct_norm *= sqrt(n4);
633 }
634
635 /* finally compute the MDCT coefficients */
636
2/2
✓ Branch 0 taken 1172 times.
✓ Branch 1 taken 586 times.
1758 for (ch = 0; ch < channels; ch++) {
637
2/2
✓ Branch 0 taken 1136 times.
✓ Branch 1 taken 36 times.
1172 if (s->channel_coded[ch]) {
638 WMACoef *coefs1;
639 float *coefs, *exponents, mult, mult1, noise;
640 int i, j, n, n1, last_high_band, esize;
641 float exp_power[HIGH_BAND_MAX_SIZE];
642
643 1136 coefs1 = s->coefs1[ch];
644 1136 exponents = s->exponents[ch];
645 1136 esize = s->exponents_bsize[ch];
646 1136 mult = ff_exp10(total_gain * 0.05) / s->max_exponent[ch];
647 1136 mult *= mdct_norm;
648 1136 coefs = s->coefs[ch];
649
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1136 times.
1136 if (s->use_noise_coding) {
650 mult1 = mult;
651 /* very low freqs : noise */
652 for (i = 0; i < s->coefs_start; i++) {
653 *coefs++ = s->noise_table[s->noise_index] *
654 exponents[i << bsize >> esize] * mult1;
655 s->noise_index = (s->noise_index + 1) &
656 (NOISE_TAB_SIZE - 1);
657 }
658
659 n1 = s->exponent_high_sizes[bsize];
660
661 /* compute power of high bands */
662 exponents = s->exponents[ch] +
663 (s->high_band_start[bsize] << bsize >> esize);
664 last_high_band = 0; /* avoid warning */
665 for (j = 0; j < n1; j++) {
666 n = s->exponent_high_bands[s->frame_len_bits -
667 s->block_len_bits][j];
668 if (s->high_band_coded[ch][j]) {
669 float e2, v;
670 e2 = 0;
671 for (i = 0; i < n; i++) {
672 v = exponents[i << bsize >> esize];
673 e2 += v * v;
674 }
675 exp_power[j] = e2 / n;
676 last_high_band = j;
677 ff_tlog(s->avctx, "%d: power=%f (%d)\n", j, exp_power[j], n);
678 }
679 exponents += n << bsize >> esize;
680 }
681
682 /* main freqs and high freqs */
683 exponents = s->exponents[ch] + (s->coefs_start << bsize >> esize);
684 for (j = -1; j < n1; j++) {
685 if (j < 0)
686 n = s->high_band_start[bsize] - s->coefs_start;
687 else
688 n = s->exponent_high_bands[s->frame_len_bits -
689 s->block_len_bits][j];
690 if (j >= 0 && s->high_band_coded[ch][j]) {
691 /* use noise with specified power */
692 mult1 = sqrt(exp_power[j] / exp_power[last_high_band]);
693 /* XXX: use a table */
694 mult1 = mult1 * ff_exp10(s->high_band_values[ch][j] * 0.05);
695 mult1 = mult1 / (s->max_exponent[ch] * s->noise_mult);
696 mult1 *= mdct_norm;
697 for (i = 0; i < n; i++) {
698 noise = s->noise_table[s->noise_index];
699 s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
700 *coefs++ = noise * exponents[i << bsize >> esize] * mult1;
701 }
702 exponents += n << bsize >> esize;
703 } else {
704 /* coded values + small noise */
705 for (i = 0; i < n; i++) {
706 noise = s->noise_table[s->noise_index];
707 s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
708 *coefs++ = ((*coefs1++) + noise) *
709 exponents[i << bsize >> esize] * mult;
710 }
711 exponents += n << bsize >> esize;
712 }
713 }
714
715 /* very high freqs : noise */
716 n = s->block_len - s->coefs_end[bsize];
717 mult1 = mult * exponents[(-(1 << bsize)) >> esize];
718 for (i = 0; i < n; i++) {
719 *coefs++ = s->noise_table[s->noise_index] * mult1;
720 s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1);
721 }
722 } else {
723 /* XXX: optimize more */
724
2/2
✓ Branch 0 taken 1230 times.
✓ Branch 1 taken 1136 times.
2366 for (i = 0; i < s->coefs_start; i++)
725 1230 *coefs++ = 0.0;
726 1136 n = nb_coefs[ch];
727
2/2
✓ Branch 0 taken 2116274 times.
✓ Branch 1 taken 1136 times.
2117410 for (i = 0; i < n; i++)
728 2116274 *coefs++ = coefs1[i] * exponents[i << bsize >> esize] * mult;
729 1136 n = s->block_len - s->coefs_end[bsize];
730
2/2
✓ Branch 0 taken 209024 times.
✓ Branch 1 taken 1136 times.
210160 for (i = 0; i < n; i++)
731 209024 *coefs++ = 0.0;
732 }
733 }
734 }
735
736 #ifdef TRACE
737 for (ch = 0; ch < channels; ch++) {
738 if (s->channel_coded[ch]) {
739 dump_floats(s, "exponents", 3, s->exponents[ch], s->block_len);
740 dump_floats(s, "coefs", 1, s->coefs[ch], s->block_len);
741 }
742 }
743 #endif /* TRACE */
744
745
4/4
✓ Branch 0 taken 105 times.
✓ Branch 1 taken 481 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 480 times.
586 if (s->ms_stereo && s->channel_coded[1]) {
746 /* nominal case for ms stereo: we do it before mdct */
747 /* no need to optimize this case because it should almost
748 * never happen */
749
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 480 times.
480 if (!s->channel_coded[0]) {
750 ff_tlog(s->avctx, "rare ms-stereo case happened\n");
751 memset(s->coefs[0], 0, sizeof(float) * s->block_len);
752 s->channel_coded[0] = 1;
753 }
754
755 480 s->fdsp->butterflies_float(s->coefs[0], s->coefs[1], s->block_len);
756 }
757
758 106 next:
759 586 mdct = &s->mdct_ctx[bsize];
760
761
2/2
✓ Branch 0 taken 1172 times.
✓ Branch 1 taken 586 times.
1758 for (ch = 0; ch < channels; ch++) {
762 int n4, index;
763
764 1172 n4 = s->block_len / 2;
765
2/2
✓ Branch 0 taken 1136 times.
✓ Branch 1 taken 36 times.
1172 if (s->channel_coded[ch])
766 1136 mdct->imdct_calc(mdct, s->output, s->coefs[ch]);
767
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
36 else if (!(s->ms_stereo && ch == 1))
768 35 memset(s->output, 0, sizeof(s->output));
769
770 /* multiply by the window and add in the frame */
771 1172 index = (s->frame_len / 2) + s->block_pos - n4;
772 1172 wma_window(s, &s->frame_out[ch][index]);
773 }
774
775 /* update block number */
776 586 s->block_num++;
777 586 s->block_pos += s->block_len;
778
1/2
✓ Branch 0 taken 586 times.
✗ Branch 1 not taken.
586 if (s->block_pos >= s->frame_len)
779 586 return 1;
780 else
781 return 0;
782 }
783
784 /* decode a frame of frame_len samples */
785 586 static int wma_decode_frame(WMACodecContext *s, float **samples,
786 int samples_offset)
787 {
788 int ret, ch;
789
790 #ifdef TRACE
791 ff_tlog(s->avctx, "***decode_frame: %d size=%d\n",
792 s->frame_count++, s->frame_len);
793 #endif /* TRACE */
794
795 /* read each block */
796 586 s->block_num = 0;
797 586 s->block_pos = 0;
798 for (;;) {
799 586 ret = wma_decode_block(s);
800
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 586 times.
586 if (ret < 0)
801 return -1;
802
1/2
✓ Branch 0 taken 586 times.
✗ Branch 1 not taken.
586 if (ret)
803 586 break;
804 }
805
806
2/2
✓ Branch 0 taken 1172 times.
✓ Branch 1 taken 586 times.
1758 for (ch = 0; ch < s->avctx->ch_layout.nb_channels; ch++) {
807 /* copy current block to output */
808 1172 memcpy(samples[ch] + samples_offset, s->frame_out[ch],
809 1172 s->frame_len * sizeof(*s->frame_out[ch]));
810 /* prepare for next block */
811 1172 memmove(&s->frame_out[ch][0], &s->frame_out[ch][s->frame_len],
812 1172 s->frame_len * sizeof(*s->frame_out[ch]));
813
814 #ifdef TRACE
815 dump_floats(s, "samples", 6, samples[ch] + samples_offset,
816 s->frame_len);
817 #endif /* TRACE */
818 }
819
820 586 return 0;
821 }
822
823 593 static int wma_decode_superframe(AVCodecContext *avctx, AVFrame *frame,
824 int *got_frame_ptr, AVPacket *avpkt)
825 {
826 593 const uint8_t *buf = avpkt->data;
827 593 int buf_size = avpkt->size;
828 593 WMACodecContext *s = avctx->priv_data;
829 int nb_frames, bit_offset, i, pos, len, ret;
830 uint8_t *q;
831 float **samples;
832 int samples_offset;
833
834 ff_tlog(avctx, "***decode_superframe:\n");
835
836
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 587 times.
593 if (buf_size == 0) {
837
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (s->eof_done)
838 3 return 0;
839
840 3 frame->nb_samples = s->frame_len;
841
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
3 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
842 return ret;
843
844
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 for (i = 0; i < s->avctx->ch_layout.nb_channels; i++)
845 6 memcpy(frame->extended_data[i], &s->frame_out[i][0],
846 6 frame->nb_samples * sizeof(s->frame_out[i][0]));
847
848 3 s->last_superframe_len = 0;
849 3 s->eof_done = 1;
850 3 *got_frame_ptr = 1;
851 3 return 0;
852 }
853
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 586 times.
587 if (buf_size < avctx->block_align) {
854 1 av_log(avctx, AV_LOG_ERROR,
855 "Input packet size too small (%d < %d)\n",
856 buf_size, avctx->block_align);
857 1 return AVERROR_INVALIDDATA;
858 }
859
1/2
✓ Branch 0 taken 586 times.
✗ Branch 1 not taken.
586 if (avctx->block_align)
860 586 buf_size = avctx->block_align;
861
862 586 init_get_bits(&s->gb, buf, buf_size * 8);
863
864
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 586 times.
586 if (s->use_bit_reservoir) {
865 /* read super frame header */
866 skip_bits(&s->gb, 4); /* super frame index */
867 nb_frames = get_bits(&s->gb, 4) - (s->last_superframe_len <= 0);
868 if (nb_frames <= 0) {
869 int is_error = nb_frames < 0 || get_bits_left(&s->gb) <= 8;
870 av_log(avctx, is_error ? AV_LOG_ERROR : AV_LOG_WARNING,
871 "nb_frames is %d bits left %d\n",
872 nb_frames, get_bits_left(&s->gb));
873 if (is_error)
874 return AVERROR_INVALIDDATA;
875
876 if ((s->last_superframe_len + buf_size - 1) >
877 MAX_CODED_SUPERFRAME_SIZE)
878 goto fail;
879
880 q = s->last_superframe + s->last_superframe_len;
881 len = buf_size - 1;
882 while (len > 0) {
883 *q++ = get_bits (&s->gb, 8);
884 len --;
885 }
886 memset(q, 0, AV_INPUT_BUFFER_PADDING_SIZE);
887
888 s->last_superframe_len += 8*buf_size - 8;
889 // s->reset_block_lengths = 1; //XXX is this needed ?
890 *got_frame_ptr = 0;
891 return buf_size;
892 }
893 } else
894 586 nb_frames = 1;
895
896 /* get output buffer */
897 586 frame->nb_samples = nb_frames * s->frame_len;
898
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 586 times.
586 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
899 return ret;
900 586 samples = (float **) frame->extended_data;
901 586 samples_offset = 0;
902
903
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 586 times.
586 if (s->use_bit_reservoir) {
904 bit_offset = get_bits(&s->gb, s->byte_offset_bits + 3);
905 if (bit_offset > get_bits_left(&s->gb)) {
906 av_log(avctx, AV_LOG_ERROR,
907 "Invalid last frame bit offset %d > buf size %d (%d)\n",
908 bit_offset, get_bits_left(&s->gb), buf_size);
909 goto fail;
910 }
911
912 if (s->last_superframe_len > 0) {
913 /* add bit_offset bits to last frame */
914 if ((s->last_superframe_len + ((bit_offset + 7) >> 3)) >
915 MAX_CODED_SUPERFRAME_SIZE)
916 goto fail;
917 q = s->last_superframe + s->last_superframe_len;
918 len = bit_offset;
919 while (len > 7) {
920 *q++ = get_bits(&s->gb, 8);
921 len -= 8;
922 }
923 if (len > 0)
924 *q++ = get_bits(&s->gb, len) << (8 - len);
925 memset(q, 0, AV_INPUT_BUFFER_PADDING_SIZE);
926
927 /* XXX: bit_offset bits into last frame */
928 init_get_bits(&s->gb, s->last_superframe,
929 s->last_superframe_len * 8 + bit_offset);
930 /* skip unused bits */
931 if (s->last_bitoffset > 0)
932 skip_bits(&s->gb, s->last_bitoffset);
933 /* this frame is stored in the last superframe and in the
934 * current one */
935 if (wma_decode_frame(s, samples, samples_offset) < 0)
936 goto fail;
937 samples_offset += s->frame_len;
938 nb_frames--;
939 }
940
941 /* read each frame starting from bit_offset */
942 pos = bit_offset + 4 + 4 + s->byte_offset_bits + 3;
943 if (pos >= MAX_CODED_SUPERFRAME_SIZE * 8 || pos > buf_size * 8)
944 return AVERROR_INVALIDDATA;
945 init_get_bits(&s->gb, buf + (pos >> 3), (buf_size - (pos >> 3)) * 8);
946 len = pos & 7;
947 if (len > 0)
948 skip_bits(&s->gb, len);
949
950 s->reset_block_lengths = 1;
951 for (i = 0; i < nb_frames; i++) {
952 if (wma_decode_frame(s, samples, samples_offset) < 0)
953 goto fail;
954 samples_offset += s->frame_len;
955 }
956
957 /* we copy the end of the frame in the last frame buffer */
958 pos = get_bits_count(&s->gb) +
959 ((bit_offset + 4 + 4 + s->byte_offset_bits + 3) & ~7);
960 s->last_bitoffset = pos & 7;
961 pos >>= 3;
962 len = buf_size - pos;
963 if (len > MAX_CODED_SUPERFRAME_SIZE || len < 0) {
964 av_log(s->avctx, AV_LOG_ERROR, "len %d invalid\n", len);
965 goto fail;
966 }
967 s->last_superframe_len = len;
968 memcpy(s->last_superframe, buf + pos, len);
969 } else {
970 /* single frame decode */
971
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 586 times.
586 if (wma_decode_frame(s, samples, samples_offset) < 0)
972 goto fail;
973 586 samples_offset += s->frame_len;
974 }
975
976 ff_dlog(s->avctx, "%d %d %d %d eaten:%d\n",
977 s->frame_len_bits, s->block_len_bits, s->frame_len, s->block_len,
978 avctx->block_align);
979
980 586 *got_frame_ptr = 1;
981
982 586 return buf_size;
983
984 fail:
985 /* when error, we reset the bit reservoir */
986 s->last_superframe_len = 0;
987 return -1;
988 }
989
990 1 static av_cold void flush(AVCodecContext *avctx)
991 {
992 1 WMACodecContext *s = avctx->priv_data;
993
994 1 s->last_bitoffset =
995 1 s->last_superframe_len = 0;
996
997 1 s->eof_done = 0;
998 1 avctx->internal->skip_samples = s->frame_len * 2;
999 1 }
1000
1001 #if CONFIG_WMAV1_DECODER
1002 const FFCodec ff_wmav1_decoder = {
1003 .p.name = "wmav1",
1004 .p.long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 1"),
1005 .p.type = AVMEDIA_TYPE_AUDIO,
1006 .p.id = AV_CODEC_ID_WMAV1,
1007 .priv_data_size = sizeof(WMACodecContext),
1008 .init = wma_decode_init,
1009 .close = ff_wma_end,
1010 FF_CODEC_DECODE_CB(wma_decode_superframe),
1011 .flush = flush,
1012 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
1013 .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1014 AV_SAMPLE_FMT_NONE },
1015 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
1016 };
1017 #endif
1018 #if CONFIG_WMAV2_DECODER
1019 const FFCodec ff_wmav2_decoder = {
1020 .p.name = "wmav2",
1021 .p.long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 2"),
1022 .p.type = AVMEDIA_TYPE_AUDIO,
1023 .p.id = AV_CODEC_ID_WMAV2,
1024 .priv_data_size = sizeof(WMACodecContext),
1025 .init = wma_decode_init,
1026 .close = ff_wma_end,
1027 FF_CODEC_DECODE_CB(wma_decode_superframe),
1028 .flush = flush,
1029 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
1030 .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1031 AV_SAMPLE_FMT_NONE },
1032 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
1033 };
1034 #endif
1035