FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
on2avc.c
Go to the documentation of this file.
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 
24 #include "libavutil/ffmath.h"
25 #include "libavutil/float_dsp.h"
26 #include "avcodec.h"
27 #include "bytestream.h"
28 #include "fft.h"
29 #include "get_bits.h"
30 #include "internal.h"
31 
32 #include "on2avcdata.h"
33 
34 #define ON2AVC_SUBFRAME_SIZE 1024
35 
45 };
46 
47 typedef struct On2AVCContext {
52  void (*wtf)(struct On2AVCContext *ctx, float *out, float *in, int size);
53 
54  int is_av500;
55 
56  const On2AVCMode *modes;
60  const int *band_start;
61 
62  int grouping[8];
65 
66  int is_long;
67 
71 
73 
75  VLC cb_vlc[16];
76 
77  float scale_tab[128];
78 
81 
87 
89 {
90  int w, b, band_off = 0;
91 
92  c->ms_present = get_bits1(gb);
93  if (!c->ms_present)
94  return;
95  for (w = 0; w < c->num_windows; w++) {
96  if (!c->grouping[w]) {
97  memcpy(c->ms_info + band_off,
98  c->ms_info + band_off - c->num_bands,
99  c->num_bands * sizeof(*c->ms_info));
100  band_off += c->num_bands;
101  continue;
102  }
103  for (b = 0; b < c->num_bands; b++)
104  c->ms_info[band_off++] = get_bits1(gb);
105  }
106 }
107 
108 // do not see Table 17 in ISO/IEC 13818-7
110 {
111  int bits_per_sect = c->is_long ? 5 : 3;
112  int esc_val = (1 << bits_per_sect) - 1;
113  int num_bands = c->num_bands * c->num_windows;
114  int band = 0, i, band_type, run_len, run;
115 
116  while (band < num_bands) {
117  band_type = get_bits(gb, 4);
118  run_len = 1;
119  do {
120  run = get_bits(gb, bits_per_sect);
121  if (run > num_bands - band - run_len) {
122  av_log(c->avctx, AV_LOG_ERROR, "Invalid band type run\n");
123  return AVERROR_INVALIDDATA;
124  }
125  run_len += run;
126  } while (run == esc_val);
127  for (i = band; i < band + run_len; i++) {
128  c->band_type[i] = band_type;
129  c->band_run_end[i] = band + run_len;
130  }
131  band += run_len;
132  }
133 
134  return 0;
135 }
136 
137 // completely not like Table 18 in ISO/IEC 13818-7
138 // (no intensity stereo, different coding for the first coefficient)
140 {
141  int w, w2, b, scale, first = 1;
142  int band_off = 0;
143 
144  for (w = 0; w < c->num_windows; w++) {
145  if (!c->grouping[w]) {
146  memcpy(c->band_scales + band_off,
147  c->band_scales + band_off - c->num_bands,
148  c->num_bands * sizeof(*c->band_scales));
149  band_off += c->num_bands;
150  continue;
151  }
152  for (b = 0; b < c->num_bands; b++) {
153  if (!c->band_type[band_off]) {
154  int all_zero = 1;
155  for (w2 = w + 1; w2 < c->num_windows; w2++) {
156  if (c->grouping[w2])
157  break;
158  if (c->band_type[w2 * c->num_bands + b]) {
159  all_zero = 0;
160  break;
161  }
162  }
163  if (all_zero) {
164  c->band_scales[band_off++] = 0;
165  continue;
166  }
167  }
168  if (first) {
169  scale = get_bits(gb, 7);
170  first = 0;
171  } else {
172  scale += get_vlc2(gb, c->scale_diff.table, 9, 3) - 60;
173  }
174  if (scale < 0 || scale > 127) {
175  av_log(c->avctx, AV_LOG_ERROR, "Invalid scale value %d\n",
176  scale);
177  return AVERROR_INVALIDDATA;
178  }
179  c->band_scales[band_off++] = c->scale_tab[scale];
180  }
181  }
182 
183  return 0;
184 }
185 
186 static inline float on2avc_scale(int v, float scale)
187 {
188  return v * sqrtf(abs(v)) * scale;
189 }
190 
191 // spectral data is coded completely differently - there are no unsigned codebooks
192 static int on2avc_decode_quads(On2AVCContext *c, GetBitContext *gb, float *dst,
193  int dst_size, int type, float band_scale)
194 {
195  int i, j, val, val1;
196 
197  for (i = 0; i < dst_size; i += 4) {
198  val = get_vlc2(gb, c->cb_vlc[type].table, 9, 3);
199 
200  for (j = 0; j < 4; j++) {
201  val1 = sign_extend((val >> (12 - j * 4)) & 0xF, 4);
202  *dst++ = on2avc_scale(val1, band_scale);
203  }
204  }
205 
206  return 0;
207 }
208 
209 static inline int get_egolomb(GetBitContext *gb)
210 {
211  int v = 4;
212 
213  while (get_bits1(gb)) {
214  v++;
215  if (v > 30) {
216  av_log(NULL, AV_LOG_WARNING, "Too large golomb code in get_egolomb.\n");
217  v = 30;
218  break;
219  }
220  }
221 
222  return (1 << v) + get_bits_long(gb, v);
223 }
224 
225 static int on2avc_decode_pairs(On2AVCContext *c, GetBitContext *gb, float *dst,
226  int dst_size, int type, float band_scale)
227 {
228  int i, val, val1, val2, sign;
229 
230  for (i = 0; i < dst_size; i += 2) {
231  val = get_vlc2(gb, c->cb_vlc[type].table, 9, 3);
232 
233  val1 = sign_extend(val >> 8, 8);
234  val2 = sign_extend(val & 0xFF, 8);
235  if (type == ON2AVC_ESC_CB) {
236  if (val1 <= -16 || val1 >= 16) {
237  sign = 1 - (val1 < 0) * 2;
238  val1 = sign * get_egolomb(gb);
239  }
240  if (val2 <= -16 || val2 >= 16) {
241  sign = 1 - (val2 < 0) * 2;
242  val2 = sign * get_egolomb(gb);
243  }
244  }
245 
246  *dst++ = on2avc_scale(val1, band_scale);
247  *dst++ = on2avc_scale(val2, band_scale);
248  }
249 
250  return 0;
251 }
252 
254 {
255  int ret;
256  int w, b, band_idx;
257  float *coeff_ptr;
258 
259  if ((ret = on2avc_decode_band_types(c, gb)) < 0)
260  return ret;
261  if ((ret = on2avc_decode_band_scales(c, gb)) < 0)
262  return ret;
263 
264  coeff_ptr = c->coeffs[ch];
265  band_idx = 0;
266  memset(coeff_ptr, 0, ON2AVC_SUBFRAME_SIZE * sizeof(*coeff_ptr));
267  for (w = 0; w < c->num_windows; w++) {
268  for (b = 0; b < c->num_bands; b++) {
269  int band_size = c->band_start[b + 1] - c->band_start[b];
270  int band_type = c->band_type[band_idx + b];
271 
272  if (!band_type) {
273  coeff_ptr += band_size;
274  continue;
275  }
276  if (band_type < 9)
277  on2avc_decode_quads(c, gb, coeff_ptr, band_size, band_type,
278  c->band_scales[band_idx + b]);
279  else
280  on2avc_decode_pairs(c, gb, coeff_ptr, band_size, band_type,
281  c->band_scales[band_idx + b]);
282  coeff_ptr += band_size;
283  }
284  band_idx += c->num_bands;
285  }
286 
287  return 0;
288 }
289 
291 {
292  int w, b, i;
293  int band_off = 0;
294  float *ch0 = c->coeffs[0];
295  float *ch1 = c->coeffs[1];
296 
297  for (w = 0; w < c->num_windows; w++) {
298  for (b = 0; b < c->num_bands; b++) {
299  if (c->ms_info[band_off + b]) {
300  for (i = c->band_start[b]; i < c->band_start[b + 1]; i++) {
301  float l = *ch0, r = *ch1;
302  *ch0++ = l + r;
303  *ch1++ = l - r;
304  }
305  } else {
306  ch0 += c->band_start[b + 1] - c->band_start[b];
307  ch1 += c->band_start[b + 1] - c->band_start[b];
308  }
309  }
310  band_off += c->num_bands;
311  }
312  return 0;
313 }
314 
315 static void zero_head_and_tail(float *src, int len, int order0, int order1)
316 {
317  memset(src, 0, sizeof(*src) * order0);
318  memset(src + len - order1, 0, sizeof(*src) * order1);
319 }
320 
321 static void pretwiddle(float *src, float *dst, int dst_len, int tab_step,
322  int step, int order0, int order1, const double * const *tabs)
323 {
324  float *src2, *out;
325  const double *tab;
326  int i, j;
327 
328  out = dst;
329  tab = tabs[0];
330  for (i = 0; i < tab_step; i++) {
331  double sum = 0;
332  for (j = 0; j < order0; j++)
333  sum += src[j] * tab[j * tab_step + i];
334  out[i] += sum;
335  }
336 
337  out = dst + dst_len - tab_step;
338  tab = tabs[order0];
339  src2 = src + (dst_len - tab_step) / step + 1 + order0;
340  for (i = 0; i < tab_step; i++) {
341  double sum = 0;
342  for (j = 0; j < order1; j++)
343  sum += src2[j] * tab[j * tab_step + i];
344  out[i] += sum;
345  }
346 }
347 
348 static void twiddle(float *src1, float *src2, int src2_len,
349  const double *tab, int tab_len, int step,
350  int order0, int order1, const double * const *tabs)
351 {
352  int steps;
353  int mask;
354  int i, j;
355 
356  steps = (src2_len - tab_len) / step + 1;
357  pretwiddle(src1, src2, src2_len, tab_len, step, order0, order1, tabs);
358  mask = tab_len - 1;
359 
360  for (i = 0; i < steps; i++) {
361  float in0 = src1[order0 + i];
362  int pos = (src2_len - 1) & mask;
363 
364  if (pos < tab_len) {
365  const double *t = tab;
366  for (j = pos; j >= 0; j--)
367  src2[j] += in0 * *t++;
368  for (j = 0; j < tab_len - pos - 1; j++)
369  src2[src2_len - j - 1] += in0 * tab[pos + 1 + j];
370  } else {
371  for (j = 0; j < tab_len; j++)
372  src2[pos - j] += in0 * tab[j];
373  }
374  mask = pos + step;
375  }
376 }
377 
378 #define CMUL1_R(s, t, is, it) \
379  s[is + 0] * t[it + 0] - s[is + 1] * t[it + 1]
380 #define CMUL1_I(s, t, is, it) \
381  s[is + 0] * t[it + 1] + s[is + 1] * t[it + 0]
382 #define CMUL2_R(s, t, is, it) \
383  s[is + 0] * t[it + 0] + s[is + 1] * t[it + 1]
384 #define CMUL2_I(s, t, is, it) \
385  s[is + 0] * t[it + 1] - s[is + 1] * t[it + 0]
386 
387 #define CMUL0(dst, id, s0, s1, s2, s3, t0, t1, t2, t3, is, it) \
388  dst[id] = s0[is] * t0[it] + s1[is] * t1[it] \
389  + s2[is] * t2[it] + s3[is] * t3[it]; \
390  dst[id + 1] = s0[is] * t0[it + 1] + s1[is] * t1[it + 1] \
391  + s2[is] * t2[it + 1] + s3[is] * t3[it + 1];
392 
393 #define CMUL1(dst, s0, s1, s2, s3, t0, t1, t2, t3, is, it) \
394  *dst++ = CMUL1_R(s0, t0, is, it) \
395  + CMUL1_R(s1, t1, is, it) \
396  + CMUL1_R(s2, t2, is, it) \
397  + CMUL1_R(s3, t3, is, it); \
398  *dst++ = CMUL1_I(s0, t0, is, it) \
399  + CMUL1_I(s1, t1, is, it) \
400  + CMUL1_I(s2, t2, is, it) \
401  + CMUL1_I(s3, t3, is, it);
402 
403 #define CMUL2(dst, s0, s1, s2, s3, t0, t1, t2, t3, is, it) \
404  *dst++ = CMUL2_R(s0, t0, is, it) \
405  + CMUL2_R(s1, t1, is, it) \
406  + CMUL2_R(s2, t2, is, it) \
407  + CMUL2_R(s3, t3, is, it); \
408  *dst++ = CMUL2_I(s0, t0, is, it) \
409  + CMUL2_I(s1, t1, is, it) \
410  + CMUL2_I(s2, t2, is, it) \
411  + CMUL2_I(s3, t3, is, it);
412 
413 static void combine_fft(float *s0, float *s1, float *s2, float *s3, float *dst,
414  const float *t0, const float *t1,
415  const float *t2, const float *t3, int len, int step)
416 {
417  const float *h0, *h1, *h2, *h3;
418  float *d1, *d2;
419  int tmp, half;
420  int len2 = len >> 1, len4 = len >> 2;
421  int hoff;
422  int i, j, k;
423 
424  tmp = step;
425  for (half = len2; tmp > 1; half <<= 1, tmp >>= 1);
426 
427  h0 = t0 + half;
428  h1 = t1 + half;
429  h2 = t2 + half;
430  h3 = t3 + half;
431 
432  CMUL0(dst, 0, s0, s1, s2, s3, t0, t1, t2, t3, 0, 0);
433 
434  hoff = 2 * step * (len4 >> 1);
435 
436  j = 2;
437  k = 2 * step;
438  d1 = dst + 2;
439  d2 = dst + 2 + (len >> 1);
440  for (i = 0; i < (len4 - 1) >> 1; i++) {
441  CMUL1(d1, s0, s1, s2, s3, t0, t1, t2, t3, j, k);
442  CMUL1(d2, s0, s1, s2, s3, h0, h1, h2, h3, j, k);
443  j += 2;
444  k += 2 * step;
445  }
446  CMUL0(dst, len4, s0, s1, s2, s3, t0, t1, t2, t3, 1, hoff);
447  CMUL0(dst, len4 + len2, s0, s1, s2, s3, h0, h1, h2, h3, 1, hoff);
448 
449  j = len4;
450  k = hoff + 2 * step * len4;
451  d1 = dst + len4 + 2;
452  d2 = dst + len4 + 2 + len2;
453  for (i = 0; i < (len4 - 2) >> 1; i++) {
454  CMUL2(d1, s0, s1, s2, s3, t0, t1, t2, t3, j, k);
455  CMUL2(d2, s0, s1, s2, s3, h0, h1, h2, h3, j, k);
456  j -= 2;
457  k += 2 * step;
458  }
459  CMUL0(dst, len2 + 4, s0, s1, s2, s3, t0, t1, t2, t3, 0, k);
460 }
461 
462 static void wtf_end_512(On2AVCContext *c, float *out, float *src,
463  float *tmp0, float *tmp1)
464 {
465  memcpy(src, tmp0, 384 * sizeof(*tmp0));
466  memcpy(tmp0 + 384, src + 384, 128 * sizeof(*tmp0));
467 
468  zero_head_and_tail(src, 128, 16, 4);
469  zero_head_and_tail(src + 128, 128, 16, 4);
470  zero_head_and_tail(src + 256, 128, 13, 7);
471  zero_head_and_tail(src + 384, 128, 15, 5);
472 
473  c->fft128.fft_permute(&c->fft128, (FFTComplex*)src);
474  c->fft128.fft_permute(&c->fft128, (FFTComplex*)(src + 128));
475  c->fft128.fft_permute(&c->fft128, (FFTComplex*)(src + 256));
476  c->fft128.fft_permute(&c->fft128, (FFTComplex*)(src + 384));
477  c->fft128.fft_calc(&c->fft128, (FFTComplex*)src);
478  c->fft128.fft_calc(&c->fft128, (FFTComplex*)(src + 128));
479  c->fft128.fft_calc(&c->fft128, (FFTComplex*)(src + 256));
480  c->fft128.fft_calc(&c->fft128, (FFTComplex*)(src + 384));
481  combine_fft(src, src + 128, src + 256, src + 384, tmp1,
484  c->fft512.fft_permute(&c->fft512, (FFTComplex*)tmp1);
485  c->fft512.fft_calc(&c->fft512, (FFTComplex*)tmp1);
486 
487  pretwiddle(&tmp0[ 0], tmp1, 512, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
488  pretwiddle(&tmp0[128], tmp1, 512, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
489  pretwiddle(&tmp0[256], tmp1, 512, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
490  pretwiddle(&tmp0[384], tmp1, 512, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
491 
492  memcpy(src, tmp1, 512 * sizeof(float));
493 }
494 
495 static void wtf_end_1024(On2AVCContext *c, float *out, float *src,
496  float *tmp0, float *tmp1)
497 {
498  memcpy(src, tmp0, 768 * sizeof(*tmp0));
499  memcpy(tmp0 + 768, src + 768, 256 * sizeof(*tmp0));
500 
501  zero_head_and_tail(src, 256, 16, 4);
502  zero_head_and_tail(src + 256, 256, 16, 4);
503  zero_head_and_tail(src + 512, 256, 13, 7);
504  zero_head_and_tail(src + 768, 256, 15, 5);
505 
506  c->fft256.fft_permute(&c->fft256, (FFTComplex*)src);
507  c->fft256.fft_permute(&c->fft256, (FFTComplex*)(src + 256));
508  c->fft256.fft_permute(&c->fft256, (FFTComplex*)(src + 512));
509  c->fft256.fft_permute(&c->fft256, (FFTComplex*)(src + 768));
510  c->fft256.fft_calc(&c->fft256, (FFTComplex*)src);
511  c->fft256.fft_calc(&c->fft256, (FFTComplex*)(src + 256));
512  c->fft256.fft_calc(&c->fft256, (FFTComplex*)(src + 512));
513  c->fft256.fft_calc(&c->fft256, (FFTComplex*)(src + 768));
514  combine_fft(src, src + 256, src + 512, src + 768, tmp1,
517  c->fft1024.fft_permute(&c->fft1024, (FFTComplex*)tmp1);
518  c->fft1024.fft_calc(&c->fft1024, (FFTComplex*)tmp1);
519 
520  pretwiddle(&tmp0[ 0], tmp1, 1024, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
521  pretwiddle(&tmp0[256], tmp1, 1024, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
522  pretwiddle(&tmp0[512], tmp1, 1024, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
523  pretwiddle(&tmp0[768], tmp1, 1024, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
524 
525  memcpy(src, tmp1, 1024 * sizeof(float));
526 }
527 
528 static void wtf_40(On2AVCContext *c, float *out, float *src, int size)
529 {
530  float *tmp0 = c->temp, *tmp1 = c->temp + 1024;
531 
532  memset(tmp0, 0, sizeof(*tmp0) * 1024);
533  memset(tmp1, 0, sizeof(*tmp1) * 1024);
534 
535  if (size == 512) {
536  twiddle(src, &tmp0[ 0], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
537  twiddle(src + 8, &tmp0[ 0], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
538  twiddle(src + 16, &tmp0[ 16], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
539  twiddle(src + 24, &tmp0[ 16], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
540  twiddle(src + 32, &tmp0[ 32], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
541  twiddle(src + 40, &tmp0[ 32], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
542  twiddle(src + 48, &tmp0[ 48], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
543  twiddle(src + 56, &tmp0[ 48], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
544  twiddle(&tmp0[ 0], &tmp1[ 0], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
545  twiddle(&tmp0[16], &tmp1[ 0], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
546  twiddle(&tmp0[32], &tmp1[ 32], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
547  twiddle(&tmp0[48], &tmp1[ 32], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
548  twiddle(src + 64, &tmp1[ 64], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
549  twiddle(src + 80, &tmp1[ 64], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
550  twiddle(src + 96, &tmp1[ 96], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
551  twiddle(src + 112, &tmp1[ 96], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
552  twiddle(src + 128, &tmp1[128], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
553  twiddle(src + 144, &tmp1[128], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
554  twiddle(src + 160, &tmp1[160], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
555  twiddle(src + 176, &tmp1[160], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
556 
557  memset(tmp0, 0, 64 * sizeof(*tmp0));
558 
559  twiddle(&tmp1[ 0], &tmp0[ 0], 128, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
560  twiddle(&tmp1[ 32], &tmp0[ 0], 128, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
561  twiddle(&tmp1[ 64], &tmp0[ 0], 128, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
562  twiddle(&tmp1[ 96], &tmp0[ 0], 128, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
563  twiddle(&tmp1[128], &tmp0[128], 128, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
564  twiddle(&tmp1[160], &tmp0[128], 128, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
565  twiddle(src + 192, &tmp0[128], 128, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
566  twiddle(src + 224, &tmp0[128], 128, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
567  twiddle(src + 256, &tmp0[256], 128, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
568  twiddle(src + 288, &tmp0[256], 128, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
569  twiddle(src + 320, &tmp0[256], 128, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
570  twiddle(src + 352, &tmp0[256], 128, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
571 
572  wtf_end_512(c, out, src, tmp0, tmp1);
573  } else {
574  twiddle(src, &tmp0[ 0], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
575  twiddle(src + 16, &tmp0[ 0], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
576  twiddle(src + 32, &tmp0[ 32], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
577  twiddle(src + 48, &tmp0[ 32], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
578  twiddle(src + 64, &tmp0[ 64], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
579  twiddle(src + 80, &tmp0[ 64], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
580  twiddle(src + 96, &tmp0[ 96], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
581  twiddle(src + 112, &tmp0[ 96], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
582  twiddle(&tmp0[ 0], &tmp1[ 0], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
583  twiddle(&tmp0[32], &tmp1[ 0], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
584  twiddle(&tmp0[64], &tmp1[ 64], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
585  twiddle(&tmp0[96], &tmp1[ 64], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
586  twiddle(src + 128, &tmp1[128], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
587  twiddle(src + 160, &tmp1[128], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
588  twiddle(src + 192, &tmp1[192], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
589  twiddle(src + 224, &tmp1[192], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
590  twiddle(src + 256, &tmp1[256], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
591  twiddle(src + 288, &tmp1[256], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
592  twiddle(src + 320, &tmp1[320], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
593  twiddle(src + 352, &tmp1[320], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
594 
595  memset(tmp0, 0, 128 * sizeof(*tmp0));
596 
597  twiddle(&tmp1[ 0], &tmp0[ 0], 256, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
598  twiddle(&tmp1[ 64], &tmp0[ 0], 256, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
599  twiddle(&tmp1[128], &tmp0[ 0], 256, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
600  twiddle(&tmp1[192], &tmp0[ 0], 256, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
601  twiddle(&tmp1[256], &tmp0[256], 256, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
602  twiddle(&tmp1[320], &tmp0[256], 256, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
603  twiddle(src + 384, &tmp0[256], 256, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
604  twiddle(src + 448, &tmp0[256], 256, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
605  twiddle(src + 512, &tmp0[512], 256, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
606  twiddle(src + 576, &tmp0[512], 256, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
607  twiddle(src + 640, &tmp0[512], 256, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
608  twiddle(src + 704, &tmp0[512], 256, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
609 
610  wtf_end_1024(c, out, src, tmp0, tmp1);
611  }
612 }
613 
614 static void wtf_44(On2AVCContext *c, float *out, float *src, int size)
615 {
616  float *tmp0 = c->temp, *tmp1 = c->temp + 1024;
617 
618  memset(tmp0, 0, sizeof(*tmp0) * 1024);
619  memset(tmp1, 0, sizeof(*tmp1) * 1024);
620 
621  if (size == 512) {
622  twiddle(src, &tmp0[ 0], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
623  twiddle(src + 8, &tmp0[ 0], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
624  twiddle(src + 16, &tmp0[16], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
625  twiddle(src + 24, &tmp0[16], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
626  twiddle(src + 32, &tmp0[32], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
627  twiddle(src + 40, &tmp0[32], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
628  twiddle(src + 48, &tmp0[48], 16, ff_on2avc_tab_10_2, 10, 2, 3, 1, ff_on2avc_tabs_4_10_2);
629  twiddle(src + 56, &tmp0[48], 16, ff_on2avc_tab_10_1, 10, 2, 1, 3, ff_on2avc_tabs_4_10_1);
630  twiddle(&tmp0[ 0], &tmp1[ 0], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
631  twiddle(&tmp0[16], &tmp1[ 0], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
632  twiddle(&tmp0[32], &tmp1[32], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
633  twiddle(&tmp0[48], &tmp1[32], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
634  twiddle(src + 64, &tmp1[64], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
635  twiddle(src + 80, &tmp1[64], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
636  twiddle(src + 96, &tmp1[96], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
637  twiddle(src + 112, &tmp1[96], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
638 
639  memset(tmp0, 0, 64 * sizeof(*tmp0));
640 
641  twiddle(&tmp1[ 0], &tmp0[ 0], 128, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
642  twiddle(&tmp1[32], &tmp0[ 0], 128, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
643  twiddle(&tmp1[64], &tmp0[ 0], 128, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
644  twiddle(&tmp1[96], &tmp0[ 0], 128, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
645  twiddle(src + 128, &tmp0[128], 128, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
646  twiddle(src + 160, &tmp0[128], 128, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
647  twiddle(src + 192, &tmp0[128], 128, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
648  twiddle(src + 224, &tmp0[128], 128, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
649  twiddle(src + 256, &tmp0[256], 128, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
650  twiddle(src + 320, &tmp0[256], 128, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
651 
652  wtf_end_512(c, out, src, tmp0, tmp1);
653  } else {
654  twiddle(src, &tmp0[ 0], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
655  twiddle(src + 16, &tmp0[ 0], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
656  twiddle(src + 32, &tmp0[ 32], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
657  twiddle(src + 48, &tmp0[ 32], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
658  twiddle(src + 64, &tmp0[ 64], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
659  twiddle(src + 80, &tmp0[ 64], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
660  twiddle(src + 96, &tmp0[ 96], 32, ff_on2avc_tab_20_2, 20, 2, 4, 5, ff_on2avc_tabs_9_20_2);
661  twiddle(src + 112, &tmp0[ 96], 32, ff_on2avc_tab_20_1, 20, 2, 5, 4, ff_on2avc_tabs_9_20_1);
662  twiddle(&tmp0[ 0], &tmp1[ 0], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
663  twiddle(&tmp0[32], &tmp1[ 0], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
664  twiddle(&tmp0[64], &tmp1[ 64], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
665  twiddle(&tmp0[96], &tmp1[ 64], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
666  twiddle(src + 128, &tmp1[128], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
667  twiddle(src + 160, &tmp1[128], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
668  twiddle(src + 192, &tmp1[192], 64, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
669  twiddle(src + 224, &tmp1[192], 64, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
670 
671  memset(tmp0, 0, 128 * sizeof(*tmp0));
672 
673  twiddle(&tmp1[ 0], &tmp0[ 0], 256, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
674  twiddle(&tmp1[ 64], &tmp0[ 0], 256, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
675  twiddle(&tmp1[128], &tmp0[ 0], 256, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
676  twiddle(&tmp1[192], &tmp0[ 0], 256, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
677  twiddle(src + 256, &tmp0[256], 256, ff_on2avc_tab_84_4, 84, 4, 15, 5, ff_on2avc_tabs_20_84_4);
678  twiddle(src + 320, &tmp0[256], 256, ff_on2avc_tab_84_3, 84, 4, 13, 7, ff_on2avc_tabs_20_84_3);
679  twiddle(src + 384, &tmp0[256], 256, ff_on2avc_tab_84_2, 84, 4, 16, 4, ff_on2avc_tabs_20_84_2);
680  twiddle(src + 448, &tmp0[256], 256, ff_on2avc_tab_84_1, 84, 4, 16, 4, ff_on2avc_tabs_20_84_1);
681  twiddle(src + 512, &tmp0[512], 256, ff_on2avc_tab_40_1, 40, 2, 11, 8, ff_on2avc_tabs_19_40_1);
682  twiddle(src + 640, &tmp0[512], 256, ff_on2avc_tab_40_2, 40, 2, 8, 11, ff_on2avc_tabs_19_40_2);
683 
684  wtf_end_1024(c, out, src, tmp0, tmp1);
685  }
686 }
687 
689 {
690  int ch, i;
691 
692  for (ch = 0; ch < c->avctx->channels; ch++) {
693  float *out = (float*)dst->extended_data[ch] + offset;
694  float *in = c->coeffs[ch];
695  float *saved = c->delay[ch];
696  float *buf = c->mdct_buf;
697  float *wout = out + 448;
698 
699  switch (c->window_type) {
700  case WINDOW_TYPE_EXT7:
701  c->mdct.imdct_half(&c->mdct, buf, in);
702  break;
703  case WINDOW_TYPE_EXT4:
704  c->wtf(c, buf, in, 1024);
705  break;
706  case WINDOW_TYPE_EXT5:
707  c->wtf(c, buf, in, 512);
708  c->mdct.imdct_half(&c->mdct_half, buf + 512, in + 512);
709  for (i = 0; i < 256; i++) {
710  FFSWAP(float, buf[i + 512], buf[1023 - i]);
711  }
712  break;
713  case WINDOW_TYPE_EXT6:
714  c->mdct.imdct_half(&c->mdct_half, buf, in);
715  for (i = 0; i < 256; i++) {
716  FFSWAP(float, buf[i], buf[511 - i]);
717  }
718  c->wtf(c, buf + 512, in + 512, 512);
719  break;
720  }
721 
722  memcpy(out, saved, 448 * sizeof(float));
723  c->fdsp->vector_fmul_window(wout, saved + 448, buf, c->short_win, 64);
724  memcpy(wout + 128, buf + 64, 448 * sizeof(float));
725  memcpy(saved, buf + 512, 448 * sizeof(float));
726  memcpy(saved + 448, buf + 7*128 + 64, 64 * sizeof(float));
727  }
728 
729  return 0;
730 }
731 
732 // not borrowed from aacdec.c - the codec has original design after all
734  AVFrame *dst, int offset)
735 {
736  int i;
737  float *out = (float*)dst->extended_data[channel] + offset;
738  float *in = c->coeffs[channel];
739  float *saved = c->delay[channel];
740  float *buf = c->mdct_buf;
741  float *temp = c->temp;
742 
743  switch (c->window_type) {
746  case WINDOW_TYPE_LONG:
747  c->mdct.imdct_half(&c->mdct, buf, in);
748  break;
749  case WINDOW_TYPE_8SHORT:
750  for (i = 0; i < ON2AVC_SUBFRAME_SIZE; i += ON2AVC_SUBFRAME_SIZE / 8)
751  c->mdct_small.imdct_half(&c->mdct_small, buf + i, in + i);
752  break;
753  }
754 
755  if ((c->prev_window_type == WINDOW_TYPE_LONG ||
757  (c->window_type == WINDOW_TYPE_LONG ||
759  c->fdsp->vector_fmul_window(out, saved, buf, c->long_win, 512);
760  } else {
761  float *wout = out + 448;
762  memcpy(out, saved, 448 * sizeof(float));
763 
764  if (c->window_type == WINDOW_TYPE_8SHORT) {
765  c->fdsp->vector_fmul_window(wout + 0*128, saved + 448, buf + 0*128, c->short_win, 64);
766  c->fdsp->vector_fmul_window(wout + 1*128, buf + 0*128 + 64, buf + 1*128, c->short_win, 64);
767  c->fdsp->vector_fmul_window(wout + 2*128, buf + 1*128 + 64, buf + 2*128, c->short_win, 64);
768  c->fdsp->vector_fmul_window(wout + 3*128, buf + 2*128 + 64, buf + 3*128, c->short_win, 64);
769  c->fdsp->vector_fmul_window(temp, buf + 3*128 + 64, buf + 4*128, c->short_win, 64);
770  memcpy(wout + 4*128, temp, 64 * sizeof(float));
771  } else {
772  c->fdsp->vector_fmul_window(wout, saved + 448, buf, c->short_win, 64);
773  memcpy(wout + 128, buf + 64, 448 * sizeof(float));
774  }
775  }
776 
777  // buffer update
778  switch (c->window_type) {
779  case WINDOW_TYPE_8SHORT:
780  memcpy(saved, temp + 64, 64 * sizeof(float));
781  c->fdsp->vector_fmul_window(saved + 64, buf + 4*128 + 64, buf + 5*128, c->short_win, 64);
782  c->fdsp->vector_fmul_window(saved + 192, buf + 5*128 + 64, buf + 6*128, c->short_win, 64);
783  c->fdsp->vector_fmul_window(saved + 320, buf + 6*128 + 64, buf + 7*128, c->short_win, 64);
784  memcpy(saved + 448, buf + 7*128 + 64, 64 * sizeof(float));
785  break;
787  memcpy(saved, buf + 512, 448 * sizeof(float));
788  memcpy(saved + 448, buf + 7*128 + 64, 64 * sizeof(float));
789  break;
791  case WINDOW_TYPE_LONG:
792  memcpy(saved, buf + 512, 512 * sizeof(float));
793  break;
794  }
795  return 0;
796 }
797 
799  int buf_size, AVFrame *dst, int offset)
800 {
801  GetBitContext gb;
802  int i, ret;
803 
804  if ((ret = init_get_bits8(&gb, buf, buf_size)) < 0)
805  return ret;
806 
807  if (get_bits1(&gb)) {
808  av_log(c->avctx, AV_LOG_ERROR, "enh bit set\n");
809  return AVERROR_INVALIDDATA;
810  }
812  c->window_type = get_bits(&gb, 3);
813 
816  c->num_bands = c->modes[c->window_type].num_bands;
818 
819  c->grouping[0] = 1;
820  for (i = 1; i < c->num_windows; i++)
821  c->grouping[i] = !get_bits1(&gb);
822 
823  on2avc_read_ms_info(c, &gb);
824  for (i = 0; i < c->avctx->channels; i++)
825  if ((ret = on2avc_read_channel_data(c, &gb, i)) < 0)
826  return AVERROR_INVALIDDATA;
827  if (c->avctx->channels == 2 && c->ms_present)
828  on2avc_apply_ms(c);
829  if (c->window_type < WINDOW_TYPE_EXT4) {
830  for (i = 0; i < c->avctx->channels; i++)
831  on2avc_reconstruct_channel(c, i, dst, offset);
832  } else {
833  on2avc_reconstruct_channel_ext(c, dst, offset);
834  }
835 
836  return 0;
837 }
838 
840  int *got_frame_ptr, AVPacket *avpkt)
841 {
842  AVFrame *frame = data;
843  const uint8_t *buf = avpkt->data;
844  int buf_size = avpkt->size;
845  On2AVCContext *c = avctx->priv_data;
846  GetByteContext gb;
847  int num_frames = 0, frame_size, audio_off;
848  int ret;
849 
850  if (c->is_av500) {
851  /* get output buffer */
853  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
854  return ret;
855 
856  if ((ret = on2avc_decode_subframe(c, buf, buf_size, frame, 0)) < 0)
857  return ret;
858  } else {
859  bytestream2_init(&gb, buf, buf_size);
860  while (bytestream2_get_bytes_left(&gb) > 2) {
861  frame_size = bytestream2_get_le16(&gb);
863  av_log(avctx, AV_LOG_ERROR, "Invalid subframe size %d\n",
864  frame_size);
865  return AVERROR_INVALIDDATA;
866  }
867  num_frames++;
869  }
870  if (!num_frames) {
871  av_log(avctx, AV_LOG_ERROR, "No subframes present\n");
872  return AVERROR_INVALIDDATA;
873  }
874 
875  /* get output buffer */
876  frame->nb_samples = ON2AVC_SUBFRAME_SIZE * num_frames;
877  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
878  return ret;
879 
880  audio_off = 0;
881  bytestream2_init(&gb, buf, buf_size);
882  while (bytestream2_get_bytes_left(&gb) > 2) {
883  frame_size = bytestream2_get_le16(&gb);
884  if ((ret = on2avc_decode_subframe(c, gb.buffer, frame_size,
885  frame, audio_off)) < 0)
886  return ret;
887  audio_off += ON2AVC_SUBFRAME_SIZE;
889  }
890  }
891 
892  *got_frame_ptr = 1;
893 
894  return buf_size;
895 }
896 
898 {
899  int i;
900 
901  ff_free_vlc(&c->scale_diff);
902  for (i = 1; i < 16; i++)
903  ff_free_vlc(&c->cb_vlc[i]);
904 }
905 
907 {
908  On2AVCContext *c = avctx->priv_data;
909  int i;
910 
911  if (avctx->channels > 2U) {
912  avpriv_request_sample(avctx, "Decoding more than 2 channels");
913  return AVERROR_PATCHWELCOME;
914  }
915 
916  c->avctx = avctx;
918  avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO
920 
921  c->is_av500 = (avctx->codec_tag == 0x500);
922 
923  if (avctx->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  for (i = 0; i < 20; i++)
931  c->scale_tab[i] = ceil(ff_exp10(i * 0.1) * 16 - 0.01) / 32;
932  for (; i < 128; i++)
933  c->scale_tab[i] = ceil(ff_exp10(i * 0.1) * 0.5 - 0.01);
934 
935  if (avctx->sample_rate < 32000 || avctx->channels == 1)
937  1024 * sizeof(*c->long_win));
938  else
940  1024 * sizeof(*c->long_win));
941  memcpy(c->short_win, ff_on2avc_window_short, 128 * sizeof(*c->short_win));
942 
943  c->modes = (avctx->sample_rate <= 40000) ? ff_on2avc_modes_40
945  c->wtf = (avctx->sample_rate <= 40000) ? wtf_40
946  : wtf_44;
947 
948  ff_mdct_init(&c->mdct, 11, 1, 1.0 / (32768.0 * 1024.0));
949  ff_mdct_init(&c->mdct_half, 10, 1, 1.0 / (32768.0 * 512.0));
950  ff_mdct_init(&c->mdct_small, 8, 1, 1.0 / (32768.0 * 128.0));
951  ff_fft_init(&c->fft128, 6, 0);
952  ff_fft_init(&c->fft256, 7, 0);
953  ff_fft_init(&c->fft512, 8, 1);
954  ff_fft_init(&c->fft1024, 9, 1);
956  if (!c->fdsp)
957  return AVERROR(ENOMEM);
958 
961  ff_on2avc_scale_diff_codes, 4, 4, 0)) {
962  goto vlc_fail;
963  }
964  for (i = 1; i < 9; i++) {
965  int idx = i - 1;
967  ff_on2avc_quad_cb_bits[idx], 1, 1,
968  ff_on2avc_quad_cb_codes[idx], 4, 4,
969  ff_on2avc_quad_cb_syms[idx], 2, 2, 0)) {
970  goto vlc_fail;
971  }
972  }
973  for (i = 9; i < 16; i++) {
974  int idx = i - 9;
976  ff_on2avc_pair_cb_bits[idx], 1, 1,
977  ff_on2avc_pair_cb_codes[idx], 2, 2,
978  ff_on2avc_pair_cb_syms[idx], 2, 2, 0)) {
979  goto vlc_fail;
980  }
981  }
982 
983  return 0;
984 vlc_fail:
985  av_log(avctx, AV_LOG_ERROR, "Cannot init VLC\n");
986  on2avc_free_vlcs(c);
987  av_freep(&c->fdsp);
988  return AVERROR(ENOMEM);
989 }
990 
992 {
993  On2AVCContext *c = avctx->priv_data;
994 
995  ff_mdct_end(&c->mdct);
996  ff_mdct_end(&c->mdct_half);
997  ff_mdct_end(&c->mdct_small);
998  ff_fft_end(&c->fft128);
999  ff_fft_end(&c->fft256);
1000  ff_fft_end(&c->fft512);
1001  ff_fft_end(&c->fft1024);
1002 
1003  av_freep(&c->fdsp);
1004 
1005  on2avc_free_vlcs(c);
1006 
1007  return 0;
1008 }
1009 
1010 
1012  .name = "on2avc",
1013  .long_name = NULL_IF_CONFIG_SMALL("On2 Audio for Video Codec"),
1014  .type = AVMEDIA_TYPE_AUDIO,
1015  .id = AV_CODEC_ID_ON2AVC,
1016  .priv_data_size = sizeof(On2AVCContext),
1019  .close = on2avc_decode_close,
1020  .capabilities = AV_CODEC_CAP_DR1,
1021  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1023 };
static int on2avc_reconstruct_channel_ext(On2AVCContext *c, AVFrame *dst, int offset)
Definition: on2avc.c:688
float, planar
Definition: samplefmt.h:69
#define NULL
Definition: coverity.c:32
const double *const ff_on2avc_tabs_4_10_1[4]
Definition: on2avcdata.c:7644
const char const char void * val
Definition: avisynth_c.h:771
void(* wtf)(struct On2AVCContext *ctx, float *out, float *in, int size)
Definition: on2avc.c:52
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
static int on2avc_read_channel_data(On2AVCContext *c, GetBitContext *gb, int ch)
Definition: on2avc.c:253
const double ff_on2avc_tab_20_1[]
Definition: on2avcdata.c:7454
This structure describes decoded (raw) audio or video data.
Definition: frame.h:201
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
const uint8_t *const ff_on2avc_pair_cb_bits[]
Definition: on2avcdata.c:6873
float coeffs[2][ON2AVC_SUBFRAME_SIZE]
Definition: on2avc.c:79
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:261
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
float scale_tab[128]
Definition: on2avc.c:77
else temp
Definition: vf_mcdeint.c:256
float delay[2][ON2AVC_SUBFRAME_SIZE]
Definition: on2avc.c:80
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
const On2AVCMode ff_on2avc_modes_40[8]
Definition: on2avcdata.c:91
int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
Definition: bitstream.c:268
int size
Definition: avcodec.h:1401
static void on2avc_read_ms_info(On2AVCContext *c, GetBitContext *gb)
Definition: on2avc.c:88
const char * b
Definition: vf_curves.c:113
#define CMUL0(dst, id, s0, s1, s2, s3, t0, t1, t2, t3, is, it)
Definition: on2avc.c:387
void(* fft_permute)(struct FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling fft_calc().
Definition: fft.h:101
AVCodecContext * avctx
Definition: on2avc.c:48
const double ff_on2avc_tab_84_4[]
Definition: on2avcdata.c:7594
int num_sections
Definition: on2avc.c:70
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:133
const int ff_on2avc_quad_cb_elems[]
Definition: on2avcdata.c:6863
int num_windows
Definition: on2avcdata.h:32
uint8_t run
Definition: svq3.c:206
#define AV_CH_LAYOUT_STEREO
#define src
Definition: vp8dsp.c:254
AVCodec.
Definition: avcodec.h:3351
float mdct_buf[ON2AVC_SUBFRAME_SIZE]
Definition: on2avc.c:83
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:42
static int on2avc_apply_ms(On2AVCContext *c)
Definition: on2avc.c:290
static float on2avc_scale(int v, float scale)
Definition: on2avc.c:186
static int on2avc_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: on2avc.c:839
static const uint8_t run_len[7][16]
Definition: h264_cavlc.c:219
const uint16_t *const ff_on2avc_pair_cb_codes[]
Definition: on2avcdata.c:6868
int num_bands
Definition: on2avc.c:58
const float ff_on2avc_window_short[128]
Definition: on2avcdata.c:7406
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
void(* vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, int len)
Overlap/add with window function.
Definition: float_dsp.h:119
uint8_t band_type[ON2AVC_MAX_BANDS]
Definition: on2avc.c:68
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2151
uint8_t
#define av_cold
Definition: attributes.h:82
const On2AVCMode * modes
Definition: on2avc.c:56
static void wtf_end_1024(On2AVCContext *c, float *out, float *src, float *tmp0, float *tmp1)
Definition: on2avc.c:495
static av_cold int on2avc_decode_init(AVCodecContext *avctx)
Definition: on2avc.c:906
const double ff_on2avc_tab_84_1[]
Definition: on2avcdata.c:7501
#define t0
Definition: regdef.h:28
const float ff_on2avc_ctab_1[2048]
Definition: on2avcdata.c:8861
static AVFrame * frame
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
Definition: mem.h:112
uint8_t * data
Definition: avcodec.h:1400
const uint8_t * buffer
Definition: bytestream.h:34
static int on2avc_decode_band_types(On2AVCContext *c, GetBitContext *gb)
Definition: on2avc.c:109
const double *const ff_on2avc_tabs_20_84_1[20]
Definition: on2avcdata.c:8829
bitstream reader API header.
int window_type
Definition: on2avc.c:57
static void wtf_40(On2AVCContext *c, float *out, float *src, int size)
Definition: on2avc.c:528
const uint32_t *const ff_on2avc_quad_cb_codes[]
Definition: on2avcdata.c:6848
ptrdiff_t size
Definition: opengl_enc.c:101
uint8_t band_run_end[ON2AVC_MAX_BANDS]
Definition: on2avc.c:69
const uint32_t ff_on2avc_scale_diff_codes[ON2AVC_SCALE_DIFFS]
Definition: on2avcdata.c:113
#define av_log(a,...)
const double ff_on2avc_tab_84_2[]
Definition: on2avcdata.c:7532
const double ff_on2avc_tab_40_2[]
Definition: on2avcdata.c:7484
static int on2avc_decode_subframe(On2AVCContext *c, const uint8_t *buf, int buf_size, AVFrame *dst, int offset)
Definition: on2avc.c:798
#define U(x)
Definition: vp56_arith.h:37
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
Definition: ffmath.h:42
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:127
#define s2
Definition: regdef.h:39
static const uint16_t mask[17]
Definition: lzw.c:38
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
Definition: vlc.h:38
const double *const ff_on2avc_tabs_9_20_2[9]
Definition: on2avcdata.c:7732
int is_av500
Definition: on2avc.c:54
#define AVERROR(e)
Definition: error.h:43
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:164
#define CMUL1(dst, s0, s1, s2, s3, t0, t1, t2, t3, is, it)
Definition: on2avc.c:393
#define CMUL2(dst, s0, s1, s2, s3, t0, t1, t2, t3, is, it)
Definition: on2avc.c:403
const float ff_on2avc_window_long_24000[1024]
Definition: on2avcdata.c:7147
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
const char * r
Definition: vf_curves.c:111
#define s0
Definition: regdef.h:37
#define t1
Definition: regdef.h:29
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:154
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:1568
const char * name
Name of the codec implementation.
Definition: avcodec.h:3358
#define ff_mdct_init
Definition: fft.h:169
#define t3
Definition: regdef.h:31
const double ff_on2avc_tab_20_2[]
Definition: on2avcdata.c:7461
const uint16_t *const ff_on2avc_pair_cb_syms[]
Definition: on2avcdata.c:6878
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
int bits_per_section
Definition: on2avc.c:59
const double ff_on2avc_tab_40_1[]
Definition: on2avcdata.c:7471
Definition: vlc.h:26
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2194
static int get_egolomb(GetBitContext *gb)
Definition: on2avc.c:209
const double *const ff_on2avc_tabs_9_20_1[9]
Definition: on2avcdata.c:7727
const uint16_t *const ff_on2avc_quad_cb_syms[]
Definition: on2avcdata.c:6858
static av_cold void on2avc_free_vlcs(On2AVCContext *c)
Definition: on2avc.c:897
Definition: fft.h:88
audio channel layout utility functions
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:883
static int on2avc_reconstruct_channel(On2AVCContext *c, int channel, AVFrame *dst, int offset)
Definition: on2avc.c:733
static void wtf_end_512(On2AVCContext *c, float *out, float *src, float *tmp0, float *tmp1)
Definition: on2avc.c:462
int ms_info[ON2AVC_MAX_BANDS]
Definition: on2avc.c:64
float short_win[ON2AVC_SUBFRAME_SIZE/8]
Definition: on2avc.c:85
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
VLC scale_diff
Definition: on2avc.c:74
#define ff_fft_init
Definition: fft.h:149
static void twiddle(float *src1, float *src2, int src2_len, const double *tab, int tab_len, int step, int order0, int order1, const double *const *tabs)
Definition: on2avc.c:348
AVFormatContext * ctx
Definition: movenc.c:48
static void pretwiddle(float *src, float *dst, int dst_len, int tab_step, int step, int order0, int order1, const double *const *tabs)
Definition: on2avc.c:321
#define ON2AVC_ESC_CB
Definition: on2avcdata.h:29
const int ff_on2avc_pair_cb_elems[]
Definition: on2avcdata.c:6883
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:554
WindowTypes
Definition: on2avc.c:36
const On2AVCMode ff_on2avc_modes_44[8]
Definition: on2avcdata.c:102
FFTContext mdct
Definition: on2avc.c:50
#define s3
Definition: regdef.h:40
int grouping[8]
Definition: on2avc.c:62
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
float long_win[ON2AVC_SUBFRAME_SIZE]
Definition: on2avc.c:84
#define ON2AVC_SUBFRAME_SIZE
Definition: on2avc.c:34
const double *const ff_on2avc_tabs_4_10_2[4]
Definition: on2avcdata.c:7648
const uint8_t *const ff_on2avc_quad_cb_bits[]
Definition: on2avcdata.c:6853
const uint8_t ff_on2avc_scale_diff_bits[ON2AVC_SCALE_DIFFS]
Definition: on2avcdata.c:137
#define src1
Definition: h264pred.c:139
int frame_size
Definition: mxfenc.c:1947
Libavcodec external API header.
static int on2avc_decode_quads(On2AVCContext *c, GetBitContext *gb, float *dst, int dst_size, int type, float band_scale)
Definition: on2avc.c:192
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
int sample_rate
samples per second
Definition: avcodec.h:2143
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:456
int ms_present
Definition: on2avc.c:63
int num_windows
Definition: on2avc.c:58
main external API structure.
Definition: avcodec.h:1488
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1513
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1886
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
const float ff_on2avc_ctab_2[2048]
Definition: on2avcdata.c:8992
void * buf
Definition: avisynth_c.h:690
FFTContext fft128
Definition: on2avc.c:51
void(* imdct_half)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
Definition: fft.h:108
GLint GLenum type
Definition: opengl_enc.c:105
VLC cb_vlc[16]
Definition: on2avc.c:75
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:313
AVCodec ff_on2avc_decoder
Definition: on2avc.c:1011
const double ff_on2avc_tab_10_2[]
Definition: on2avcdata.c:7446
int num_bands
Definition: on2avcdata.h:33
#define s1
Definition: regdef.h:38
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:346
const double *const ff_on2avc_tabs_20_84_4[20]
Definition: on2avcdata.c:8853
static av_const int sign_extend(int val, unsigned bits)
Definition: mathops.h:130
const float ff_on2avc_ctab_4[2048]
Definition: on2avcdata.c:9254
internal math functions header
const int * band_start
Definition: on2avc.c:60
AVFloatDSPContext * fdsp
Definition: on2avc.c:49
common internal api header.
static av_cold int on2avc_decode_close(AVCodecContext *avctx)
Definition: on2avc.c:991
#define ON2AVC_MAX_BANDS
Definition: on2avcdata.h:28
#define ff_mdct_end
Definition: fft.h:170
static double c[64]
channel
Use these values when setting the channel map with ebur128_set_channel().
Definition: ebur128.h:39
const double *const ff_on2avc_tabs_20_84_2[20]
Definition: on2avcdata.c:8837
FFTContext fft256
Definition: on2avc.c:51
#define ff_fft_end
Definition: fft.h:150
void(* fft_calc)(struct FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in ff_fft_init().
Definition: fft.h:106
FFTContext mdct_half
Definition: on2avc.c:50
void * priv_data
Definition: avcodec.h:1515
static void zero_head_and_tail(float *src, int len, int order0, int order1)
Definition: on2avc.c:315
int prev_window_type
Definition: on2avc.c:57
const double ff_on2avc_tab_84_3[]
Definition: on2avcdata.c:7563
const int * band_start
Definition: on2avcdata.h:34
FFTContext mdct_small
Definition: on2avc.c:50
FFTContext fft1024
Definition: on2avc.c:51
float temp[ON2AVC_SUBFRAME_SIZE *2]
Definition: on2avc.c:82
int is_long
Definition: on2avc.c:66
int len
int channels
number of audio channels
Definition: avcodec.h:2144
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
static int on2avc_decode_pairs(On2AVCContext *c, GetBitContext *gb, float *dst, int dst_size, int type, float band_scale)
Definition: on2avc.c:225
const float ff_on2avc_window_long_32000[1024]
Definition: on2avcdata.c:6888
const double *const ff_on2avc_tabs_19_40_1[19]
Definition: on2avcdata.c:7930
static const struct @105 tabs[]
static const struct twinvq_data tab
const double *const ff_on2avc_tabs_19_40_2[19]
Definition: on2avcdata.c:7938
const double *const ff_on2avc_tabs_20_84_3[20]
Definition: on2avcdata.c:8845
static int on2avc_decode_band_scales(On2AVCContext *c, GetBitContext *gb)
Definition: on2avc.c:139
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
FILE * out
Definition: movenc.c:54
const float ff_on2avc_ctab_3[2048]
Definition: on2avcdata.c:9123
#define av_freep(p)
static void wtf_44(On2AVCContext *c, float *out, float *src, int size)
Definition: on2avc.c:614
#define ON2AVC_SCALE_DIFFS
Definition: on2avcdata.h:40
static void combine_fft(float *s0, float *s1, float *s2, float *s3, float *dst, const float *t0, const float *t1, const float *t2, const float *t3, int len, int step)
Definition: on2avc.c:413
#define FFSWAP(type, a, b)
Definition: common.h:99
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:248
#define AV_CH_LAYOUT_MONO
This structure stores compressed data.
Definition: avcodec.h:1377
void ff_free_vlc(VLC *vlc)
Definition: bitstream.c:354
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:267
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:956
float band_scales[ON2AVC_MAX_BANDS]
Definition: on2avc.c:72
#define t2
Definition: regdef.h:30
FFTContext fft512
Definition: on2avc.c:51
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
static uint8_t tmp[11]
Definition: aes_ctr.c:26
const double ff_on2avc_tab_10_1[]
Definition: on2avcdata.c:7441