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.

712 lines
23KB

  1. /*
  2. * ALAC (Apple Lossless Audio Codec) decoder
  3. * Copyright (c) 2005 David Hammerton
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * ALAC (Apple Lossless Audio Codec) decoder
  24. * @author 2005 David Hammerton
  25. * @see http://crazney.net/programs/itunes/alac.html
  26. *
  27. * Note: This decoder expects a 36- (0x24-)byte QuickTime atom to be
  28. * passed through the extradata[_size] fields. This atom is tacked onto
  29. * the end of an 'alac' stsd atom and has the following format:
  30. * bytes 0-3 atom size (0x24), big-endian
  31. * bytes 4-7 atom type ('alac', not the 'alac' tag from start of stsd)
  32. * bytes 8-35 data bytes needed by decoder
  33. *
  34. * Extradata:
  35. * 32bit size
  36. * 32bit tag (=alac)
  37. * 32bit zero?
  38. * 32bit max sample per frame
  39. * 8bit ?? (zero?)
  40. * 8bit sample size
  41. * 8bit history mult
  42. * 8bit initial history
  43. * 8bit kmodifier
  44. * 8bit channels?
  45. * 16bit ??
  46. * 32bit max coded frame size
  47. * 32bit bitrate?
  48. * 32bit samplerate
  49. */
  50. #include "avcodec.h"
  51. #include "get_bits.h"
  52. #include "bytestream.h"
  53. #include "unary.h"
  54. #include "mathops.h"
  55. #define ALAC_EXTRADATA_SIZE 36
  56. #define MAX_CHANNELS 2
  57. typedef struct {
  58. AVCodecContext *avctx;
  59. GetBitContext gb;
  60. int numchannels;
  61. int bytespersample;
  62. /* buffers */
  63. int32_t *predicterror_buffer[MAX_CHANNELS];
  64. int32_t *outputsamples_buffer[MAX_CHANNELS];
  65. int32_t *wasted_bits_buffer[MAX_CHANNELS];
  66. /* stuff from setinfo */
  67. uint32_t setinfo_max_samples_per_frame; /* 0x1000 = 4096 */ /* max samples per frame? */
  68. uint8_t setinfo_sample_size; /* 0x10 */
  69. uint8_t setinfo_rice_historymult; /* 0x28 */
  70. uint8_t setinfo_rice_initialhistory; /* 0x0a */
  71. uint8_t setinfo_rice_kmodifier; /* 0x0e */
  72. /* end setinfo stuff */
  73. int wasted_bits;
  74. } ALACContext;
  75. static inline int decode_scalar(GetBitContext *gb, int k, int limit, int readsamplesize){
  76. /* read x - number of 1s before 0 represent the rice */
  77. int x = get_unary_0_9(gb);
  78. if (x > 8) { /* RICE THRESHOLD */
  79. /* use alternative encoding */
  80. x = get_bits(gb, readsamplesize);
  81. } else {
  82. if (k >= limit)
  83. k = limit;
  84. if (k != 1) {
  85. int extrabits = show_bits(gb, k);
  86. /* multiply x by 2^k - 1, as part of their strange algorithm */
  87. x = (x << k) - x;
  88. if (extrabits > 1) {
  89. x += extrabits - 1;
  90. skip_bits(gb, k);
  91. } else
  92. skip_bits(gb, k - 1);
  93. }
  94. }
  95. return x;
  96. }
  97. static void bastardized_rice_decompress(ALACContext *alac,
  98. int32_t *output_buffer,
  99. int output_size,
  100. int readsamplesize, /* arg_10 */
  101. int rice_initialhistory, /* arg424->b */
  102. int rice_kmodifier, /* arg424->d */
  103. int rice_historymult, /* arg424->c */
  104. int rice_kmodifier_mask /* arg424->e */
  105. )
  106. {
  107. int output_count;
  108. unsigned int history = rice_initialhistory;
  109. int sign_modifier = 0;
  110. for (output_count = 0; output_count < output_size; output_count++) {
  111. int32_t x;
  112. int32_t x_modified;
  113. int32_t final_val;
  114. /* standard rice encoding */
  115. int k; /* size of extra bits */
  116. /* read k, that is bits as is */
  117. k = av_log2((history >> 9) + 3);
  118. x= decode_scalar(&alac->gb, k, rice_kmodifier, readsamplesize);
  119. x_modified = sign_modifier + x;
  120. final_val = (x_modified + 1) / 2;
  121. if (x_modified & 1) final_val *= -1;
  122. output_buffer[output_count] = final_val;
  123. sign_modifier = 0;
  124. /* now update the history */
  125. history += x_modified * rice_historymult
  126. - ((history * rice_historymult) >> 9);
  127. if (x_modified > 0xffff)
  128. history = 0xffff;
  129. /* special case: there may be compressed blocks of 0 */
  130. if ((history < 128) && (output_count+1 < output_size)) {
  131. int k;
  132. unsigned int block_size;
  133. sign_modifier = 1;
  134. k = 7 - av_log2(history) + ((history + 16) >> 6 /* / 64 */);
  135. block_size= decode_scalar(&alac->gb, k, rice_kmodifier, 16);
  136. if (block_size > 0) {
  137. if(block_size >= output_size - output_count){
  138. av_log(alac->avctx, AV_LOG_ERROR, "invalid zero block size of %d %d %d\n", block_size, output_size, output_count);
  139. block_size= output_size - output_count - 1;
  140. }
  141. memset(&output_buffer[output_count+1], 0, block_size * 4);
  142. output_count += block_size;
  143. }
  144. if (block_size > 0xffff)
  145. sign_modifier = 0;
  146. history = 0;
  147. }
  148. }
  149. }
  150. static inline int sign_only(int v)
  151. {
  152. return v ? FFSIGN(v) : 0;
  153. }
  154. static void predictor_decompress_fir_adapt(int32_t *error_buffer,
  155. int32_t *buffer_out,
  156. int output_size,
  157. int readsamplesize,
  158. int16_t *predictor_coef_table,
  159. int predictor_coef_num,
  160. int predictor_quantitization)
  161. {
  162. int i;
  163. /* first sample always copies */
  164. *buffer_out = *error_buffer;
  165. if (!predictor_coef_num) {
  166. if (output_size <= 1)
  167. return;
  168. memcpy(buffer_out+1, error_buffer+1, (output_size-1) * 4);
  169. return;
  170. }
  171. if (predictor_coef_num == 0x1f) { /* 11111 - max value of predictor_coef_num */
  172. /* second-best case scenario for fir decompression,
  173. * error describes a small difference from the previous sample only
  174. */
  175. if (output_size <= 1)
  176. return;
  177. for (i = 0; i < output_size - 1; i++) {
  178. int32_t prev_value;
  179. int32_t error_value;
  180. prev_value = buffer_out[i];
  181. error_value = error_buffer[i+1];
  182. buffer_out[i+1] =
  183. sign_extend((prev_value + error_value), readsamplesize);
  184. }
  185. return;
  186. }
  187. /* read warm-up samples */
  188. if (predictor_coef_num > 0)
  189. for (i = 0; i < predictor_coef_num; i++) {
  190. int32_t val;
  191. val = buffer_out[i] + error_buffer[i+1];
  192. val = sign_extend(val, readsamplesize);
  193. buffer_out[i+1] = val;
  194. }
  195. /* 4 and 8 are very common cases (the only ones i've seen). these
  196. * should be unrolled and optimized
  197. */
  198. /* general case */
  199. if (predictor_coef_num > 0) {
  200. for (i = predictor_coef_num + 1; i < output_size; i++) {
  201. int j;
  202. int sum = 0;
  203. int outval;
  204. int error_val = error_buffer[i];
  205. for (j = 0; j < predictor_coef_num; j++) {
  206. sum += (buffer_out[predictor_coef_num-j] - buffer_out[0]) *
  207. predictor_coef_table[j];
  208. }
  209. outval = (1 << (predictor_quantitization-1)) + sum;
  210. outval = outval >> predictor_quantitization;
  211. outval = outval + buffer_out[0] + error_val;
  212. outval = sign_extend(outval, readsamplesize);
  213. buffer_out[predictor_coef_num+1] = outval;
  214. if (error_val > 0) {
  215. int predictor_num = predictor_coef_num - 1;
  216. while (predictor_num >= 0 && error_val > 0) {
  217. int val = buffer_out[0] - buffer_out[predictor_coef_num - predictor_num];
  218. int sign = sign_only(val);
  219. predictor_coef_table[predictor_num] -= sign;
  220. val *= sign; /* absolute value */
  221. error_val -= ((val >> predictor_quantitization) *
  222. (predictor_coef_num - predictor_num));
  223. predictor_num--;
  224. }
  225. } else if (error_val < 0) {
  226. int predictor_num = predictor_coef_num - 1;
  227. while (predictor_num >= 0 && error_val < 0) {
  228. int val = buffer_out[0] - buffer_out[predictor_coef_num - predictor_num];
  229. int sign = - sign_only(val);
  230. predictor_coef_table[predictor_num] -= sign;
  231. val *= sign; /* neg value */
  232. error_val -= ((val >> predictor_quantitization) *
  233. (predictor_coef_num - predictor_num));
  234. predictor_num--;
  235. }
  236. }
  237. buffer_out++;
  238. }
  239. }
  240. }
  241. static void reconstruct_stereo_16(int32_t *buffer[MAX_CHANNELS],
  242. int16_t *buffer_out,
  243. int numchannels, int numsamples,
  244. uint8_t interlacing_shift,
  245. uint8_t interlacing_leftweight)
  246. {
  247. int i;
  248. if (numsamples <= 0)
  249. return;
  250. /* weighted interlacing */
  251. if (interlacing_leftweight) {
  252. for (i = 0; i < numsamples; i++) {
  253. int32_t a, b;
  254. a = buffer[0][i];
  255. b = buffer[1][i];
  256. a -= (b * interlacing_leftweight) >> interlacing_shift;
  257. b += a;
  258. buffer_out[i*numchannels] = b;
  259. buffer_out[i*numchannels + 1] = a;
  260. }
  261. return;
  262. }
  263. /* otherwise basic interlacing took place */
  264. for (i = 0; i < numsamples; i++) {
  265. int16_t left, right;
  266. left = buffer[0][i];
  267. right = buffer[1][i];
  268. buffer_out[i*numchannels] = left;
  269. buffer_out[i*numchannels + 1] = right;
  270. }
  271. }
  272. static void decorrelate_stereo_24(int32_t *buffer[MAX_CHANNELS],
  273. int32_t *buffer_out,
  274. int32_t *wasted_bits_buffer[MAX_CHANNELS],
  275. int wasted_bits,
  276. int numchannels, int numsamples,
  277. uint8_t interlacing_shift,
  278. uint8_t interlacing_leftweight)
  279. {
  280. int i;
  281. if (numsamples <= 0)
  282. return;
  283. /* weighted interlacing */
  284. if (interlacing_leftweight) {
  285. for (i = 0; i < numsamples; i++) {
  286. int32_t a, b;
  287. a = buffer[0][i];
  288. b = buffer[1][i];
  289. a -= (b * interlacing_leftweight) >> interlacing_shift;
  290. b += a;
  291. if (wasted_bits) {
  292. b = (b << wasted_bits) | wasted_bits_buffer[0][i];
  293. a = (a << wasted_bits) | wasted_bits_buffer[1][i];
  294. }
  295. buffer_out[i * numchannels] = b << 8;
  296. buffer_out[i * numchannels + 1] = a << 8;
  297. }
  298. } else {
  299. for (i = 0; i < numsamples; i++) {
  300. int32_t left, right;
  301. left = buffer[0][i];
  302. right = buffer[1][i];
  303. if (wasted_bits) {
  304. left = (left << wasted_bits) | wasted_bits_buffer[0][i];
  305. right = (right << wasted_bits) | wasted_bits_buffer[1][i];
  306. }
  307. buffer_out[i * numchannels] = left << 8;
  308. buffer_out[i * numchannels + 1] = right << 8;
  309. }
  310. }
  311. }
  312. static int alac_decode_frame(AVCodecContext *avctx,
  313. void *outbuffer, int *outputsize,
  314. AVPacket *avpkt)
  315. {
  316. const uint8_t *inbuffer = avpkt->data;
  317. int input_buffer_size = avpkt->size;
  318. ALACContext *alac = avctx->priv_data;
  319. int channels;
  320. unsigned int outputsamples;
  321. int hassize;
  322. unsigned int readsamplesize;
  323. int isnotcompressed;
  324. uint8_t interlacing_shift;
  325. uint8_t interlacing_leftweight;
  326. /* short-circuit null buffers */
  327. if (!inbuffer || !input_buffer_size)
  328. return -1;
  329. init_get_bits(&alac->gb, inbuffer, input_buffer_size * 8);
  330. channels = get_bits(&alac->gb, 3) + 1;
  331. if (channels != avctx->channels) {
  332. av_log(avctx, AV_LOG_ERROR, "frame header channel count mismatch\n");
  333. return AVERROR_INVALIDDATA;
  334. }
  335. /* 2^result = something to do with output waiting.
  336. * perhaps matters if we read > 1 frame in a pass?
  337. */
  338. skip_bits(&alac->gb, 4);
  339. skip_bits(&alac->gb, 12); /* unknown, skip 12 bits */
  340. /* the output sample size is stored soon */
  341. hassize = get_bits1(&alac->gb);
  342. alac->wasted_bits = get_bits(&alac->gb, 2) << 3;
  343. /* whether the frame is compressed */
  344. isnotcompressed = get_bits1(&alac->gb);
  345. if (hassize) {
  346. /* now read the number of samples as a 32bit integer */
  347. outputsamples = get_bits_long(&alac->gb, 32);
  348. if(outputsamples > alac->setinfo_max_samples_per_frame){
  349. av_log(avctx, AV_LOG_ERROR, "outputsamples %d > %d\n", outputsamples, alac->setinfo_max_samples_per_frame);
  350. return -1;
  351. }
  352. } else
  353. outputsamples = alac->setinfo_max_samples_per_frame;
  354. alac->bytespersample = channels * av_get_bytes_per_sample(avctx->sample_fmt);
  355. if(outputsamples > *outputsize / alac->bytespersample){
  356. av_log(avctx, AV_LOG_ERROR, "sample buffer too small\n");
  357. return -1;
  358. }
  359. *outputsize = outputsamples * alac->bytespersample;
  360. readsamplesize = alac->setinfo_sample_size - (alac->wasted_bits) + channels - 1;
  361. if (readsamplesize > MIN_CACHE_BITS) {
  362. av_log(avctx, AV_LOG_ERROR, "readsamplesize too big (%d)\n", readsamplesize);
  363. return -1;
  364. }
  365. if (!isnotcompressed) {
  366. /* so it is compressed */
  367. int16_t predictor_coef_table[MAX_CHANNELS][32];
  368. int predictor_coef_num[MAX_CHANNELS];
  369. int prediction_type[MAX_CHANNELS];
  370. int prediction_quantitization[MAX_CHANNELS];
  371. int ricemodifier[MAX_CHANNELS];
  372. int i, chan;
  373. interlacing_shift = get_bits(&alac->gb, 8);
  374. interlacing_leftweight = get_bits(&alac->gb, 8);
  375. for (chan = 0; chan < channels; chan++) {
  376. prediction_type[chan] = get_bits(&alac->gb, 4);
  377. prediction_quantitization[chan] = get_bits(&alac->gb, 4);
  378. ricemodifier[chan] = get_bits(&alac->gb, 3);
  379. predictor_coef_num[chan] = get_bits(&alac->gb, 5);
  380. /* read the predictor table */
  381. for (i = 0; i < predictor_coef_num[chan]; i++)
  382. predictor_coef_table[chan][i] = (int16_t)get_bits(&alac->gb, 16);
  383. }
  384. if (alac->wasted_bits) {
  385. int i, ch;
  386. for (i = 0; i < outputsamples; i++) {
  387. for (ch = 0; ch < channels; ch++)
  388. alac->wasted_bits_buffer[ch][i] = get_bits(&alac->gb, alac->wasted_bits);
  389. }
  390. }
  391. for (chan = 0; chan < channels; chan++) {
  392. bastardized_rice_decompress(alac,
  393. alac->predicterror_buffer[chan],
  394. outputsamples,
  395. readsamplesize,
  396. alac->setinfo_rice_initialhistory,
  397. alac->setinfo_rice_kmodifier,
  398. ricemodifier[chan] * alac->setinfo_rice_historymult / 4,
  399. (1 << alac->setinfo_rice_kmodifier) - 1);
  400. if (prediction_type[chan] == 0) {
  401. /* adaptive fir */
  402. predictor_decompress_fir_adapt(alac->predicterror_buffer[chan],
  403. alac->outputsamples_buffer[chan],
  404. outputsamples,
  405. readsamplesize,
  406. predictor_coef_table[chan],
  407. predictor_coef_num[chan],
  408. prediction_quantitization[chan]);
  409. } else {
  410. av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type[chan]);
  411. /* I think the only other prediction type (or perhaps this is
  412. * just a boolean?) runs adaptive fir twice.. like:
  413. * predictor_decompress_fir_adapt(predictor_error, tempout, ...)
  414. * predictor_decompress_fir_adapt(predictor_error, outputsamples ...)
  415. * little strange..
  416. */
  417. }
  418. }
  419. } else {
  420. /* not compressed, easy case */
  421. int i, chan;
  422. if (alac->setinfo_sample_size <= 16) {
  423. for (i = 0; i < outputsamples; i++)
  424. for (chan = 0; chan < channels; chan++) {
  425. int32_t audiobits;
  426. audiobits = get_sbits_long(&alac->gb, alac->setinfo_sample_size);
  427. alac->outputsamples_buffer[chan][i] = audiobits;
  428. }
  429. } else {
  430. for (i = 0; i < outputsamples; i++) {
  431. for (chan = 0; chan < channels; chan++) {
  432. alac->outputsamples_buffer[chan][i] = get_bits(&alac->gb,
  433. alac->setinfo_sample_size);
  434. alac->outputsamples_buffer[chan][i] = sign_extend(alac->outputsamples_buffer[chan][i],
  435. alac->setinfo_sample_size);
  436. }
  437. }
  438. }
  439. alac->wasted_bits = 0;
  440. interlacing_shift = 0;
  441. interlacing_leftweight = 0;
  442. }
  443. if (get_bits(&alac->gb, 3) != 7)
  444. av_log(avctx, AV_LOG_ERROR, "Error : Wrong End Of Frame\n");
  445. switch(alac->setinfo_sample_size) {
  446. case 16:
  447. if (channels == 2) {
  448. reconstruct_stereo_16(alac->outputsamples_buffer,
  449. (int16_t*)outbuffer,
  450. alac->numchannels,
  451. outputsamples,
  452. interlacing_shift,
  453. interlacing_leftweight);
  454. } else {
  455. int i;
  456. for (i = 0; i < outputsamples; i++) {
  457. ((int16_t*)outbuffer)[i] = alac->outputsamples_buffer[0][i];
  458. }
  459. }
  460. break;
  461. case 24:
  462. if (channels == 2) {
  463. decorrelate_stereo_24(alac->outputsamples_buffer,
  464. outbuffer,
  465. alac->wasted_bits_buffer,
  466. alac->wasted_bits,
  467. alac->numchannels,
  468. outputsamples,
  469. interlacing_shift,
  470. interlacing_leftweight);
  471. } else {
  472. int i;
  473. for (i = 0; i < outputsamples; i++)
  474. ((int32_t *)outbuffer)[i] = alac->outputsamples_buffer[0][i] << 8;
  475. }
  476. break;
  477. }
  478. if (input_buffer_size * 8 - get_bits_count(&alac->gb) > 8)
  479. av_log(avctx, AV_LOG_ERROR, "Error : %d bits left\n", input_buffer_size * 8 - get_bits_count(&alac->gb));
  480. return input_buffer_size;
  481. }
  482. static av_cold int alac_decode_close(AVCodecContext *avctx)
  483. {
  484. ALACContext *alac = avctx->priv_data;
  485. int chan;
  486. for (chan = 0; chan < alac->numchannels; chan++) {
  487. av_freep(&alac->predicterror_buffer[chan]);
  488. av_freep(&alac->outputsamples_buffer[chan]);
  489. av_freep(&alac->wasted_bits_buffer[chan]);
  490. }
  491. return 0;
  492. }
  493. static int allocate_buffers(ALACContext *alac)
  494. {
  495. int chan;
  496. for (chan = 0; chan < alac->numchannels; chan++) {
  497. alac->predicterror_buffer[chan] =
  498. av_malloc(alac->setinfo_max_samples_per_frame * 4);
  499. alac->outputsamples_buffer[chan] =
  500. av_malloc(alac->setinfo_max_samples_per_frame * 4);
  501. alac->wasted_bits_buffer[chan] = av_malloc(alac->setinfo_max_samples_per_frame * 4);
  502. if (!alac->predicterror_buffer[chan] ||
  503. !alac->outputsamples_buffer[chan] ||
  504. !alac->wasted_bits_buffer[chan]) {
  505. alac_decode_close(alac->avctx);
  506. return AVERROR(ENOMEM);
  507. }
  508. }
  509. return 0;
  510. }
  511. static int alac_set_info(ALACContext *alac)
  512. {
  513. const unsigned char *ptr = alac->avctx->extradata;
  514. ptr += 4; /* size */
  515. ptr += 4; /* alac */
  516. ptr += 4; /* 0 ? */
  517. if(AV_RB32(ptr) >= UINT_MAX/4){
  518. av_log(alac->avctx, AV_LOG_ERROR, "setinfo_max_samples_per_frame too large\n");
  519. return -1;
  520. }
  521. /* buffer size / 2 ? */
  522. alac->setinfo_max_samples_per_frame = bytestream_get_be32(&ptr);
  523. ptr++; /* ??? */
  524. alac->setinfo_sample_size = *ptr++;
  525. alac->setinfo_rice_historymult = *ptr++;
  526. alac->setinfo_rice_initialhistory = *ptr++;
  527. alac->setinfo_rice_kmodifier = *ptr++;
  528. alac->numchannels = *ptr++;
  529. bytestream_get_be16(&ptr); /* ??? */
  530. bytestream_get_be32(&ptr); /* max coded frame size */
  531. bytestream_get_be32(&ptr); /* bitrate ? */
  532. bytestream_get_be32(&ptr); /* samplerate */
  533. return 0;
  534. }
  535. static av_cold int alac_decode_init(AVCodecContext * avctx)
  536. {
  537. int ret;
  538. ALACContext *alac = avctx->priv_data;
  539. alac->avctx = avctx;
  540. /* initialize from the extradata */
  541. if (alac->avctx->extradata_size != ALAC_EXTRADATA_SIZE) {
  542. av_log(avctx, AV_LOG_ERROR, "alac: expected %d extradata bytes\n",
  543. ALAC_EXTRADATA_SIZE);
  544. return -1;
  545. }
  546. if (alac_set_info(alac)) {
  547. av_log(avctx, AV_LOG_ERROR, "alac: set_info failed\n");
  548. return -1;
  549. }
  550. switch (alac->setinfo_sample_size) {
  551. case 16: avctx->sample_fmt = AV_SAMPLE_FMT_S16;
  552. break;
  553. case 24: avctx->sample_fmt = AV_SAMPLE_FMT_S32;
  554. break;
  555. default: av_log(avctx, AV_LOG_ERROR, "Sample depth %d is not supported.\n",
  556. alac->setinfo_sample_size);
  557. return -1;
  558. }
  559. if (alac->numchannels < 1) {
  560. av_log(avctx, AV_LOG_WARNING, "Invalid channel count\n");
  561. alac->numchannels = avctx->channels;
  562. } else {
  563. if (alac->numchannels > MAX_CHANNELS)
  564. alac->numchannels = avctx->channels;
  565. else
  566. avctx->channels = alac->numchannels;
  567. }
  568. if (avctx->channels > MAX_CHANNELS) {
  569. av_log(avctx, AV_LOG_ERROR, "Unsupported channel count: %d\n",
  570. avctx->channels);
  571. return AVERROR_PATCHWELCOME;
  572. }
  573. if ((ret = allocate_buffers(alac)) < 0) {
  574. av_log(avctx, AV_LOG_ERROR, "Error allocating buffers\n");
  575. return ret;
  576. }
  577. return 0;
  578. }
  579. AVCodec ff_alac_decoder = {
  580. .name = "alac",
  581. .type = AVMEDIA_TYPE_AUDIO,
  582. .id = CODEC_ID_ALAC,
  583. .priv_data_size = sizeof(ALACContext),
  584. .init = alac_decode_init,
  585. .close = alac_decode_close,
  586. .decode = alac_decode_frame,
  587. .long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"),
  588. };