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.

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