You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1727 lines
63KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * Libav is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. /**
  19. * @file
  20. * Vorbis I decoder
  21. * @author Denes Balatoni ( dbalatoni programozo hu )
  22. */
  23. #include <inttypes.h>
  24. #include <math.h>
  25. #define BITSTREAM_READER_LE
  26. #include "libavutil/float_dsp.h"
  27. #include "avcodec.h"
  28. #include "get_bits.h"
  29. #include "dsputil.h"
  30. #include "fft.h"
  31. #include "fmtconvert.h"
  32. #include "internal.h"
  33. #include "vorbis.h"
  34. #include "xiph.h"
  35. #define V_NB_BITS 8
  36. #define V_NB_BITS2 11
  37. #define V_MAX_VLCS (1 << 16)
  38. #define V_MAX_PARTITIONS (1 << 20)
  39. #undef NDEBUG
  40. #include <assert.h>
  41. typedef struct {
  42. uint8_t dimensions;
  43. uint8_t lookup_type;
  44. uint8_t maxdepth;
  45. VLC vlc;
  46. float *codevectors;
  47. unsigned int nb_bits;
  48. } vorbis_codebook;
  49. typedef union vorbis_floor_u vorbis_floor_data;
  50. typedef struct vorbis_floor0_s vorbis_floor0;
  51. typedef struct vorbis_floor1_s vorbis_floor1;
  52. struct vorbis_context_s;
  53. typedef
  54. int (* vorbis_floor_decode_func)
  55. (struct vorbis_context_s *, vorbis_floor_data *, float *);
  56. typedef struct {
  57. uint8_t floor_type;
  58. vorbis_floor_decode_func decode;
  59. union vorbis_floor_u {
  60. struct vorbis_floor0_s {
  61. uint8_t order;
  62. uint16_t rate;
  63. uint16_t bark_map_size;
  64. int32_t *map[2];
  65. uint32_t map_size[2];
  66. uint8_t amplitude_bits;
  67. uint8_t amplitude_offset;
  68. uint8_t num_books;
  69. uint8_t *book_list;
  70. float *lsp;
  71. } t0;
  72. struct vorbis_floor1_s {
  73. uint8_t partitions;
  74. uint8_t partition_class[32];
  75. uint8_t class_dimensions[16];
  76. uint8_t class_subclasses[16];
  77. uint8_t class_masterbook[16];
  78. int16_t subclass_books[16][8];
  79. uint8_t multiplier;
  80. uint16_t x_list_dim;
  81. vorbis_floor1_entry *list;
  82. } t1;
  83. } data;
  84. } vorbis_floor;
  85. typedef struct {
  86. uint16_t type;
  87. uint32_t begin;
  88. uint32_t end;
  89. unsigned partition_size;
  90. uint8_t classifications;
  91. uint8_t classbook;
  92. int16_t books[64][8];
  93. uint8_t maxpass;
  94. uint16_t ptns_to_read;
  95. uint8_t *classifs;
  96. } vorbis_residue;
  97. typedef struct {
  98. uint8_t submaps;
  99. uint16_t coupling_steps;
  100. uint8_t *magnitude;
  101. uint8_t *angle;
  102. uint8_t *mux;
  103. uint8_t submap_floor[16];
  104. uint8_t submap_residue[16];
  105. } vorbis_mapping;
  106. typedef struct {
  107. uint8_t blockflag;
  108. uint16_t windowtype;
  109. uint16_t transformtype;
  110. uint8_t mapping;
  111. } vorbis_mode;
  112. typedef struct vorbis_context_s {
  113. AVCodecContext *avccontext;
  114. AVFrame frame;
  115. GetBitContext gb;
  116. DSPContext dsp;
  117. AVFloatDSPContext fdsp;
  118. FmtConvertContext fmt_conv;
  119. FFTContext mdct[2];
  120. uint8_t first_frame;
  121. uint32_t version;
  122. uint8_t audio_channels;
  123. uint32_t audio_samplerate;
  124. uint32_t bitrate_maximum;
  125. uint32_t bitrate_nominal;
  126. uint32_t bitrate_minimum;
  127. uint32_t blocksize[2];
  128. const float *win[2];
  129. uint16_t codebook_count;
  130. vorbis_codebook *codebooks;
  131. uint8_t floor_count;
  132. vorbis_floor *floors;
  133. uint8_t residue_count;
  134. vorbis_residue *residues;
  135. uint8_t mapping_count;
  136. vorbis_mapping *mappings;
  137. uint8_t mode_count;
  138. vorbis_mode *modes;
  139. uint8_t mode_number; // mode number for the current packet
  140. uint8_t previous_window;
  141. float *channel_residues;
  142. float *saved;
  143. } vorbis_context;
  144. /* Helper functions */
  145. #define BARK(x) \
  146. (13.1f * atan(0.00074f * (x)) + 2.24f * atan(1.85e-8f * (x) * (x)) + 1e-4f * (x))
  147. static const char idx_err_str[] = "Index value %d out of range (0 - %d) for %s at %s:%i\n";
  148. #define VALIDATE_INDEX(idx, limit) \
  149. if (idx >= limit) {\
  150. av_log(vc->avccontext, AV_LOG_ERROR,\
  151. idx_err_str,\
  152. (int)(idx), (int)(limit - 1), #idx, __FILE__, __LINE__);\
  153. return AVERROR_INVALIDDATA;\
  154. }
  155. #define GET_VALIDATED_INDEX(idx, bits, limit) \
  156. {\
  157. idx = get_bits(gb, bits);\
  158. VALIDATE_INDEX(idx, limit)\
  159. }
  160. static float vorbisfloat2float(unsigned val)
  161. {
  162. double mant = val & 0x1fffff;
  163. long exp = (val & 0x7fe00000L) >> 21;
  164. if (val & 0x80000000)
  165. mant = -mant;
  166. return ldexp(mant, exp - 20 - 768);
  167. }
  168. // Free all allocated memory -----------------------------------------
  169. static void vorbis_free(vorbis_context *vc)
  170. {
  171. int i;
  172. av_freep(&vc->channel_residues);
  173. av_freep(&vc->saved);
  174. for (i = 0; i < vc->residue_count; i++)
  175. av_free(vc->residues[i].classifs);
  176. av_freep(&vc->residues);
  177. av_freep(&vc->modes);
  178. ff_mdct_end(&vc->mdct[0]);
  179. ff_mdct_end(&vc->mdct[1]);
  180. for (i = 0; i < vc->codebook_count; ++i) {
  181. av_free(vc->codebooks[i].codevectors);
  182. ff_free_vlc(&vc->codebooks[i].vlc);
  183. }
  184. av_freep(&vc->codebooks);
  185. for (i = 0; i < vc->floor_count; ++i) {
  186. if (vc->floors[i].floor_type == 0) {
  187. av_free(vc->floors[i].data.t0.map[0]);
  188. av_free(vc->floors[i].data.t0.map[1]);
  189. av_free(vc->floors[i].data.t0.book_list);
  190. av_free(vc->floors[i].data.t0.lsp);
  191. } else {
  192. av_free(vc->floors[i].data.t1.list);
  193. }
  194. }
  195. av_freep(&vc->floors);
  196. for (i = 0; i < vc->mapping_count; ++i) {
  197. av_free(vc->mappings[i].magnitude);
  198. av_free(vc->mappings[i].angle);
  199. av_free(vc->mappings[i].mux);
  200. }
  201. av_freep(&vc->mappings);
  202. }
  203. // Parse setup header -------------------------------------------------
  204. // Process codebooks part
  205. static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
  206. {
  207. unsigned cb;
  208. uint8_t *tmp_vlc_bits;
  209. uint32_t *tmp_vlc_codes;
  210. GetBitContext *gb = &vc->gb;
  211. uint16_t *codebook_multiplicands;
  212. int ret = 0;
  213. vc->codebook_count = get_bits(gb, 8) + 1;
  214. av_dlog(NULL, " Codebooks: %d \n", vc->codebook_count);
  215. vc->codebooks = av_mallocz(vc->codebook_count * sizeof(*vc->codebooks));
  216. tmp_vlc_bits = av_mallocz(V_MAX_VLCS * sizeof(*tmp_vlc_bits));
  217. tmp_vlc_codes = av_mallocz(V_MAX_VLCS * sizeof(*tmp_vlc_codes));
  218. codebook_multiplicands = av_malloc(V_MAX_VLCS * sizeof(*codebook_multiplicands));
  219. for (cb = 0; cb < vc->codebook_count; ++cb) {
  220. vorbis_codebook *codebook_setup = &vc->codebooks[cb];
  221. unsigned ordered, t, entries, used_entries = 0;
  222. av_dlog(NULL, " %u. Codebook\n", cb);
  223. if (get_bits(gb, 24) != 0x564342) {
  224. av_log(vc->avccontext, AV_LOG_ERROR,
  225. " %u. Codebook setup data corrupt.\n", cb);
  226. ret = AVERROR_INVALIDDATA;
  227. goto error;
  228. }
  229. codebook_setup->dimensions=get_bits(gb, 16);
  230. if (codebook_setup->dimensions > 16 || codebook_setup->dimensions == 0) {
  231. av_log(vc->avccontext, AV_LOG_ERROR,
  232. " %u. Codebook's dimension is invalid (%d).\n",
  233. cb, codebook_setup->dimensions);
  234. ret = AVERROR_INVALIDDATA;
  235. goto error;
  236. }
  237. entries = get_bits(gb, 24);
  238. if (entries > V_MAX_VLCS) {
  239. av_log(vc->avccontext, AV_LOG_ERROR,
  240. " %u. Codebook has too many entries (%u).\n",
  241. cb, entries);
  242. ret = AVERROR_INVALIDDATA;
  243. goto error;
  244. }
  245. ordered = get_bits1(gb);
  246. av_dlog(NULL, " codebook_dimensions %d, codebook_entries %u\n",
  247. codebook_setup->dimensions, entries);
  248. if (!ordered) {
  249. unsigned ce, flag;
  250. unsigned sparse = get_bits1(gb);
  251. av_dlog(NULL, " not ordered \n");
  252. if (sparse) {
  253. av_dlog(NULL, " sparse \n");
  254. used_entries = 0;
  255. for (ce = 0; ce < entries; ++ce) {
  256. flag = get_bits1(gb);
  257. if (flag) {
  258. tmp_vlc_bits[ce] = get_bits(gb, 5) + 1;
  259. ++used_entries;
  260. } else
  261. tmp_vlc_bits[ce] = 0;
  262. }
  263. } else {
  264. av_dlog(NULL, " not sparse \n");
  265. used_entries = entries;
  266. for (ce = 0; ce < entries; ++ce)
  267. tmp_vlc_bits[ce] = get_bits(gb, 5) + 1;
  268. }
  269. } else {
  270. unsigned current_entry = 0;
  271. unsigned current_length = get_bits(gb, 5) + 1;
  272. av_dlog(NULL, " ordered, current length: %u\n", current_length); //FIXME
  273. used_entries = entries;
  274. for (; current_entry < used_entries && current_length <= 32; ++current_length) {
  275. unsigned i, number;
  276. av_dlog(NULL, " number bits: %u ", ilog(entries - current_entry));
  277. number = get_bits(gb, ilog(entries - current_entry));
  278. av_dlog(NULL, " number: %u\n", number);
  279. for (i = current_entry; i < number+current_entry; ++i)
  280. if (i < used_entries)
  281. tmp_vlc_bits[i] = current_length;
  282. current_entry+=number;
  283. }
  284. if (current_entry>used_entries) {
  285. av_log(vc->avccontext, AV_LOG_ERROR, " More codelengths than codes in codebook. \n");
  286. ret = AVERROR_INVALIDDATA;
  287. goto error;
  288. }
  289. }
  290. codebook_setup->lookup_type = get_bits(gb, 4);
  291. av_dlog(NULL, " lookup type: %d : %s \n", codebook_setup->lookup_type,
  292. codebook_setup->lookup_type ? "vq" : "no lookup");
  293. // If the codebook is used for (inverse) VQ, calculate codevectors.
  294. if (codebook_setup->lookup_type == 1) {
  295. unsigned i, j, k;
  296. unsigned codebook_lookup_values = ff_vorbis_nth_root(entries, codebook_setup->dimensions);
  297. float codebook_minimum_value = vorbisfloat2float(get_bits_long(gb, 32));
  298. float codebook_delta_value = vorbisfloat2float(get_bits_long(gb, 32));
  299. unsigned codebook_value_bits = get_bits(gb, 4) + 1;
  300. unsigned codebook_sequence_p = get_bits1(gb);
  301. av_dlog(NULL, " We expect %d numbers for building the codevectors. \n",
  302. codebook_lookup_values);
  303. av_dlog(NULL, " delta %f minmum %f \n",
  304. codebook_delta_value, codebook_minimum_value);
  305. for (i = 0; i < codebook_lookup_values; ++i) {
  306. codebook_multiplicands[i] = get_bits(gb, codebook_value_bits);
  307. av_dlog(NULL, " multiplicands*delta+minmum : %e \n",
  308. (float)codebook_multiplicands[i] * codebook_delta_value + codebook_minimum_value);
  309. av_dlog(NULL, " multiplicand %u\n", codebook_multiplicands[i]);
  310. }
  311. // Weed out unused vlcs and build codevector vector
  312. codebook_setup->codevectors = used_entries ? av_mallocz(used_entries *
  313. codebook_setup->dimensions *
  314. sizeof(*codebook_setup->codevectors))
  315. : NULL;
  316. for (j = 0, i = 0; i < entries; ++i) {
  317. unsigned dim = codebook_setup->dimensions;
  318. if (tmp_vlc_bits[i]) {
  319. float last = 0.0;
  320. unsigned lookup_offset = i;
  321. av_dlog(vc->avccontext, "Lookup offset %u ,", i);
  322. for (k = 0; k < dim; ++k) {
  323. unsigned multiplicand_offset = lookup_offset % codebook_lookup_values;
  324. codebook_setup->codevectors[j * dim + k] = codebook_multiplicands[multiplicand_offset] * codebook_delta_value + codebook_minimum_value + last;
  325. if (codebook_sequence_p)
  326. last = codebook_setup->codevectors[j * dim + k];
  327. lookup_offset/=codebook_lookup_values;
  328. }
  329. tmp_vlc_bits[j] = tmp_vlc_bits[i];
  330. av_dlog(vc->avccontext, "real lookup offset %u, vector: ", j);
  331. for (k = 0; k < dim; ++k)
  332. av_dlog(vc->avccontext, " %f ",
  333. codebook_setup->codevectors[j * dim + k]);
  334. av_dlog(vc->avccontext, "\n");
  335. ++j;
  336. }
  337. }
  338. if (j != used_entries) {
  339. av_log(vc->avccontext, AV_LOG_ERROR, "Bug in codevector vector building code. \n");
  340. ret = AVERROR_INVALIDDATA;
  341. goto error;
  342. }
  343. entries = used_entries;
  344. } else if (codebook_setup->lookup_type >= 2) {
  345. av_log(vc->avccontext, AV_LOG_ERROR, "Codebook lookup type not supported. \n");
  346. ret = AVERROR_INVALIDDATA;
  347. goto error;
  348. }
  349. // Initialize VLC table
  350. if (ff_vorbis_len2vlc(tmp_vlc_bits, tmp_vlc_codes, entries)) {
  351. av_log(vc->avccontext, AV_LOG_ERROR, " Invalid code lengths while generating vlcs. \n");
  352. ret = AVERROR_INVALIDDATA;
  353. goto error;
  354. }
  355. codebook_setup->maxdepth = 0;
  356. for (t = 0; t < entries; ++t)
  357. if (tmp_vlc_bits[t] >= codebook_setup->maxdepth)
  358. codebook_setup->maxdepth = tmp_vlc_bits[t];
  359. if (codebook_setup->maxdepth > 3 * V_NB_BITS)
  360. codebook_setup->nb_bits = V_NB_BITS2;
  361. else
  362. codebook_setup->nb_bits = V_NB_BITS;
  363. codebook_setup->maxdepth = (codebook_setup->maxdepth+codebook_setup->nb_bits - 1) / codebook_setup->nb_bits;
  364. if ((ret = init_vlc(&codebook_setup->vlc, codebook_setup->nb_bits,
  365. entries, tmp_vlc_bits, sizeof(*tmp_vlc_bits),
  366. sizeof(*tmp_vlc_bits), tmp_vlc_codes,
  367. sizeof(*tmp_vlc_codes), sizeof(*tmp_vlc_codes),
  368. INIT_VLC_LE))) {
  369. av_log(vc->avccontext, AV_LOG_ERROR, " Error generating vlc tables. \n");
  370. goto error;
  371. }
  372. }
  373. av_free(tmp_vlc_bits);
  374. av_free(tmp_vlc_codes);
  375. av_free(codebook_multiplicands);
  376. return 0;
  377. // Error:
  378. error:
  379. av_free(tmp_vlc_bits);
  380. av_free(tmp_vlc_codes);
  381. av_free(codebook_multiplicands);
  382. return ret;
  383. }
  384. // Process time domain transforms part (unused in Vorbis I)
  385. static int vorbis_parse_setup_hdr_tdtransforms(vorbis_context *vc)
  386. {
  387. GetBitContext *gb = &vc->gb;
  388. unsigned i, vorbis_time_count = get_bits(gb, 6) + 1;
  389. for (i = 0; i < vorbis_time_count; ++i) {
  390. unsigned vorbis_tdtransform = get_bits(gb, 16);
  391. av_dlog(NULL, " Vorbis time domain transform %u: %u\n",
  392. vorbis_time_count, vorbis_tdtransform);
  393. if (vorbis_tdtransform) {
  394. av_log(vc->avccontext, AV_LOG_ERROR, "Vorbis time domain transform data nonzero. \n");
  395. return AVERROR_INVALIDDATA;
  396. }
  397. }
  398. return 0;
  399. }
  400. // Process floors part
  401. static int vorbis_floor0_decode(vorbis_context *vc,
  402. vorbis_floor_data *vfu, float *vec);
  403. static void create_map(vorbis_context *vc, unsigned floor_number);
  404. static int vorbis_floor1_decode(vorbis_context *vc,
  405. vorbis_floor_data *vfu, float *vec);
  406. static int vorbis_parse_setup_hdr_floors(vorbis_context *vc)
  407. {
  408. GetBitContext *gb = &vc->gb;
  409. int i,j,k;
  410. vc->floor_count = get_bits(gb, 6) + 1;
  411. vc->floors = av_mallocz(vc->floor_count * sizeof(*vc->floors));
  412. for (i = 0; i < vc->floor_count; ++i) {
  413. vorbis_floor *floor_setup = &vc->floors[i];
  414. floor_setup->floor_type = get_bits(gb, 16);
  415. av_dlog(NULL, " %d. floor type %d \n", i, floor_setup->floor_type);
  416. if (floor_setup->floor_type == 1) {
  417. int maximum_class = -1;
  418. unsigned rangebits, rangemax, floor1_values = 2;
  419. floor_setup->decode = vorbis_floor1_decode;
  420. floor_setup->data.t1.partitions = get_bits(gb, 5);
  421. av_dlog(NULL, " %d.floor: %d partitions \n",
  422. i, floor_setup->data.t1.partitions);
  423. for (j = 0; j < floor_setup->data.t1.partitions; ++j) {
  424. floor_setup->data.t1.partition_class[j] = get_bits(gb, 4);
  425. if (floor_setup->data.t1.partition_class[j] > maximum_class)
  426. maximum_class = floor_setup->data.t1.partition_class[j];
  427. av_dlog(NULL, " %d. floor %d partition class %d \n",
  428. i, j, floor_setup->data.t1.partition_class[j]);
  429. }
  430. av_dlog(NULL, " maximum class %d \n", maximum_class);
  431. for (j = 0; j <= maximum_class; ++j) {
  432. floor_setup->data.t1.class_dimensions[j] = get_bits(gb, 3) + 1;
  433. floor_setup->data.t1.class_subclasses[j] = get_bits(gb, 2);
  434. av_dlog(NULL, " %d floor %d class dim: %d subclasses %d \n", i, j,
  435. floor_setup->data.t1.class_dimensions[j],
  436. floor_setup->data.t1.class_subclasses[j]);
  437. if (floor_setup->data.t1.class_subclasses[j]) {
  438. GET_VALIDATED_INDEX(floor_setup->data.t1.class_masterbook[j], 8, vc->codebook_count)
  439. av_dlog(NULL, " masterbook: %d \n", floor_setup->data.t1.class_masterbook[j]);
  440. }
  441. for (k = 0; k < (1 << floor_setup->data.t1.class_subclasses[j]); ++k) {
  442. int16_t bits = get_bits(gb, 8) - 1;
  443. if (bits != -1)
  444. VALIDATE_INDEX(bits, vc->codebook_count)
  445. floor_setup->data.t1.subclass_books[j][k] = bits;
  446. av_dlog(NULL, " book %d. : %d \n", k, floor_setup->data.t1.subclass_books[j][k]);
  447. }
  448. }
  449. floor_setup->data.t1.multiplier = get_bits(gb, 2) + 1;
  450. floor_setup->data.t1.x_list_dim = 2;
  451. for (j = 0; j < floor_setup->data.t1.partitions; ++j)
  452. floor_setup->data.t1.x_list_dim+=floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]];
  453. floor_setup->data.t1.list = av_mallocz(floor_setup->data.t1.x_list_dim *
  454. sizeof(*floor_setup->data.t1.list));
  455. rangebits = get_bits(gb, 4);
  456. rangemax = (1 << rangebits);
  457. if (rangemax > vc->blocksize[1] / 2) {
  458. av_log(vc->avccontext, AV_LOG_ERROR,
  459. "Floor value is too large for blocksize: %u (%"PRIu32")\n",
  460. rangemax, vc->blocksize[1] / 2);
  461. return AVERROR_INVALIDDATA;
  462. }
  463. floor_setup->data.t1.list[0].x = 0;
  464. floor_setup->data.t1.list[1].x = rangemax;
  465. for (j = 0; j < floor_setup->data.t1.partitions; ++j) {
  466. for (k = 0; k < floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]]; ++k, ++floor1_values) {
  467. floor_setup->data.t1.list[floor1_values].x = get_bits(gb, rangebits);
  468. av_dlog(NULL, " %u. floor1 Y coord. %d\n", floor1_values,
  469. floor_setup->data.t1.list[floor1_values].x);
  470. }
  471. }
  472. // Precalculate order of x coordinates - needed for decode
  473. if (ff_vorbis_ready_floor1_list(vc->avccontext,
  474. floor_setup->data.t1.list,
  475. floor_setup->data.t1.x_list_dim)) {
  476. return AVERROR_INVALIDDATA;
  477. }
  478. } else if (floor_setup->floor_type == 0) {
  479. unsigned max_codebook_dim = 0;
  480. floor_setup->decode = vorbis_floor0_decode;
  481. floor_setup->data.t0.order = get_bits(gb, 8);
  482. floor_setup->data.t0.rate = get_bits(gb, 16);
  483. floor_setup->data.t0.bark_map_size = get_bits(gb, 16);
  484. floor_setup->data.t0.amplitude_bits = get_bits(gb, 6);
  485. /* zero would result in a div by zero later *
  486. * 2^0 - 1 == 0 */
  487. if (floor_setup->data.t0.amplitude_bits == 0) {
  488. av_log(vc->avccontext, AV_LOG_ERROR,
  489. "Floor 0 amplitude bits is 0.\n");
  490. return AVERROR_INVALIDDATA;
  491. }
  492. floor_setup->data.t0.amplitude_offset = get_bits(gb, 8);
  493. floor_setup->data.t0.num_books = get_bits(gb, 4) + 1;
  494. /* allocate mem for booklist */
  495. floor_setup->data.t0.book_list =
  496. av_malloc(floor_setup->data.t0.num_books);
  497. if (!floor_setup->data.t0.book_list)
  498. return AVERROR(ENOMEM);
  499. /* read book indexes */
  500. {
  501. int idx;
  502. unsigned book_idx;
  503. for (idx = 0; idx < floor_setup->data.t0.num_books; ++idx) {
  504. GET_VALIDATED_INDEX(book_idx, 8, vc->codebook_count)
  505. floor_setup->data.t0.book_list[idx] = book_idx;
  506. if (vc->codebooks[book_idx].dimensions > max_codebook_dim)
  507. max_codebook_dim = vc->codebooks[book_idx].dimensions;
  508. }
  509. }
  510. create_map(vc, i);
  511. /* codebook dim is for padding if codebook dim doesn't *
  512. * divide order+1 then we need to read more data */
  513. floor_setup->data.t0.lsp =
  514. av_malloc((floor_setup->data.t0.order + 1 + max_codebook_dim)
  515. * sizeof(*floor_setup->data.t0.lsp));
  516. if (!floor_setup->data.t0.lsp)
  517. return AVERROR(ENOMEM);
  518. /* debug output parsed headers */
  519. av_dlog(NULL, "floor0 order: %u\n", floor_setup->data.t0.order);
  520. av_dlog(NULL, "floor0 rate: %u\n", floor_setup->data.t0.rate);
  521. av_dlog(NULL, "floor0 bark map size: %u\n",
  522. floor_setup->data.t0.bark_map_size);
  523. av_dlog(NULL, "floor0 amplitude bits: %u\n",
  524. floor_setup->data.t0.amplitude_bits);
  525. av_dlog(NULL, "floor0 amplitude offset: %u\n",
  526. floor_setup->data.t0.amplitude_offset);
  527. av_dlog(NULL, "floor0 number of books: %u\n",
  528. floor_setup->data.t0.num_books);
  529. av_dlog(NULL, "floor0 book list pointer: %p\n",
  530. floor_setup->data.t0.book_list);
  531. {
  532. int idx;
  533. for (idx = 0; idx < floor_setup->data.t0.num_books; ++idx) {
  534. av_dlog(NULL, " Book %d: %u\n", idx + 1,
  535. floor_setup->data.t0.book_list[idx]);
  536. }
  537. }
  538. } else {
  539. av_log(vc->avccontext, AV_LOG_ERROR, "Invalid floor type!\n");
  540. return AVERROR_INVALIDDATA;
  541. }
  542. }
  543. return 0;
  544. }
  545. // Process residues part
  546. static int vorbis_parse_setup_hdr_residues(vorbis_context *vc)
  547. {
  548. GetBitContext *gb = &vc->gb;
  549. unsigned i, j, k;
  550. vc->residue_count = get_bits(gb, 6)+1;
  551. vc->residues = av_mallocz(vc->residue_count * sizeof(*vc->residues));
  552. av_dlog(NULL, " There are %d residues. \n", vc->residue_count);
  553. for (i = 0; i < vc->residue_count; ++i) {
  554. vorbis_residue *res_setup = &vc->residues[i];
  555. uint8_t cascade[64];
  556. unsigned high_bits, low_bits;
  557. res_setup->type = get_bits(gb, 16);
  558. av_dlog(NULL, " %u. residue type %d\n", i, res_setup->type);
  559. res_setup->begin = get_bits(gb, 24);
  560. res_setup->end = get_bits(gb, 24);
  561. res_setup->partition_size = get_bits(gb, 24) + 1;
  562. /* Validations to prevent a buffer overflow later. */
  563. if (res_setup->begin>res_setup->end ||
  564. res_setup->end > (res_setup->type == 2 ? vc->avccontext->channels : 1) * vc->blocksize[1] / 2 ||
  565. (res_setup->end-res_setup->begin) / res_setup->partition_size > V_MAX_PARTITIONS) {
  566. av_log(vc->avccontext, AV_LOG_ERROR,
  567. "partition out of bounds: type, begin, end, size, blocksize: %"PRIu16", %"PRIu32", %"PRIu32", %u, %"PRIu32"\n",
  568. res_setup->type, res_setup->begin, res_setup->end,
  569. res_setup->partition_size, vc->blocksize[1] / 2);
  570. return AVERROR_INVALIDDATA;
  571. }
  572. res_setup->classifications = get_bits(gb, 6) + 1;
  573. GET_VALIDATED_INDEX(res_setup->classbook, 8, vc->codebook_count)
  574. res_setup->ptns_to_read =
  575. (res_setup->end - res_setup->begin) / res_setup->partition_size;
  576. res_setup->classifs = av_malloc(res_setup->ptns_to_read *
  577. vc->audio_channels *
  578. sizeof(*res_setup->classifs));
  579. if (!res_setup->classifs)
  580. return AVERROR(ENOMEM);
  581. av_dlog(NULL, " begin %d end %d part.size %d classif.s %d classbook %d \n",
  582. res_setup->begin, res_setup->end, res_setup->partition_size,
  583. res_setup->classifications, res_setup->classbook);
  584. for (j = 0; j < res_setup->classifications; ++j) {
  585. high_bits = 0;
  586. low_bits = get_bits(gb, 3);
  587. if (get_bits1(gb))
  588. high_bits = get_bits(gb, 5);
  589. cascade[j] = (high_bits << 3) + low_bits;
  590. av_dlog(NULL, " %u class cascade depth: %d\n", j, ilog(cascade[j]));
  591. }
  592. res_setup->maxpass = 0;
  593. for (j = 0; j < res_setup->classifications; ++j) {
  594. for (k = 0; k < 8; ++k) {
  595. if (cascade[j]&(1 << k)) {
  596. GET_VALIDATED_INDEX(res_setup->books[j][k], 8, vc->codebook_count)
  597. av_dlog(NULL, " %u class cascade depth %u book: %d\n",
  598. j, k, res_setup->books[j][k]);
  599. if (k>res_setup->maxpass)
  600. res_setup->maxpass = k;
  601. } else {
  602. res_setup->books[j][k] = -1;
  603. }
  604. }
  605. }
  606. }
  607. return 0;
  608. }
  609. // Process mappings part
  610. static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc)
  611. {
  612. GetBitContext *gb = &vc->gb;
  613. unsigned i, j;
  614. vc->mapping_count = get_bits(gb, 6)+1;
  615. vc->mappings = av_mallocz(vc->mapping_count * sizeof(*vc->mappings));
  616. av_dlog(NULL, " There are %d mappings. \n", vc->mapping_count);
  617. for (i = 0; i < vc->mapping_count; ++i) {
  618. vorbis_mapping *mapping_setup = &vc->mappings[i];
  619. if (get_bits(gb, 16)) {
  620. av_log(vc->avccontext, AV_LOG_ERROR, "Other mappings than type 0 are not compliant with the Vorbis I specification. \n");
  621. return AVERROR_INVALIDDATA;
  622. }
  623. if (get_bits1(gb)) {
  624. mapping_setup->submaps = get_bits(gb, 4) + 1;
  625. } else {
  626. mapping_setup->submaps = 1;
  627. }
  628. if (get_bits1(gb)) {
  629. mapping_setup->coupling_steps = get_bits(gb, 8) + 1;
  630. mapping_setup->magnitude = av_mallocz(mapping_setup->coupling_steps *
  631. sizeof(*mapping_setup->magnitude));
  632. mapping_setup->angle = av_mallocz(mapping_setup->coupling_steps *
  633. sizeof(*mapping_setup->angle));
  634. for (j = 0; j < mapping_setup->coupling_steps; ++j) {
  635. GET_VALIDATED_INDEX(mapping_setup->magnitude[j], ilog(vc->audio_channels - 1), vc->audio_channels)
  636. GET_VALIDATED_INDEX(mapping_setup->angle[j], ilog(vc->audio_channels - 1), vc->audio_channels)
  637. }
  638. } else {
  639. mapping_setup->coupling_steps = 0;
  640. }
  641. av_dlog(NULL, " %u mapping coupling steps: %d\n",
  642. i, mapping_setup->coupling_steps);
  643. if (get_bits(gb, 2)) {
  644. av_log(vc->avccontext, AV_LOG_ERROR, "%u. mapping setup data invalid.\n", i);
  645. return AVERROR_INVALIDDATA; // following spec.
  646. }
  647. if (mapping_setup->submaps>1) {
  648. mapping_setup->mux = av_mallocz(vc->audio_channels *
  649. sizeof(*mapping_setup->mux));
  650. for (j = 0; j < vc->audio_channels; ++j)
  651. mapping_setup->mux[j] = get_bits(gb, 4);
  652. }
  653. for (j = 0; j < mapping_setup->submaps; ++j) {
  654. skip_bits(gb, 8); // FIXME check?
  655. GET_VALIDATED_INDEX(mapping_setup->submap_floor[j], 8, vc->floor_count)
  656. GET_VALIDATED_INDEX(mapping_setup->submap_residue[j], 8, vc->residue_count)
  657. av_dlog(NULL, " %u mapping %u submap : floor %d, residue %d\n", i, j,
  658. mapping_setup->submap_floor[j],
  659. mapping_setup->submap_residue[j]);
  660. }
  661. }
  662. return 0;
  663. }
  664. // Process modes part
  665. static void create_map(vorbis_context *vc, unsigned floor_number)
  666. {
  667. vorbis_floor *floors = vc->floors;
  668. vorbis_floor0 *vf;
  669. int idx;
  670. int blockflag, n;
  671. int32_t *map;
  672. for (blockflag = 0; blockflag < 2; ++blockflag) {
  673. n = vc->blocksize[blockflag] / 2;
  674. floors[floor_number].data.t0.map[blockflag] =
  675. av_malloc((n + 1) * sizeof(int32_t)); // n + sentinel
  676. map = floors[floor_number].data.t0.map[blockflag];
  677. vf = &floors[floor_number].data.t0;
  678. for (idx = 0; idx < n; ++idx) {
  679. map[idx] = floor(BARK((vf->rate * idx) / (2.0f * n)) *
  680. (vf->bark_map_size / BARK(vf->rate / 2.0f)));
  681. if (vf->bark_map_size-1 < map[idx])
  682. map[idx] = vf->bark_map_size - 1;
  683. }
  684. map[n] = -1;
  685. vf->map_size[blockflag] = n;
  686. }
  687. for (idx = 0; idx <= n; ++idx) {
  688. av_dlog(NULL, "floor0 map: map at pos %d is %d\n", idx, map[idx]);
  689. }
  690. }
  691. static int vorbis_parse_setup_hdr_modes(vorbis_context *vc)
  692. {
  693. GetBitContext *gb = &vc->gb;
  694. unsigned i;
  695. vc->mode_count = get_bits(gb, 6) + 1;
  696. vc->modes = av_mallocz(vc->mode_count * sizeof(*vc->modes));
  697. av_dlog(NULL, " There are %d modes.\n", vc->mode_count);
  698. for (i = 0; i < vc->mode_count; ++i) {
  699. vorbis_mode *mode_setup = &vc->modes[i];
  700. mode_setup->blockflag = get_bits1(gb);
  701. mode_setup->windowtype = get_bits(gb, 16); //FIXME check
  702. mode_setup->transformtype = get_bits(gb, 16); //FIXME check
  703. GET_VALIDATED_INDEX(mode_setup->mapping, 8, vc->mapping_count);
  704. av_dlog(NULL, " %u mode: blockflag %d, windowtype %d, transformtype %d, mapping %d\n",
  705. i, mode_setup->blockflag, mode_setup->windowtype,
  706. mode_setup->transformtype, mode_setup->mapping);
  707. }
  708. return 0;
  709. }
  710. // Process the whole setup header using the functions above
  711. static int vorbis_parse_setup_hdr(vorbis_context *vc)
  712. {
  713. GetBitContext *gb = &vc->gb;
  714. int ret;
  715. if ((get_bits(gb, 8) != 'v') || (get_bits(gb, 8) != 'o') ||
  716. (get_bits(gb, 8) != 'r') || (get_bits(gb, 8) != 'b') ||
  717. (get_bits(gb, 8) != 'i') || (get_bits(gb, 8) != 's')) {
  718. av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (no vorbis signature). \n");
  719. return AVERROR_INVALIDDATA;
  720. }
  721. if ((ret = vorbis_parse_setup_hdr_codebooks(vc))) {
  722. av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (codebooks). \n");
  723. return ret;
  724. }
  725. if ((ret = vorbis_parse_setup_hdr_tdtransforms(vc))) {
  726. av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (time domain transforms). \n");
  727. return ret;
  728. }
  729. if ((ret = vorbis_parse_setup_hdr_floors(vc))) {
  730. av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (floors). \n");
  731. return ret;
  732. }
  733. if ((ret = vorbis_parse_setup_hdr_residues(vc))) {
  734. av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (residues). \n");
  735. return ret;
  736. }
  737. if ((ret = vorbis_parse_setup_hdr_mappings(vc))) {
  738. av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (mappings). \n");
  739. return ret;
  740. }
  741. if ((ret = vorbis_parse_setup_hdr_modes(vc))) {
  742. av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (modes). \n");
  743. return ret;
  744. }
  745. if (!get_bits1(gb)) {
  746. av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (framing flag). \n");
  747. return AVERROR_INVALIDDATA; // framing flag bit unset error
  748. }
  749. return 0;
  750. }
  751. // Process the identification header
  752. static int vorbis_parse_id_hdr(vorbis_context *vc)
  753. {
  754. GetBitContext *gb = &vc->gb;
  755. unsigned bl0, bl1;
  756. if ((get_bits(gb, 8) != 'v') || (get_bits(gb, 8) != 'o') ||
  757. (get_bits(gb, 8) != 'r') || (get_bits(gb, 8) != 'b') ||
  758. (get_bits(gb, 8) != 'i') || (get_bits(gb, 8) != 's')) {
  759. av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (no vorbis signature). \n");
  760. return AVERROR_INVALIDDATA;
  761. }
  762. vc->version = get_bits_long(gb, 32); //FIXME check 0
  763. vc->audio_channels = get_bits(gb, 8);
  764. if (vc->audio_channels <= 0) {
  765. av_log(vc->avccontext, AV_LOG_ERROR, "Invalid number of channels\n");
  766. return AVERROR_INVALIDDATA;
  767. }
  768. vc->audio_samplerate = get_bits_long(gb, 32);
  769. if (vc->audio_samplerate <= 0) {
  770. av_log(vc->avccontext, AV_LOG_ERROR, "Invalid samplerate\n");
  771. return AVERROR_INVALIDDATA;
  772. }
  773. vc->bitrate_maximum = get_bits_long(gb, 32);
  774. vc->bitrate_nominal = get_bits_long(gb, 32);
  775. vc->bitrate_minimum = get_bits_long(gb, 32);
  776. bl0 = get_bits(gb, 4);
  777. bl1 = get_bits(gb, 4);
  778. vc->blocksize[0] = (1 << bl0);
  779. vc->blocksize[1] = (1 << bl1);
  780. if (bl0 > 13 || bl0 < 6 || bl1 > 13 || bl1 < 6 || bl1 < bl0) {
  781. av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (illegal blocksize). \n");
  782. return AVERROR_INVALIDDATA;
  783. }
  784. vc->win[0] = ff_vorbis_vwin[bl0 - 6];
  785. vc->win[1] = ff_vorbis_vwin[bl1 - 6];
  786. if ((get_bits1(gb)) == 0) {
  787. av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (framing flag not set). \n");
  788. return AVERROR_INVALIDDATA;
  789. }
  790. vc->channel_residues = av_malloc((vc->blocksize[1] / 2) * vc->audio_channels * sizeof(*vc->channel_residues));
  791. vc->saved = av_mallocz((vc->blocksize[1] / 4) * vc->audio_channels * sizeof(*vc->saved));
  792. vc->previous_window = 0;
  793. ff_mdct_init(&vc->mdct[0], bl0, 1, -1.0);
  794. ff_mdct_init(&vc->mdct[1], bl1, 1, -1.0);
  795. av_dlog(NULL, " vorbis version %d \n audio_channels %d \n audio_samplerate %d \n bitrate_max %d \n bitrate_nom %d \n bitrate_min %d \n blk_0 %d blk_1 %d \n ",
  796. vc->version, vc->audio_channels, vc->audio_samplerate, vc->bitrate_maximum, vc->bitrate_nominal, vc->bitrate_minimum, vc->blocksize[0], vc->blocksize[1]);
  797. /*
  798. BLK = vc->blocksize[0];
  799. for (i = 0; i < BLK / 2; ++i) {
  800. 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)));
  801. }
  802. */
  803. return 0;
  804. }
  805. // Process the extradata using the functions above (identification header, setup header)
  806. static av_cold int vorbis_decode_init(AVCodecContext *avccontext)
  807. {
  808. vorbis_context *vc = avccontext->priv_data;
  809. uint8_t *headers = avccontext->extradata;
  810. int headers_len = avccontext->extradata_size;
  811. uint8_t *header_start[3];
  812. int header_len[3];
  813. GetBitContext *gb = &vc->gb;
  814. int hdr_type, ret;
  815. vc->avccontext = avccontext;
  816. ff_dsputil_init(&vc->dsp, avccontext);
  817. avpriv_float_dsp_init(&vc->fdsp, avccontext->flags & CODEC_FLAG_BITEXACT);
  818. ff_fmt_convert_init(&vc->fmt_conv, avccontext);
  819. avccontext->sample_fmt = AV_SAMPLE_FMT_FLTP;
  820. if (!headers_len) {
  821. av_log(avccontext, AV_LOG_ERROR, "Extradata missing.\n");
  822. return AVERROR_INVALIDDATA;
  823. }
  824. if ((ret = avpriv_split_xiph_headers(headers, headers_len, 30, header_start, header_len)) < 0) {
  825. av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n");
  826. return ret;
  827. }
  828. init_get_bits(gb, header_start[0], header_len[0]*8);
  829. hdr_type = get_bits(gb, 8);
  830. if (hdr_type != 1) {
  831. av_log(avccontext, AV_LOG_ERROR, "First header is not the id header.\n");
  832. return AVERROR_INVALIDDATA;
  833. }
  834. if ((ret = vorbis_parse_id_hdr(vc))) {
  835. av_log(avccontext, AV_LOG_ERROR, "Id header corrupt.\n");
  836. vorbis_free(vc);
  837. return ret;
  838. }
  839. init_get_bits(gb, header_start[2], header_len[2]*8);
  840. hdr_type = get_bits(gb, 8);
  841. if (hdr_type != 5) {
  842. av_log(avccontext, AV_LOG_ERROR, "Third header is not the setup header.\n");
  843. vorbis_free(vc);
  844. return AVERROR_INVALIDDATA;
  845. }
  846. if ((ret = vorbis_parse_setup_hdr(vc))) {
  847. av_log(avccontext, AV_LOG_ERROR, "Setup header corrupt.\n");
  848. vorbis_free(vc);
  849. return ret;
  850. }
  851. if (vc->audio_channels > 8)
  852. avccontext->channel_layout = 0;
  853. else
  854. avccontext->channel_layout = ff_vorbis_channel_layouts[vc->audio_channels - 1];
  855. avccontext->channels = vc->audio_channels;
  856. avccontext->sample_rate = vc->audio_samplerate;
  857. avcodec_get_frame_defaults(&vc->frame);
  858. avccontext->coded_frame = &vc->frame;
  859. return 0;
  860. }
  861. // Decode audiopackets -------------------------------------------------
  862. // Read and decode floor
  863. static int vorbis_floor0_decode(vorbis_context *vc,
  864. vorbis_floor_data *vfu, float *vec)
  865. {
  866. vorbis_floor0 *vf = &vfu->t0;
  867. float *lsp = vf->lsp;
  868. unsigned amplitude, book_idx;
  869. unsigned blockflag = vc->modes[vc->mode_number].blockflag;
  870. amplitude = get_bits(&vc->gb, vf->amplitude_bits);
  871. if (amplitude > 0) {
  872. float last = 0;
  873. unsigned idx, lsp_len = 0;
  874. vorbis_codebook codebook;
  875. book_idx = get_bits(&vc->gb, ilog(vf->num_books));
  876. if (book_idx >= vf->num_books) {
  877. av_log(vc->avccontext, AV_LOG_ERROR,
  878. "floor0 dec: booknumber too high!\n");
  879. book_idx = 0;
  880. }
  881. av_dlog(NULL, "floor0 dec: booknumber: %u\n", book_idx);
  882. codebook = vc->codebooks[vf->book_list[book_idx]];
  883. /* Invalid codebook! */
  884. if (!codebook.codevectors)
  885. return AVERROR_INVALIDDATA;
  886. while (lsp_len<vf->order) {
  887. int vec_off;
  888. av_dlog(NULL, "floor0 dec: book dimension: %d\n", codebook.dimensions);
  889. av_dlog(NULL, "floor0 dec: maximum depth: %d\n", codebook.maxdepth);
  890. /* read temp vector */
  891. vec_off = get_vlc2(&vc->gb, codebook.vlc.table,
  892. codebook.nb_bits, codebook.maxdepth)
  893. * codebook.dimensions;
  894. av_dlog(NULL, "floor0 dec: vector offset: %d\n", vec_off);
  895. /* copy each vector component and add last to it */
  896. for (idx = 0; idx < codebook.dimensions; ++idx)
  897. lsp[lsp_len+idx] = codebook.codevectors[vec_off+idx] + last;
  898. last = lsp[lsp_len+idx-1]; /* set last to last vector component */
  899. lsp_len += codebook.dimensions;
  900. }
  901. /* DEBUG: output lsp coeffs */
  902. {
  903. int idx;
  904. for (idx = 0; idx < lsp_len; ++idx)
  905. av_dlog(NULL, "floor0 dec: coeff at %d is %f\n", idx, lsp[idx]);
  906. }
  907. /* synthesize floor output vector */
  908. {
  909. int i;
  910. int order = vf->order;
  911. float wstep = M_PI / vf->bark_map_size;
  912. for (i = 0; i < order; i++)
  913. lsp[i] = 2.0f * cos(lsp[i]);
  914. av_dlog(NULL, "floor0 synth: map_size = %"PRIu32"; m = %d; wstep = %f\n",
  915. vf->map_size[blockflag], order, wstep);
  916. i = 0;
  917. while (i < vf->map_size[blockflag]) {
  918. int j, iter_cond = vf->map[blockflag][i];
  919. float p = 0.5f;
  920. float q = 0.5f;
  921. float two_cos_w = 2.0f * cos(wstep * iter_cond); // needed all times
  922. /* similar part for the q and p products */
  923. for (j = 0; j + 1 < order; j += 2) {
  924. q *= lsp[j] - two_cos_w;
  925. p *= lsp[j + 1] - two_cos_w;
  926. }
  927. if (j == order) { // even order
  928. p *= p * (2.0f - two_cos_w);
  929. q *= q * (2.0f + two_cos_w);
  930. } else { // odd order
  931. q *= two_cos_w-lsp[j]; // one more time for q
  932. /* final step and square */
  933. p *= p * (4.f - two_cos_w * two_cos_w);
  934. q *= q;
  935. }
  936. /* calculate linear floor value */
  937. q = exp((((amplitude*vf->amplitude_offset) /
  938. (((1 << vf->amplitude_bits) - 1) * sqrt(p + q)))
  939. - vf->amplitude_offset) * .11512925f);
  940. /* fill vector */
  941. do {
  942. vec[i] = q; ++i;
  943. } while (vf->map[blockflag][i] == iter_cond);
  944. }
  945. }
  946. } else {
  947. /* this channel is unused */
  948. return 1;
  949. }
  950. av_dlog(NULL, " Floor0 decoded\n");
  951. return 0;
  952. }
  953. static int vorbis_floor1_decode(vorbis_context *vc,
  954. vorbis_floor_data *vfu, float *vec)
  955. {
  956. vorbis_floor1 *vf = &vfu->t1;
  957. GetBitContext *gb = &vc->gb;
  958. uint16_t range_v[4] = { 256, 128, 86, 64 };
  959. unsigned range = range_v[vf->multiplier - 1];
  960. uint16_t floor1_Y[258];
  961. uint16_t floor1_Y_final[258];
  962. int floor1_flag[258];
  963. unsigned class, cdim, cbits, csub, cval, offset, i, j;
  964. int book, adx, ady, dy, off, predicted, err;
  965. if (!get_bits1(gb)) // silence
  966. return 1;
  967. // Read values (or differences) for the floor's points
  968. floor1_Y[0] = get_bits(gb, ilog(range - 1));
  969. floor1_Y[1] = get_bits(gb, ilog(range - 1));
  970. av_dlog(NULL, "floor 0 Y %d floor 1 Y %d \n", floor1_Y[0], floor1_Y[1]);
  971. offset = 2;
  972. for (i = 0; i < vf->partitions; ++i) {
  973. class = vf->partition_class[i];
  974. cdim = vf->class_dimensions[class];
  975. cbits = vf->class_subclasses[class];
  976. csub = (1 << cbits) - 1;
  977. cval = 0;
  978. av_dlog(NULL, "Cbits %u\n", cbits);
  979. if (cbits) // this reads all subclasses for this partition's class
  980. cval = get_vlc2(gb, vc->codebooks[vf->class_masterbook[class]].vlc.table,
  981. vc->codebooks[vf->class_masterbook[class]].nb_bits, 3);
  982. for (j = 0; j < cdim; ++j) {
  983. book = vf->subclass_books[class][cval & csub];
  984. av_dlog(NULL, "book %d Cbits %u cval %u bits:%d\n",
  985. book, cbits, cval, get_bits_count(gb));
  986. cval = cval >> cbits;
  987. if (book > -1) {
  988. floor1_Y[offset+j] = get_vlc2(gb, vc->codebooks[book].vlc.table,
  989. vc->codebooks[book].nb_bits, 3);
  990. } else {
  991. floor1_Y[offset+j] = 0;
  992. }
  993. av_dlog(NULL, " floor(%d) = %d \n",
  994. vf->list[offset+j].x, floor1_Y[offset+j]);
  995. }
  996. offset+=cdim;
  997. }
  998. // Amplitude calculation from the differences
  999. floor1_flag[0] = 1;
  1000. floor1_flag[1] = 1;
  1001. floor1_Y_final[0] = floor1_Y[0];
  1002. floor1_Y_final[1] = floor1_Y[1];
  1003. for (i = 2; i < vf->x_list_dim; ++i) {
  1004. unsigned val, highroom, lowroom, room, high_neigh_offs, low_neigh_offs;
  1005. low_neigh_offs = vf->list[i].low;
  1006. high_neigh_offs = vf->list[i].high;
  1007. dy = floor1_Y_final[high_neigh_offs] - floor1_Y_final[low_neigh_offs]; // render_point begin
  1008. adx = vf->list[high_neigh_offs].x - vf->list[low_neigh_offs].x;
  1009. ady = FFABS(dy);
  1010. err = ady * (vf->list[i].x - vf->list[low_neigh_offs].x);
  1011. off = err / adx;
  1012. if (dy < 0) {
  1013. predicted = floor1_Y_final[low_neigh_offs] - off;
  1014. } else {
  1015. predicted = floor1_Y_final[low_neigh_offs] + off;
  1016. } // render_point end
  1017. val = floor1_Y[i];
  1018. highroom = range-predicted;
  1019. lowroom = predicted;
  1020. if (highroom < lowroom) {
  1021. room = highroom * 2;
  1022. } else {
  1023. room = lowroom * 2; // SPEC mispelling
  1024. }
  1025. if (val) {
  1026. floor1_flag[low_neigh_offs] = 1;
  1027. floor1_flag[high_neigh_offs] = 1;
  1028. floor1_flag[i] = 1;
  1029. if (val >= room) {
  1030. if (highroom > lowroom) {
  1031. floor1_Y_final[i] = av_clip_uint16(val - lowroom + predicted);
  1032. } else {
  1033. floor1_Y_final[i] = av_clip_uint16(predicted - val + highroom - 1);
  1034. }
  1035. } else {
  1036. if (val & 1) {
  1037. floor1_Y_final[i] = av_clip_uint16(predicted - (val + 1) / 2);
  1038. } else {
  1039. floor1_Y_final[i] = av_clip_uint16(predicted + val / 2);
  1040. }
  1041. }
  1042. } else {
  1043. floor1_flag[i] = 0;
  1044. floor1_Y_final[i] = av_clip_uint16(predicted);
  1045. }
  1046. av_dlog(NULL, " Decoded floor(%d) = %u / val %u\n",
  1047. vf->list[i].x, floor1_Y_final[i], val);
  1048. }
  1049. // Curve synth - connect the calculated dots and convert from dB scale FIXME optimize ?
  1050. ff_vorbis_floor1_render_list(vf->list, vf->x_list_dim, floor1_Y_final, floor1_flag, vf->multiplier, vec, vf->list[1].x);
  1051. av_dlog(NULL, " Floor decoded\n");
  1052. return 0;
  1053. }
  1054. // Read and decode residue
  1055. static av_always_inline int vorbis_residue_decode_internal(vorbis_context *vc,
  1056. vorbis_residue *vr,
  1057. unsigned ch,
  1058. uint8_t *do_not_decode,
  1059. float *vec,
  1060. unsigned vlen,
  1061. unsigned ch_left,
  1062. int vr_type)
  1063. {
  1064. GetBitContext *gb = &vc->gb;
  1065. unsigned c_p_c = vc->codebooks[vr->classbook].dimensions;
  1066. unsigned ptns_to_read = vr->ptns_to_read;
  1067. uint8_t *classifs = vr->classifs;
  1068. unsigned pass, ch_used, i, j, k, l;
  1069. unsigned max_output = (ch - 1) * vlen;
  1070. if (vr_type == 2) {
  1071. for (j = 1; j < ch; ++j)
  1072. do_not_decode[0] &= do_not_decode[j]; // FIXME - clobbering input
  1073. if (do_not_decode[0])
  1074. return 0;
  1075. ch_used = 1;
  1076. max_output += vr->end / ch;
  1077. } else {
  1078. ch_used = ch;
  1079. max_output += vr->end;
  1080. }
  1081. if (max_output > ch_left * vlen) {
  1082. av_log(vc->avccontext, AV_LOG_ERROR, "Insufficient output buffer\n");
  1083. return -1;
  1084. }
  1085. av_dlog(NULL, " residue type 0/1/2 decode begin, ch: %d cpc %d \n", ch, c_p_c);
  1086. for (pass = 0; pass <= vr->maxpass; ++pass) { // FIXME OPTIMIZE?
  1087. uint16_t voffset, partition_count, j_times_ptns_to_read;
  1088. voffset = vr->begin;
  1089. for (partition_count = 0; partition_count < ptns_to_read;) { // SPEC error
  1090. if (!pass) {
  1091. unsigned inverse_class = ff_inverse[vr->classifications];
  1092. for (j_times_ptns_to_read = 0, j = 0; j < ch_used; ++j) {
  1093. if (!do_not_decode[j]) {
  1094. unsigned temp = get_vlc2(gb, vc->codebooks[vr->classbook].vlc.table,
  1095. vc->codebooks[vr->classbook].nb_bits, 3);
  1096. av_dlog(NULL, "Classword: %u\n", temp);
  1097. assert(vr->classifications > 1 && temp <= 65536); //needed for inverse[]
  1098. for (i = 0; i < c_p_c; ++i) {
  1099. unsigned temp2;
  1100. temp2 = (((uint64_t)temp) * inverse_class) >> 32;
  1101. if (partition_count + c_p_c - 1 - i < ptns_to_read)
  1102. classifs[j_times_ptns_to_read + partition_count + c_p_c - 1 - i] = temp - temp2 * vr->classifications;
  1103. temp = temp2;
  1104. }
  1105. }
  1106. j_times_ptns_to_read += ptns_to_read;
  1107. }
  1108. }
  1109. for (i = 0; (i < c_p_c) && (partition_count < ptns_to_read); ++i) {
  1110. for (j_times_ptns_to_read = 0, j = 0; j < ch_used; ++j) {
  1111. unsigned voffs;
  1112. if (!do_not_decode[j]) {
  1113. unsigned vqclass = classifs[j_times_ptns_to_read + partition_count];
  1114. int vqbook = vr->books[vqclass][pass];
  1115. if (vqbook >= 0 && vc->codebooks[vqbook].codevectors) {
  1116. unsigned coffs;
  1117. unsigned dim = vc->codebooks[vqbook].dimensions;
  1118. unsigned step = FASTDIV(vr->partition_size << 1, dim << 1);
  1119. vorbis_codebook codebook = vc->codebooks[vqbook];
  1120. if (vr_type == 0) {
  1121. voffs = voffset+j*vlen;
  1122. for (k = 0; k < step; ++k) {
  1123. coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim;
  1124. for (l = 0; l < dim; ++l)
  1125. vec[voffs + k + l * step] += codebook.codevectors[coffs + l];
  1126. }
  1127. } else if (vr_type == 1) {
  1128. voffs = voffset + j * vlen;
  1129. for (k = 0; k < step; ++k) {
  1130. coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim;
  1131. for (l = 0; l < dim; ++l, ++voffs) {
  1132. vec[voffs]+=codebook.codevectors[coffs+l];
  1133. av_dlog(NULL, " pass %d offs: %d curr: %f change: %f cv offs.: %d \n",
  1134. pass, voffs, vec[voffs], codebook.codevectors[coffs+l], coffs);
  1135. }
  1136. }
  1137. } else if (vr_type == 2 && ch == 2 && (voffset & 1) == 0 && (dim & 1) == 0) { // most frequent case optimized
  1138. voffs = voffset >> 1;
  1139. if (dim == 2) {
  1140. for (k = 0; k < step; ++k) {
  1141. coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * 2;
  1142. vec[voffs + k ] += codebook.codevectors[coffs ];
  1143. vec[voffs + k + vlen] += codebook.codevectors[coffs + 1];
  1144. }
  1145. } else if (dim == 4) {
  1146. for (k = 0; k < step; ++k, voffs += 2) {
  1147. coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * 4;
  1148. vec[voffs ] += codebook.codevectors[coffs ];
  1149. vec[voffs + 1 ] += codebook.codevectors[coffs + 2];
  1150. vec[voffs + vlen ] += codebook.codevectors[coffs + 1];
  1151. vec[voffs + vlen + 1] += codebook.codevectors[coffs + 3];
  1152. }
  1153. } else
  1154. for (k = 0; k < step; ++k) {
  1155. coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim;
  1156. for (l = 0; l < dim; l += 2, voffs++) {
  1157. vec[voffs ] += codebook.codevectors[coffs + l ];
  1158. vec[voffs + vlen] += codebook.codevectors[coffs + l + 1];
  1159. av_dlog(NULL, " pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n",
  1160. pass, voffset / ch + (voffs % ch) * vlen,
  1161. vec[voffset / ch + (voffs % ch) * vlen],
  1162. codebook.codevectors[coffs + l], coffs, l);
  1163. }
  1164. }
  1165. } else if (vr_type == 2) {
  1166. unsigned voffs_div = FASTDIV(voffset << 1, ch <<1);
  1167. unsigned voffs_mod = voffset - voffs_div * ch;
  1168. for (k = 0; k < step; ++k) {
  1169. coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim;
  1170. for (l = 0; l < dim; ++l) {
  1171. vec[voffs_div + voffs_mod * vlen] +=
  1172. codebook.codevectors[coffs + l];
  1173. av_dlog(NULL, " pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n",
  1174. pass, voffs_div + voffs_mod * vlen,
  1175. vec[voffs_div + voffs_mod * vlen],
  1176. codebook.codevectors[coffs + l], coffs, l);
  1177. if (++voffs_mod == ch) {
  1178. voffs_div++;
  1179. voffs_mod = 0;
  1180. }
  1181. }
  1182. }
  1183. }
  1184. }
  1185. }
  1186. j_times_ptns_to_read += ptns_to_read;
  1187. }
  1188. ++partition_count;
  1189. voffset += vr->partition_size;
  1190. }
  1191. }
  1192. }
  1193. return 0;
  1194. }
  1195. static inline int vorbis_residue_decode(vorbis_context *vc, vorbis_residue *vr,
  1196. unsigned ch,
  1197. uint8_t *do_not_decode,
  1198. float *vec, unsigned vlen,
  1199. unsigned ch_left)
  1200. {
  1201. if (vr->type == 2)
  1202. return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vlen, ch_left, 2);
  1203. else if (vr->type == 1)
  1204. return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vlen, ch_left, 1);
  1205. else if (vr->type == 0)
  1206. return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vlen, ch_left, 0);
  1207. else {
  1208. av_log(vc->avccontext, AV_LOG_ERROR, " Invalid residue type while residue decode?! \n");
  1209. return AVERROR_INVALIDDATA;
  1210. }
  1211. }
  1212. void ff_vorbis_inverse_coupling(float *mag, float *ang, int blocksize)
  1213. {
  1214. int i;
  1215. for (i = 0; i < blocksize; i++) {
  1216. if (mag[i] > 0.0) {
  1217. if (ang[i] > 0.0) {
  1218. ang[i] = mag[i] - ang[i];
  1219. } else {
  1220. float temp = ang[i];
  1221. ang[i] = mag[i];
  1222. mag[i] += temp;
  1223. }
  1224. } else {
  1225. if (ang[i] > 0.0) {
  1226. ang[i] += mag[i];
  1227. } else {
  1228. float temp = ang[i];
  1229. ang[i] = mag[i];
  1230. mag[i] -= temp;
  1231. }
  1232. }
  1233. }
  1234. }
  1235. // Decode the audio packet using the functions above
  1236. static int vorbis_parse_audio_packet(vorbis_context *vc, float **floor_ptr)
  1237. {
  1238. GetBitContext *gb = &vc->gb;
  1239. FFTContext *mdct;
  1240. unsigned previous_window = vc->previous_window;
  1241. unsigned mode_number, blockflag, blocksize;
  1242. int i, j;
  1243. uint8_t no_residue[255];
  1244. uint8_t do_not_decode[255];
  1245. vorbis_mapping *mapping;
  1246. float *ch_res_ptr = vc->channel_residues;
  1247. uint8_t res_chan[255];
  1248. unsigned res_num = 0;
  1249. int retlen = 0;
  1250. unsigned ch_left = vc->audio_channels;
  1251. unsigned vlen;
  1252. if (get_bits1(gb)) {
  1253. av_log(vc->avccontext, AV_LOG_ERROR, "Not a Vorbis I audio packet.\n");
  1254. return AVERROR_INVALIDDATA; // packet type not audio
  1255. }
  1256. if (vc->mode_count == 1) {
  1257. mode_number = 0;
  1258. } else {
  1259. GET_VALIDATED_INDEX(mode_number, ilog(vc->mode_count-1), vc->mode_count)
  1260. }
  1261. vc->mode_number = mode_number;
  1262. mapping = &vc->mappings[vc->modes[mode_number].mapping];
  1263. av_dlog(NULL, " Mode number: %u , mapping: %d , blocktype %d\n", mode_number,
  1264. vc->modes[mode_number].mapping, vc->modes[mode_number].blockflag);
  1265. blockflag = vc->modes[mode_number].blockflag;
  1266. blocksize = vc->blocksize[blockflag];
  1267. vlen = blocksize / 2;
  1268. if (blockflag) {
  1269. previous_window = get_bits(gb, 1);
  1270. skip_bits1(gb); // next_window
  1271. }
  1272. memset(ch_res_ptr, 0, sizeof(float) * vc->audio_channels * vlen); //FIXME can this be removed ?
  1273. for (i = 0; i < vc->audio_channels; ++i)
  1274. memset(floor_ptr[i], 0, vlen * sizeof(floor_ptr[0][0])); //FIXME can this be removed ?
  1275. // Decode floor
  1276. for (i = 0; i < vc->audio_channels; ++i) {
  1277. vorbis_floor *floor;
  1278. int ret;
  1279. if (mapping->submaps > 1) {
  1280. floor = &vc->floors[mapping->submap_floor[mapping->mux[i]]];
  1281. } else {
  1282. floor = &vc->floors[mapping->submap_floor[0]];
  1283. }
  1284. ret = floor->decode(vc, &floor->data, floor_ptr[i]);
  1285. if (ret < 0) {
  1286. av_log(vc->avccontext, AV_LOG_ERROR, "Invalid codebook in vorbis_floor_decode.\n");
  1287. return AVERROR_INVALIDDATA;
  1288. }
  1289. no_residue[i] = ret;
  1290. }
  1291. // Nonzero vector propagate
  1292. for (i = mapping->coupling_steps - 1; i >= 0; --i) {
  1293. if (!(no_residue[mapping->magnitude[i]] & no_residue[mapping->angle[i]])) {
  1294. no_residue[mapping->magnitude[i]] = 0;
  1295. no_residue[mapping->angle[i]] = 0;
  1296. }
  1297. }
  1298. // Decode residue
  1299. for (i = 0; i < mapping->submaps; ++i) {
  1300. vorbis_residue *residue;
  1301. unsigned ch = 0;
  1302. int ret;
  1303. for (j = 0; j < vc->audio_channels; ++j) {
  1304. if ((mapping->submaps == 1) || (i == mapping->mux[j])) {
  1305. res_chan[j] = res_num;
  1306. if (no_residue[j]) {
  1307. do_not_decode[ch] = 1;
  1308. } else {
  1309. do_not_decode[ch] = 0;
  1310. }
  1311. ++ch;
  1312. ++res_num;
  1313. }
  1314. }
  1315. residue = &vc->residues[mapping->submap_residue[i]];
  1316. if (ch_left < ch) {
  1317. av_log(vc->avccontext, AV_LOG_ERROR, "Too many channels in vorbis_floor_decode.\n");
  1318. return -1;
  1319. }
  1320. if (ch) {
  1321. ret = vorbis_residue_decode(vc, residue, ch, do_not_decode, ch_res_ptr, vlen, ch_left);
  1322. if (ret < 0)
  1323. return ret;
  1324. }
  1325. ch_res_ptr += ch * vlen;
  1326. ch_left -= ch;
  1327. }
  1328. if (ch_left > 0)
  1329. return AVERROR_INVALIDDATA;
  1330. // Inverse coupling
  1331. for (i = mapping->coupling_steps - 1; i >= 0; --i) { //warning: i has to be signed
  1332. float *mag, *ang;
  1333. mag = vc->channel_residues+res_chan[mapping->magnitude[i]] * blocksize / 2;
  1334. ang = vc->channel_residues+res_chan[mapping->angle[i]] * blocksize / 2;
  1335. vc->dsp.vorbis_inverse_coupling(mag, ang, blocksize / 2);
  1336. }
  1337. // Dotproduct, MDCT
  1338. mdct = &vc->mdct[blockflag];
  1339. for (j = vc->audio_channels-1;j >= 0; j--) {
  1340. ch_res_ptr = vc->channel_residues + res_chan[j] * blocksize / 2;
  1341. vc->fdsp.vector_fmul(floor_ptr[j], floor_ptr[j], ch_res_ptr, blocksize / 2);
  1342. mdct->imdct_half(mdct, ch_res_ptr, floor_ptr[j]);
  1343. }
  1344. // Overlap/add, save data for next overlapping
  1345. retlen = (blocksize + vc->blocksize[previous_window]) / 4;
  1346. for (j = 0; j < vc->audio_channels; j++) {
  1347. unsigned bs0 = vc->blocksize[0];
  1348. unsigned bs1 = vc->blocksize[1];
  1349. float *residue = vc->channel_residues + res_chan[j] * blocksize / 2;
  1350. float *saved = vc->saved + j * bs1 / 4;
  1351. float *ret = floor_ptr[j];
  1352. float *buf = residue;
  1353. const float *win = vc->win[blockflag & previous_window];
  1354. if (blockflag == previous_window) {
  1355. vc->dsp.vector_fmul_window(ret, saved, buf, win, blocksize / 4);
  1356. } else if (blockflag > previous_window) {
  1357. vc->dsp.vector_fmul_window(ret, saved, buf, win, bs0 / 4);
  1358. memcpy(ret+bs0/2, buf+bs0/4, ((bs1-bs0)/4) * sizeof(float));
  1359. } else {
  1360. memcpy(ret, saved, ((bs1 - bs0) / 4) * sizeof(float));
  1361. vc->dsp.vector_fmul_window(ret + (bs1 - bs0) / 4, saved + (bs1 - bs0) / 4, buf, win, bs0 / 4);
  1362. }
  1363. memcpy(saved, buf + blocksize / 4, blocksize / 4 * sizeof(float));
  1364. }
  1365. vc->previous_window = blockflag;
  1366. return retlen;
  1367. }
  1368. // Return the decoded audio packet through the standard api
  1369. static int vorbis_decode_frame(AVCodecContext *avccontext, void *data,
  1370. int *got_frame_ptr, AVPacket *avpkt)
  1371. {
  1372. const uint8_t *buf = avpkt->data;
  1373. int buf_size = avpkt->size;
  1374. vorbis_context *vc = avccontext->priv_data;
  1375. GetBitContext *gb = &vc->gb;
  1376. float *channel_ptrs[255];
  1377. int i, len, ret;
  1378. av_dlog(NULL, "packet length %d \n", buf_size);
  1379. /* get output buffer */
  1380. vc->frame.nb_samples = vc->blocksize[1] / 2;
  1381. if ((ret = ff_get_buffer(avccontext, &vc->frame)) < 0) {
  1382. av_log(avccontext, AV_LOG_ERROR, "get_buffer() failed\n");
  1383. return ret;
  1384. }
  1385. if (vc->audio_channels > 8) {
  1386. for (i = 0; i < vc->audio_channels; i++)
  1387. channel_ptrs[i] = (float *)vc->frame.extended_data[i];
  1388. } else {
  1389. for (i = 0; i < vc->audio_channels; i++) {
  1390. int ch = ff_vorbis_channel_layout_offsets[vc->audio_channels - 1][i];
  1391. channel_ptrs[ch] = (float *)vc->frame.extended_data[i];
  1392. }
  1393. }
  1394. init_get_bits(gb, buf, buf_size*8);
  1395. if ((len = vorbis_parse_audio_packet(vc, channel_ptrs)) <= 0)
  1396. return len;
  1397. if (!vc->first_frame) {
  1398. vc->first_frame = 1;
  1399. *got_frame_ptr = 0;
  1400. return buf_size;
  1401. }
  1402. av_dlog(NULL, "parsed %d bytes %d bits, returned %d samples (*ch*bits) \n",
  1403. get_bits_count(gb) / 8, get_bits_count(gb) % 8, len);
  1404. vc->frame.nb_samples = len;
  1405. *got_frame_ptr = 1;
  1406. *(AVFrame *)data = vc->frame;
  1407. return buf_size;
  1408. }
  1409. // Close decoder
  1410. static av_cold int vorbis_decode_close(AVCodecContext *avccontext)
  1411. {
  1412. vorbis_context *vc = avccontext->priv_data;
  1413. vorbis_free(vc);
  1414. return 0;
  1415. }
  1416. static av_cold void vorbis_decode_flush(AVCodecContext *avccontext)
  1417. {
  1418. vorbis_context *vc = avccontext->priv_data;
  1419. if (vc->saved) {
  1420. memset(vc->saved, 0, (vc->blocksize[1] / 4) * vc->audio_channels *
  1421. sizeof(*vc->saved));
  1422. }
  1423. vc->previous_window = 0;
  1424. }
  1425. AVCodec ff_vorbis_decoder = {
  1426. .name = "vorbis",
  1427. .type = AVMEDIA_TYPE_AUDIO,
  1428. .id = AV_CODEC_ID_VORBIS,
  1429. .priv_data_size = sizeof(vorbis_context),
  1430. .init = vorbis_decode_init,
  1431. .close = vorbis_decode_close,
  1432. .decode = vorbis_decode_frame,
  1433. .flush = vorbis_decode_flush,
  1434. .capabilities = CODEC_CAP_DR1,
  1435. .long_name = NULL_IF_CONFIG_SMALL("Vorbis"),
  1436. .channel_layouts = ff_vorbis_channel_layouts,
  1437. .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
  1438. AV_SAMPLE_FMT_NONE },
  1439. };