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