FFmpeg
vorbisdec.c
Go to the documentation of this file.
1 /**
2  * @file
3  * Vorbis I decoder
4  * @author Denes Balatoni ( dbalatoni programozo hu )
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 /**
24  * @file
25  * Vorbis I decoder
26  * @author Denes Balatoni ( dbalatoni programozo hu )
27  */
28 
29 #include <inttypes.h>
30 #include <math.h>
31 
32 #include "libavutil/avassert.h"
33 #include "libavutil/float_dsp.h"
34 #include "libavutil/tx.h"
35 
36 #define BITSTREAM_READER_LE
37 #include "avcodec.h"
38 #include "codec_internal.h"
39 #include "decode.h"
40 #include "get_bits.h"
41 #include "internal.h"
42 #include "vorbis.h"
43 #include "vorbisdsp.h"
44 #include "vorbis_data.h"
45 #include "xiph.h"
46 
47 #define V_NB_BITS 8
48 #define V_NB_BITS2 11
49 #define V_MAX_VLCS (1 << 16)
50 #define V_MAX_PARTITIONS (1 << 20)
51 
52 typedef struct vorbis_codebook {
53  uint8_t dimensions;
54  uint8_t lookup_type;
55  uint8_t maxdepth;
57  float *codevectors;
58  unsigned int nb_bits;
60 
61 typedef union vorbis_floor_u vorbis_floor_data;
62 typedef struct vorbis_floor0_s vorbis_floor0;
63 typedef struct vorbis_floor1_s vorbis_floor1;
64 struct vorbis_context_s;
65 typedef
67  (struct vorbis_context_s *, vorbis_floor_data *, float *);
68 typedef struct vorbis_floor {
69  uint8_t floor_type;
72  struct vorbis_floor0_s {
73  uint8_t order;
74  uint16_t rate;
75  uint16_t bark_map_size;
76  int32_t *map[2];
77  uint32_t map_size[2];
78  uint8_t amplitude_bits;
80  uint8_t num_books;
81  uint8_t *book_list;
82  float *lsp;
83  } t0;
84  struct vorbis_floor1_s {
85  uint8_t partitions;
86  uint8_t partition_class[32];
87  uint8_t class_dimensions[16];
88  uint8_t class_subclasses[16];
89  uint8_t class_masterbook[16];
90  int16_t subclass_books[16][8];
91  uint8_t multiplier;
92  uint16_t x_list_dim;
94  } t1;
95  } data;
96 } vorbis_floor;
97 
98 typedef struct vorbis_residue {
99  uint16_t type;
100  uint32_t begin;
101  uint32_t end;
102  unsigned partition_size;
104  uint8_t classbook;
105  int16_t books[64][8];
106  uint8_t maxpass;
107  uint16_t ptns_to_read;
108  uint8_t *classifs;
110 
111 typedef struct vorbis_mapping {
112  uint8_t submaps;
113  uint16_t coupling_steps;
114  uint8_t *magnitude;
115  uint8_t *angle;
116  uint8_t *mux;
117  uint8_t submap_floor[16];
118  uint8_t submap_residue[16];
120 
121 typedef struct vorbis_mode {
122  uint8_t blockflag;
123  uint16_t windowtype;
124  uint16_t transformtype;
125  uint8_t mapping;
126 } vorbis_mode;
127 
128 typedef struct vorbis_context_s {
133 
136 
137  uint8_t first_frame;
138  uint32_t version;
139  uint8_t audio_channels;
141  uint32_t bitrate_maximum;
142  uint32_t bitrate_nominal;
143  uint32_t bitrate_minimum;
144  uint32_t blocksize[2];
145  const float *win[2];
146  uint16_t codebook_count;
148  uint8_t floor_count;
150  uint8_t residue_count;
152  uint8_t mapping_count;
154  uint8_t mode_count;
156  uint8_t mode_number; // mode number for the current packet
159  float *saved;
160 } vorbis_context;
161 
162 /* Helper functions */
163 
164 #define BARK(x) \
165  (13.1f * atan(0.00074f * (x)) + 2.24f * atan(1.85e-8f * (x) * (x)) + 1e-4f * (x))
166 
167 static const char idx_err_str[] = "Index value %d out of range (0 - %d) for %s at %s:%i\n";
168 #define VALIDATE_INDEX(idx, limit) \
169  if (idx >= limit) {\
170  av_log(vc->avctx, AV_LOG_ERROR,\
171  idx_err_str,\
172  (int)(idx), (int)(limit - 1), #idx, __FILE__, __LINE__);\
173  return AVERROR_INVALIDDATA;\
174  }
175 #define GET_VALIDATED_INDEX(idx, bits, limit) \
176  {\
177  idx = get_bits(gb, bits);\
178  VALIDATE_INDEX(idx, limit)\
179  }
180 
181 static float vorbisfloat2float(unsigned val)
182 {
183  double mant = val & 0x1fffff;
184  long exp = (val & 0x7fe00000L) >> 21;
185  if (val & 0x80000000)
186  mant = -mant;
187  return ldexp(mant, exp - 20 - 768);
188 }
189 
190 
191 // Free all allocated memory -----------------------------------------
192 
193 static void vorbis_free(vorbis_context *vc)
194 {
195  int i;
196 
197  av_freep(&vc->channel_residues);
198  av_freep(&vc->saved);
199  av_freep(&vc->fdsp);
200 
201  if (vc->residues)
202  for (i = 0; i < vc->residue_count; i++)
203  av_freep(&vc->residues[i].classifs);
204  av_freep(&vc->residues);
205  av_freep(&vc->modes);
206 
207  av_tx_uninit(&vc->mdct[0]);
208  av_tx_uninit(&vc->mdct[1]);
209 
210  if (vc->codebooks)
211  for (i = 0; i < vc->codebook_count; ++i) {
212  av_freep(&vc->codebooks[i].codevectors);
213  ff_vlc_free(&vc->codebooks[i].vlc);
214  }
215  av_freep(&vc->codebooks);
216 
217  if (vc->floors)
218  for (i = 0; i < vc->floor_count; ++i) {
219  if (vc->floors[i].floor_type == 0) {
220  av_freep(&vc->floors[i].data.t0.map[0]);
221  av_freep(&vc->floors[i].data.t0.map[1]);
222  av_freep(&vc->floors[i].data.t0.book_list);
223  av_freep(&vc->floors[i].data.t0.lsp);
224  } else {
225  av_freep(&vc->floors[i].data.t1.list);
226  }
227  }
228  av_freep(&vc->floors);
229 
230  if (vc->mappings)
231  for (i = 0; i < vc->mapping_count; ++i) {
232  av_freep(&vc->mappings[i].magnitude);
233  av_freep(&vc->mappings[i].angle);
234  av_freep(&vc->mappings[i].mux);
235  }
236  av_freep(&vc->mappings);
237 }
238 
239 // Parse setup header -------------------------------------------------
240 
241 // Process codebooks part
242 
243 static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
244 {
245  unsigned cb;
246  uint8_t *tmp_vlc_bits = NULL;
247  uint32_t *tmp_vlc_codes = NULL;
248  GetBitContext *gb = &vc->gb;
249  uint16_t *codebook_multiplicands = NULL;
250  int ret = 0;
251 
252  vc->codebook_count = get_bits(gb, 8) + 1;
253 
254  ff_dlog(NULL, " Codebooks: %d \n", vc->codebook_count);
255 
256  vc->codebooks = av_mallocz(vc->codebook_count * sizeof(*vc->codebooks));
257  tmp_vlc_bits = av_mallocz(V_MAX_VLCS * sizeof(*tmp_vlc_bits));
258  tmp_vlc_codes = av_mallocz(V_MAX_VLCS * sizeof(*tmp_vlc_codes));
259  codebook_multiplicands = av_malloc(V_MAX_VLCS * sizeof(*codebook_multiplicands));
260  if (!vc->codebooks ||
261  !tmp_vlc_bits || !tmp_vlc_codes || !codebook_multiplicands) {
262  ret = AVERROR(ENOMEM);
263  goto error;
264  }
265 
266  for (cb = 0; cb < vc->codebook_count; ++cb) {
267  vorbis_codebook *codebook_setup = &vc->codebooks[cb];
268  unsigned ordered, t, entries, used_entries = 0;
269 
270  ff_dlog(NULL, " %u. Codebook\n", cb);
271 
272  if (get_bits(gb, 24) != 0x564342) {
273  av_log(vc->avctx, AV_LOG_ERROR,
274  " %u. Codebook setup data corrupt.\n", cb);
276  goto error;
277  }
278 
279  codebook_setup->dimensions=get_bits(gb, 16);
280  if (codebook_setup->dimensions > 16 || codebook_setup->dimensions == 0) {
281  av_log(vc->avctx, AV_LOG_ERROR,
282  " %u. Codebook's dimension is invalid (%d).\n",
283  cb, codebook_setup->dimensions);
285  goto error;
286  }
287  entries = get_bits(gb, 24);
288  if (entries > V_MAX_VLCS) {
289  av_log(vc->avctx, AV_LOG_ERROR,
290  " %u. Codebook has too many entries (%u).\n",
291  cb, entries);
293  goto error;
294  }
295 
296  ordered = get_bits1(gb);
297 
298  ff_dlog(NULL, " codebook_dimensions %d, codebook_entries %u\n",
299  codebook_setup->dimensions, entries);
300 
301  if (!ordered) {
302  unsigned ce, flag;
303  unsigned sparse = get_bits1(gb);
304 
305  ff_dlog(NULL, " not ordered \n");
306 
307  if (sparse) {
308  ff_dlog(NULL, " sparse \n");
309 
310  used_entries = 0;
311  for (ce = 0; ce < entries; ++ce) {
312  flag = get_bits1(gb);
313  if (flag) {
314  tmp_vlc_bits[ce] = get_bits(gb, 5) + 1;
315  ++used_entries;
316  } else
317  tmp_vlc_bits[ce] = 0;
318  }
319  } else {
320  ff_dlog(NULL, " not sparse \n");
321 
322  used_entries = entries;
323  for (ce = 0; ce < entries; ++ce)
324  tmp_vlc_bits[ce] = get_bits(gb, 5) + 1;
325  }
326  } else {
327  unsigned current_entry = 0;
328  unsigned current_length = get_bits(gb, 5) + 1;
329 
330  ff_dlog(NULL, " ordered, current length: %u\n", current_length); //FIXME
331 
332  used_entries = entries;
333  for (; current_entry < used_entries && current_length <= 32; ++current_length) {
334  unsigned i, number;
335 
336  ff_dlog(NULL, " number bits: %u ", ilog(entries - current_entry));
337 
338  number = get_bits(gb, ilog(entries - current_entry));
339 
340  ff_dlog(NULL, " number: %u\n", number);
341 
342  for (i = current_entry; i < number+current_entry; ++i)
343  if (i < used_entries)
344  tmp_vlc_bits[i] = current_length;
345 
346  current_entry+=number;
347  }
348  if (current_entry>used_entries) {
349  av_log(vc->avctx, AV_LOG_ERROR, " More codelengths than codes in codebook. \n");
351  goto error;
352  }
353  }
354 
355  codebook_setup->lookup_type = get_bits(gb, 4);
356 
357  ff_dlog(NULL, " lookup type: %d : %s \n", codebook_setup->lookup_type,
358  codebook_setup->lookup_type ? "vq" : "no lookup");
359 
360 // If the codebook is used for (inverse) VQ, calculate codevectors.
361 
362  if (codebook_setup->lookup_type == 1) {
363  unsigned i, j, k;
364  unsigned codebook_lookup_values = ff_vorbis_nth_root(entries, codebook_setup->dimensions);
365 
366  float codebook_minimum_value = vorbisfloat2float(get_bits_long(gb, 32));
367  float codebook_delta_value = vorbisfloat2float(get_bits_long(gb, 32));
368  unsigned codebook_value_bits = get_bits(gb, 4) + 1;
369  unsigned codebook_sequence_p = get_bits1(gb);
370 
371  if (!isfinite(codebook_minimum_value) || !isfinite(codebook_delta_value)) {
373  goto error;
374  }
375  ff_dlog(NULL, " We expect %d numbers for building the codevectors. \n",
376  codebook_lookup_values);
377  ff_dlog(NULL, " delta %f minmum %f \n",
378  codebook_delta_value, codebook_minimum_value);
379 
380  for (i = 0; i < codebook_lookup_values; ++i) {
381  codebook_multiplicands[i] = get_bits(gb, codebook_value_bits);
382 
383  ff_dlog(NULL, " multiplicands*delta+minmum : %e \n",
384  (float)codebook_multiplicands[i] * codebook_delta_value + codebook_minimum_value);
385  ff_dlog(NULL, " multiplicand %u\n", codebook_multiplicands[i]);
386  }
387 
388 // Weed out unused vlcs and build codevector vector
389  if (used_entries) {
390  codebook_setup->codevectors =
391  av_calloc(used_entries, codebook_setup->dimensions *
392  sizeof(*codebook_setup->codevectors));
393  if (!codebook_setup->codevectors) {
394  ret = AVERROR(ENOMEM);
395  goto error;
396  }
397  } else
398  codebook_setup->codevectors = NULL;
399 
400  for (j = 0, i = 0; i < entries; ++i) {
401  unsigned dim = codebook_setup->dimensions;
402 
403  if (tmp_vlc_bits[i]) {
404  float last = 0.0;
405  unsigned lookup_offset = i;
406 
407  ff_dlog(vc->avctx, "Lookup offset %u ,", i);
408 
409  for (k = 0; k < dim; ++k) {
410  unsigned multiplicand_offset = lookup_offset % codebook_lookup_values;
411  codebook_setup->codevectors[j * dim + k] = codebook_multiplicands[multiplicand_offset] * codebook_delta_value + codebook_minimum_value + last;
412  if (codebook_sequence_p)
413  last = codebook_setup->codevectors[j * dim + k];
414  lookup_offset/=codebook_lookup_values;
415  }
416  tmp_vlc_bits[j] = tmp_vlc_bits[i];
417 
418  ff_dlog(vc->avctx, "real lookup offset %u, vector: ", j);
419  for (k = 0; k < dim; ++k)
420  ff_dlog(vc->avctx, " %f ",
421  codebook_setup->codevectors[j * dim + k]);
422  ff_dlog(vc->avctx, "\n");
423 
424  ++j;
425  }
426  }
427  if (j != used_entries) {
428  av_log(vc->avctx, AV_LOG_ERROR, "Bug in codevector vector building code. \n");
430  goto error;
431  }
432  entries = used_entries;
433  } else if (codebook_setup->lookup_type >= 2) {
434  av_log(vc->avctx, AV_LOG_ERROR, "Codebook lookup type not supported. \n");
436  goto error;
437  }
438 
439 // Initialize VLC table
440  if (ff_vorbis_len2vlc(tmp_vlc_bits, tmp_vlc_codes, entries)) {
441  av_log(vc->avctx, AV_LOG_ERROR, " Invalid code lengths while generating vlcs. \n");
443  goto error;
444  }
445  codebook_setup->maxdepth = 0;
446  for (t = 0; t < entries; ++t)
447  if (tmp_vlc_bits[t] >= codebook_setup->maxdepth)
448  codebook_setup->maxdepth = tmp_vlc_bits[t];
449 
450  if (codebook_setup->maxdepth > 3 * V_NB_BITS)
451  codebook_setup->nb_bits = V_NB_BITS2;
452  else
453  codebook_setup->nb_bits = V_NB_BITS;
454 
455  codebook_setup->maxdepth = (codebook_setup->maxdepth+codebook_setup->nb_bits - 1) / codebook_setup->nb_bits;
456 
457  if ((ret = vlc_init(&codebook_setup->vlc, codebook_setup->nb_bits,
458  entries, tmp_vlc_bits, sizeof(*tmp_vlc_bits),
459  sizeof(*tmp_vlc_bits), tmp_vlc_codes,
460  sizeof(*tmp_vlc_codes), sizeof(*tmp_vlc_codes),
461  VLC_INIT_LE))) {
462  av_log(vc->avctx, AV_LOG_ERROR, " Error generating vlc tables. \n");
463  goto error;
464  }
465  }
466 
467  av_free(tmp_vlc_bits);
468  av_free(tmp_vlc_codes);
469  av_free(codebook_multiplicands);
470  return 0;
471 
472 // Error:
473 error:
474  av_free(tmp_vlc_bits);
475  av_free(tmp_vlc_codes);
476  av_free(codebook_multiplicands);
477  return ret;
478 }
479 
480 // Process time domain transforms part (unused in Vorbis I)
481 
482 static int vorbis_parse_setup_hdr_tdtransforms(vorbis_context *vc)
483 {
484  GetBitContext *gb = &vc->gb;
485  unsigned i, vorbis_time_count = get_bits(gb, 6) + 1;
486 
487  for (i = 0; i < vorbis_time_count; ++i) {
488  unsigned vorbis_tdtransform = get_bits(gb, 16);
489 
490  ff_dlog(NULL, " Vorbis time domain transform %u: %u\n",
491  vorbis_time_count, vorbis_tdtransform);
492 
493  if (vorbis_tdtransform) {
494  av_log(vc->avctx, AV_LOG_ERROR, "Vorbis time domain transform data nonzero. \n");
495  return AVERROR_INVALIDDATA;
496  }
497  }
498  return 0;
499 }
500 
501 // Process floors part
502 
503 static int vorbis_floor0_decode(vorbis_context *vc,
504  vorbis_floor_data *vfu, float *vec);
505 static int create_map(vorbis_context *vc, unsigned floor_number);
506 static int vorbis_floor1_decode(vorbis_context *vc,
507  vorbis_floor_data *vfu, float *vec);
508 static int vorbis_parse_setup_hdr_floors(vorbis_context *vc)
509 {
510  GetBitContext *gb = &vc->gb;
511  int i, j, k, ret;
512 
513  vc->floor_count = get_bits(gb, 6) + 1;
514 
515  vc->floors = av_mallocz(vc->floor_count * sizeof(*vc->floors));
516  if (!vc->floors)
517  return AVERROR(ENOMEM);
518 
519  for (i = 0; i < vc->floor_count; ++i) {
520  vorbis_floor *floor_setup = &vc->floors[i];
521 
522  floor_setup->floor_type = get_bits(gb, 16);
523 
524  ff_dlog(NULL, " %d. floor type %d \n", i, floor_setup->floor_type);
525 
526  if (floor_setup->floor_type == 1) {
527  int maximum_class = -1;
528  unsigned rangebits, rangemax, floor1_values = 2;
529 
530  floor_setup->decode = vorbis_floor1_decode;
531 
532  floor_setup->data.t1.partitions = get_bits(gb, 5);
533 
534  ff_dlog(NULL, " %d.floor: %d partitions \n",
535  i, floor_setup->data.t1.partitions);
536 
537  for (j = 0; j < floor_setup->data.t1.partitions; ++j) {
538  floor_setup->data.t1.partition_class[j] = get_bits(gb, 4);
539  if (floor_setup->data.t1.partition_class[j] > maximum_class)
540  maximum_class = floor_setup->data.t1.partition_class[j];
541 
542  ff_dlog(NULL, " %d. floor %d partition class %d \n",
543  i, j, floor_setup->data.t1.partition_class[j]);
544 
545  }
546 
547  ff_dlog(NULL, " maximum class %d \n", maximum_class);
548 
549  for (j = 0; j <= maximum_class; ++j) {
550  floor_setup->data.t1.class_dimensions[j] = get_bits(gb, 3) + 1;
551  floor_setup->data.t1.class_subclasses[j] = get_bits(gb, 2);
552 
553  ff_dlog(NULL, " %d floor %d class dim: %d subclasses %d \n", i, j,
554  floor_setup->data.t1.class_dimensions[j],
555  floor_setup->data.t1.class_subclasses[j]);
556 
557  if (floor_setup->data.t1.class_subclasses[j]) {
558  GET_VALIDATED_INDEX(floor_setup->data.t1.class_masterbook[j], 8, vc->codebook_count)
559 
560  ff_dlog(NULL, " masterbook: %d \n", floor_setup->data.t1.class_masterbook[j]);
561  }
562 
563  for (k = 0; k < (1 << floor_setup->data.t1.class_subclasses[j]); ++k) {
564  int16_t bits = get_bits(gb, 8) - 1;
565  if (bits != -1)
566  VALIDATE_INDEX(bits, vc->codebook_count)
567  floor_setup->data.t1.subclass_books[j][k] = bits;
568 
569  ff_dlog(NULL, " book %d. : %d \n", k, floor_setup->data.t1.subclass_books[j][k]);
570  }
571  }
572 
573  floor_setup->data.t1.multiplier = get_bits(gb, 2) + 1;
574  floor_setup->data.t1.x_list_dim = 2;
575 
576  for (j = 0; j < floor_setup->data.t1.partitions; ++j)
577  floor_setup->data.t1.x_list_dim+=floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]];
578 
579  floor_setup->data.t1.list = av_calloc(floor_setup->data.t1.x_list_dim,
580  sizeof(*floor_setup->data.t1.list));
581  if (!floor_setup->data.t1.list)
582  return AVERROR(ENOMEM);
583 
584  rangebits = get_bits(gb, 4);
585  if (!rangebits && floor_setup->data.t1.partitions) {
586  av_log(vc->avctx, AV_LOG_ERROR,
587  "A rangebits value of 0 is not compliant with the Vorbis I specification.\n");
588  return AVERROR_INVALIDDATA;
589  }
590  rangemax = (1 << rangebits);
591  if (rangemax > vc->blocksize[1] / 2) {
592  av_log(vc->avctx, AV_LOG_ERROR,
593  "Floor value is too large for blocksize: %u (%"PRIu32")\n",
594  rangemax, vc->blocksize[1] / 2);
595  return AVERROR_INVALIDDATA;
596  }
597  floor_setup->data.t1.list[0].x = 0;
598  floor_setup->data.t1.list[1].x = rangemax;
599 
600  for (j = 0; j < floor_setup->data.t1.partitions; ++j) {
601  for (k = 0; k < floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]]; ++k, ++floor1_values) {
602  floor_setup->data.t1.list[floor1_values].x = get_bits(gb, rangebits);
603 
604  ff_dlog(NULL, " %u. floor1 Y coord. %d\n", floor1_values,
605  floor_setup->data.t1.list[floor1_values].x);
606  }
607  }
608 
609 // Precalculate order of x coordinates - needed for decode
610  if (ff_vorbis_ready_floor1_list(vc->avctx,
611  floor_setup->data.t1.list,
612  floor_setup->data.t1.x_list_dim)) {
613  return AVERROR_INVALIDDATA;
614  }
615  } else if (floor_setup->floor_type == 0) {
616  unsigned max_codebook_dim = 0;
617 
618  floor_setup->decode = vorbis_floor0_decode;
619 
620  floor_setup->data.t0.order = get_bits(gb, 8);
621  if (!floor_setup->data.t0.order) {
622  av_log(vc->avctx, AV_LOG_ERROR, "Floor 0 order is 0.\n");
623  return AVERROR_INVALIDDATA;
624  }
625  floor_setup->data.t0.rate = get_bits(gb, 16);
626  if (!floor_setup->data.t0.rate) {
627  av_log(vc->avctx, AV_LOG_ERROR, "Floor 0 rate is 0.\n");
628  return AVERROR_INVALIDDATA;
629  }
630  floor_setup->data.t0.bark_map_size = get_bits(gb, 16);
631  if (!floor_setup->data.t0.bark_map_size) {
632  av_log(vc->avctx, AV_LOG_ERROR,
633  "Floor 0 bark map size is 0.\n");
634  return AVERROR_INVALIDDATA;
635  }
636  floor_setup->data.t0.amplitude_bits = get_bits(gb, 6);
637  floor_setup->data.t0.amplitude_offset = get_bits(gb, 8);
638  floor_setup->data.t0.num_books = get_bits(gb, 4) + 1;
639 
640  /* allocate mem for booklist */
641  floor_setup->data.t0.book_list =
642  av_malloc(floor_setup->data.t0.num_books);
643  if (!floor_setup->data.t0.book_list)
644  return AVERROR(ENOMEM);
645  /* read book indexes */
646  {
647  int idx;
648  unsigned book_idx;
649  for (idx = 0; idx < floor_setup->data.t0.num_books; ++idx) {
650  GET_VALIDATED_INDEX(book_idx, 8, vc->codebook_count)
651  floor_setup->data.t0.book_list[idx] = book_idx;
652  if (vc->codebooks[book_idx].dimensions > max_codebook_dim)
653  max_codebook_dim = vc->codebooks[book_idx].dimensions;
654  }
655  }
656 
657  if ((ret = create_map(vc, i)) < 0)
658  return ret;
659 
660  /* codebook dim is for padding if codebook dim doesn't *
661  * divide order+1 then we need to read more data */
662  floor_setup->data.t0.lsp =
663  av_malloc_array((floor_setup->data.t0.order + 1 + max_codebook_dim),
664  sizeof(*floor_setup->data.t0.lsp));
665  if (!floor_setup->data.t0.lsp)
666  return AVERROR(ENOMEM);
667 
668  /* debug output parsed headers */
669  ff_dlog(NULL, "floor0 order: %u\n", floor_setup->data.t0.order);
670  ff_dlog(NULL, "floor0 rate: %u\n", floor_setup->data.t0.rate);
671  ff_dlog(NULL, "floor0 bark map size: %u\n",
672  floor_setup->data.t0.bark_map_size);
673  ff_dlog(NULL, "floor0 amplitude bits: %u\n",
674  floor_setup->data.t0.amplitude_bits);
675  ff_dlog(NULL, "floor0 amplitude offset: %u\n",
676  floor_setup->data.t0.amplitude_offset);
677  ff_dlog(NULL, "floor0 number of books: %u\n",
678  floor_setup->data.t0.num_books);
679  ff_dlog(NULL, "floor0 book list pointer: %p\n",
680  floor_setup->data.t0.book_list);
681  {
682  int idx;
683  for (idx = 0; idx < floor_setup->data.t0.num_books; ++idx) {
684  ff_dlog(NULL, " Book %d: %u\n", idx + 1,
685  floor_setup->data.t0.book_list[idx]);
686  }
687  }
688  } else {
689  av_log(vc->avctx, AV_LOG_ERROR, "Invalid floor type!\n");
690  return AVERROR_INVALIDDATA;
691  }
692  }
693  return 0;
694 }
695 
696 // Process residues part
697 
698 static int vorbis_parse_setup_hdr_residues(vorbis_context *vc)
699 {
700  GetBitContext *gb = &vc->gb;
701  unsigned i, j, k;
702 
703  vc->residue_count = get_bits(gb, 6)+1;
704  vc->residues = av_mallocz(vc->residue_count * sizeof(*vc->residues));
705  if (!vc->residues)
706  return AVERROR(ENOMEM);
707 
708  ff_dlog(NULL, " There are %d residues. \n", vc->residue_count);
709 
710  for (i = 0; i < vc->residue_count; ++i) {
711  vorbis_residue *res_setup = &vc->residues[i];
712  uint8_t cascade[64];
713  unsigned high_bits, low_bits;
714 
715  res_setup->type = get_bits(gb, 16);
716 
717  ff_dlog(NULL, " %u. residue type %d\n", i, res_setup->type);
718 
719  res_setup->begin = get_bits(gb, 24);
720  res_setup->end = get_bits(gb, 24);
721  res_setup->partition_size = get_bits(gb, 24) + 1;
722  /* Validations to prevent a buffer overflow later. */
723  if (res_setup->begin>res_setup->end ||
724  (res_setup->end-res_setup->begin) / res_setup->partition_size > FFMIN(V_MAX_PARTITIONS, 65535)) {
725  av_log(vc->avctx, AV_LOG_ERROR,
726  "partition out of bounds: type, begin, end, size, blocksize: %"PRIu16", %"PRIu32", %"PRIu32", %u, %"PRIu32"\n",
727  res_setup->type, res_setup->begin, res_setup->end,
728  res_setup->partition_size, vc->blocksize[1] / 2);
729  return AVERROR_INVALIDDATA;
730  }
731 
732  res_setup->classifications = get_bits(gb, 6) + 1;
733  GET_VALIDATED_INDEX(res_setup->classbook, 8, vc->codebook_count)
734 
735  res_setup->ptns_to_read =
736  (res_setup->end - res_setup->begin) / res_setup->partition_size;
737  res_setup->classifs = av_malloc_array(res_setup->ptns_to_read,
738  vc->audio_channels *
739  sizeof(*res_setup->classifs));
740  if (!res_setup->classifs)
741  return AVERROR(ENOMEM);
742 
743  ff_dlog(NULL, " begin %"PRIu32" end %"PRIu32" part.size %u classif.s %"PRIu8" classbook %"PRIu8"\n",
744  res_setup->begin, res_setup->end, res_setup->partition_size,
745  res_setup->classifications, res_setup->classbook);
746 
747  for (j = 0; j < res_setup->classifications; ++j) {
748  high_bits = 0;
749  low_bits = get_bits(gb, 3);
750  if (get_bits1(gb))
751  high_bits = get_bits(gb, 5);
752  cascade[j] = (high_bits << 3) + low_bits;
753 
754  ff_dlog(NULL, " %u class cascade depth: %d\n", j, ilog(cascade[j]));
755  }
756 
757  res_setup->maxpass = 0;
758  for (j = 0; j < res_setup->classifications; ++j) {
759  for (k = 0; k < 8; ++k) {
760  if (cascade[j]&(1 << k)) {
761  GET_VALIDATED_INDEX(res_setup->books[j][k], 8, vc->codebook_count)
762 
763  ff_dlog(NULL, " %u class cascade depth %u book: %d\n",
764  j, k, res_setup->books[j][k]);
765 
766  if (k>res_setup->maxpass)
767  res_setup->maxpass = k;
768  } else {
769  res_setup->books[j][k] = -1;
770  }
771  }
772  }
773  }
774  return 0;
775 }
776 
777 // Process mappings part
778 
779 static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc)
780 {
781  GetBitContext *gb = &vc->gb;
782  unsigned i, j;
783 
784  vc->mapping_count = get_bits(gb, 6)+1;
785  vc->mappings = av_mallocz(vc->mapping_count * sizeof(*vc->mappings));
786  if (!vc->mappings)
787  return AVERROR(ENOMEM);
788 
789  ff_dlog(NULL, " There are %d mappings. \n", vc->mapping_count);
790 
791  for (i = 0; i < vc->mapping_count; ++i) {
792  vorbis_mapping *mapping_setup = &vc->mappings[i];
793 
794  if (get_bits(gb, 16)) {
795  av_log(vc->avctx, AV_LOG_ERROR, "Other mappings than type 0 are not compliant with the Vorbis I specification. \n");
796  return AVERROR_INVALIDDATA;
797  }
798  if (get_bits1(gb)) {
799  mapping_setup->submaps = get_bits(gb, 4) + 1;
800  } else {
801  mapping_setup->submaps = 1;
802  }
803 
804  if (get_bits1(gb)) {
805  mapping_setup->coupling_steps = get_bits(gb, 8) + 1;
806  if (vc->audio_channels < 2) {
807  av_log(vc->avctx, AV_LOG_ERROR,
808  "Square polar channel mapping with less than two channels is not compliant with the Vorbis I specification.\n");
809  return AVERROR_INVALIDDATA;
810  }
811  mapping_setup->magnitude = av_mallocz(mapping_setup->coupling_steps *
812  sizeof(*mapping_setup->magnitude));
813  mapping_setup->angle = av_mallocz(mapping_setup->coupling_steps *
814  sizeof(*mapping_setup->angle));
815  if (!mapping_setup->angle || !mapping_setup->magnitude)
816  return AVERROR(ENOMEM);
817 
818  for (j = 0; j < mapping_setup->coupling_steps; ++j) {
819  GET_VALIDATED_INDEX(mapping_setup->magnitude[j], ilog(vc->audio_channels - 1), vc->audio_channels)
820  GET_VALIDATED_INDEX(mapping_setup->angle[j], ilog(vc->audio_channels - 1), vc->audio_channels)
821  }
822  } else {
823  mapping_setup->coupling_steps = 0;
824  }
825 
826  ff_dlog(NULL, " %u mapping coupling steps: %d\n",
827  i, mapping_setup->coupling_steps);
828 
829  if (get_bits(gb, 2)) {
830  av_log(vc->avctx, AV_LOG_ERROR, "%u. mapping setup data invalid.\n", i);
831  return AVERROR_INVALIDDATA; // following spec.
832  }
833 
834  if (mapping_setup->submaps>1) {
835  mapping_setup->mux = av_calloc(vc->audio_channels,
836  sizeof(*mapping_setup->mux));
837  if (!mapping_setup->mux)
838  return AVERROR(ENOMEM);
839 
840  for (j = 0; j < vc->audio_channels; ++j)
841  mapping_setup->mux[j] = get_bits(gb, 4);
842  }
843 
844  for (j = 0; j < mapping_setup->submaps; ++j) {
845  skip_bits(gb, 8); // FIXME check?
846  GET_VALIDATED_INDEX(mapping_setup->submap_floor[j], 8, vc->floor_count)
847  GET_VALIDATED_INDEX(mapping_setup->submap_residue[j], 8, vc->residue_count)
848 
849  ff_dlog(NULL, " %u mapping %u submap : floor %d, residue %d\n", i, j,
850  mapping_setup->submap_floor[j],
851  mapping_setup->submap_residue[j]);
852  }
853  }
854  return 0;
855 }
856 
857 // Process modes part
858 
859 static int create_map(vorbis_context *vc, unsigned floor_number)
860 {
861  vorbis_floor *floors = vc->floors;
862  vorbis_floor0 *vf;
863  int idx;
864  int blockflag, n;
865  int32_t *map;
866 
867  for (blockflag = 0; blockflag < 2; ++blockflag) {
868  n = vc->blocksize[blockflag] / 2;
869  floors[floor_number].data.t0.map[blockflag] =
870  av_malloc_array(n + 1, sizeof(int32_t)); // n + sentinel
871  if (!floors[floor_number].data.t0.map[blockflag])
872  return AVERROR(ENOMEM);
873 
874  map = floors[floor_number].data.t0.map[blockflag];
875  vf = &floors[floor_number].data.t0;
876 
877  for (idx = 0; idx < n; ++idx) {
878  map[idx] = floor(BARK((vf->rate * idx) / (2.0f * n)) *
879  (vf->bark_map_size / BARK(vf->rate / 2.0f)));
880  if (vf->bark_map_size-1 < map[idx])
881  map[idx] = vf->bark_map_size - 1;
882  }
883  map[n] = -1;
884  vf->map_size[blockflag] = n;
885  }
886 
887  for (idx = 0; idx <= n; ++idx) {
888  ff_dlog(NULL, "floor0 map: map at pos %d is %"PRId32"\n", idx, map[idx]);
889  }
890 
891  return 0;
892 }
893 
894 static int vorbis_parse_setup_hdr_modes(vorbis_context *vc)
895 {
896  GetBitContext *gb = &vc->gb;
897  unsigned i;
898 
899  vc->mode_count = get_bits(gb, 6) + 1;
900  vc->modes = av_mallocz(vc->mode_count * sizeof(*vc->modes));
901  if (!vc->modes)
902  return AVERROR(ENOMEM);
903 
904  ff_dlog(NULL, " There are %d modes.\n", vc->mode_count);
905 
906  for (i = 0; i < vc->mode_count; ++i) {
907  vorbis_mode *mode_setup = &vc->modes[i];
908 
909  mode_setup->blockflag = get_bits1(gb);
910  mode_setup->windowtype = get_bits(gb, 16); //FIXME check
911  mode_setup->transformtype = get_bits(gb, 16); //FIXME check
912  GET_VALIDATED_INDEX(mode_setup->mapping, 8, vc->mapping_count);
913 
914  ff_dlog(NULL, " %u mode: blockflag %d, windowtype %d, transformtype %d, mapping %d\n",
915  i, mode_setup->blockflag, mode_setup->windowtype,
916  mode_setup->transformtype, mode_setup->mapping);
917  }
918  return 0;
919 }
920 
921 // Process the whole setup header using the functions above
922 
923 static int vorbis_parse_setup_hdr(vorbis_context *vc)
924 {
925  GetBitContext *gb = &vc->gb;
926  int ret;
927 
928  if ((get_bits(gb, 8) != 'v') || (get_bits(gb, 8) != 'o') ||
929  (get_bits(gb, 8) != 'r') || (get_bits(gb, 8) != 'b') ||
930  (get_bits(gb, 8) != 'i') || (get_bits(gb, 8) != 's')) {
931  av_log(vc->avctx, AV_LOG_ERROR, " Vorbis setup header packet corrupt (no vorbis signature). \n");
932  return AVERROR_INVALIDDATA;
933  }
934 
936  av_log(vc->avctx, AV_LOG_ERROR, " Vorbis setup header packet corrupt (codebooks). \n");
937  return ret;
938  }
940  av_log(vc->avctx, AV_LOG_ERROR, " Vorbis setup header packet corrupt (time domain transforms). \n");
941  return ret;
942  }
943  if ((ret = vorbis_parse_setup_hdr_floors(vc))) {
944  av_log(vc->avctx, AV_LOG_ERROR, " Vorbis setup header packet corrupt (floors). \n");
945  return ret;
946  }
947  if ((ret = vorbis_parse_setup_hdr_residues(vc))) {
948  av_log(vc->avctx, AV_LOG_ERROR, " Vorbis setup header packet corrupt (residues). \n");
949  return ret;
950  }
951  if ((ret = vorbis_parse_setup_hdr_mappings(vc))) {
952  av_log(vc->avctx, AV_LOG_ERROR, " Vorbis setup header packet corrupt (mappings). \n");
953  return ret;
954  }
955  if ((ret = vorbis_parse_setup_hdr_modes(vc))) {
956  av_log(vc->avctx, AV_LOG_ERROR, " Vorbis setup header packet corrupt (modes). \n");
957  return ret;
958  }
959  if (!get_bits1(gb)) {
960  av_log(vc->avctx, AV_LOG_ERROR, " Vorbis setup header packet corrupt (framing flag). \n");
961  return AVERROR_INVALIDDATA; // framing flag bit unset error
962  }
963 
964  return 0;
965 }
966 
967 // Process the identification header
968 
969 static int vorbis_parse_id_hdr(vorbis_context *vc)
970 {
971  GetBitContext *gb = &vc->gb;
972  unsigned bl0, bl1;
973  float scale = -1.0;
974  int ret;
975 
976  if ((get_bits(gb, 8) != 'v') || (get_bits(gb, 8) != 'o') ||
977  (get_bits(gb, 8) != 'r') || (get_bits(gb, 8) != 'b') ||
978  (get_bits(gb, 8) != 'i') || (get_bits(gb, 8) != 's')) {
979  av_log(vc->avctx, AV_LOG_ERROR, " Vorbis id header packet corrupt (no vorbis signature). \n");
980  return AVERROR_INVALIDDATA;
981  }
982 
983  vc->version = get_bits_long(gb, 32); //FIXME check 0
984  vc->audio_channels = get_bits(gb, 8);
985  if (vc->audio_channels <= 0) {
986  av_log(vc->avctx, AV_LOG_ERROR, "Invalid number of channels\n");
987  return AVERROR_INVALIDDATA;
988  }
989  vc->audio_samplerate = get_bits_long(gb, 32);
990  if (vc->audio_samplerate <= 0) {
991  av_log(vc->avctx, AV_LOG_ERROR, "Invalid samplerate\n");
992  return AVERROR_INVALIDDATA;
993  }
994  vc->bitrate_maximum = get_bits_long(gb, 32);
995  vc->bitrate_nominal = get_bits_long(gb, 32);
996  vc->bitrate_minimum = get_bits_long(gb, 32);
997  bl0 = get_bits(gb, 4);
998  bl1 = get_bits(gb, 4);
999  if (bl0 > 13 || bl0 < 6 || bl1 > 13 || bl1 < 6 || bl1 < bl0) {
1000  av_log(vc->avctx, AV_LOG_ERROR, " Vorbis id header packet corrupt (illegal blocksize). \n");
1001  return AVERROR_INVALIDDATA;
1002  }
1003  vc->blocksize[0] = (1 << bl0);
1004  vc->blocksize[1] = (1 << bl1);
1005  vc->win[0] = ff_vorbis_vwin[bl0 - 6];
1006  vc->win[1] = ff_vorbis_vwin[bl1 - 6];
1007 
1008  if ((get_bits1(gb)) == 0) {
1009  av_log(vc->avctx, AV_LOG_ERROR, " Vorbis id header packet corrupt (framing flag not set). \n");
1010  return AVERROR_INVALIDDATA;
1011  }
1012 
1013  vc->channel_residues = av_malloc_array(vc->blocksize[1] / 2, vc->audio_channels * sizeof(*vc->channel_residues));
1014  vc->saved = av_calloc(vc->blocksize[1] / 4, vc->audio_channels * sizeof(*vc->saved));
1015  if (!vc->channel_residues || !vc->saved)
1016  return AVERROR(ENOMEM);
1017 
1018  vc->previous_window = -1;
1019 
1020  ret = av_tx_init(&vc->mdct[0], &vc->mdct_fn[0], AV_TX_FLOAT_MDCT, 1,
1021  vc->blocksize[0] >> 1, &scale, 0);
1022  if (ret < 0)
1023  return ret;
1024 
1025  ret = av_tx_init(&vc->mdct[1], &vc->mdct_fn[1], AV_TX_FLOAT_MDCT, 1,
1026  vc->blocksize[1] >> 1, &scale, 0);
1027  if (ret < 0)
1028  return ret;
1029 
1030  vc->fdsp = avpriv_float_dsp_alloc(vc->avctx->flags & AV_CODEC_FLAG_BITEXACT);
1031  if (!vc->fdsp)
1032  return AVERROR(ENOMEM);
1033 
1034  ff_dlog(NULL, " vorbis version %"PRIu32" \n audio_channels %"PRIu8" \n audio_samplerate %"PRIu32" \n bitrate_max %"PRIu32" \n bitrate_nom %"PRIu32" \n bitrate_min %"PRIu32" \n blk_0 %"PRIu32" blk_1 %"PRIu32" \n ",
1035  vc->version, vc->audio_channels, vc->audio_samplerate, vc->bitrate_maximum, vc->bitrate_nominal, vc->bitrate_minimum, vc->blocksize[0], vc->blocksize[1]);
1036 
1037 /*
1038  BLK = vc->blocksize[0];
1039  for (i = 0; i < BLK / 2; ++i) {
1040  vc->win[0][i] = sin(0.5*3.14159265358*(sin(((float)i + 0.5) / (float)BLK*3.14159265358))*(sin(((float)i + 0.5) / (float)BLK*3.14159265358)));
1041  }
1042 */
1043 
1044  return 0;
1045 }
1046 
1047 // Process the extradata using the functions above (identification header, setup header)
1048 
1050 {
1051  vorbis_context *vc = avctx->priv_data;
1052  uint8_t *headers = avctx->extradata;
1053  int headers_len = avctx->extradata_size;
1054  const uint8_t *header_start[3];
1055  int header_len[3];
1056  GetBitContext *gb = &vc->gb;
1057  int hdr_type, ret;
1058 
1059  vc->avctx = avctx;
1060  ff_vorbisdsp_init(&vc->dsp);
1061 
1062  avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
1063 
1064  if (!headers_len) {
1065  av_log(avctx, AV_LOG_ERROR, "Extradata missing.\n");
1066  return AVERROR_INVALIDDATA;
1067  }
1068 
1069  if ((ret = avpriv_split_xiph_headers(headers, headers_len, 30, header_start, header_len)) < 0) {
1070  av_log(avctx, AV_LOG_ERROR, "Extradata corrupt.\n");
1071  return ret;
1072  }
1073 
1074  init_get_bits(gb, header_start[0], header_len[0]*8);
1075  hdr_type = get_bits(gb, 8);
1076  if (hdr_type != 1) {
1077  av_log(avctx, AV_LOG_ERROR, "First header is not the id header.\n");
1078  return AVERROR_INVALIDDATA;
1079  }
1080  if ((ret = vorbis_parse_id_hdr(vc))) {
1081  av_log(avctx, AV_LOG_ERROR, "Id header corrupt.\n");
1082  vorbis_free(vc);
1083  return ret;
1084  }
1085 
1086  init_get_bits(gb, header_start[2], header_len[2]*8);
1087  hdr_type = get_bits(gb, 8);
1088  if (hdr_type != 5) {
1089  av_log(avctx, AV_LOG_ERROR, "Third header is not the setup header.\n");
1090  vorbis_free(vc);
1091  return AVERROR_INVALIDDATA;
1092  }
1093  if ((ret = vorbis_parse_setup_hdr(vc))) {
1094  av_log(avctx, AV_LOG_ERROR, "Setup header corrupt.\n");
1095  vorbis_free(vc);
1096  return ret;
1097  }
1098 
1100  if (vc->audio_channels > 8) {
1102  avctx->ch_layout.nb_channels = vc->audio_channels;
1103  } else {
1104  av_channel_layout_copy(&avctx->ch_layout, &ff_vorbis_ch_layouts[vc->audio_channels - 1]);
1105  }
1106 
1107  avctx->sample_rate = vc->audio_samplerate;
1108 
1109  return 0;
1110 }
1111 
1112 // Decode audiopackets -------------------------------------------------
1113 
1114 // Read and decode floor
1115 
1116 static int vorbis_floor0_decode(vorbis_context *vc,
1117  vorbis_floor_data *vfu, float *vec)
1118 {
1119  vorbis_floor0 *vf = &vfu->t0;
1120  float *lsp = vf->lsp;
1121  unsigned book_idx;
1122  uint64_t amplitude;
1123  unsigned blockflag = vc->modes[vc->mode_number].blockflag;
1124 
1125  if (!vf->amplitude_bits)
1126  return 1;
1127 
1128  amplitude = get_bits64(&vc->gb, vf->amplitude_bits);
1129  if (amplitude > 0) {
1130  float last = 0;
1131  unsigned idx, lsp_len = 0;
1133 
1134  book_idx = get_bits(&vc->gb, ilog(vf->num_books));
1135  if (book_idx >= vf->num_books) {
1136  av_log(vc->avctx, AV_LOG_ERROR, "floor0 dec: booknumber too high!\n");
1137  book_idx = 0;
1138  }
1139  ff_dlog(NULL, "floor0 dec: booknumber: %u\n", book_idx);
1140  codebook = vc->codebooks[vf->book_list[book_idx]];
1141  /* Invalid codebook! */
1142  if (!codebook.codevectors)
1143  return AVERROR_INVALIDDATA;
1144 
1145  while (lsp_len<vf->order) {
1146  int vec_off;
1147 
1148  ff_dlog(NULL, "floor0 dec: book dimension: %d\n", codebook.dimensions);
1149  ff_dlog(NULL, "floor0 dec: maximum depth: %d\n", codebook.maxdepth);
1150  /* read temp vector */
1151  vec_off = get_vlc2(&vc->gb, codebook.vlc.table,
1152  codebook.nb_bits, codebook.maxdepth);
1153  if (vec_off < 0)
1154  return AVERROR_INVALIDDATA;
1155  vec_off *= codebook.dimensions;
1156  ff_dlog(NULL, "floor0 dec: vector offset: %d\n", vec_off);
1157  /* copy each vector component and add last to it */
1158  for (idx = 0; idx < codebook.dimensions; ++idx)
1159  lsp[lsp_len+idx] = codebook.codevectors[vec_off+idx] + last;
1160  last = lsp[lsp_len+idx-1]; /* set last to last vector component */
1161 
1162  lsp_len += codebook.dimensions;
1163  }
1164  /* DEBUG: output lsp coeffs */
1165  {
1166  int idx;
1167  for (idx = 0; idx < lsp_len; ++idx)
1168  ff_dlog(NULL, "floor0 dec: coeff at %d is %f\n", idx, lsp[idx]);
1169  }
1170 
1171  /* synthesize floor output vector */
1172  {
1173  int i;
1174  int order = vf->order;
1175  float wstep = M_PI / vf->bark_map_size;
1176 
1177  for (i = 0; i < order; i++)
1178  lsp[i] = 2.0f * cos(lsp[i]);
1179 
1180  ff_dlog(NULL, "floor0 synth: map_size = %"PRIu32"; m = %d; wstep = %f\n",
1181  vf->map_size[blockflag], order, wstep);
1182 
1183  i = 0;
1184  while (i < vf->map_size[blockflag]) {
1185  int j, iter_cond = vf->map[blockflag][i];
1186  float p = 0.5f;
1187  float q = 0.5f;
1188  float two_cos_w = 2.0f * cos(wstep * iter_cond); // needed all times
1189 
1190  /* similar part for the q and p products */
1191  for (j = 0; j + 1 < order; j += 2) {
1192  q *= lsp[j] - two_cos_w;
1193  p *= lsp[j + 1] - two_cos_w;
1194  }
1195  if (j == order) { // even order
1196  p *= p * (2.0f - two_cos_w);
1197  q *= q * (2.0f + two_cos_w);
1198  } else { // odd order
1199  q *= two_cos_w-lsp[j]; // one more time for q
1200 
1201  /* final step and square */
1202  p *= p * (4.f - two_cos_w * two_cos_w);
1203  q *= q;
1204  }
1205 
1206  if (p + q == 0.0)
1207  return AVERROR_INVALIDDATA;
1208 
1209  /* calculate linear floor value */
1210  q = exp((((amplitude*vf->amplitude_offset) /
1211  (((1ULL << vf->amplitude_bits) - 1) * sqrt(p + q)))
1212  - vf->amplitude_offset) * .11512925f);
1213 
1214  /* fill vector */
1215  do {
1216  vec[i] = q; ++i;
1217  } while (vf->map[blockflag][i] == iter_cond);
1218  }
1219  }
1220  } else {
1221  /* this channel is unused */
1222  return 1;
1223  }
1224 
1225  ff_dlog(NULL, " Floor0 decoded\n");
1226 
1227  return 0;
1228 }
1229 
1230 static int vorbis_floor1_decode(vorbis_context *vc,
1231  vorbis_floor_data *vfu, float *vec)
1232 {
1233  vorbis_floor1 *vf = &vfu->t1;
1234  GetBitContext *gb = &vc->gb;
1235  uint16_t range_v[4] = { 256, 128, 86, 64 };
1236  unsigned range = range_v[vf->multiplier - 1];
1237  uint16_t floor1_Y[258];
1238  uint16_t floor1_Y_final[258];
1239  int floor1_flag[258];
1240  unsigned partition_class, cdim, cbits, csub, cval, offset, i, j;
1241  int book, adx, ady, dy, off, predicted, err;
1242 
1243 
1244  if (!get_bits1(gb)) // silence
1245  return 1;
1246 
1247 // Read values (or differences) for the floor's points
1248 
1249  floor1_Y[0] = get_bits(gb, ilog(range - 1));
1250  floor1_Y[1] = get_bits(gb, ilog(range - 1));
1251 
1252  ff_dlog(NULL, "floor 0 Y %d floor 1 Y %d \n", floor1_Y[0], floor1_Y[1]);
1253 
1254  offset = 2;
1255  for (i = 0; i < vf->partitions; ++i) {
1256  partition_class = vf->partition_class[i];
1257  cdim = vf->class_dimensions[partition_class];
1258  cbits = vf->class_subclasses[partition_class];
1259  csub = (1 << cbits) - 1;
1260  cval = 0;
1261 
1262  ff_dlog(NULL, "Cbits %u\n", cbits);
1263 
1264  if (cbits) // this reads all subclasses for this partition's class
1265  cval = get_vlc2(gb, vc->codebooks[vf->class_masterbook[partition_class]].vlc.table,
1266  vc->codebooks[vf->class_masterbook[partition_class]].nb_bits, 3);
1267 
1268  for (j = 0; j < cdim; ++j) {
1269  book = vf->subclass_books[partition_class][cval & csub];
1270 
1271  ff_dlog(NULL, "book %d Cbits %u cval %u bits:%d\n",
1272  book, cbits, cval, get_bits_count(gb));
1273 
1274  cval = cval >> cbits;
1275  if (book > -1) {
1276  int v = get_vlc2(gb, vc->codebooks[book].vlc.table,
1277  vc->codebooks[book].nb_bits, 3);
1278  if (v < 0)
1279  return AVERROR_INVALIDDATA;
1280  floor1_Y[offset+j] = v;
1281  } else {
1282  floor1_Y[offset+j] = 0;
1283  }
1284 
1285  ff_dlog(NULL, " floor(%d) = %d \n",
1286  vf->list[offset+j].x, floor1_Y[offset+j]);
1287  }
1288  offset+=cdim;
1289  }
1290 
1291 // Amplitude calculation from the differences
1292 
1293  floor1_flag[0] = 1;
1294  floor1_flag[1] = 1;
1295  floor1_Y_final[0] = floor1_Y[0];
1296  floor1_Y_final[1] = floor1_Y[1];
1297 
1298  for (i = 2; i < vf->x_list_dim; ++i) {
1299  unsigned val, highroom, lowroom, room, high_neigh_offs, low_neigh_offs;
1300 
1301  low_neigh_offs = vf->list[i].low;
1302  high_neigh_offs = vf->list[i].high;
1303  dy = floor1_Y_final[high_neigh_offs] - floor1_Y_final[low_neigh_offs]; // render_point begin
1304  adx = vf->list[high_neigh_offs].x - vf->list[low_neigh_offs].x;
1305  ady = FFABS(dy);
1306  err = ady * (vf->list[i].x - vf->list[low_neigh_offs].x);
1307  off = err / adx;
1308  if (dy < 0) {
1309  predicted = floor1_Y_final[low_neigh_offs] - off;
1310  } else {
1311  predicted = floor1_Y_final[low_neigh_offs] + off;
1312  } // render_point end
1313 
1314  val = floor1_Y[i];
1315  highroom = range-predicted;
1316  lowroom = predicted;
1317  if (highroom < lowroom) {
1318  room = highroom * 2;
1319  } else {
1320  room = lowroom * 2; // SPEC misspelling
1321  }
1322  if (val) {
1323  floor1_flag[low_neigh_offs] = 1;
1324  floor1_flag[high_neigh_offs] = 1;
1325  floor1_flag[i] = 1;
1326  if (val >= room) {
1327  if (highroom > lowroom) {
1328  floor1_Y_final[i] = av_clip_uint16(val - lowroom + predicted);
1329  } else {
1330  floor1_Y_final[i] = av_clip_uint16(predicted - val + highroom - 1);
1331  }
1332  } else {
1333  if (val & 1) {
1334  floor1_Y_final[i] = av_clip_uint16(predicted - (val + 1) / 2);
1335  } else {
1336  floor1_Y_final[i] = av_clip_uint16(predicted + val / 2);
1337  }
1338  }
1339  } else {
1340  floor1_flag[i] = 0;
1341  floor1_Y_final[i] = av_clip_uint16(predicted);
1342  }
1343 
1344  ff_dlog(NULL, " Decoded floor(%d) = %u / val %u\n",
1345  vf->list[i].x, floor1_Y_final[i], val);
1346  }
1347 
1348 // Curve synth - connect the calculated dots and convert from dB scale FIXME optimize ?
1349 
1350  ff_vorbis_floor1_render_list(vf->list, vf->x_list_dim, floor1_Y_final, floor1_flag, vf->multiplier, vec, vf->list[1].x);
1351 
1352  ff_dlog(NULL, " Floor decoded\n");
1353 
1354  return 0;
1355 }
1356 
1357 static av_always_inline int setup_classifs(vorbis_context *vc,
1358  vorbis_residue *vr,
1359  uint8_t *do_not_decode,
1360  unsigned ch_used,
1361  int partition_count,
1362  int ptns_to_read
1363  )
1364 {
1365  vorbis_codebook *codebook = vc->codebooks + vr->classbook;
1366  int p, j, i;
1367  unsigned c_p_c = codebook->dimensions;
1368  unsigned inverse_class = ff_inverse[vr->classifications];
1369  int temp, temp2;
1370  for (p = 0, j = 0; j < ch_used; ++j) {
1371  if (!do_not_decode[j]) {
1372  temp = get_vlc2(&vc->gb, codebook->vlc.table,
1373  codebook->nb_bits, 3);
1374 
1375  ff_dlog(NULL, "Classword: %u\n", temp);
1376 
1377  av_assert0(temp < 65536);
1378 
1379  if (temp < 0) {
1380  av_log(vc->avctx, AV_LOG_ERROR,
1381  "Invalid vlc code decoding %d channel.", j);
1382  return AVERROR_INVALIDDATA;
1383  }
1384 
1385  if (vr->classifications == 1) {
1386  for (i = partition_count + c_p_c - 1; i >= partition_count; i--) {
1387  if (i < ptns_to_read)
1388  vr->classifs[p + i] = 0;
1389  }
1390  } else {
1391  for (i = partition_count + c_p_c - 1; i >= partition_count; i--) {
1392  temp2 = (((uint64_t)temp) * inverse_class) >> 32;
1393 
1394  if (i < ptns_to_read)
1395  vr->classifs[p + i] = temp - temp2 * vr->classifications;
1396  temp = temp2;
1397  }
1398  }
1399  }
1400  p += ptns_to_read;
1401  }
1402  return 0;
1403 }
1404 // Read and decode residue
1405 
1406 static av_always_inline int vorbis_residue_decode_internal(vorbis_context *vc,
1407  vorbis_residue *vr,
1408  unsigned ch,
1409  uint8_t *do_not_decode,
1410  float *vec,
1411  unsigned vlen,
1412  unsigned ch_left,
1413  int vr_type)
1414 {
1415  GetBitContext *gb = &vc->gb;
1416  unsigned c_p_c = vc->codebooks[vr->classbook].dimensions;
1417  uint8_t *classifs = vr->classifs;
1418  unsigned pass, ch_used, i, j, k, l;
1419  unsigned max_output = (ch - 1) * vlen;
1420  int ptns_to_read = vr->ptns_to_read;
1421  int libvorbis_bug = 0;
1422 
1423  if (vr_type == 2) {
1424  for (j = 1; j < ch; ++j)
1425  do_not_decode[0] &= do_not_decode[j]; // FIXME - clobbering input
1426  if (do_not_decode[0])
1427  return 0;
1428  ch_used = 1;
1429  max_output += vr->end / ch;
1430  } else {
1431  ch_used = ch;
1432  max_output += vr->end;
1433  }
1434 
1435  if (max_output > ch_left * vlen) {
1436  if (max_output <= ch_left * vlen + vr->partition_size*ch_used/ch) {
1437  ptns_to_read--;
1438  libvorbis_bug = 1;
1439  } else {
1440  av_log(vc->avctx, AV_LOG_ERROR, "Insufficient output buffer\n");
1441  return AVERROR_INVALIDDATA;
1442  }
1443  }
1444 
1445  ff_dlog(NULL, " residue type 0/1/2 decode begin, ch: %d cpc %d \n", ch, c_p_c);
1446 
1447  for (pass = 0; pass <= vr->maxpass; ++pass) { // FIXME OPTIMIZE?
1448  int voffset, partition_count, j_times_ptns_to_read;
1449 
1450  voffset = vr->begin;
1451  for (partition_count = 0; partition_count < ptns_to_read;) { // SPEC error
1452  if (!pass) {
1453  int ret = setup_classifs(vc, vr, do_not_decode, ch_used, partition_count, ptns_to_read);
1454  if (ret < 0)
1455  return ret;
1456  }
1457  for (i = 0; (i < c_p_c) && (partition_count < ptns_to_read); ++i) {
1458  for (j_times_ptns_to_read = 0, j = 0; j < ch_used; ++j) {
1459  unsigned voffs;
1460 
1461  if (!do_not_decode[j]) {
1462  unsigned vqclass = classifs[j_times_ptns_to_read + partition_count];
1463  int vqbook = vr->books[vqclass][pass];
1464 
1465  if (vqbook >= 0 && vc->codebooks[vqbook].codevectors) {
1466  int coffs;
1467  unsigned dim = vc->codebooks[vqbook].dimensions;
1468  unsigned step = FASTDIV(vr->partition_size << 1, dim << 1);
1469  vorbis_codebook codebook = vc->codebooks[vqbook];
1470 
1471  if (get_bits_left(gb) <= 0)
1472  return AVERROR_INVALIDDATA;
1473 
1474  if (vr_type == 0) {
1475 
1476  voffs = voffset+j*vlen;
1477  for (k = 0; k < step; ++k) {
1478  coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3);
1479  if (coffs < 0)
1480  return coffs;
1481  coffs *= dim;
1482  for (l = 0; l < dim; ++l)
1483  vec[voffs + k + l * step] += codebook.codevectors[coffs + l];
1484  }
1485  } else if (vr_type == 1) {
1486  voffs = voffset + j * vlen;
1487  for (k = 0; k < step; ++k) {
1488  coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3);
1489  if (coffs < 0)
1490  return coffs;
1491  coffs *= dim;
1492  for (l = 0; l < dim; ++l, ++voffs) {
1493  vec[voffs]+=codebook.codevectors[coffs+l];
1494 
1495  ff_dlog(NULL, " pass %d offs: %d curr: %f change: %f cv offs.: %d \n",
1496  pass, voffs, vec[voffs], codebook.codevectors[coffs+l], coffs);
1497  }
1498  }
1499  } else if (vr_type == 2 && ch == 2 && (voffset & 1) == 0 && (dim & 1) == 0) { // most frequent case optimized
1500  voffs = voffset >> 1;
1501 
1502  if (dim == 2) {
1503  for (k = 0; k < step; ++k) {
1504  coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3);
1505  if (coffs < 0)
1506  return coffs;
1507  coffs *= 2;
1508  vec[voffs + k ] += codebook.codevectors[coffs ];
1509  vec[voffs + k + vlen] += codebook.codevectors[coffs + 1];
1510  }
1511  } else if (dim == 4) {
1512  for (k = 0; k < step; ++k, voffs += 2) {
1513  coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3);
1514  if (coffs < 0)
1515  return coffs;
1516  coffs *= 4;
1517  vec[voffs ] += codebook.codevectors[coffs ];
1518  vec[voffs + 1 ] += codebook.codevectors[coffs + 2];
1519  vec[voffs + vlen ] += codebook.codevectors[coffs + 1];
1520  vec[voffs + vlen + 1] += codebook.codevectors[coffs + 3];
1521  }
1522  } else
1523  for (k = 0; k < step; ++k) {
1524  coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3);
1525  if (coffs < 0)
1526  return coffs;
1527  coffs *= dim;
1528  for (l = 0; l < dim; l += 2, voffs++) {
1529  vec[voffs ] += codebook.codevectors[coffs + l ];
1530  vec[voffs + vlen] += codebook.codevectors[coffs + l + 1];
1531 
1532  ff_dlog(NULL, " pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n",
1533  pass, voffset / ch + (voffs % ch) * vlen,
1534  vec[voffset / ch + (voffs % ch) * vlen],
1535  codebook.codevectors[coffs + l], coffs, l);
1536  }
1537  }
1538 
1539  } else if (vr_type == 2) {
1540  unsigned voffs_div = ch == 1 ? voffset : FASTDIV(voffset, ch);
1541  unsigned voffs_mod = voffset - voffs_div * ch;
1542 
1543  for (k = 0; k < step; ++k) {
1544  coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3);
1545  if (coffs < 0)
1546  return coffs;
1547  coffs *= dim;
1548  for (l = 0; l < dim; ++l) {
1549  vec[voffs_div + voffs_mod * vlen] +=
1550  codebook.codevectors[coffs + l];
1551 
1552  ff_dlog(NULL, " pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n",
1553  pass, voffs_div + voffs_mod * vlen,
1554  vec[voffs_div + voffs_mod * vlen],
1555  codebook.codevectors[coffs + l], coffs, l);
1556 
1557  if (++voffs_mod == ch) {
1558  voffs_div++;
1559  voffs_mod = 0;
1560  }
1561  }
1562  }
1563  }
1564  }
1565  }
1566  j_times_ptns_to_read += ptns_to_read;
1567  }
1568  ++partition_count;
1569  voffset += vr->partition_size;
1570  }
1571  }
1572  if (libvorbis_bug && !pass) {
1573  for (j = 0; j < ch_used; ++j) {
1574  if (!do_not_decode[j]) {
1575  get_vlc2(&vc->gb, vc->codebooks[vr->classbook].vlc.table,
1576  vc->codebooks[vr->classbook].nb_bits, 3);
1577  }
1578  }
1579  }
1580  }
1581  return 0;
1582 }
1583 
1584 static inline int vorbis_residue_decode(vorbis_context *vc, vorbis_residue *vr,
1585  unsigned ch,
1586  uint8_t *do_not_decode,
1587  float *vec, unsigned vlen,
1588  unsigned ch_left)
1589 {
1590  if (vr->type == 2)
1591  return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vlen, ch_left, 2);
1592  else if (vr->type == 1)
1593  return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vlen, ch_left, 1);
1594  else if (vr->type == 0)
1595  return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vlen, ch_left, 0);
1596  else {
1597  av_log(vc->avctx, AV_LOG_ERROR, " Invalid residue type while residue decode?! \n");
1598  return AVERROR_INVALIDDATA;
1599  }
1600 }
1601 
1602 // Decode the audio packet using the functions above
1603 
1604 static int vorbis_parse_audio_packet(vorbis_context *vc, float **floor_ptr)
1605 {
1606  GetBitContext *gb = &vc->gb;
1607  AVTXContext *mdct;
1608  av_tx_fn mdct_fn;
1609  int previous_window = vc->previous_window;
1610  unsigned mode_number, blockflag, blocksize;
1611  int i, j;
1612  uint8_t no_residue[255];
1613  uint8_t do_not_decode[255];
1614  vorbis_mapping *mapping;
1615  float *ch_res_ptr = vc->channel_residues;
1616  uint8_t res_chan[255];
1617  unsigned res_num = 0;
1618  int retlen = 0;
1619  unsigned ch_left = vc->audio_channels;
1620  unsigned vlen;
1621 
1622  if (get_bits1(gb)) {
1623  av_log(vc->avctx, AV_LOG_ERROR, "Not a Vorbis I audio packet.\n");
1624  return AVERROR_INVALIDDATA; // packet type not audio
1625  }
1626 
1627  if (vc->mode_count == 1) {
1628  mode_number = 0;
1629  } else {
1630  GET_VALIDATED_INDEX(mode_number, ilog(vc->mode_count-1), vc->mode_count)
1631  }
1632  vc->mode_number = mode_number;
1633  mapping = &vc->mappings[vc->modes[mode_number].mapping];
1634 
1635  ff_dlog(NULL, " Mode number: %u , mapping: %d , blocktype %d\n", mode_number,
1636  vc->modes[mode_number].mapping, vc->modes[mode_number].blockflag);
1637 
1638  blockflag = vc->modes[mode_number].blockflag;
1639  blocksize = vc->blocksize[blockflag];
1640  vlen = blocksize / 2;
1641  if (blockflag) {
1642  int code = get_bits(gb, 2);
1643  if (previous_window < 0)
1644  previous_window = code>>1;
1645  } else if (previous_window < 0)
1646  previous_window = 0;
1647 
1648  memset(ch_res_ptr, 0, sizeof(float) * vc->audio_channels * vlen); //FIXME can this be removed ?
1649  for (i = 0; i < vc->audio_channels; ++i)
1650  memset(floor_ptr[i], 0, vlen * sizeof(floor_ptr[0][0])); //FIXME can this be removed ?
1651 
1652 // Decode floor
1653 
1654  for (i = 0; i < vc->audio_channels; ++i) {
1656  int ret;
1657  if (mapping->submaps > 1) {
1658  floor = &vc->floors[mapping->submap_floor[mapping->mux[i]]];
1659  } else {
1660  floor = &vc->floors[mapping->submap_floor[0]];
1661  }
1662 
1663  ret = floor->decode(vc, &floor->data, floor_ptr[i]);
1664 
1665  if (ret < 0) {
1666  av_log(vc->avctx, AV_LOG_ERROR, "Invalid codebook in vorbis_floor_decode.\n");
1667  return AVERROR_INVALIDDATA;
1668  }
1669  no_residue[i] = ret;
1670  }
1671 
1672 // Nonzero vector propagate
1673 
1674  for (i = mapping->coupling_steps - 1; i >= 0; --i) {
1675  if (!(no_residue[mapping->magnitude[i]] & no_residue[mapping->angle[i]])) {
1676  no_residue[mapping->magnitude[i]] = 0;
1677  no_residue[mapping->angle[i]] = 0;
1678  }
1679  }
1680 
1681 // Decode residue
1682 
1683  for (i = 0; i < mapping->submaps; ++i) {
1684  vorbis_residue *residue;
1685  unsigned ch = 0;
1686  int ret;
1687 
1688  for (j = 0; j < vc->audio_channels; ++j) {
1689  if ((mapping->submaps == 1) || (i == mapping->mux[j])) {
1690  res_chan[j] = res_num;
1691  if (no_residue[j]) {
1692  do_not_decode[ch] = 1;
1693  } else {
1694  do_not_decode[ch] = 0;
1695  }
1696  ++ch;
1697  ++res_num;
1698  }
1699  }
1700  residue = &vc->residues[mapping->submap_residue[i]];
1701  if (ch_left < ch) {
1702  av_log(vc->avctx, AV_LOG_ERROR, "Too many channels in vorbis_floor_decode.\n");
1703  return AVERROR_INVALIDDATA;
1704  }
1705  if (ch) {
1706  ret = vorbis_residue_decode(vc, residue, ch, do_not_decode, ch_res_ptr, vlen, ch_left);
1707  if (ret < 0)
1708  return ret;
1709  }
1710 
1711  ch_res_ptr += ch * vlen;
1712  ch_left -= ch;
1713  }
1714 
1715  if (ch_left > 0)
1716  return AVERROR_INVALIDDATA;
1717 
1718 // Inverse coupling
1719 
1720  for (i = mapping->coupling_steps - 1; i >= 0; --i) { //warning: i has to be signed
1721  float *mag, *ang;
1722 
1723  mag = vc->channel_residues+res_chan[mapping->magnitude[i]] * blocksize / 2;
1724  ang = vc->channel_residues+res_chan[mapping->angle[i]] * blocksize / 2;
1725  vc->dsp.vorbis_inverse_coupling(mag, ang, blocksize / 2);
1726  }
1727 
1728 // Dotproduct, MDCT
1729 
1730  mdct = vc->mdct[blockflag];
1731  mdct_fn = vc->mdct_fn[blockflag];
1732 
1733  for (j = vc->audio_channels-1;j >= 0; j--) {
1734  ch_res_ptr = vc->channel_residues + res_chan[j] * blocksize / 2;
1735  vc->fdsp->vector_fmul(floor_ptr[j], floor_ptr[j], ch_res_ptr, blocksize / 2);
1736  mdct_fn(mdct, ch_res_ptr, floor_ptr[j], sizeof(float));
1737  }
1738 
1739 // Overlap/add, save data for next overlapping
1740 
1741  retlen = (blocksize + vc->blocksize[previous_window]) / 4;
1742  for (j = 0; j < vc->audio_channels; j++) {
1743  unsigned bs0 = vc->blocksize[0];
1744  unsigned bs1 = vc->blocksize[1];
1745  float *residue = vc->channel_residues + res_chan[j] * blocksize / 2;
1746  float *saved = vc->saved + j * bs1 / 4;
1747  float *ret = floor_ptr[j];
1748  float *buf = residue;
1749  const float *win = vc->win[blockflag & previous_window];
1750 
1751  if (blockflag == previous_window) {
1752  vc->fdsp->vector_fmul_window(ret, saved, buf, win, blocksize / 4);
1753  } else if (blockflag > previous_window) {
1754  vc->fdsp->vector_fmul_window(ret, saved, buf, win, bs0 / 4);
1755  memcpy(ret+bs0/2, buf+bs0/4, ((bs1-bs0)/4) * sizeof(float));
1756  } else {
1757  memcpy(ret, saved, ((bs1 - bs0) / 4) * sizeof(float));
1758  vc->fdsp->vector_fmul_window(ret + (bs1 - bs0) / 4, saved + (bs1 - bs0) / 4, buf, win, bs0 / 4);
1759  }
1760  memcpy(saved, buf + blocksize / 4, blocksize / 4 * sizeof(float));
1761  }
1762 
1763  vc->previous_window = blockflag;
1764  return retlen;
1765 }
1766 
1767 // Return the decoded audio packet through the standard api
1768 
1770  int *got_frame_ptr, AVPacket *avpkt)
1771 {
1772  const uint8_t *buf = avpkt->data;
1773  int buf_size = avpkt->size;
1774  vorbis_context *vc = avctx->priv_data;
1775  GetBitContext *gb = &vc->gb;
1776  float *channel_ptrs[255];
1777  int i, len, ret;
1778 
1779  ff_dlog(NULL, "packet length %d \n", buf_size);
1780 
1781  if (*buf == 1 && buf_size > 7) {
1782  if ((ret = init_get_bits8(gb, buf + 1, buf_size - 1)) < 0)
1783  return ret;
1784 
1785  vorbis_free(vc);
1786  if ((ret = vorbis_parse_id_hdr(vc))) {
1787  av_log(avctx, AV_LOG_ERROR, "Id header corrupt.\n");
1788  vorbis_free(vc);
1789  return ret;
1790  }
1791 
1793  if (vc->audio_channels > 8) {
1795  avctx->ch_layout.nb_channels = vc->audio_channels;
1796  } else {
1797  av_channel_layout_copy(&avctx->ch_layout, &ff_vorbis_ch_layouts[vc->audio_channels - 1]);
1798  }
1799 
1800  avctx->sample_rate = vc->audio_samplerate;
1801  return buf_size;
1802  }
1803 
1804  if (*buf == 3 && buf_size > 7) {
1805  av_log(avctx, AV_LOG_DEBUG, "Ignoring comment header\n");
1806  return buf_size;
1807  }
1808 
1809  if (*buf == 5 && buf_size > 7 && vc->channel_residues && !vc->modes) {
1810  if ((ret = init_get_bits8(gb, buf + 1, buf_size - 1)) < 0)
1811  return ret;
1812 
1813  if ((ret = vorbis_parse_setup_hdr(vc))) {
1814  av_log(avctx, AV_LOG_ERROR, "Setup header corrupt.\n");
1815  vorbis_free(vc);
1816  return ret;
1817  }
1818  return buf_size;
1819  }
1820 
1821  if (!vc->channel_residues || !vc->modes) {
1822  av_log(avctx, AV_LOG_ERROR, "Data packet before valid headers\n");
1823  return AVERROR_INVALIDDATA;
1824  }
1825 
1826  /* get output buffer */
1827  frame->nb_samples = vc->blocksize[1] / 2;
1828  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
1829  return ret;
1830 
1831  if (vc->audio_channels > 8) {
1832  for (i = 0; i < vc->audio_channels; i++)
1833  channel_ptrs[i] = (float *)frame->extended_data[i];
1834  } else {
1835  for (i = 0; i < vc->audio_channels; i++) {
1836  int ch = ff_vorbis_channel_layout_offsets[vc->audio_channels - 1][i];
1837  channel_ptrs[ch] = (float *)frame->extended_data[i];
1838  }
1839  }
1840 
1841  if ((ret = init_get_bits8(gb, buf, buf_size)) < 0)
1842  return ret;
1843 
1844  if ((len = vorbis_parse_audio_packet(vc, channel_ptrs)) <= 0)
1845  return len;
1846 
1847  if (!vc->first_frame) {
1848  vc->first_frame = 1;
1849  avctx->internal->skip_samples = len;
1850  }
1851 
1852  ff_dlog(NULL, "parsed %d bytes %d bits, returned %d samples (*ch*bits) \n",
1853  get_bits_count(gb) / 8, get_bits_count(gb) % 8, len);
1854 
1855  frame->nb_samples = len;
1856  *got_frame_ptr = 1;
1857 
1858  return buf_size;
1859 }
1860 
1861 // Close decoder
1862 
1864 {
1865  vorbis_context *vc = avctx->priv_data;
1866 
1867  vorbis_free(vc);
1868 
1869  return 0;
1870 }
1871 
1873 {
1874  vorbis_context *vc = avctx->priv_data;
1875 
1876  if (vc->saved) {
1877  memset(vc->saved, 0, (vc->blocksize[1] / 4) * vc->audio_channels *
1878  sizeof(*vc->saved));
1879  }
1880  vc->previous_window = -1;
1881  vc->first_frame = 0;
1882 }
1883 
1885  .p.name = "vorbis",
1886  CODEC_LONG_NAME("Vorbis"),
1887  .p.type = AVMEDIA_TYPE_AUDIO,
1888  .p.id = AV_CODEC_ID_VORBIS,
1889  .priv_data_size = sizeof(vorbis_context),
1891  .close = vorbis_decode_close,
1893  .flush = vorbis_decode_flush,
1894  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
1895  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1896  .p.ch_layouts = ff_vorbis_ch_layouts,
1897  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
1899 };
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
ff_vorbis_decoder
const FFCodec ff_vorbis_decoder
Definition: vorbisdec.c:1884
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
BARK
#define BARK(x)
Definition: vorbisdec.c:164
vorbis_floor::vorbis_floor_u::vorbis_floor0_s::bark_map_size
uint16_t bark_map_size
Definition: vorbisdec.c:75
create_map
static int create_map(vorbis_context *vc, unsigned floor_number)
Definition: vorbisdec.c:859
vorbis_mapping::angle
uint8_t * angle
Definition: vorbisdec.c:115
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
vorbis_context_s::mdct
AVTXContext * mdct[2]
Definition: vorbisdec.c:134
vorbis_floor::floor_type
uint8_t floor_type
Definition: vorbisdec.c:69
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:694
vorbis_decode_close
static av_cold int vorbis_decode_close(AVCodecContext *avctx)
Definition: vorbisdec.c:1863
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
vorbis_mode
Definition: vorbisdec.c:121
vorbis_context_s::codebook_count
uint16_t codebook_count
Definition: vorbisdec.c:146
vorbis_mapping::submaps
uint8_t submaps
Definition: vorbisdec.c:112
vorbis_residue::maxpass
uint8_t maxpass
Definition: vorbisdec.c:106
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1050
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:241
vorbis_floor::vorbis_floor_u::t0
struct vorbis_floor::vorbis_floor_u::vorbis_floor0_s t0
vorbis_context_s::residue_count
uint8_t residue_count
Definition: vorbisdec.c:150
ff_vorbis_ready_floor1_list
int ff_vorbis_ready_floor1_list(void *logctx, vorbis_floor1_entry *list, int values)
Definition: vorbis.c:109
AVTXContext
Definition: tx_priv.h:235
AVCodecInternal::skip_samples
int skip_samples
Number of audio samples to skip at the start of the next decoded frame.
Definition: internal.h:116
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:421
vorbis_context_s::fdsp
AVFloatDSPContext * fdsp
Definition: vorbisdec.c:132
vorbis_context_s::version
uint32_t version
Definition: vorbisdec.c:138
vorbis_floor::vorbis_floor_u
Definition: vorbisdec.c:71
vorbis_mode::transformtype
uint16_t transformtype
Definition: vorbisdec.c:124
vorbis_floor::vorbis_floor_u::vorbis_floor0_s::map
int32_t * map[2]
Definition: vorbisdec.c:76
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:266
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
step
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
Definition: rate_distortion.txt:58
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:522
GET_VALIDATED_INDEX
#define GET_VALIDATED_INDEX(idx, bits, limit)
Definition: vorbisdec.c:175
data
const char data[16]
Definition: mxf.c:148
vorbisfloat2float
static float vorbisfloat2float(unsigned val)
Definition: vorbisdec.c:181
idx_err_str
static const char idx_err_str[]
Definition: vorbisdec.c:167
vorbis_floor1
struct vorbis_floor1_s vorbis_floor1
Definition: vorbisdec.c:63
vorbis_context_s::previous_window
int8_t previous_window
Definition: vorbisdec.c:157
FFCodec
Definition: codec_internal.h:127
vorbis_floor::vorbis_floor_u::vorbis_floor1_s::class_subclasses
uint8_t class_subclasses[16]
Definition: vorbisdec.c:88
vorbis_residue_decode
static int vorbis_residue_decode(vorbis_context *vc, vorbis_residue *vr, unsigned ch, uint8_t *do_not_decode, float *vec, unsigned vlen, unsigned ch_left)
Definition: vorbisdec.c:1584
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:308
vorbis_residue::books
int16_t books[64][8]
Definition: vorbisdec.c:105
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:313
ff_inverse
const uint32_t ff_inverse[257]
Definition: mathtables.c:27
vorbis_floor1_entry::x
uint16_t x
Definition: vorbis.h:27
vorbis_data.h
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:514
av_tx_init
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
Definition: tx.c:902
ff_vorbis_nth_root
unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n)
Definition: vorbis.c:41
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
vorbis_free
static void vorbis_free(vorbis_context *vc)
Definition: vorbisdec.c:193
xiph.h
win
static float win(SuperEqualizerContext *s, float n, int N)
Definition: af_superequalizer.c:119
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:381
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:1065
GetBitContext
Definition: get_bits.h:108
ff_vorbis_floor1_render_list
void ff_vorbis_floor1_render_list(vorbis_floor1_entry *list, int values, uint16_t *y_list, int *flag, int multiplier, float *out, int samples)
Definition: vorbis.c:199
val
static double val(void *priv, double ch)
Definition: aeval.c:78
vorbis_floor::data
union vorbis_floor::vorbis_floor_u data
vorbis_floor_decode_func
int(* vorbis_floor_decode_func)(struct vorbis_context_s *, vorbis_floor_data *, float *)
Definition: vorbisdec.c:67
vorbis_parse_id_hdr
static int vorbis_parse_id_hdr(vorbis_context *vc)
Definition: vorbisdec.c:969
VorbisDSPContext
Definition: vorbisdsp.h:24
vorbis_context_s::gb
GetBitContext gb
Definition: vorbisdec.c:130
avassert.h
vorbis_residue::classbook
uint8_t classbook
Definition: vorbisdec.c:104
vorbis_floor::vorbis_floor_u::vorbis_floor1_s::partition_class
uint8_t partition_class[32]
Definition: vorbisdec.c:86
V_MAX_PARTITIONS
#define V_MAX_PARTITIONS
Definition: vorbisdec.c:50
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:545
av_tx_fn
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition: tx.h:151
vorbis_floor1_entry
Definition: vorbis.h:26
vorbis_context_s::mode_number
uint8_t mode_number
Definition: vorbisdec.c:156
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:524
AV_TX_FLOAT_MDCT
@ AV_TX_FLOAT_MDCT
Standard MDCT with a sample data type of float, double or int32_t, respecively.
Definition: tx.h:68
vorbis_context_s::audio_samplerate
uint32_t audio_samplerate
Definition: vorbisdec.c:140
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:287
VLC_INIT_LE
#define VLC_INIT_LE
Definition: vlc.h:186
floor
static __device__ float floor(float a)
Definition: cuda_runtime.h:173
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_CHANNEL_ORDER_UNSPEC
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
Definition: channel_layout.h:112
vorbis_floor::vorbis_floor_u::vorbis_floor0_s::lsp
float * lsp
Definition: vorbisdec.c:82
vorbis_parse_setup_hdr_tdtransforms
static int vorbis_parse_setup_hdr_tdtransforms(vorbis_context *vc)
Definition: vorbisdec.c:482
vorbis_codebook::nb_bits
unsigned int nb_bits
Definition: vorbisdec.c:58
vorbis_parse_audio_packet
static int vorbis_parse_audio_packet(vorbis_context *vc, float **floor_ptr)
Definition: vorbisdec.c:1604
bits
uint8_t bits
Definition: vp3data.h:128
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
ff_vorbis_len2vlc
int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, unsigned num)
Definition: vorbis.c:59
vlc_init
#define vlc_init(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
Definition: vlc.h:59
vorbis_floor::vorbis_floor_u::vorbis_floor1_s::partitions
uint8_t partitions
Definition: vorbisdec.c:85
vorbis_mode::windowtype
uint16_t windowtype
Definition: vorbisdec.c:123
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
decode.h
get_bits.h
vorbis_context_s::bitrate_nominal
uint32_t bitrate_nominal
Definition: vorbisdec.c:142
isfinite
#define isfinite(x)
Definition: libm.h:359
vorbis_context_s::blocksize
uint32_t blocksize[2]
Definition: vorbisdec.c:144
vorbis_context_s::floors
vorbis_floor * floors
Definition: vorbisdec.c:149
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
vorbis_codebook::codevectors
float * codevectors
Definition: vorbisdec.c:57
vorbis_parse_setup_hdr_residues
static int vorbis_parse_setup_hdr_residues(vorbis_context *vc)
Definition: vorbisdec.c:698
frame
static AVFrame * frame
Definition: demux_decode.c:54
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
if
if(ret)
Definition: filter_design.txt:179
vorbis_residue::ptns_to_read
uint16_t ptns_to_read
Definition: vorbisdec.c:107
NULL
#define NULL
Definition: coverity.c:32
vorbis_mapping::mux
uint8_t * mux
Definition: vorbisdec.c:116
vorbis_context_s::audio_channels
uint8_t audio_channels
Definition: vorbisdec.c:139
VALIDATE_INDEX
#define VALIDATE_INDEX(idx, limit)
Definition: vorbisdec.c:168
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:480
vorbis_context_s::win
const float * win[2]
Definition: vorbisdec.c:145
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
vorbis_floor0_decode
static int vorbis_floor0_decode(vorbis_context *vc, vorbis_floor_data *vfu, float *vec)
Definition: vorbisdec.c:1116
vorbis_context_s::modes
vorbis_mode * modes
Definition: vorbisdec.c:155
FASTDIV
#define FASTDIV(a, b)
Definition: mathops.h:214
vorbis_floor_data
union vorbis_floor_u vorbis_floor_data
Definition: vorbisdec.c:61
vorbis_parse_setup_hdr
static int vorbis_parse_setup_hdr(vorbis_context *vc)
Definition: vorbisdec.c:923
exp
int8_t exp
Definition: eval.c:74
get_vlc2
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:652
vorbis_mapping
Definition: vorbisdec.c:111
float_dsp.h
vorbis_floor0
struct vorbis_floor0_s vorbis_floor0
Definition: vorbisdec.c:62
vorbis_mapping::coupling_steps
uint16_t coupling_steps
Definition: vorbisdec.c:113
vorbis_decode_init
static av_cold int vorbis_decode_init(AVCodecContext *avctx)
Definition: vorbisdec.c:1049
vorbis_floor
Definition: vorbisdec.c:68
AV_CODEC_CAP_CHANNEL_CONF
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
Definition: codec.h:106
vorbis_mapping::submap_residue
uint8_t submap_residue[16]
Definition: vorbisdec.c:118
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
vorbis_decode_frame
static int vorbis_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: vorbisdec.c:1769
vorbis_floor::vorbis_floor_u::vorbis_floor0_s::amplitude_bits
uint8_t amplitude_bits
Definition: vorbisdec.c:78
f
f
Definition: af_crystalizer.c:121
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1568
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
vorbis_mode::blockflag
uint8_t blockflag
Definition: vorbisdec.c:122
AVPacket::size
int size
Definition: packet.h:523
vorbis_parse_setup_hdr_floors
static int vorbis_parse_setup_hdr_floors(vorbis_context *vc)
Definition: vorbisdec.c:508
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: vvc_intra.c:291
codec_internal.h
vorbis_floor::vorbis_floor_u::vorbis_floor0_s::map_size
uint32_t map_size[2]
Definition: vorbisdec.c:77
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1057
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
vorbis_floor::vorbis_floor_u::vorbis_floor1_s::multiplier
uint8_t multiplier
Definition: vorbisdec.c:91
vorbisdsp.h
vorbis_codebook::vlc
VLC vlc
Definition: vorbisdec.c:56
vorbis_floor::vorbis_floor_u::vorbis_floor1_s::class_dimensions
uint8_t class_dimensions[16]
Definition: vorbisdec.c:87
AVFloatDSPContext
Definition: float_dsp.h:22
range
enum AVColorRange range
Definition: mediacodec_wrapper.c:2646
vorbis_context_s::bitrate_minimum
uint32_t bitrate_minimum
Definition: vorbisdec.c:143
vorbis_floor::vorbis_floor_u::vorbis_floor1_s::x_list_dim
uint16_t x_list_dim
Definition: vorbisdec.c:92
vorbis_mode::mapping
uint8_t mapping
Definition: vorbisdec.c:125
vorbis_floor::vorbis_floor_u::vorbis_floor1_s::class_masterbook
uint8_t class_masterbook[16]
Definition: vorbisdec.c:89
vorbis_floor::vorbis_floor_u::vorbis_floor1_s::subclass_books
int16_t subclass_books[16][8]
Definition: vorbisdec.c:90
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
vorbis_codebook::maxdepth
uint8_t maxdepth
Definition: vorbisdec.c:55
vorbis_floor1_decode
static int vorbis_floor1_decode(vorbis_context *vc, vorbis_floor_data *vfu, float *vec)
Definition: vorbisdec.c:1230
vorbis_residue
Definition: vorbisdec.c:98
vorbis_residue::end
uint32_t end
Definition: vorbisdec.c:101
M_PI
#define M_PI
Definition: mathematics.h:67
av_tx_uninit
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
Definition: tx.c:294
ff_vorbis_channel_layout_offsets
const uint8_t ff_vorbis_channel_layout_offsets[8][8]
Definition: vorbis_data.c:26
vorbis_context_s::dsp
VorbisDSPContext dsp
Definition: vorbisdec.c:131
get_bits64
static uint64_t get_bits64(GetBitContext *s, int n)
Read 0-64 bits.
Definition: get_bits.h:453
flag
#define flag(name)
Definition: cbs_av1.c:466
vorbis_residue::type
uint16_t type
Definition: vorbisdec.c:99
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:420
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
vorbis.h
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:523
vorbis_context_s::floor_count
uint8_t floor_count
Definition: vorbisdec.c:148
vorbis_context_s::codebooks
vorbis_codebook * codebooks
Definition: vorbisdec.c:147
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:401
vorbis_residue_decode_internal
static av_always_inline int vorbis_residue_decode_internal(vorbis_context *vc, vorbis_residue *vr, unsigned ch, uint8_t *do_not_decode, float *vec, unsigned vlen, unsigned ch_left, int vr_type)
Definition: vorbisdec.c:1406
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
V_MAX_VLCS
#define V_MAX_VLCS
Definition: vorbisdec.c:49
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
vorbis_context_s
Definition: vorbisdec.c:128
av_always_inline
#define av_always_inline
Definition: attributes.h:49
vorbis_parse_setup_hdr_mappings
static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc)
Definition: vorbisdec.c:779
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
vorbis_context_s::residues
vorbis_residue * residues
Definition: vorbisdec.c:151
vorbis_residue::classifications
uint8_t classifications
Definition: vorbisdec.c:103
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
len
int len
Definition: vorbis_enc_data.h:426
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
vorbis_mapping::submap_floor
uint8_t submap_floor[16]
Definition: vorbisdec.c:117
avcodec.h
vorbis_floor::vorbis_floor_u::vorbis_floor1_s::list
vorbis_floor1_entry * list
Definition: vorbisdec.c:93
dim
int dim
Definition: vorbis_enc_data.h:425
V_NB_BITS
#define V_NB_BITS
Definition: vorbisdec.c:47
ff_vlc_free
void ff_vlc_free(VLC *vlc)
Definition: vlc.c:577
ret
ret
Definition: filter_design.txt:187
vorbis_residue::begin
uint32_t begin
Definition: vorbisdec.c:100
AVCodecContext
main external API structure.
Definition: avcodec.h:445
ilog
#define ilog(i)
Definition: vorbis.h:41
V_NB_BITS2
#define V_NB_BITS2
Definition: vorbisdec.c:48
setup_classifs
static av_always_inline int setup_classifs(vorbis_context *vc, vorbis_residue *vr, uint8_t *do_not_decode, unsigned ch_used, int partition_count, int ptns_to_read)
Definition: vorbisdec.c:1357
vorbis_context_s::avctx
AVCodecContext * avctx
Definition: vorbisdec.c:129
VLC
Definition: vlc.h:36
vorbis_context_s::channel_residues
float * channel_residues
Definition: vorbisdec.c:158
headers
FFmpeg currently uses a custom build this text attempts to document some of its obscure features and options Makefile the full command issued by make and its output will be shown on the screen DBG Preprocess x86 external assembler files to a dbg asm file in the object which then gets compiled Helps in developing those assembler files DESTDIR Destination directory for the install useful to prepare packages or install FFmpeg in cross environments GEN Set to ‘1’ to generate the missing or mismatched references Makefile builds all the libraries and the executables fate Run the fate test note that you must have installed it fate list List all fate regression test targets install Install headers
Definition: build_system.txt:34
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:432
vorbis_mapping::magnitude
uint8_t * magnitude
Definition: vorbisdec.c:114
ff_vorbisdsp_init
av_cold void ff_vorbisdsp_init(VorbisDSPContext *dsp)
Definition: vorbisdsp.c:46
vorbis_context_s::mappings
vorbis_mapping * mappings
Definition: vorbisdec.c:153
temp
else temp
Definition: vf_mcdeint.c:263
L
#define L(x)
Definition: vpx_arith.h:36
vorbis_codebook
Definition: vorbisdec.c:52
avpriv_split_xiph_headers
int avpriv_split_xiph_headers(const uint8_t *extradata, int extradata_size, int first_header_size, const uint8_t *header_start[3], int header_len[3])
Split a single extradata buffer into the three headers that most Xiph codecs use.
Definition: xiph.c:26
av_clip_uint16
#define av_clip_uint16
Definition: common.h:110
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:439
vorbis_context_s::mode_count
uint8_t mode_count
Definition: vorbisdec.c:154
vorbis_codebook::lookup_type
uint8_t lookup_type
Definition: vorbisdec.c:54
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:342
vorbis_context_s::mapping_count
uint8_t mapping_count
Definition: vorbisdec.c:152
vorbis_parse_setup_hdr_codebooks
static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
Definition: vorbisdec.c:243
ff_vorbis_ch_layouts
const AVChannelLayout ff_vorbis_ch_layouts[9]
Definition: vorbis_data.c:37
vorbis_floor::vorbis_floor_u::vorbis_floor0_s::order
uint8_t order
Definition: vorbisdec.c:73
map
const VDPAUPixFmtMap * map
Definition: hwcontext_vdpau.c:71
vorbis_floor::vorbis_floor_u::vorbis_floor0_s::book_list
uint8_t * book_list
Definition: vorbisdec.c:81
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
vorbis_floor::vorbis_floor_u::vorbis_floor1_s
Definition: vorbisdec.c:84
AVPacket
This structure stores compressed data.
Definition: packet.h:499
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
avpriv_float_dsp_alloc
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
vorbis_context_s::bitrate_maximum
uint32_t bitrate_maximum
Definition: vorbisdec.c:141
vorbis_floor::vorbis_floor_u::vorbis_floor0_s::amplitude_offset
uint8_t amplitude_offset
Definition: vorbisdec.c:79
int32_t
int32_t
Definition: audioconvert.c:56
vorbis_context_s::mdct_fn
av_tx_fn mdct_fn[2]
Definition: vorbisdec.c:135
ff_vorbis_vwin
const float *const ff_vorbis_vwin[8]
Definition: vorbis_data.c:2184
vorbis_floor::vorbis_floor_u::vorbis_floor0_s
Definition: vorbisdec.c:72
vorbis_context_s::saved
float * saved
Definition: vorbisdec.c:159
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
AV_CODEC_ID_VORBIS
@ AV_CODEC_ID_VORBIS
Definition: codec_id.h:445
vorbis_residue::classifs
uint8_t * classifs
Definition: vorbisdec.c:108
vorbis_context_s::first_frame
uint8_t first_frame
Definition: vorbisdec.c:137
vorbis_floor::decode
vorbis_floor_decode_func decode
Definition: vorbisdec.c:70
vorbis_decode_flush
static av_cold void vorbis_decode_flush(AVCodecContext *avctx)
Definition: vorbisdec.c:1872
int
int
Definition: ffmpeg_filter.c:425
vorbis_floor::vorbis_floor_u::vorbis_floor0_s::rate
uint16_t rate
Definition: vorbisdec.c:74
vorbis_parse_setup_hdr_modes
static int vorbis_parse_setup_hdr_modes(vorbis_context *vc)
Definition: vorbisdec.c:894
vorbis_floor::vorbis_floor_u::t1
struct vorbis_floor::vorbis_floor_u::vorbis_floor1_s t1
vorbis_floor::vorbis_floor_u::vorbis_floor0_s::num_books
uint8_t num_books
Definition: vorbisdec.c:80
codebook
static const unsigned codebook[256][2]
Definition: cfhdenc.c:42
vorbis_residue::partition_size
unsigned partition_size
Definition: vorbisdec.c:102
tx.h
vorbis_codebook::dimensions
uint8_t dimensions
Definition: vorbisdec.c:53