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.

713 lines
23KB

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