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.

1270 lines
41KB

  1. /*
  2. * COOK compatible decoder
  3. * Copyright (c) 2003 Sascha Sommer
  4. * Copyright (c) 2005 Benjamin Larsson
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. */
  23. /**
  24. * @file cook.c
  25. * Cook compatible decoder.
  26. * This decoder handles RealNetworks, RealAudio G2 data.
  27. * Cook is identified by the codec name cook in RM files.
  28. *
  29. * To use this decoder, a calling application must supply the extradata
  30. * bytes provided from the RM container; 8+ bytes for mono streams and
  31. * 16+ for stereo streams (maybe more).
  32. *
  33. * Codec technicalities (all this assume a buffer length of 1024):
  34. * Cook works with several different techniques to achieve its compression.
  35. * In the timedomain the buffer is divided into 8 pieces and quantized. If
  36. * two neighboring pieces have different quantization index a smooth
  37. * quantization curve is used to get a smooth overlap between the different
  38. * pieces.
  39. * To get to the transformdomain Cook uses a modulated lapped transform.
  40. * The transform domain has 50 subbands with 20 elements each. This
  41. * means only a maximum of 50*20=1000 coefficients are used out of the 1024
  42. * available.
  43. */
  44. #include <math.h>
  45. #include <stddef.h>
  46. #include <stdio.h>
  47. #include "avcodec.h"
  48. #include "bitstream.h"
  49. #include "dsputil.h"
  50. #include "common.h"
  51. #include "bytestream.h"
  52. #include "cookdata.h"
  53. /* the different Cook versions */
  54. #define MONO 0x1000001
  55. #define STEREO 0x1000002
  56. #define JOINT_STEREO 0x1000003
  57. #define MC_COOK 0x2000000 //multichannel Cook, not supported
  58. #define SUBBAND_SIZE 20
  59. //#define COOKDEBUG
  60. typedef struct {
  61. int size;
  62. int qidx_table1[8];
  63. int qidx_table2[8];
  64. } COOKgain;
  65. typedef struct {
  66. GetBitContext gb;
  67. /* stream data */
  68. int nb_channels;
  69. int joint_stereo;
  70. int bit_rate;
  71. int sample_rate;
  72. int samples_per_channel;
  73. int samples_per_frame;
  74. int subbands;
  75. int log2_numvector_size;
  76. int numvector_size; //1 << log2_numvector_size;
  77. int js_subband_start;
  78. int total_subbands;
  79. int num_vectors;
  80. int bits_per_subpacket;
  81. int cookversion;
  82. /* states */
  83. int random_state;
  84. /* transform data */
  85. FFTContext fft_ctx;
  86. FFTSample mlt_tmp[1024] __attribute__((aligned(16))); /* temporary storage for imlt */
  87. float* mlt_window;
  88. float* mlt_precos;
  89. float* mlt_presin;
  90. float* mlt_postcos;
  91. int fft_size;
  92. int fft_order;
  93. int mlt_size; //modulated lapped transform size
  94. /* gain buffers */
  95. COOKgain *gain_ptr1[2];
  96. COOKgain *gain_ptr2[2];
  97. COOKgain gain_1;
  98. COOKgain gain_2;
  99. COOKgain gain_3;
  100. COOKgain gain_4;
  101. /* VLC data */
  102. int js_vlc_bits;
  103. VLC envelope_quant_index[13];
  104. VLC sqvh[7]; //scalar quantization
  105. VLC ccpl; //channel coupling
  106. /* generatable tables and related variables */
  107. int gain_size_factor;
  108. float gain_table[23];
  109. float pow2tab[127];
  110. float rootpow2tab[127];
  111. /* data buffers */
  112. uint8_t* decoded_bytes_buffer;
  113. float mono_mdct_output[2048] __attribute__((aligned(16)));
  114. float mono_previous_buffer1[1024];
  115. float mono_previous_buffer2[1024];
  116. float decode_buffer_1[1024];
  117. float decode_buffer_2[1024];
  118. } COOKContext;
  119. /* debug functions */
  120. #ifdef COOKDEBUG
  121. static void dump_float_table(float* table, int size, int delimiter) {
  122. int i=0;
  123. av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i);
  124. for (i=0 ; i<size ; i++) {
  125. av_log(NULL, AV_LOG_ERROR, "%5.1f, ", table[i]);
  126. if ((i+1)%delimiter == 0) av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i+1);
  127. }
  128. }
  129. static void dump_int_table(int* table, int size, int delimiter) {
  130. int i=0;
  131. av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i);
  132. for (i=0 ; i<size ; i++) {
  133. av_log(NULL, AV_LOG_ERROR, "%d, ", table[i]);
  134. if ((i+1)%delimiter == 0) av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i+1);
  135. }
  136. }
  137. static void dump_short_table(short* table, int size, int delimiter) {
  138. int i=0;
  139. av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i);
  140. for (i=0 ; i<size ; i++) {
  141. av_log(NULL, AV_LOG_ERROR, "%d, ", table[i]);
  142. if ((i+1)%delimiter == 0) av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i+1);
  143. }
  144. }
  145. #endif
  146. /*************** init functions ***************/
  147. /* table generator */
  148. static void init_pow2table(COOKContext *q){
  149. int i;
  150. q->pow2tab[63] = 1.0;
  151. for (i=1 ; i<64 ; i++){
  152. q->pow2tab[63+i]=(float)((uint64_t)1<<i);
  153. q->pow2tab[63-i]=1.0/(float)((uint64_t)1<<i);
  154. }
  155. }
  156. /* table generator */
  157. static void init_rootpow2table(COOKContext *q){
  158. int i;
  159. q->rootpow2tab[63] = 1.0;
  160. for (i=1 ; i<64 ; i++){
  161. q->rootpow2tab[63+i]=sqrt((float)((uint64_t)1<<i));
  162. q->rootpow2tab[63-i]=sqrt(1.0/(float)((uint64_t)1<<i));
  163. }
  164. }
  165. /* table generator */
  166. static void init_gain_table(COOKContext *q) {
  167. int i;
  168. q->gain_size_factor = q->samples_per_channel/8;
  169. for (i=0 ; i<23 ; i++) {
  170. q->gain_table[i] = pow((double)q->pow2tab[i+52] ,
  171. (1.0/(double)q->gain_size_factor));
  172. }
  173. }
  174. static int init_cook_vlc_tables(COOKContext *q) {
  175. int i, result;
  176. result = 0;
  177. for (i=0 ; i<13 ; i++) {
  178. result &= init_vlc (&q->envelope_quant_index[i], 9, 24,
  179. envelope_quant_index_huffbits[i], 1, 1,
  180. envelope_quant_index_huffcodes[i], 2, 2, 0);
  181. }
  182. av_log(NULL,AV_LOG_DEBUG,"sqvh VLC init\n");
  183. for (i=0 ; i<7 ; i++) {
  184. result &= init_vlc (&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i],
  185. cvh_huffbits[i], 1, 1,
  186. cvh_huffcodes[i], 2, 2, 0);
  187. }
  188. if (q->nb_channels==2 && q->joint_stereo==1){
  189. result &= init_vlc (&q->ccpl, 6, (1<<q->js_vlc_bits)-1,
  190. ccpl_huffbits[q->js_vlc_bits-2], 1, 1,
  191. ccpl_huffcodes[q->js_vlc_bits-2], 2, 2, 0);
  192. av_log(NULL,AV_LOG_DEBUG,"Joint-stereo VLC used.\n");
  193. }
  194. av_log(NULL,AV_LOG_DEBUG,"VLC tables initialized.\n");
  195. return result;
  196. }
  197. static int init_cook_mlt(COOKContext *q) {
  198. int j;
  199. float alpha;
  200. /* Allocate the buffers, could be replaced with a static [512]
  201. array if needed. */
  202. q->mlt_size = q->samples_per_channel;
  203. q->mlt_window = av_malloc(sizeof(float)*q->mlt_size);
  204. q->mlt_precos = av_malloc(sizeof(float)*q->mlt_size/2);
  205. q->mlt_presin = av_malloc(sizeof(float)*q->mlt_size/2);
  206. q->mlt_postcos = av_malloc(sizeof(float)*q->mlt_size/2);
  207. /* Initialize the MLT window: simple sine window. */
  208. alpha = M_PI / (2.0 * (float)q->mlt_size);
  209. for(j=0 ; j<q->mlt_size ; j++) {
  210. q->mlt_window[j] = sin((j + 512.0/(float)q->mlt_size) * alpha);
  211. }
  212. /* pre/post twiddle factors */
  213. for (j=0 ; j<q->mlt_size/2 ; j++){
  214. q->mlt_precos[j] = cos( ((j+0.25)*M_PI)/q->mlt_size);
  215. q->mlt_presin[j] = sin( ((j+0.25)*M_PI)/q->mlt_size);
  216. q->mlt_postcos[j] = (float)sqrt(2.0/(float)q->mlt_size)*cos( ((float)j*M_PI) /q->mlt_size); //sqrt(2/MLT_size) = scalefactor
  217. }
  218. /* Initialize the FFT. */
  219. ff_fft_init(&q->fft_ctx, av_log2(q->mlt_size)-1, 0);
  220. av_log(NULL,AV_LOG_DEBUG,"FFT initialized, order = %d.\n",
  221. av_log2(q->samples_per_channel)-1);
  222. return (int)(q->mlt_window && q->mlt_precos && q->mlt_presin && q->mlt_postcos);
  223. }
  224. /*************** init functions end ***********/
  225. /**
  226. * Cook indata decoding, every 32 bits are XORed with 0x37c511f2.
  227. * Why? No idea, some checksum/error detection method maybe.
  228. *
  229. * Out buffer size: extra bytes are needed to cope with
  230. * padding/missalignment.
  231. * Subpackets passed to the decoder can contain two, consecutive
  232. * half-subpackets, of identical but arbitrary size.
  233. * 1234 1234 1234 1234 extraA extraB
  234. * Case 1: AAAA BBBB 0 0
  235. * Case 2: AAAA ABBB BB-- 3 3
  236. * Case 3: AAAA AABB BBBB 2 2
  237. * Case 4: AAAA AAAB BBBB BB-- 1 5
  238. *
  239. * Nice way to waste CPU cycles.
  240. *
  241. * @param inbuffer pointer to byte array of indata
  242. * @param out pointer to byte array of outdata
  243. * @param bytes number of bytes
  244. */
  245. #define DECODE_BYTES_PAD1(bytes) (3 - ((bytes)+3) % 4)
  246. #define DECODE_BYTES_PAD2(bytes) ((bytes) % 4 + DECODE_BYTES_PAD1(2 * (bytes)))
  247. static inline int decode_bytes(uint8_t* inbuffer, uint8_t* out, int bytes){
  248. int i, off;
  249. uint32_t c;
  250. uint32_t* buf;
  251. uint32_t* obuf = (uint32_t*) out;
  252. /* FIXME: 64 bit platforms would be able to do 64 bits at a time.
  253. * I'm too lazy though, should be something like
  254. * for(i=0 ; i<bitamount/64 ; i++)
  255. * (int64_t)out[i] = 0x37c511f237c511f2^be2me_64(int64_t)in[i]);
  256. * Buffer alignment needs to be checked. */
  257. off = (int)((long)inbuffer & 3);
  258. buf = (uint32_t*) (inbuffer - off);
  259. c = be2me_32((0x37c511f2 >> (off*8)) | (0x37c511f2 << (32-(off*8))));
  260. bytes += 3 + off;
  261. for (i = 0; i < bytes/4; i++)
  262. obuf[i] = c ^ buf[i];
  263. return off;
  264. }
  265. /**
  266. * Cook uninit
  267. */
  268. static int cook_decode_close(AVCodecContext *avctx)
  269. {
  270. int i;
  271. COOKContext *q = avctx->priv_data;
  272. av_log(avctx,AV_LOG_DEBUG, "Deallocating memory.\n");
  273. /* Free allocated memory buffers. */
  274. av_free(q->mlt_window);
  275. av_free(q->mlt_precos);
  276. av_free(q->mlt_presin);
  277. av_free(q->mlt_postcos);
  278. av_free(q->decoded_bytes_buffer);
  279. /* Free the transform. */
  280. ff_fft_end(&q->fft_ctx);
  281. /* Free the VLC tables. */
  282. for (i=0 ; i<13 ; i++) {
  283. free_vlc(&q->envelope_quant_index[i]);
  284. }
  285. for (i=0 ; i<7 ; i++) {
  286. free_vlc(&q->sqvh[i]);
  287. }
  288. if(q->nb_channels==2 && q->joint_stereo==1 ){
  289. free_vlc(&q->ccpl);
  290. }
  291. av_log(NULL,AV_LOG_DEBUG,"Memory deallocated.\n");
  292. return 0;
  293. }
  294. /**
  295. * Fill the COOKgain structure for the timedomain quantization.
  296. *
  297. * @param q pointer to the COOKContext
  298. * @param gaininfo pointer to the COOKgain
  299. */
  300. static void decode_gain_info(GetBitContext *gb, COOKgain* gaininfo) {
  301. int i;
  302. while (get_bits1(gb)) {}
  303. gaininfo->size = get_bits_count(gb) - 1; //amount of elements*2 to update
  304. if (get_bits_count(gb) - 1 <= 0) return;
  305. for (i=0 ; i<gaininfo->size ; i++){
  306. gaininfo->qidx_table1[i] = get_bits(gb,3);
  307. if (get_bits1(gb)) {
  308. gaininfo->qidx_table2[i] = get_bits(gb,4) - 7; //convert to signed
  309. } else {
  310. gaininfo->qidx_table2[i] = -1;
  311. }
  312. }
  313. }
  314. /**
  315. * Create the quant index table needed for the envelope.
  316. *
  317. * @param q pointer to the COOKContext
  318. * @param quant_index_table pointer to the array
  319. */
  320. static void decode_envelope(COOKContext *q, int* quant_index_table) {
  321. int i,j, vlc_index;
  322. int bitbias;
  323. bitbias = get_bits_count(&q->gb);
  324. quant_index_table[0]= get_bits(&q->gb,6) - 6; //This is used later in categorize
  325. for (i=1 ; i < q->total_subbands ; i++){
  326. vlc_index=i;
  327. if (i >= q->js_subband_start * 2) {
  328. vlc_index-=q->js_subband_start;
  329. } else {
  330. vlc_index/=2;
  331. if(vlc_index < 1) vlc_index = 1;
  332. }
  333. if (vlc_index>13) vlc_index = 13; //the VLC tables >13 are identical to No. 13
  334. j = get_vlc2(&q->gb, q->envelope_quant_index[vlc_index-1].table,
  335. q->envelope_quant_index[vlc_index-1].bits,2);
  336. quant_index_table[i] = quant_index_table[i-1] + j - 12; //differential encoding
  337. }
  338. }
  339. /**
  340. * Create the quant value table.
  341. *
  342. * @param q pointer to the COOKContext
  343. * @param quant_value_table pointer to the array
  344. */
  345. static void inline dequant_envelope(COOKContext *q, int* quant_index_table,
  346. float* quant_value_table){
  347. int i;
  348. for(i=0 ; i < q->total_subbands ; i++){
  349. quant_value_table[i] = q->rootpow2tab[quant_index_table[i]+63];
  350. }
  351. }
  352. /**
  353. * Calculate the category and category_index vector.
  354. *
  355. * @param q pointer to the COOKContext
  356. * @param quant_index_table pointer to the array
  357. * @param category pointer to the category array
  358. * @param category_index pointer to the category_index array
  359. */
  360. static void categorize(COOKContext *q, int* quant_index_table,
  361. int* category, int* category_index){
  362. int exp_idx, bias, tmpbias, bits_left, num_bits, index, v, i, j;
  363. int exp_index2[102];
  364. int exp_index1[102];
  365. int tmp_categorize_array1[128];
  366. int tmp_categorize_array1_idx=0;
  367. int tmp_categorize_array2[128];
  368. int tmp_categorize_array2_idx=0;
  369. int category_index_size=0;
  370. bits_left = q->bits_per_subpacket - get_bits_count(&q->gb);
  371. if(bits_left > q->samples_per_channel) {
  372. bits_left = q->samples_per_channel +
  373. ((bits_left - q->samples_per_channel)*5)/8;
  374. //av_log(NULL, AV_LOG_ERROR, "bits_left = %d\n",bits_left);
  375. }
  376. memset(&exp_index1,0,102*sizeof(int));
  377. memset(&exp_index2,0,102*sizeof(int));
  378. memset(&tmp_categorize_array1,0,128*sizeof(int));
  379. memset(&tmp_categorize_array2,0,128*sizeof(int));
  380. bias=-32;
  381. /* Estimate bias. */
  382. for (i=32 ; i>0 ; i=i/2){
  383. num_bits = 0;
  384. index = 0;
  385. for (j=q->total_subbands ; j>0 ; j--){
  386. exp_idx = (i - quant_index_table[index] + bias) / 2;
  387. if (exp_idx<0){
  388. exp_idx=0;
  389. } else if(exp_idx >7) {
  390. exp_idx=7;
  391. }
  392. index++;
  393. num_bits+=expbits_tab[exp_idx];
  394. }
  395. if(num_bits >= bits_left - 32){
  396. bias+=i;
  397. }
  398. }
  399. /* Calculate total number of bits. */
  400. num_bits=0;
  401. for (i=0 ; i<q->total_subbands ; i++) {
  402. exp_idx = (bias - quant_index_table[i]) / 2;
  403. if (exp_idx<0) {
  404. exp_idx=0;
  405. } else if(exp_idx >7) {
  406. exp_idx=7;
  407. }
  408. num_bits += expbits_tab[exp_idx];
  409. exp_index1[i] = exp_idx;
  410. exp_index2[i] = exp_idx;
  411. }
  412. tmpbias = bias = num_bits;
  413. for (j = 1 ; j < q->numvector_size ; j++) {
  414. if (tmpbias + bias > 2*bits_left) { /* ---> */
  415. int max = -999999;
  416. index=-1;
  417. for (i=0 ; i<q->total_subbands ; i++){
  418. if (exp_index1[i] < 7) {
  419. v = (-2*exp_index1[i]) - quant_index_table[i] - 32;
  420. if ( v >= max) {
  421. max = v;
  422. index = i;
  423. }
  424. }
  425. }
  426. if(index==-1)break;
  427. tmp_categorize_array1[tmp_categorize_array1_idx++] = index;
  428. tmpbias -= expbits_tab[exp_index1[index]] -
  429. expbits_tab[exp_index1[index]+1];
  430. ++exp_index1[index];
  431. } else { /* <--- */
  432. int min = 999999;
  433. index=-1;
  434. for (i=0 ; i<q->total_subbands ; i++){
  435. if(exp_index2[i] > 0){
  436. v = (-2*exp_index2[i])-quant_index_table[i];
  437. if ( v < min) {
  438. min = v;
  439. index = i;
  440. }
  441. }
  442. }
  443. if(index == -1)break;
  444. tmp_categorize_array2[tmp_categorize_array2_idx++] = index;
  445. tmpbias -= expbits_tab[exp_index2[index]] -
  446. expbits_tab[exp_index2[index]-1];
  447. --exp_index2[index];
  448. }
  449. }
  450. for(i=0 ; i<q->total_subbands ; i++)
  451. category[i] = exp_index2[i];
  452. /* Concatenate the two arrays. */
  453. for(i=tmp_categorize_array2_idx-1 ; i >= 0; i--)
  454. category_index[category_index_size++] = tmp_categorize_array2[i];
  455. for(i=0;i<tmp_categorize_array1_idx;i++)
  456. category_index[category_index_size++ ] = tmp_categorize_array1[i];
  457. /* FIXME: mc_sich_ra8_20.rm triggers this, not sure with what we
  458. should fill the remaining bytes. */
  459. for(i=category_index_size;i<q->numvector_size;i++)
  460. category_index[i]=0;
  461. }
  462. /**
  463. * Expand the category vector.
  464. *
  465. * @param q pointer to the COOKContext
  466. * @param category pointer to the category array
  467. * @param category_index pointer to the category_index array
  468. */
  469. static void inline expand_category(COOKContext *q, int* category,
  470. int* category_index){
  471. int i;
  472. for(i=0 ; i<q->num_vectors ; i++){
  473. ++category[category_index[i]];
  474. }
  475. }
  476. /**
  477. * The real requantization of the mltcoefs
  478. *
  479. * @param q pointer to the COOKContext
  480. * @param index index
  481. * @param band current subband
  482. * @param quant_value_table pointer to the array
  483. * @param subband_coef_index array of indexes to quant_centroid_tab
  484. * @param subband_coef_noise use random noise instead of predetermined value
  485. * @param mlt_buffer pointer to the mlt buffer
  486. */
  487. static void scalar_dequant(COOKContext *q, int index, int band,
  488. float* quant_value_table, int* subband_coef_index,
  489. int* subband_coef_noise, float* mlt_buffer){
  490. int i;
  491. float f1;
  492. for(i=0 ; i<SUBBAND_SIZE ; i++) {
  493. if (subband_coef_index[i]) {
  494. if (subband_coef_noise[i]) {
  495. f1 = -quant_centroid_tab[index][subband_coef_index[i]];
  496. } else {
  497. f1 = quant_centroid_tab[index][subband_coef_index[i]];
  498. }
  499. } else {
  500. /* noise coding if subband_coef_noise[i] == 0 */
  501. q->random_state = q->random_state * 214013 + 2531011; //typical RNG numbers
  502. f1 = randsign[(q->random_state/0x1000000)&1] * dither_tab[index]; //>>31
  503. }
  504. mlt_buffer[band*20+ i] = f1 * quant_value_table[band];
  505. }
  506. }
  507. /**
  508. * Unpack the subband_coef_index and subband_coef_noise vectors.
  509. *
  510. * @param q pointer to the COOKContext
  511. * @param category pointer to the category array
  512. * @param subband_coef_index array of indexes to quant_centroid_tab
  513. * @param subband_coef_noise use random noise instead of predetermined value
  514. */
  515. static int unpack_SQVH(COOKContext *q, int category, int* subband_coef_index,
  516. int* subband_coef_noise) {
  517. int i,j;
  518. int vlc, vd ,tmp, result;
  519. int ub;
  520. int cb;
  521. vd = vd_tab[category];
  522. result = 0;
  523. for(i=0 ; i<vpr_tab[category] ; i++){
  524. ub = get_bits_count(&q->gb);
  525. vlc = get_vlc2(&q->gb, q->sqvh[category].table, q->sqvh[category].bits, 3);
  526. cb = get_bits_count(&q->gb);
  527. if (q->bits_per_subpacket < get_bits_count(&q->gb)){
  528. vlc = 0;
  529. result = 1;
  530. }
  531. for(j=vd-1 ; j>=0 ; j--){
  532. tmp = (vlc * invradix_tab[category])/0x100000;
  533. subband_coef_index[vd*i+j] = vlc - tmp * (kmax_tab[category]+1);
  534. vlc = tmp;
  535. }
  536. for(j=0 ; j<vd ; j++){
  537. if (subband_coef_index[i*vd + j]) {
  538. if(get_bits_count(&q->gb) < q->bits_per_subpacket){
  539. subband_coef_noise[i*vd+j] = get_bits1(&q->gb);
  540. } else {
  541. result=1;
  542. subband_coef_noise[i*vd+j]=0;
  543. }
  544. } else {
  545. subband_coef_noise[i*vd+j]=0;
  546. }
  547. }
  548. }
  549. return result;
  550. }
  551. /**
  552. * Fill the mlt_buffer with mlt coefficients.
  553. *
  554. * @param q pointer to the COOKContext
  555. * @param category pointer to the category array
  556. * @param quant_value_table pointer to the array
  557. * @param mlt_buffer pointer to mlt coefficients
  558. */
  559. static void decode_vectors(COOKContext* q, int* category,
  560. float* quant_value_table, float* mlt_buffer){
  561. /* A zero in this table means that the subband coefficient is
  562. random noise coded. */
  563. int subband_coef_noise[SUBBAND_SIZE];
  564. /* A zero in this table means that the subband coefficient is a
  565. positive multiplicator. */
  566. int subband_coef_index[SUBBAND_SIZE];
  567. int band, j;
  568. int index=0;
  569. for(band=0 ; band<q->total_subbands ; band++){
  570. index = category[band];
  571. if(category[band] < 7){
  572. if(unpack_SQVH(q, category[band], subband_coef_index, subband_coef_noise)){
  573. index=7;
  574. for(j=0 ; j<q->total_subbands ; j++) category[band+j]=7;
  575. }
  576. }
  577. if(index==7) {
  578. memset(subband_coef_index, 0, sizeof(subband_coef_index));
  579. memset(subband_coef_noise, 0, sizeof(subband_coef_noise));
  580. }
  581. scalar_dequant(q, index, band, quant_value_table, subband_coef_index,
  582. subband_coef_noise, mlt_buffer);
  583. }
  584. if(q->total_subbands*SUBBAND_SIZE >= q->samples_per_channel){
  585. return;
  586. }
  587. }
  588. /**
  589. * function for decoding mono data
  590. *
  591. * @param q pointer to the COOKContext
  592. * @param mlt_buffer1 pointer to left channel mlt coefficients
  593. * @param mlt_buffer2 pointer to right channel mlt coefficients
  594. */
  595. static void mono_decode(COOKContext *q, float* mlt_buffer) {
  596. int category_index[128];
  597. float quant_value_table[102];
  598. int quant_index_table[102];
  599. int category[128];
  600. memset(&category, 0, 128*sizeof(int));
  601. memset(&quant_value_table, 0, 102*sizeof(int));
  602. memset(&category_index, 0, 128*sizeof(int));
  603. decode_envelope(q, quant_index_table);
  604. q->num_vectors = get_bits(&q->gb,q->log2_numvector_size);
  605. dequant_envelope(q, quant_index_table, quant_value_table);
  606. categorize(q, quant_index_table, category, category_index);
  607. expand_category(q, category, category_index);
  608. decode_vectors(q, category, quant_value_table, mlt_buffer);
  609. }
  610. /**
  611. * The modulated lapped transform, this takes transform coefficients
  612. * and transforms them into timedomain samples. This is done through
  613. * an FFT-based algorithm with pre- and postrotation steps.
  614. * A window and reorder step is also included.
  615. *
  616. * @param q pointer to the COOKContext
  617. * @param inbuffer pointer to the mltcoefficients
  618. * @param outbuffer pointer to the timedomain buffer
  619. * @param mlt_tmp pointer to temporary storage space
  620. */
  621. static void cook_imlt(COOKContext *q, float* inbuffer, float* outbuffer,
  622. float* mlt_tmp){
  623. int i;
  624. /* prerotation */
  625. for(i=0 ; i<q->mlt_size ; i+=2){
  626. outbuffer[i] = (q->mlt_presin[i/2] * inbuffer[q->mlt_size-1-i]) +
  627. (q->mlt_precos[i/2] * inbuffer[i]);
  628. outbuffer[i+1] = (q->mlt_precos[i/2] * inbuffer[q->mlt_size-1-i]) -
  629. (q->mlt_presin[i/2] * inbuffer[i]);
  630. }
  631. /* FFT */
  632. ff_fft_permute(&q->fft_ctx, (FFTComplex *) outbuffer);
  633. ff_fft_calc (&q->fft_ctx, (FFTComplex *) outbuffer);
  634. /* postrotation */
  635. for(i=0 ; i<q->mlt_size ; i+=2){
  636. mlt_tmp[i] = (q->mlt_postcos[(q->mlt_size-1-i)/2] * outbuffer[i+1]) +
  637. (q->mlt_postcos[i/2] * outbuffer[i]);
  638. mlt_tmp[q->mlt_size-1-i] = (q->mlt_postcos[(q->mlt_size-1-i)/2] * outbuffer[i]) -
  639. (q->mlt_postcos[i/2] * outbuffer[i+1]);
  640. }
  641. /* window and reorder */
  642. for(i=0 ; i<q->mlt_size/2 ; i++){
  643. outbuffer[i] = mlt_tmp[q->mlt_size/2-1-i] * q->mlt_window[i];
  644. outbuffer[q->mlt_size-1-i]= mlt_tmp[q->mlt_size/2-1-i] *
  645. q->mlt_window[q->mlt_size-1-i];
  646. outbuffer[q->mlt_size+i]= mlt_tmp[q->mlt_size/2+i] *
  647. q->mlt_window[q->mlt_size-1-i];
  648. outbuffer[2*q->mlt_size-1-i]= -(mlt_tmp[q->mlt_size/2+i] *
  649. q->mlt_window[i]);
  650. }
  651. }
  652. /**
  653. * the actual requantization of the timedomain samples
  654. *
  655. * @param q pointer to the COOKContext
  656. * @param buffer pointer to the timedomain buffer
  657. * @param gain_index index for the block multiplier
  658. * @param gain_index_next index for the next block multiplier
  659. */
  660. static void interpolate(COOKContext *q, float* buffer,
  661. int gain_index, int gain_index_next){
  662. int i;
  663. float fc1, fc2;
  664. fc1 = q->pow2tab[gain_index+63];
  665. if(gain_index == gain_index_next){ //static gain
  666. for(i=0 ; i<q->gain_size_factor ; i++){
  667. buffer[i]*=fc1;
  668. }
  669. return;
  670. } else { //smooth gain
  671. fc2 = q->gain_table[11 + (gain_index_next-gain_index)];
  672. for(i=0 ; i<q->gain_size_factor ; i++){
  673. buffer[i]*=fc1;
  674. fc1*=fc2;
  675. }
  676. return;
  677. }
  678. }
  679. /**
  680. * timedomain requantization of the timedomain samples
  681. *
  682. * @param q pointer to the COOKContext
  683. * @param buffer pointer to the timedomain buffer
  684. * @param gain_now current gain structure
  685. * @param gain_previous previous gain structure
  686. */
  687. static void gain_window(COOKContext *q, float* buffer, COOKgain* gain_now,
  688. COOKgain* gain_previous){
  689. int i, index;
  690. int gain_index[9];
  691. int tmp_gain_index;
  692. gain_index[8]=0;
  693. index = gain_previous->size;
  694. for (i=7 ; i>=0 ; i--) {
  695. if(index && gain_previous->qidx_table1[index-1]==i) {
  696. gain_index[i] = gain_previous->qidx_table2[index-1];
  697. index--;
  698. } else {
  699. gain_index[i]=gain_index[i+1];
  700. }
  701. }
  702. /* This is applied to the to be previous data buffer. */
  703. for(i=0;i<8;i++){
  704. interpolate(q, &buffer[q->samples_per_channel+q->gain_size_factor*i],
  705. gain_index[i], gain_index[i+1]);
  706. }
  707. tmp_gain_index = gain_index[0];
  708. index = gain_now->size;
  709. for (i=7 ; i>=0 ; i--) {
  710. if(index && gain_now->qidx_table1[index-1]==i) {
  711. gain_index[i]= gain_now->qidx_table2[index-1];
  712. index--;
  713. } else {
  714. gain_index[i]=gain_index[i+1];
  715. }
  716. }
  717. /* This is applied to the to be current block. */
  718. for(i=0;i<8;i++){
  719. interpolate(q, &buffer[i*q->gain_size_factor],
  720. tmp_gain_index+gain_index[i],
  721. tmp_gain_index+gain_index[i+1]);
  722. }
  723. }
  724. /**
  725. * mlt overlapping and buffer management
  726. *
  727. * @param q pointer to the COOKContext
  728. * @param buffer pointer to the timedomain buffer
  729. * @param gain_now current gain structure
  730. * @param gain_previous previous gain structure
  731. * @param previous_buffer pointer to the previous buffer to be used for overlapping
  732. *
  733. */
  734. static void gain_compensate(COOKContext *q, float* buffer, COOKgain* gain_now,
  735. COOKgain* gain_previous, float* previous_buffer) {
  736. int i;
  737. if((gain_now->size || gain_previous->size)) {
  738. gain_window(q, buffer, gain_now, gain_previous);
  739. }
  740. /* Overlap with the previous block. */
  741. for(i=0 ; i<q->samples_per_channel ; i++) buffer[i]+=previous_buffer[i];
  742. /* Save away the current to be previous block. */
  743. memcpy(previous_buffer, buffer+q->samples_per_channel,
  744. sizeof(float)*q->samples_per_channel);
  745. }
  746. /**
  747. * function for getting the jointstereo coupling information
  748. *
  749. * @param q pointer to the COOKContext
  750. * @param decouple_tab decoupling array
  751. *
  752. */
  753. static void decouple_info(COOKContext *q, int* decouple_tab){
  754. int length, i;
  755. if(get_bits1(&q->gb)) {
  756. if(cplband[q->js_subband_start] > cplband[q->subbands-1]) return;
  757. length = cplband[q->subbands-1] - cplband[q->js_subband_start] + 1;
  758. for (i=0 ; i<length ; i++) {
  759. decouple_tab[cplband[q->js_subband_start] + i] = get_vlc2(&q->gb, q->ccpl.table, q->ccpl.bits, 2);
  760. }
  761. return;
  762. }
  763. if(cplband[q->js_subband_start] > cplband[q->subbands-1]) return;
  764. length = cplband[q->subbands-1] - cplband[q->js_subband_start] + 1;
  765. for (i=0 ; i<length ; i++) {
  766. decouple_tab[cplband[q->js_subband_start] + i] = get_bits(&q->gb, q->js_vlc_bits);
  767. }
  768. return;
  769. }
  770. /**
  771. * function for decoding joint stereo data
  772. *
  773. * @param q pointer to the COOKContext
  774. * @param mlt_buffer1 pointer to left channel mlt coefficients
  775. * @param mlt_buffer2 pointer to right channel mlt coefficients
  776. */
  777. static void joint_decode(COOKContext *q, float* mlt_buffer1,
  778. float* mlt_buffer2) {
  779. int i,j;
  780. int decouple_tab[SUBBAND_SIZE];
  781. float decode_buffer[1060];
  782. int idx, cpl_tmp,tmp_idx;
  783. float f1,f2;
  784. float* cplscale;
  785. memset(decouple_tab, 0, sizeof(decouple_tab));
  786. memset(decode_buffer, 0, sizeof(decode_buffer));
  787. /* Make sure the buffers are zeroed out. */
  788. memset(mlt_buffer1,0, 1024*sizeof(float));
  789. memset(mlt_buffer2,0, 1024*sizeof(float));
  790. decouple_info(q, decouple_tab);
  791. mono_decode(q, decode_buffer);
  792. /* The two channels are stored interleaved in decode_buffer. */
  793. for (i=0 ; i<q->js_subband_start ; i++) {
  794. for (j=0 ; j<SUBBAND_SIZE ; j++) {
  795. mlt_buffer1[i*20+j] = decode_buffer[i*40+j];
  796. mlt_buffer2[i*20+j] = decode_buffer[i*40+20+j];
  797. }
  798. }
  799. /* When we reach js_subband_start (the higher frequencies)
  800. the coefficients are stored in a coupling scheme. */
  801. idx = (1 << q->js_vlc_bits) - 1;
  802. for (i=q->js_subband_start ; i<q->subbands ; i++) {
  803. cpl_tmp = cplband[i];
  804. idx -=decouple_tab[cpl_tmp];
  805. cplscale = (float*)cplscales[q->js_vlc_bits-2]; //choose decoupler table
  806. f1 = cplscale[decouple_tab[cpl_tmp]];
  807. f2 = cplscale[idx-1];
  808. for (j=0 ; j<SUBBAND_SIZE ; j++) {
  809. tmp_idx = ((q->js_subband_start + i)*20)+j;
  810. mlt_buffer1[20*i + j] = f1 * decode_buffer[tmp_idx];
  811. mlt_buffer2[20*i + j] = f2 * decode_buffer[tmp_idx];
  812. }
  813. idx = (1 << q->js_vlc_bits) - 1;
  814. }
  815. }
  816. /**
  817. * First part of subpacket decoding:
  818. * decode raw stream bytes and read gain info.
  819. *
  820. * @param q pointer to the COOKContext
  821. * @param inbuffer pointer to raw stream data
  822. * @param gain_ptr array of current/prev gain pointers
  823. */
  824. static inline void
  825. decode_bytes_and_gain(COOKContext *q, uint8_t *inbuffer,
  826. COOKgain *gain_ptr[])
  827. {
  828. int offset;
  829. offset = decode_bytes(inbuffer, q->decoded_bytes_buffer,
  830. q->bits_per_subpacket/8);
  831. init_get_bits(&q->gb, q->decoded_bytes_buffer + offset,
  832. q->bits_per_subpacket);
  833. decode_gain_info(&q->gb, gain_ptr[0]);
  834. /* Swap current and previous gains */
  835. FFSWAP(COOKgain *, gain_ptr[0], gain_ptr[1]);
  836. }
  837. /**
  838. * Final part of subpacket decoding:
  839. * Apply modulated lapped transform, gain compensation,
  840. * clip and convert to integer.
  841. *
  842. * @param q pointer to the COOKContext
  843. * @param decode_buffer pointer to the mlt coefficients
  844. * @param gain_ptr array of current/prev gain pointers
  845. * @param previous_buffer pointer to the previous buffer to be used for overlapping
  846. * @param out pointer to the output buffer
  847. * @param chan 0: left or single channel, 1: right channel
  848. */
  849. static inline void
  850. mlt_compensate_output(COOKContext *q, float *decode_buffer,
  851. COOKgain *gain_ptr[], float *previous_buffer,
  852. int16_t *out, int chan)
  853. {
  854. int j;
  855. cook_imlt(q, decode_buffer, q->mono_mdct_output, q->mlt_tmp);
  856. gain_compensate(q, q->mono_mdct_output, gain_ptr[0],
  857. gain_ptr[1], previous_buffer);
  858. /* Clip and convert floats to 16 bits.
  859. */
  860. for (j = 0; j < q->samples_per_channel; j++) {
  861. out[chan + q->nb_channels * j] =
  862. clip(lrintf(q->mono_mdct_output[j]), -32768, 32767);
  863. }
  864. }
  865. /**
  866. * Cook subpacket decoding. This function returns one decoded subpacket,
  867. * usually 1024 samples per channel.
  868. *
  869. * @param q pointer to the COOKContext
  870. * @param inbuffer pointer to the inbuffer
  871. * @param sub_packet_size subpacket size
  872. * @param outbuffer pointer to the outbuffer
  873. */
  874. static int decode_subpacket(COOKContext *q, uint8_t *inbuffer,
  875. int sub_packet_size, int16_t *outbuffer) {
  876. /* packet dump */
  877. // for (i=0 ; i<sub_packet_size ; i++) {
  878. // av_log(NULL, AV_LOG_ERROR, "%02x", inbuffer[i]);
  879. // }
  880. // av_log(NULL, AV_LOG_ERROR, "\n");
  881. decode_bytes_and_gain(q, inbuffer, q->gain_ptr1);
  882. if (q->joint_stereo) {
  883. joint_decode(q, q->decode_buffer_1, q->decode_buffer_2);
  884. } else {
  885. mono_decode(q, q->decode_buffer_1);
  886. if (q->nb_channels == 2) {
  887. decode_bytes_and_gain(q, inbuffer + sub_packet_size/2,
  888. q->gain_ptr2);
  889. mono_decode(q, q->decode_buffer_2);
  890. }
  891. }
  892. mlt_compensate_output(q, q->decode_buffer_1, q->gain_ptr1,
  893. q->mono_previous_buffer1, outbuffer, 0);
  894. if (q->nb_channels == 2) {
  895. if (q->joint_stereo) {
  896. mlt_compensate_output(q, q->decode_buffer_2, q->gain_ptr1,
  897. q->mono_previous_buffer2, outbuffer, 1);
  898. } else {
  899. mlt_compensate_output(q, q->decode_buffer_2, q->gain_ptr2,
  900. q->mono_previous_buffer2, outbuffer, 1);
  901. }
  902. }
  903. return q->samples_per_frame * sizeof(int16_t);
  904. }
  905. /**
  906. * Cook frame decoding
  907. *
  908. * @param avctx pointer to the AVCodecContext
  909. */
  910. static int cook_decode_frame(AVCodecContext *avctx,
  911. void *data, int *data_size,
  912. uint8_t *buf, int buf_size) {
  913. COOKContext *q = avctx->priv_data;
  914. if (buf_size < avctx->block_align)
  915. return buf_size;
  916. *data_size = decode_subpacket(q, buf, avctx->block_align, data);
  917. return avctx->block_align;
  918. }
  919. #ifdef COOKDEBUG
  920. static void dump_cook_context(COOKContext *q)
  921. {
  922. //int i=0;
  923. #define PRINT(a,b) av_log(NULL,AV_LOG_ERROR," %s = %d\n", a, b);
  924. av_log(NULL,AV_LOG_ERROR,"COOKextradata\n");
  925. av_log(NULL,AV_LOG_ERROR,"cookversion=%x\n",q->cookversion);
  926. if (q->cookversion > STEREO) {
  927. PRINT("js_subband_start",q->js_subband_start);
  928. PRINT("js_vlc_bits",q->js_vlc_bits);
  929. }
  930. av_log(NULL,AV_LOG_ERROR,"COOKContext\n");
  931. PRINT("nb_channels",q->nb_channels);
  932. PRINT("bit_rate",q->bit_rate);
  933. PRINT("sample_rate",q->sample_rate);
  934. PRINT("samples_per_channel",q->samples_per_channel);
  935. PRINT("samples_per_frame",q->samples_per_frame);
  936. PRINT("subbands",q->subbands);
  937. PRINT("random_state",q->random_state);
  938. PRINT("mlt_size",q->mlt_size);
  939. PRINT("js_subband_start",q->js_subband_start);
  940. PRINT("log2_numvector_size",q->log2_numvector_size);
  941. PRINT("numvector_size",q->numvector_size);
  942. PRINT("total_subbands",q->total_subbands);
  943. }
  944. #endif
  945. /**
  946. * Cook initialization
  947. *
  948. * @param avctx pointer to the AVCodecContext
  949. */
  950. static int cook_decode_init(AVCodecContext *avctx)
  951. {
  952. COOKContext *q = avctx->priv_data;
  953. uint8_t *edata_ptr = avctx->extradata;
  954. /* Take care of the codec specific extradata. */
  955. if (avctx->extradata_size <= 0) {
  956. av_log(avctx,AV_LOG_ERROR,"Necessary extradata missing!\n");
  957. return -1;
  958. } else {
  959. /* 8 for mono, 16 for stereo, ? for multichannel
  960. Swap to right endianness so we don't need to care later on. */
  961. av_log(avctx,AV_LOG_DEBUG,"codecdata_length=%d\n",avctx->extradata_size);
  962. if (avctx->extradata_size >= 8){
  963. q->cookversion = be2me_32(bytestream_get_le32(&edata_ptr));
  964. q->samples_per_frame = be2me_16(bytestream_get_le16(&edata_ptr));
  965. q->subbands = be2me_16(bytestream_get_le16(&edata_ptr));
  966. }
  967. if (avctx->extradata_size >= 16){
  968. bytestream_get_le32(&edata_ptr); //Unknown unused
  969. q->js_subband_start = be2me_16(bytestream_get_le16(&edata_ptr));
  970. q->js_vlc_bits = be2me_16(bytestream_get_le16(&edata_ptr));
  971. }
  972. }
  973. /* Take data from the AVCodecContext (RM container). */
  974. q->sample_rate = avctx->sample_rate;
  975. q->nb_channels = avctx->channels;
  976. q->bit_rate = avctx->bit_rate;
  977. /* Initialize state. */
  978. q->random_state = 1;
  979. /* Initialize extradata related variables. */
  980. q->samples_per_channel = q->samples_per_frame / q->nb_channels;
  981. q->bits_per_subpacket = avctx->block_align * 8;
  982. /* Initialize default data states. */
  983. q->log2_numvector_size = 5;
  984. q->total_subbands = q->subbands;
  985. /* Initialize version-dependent variables */
  986. av_log(NULL,AV_LOG_DEBUG,"q->cookversion=%x\n",q->cookversion);
  987. q->joint_stereo = 0;
  988. switch (q->cookversion) {
  989. case MONO:
  990. if (q->nb_channels != 1) {
  991. av_log(avctx,AV_LOG_ERROR,"Container channels != 1, report sample!\n");
  992. return -1;
  993. }
  994. av_log(avctx,AV_LOG_DEBUG,"MONO\n");
  995. break;
  996. case STEREO:
  997. if (q->nb_channels != 1) {
  998. q->bits_per_subpacket = q->bits_per_subpacket/2;
  999. }
  1000. av_log(avctx,AV_LOG_DEBUG,"STEREO\n");
  1001. break;
  1002. case JOINT_STEREO:
  1003. if (q->nb_channels != 2) {
  1004. av_log(avctx,AV_LOG_ERROR,"Container channels != 2, report sample!\n");
  1005. return -1;
  1006. }
  1007. av_log(avctx,AV_LOG_DEBUG,"JOINT_STEREO\n");
  1008. if (avctx->extradata_size >= 16){
  1009. q->total_subbands = q->subbands + q->js_subband_start;
  1010. q->joint_stereo = 1;
  1011. }
  1012. if (q->samples_per_channel > 256) {
  1013. q->log2_numvector_size = 6;
  1014. }
  1015. if (q->samples_per_channel > 512) {
  1016. q->log2_numvector_size = 7;
  1017. }
  1018. break;
  1019. case MC_COOK:
  1020. av_log(avctx,AV_LOG_ERROR,"MC_COOK not supported!\n");
  1021. return -1;
  1022. break;
  1023. default:
  1024. av_log(avctx,AV_LOG_ERROR,"Unknown Cook version, report sample!\n");
  1025. return -1;
  1026. break;
  1027. }
  1028. /* Initialize variable relations */
  1029. q->mlt_size = q->samples_per_channel;
  1030. q->numvector_size = (1 << q->log2_numvector_size);
  1031. /* Generate tables */
  1032. init_rootpow2table(q);
  1033. init_pow2table(q);
  1034. init_gain_table(q);
  1035. if (init_cook_vlc_tables(q) != 0)
  1036. return -1;
  1037. if(avctx->block_align >= UINT_MAX/2)
  1038. return -1;
  1039. /* Pad the databuffer with:
  1040. DECODE_BYTES_PAD1 or DECODE_BYTES_PAD2 for decode_bytes(),
  1041. FF_INPUT_BUFFER_PADDING_SIZE, for the bitstreamreader. */
  1042. if (q->nb_channels==2 && q->joint_stereo==0) {
  1043. q->decoded_bytes_buffer =
  1044. av_mallocz(avctx->block_align/2
  1045. + DECODE_BYTES_PAD2(avctx->block_align/2)
  1046. + FF_INPUT_BUFFER_PADDING_SIZE);
  1047. } else {
  1048. q->decoded_bytes_buffer =
  1049. av_mallocz(avctx->block_align
  1050. + DECODE_BYTES_PAD1(avctx->block_align)
  1051. + FF_INPUT_BUFFER_PADDING_SIZE);
  1052. }
  1053. if (q->decoded_bytes_buffer == NULL)
  1054. return -1;
  1055. q->gain_ptr1[0] = &q->gain_1;
  1056. q->gain_ptr1[1] = &q->gain_2;
  1057. q->gain_ptr2[0] = &q->gain_3;
  1058. q->gain_ptr2[1] = &q->gain_4;
  1059. /* Initialize transform. */
  1060. if ( init_cook_mlt(q) == 0 )
  1061. return -1;
  1062. /* Try to catch some obviously faulty streams, othervise it might be exploitable */
  1063. if (q->total_subbands > 53) {
  1064. av_log(avctx,AV_LOG_ERROR,"total_subbands > 53, report sample!\n");
  1065. return -1;
  1066. }
  1067. if (q->subbands > 50) {
  1068. av_log(avctx,AV_LOG_ERROR,"subbands > 50, report sample!\n");
  1069. return -1;
  1070. }
  1071. if ((q->samples_per_channel == 256) || (q->samples_per_channel == 512) || (q->samples_per_channel == 1024)) {
  1072. } else {
  1073. av_log(avctx,AV_LOG_ERROR,"unknown amount of samples_per_channel = %d, report sample!\n",q->samples_per_channel);
  1074. return -1;
  1075. }
  1076. if ((q->js_vlc_bits > 6) || (q->js_vlc_bits < 0)) {
  1077. av_log(avctx,AV_LOG_ERROR,"q->js_vlc_bits = %d, only >= 0 and <= 6 allowed!\n",q->js_vlc_bits);
  1078. return -1;
  1079. }
  1080. #ifdef COOKDEBUG
  1081. dump_cook_context(q);
  1082. #endif
  1083. return 0;
  1084. }
  1085. AVCodec cook_decoder =
  1086. {
  1087. .name = "cook",
  1088. .type = CODEC_TYPE_AUDIO,
  1089. .id = CODEC_ID_COOK,
  1090. .priv_data_size = sizeof(COOKContext),
  1091. .init = cook_decode_init,
  1092. .close = cook_decode_close,
  1093. .decode = cook_decode_frame,
  1094. };