FFmpeg coverage


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