FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/on2avc.c
Date: 2022-11-26 13:19:19
Exec Total Coverage
Lines: 200 585 34.2%
Branches: 89 218 40.8%

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