FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/on2avc.c
Date: 2022-07-05 19:52:29
Exec Total Coverage
Lines: 197 587 33.6%
Branches: 82 204 40.2%

Line Branch Exec Source
1 /*
2 * On2 Audio for Video Codec decoder
3 *
4 * Copyright (c) 2013 Konstantin Shishkov
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg 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 * FFmpeg 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 FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "libavutil/channel_layout.h"
24 #include "libavutil/ffmath.h"
25 #include "libavutil/float_dsp.h"
26 #include "libavutil/mem_internal.h"
27
28 #include "avcodec.h"
29 #include "bytestream.h"
30 #include "codec_internal.h"
31 #include "fft.h"
32 #include "get_bits.h"
33 #include "internal.h"
34
35 #include "on2avcdata.h"
36
37 #define ON2AVC_SUBFRAME_SIZE 1024
38
39 enum WindowTypes {
40 WINDOW_TYPE_LONG = 0,
41 WINDOW_TYPE_LONG_STOP,
42 WINDOW_TYPE_LONG_START,
43 WINDOW_TYPE_8SHORT = 3,
44 WINDOW_TYPE_EXT4,
45 WINDOW_TYPE_EXT5,
46 WINDOW_TYPE_EXT6,
47 WINDOW_TYPE_EXT7,
48 };
49
50 typedef struct On2AVCContext {
51 AVCodecContext *avctx;
52 AVFloatDSPContext *fdsp;
53 FFTContext mdct, mdct_half, mdct_small;
54 FFTContext fft128, fft256, fft512, fft1024;
55 void (*wtf)(struct On2AVCContext *ctx, float *out, float *in, int size);
56
57 int is_av500;
58
59 const On2AVCMode *modes;
60 int window_type, prev_window_type;
61 int num_windows, num_bands;
62 int bits_per_section;
63 const int *band_start;
64
65 int grouping[8];
66 int ms_present;
67 int ms_info[ON2AVC_MAX_BANDS];
68
69 int is_long;
70
71 uint8_t band_type[ON2AVC_MAX_BANDS];
72 uint8_t band_run_end[ON2AVC_MAX_BANDS];
73 int num_sections;
74
75 float band_scales[ON2AVC_MAX_BANDS];
76
77 VLC scale_diff;
78 VLC cb_vlc[16];
79
80 float scale_tab[128];
81
82 DECLARE_ALIGNED(32, float, coeffs)[2][ON2AVC_SUBFRAME_SIZE];
83 DECLARE_ALIGNED(32, float, delay) [2][ON2AVC_SUBFRAME_SIZE];
84
85 DECLARE_ALIGNED(32, float, temp) [ON2AVC_SUBFRAME_SIZE * 2];
86 DECLARE_ALIGNED(32, float, mdct_buf) [ON2AVC_SUBFRAME_SIZE];
87 DECLARE_ALIGNED(32, float, long_win) [ON2AVC_SUBFRAME_SIZE];
88 DECLARE_ALIGNED(32, float, short_win)[ON2AVC_SUBFRAME_SIZE / 8];
89 } On2AVCContext;
90
91 30 static void on2avc_read_ms_info(On2AVCContext *c, GetBitContext *gb)
92 {
93 30 int w, b, band_off = 0;
94
95 30 c->ms_present = get_bits1(gb);
96
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if (!c->ms_present)
97 30 return;
98 for (w = 0; w < c->num_windows; w++) {
99 if (!c->grouping[w]) {
100 memcpy(c->ms_info + band_off,
101 c->ms_info + band_off - c->num_bands,
102 c->num_bands * sizeof(*c->ms_info));
103 band_off += c->num_bands;
104 continue;
105 }
106 for (b = 0; b < c->num_bands; b++)
107 c->ms_info[band_off++] = get_bits1(gb);
108 }
109 }
110
111 // do not see Table 17 in ISO/IEC 13818-7
112 30 static int on2avc_decode_band_types(On2AVCContext *c, GetBitContext *gb)
113 {
114
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 int bits_per_sect = c->is_long ? 5 : 3;
115 30 int esc_val = (1 << bits_per_sect) - 1;
116 30 int num_bands = c->num_bands * c->num_windows;
117 30 int band = 0, i, band_type, run_len, run;
118
119
2/2
✓ Branch 0 taken 225 times.
✓ Branch 1 taken 30 times.
255 while (band < num_bands) {
120 225 band_type = get_bits(gb, 4);
121 225 run_len = 1;
122 do {
123 225 run = get_bits(gb, bits_per_sect);
124
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 225 times.
225 if (run > num_bands - band - run_len) {
125 av_log(c->avctx, AV_LOG_ERROR, "Invalid band type run\n");
126 return AVERROR_INVALIDDATA;
127 }
128 225 run_len += run;
129
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 225 times.
225 } while (run == esc_val);
130
2/2
✓ Branch 0 taken 1470 times.
✓ Branch 1 taken 225 times.
1695 for (i = band; i < band + run_len; i++) {
131 1470 c->band_type[i] = band_type;
132 1470 c->band_run_end[i] = band + run_len;
133 }
134 225 band += run_len;
135 }
136
137 30 return 0;
138 }
139
140 // completely not like Table 18 in ISO/IEC 13818-7
141 // (no intensity stereo, different coding for the first coefficient)
142 30 static int on2avc_decode_band_scales(On2AVCContext *c, GetBitContext *gb)
143 {
144 30 int w, w2, b, scale, first = 1;
145 30 int band_off = 0;
146
147
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 30 times.
60 for (w = 0; w < c->num_windows; w++) {
148
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if (!c->grouping[w]) {
149 memcpy(c->band_scales + band_off,
150 c->band_scales + band_off - c->num_bands,
151 c->num_bands * sizeof(*c->band_scales));
152 band_off += c->num_bands;
153 continue;
154 }
155
2/2
✓ Branch 0 taken 1470 times.
✓ Branch 1 taken 30 times.
1500 for (b = 0; b < c->num_bands; b++) {
156
2/2
✓ Branch 0 taken 211 times.
✓ Branch 1 taken 1259 times.
1470 if (!c->band_type[band_off]) {
157 211 int all_zero = 1;
158
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 211 times.
211 for (w2 = w + 1; w2 < c->num_windows; w2++) {
159 if (c->grouping[w2])
160 break;
161 if (c->band_type[w2 * c->num_bands + b]) {
162 all_zero = 0;
163 break;
164 }
165 }
166
1/2
✓ Branch 0 taken 211 times.
✗ Branch 1 not taken.
211 if (all_zero) {
167 211 c->band_scales[band_off++] = 0;
168 211 continue;
169 }
170 }
171
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 1229 times.
1259 if (first) {
172 30 scale = get_bits(gb, 7);
173 30 first = 0;
174 } else {
175 1229 scale += get_vlc2(gb, c->scale_diff.table, 9, 3);
176 }
177
2/4
✓ Branch 0 taken 1259 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1259 times.
1259 if (scale < 0 || scale > 127) {
178 av_log(c->avctx, AV_LOG_ERROR, "Invalid scale value %d\n",
179 scale);
180 return AVERROR_INVALIDDATA;
181 }
182 1259 c->band_scales[band_off++] = c->scale_tab[scale];
183 }
184 }
185
186 30 return 0;
187 }
188
189 20628 static inline float on2avc_scale(int v, float scale)
190 {
191 20628 return v * sqrtf(abs(v)) * scale;
192 }
193
194 // spectral data is coded completely differently - there are no unsigned codebooks
195 1249 static int on2avc_decode_quads(On2AVCContext *c, GetBitContext *gb, float *dst,
196 int dst_size, int type, float band_scale)
197 {
198 int i, j, val, val1;
199
200
2/2
✓ Branch 0 taken 5147 times.
✓ Branch 1 taken 1249 times.
6396 for (i = 0; i < dst_size; i += 4) {
201 5147 val = get_vlc2(gb, c->cb_vlc[type].table, 9, 2);
202
203
2/2
✓ Branch 0 taken 20588 times.
✓ Branch 1 taken 5147 times.
25735 for (j = 0; j < 4; j++) {
204 20588 val1 = sign_extend((val >> (12 - j * 4)) & 0xF, 4);
205 20588 *dst++ = on2avc_scale(val1, band_scale);
206 }
207 }
208
209 1249 return 0;
210 }
211
212 2 static inline int get_egolomb(GetBitContext *gb)
213 {
214 2 int v = 4;
215
216
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
3 while (get_bits1(gb)) {
217 1 v++;
218
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (v > 30) {
219 av_log(NULL, AV_LOG_WARNING, "Too large golomb code in get_egolomb.\n");
220 v = 30;
221 break;
222 }
223 }
224
225 2 return (1 << v) + get_bits_long(gb, v);
226 }
227
228 10 static int on2avc_decode_pairs(On2AVCContext *c, GetBitContext *gb, float *dst,
229 int dst_size, int type, float band_scale)
230 {
231 int i, val, val1, val2, sign;
232
233
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 10 times.
30 for (i = 0; i < dst_size; i += 2) {
234 20 val = get_vlc2(gb, c->cb_vlc[type].table, 9, 2);
235
236 20 val1 = sign_extend(val >> 8, 8);
237 20 val2 = sign_extend(val & 0xFF, 8);
238
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 14 times.
20 if (type == ON2AVC_ESC_CB) {
239
3/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 5 times.
6 if (val1 <= -16 || val1 >= 16) {
240 1 sign = 1 - (val1 < 0) * 2;
241 1 val1 = sign * get_egolomb(gb);
242 }
243
3/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 5 times.
6 if (val2 <= -16 || val2 >= 16) {
244 1 sign = 1 - (val2 < 0) * 2;
245 1 val2 = sign * get_egolomb(gb);
246 }
247 }
248
249 20 *dst++ = on2avc_scale(val1, band_scale);
250 20 *dst++ = on2avc_scale(val2, band_scale);
251 }
252
253 10 return 0;
254 }
255
256 30 static int on2avc_read_channel_data(On2AVCContext *c, GetBitContext *gb, int ch)
257 {
258 int ret;
259 int w, b, band_idx;
260 float *coeff_ptr;
261
262
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
30 if ((ret = on2avc_decode_band_types(c, gb)) < 0)
263 return ret;
264
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
30 if ((ret = on2avc_decode_band_scales(c, gb)) < 0)
265 return ret;
266
267 30 coeff_ptr = c->coeffs[ch];
268 30 band_idx = 0;
269 30 memset(coeff_ptr, 0, ON2AVC_SUBFRAME_SIZE * sizeof(*coeff_ptr));
270
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 30 times.
60 for (w = 0; w < c->num_windows; w++) {
271
2/2
✓ Branch 0 taken 1470 times.
✓ Branch 1 taken 30 times.
1500 for (b = 0; b < c->num_bands; b++) {
272 1470 int band_size = c->band_start[b + 1] - c->band_start[b];
273 1470 int band_type = c->band_type[band_idx + b];
274
275
2/2
✓ Branch 0 taken 211 times.
✓ Branch 1 taken 1259 times.
1470 if (!band_type) {
276 211 coeff_ptr += band_size;
277 211 continue;
278 }
279
2/2
✓ Branch 0 taken 1249 times.
✓ Branch 1 taken 10 times.
1259 if (band_type < 9)
280 1249 on2avc_decode_quads(c, gb, coeff_ptr, band_size, band_type,
281 1249 c->band_scales[band_idx + b]);
282 else
283 10 on2avc_decode_pairs(c, gb, coeff_ptr, band_size, band_type,
284 10 c->band_scales[band_idx + b]);
285 1259 coeff_ptr += band_size;
286 }
287 30 band_idx += c->num_bands;
288 }
289
290 30 return 0;
291 }
292
293 static int on2avc_apply_ms(On2AVCContext *c)
294 {
295 int w, b, i;
296 int band_off = 0;
297 float *ch0 = c->coeffs[0];
298 float *ch1 = c->coeffs[1];
299
300 for (w = 0; w < c->num_windows; w++) {
301 for (b = 0; b < c->num_bands; b++) {
302 if (c->ms_info[band_off + b]) {
303 for (i = c->band_start[b]; i < c->band_start[b + 1]; i++) {
304 float l = *ch0, r = *ch1;
305 *ch0++ = l + r;
306 *ch1++ = l - r;
307 }
308 } else {
309 ch0 += c->band_start[b + 1] - c->band_start[b];
310 ch1 += c->band_start[b + 1] - c->band_start[b];
311 }
312 }
313 band_off += c->num_bands;
314 }
315 return 0;
316 }
317
318 static void zero_head_and_tail(float *src, int len, int order0, int order1)
319 {
320 memset(src, 0, sizeof(*src) * order0);
321 memset(src + len - order1, 0, sizeof(*src) * order1);
322 }
323
324 static void pretwiddle(float *src, float *dst, int dst_len, int tab_step,
325 int step, int order0, int order1, const double * const *tabs)
326 {
327 float *src2, *out;
328 const double *tab;
329 int i, j;
330
331 out = dst;
332 tab = tabs[0];
333 for (i = 0; i < tab_step; i++) {
334 double sum = 0;
335 for (j = 0; j < order0; j++)
336 sum += src[j] * tab[j * tab_step + i];
337 out[i] += sum;
338 }
339
340 out = dst + dst_len - tab_step;
341 tab = tabs[order0];
342 src2 = src + (dst_len - tab_step) / step + 1 + order0;
343 for (i = 0; i < tab_step; i++) {
344 double sum = 0;
345 for (j = 0; j < order1; j++)
346 sum += src2[j] * tab[j * tab_step + i];
347 out[i] += sum;
348 }
349 }
350
351 static void twiddle(float *src1, float *src2, int src2_len,
352 const double *tab, int tab_len, int step,
353 int order0, int order1, const double * const *tabs)
354 {
355 int steps;
356 int mask;
357 int i, j;
358
359 steps = (src2_len - tab_len) / step + 1;
360 pretwiddle(src1, src2, src2_len, tab_len, step, order0, order1, tabs);
361 mask = tab_len - 1;
362
363 for (i = 0; i < steps; i++) {
364 float in0 = src1[order0 + i];
365 int pos = (src2_len - 1) & mask;
366
367 if (pos < tab_len) {
368 const double *t = tab;
369 for (j = pos; j >= 0; j--)
370 src2[j] += in0 * *t++;
371 for (j = 0; j < tab_len - pos - 1; j++)
372 src2[src2_len - j - 1] += in0 * tab[pos + 1 + j];
373 } else {
374 for (j = 0; j < tab_len; j++)
375 src2[pos - j] += in0 * tab[j];
376 }
377 mask = pos + step;
378 }
379 }
380
381 #define CMUL1_R(s, t, is, it) \
382 s[is + 0] * t[it + 0] - s[is + 1] * t[it + 1]
383 #define CMUL1_I(s, t, is, it) \
384 s[is + 0] * t[it + 1] + s[is + 1] * t[it + 0]
385 #define CMUL2_R(s, t, is, it) \
386 s[is + 0] * t[it + 0] + s[is + 1] * t[it + 1]
387 #define CMUL2_I(s, t, is, it) \
388 s[is + 0] * t[it + 1] - s[is + 1] * t[it + 0]
389
390 #define CMUL0(dst, id, s0, s1, s2, s3, t0, t1, t2, t3, is, it) \
391 dst[id] = s0[is] * t0[it] + s1[is] * t1[it] \
392 + s2[is] * t2[it] + s3[is] * t3[it]; \
393 dst[id + 1] = s0[is] * t0[it + 1] + s1[is] * t1[it + 1] \
394 + s2[is] * t2[it + 1] + s3[is] * t3[it + 1];
395
396 #define CMUL1(dst, s0, s1, s2, s3, t0, t1, t2, t3, is, it) \
397 *dst++ = CMUL1_R(s0, t0, is, it) \
398 + CMUL1_R(s1, t1, is, it) \
399 + CMUL1_R(s2, t2, is, it) \
400 + CMUL1_R(s3, t3, is, it); \
401 *dst++ = CMUL1_I(s0, t0, is, it) \
402 + CMUL1_I(s1, t1, is, it) \
403 + CMUL1_I(s2, t2, is, it) \
404 + CMUL1_I(s3, t3, is, it);
405
406 #define CMUL2(dst, s0, s1, s2, s3, t0, t1, t2, t3, is, it) \
407 *dst++ = CMUL2_R(s0, t0, is, it) \
408 + CMUL2_R(s1, t1, is, it) \
409 + CMUL2_R(s2, t2, is, it) \
410 + CMUL2_R(s3, t3, is, it); \
411 *dst++ = CMUL2_I(s0, t0, is, it) \
412 + CMUL2_I(s1, t1, is, it) \
413 + CMUL2_I(s2, t2, is, it) \
414 + CMUL2_I(s3, t3, is, it);
415
416 static void combine_fft(float *s0, float *s1, float *s2, float *s3, float *dst,
417 const float *t0, const float *t1,
418 const float *t2, const float *t3, int len, int step)
419 {
420 const float *h0, *h1, *h2, *h3;
421 float *d1, *d2;
422 int tmp, half;
423 int len2 = len >> 1, len4 = len >> 2;
424 int hoff;
425 int i, j, k;
426
427 tmp = step;
428 for (half = len2; tmp > 1; half <<= 1, tmp >>= 1);
429
430 h0 = t0 + half;
431 h1 = t1 + half;
432 h2 = t2 + half;
433 h3 = t3 + half;
434
435 CMUL0(dst, 0, s0, s1, s2, s3, t0, t1, t2, t3, 0, 0);
436
437 hoff = 2 * step * (len4 >> 1);
438
439 j = 2;
440 k = 2 * step;
441 d1 = dst + 2;
442 d2 = dst + 2 + (len >> 1);
443 for (i = 0; i < (len4 - 1) >> 1; i++) {
444 CMUL1(d1, s0, s1, s2, s3, t0, t1, t2, t3, j, k);
445 CMUL1(d2, s0, s1, s2, s3, h0, h1, h2, h3, j, k);
446 j += 2;
447 k += 2 * step;
448 }
449 CMUL0(dst, len4, s0, s1, s2, s3, t0, t1, t2, t3, 1, hoff);
450 CMUL0(dst, len4 + len2, s0, s1, s2, s3, h0, h1, h2, h3, 1, hoff);
451
452 j = len4;
453 k = hoff + 2 * step * len4;
454 d1 = dst + len4 + 2;
455 d2 = dst + len4 + 2 + len2;
456 for (i = 0; i < (len4 - 2) >> 1; i++) {
457 CMUL2(d1, s0, s1, s2, s3, t0, t1, t2, t3, j, k);
458 CMUL2(d2, s0, s1, s2, s3, h0, h1, h2, h3, j, k);
459 j -= 2;
460 k += 2 * step;
461 }
462 CMUL0(dst, len2 + 4, s0, s1, s2, s3, t0, t1, t2, t3, 0, k);
463 }
464
465 static void wtf_end_512(On2AVCContext *c, float *out, float *src,
466 float *tmp0, float *tmp1)
467 {
468 memcpy(src, tmp0, 384 * sizeof(*tmp0));
469 memcpy(tmp0 + 384, src + 384, 128 * sizeof(*tmp0));
470
471 zero_head_and_tail(src, 128, 16, 4);
472 zero_head_and_tail(src + 128, 128, 16, 4);
473 zero_head_and_tail(src + 256, 128, 13, 7);
474 zero_head_and_tail(src + 384, 128, 15, 5);
475
476 c->fft128.fft_permute(&c->fft128, (FFTComplex*)src);
477 c->fft128.fft_permute(&c->fft128, (FFTComplex*)(src + 128));
478 c->fft128.fft_permute(&c->fft128, (FFTComplex*)(src + 256));
479 c->fft128.fft_permute(&c->fft128, (FFTComplex*)(src + 384));
480 c->fft128.fft_calc(&c->fft128, (FFTComplex*)src);
481 c->fft128.fft_calc(&c->fft128, (FFTComplex*)(src + 128));
482 c->fft128.fft_calc(&c->fft128, (FFTComplex*)(src + 256));
483 c->fft128.fft_calc(&c->fft128, (FFTComplex*)(src + 384));
484 combine_fft(src, src + 128, src + 256, src + 384, tmp1,
485 ff_on2avc_ctab_1, ff_on2avc_ctab_2,
486 ff_on2avc_ctab_3, ff_on2avc_ctab_4, 512, 2);
487 c->fft512.fft_permute(&c->fft512, (FFTComplex*)tmp1);
488 c->fft512.fft_calc(&c->fft512, (FFTComplex*)tmp1);
489
490 pretwiddle(&tmp0[ 0], tmp1, 512, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
491 pretwiddle(&tmp0[128], tmp1, 512, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
492 pretwiddle(&tmp0[256], tmp1, 512, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
493 pretwiddle(&tmp0[384], tmp1, 512, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
494
495 memcpy(src, tmp1, 512 * sizeof(float));
496 }
497
498 static void wtf_end_1024(On2AVCContext *c, float *out, float *src,
499 float *tmp0, float *tmp1)
500 {
501 memcpy(src, tmp0, 768 * sizeof(*tmp0));
502 memcpy(tmp0 + 768, src + 768, 256 * sizeof(*tmp0));
503
504 zero_head_and_tail(src, 256, 16, 4);
505 zero_head_and_tail(src + 256, 256, 16, 4);
506 zero_head_and_tail(src + 512, 256, 13, 7);
507 zero_head_and_tail(src + 768, 256, 15, 5);
508
509 c->fft256.fft_permute(&c->fft256, (FFTComplex*)src);
510 c->fft256.fft_permute(&c->fft256, (FFTComplex*)(src + 256));
511 c->fft256.fft_permute(&c->fft256, (FFTComplex*)(src + 512));
512 c->fft256.fft_permute(&c->fft256, (FFTComplex*)(src + 768));
513 c->fft256.fft_calc(&c->fft256, (FFTComplex*)src);
514 c->fft256.fft_calc(&c->fft256, (FFTComplex*)(src + 256));
515 c->fft256.fft_calc(&c->fft256, (FFTComplex*)(src + 512));
516 c->fft256.fft_calc(&c->fft256, (FFTComplex*)(src + 768));
517 combine_fft(src, src + 256, src + 512, src + 768, tmp1,
518 ff_on2avc_ctab_1, ff_on2avc_ctab_2,
519 ff_on2avc_ctab_3, ff_on2avc_ctab_4, 1024, 1);
520 c->fft1024.fft_permute(&c->fft1024, (FFTComplex*)tmp1);
521 c->fft1024.fft_calc(&c->fft1024, (FFTComplex*)tmp1);
522
523 pretwiddle(&tmp0[ 0], tmp1, 1024, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
524 pretwiddle(&tmp0[256], tmp1, 1024, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
525 pretwiddle(&tmp0[512], tmp1, 1024, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
526 pretwiddle(&tmp0[768], tmp1, 1024, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
527
528 memcpy(src, tmp1, 1024 * sizeof(float));
529 }
530
531 static void wtf_40(On2AVCContext *c, float *out, float *src, int size)
532 {
533 float *tmp0 = c->temp, *tmp1 = c->temp + 1024;
534
535 memset(tmp0, 0, sizeof(*tmp0) * 1024);
536 memset(tmp1, 0, sizeof(*tmp1) * 1024);
537
538 if (size == 512) {
539 twiddle(src, &tmp0[ 0], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
540 twiddle(src + 8, &tmp0[ 0], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
541 twiddle(src + 16, &tmp0[ 16], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
542 twiddle(src + 24, &tmp0[ 16], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
543 twiddle(src + 32, &tmp0[ 32], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
544 twiddle(src + 40, &tmp0[ 32], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
545 twiddle(src + 48, &tmp0[ 48], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
546 twiddle(src + 56, &tmp0[ 48], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
547 twiddle(&tmp0[ 0], &tmp1[ 0], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
548 twiddle(&tmp0[16], &tmp1[ 0], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
549 twiddle(&tmp0[32], &tmp1[ 32], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
550 twiddle(&tmp0[48], &tmp1[ 32], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
551 twiddle(src + 64, &tmp1[ 64], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
552 twiddle(src + 80, &tmp1[ 64], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
553 twiddle(src + 96, &tmp1[ 96], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
554 twiddle(src + 112, &tmp1[ 96], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
555 twiddle(src + 128, &tmp1[128], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
556 twiddle(src + 144, &tmp1[128], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
557 twiddle(src + 160, &tmp1[160], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
558 twiddle(src + 176, &tmp1[160], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
559
560 memset(tmp0, 0, 64 * sizeof(*tmp0));
561
562 twiddle(&tmp1[ 0], &tmp0[ 0], 128, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
563 twiddle(&tmp1[ 32], &tmp0[ 0], 128, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
564 twiddle(&tmp1[ 64], &tmp0[ 0], 128, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
565 twiddle(&tmp1[ 96], &tmp0[ 0], 128, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
566 twiddle(&tmp1[128], &tmp0[128], 128, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
567 twiddle(&tmp1[160], &tmp0[128], 128, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
568 twiddle(src + 192, &tmp0[128], 128, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
569 twiddle(src + 224, &tmp0[128], 128, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
570 twiddle(src + 256, &tmp0[256], 128, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
571 twiddle(src + 288, &tmp0[256], 128, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
572 twiddle(src + 320, &tmp0[256], 128, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
573 twiddle(src + 352, &tmp0[256], 128, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
574
575 wtf_end_512(c, out, src, tmp0, tmp1);
576 } else {
577 twiddle(src, &tmp0[ 0], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
578 twiddle(src + 16, &tmp0[ 0], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
579 twiddle(src + 32, &tmp0[ 32], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
580 twiddle(src + 48, &tmp0[ 32], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
581 twiddle(src + 64, &tmp0[ 64], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
582 twiddle(src + 80, &tmp0[ 64], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
583 twiddle(src + 96, &tmp0[ 96], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
584 twiddle(src + 112, &tmp0[ 96], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
585 twiddle(&tmp0[ 0], &tmp1[ 0], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
586 twiddle(&tmp0[32], &tmp1[ 0], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
587 twiddle(&tmp0[64], &tmp1[ 64], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
588 twiddle(&tmp0[96], &tmp1[ 64], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
589 twiddle(src + 128, &tmp1[128], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
590 twiddle(src + 160, &tmp1[128], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
591 twiddle(src + 192, &tmp1[192], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
592 twiddle(src + 224, &tmp1[192], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
593 twiddle(src + 256, &tmp1[256], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
594 twiddle(src + 288, &tmp1[256], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
595 twiddle(src + 320, &tmp1[320], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
596 twiddle(src + 352, &tmp1[320], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
597
598 memset(tmp0, 0, 128 * sizeof(*tmp0));
599
600 twiddle(&tmp1[ 0], &tmp0[ 0], 256, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
601 twiddle(&tmp1[ 64], &tmp0[ 0], 256, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
602 twiddle(&tmp1[128], &tmp0[ 0], 256, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
603 twiddle(&tmp1[192], &tmp0[ 0], 256, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
604 twiddle(&tmp1[256], &tmp0[256], 256, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
605 twiddle(&tmp1[320], &tmp0[256], 256, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
606 twiddle(src + 384, &tmp0[256], 256, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
607 twiddle(src + 448, &tmp0[256], 256, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
608 twiddle(src + 512, &tmp0[512], 256, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
609 twiddle(src + 576, &tmp0[512], 256, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
610 twiddle(src + 640, &tmp0[512], 256, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
611 twiddle(src + 704, &tmp0[512], 256, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
612
613 wtf_end_1024(c, out, src, tmp0, tmp1);
614 }
615 }
616
617 static void wtf_44(On2AVCContext *c, float *out, float *src, int size)
618 {
619 float *tmp0 = c->temp, *tmp1 = c->temp + 1024;
620
621 memset(tmp0, 0, sizeof(*tmp0) * 1024);
622 memset(tmp1, 0, sizeof(*tmp1) * 1024);
623
624 if (size == 512) {
625 twiddle(src, &tmp0[ 0], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
626 twiddle(src + 8, &tmp0[ 0], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
627 twiddle(src + 16, &tmp0[16], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
628 twiddle(src + 24, &tmp0[16], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
629 twiddle(src + 32, &tmp0[32], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
630 twiddle(src + 40, &tmp0[32], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
631 twiddle(src + 48, &tmp0[48], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
632 twiddle(src + 56, &tmp0[48], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
633 twiddle(&tmp0[ 0], &tmp1[ 0], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
634 twiddle(&tmp0[16], &tmp1[ 0], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
635 twiddle(&tmp0[32], &tmp1[32], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
636 twiddle(&tmp0[48], &tmp1[32], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
637 twiddle(src + 64, &tmp1[64], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
638 twiddle(src + 80, &tmp1[64], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
639 twiddle(src + 96, &tmp1[96], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
640 twiddle(src + 112, &tmp1[96], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
641
642 memset(tmp0, 0, 64 * sizeof(*tmp0));
643
644 twiddle(&tmp1[ 0], &tmp0[ 0], 128, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
645 twiddle(&tmp1[32], &tmp0[ 0], 128, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
646 twiddle(&tmp1[64], &tmp0[ 0], 128, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
647 twiddle(&tmp1[96], &tmp0[ 0], 128, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
648 twiddle(src + 128, &tmp0[128], 128, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
649 twiddle(src + 160, &tmp0[128], 128, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
650 twiddle(src + 192, &tmp0[128], 128, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
651 twiddle(src + 224, &tmp0[128], 128, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
652 twiddle(src + 256, &tmp0[256], 128, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
653 twiddle(src + 320, &tmp0[256], 128, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
654
655 wtf_end_512(c, out, src, tmp0, tmp1);
656 } else {
657 twiddle(src, &tmp0[ 0], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
658 twiddle(src + 16, &tmp0[ 0], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
659 twiddle(src + 32, &tmp0[ 32], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
660 twiddle(src + 48, &tmp0[ 32], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
661 twiddle(src + 64, &tmp0[ 64], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
662 twiddle(src + 80, &tmp0[ 64], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
663 twiddle(src + 96, &tmp0[ 96], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
664 twiddle(src + 112, &tmp0[ 96], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
665 twiddle(&tmp0[ 0], &tmp1[ 0], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
666 twiddle(&tmp0[32], &tmp1[ 0], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
667 twiddle(&tmp0[64], &tmp1[ 64], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
668 twiddle(&tmp0[96], &tmp1[ 64], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
669 twiddle(src + 128, &tmp1[128], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
670 twiddle(src + 160, &tmp1[128], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
671 twiddle(src + 192, &tmp1[192], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
672 twiddle(src + 224, &tmp1[192], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
673
674 memset(tmp0, 0, 128 * sizeof(*tmp0));
675
676 twiddle(&tmp1[ 0], &tmp0[ 0], 256, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
677 twiddle(&tmp1[ 64], &tmp0[ 0], 256, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
678 twiddle(&tmp1[128], &tmp0[ 0], 256, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
679 twiddle(&tmp1[192], &tmp0[ 0], 256, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
680 twiddle(src + 256, &tmp0[256], 256, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
681 twiddle(src + 320, &tmp0[256], 256, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
682 twiddle(src + 384, &tmp0[256], 256, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
683 twiddle(src + 448, &tmp0[256], 256, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
684 twiddle(src + 512, &tmp0[512], 256, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
685 twiddle(src + 640, &tmp0[512], 256, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
686
687 wtf_end_1024(c, out, src, tmp0, tmp1);
688 }
689 }
690
691 static int on2avc_reconstruct_channel_ext(On2AVCContext *c, AVFrame *dst, int offset)
692 {
693 int ch, i;
694
695 for (ch = 0; ch < c->avctx->ch_layout.nb_channels; ch++) {
696 float *out = (float*)dst->extended_data[ch] + offset;
697 float *in = c->coeffs[ch];
698 float *saved = c->delay[ch];
699 float *buf = c->mdct_buf;
700 float *wout = out + 448;
701
702 switch (c->window_type) {
703 case WINDOW_TYPE_EXT7:
704 c->mdct.imdct_half(&c->mdct, buf, in);
705 break;
706 case WINDOW_TYPE_EXT4:
707 c->wtf(c, buf, in, 1024);
708 break;
709 case WINDOW_TYPE_EXT5:
710 c->wtf(c, buf, in, 512);
711 c->mdct.imdct_half(&c->mdct_half, buf + 512, in + 512);
712 for (i = 0; i < 256; i++) {
713 FFSWAP(float, buf[i + 512], buf[1023 - i]);
714 }
715 break;
716 case WINDOW_TYPE_EXT6:
717 c->mdct.imdct_half(&c->mdct_half, buf, in);
718 for (i = 0; i < 256; i++) {
719 FFSWAP(float, buf[i], buf[511 - i]);
720 }
721 c->wtf(c, buf + 512, in + 512, 512);
722 break;
723 }
724
725 memcpy(out, saved, 448 * sizeof(float));
726 c->fdsp->vector_fmul_window(wout, saved + 448, buf, c->short_win, 64);
727 memcpy(wout + 128, buf + 64, 448 * sizeof(float));
728 memcpy(saved, buf + 512, 448 * sizeof(float));
729 memcpy(saved + 448, buf + 7*128 + 64, 64 * sizeof(float));
730 }
731
732 return 0;
733 }
734
735 // not borrowed from aacdec.c - the codec has original design after all
736 30 static int on2avc_reconstruct_channel(On2AVCContext *c, int channel,
737 AVFrame *dst, int offset)
738 {
739 int i;
740 30 float *out = (float*)dst->extended_data[channel] + offset;
741 30 float *in = c->coeffs[channel];
742 30 float *saved = c->delay[channel];
743 30 float *buf = c->mdct_buf;
744 30 float *temp = c->temp;
745
746
1/3
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
30 switch (c->window_type) {
747 30 case WINDOW_TYPE_LONG_START:
748 case WINDOW_TYPE_LONG_STOP:
749 case WINDOW_TYPE_LONG:
750 30 c->mdct.imdct_half(&c->mdct, buf, in);
751 30 break;
752 case WINDOW_TYPE_8SHORT:
753 for (i = 0; i < ON2AVC_SUBFRAME_SIZE; i += ON2AVC_SUBFRAME_SIZE / 8)
754 c->mdct_small.imdct_half(&c->mdct_small, buf + i, in + i);
755 break;
756 }
757
758
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if ((c->prev_window_type == WINDOW_TYPE_LONG ||
759 c->prev_window_type == WINDOW_TYPE_LONG_STOP) &&
760
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 (c->window_type == WINDOW_TYPE_LONG ||
761 c->window_type == WINDOW_TYPE_LONG_START)) {
762 30 c->fdsp->vector_fmul_window(out, saved, buf, c->long_win, 512);
763 } else {
764 float *wout = out + 448;
765 memcpy(out, saved, 448 * sizeof(float));
766
767 if (c->window_type == WINDOW_TYPE_8SHORT) {
768 c->fdsp->vector_fmul_window(wout + 0*128, saved + 448, buf + 0*128, c->short_win, 64);
769 c->fdsp->vector_fmul_window(wout + 1*128, buf + 0*128 + 64, buf + 1*128, c->short_win, 64);
770 c->fdsp->vector_fmul_window(wout + 2*128, buf + 1*128 + 64, buf + 2*128, c->short_win, 64);
771 c->fdsp->vector_fmul_window(wout + 3*128, buf + 2*128 + 64, buf + 3*128, c->short_win, 64);
772 c->fdsp->vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, c->short_win, 64);
773 memcpy(wout + 4*128, temp, 64 * sizeof(float));
774 } else {
775 c->fdsp->vector_fmul_window(wout, saved + 448, buf, c->short_win, 64);
776 memcpy(wout + 128, buf + 64, 448 * sizeof(float));
777 }
778 }
779
780 // buffer update
781
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
30 switch (c->window_type) {
782 case WINDOW_TYPE_8SHORT:
783 memcpy(saved, temp + 64, 64 * sizeof(float));
784 c->fdsp->vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, c->short_win, 64);
785 c->fdsp->vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, c->short_win, 64);
786 c->fdsp->vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, c->short_win, 64);
787 memcpy(saved + 448, buf + 7*128 + 64, 64 * sizeof(float));
788 break;
789 case WINDOW_TYPE_LONG_START:
790 memcpy(saved, buf + 512, 448 * sizeof(float));
791 memcpy(saved + 448, buf + 7*128 + 64, 64 * sizeof(float));
792 break;
793 30 case WINDOW_TYPE_LONG_STOP:
794 case WINDOW_TYPE_LONG:
795 30 memcpy(saved, buf + 512, 512 * sizeof(float));
796 30 break;
797 }
798 30 return 0;
799 }
800
801 30 static int on2avc_decode_subframe(On2AVCContext *c, const uint8_t *buf,
802 int buf_size, AVFrame *dst, int offset)
803 {
804 GetBitContext gb;
805 int i, ret;
806
807
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
30 if ((ret = init_get_bits8(&gb, buf, buf_size)) < 0)
808 return ret;
809
810
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
30 if (get_bits1(&gb)) {
811 av_log(c->avctx, AV_LOG_ERROR, "enh bit set\n");
812 return AVERROR_INVALIDDATA;
813 }
814 30 c->prev_window_type = c->window_type;
815 30 c->window_type = get_bits(&gb, 3);
816
817 30 c->band_start = c->modes[c->window_type].band_start;
818 30 c->num_windows = c->modes[c->window_type].num_windows;
819 30 c->num_bands = c->modes[c->window_type].num_bands;
820 30 c->is_long = (c->window_type != WINDOW_TYPE_8SHORT);
821
822 30 c->grouping[0] = 1;
823
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 for (i = 1; i < c->num_windows; i++)
824 c->grouping[i] = !get_bits1(&gb);
825
826 30 on2avc_read_ms_info(c, &gb);
827
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 30 times.
60 for (i = 0; i < c->avctx->ch_layout.nb_channels; i++)
828
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
30 if ((ret = on2avc_read_channel_data(c, &gb, i)) < 0)
829 return AVERROR_INVALIDDATA;
830
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
30 if (c->avctx->ch_layout.nb_channels == 2 && c->ms_present)
831 on2avc_apply_ms(c);
832
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if (c->window_type < WINDOW_TYPE_EXT4) {
833
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 30 times.
60 for (i = 0; i < c->avctx->ch_layout.nb_channels; i++)
834 30 on2avc_reconstruct_channel(c, i, dst, offset);
835 } else {
836 on2avc_reconstruct_channel_ext(c, dst, offset);
837 }
838
839 30 return 0;
840 }
841
842 30 static int on2avc_decode_frame(AVCodecContext * avctx, AVFrame *frame,
843 int *got_frame_ptr, AVPacket *avpkt)
844 {
845 30 const uint8_t *buf = avpkt->data;
846 30 int buf_size = avpkt->size;
847 30 On2AVCContext *c = avctx->priv_data;
848 GetByteContext gb;
849 30 int num_frames = 0, frame_size, audio_off;
850 int ret;
851
852
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if (c->is_av500) {
853 /* get output buffer */
854 30 frame->nb_samples = ON2AVC_SUBFRAME_SIZE;
855
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
30 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
856 return ret;
857
858
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
30 if ((ret = on2avc_decode_subframe(c, buf, buf_size, frame, 0)) < 0)
859 return ret;
860 } else {
861 bytestream2_init(&gb, buf, buf_size);
862 while (bytestream2_get_bytes_left(&gb) > 2) {
863 frame_size = bytestream2_get_le16(&gb);
864 if (!frame_size || frame_size > bytestream2_get_bytes_left(&gb)) {
865 av_log(avctx, AV_LOG_ERROR, "Invalid subframe size %d\n",
866 frame_size);
867 return AVERROR_INVALIDDATA;
868 }
869 num_frames++;
870 bytestream2_skip(&gb, frame_size);
871 }
872 if (!num_frames) {
873 av_log(avctx, AV_LOG_ERROR, "No subframes present\n");
874 return AVERROR_INVALIDDATA;
875 }
876
877 /* get output buffer */
878 frame->nb_samples = ON2AVC_SUBFRAME_SIZE * num_frames;
879 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
880 return ret;
881
882 audio_off = 0;
883 bytestream2_init(&gb, buf, buf_size);
884 while (bytestream2_get_bytes_left(&gb) > 2) {
885 frame_size = bytestream2_get_le16(&gb);
886 if ((ret = on2avc_decode_subframe(c, gb.buffer, frame_size,
887 frame, audio_off)) < 0)
888 return ret;
889 audio_off += ON2AVC_SUBFRAME_SIZE;
890 bytestream2_skip(&gb, frame_size);
891 }
892 }
893
894 30 *got_frame_ptr = 1;
895
896 30 return buf_size;
897 }
898
899 3 static av_cold void on2avc_free_vlcs(On2AVCContext *c)
900 {
901 int i;
902
903 3 ff_free_vlc(&c->scale_diff);
904
2/2
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 3 times.
48 for (i = 1; i < 16; i++)
905 45 ff_free_vlc(&c->cb_vlc[i]);
906 3 }
907
908 3 static av_cold int on2avc_decode_init(AVCodecContext *avctx)
909 {
910 3 On2AVCContext *c = avctx->priv_data;
911 3 const uint8_t *lens = ff_on2avc_cb_lens;
912 3 const uint16_t *syms = ff_on2avc_cb_syms;
913 3 int channels = avctx->ch_layout.nb_channels;
914 int i, ret;
915
916
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (channels > 2U) {
917 avpriv_request_sample(avctx, "Decoding more than 2 channels");
918 return AVERROR_PATCHWELCOME;
919 }
920
921 3 c->avctx = avctx;
922 3 avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
923 3 av_channel_layout_uninit(&avctx->ch_layout);
924
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 avctx->ch_layout = (channels == 2) ? (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO :
925 (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
926
927 3 c->is_av500 = (avctx->codec_tag == 0x500);
928
929
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (channels == 2)
930 av_log(avctx, AV_LOG_WARNING,
931 "Stereo mode support is not good, patch is welcome\n");
932
933 // We add -0.01 before ceil() to avoid any values to fall at exactly the
934 // midpoint between different ceil values. The results are identical to
935 // using pow(10, i / 10.0) without such bias
936
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 3 times.
63 for (i = 0; i < 20; i++)
937 60 c->scale_tab[i] = ceil(ff_exp10(i * 0.1) * 16 - 0.01) / 32;
938
2/2
✓ Branch 0 taken 324 times.
✓ Branch 1 taken 3 times.
327 for (; i < 128; i++)
939 324 c->scale_tab[i] = ceil(ff_exp10(i * 0.1) * 0.5 - 0.01);
940
941
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if (avctx->sample_rate < 32000 || channels == 1)
942 3 memcpy(c->long_win, ff_on2avc_window_long_24000,
943 1024 * sizeof(*c->long_win));
944 else
945 memcpy(c->long_win, ff_on2avc_window_long_32000,
946 1024 * sizeof(*c->long_win));
947 3 memcpy(c->short_win, ff_on2avc_window_short, 128 * sizeof(*c->short_win));
948
949 6 c->modes = (avctx->sample_rate <= 40000) ? ff_on2avc_modes_40
950
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 : ff_on2avc_modes_44;
951
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 c->wtf = (avctx->sample_rate <= 40000) ? wtf_40
952 : wtf_44;
953
954 3 ff_mdct_init(&c->mdct, 11, 1, 1.0 / (32768.0 * 1024.0));
955 3 ff_mdct_init(&c->mdct_half, 10, 1, 1.0 / (32768.0 * 512.0));
956 3 ff_mdct_init(&c->mdct_small, 8, 1, 1.0 / (32768.0 * 128.0));
957 3 ff_fft_init(&c->fft128, 6, 0);
958 3 ff_fft_init(&c->fft256, 7, 0);
959 3 ff_fft_init(&c->fft512, 8, 1);
960 3 ff_fft_init(&c->fft1024, 9, 1);
961 3 c->fdsp = avpriv_float_dsp_alloc(avctx->flags & AV_CODEC_FLAG_BITEXACT);
962
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!c->fdsp)
963 return AVERROR(ENOMEM);
964
965 3 ret = ff_init_vlc_from_lengths(&c->scale_diff, 9, ON2AVC_SCALE_DIFFS,
966 ff_on2avc_scale_diff_bits, 1,
967 ff_on2avc_scale_diff_syms, 1, 1, -60, 0, avctx);
968
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ret < 0)
969 goto vlc_fail;
970
2/2
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 3 times.
48 for (i = 1; i < 16; i++) {
971 45 int idx = i - 1;
972 45 ret = ff_init_vlc_from_lengths(&c->cb_vlc[i], 9, ff_on2avc_cb_elems[idx],
973 lens, 1,
974 syms, 2, 2, 0, 0, avctx);
975
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
45 if (ret < 0)
976 goto vlc_fail;
977 45 lens += ff_on2avc_cb_elems[idx];
978 45 syms += ff_on2avc_cb_elems[idx];
979 }
980
981 3 return 0;
982 vlc_fail:
983 av_log(avctx, AV_LOG_ERROR, "Cannot init VLC\n");
984 return ret;
985 }
986
987 3 static av_cold int on2avc_decode_close(AVCodecContext *avctx)
988 {
989 3 On2AVCContext *c = avctx->priv_data;
990
991 3 ff_mdct_end(&c->mdct);
992 3 ff_mdct_end(&c->mdct_half);
993 3 ff_mdct_end(&c->mdct_small);
994 3 ff_fft_end(&c->fft128);
995 3 ff_fft_end(&c->fft256);
996 3 ff_fft_end(&c->fft512);
997 3 ff_fft_end(&c->fft1024);
998
999 3 av_freep(&c->fdsp);
1000
1001 3 on2avc_free_vlcs(c);
1002
1003 3 return 0;
1004 }
1005
1006
1007 const FFCodec ff_on2avc_decoder = {
1008 .p.name = "on2avc",
1009 .p.long_name = NULL_IF_CONFIG_SMALL("On2 Audio for Video Codec"),
1010 .p.type = AVMEDIA_TYPE_AUDIO,
1011 .p.id = AV_CODEC_ID_ON2AVC,
1012 .priv_data_size = sizeof(On2AVCContext),
1013 .init = on2avc_decode_init,
1014 FF_CODEC_DECODE_CB(on2avc_decode_frame),
1015 .close = on2avc_decode_close,
1016 .p.capabilities = AV_CODEC_CAP_DR1,
1017 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
1018 .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1019 AV_SAMPLE_FMT_NONE },
1020 };
1021