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.

645 lines
21KB

  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
  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-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. *
  31. * 32bit atom size
  32. * 32bit tag ("alac")
  33. * 32bit tag version (0)
  34. * 32bit samples per frame (used when not set explicitly in the frames)
  35. * 8bit compatible version (0)
  36. * 8bit sample size
  37. * 8bit history mult (40)
  38. * 8bit initial history (10)
  39. * 8bit rice param limit (14)
  40. * 8bit channels
  41. * 16bit maxRun (255)
  42. * 32bit max coded frame size (0 means unknown)
  43. * 32bit average bitrate (0 means unknown)
  44. * 32bit samplerate
  45. */
  46. #include <inttypes.h>
  47. #include "libavutil/channel_layout.h"
  48. #include "avcodec.h"
  49. #include "get_bits.h"
  50. #include "bytestream.h"
  51. #include "internal.h"
  52. #include "thread.h"
  53. #include "unary.h"
  54. #include "mathops.h"
  55. #include "alac_data.h"
  56. #define ALAC_EXTRADATA_SIZE 36
  57. typedef struct {
  58. AVCodecContext *avctx;
  59. GetBitContext gb;
  60. int channels;
  61. int32_t *predict_error_buffer[2];
  62. int32_t *output_samples_buffer[2];
  63. int32_t *extra_bits_buffer[2];
  64. uint32_t max_samples_per_frame;
  65. uint8_t sample_size;
  66. uint8_t rice_history_mult;
  67. uint8_t rice_initial_history;
  68. uint8_t rice_limit;
  69. int extra_bits; /**< number of extra bits beyond 16-bit */
  70. int nb_samples; /**< number of samples in the current frame */
  71. int direct_output;
  72. } ALACContext;
  73. static inline unsigned int decode_scalar(GetBitContext *gb, int k, int bps)
  74. {
  75. unsigned int x = get_unary_0_9(gb);
  76. if (x > 8) { /* RICE THRESHOLD */
  77. /* use alternative encoding */
  78. x = get_bits_long(gb, bps);
  79. } else if (k != 1) {
  80. int extrabits = show_bits(gb, k);
  81. /* multiply x by 2^k - 1, as part of their strange algorithm */
  82. x = (x << k) - x;
  83. if (extrabits > 1) {
  84. x += extrabits - 1;
  85. skip_bits(gb, k);
  86. } else
  87. skip_bits(gb, k - 1);
  88. }
  89. return x;
  90. }
  91. static int rice_decompress(ALACContext *alac, int32_t *output_buffer,
  92. int nb_samples, int bps, int rice_history_mult)
  93. {
  94. int i;
  95. unsigned int history = alac->rice_initial_history;
  96. int sign_modifier = 0;
  97. for (i = 0; i < nb_samples; i++) {
  98. int k;
  99. unsigned int x;
  100. if(get_bits_left(&alac->gb) <= 0)
  101. return -1;
  102. /* calculate rice param and decode next value */
  103. k = av_log2((history >> 9) + 3);
  104. k = FFMIN(k, alac->rice_limit);
  105. x = decode_scalar(&alac->gb, k, bps);
  106. x += sign_modifier;
  107. sign_modifier = 0;
  108. output_buffer[i] = (x >> 1) ^ -(x & 1);
  109. /* update the history */
  110. if (x > 0xffff)
  111. history = 0xffff;
  112. else
  113. history += x * rice_history_mult -
  114. ((history * rice_history_mult) >> 9);
  115. /* special case: there may be compressed blocks of 0 */
  116. if ((history < 128) && (i + 1 < nb_samples)) {
  117. int block_size;
  118. /* calculate rice param and decode block size */
  119. k = 7 - av_log2(history) + ((history + 16) >> 6);
  120. k = FFMIN(k, alac->rice_limit);
  121. block_size = decode_scalar(&alac->gb, k, 16);
  122. if (block_size > 0) {
  123. if (block_size >= nb_samples - i) {
  124. av_log(alac->avctx, AV_LOG_ERROR,
  125. "invalid zero block size of %d %d %d\n", block_size,
  126. nb_samples, i);
  127. block_size = nb_samples - i - 1;
  128. }
  129. memset(&output_buffer[i + 1], 0,
  130. block_size * sizeof(*output_buffer));
  131. i += block_size;
  132. }
  133. if (block_size <= 0xffff)
  134. sign_modifier = 1;
  135. history = 0;
  136. }
  137. }
  138. return 0;
  139. }
  140. static inline int sign_only(int v)
  141. {
  142. return v ? FFSIGN(v) : 0;
  143. }
  144. static void lpc_prediction(int32_t *error_buffer, int32_t *buffer_out,
  145. int nb_samples, int bps, int16_t *lpc_coefs,
  146. int lpc_order, int lpc_quant)
  147. {
  148. int i;
  149. int32_t *pred = buffer_out;
  150. /* first sample always copies */
  151. *buffer_out = *error_buffer;
  152. if (nb_samples <= 1)
  153. return;
  154. if (!lpc_order) {
  155. memcpy(&buffer_out[1], &error_buffer[1],
  156. (nb_samples - 1) * sizeof(*buffer_out));
  157. return;
  158. }
  159. if (lpc_order == 31) {
  160. /* simple 1st-order prediction */
  161. for (i = 1; i < nb_samples; i++) {
  162. buffer_out[i] = sign_extend(buffer_out[i - 1] + error_buffer[i],
  163. bps);
  164. }
  165. return;
  166. }
  167. /* read warm-up samples */
  168. for (i = 1; i <= lpc_order && i < nb_samples; i++)
  169. buffer_out[i] = sign_extend(buffer_out[i - 1] + error_buffer[i], bps);
  170. /* NOTE: 4 and 8 are very common cases that could be optimized. */
  171. for (; i < nb_samples; i++) {
  172. int j;
  173. int val = 0;
  174. int error_val = error_buffer[i];
  175. int error_sign;
  176. int d = *pred++;
  177. /* LPC prediction */
  178. for (j = 0; j < lpc_order; j++)
  179. val += (pred[j] - d) * lpc_coefs[j];
  180. val = (val + (1 << (lpc_quant - 1))) >> lpc_quant;
  181. val += d + error_val;
  182. buffer_out[i] = sign_extend(val, bps);
  183. /* adapt LPC coefficients */
  184. error_sign = sign_only(error_val);
  185. if (error_sign) {
  186. for (j = 0; j < lpc_order && error_val * error_sign > 0; j++) {
  187. int sign;
  188. val = d - pred[j];
  189. sign = sign_only(val) * error_sign;
  190. lpc_coefs[j] -= sign;
  191. val *= sign;
  192. error_val -= (val >> lpc_quant) * (j + 1);
  193. }
  194. }
  195. }
  196. }
  197. static void decorrelate_stereo(int32_t *buffer[2], int nb_samples,
  198. int decorr_shift, int decorr_left_weight)
  199. {
  200. int i;
  201. for (i = 0; i < nb_samples; i++) {
  202. int32_t a, b;
  203. a = buffer[0][i];
  204. b = buffer[1][i];
  205. a -= (b * decorr_left_weight) >> decorr_shift;
  206. b += a;
  207. buffer[0][i] = b;
  208. buffer[1][i] = a;
  209. }
  210. }
  211. static void append_extra_bits(int32_t *buffer[2], int32_t *extra_bits_buffer[2],
  212. int extra_bits, int channels, int nb_samples)
  213. {
  214. int i, ch;
  215. for (ch = 0; ch < channels; ch++)
  216. for (i = 0; i < nb_samples; i++)
  217. buffer[ch][i] = (buffer[ch][i] << extra_bits) | extra_bits_buffer[ch][i];
  218. }
  219. static int decode_element(AVCodecContext *avctx, AVFrame *frame, int ch_index,
  220. int channels)
  221. {
  222. ALACContext *alac = avctx->priv_data;
  223. int has_size, bps, is_compressed, decorr_shift, decorr_left_weight, ret;
  224. uint32_t output_samples;
  225. int i, ch;
  226. skip_bits(&alac->gb, 4); /* element instance tag */
  227. skip_bits(&alac->gb, 12); /* unused header bits */
  228. /* the number of output samples is stored in the frame */
  229. has_size = get_bits1(&alac->gb);
  230. alac->extra_bits = get_bits(&alac->gb, 2) << 3;
  231. bps = alac->sample_size - alac->extra_bits + channels - 1;
  232. if (bps > 32U) {
  233. av_log(avctx, AV_LOG_ERROR, "bps is unsupported: %d\n", bps);
  234. return AVERROR_PATCHWELCOME;
  235. }
  236. /* whether the frame is compressed */
  237. is_compressed = !get_bits1(&alac->gb);
  238. if (has_size)
  239. output_samples = get_bits_long(&alac->gb, 32);
  240. else
  241. output_samples = alac->max_samples_per_frame;
  242. if (!output_samples || output_samples > alac->max_samples_per_frame) {
  243. av_log(avctx, AV_LOG_ERROR, "invalid samples per frame: %"PRIu32"\n",
  244. output_samples);
  245. return AVERROR_INVALIDDATA;
  246. }
  247. if (!alac->nb_samples) {
  248. ThreadFrame tframe = { .f = frame };
  249. /* get output buffer */
  250. frame->nb_samples = output_samples;
  251. if ((ret = ff_thread_get_buffer(avctx, &tframe, 0)) < 0)
  252. return ret;
  253. } else if (output_samples != alac->nb_samples) {
  254. av_log(avctx, AV_LOG_ERROR, "sample count mismatch: %"PRIu32" != %d\n",
  255. output_samples, alac->nb_samples);
  256. return AVERROR_INVALIDDATA;
  257. }
  258. alac->nb_samples = output_samples;
  259. if (alac->direct_output) {
  260. for (ch = 0; ch < channels; ch++)
  261. alac->output_samples_buffer[ch] = (int32_t *)frame->extended_data[ch_index + ch];
  262. }
  263. if (is_compressed) {
  264. int16_t lpc_coefs[2][32];
  265. int lpc_order[2];
  266. int prediction_type[2];
  267. int lpc_quant[2];
  268. int rice_history_mult[2];
  269. decorr_shift = get_bits(&alac->gb, 8);
  270. decorr_left_weight = get_bits(&alac->gb, 8);
  271. for (ch = 0; ch < channels; ch++) {
  272. prediction_type[ch] = get_bits(&alac->gb, 4);
  273. lpc_quant[ch] = get_bits(&alac->gb, 4);
  274. rice_history_mult[ch] = get_bits(&alac->gb, 3);
  275. lpc_order[ch] = get_bits(&alac->gb, 5);
  276. if (lpc_order[ch] >= alac->max_samples_per_frame)
  277. return AVERROR_INVALIDDATA;
  278. /* read the predictor table */
  279. for (i = lpc_order[ch] - 1; i >= 0; i--)
  280. lpc_coefs[ch][i] = get_sbits(&alac->gb, 16);
  281. }
  282. if (alac->extra_bits) {
  283. for (i = 0; i < alac->nb_samples; i++) {
  284. if(get_bits_left(&alac->gb) <= 0)
  285. return -1;
  286. for (ch = 0; ch < channels; ch++)
  287. alac->extra_bits_buffer[ch][i] = get_bits(&alac->gb, alac->extra_bits);
  288. }
  289. }
  290. for (ch = 0; ch < channels; ch++) {
  291. int ret=rice_decompress(alac, alac->predict_error_buffer[ch],
  292. alac->nb_samples, bps,
  293. rice_history_mult[ch] * alac->rice_history_mult / 4);
  294. if(ret<0)
  295. return ret;
  296. /* adaptive FIR filter */
  297. if (prediction_type[ch] == 15) {
  298. /* Prediction type 15 runs the adaptive FIR twice.
  299. * The first pass uses the special-case coef_num = 31, while
  300. * the second pass uses the coefs from the bitstream.
  301. *
  302. * However, this prediction type is not currently used by the
  303. * reference encoder.
  304. */
  305. lpc_prediction(alac->predict_error_buffer[ch],
  306. alac->predict_error_buffer[ch],
  307. alac->nb_samples, bps, NULL, 31, 0);
  308. } else if (prediction_type[ch] > 0) {
  309. av_log(avctx, AV_LOG_WARNING, "unknown prediction type: %i\n",
  310. prediction_type[ch]);
  311. }
  312. lpc_prediction(alac->predict_error_buffer[ch],
  313. alac->output_samples_buffer[ch], alac->nb_samples,
  314. bps, lpc_coefs[ch], lpc_order[ch], lpc_quant[ch]);
  315. }
  316. } else {
  317. /* not compressed, easy case */
  318. for (i = 0; i < alac->nb_samples; i++) {
  319. if(get_bits_left(&alac->gb) <= 0)
  320. return -1;
  321. for (ch = 0; ch < channels; ch++) {
  322. alac->output_samples_buffer[ch][i] =
  323. get_sbits_long(&alac->gb, alac->sample_size);
  324. }
  325. }
  326. alac->extra_bits = 0;
  327. decorr_shift = 0;
  328. decorr_left_weight = 0;
  329. }
  330. if (channels == 2 && decorr_left_weight) {
  331. decorrelate_stereo(alac->output_samples_buffer, alac->nb_samples,
  332. decorr_shift, decorr_left_weight);
  333. }
  334. if (alac->extra_bits) {
  335. append_extra_bits(alac->output_samples_buffer, alac->extra_bits_buffer,
  336. alac->extra_bits, channels, alac->nb_samples);
  337. }
  338. if(av_sample_fmt_is_planar(avctx->sample_fmt)) {
  339. switch(alac->sample_size) {
  340. case 16: {
  341. for (ch = 0; ch < channels; ch++) {
  342. int16_t *outbuffer = (int16_t *)frame->extended_data[ch_index + ch];
  343. for (i = 0; i < alac->nb_samples; i++)
  344. *outbuffer++ = alac->output_samples_buffer[ch][i];
  345. }}
  346. break;
  347. case 24: {
  348. for (ch = 0; ch < channels; ch++) {
  349. for (i = 0; i < alac->nb_samples; i++)
  350. alac->output_samples_buffer[ch][i] <<= 8;
  351. }}
  352. break;
  353. }
  354. }else{
  355. switch(alac->sample_size) {
  356. case 16: {
  357. int16_t *outbuffer = ((int16_t *)frame->extended_data[0]) + ch_index;
  358. for (i = 0; i < alac->nb_samples; i++) {
  359. for (ch = 0; ch < channels; ch++)
  360. *outbuffer++ = alac->output_samples_buffer[ch][i];
  361. outbuffer += alac->channels - channels;
  362. }
  363. }
  364. break;
  365. case 24: {
  366. int32_t *outbuffer = ((int32_t *)frame->extended_data[0]) + ch_index;
  367. for (i = 0; i < alac->nb_samples; i++) {
  368. for (ch = 0; ch < channels; ch++)
  369. *outbuffer++ = alac->output_samples_buffer[ch][i] << 8;
  370. outbuffer += alac->channels - channels;
  371. }
  372. }
  373. break;
  374. case 32: {
  375. int32_t *outbuffer = ((int32_t *)frame->extended_data[0]) + ch_index;
  376. for (i = 0; i < alac->nb_samples; i++) {
  377. for (ch = 0; ch < channels; ch++)
  378. *outbuffer++ = alac->output_samples_buffer[ch][i];
  379. outbuffer += alac->channels - channels;
  380. }
  381. }
  382. break;
  383. }
  384. }
  385. return 0;
  386. }
  387. static int alac_decode_frame(AVCodecContext *avctx, void *data,
  388. int *got_frame_ptr, AVPacket *avpkt)
  389. {
  390. ALACContext *alac = avctx->priv_data;
  391. AVFrame *frame = data;
  392. enum AlacRawDataBlockType element;
  393. int channels;
  394. int ch, ret, got_end;
  395. if ((ret = init_get_bits8(&alac->gb, avpkt->data, avpkt->size)) < 0)
  396. return ret;
  397. got_end = 0;
  398. alac->nb_samples = 0;
  399. ch = 0;
  400. while (get_bits_left(&alac->gb) >= 3) {
  401. element = get_bits(&alac->gb, 3);
  402. if (element == TYPE_END) {
  403. got_end = 1;
  404. break;
  405. }
  406. if (element > TYPE_CPE && element != TYPE_LFE) {
  407. av_log(avctx, AV_LOG_ERROR, "syntax element unsupported: %d\n", element);
  408. return AVERROR_PATCHWELCOME;
  409. }
  410. channels = (element == TYPE_CPE) ? 2 : 1;
  411. if (ch + channels > alac->channels ||
  412. ff_alac_channel_layout_offsets[alac->channels - 1][ch] + channels > alac->channels) {
  413. av_log(avctx, AV_LOG_ERROR, "invalid element channel count\n");
  414. return AVERROR_INVALIDDATA;
  415. }
  416. ret = decode_element(avctx, frame,
  417. ff_alac_channel_layout_offsets[alac->channels - 1][ch],
  418. channels);
  419. if (ret < 0 && get_bits_left(&alac->gb))
  420. return ret;
  421. ch += channels;
  422. }
  423. if (!got_end) {
  424. av_log(avctx, AV_LOG_ERROR, "no end tag found. incomplete packet.\n");
  425. return AVERROR_INVALIDDATA;
  426. }
  427. if (avpkt->size * 8 - get_bits_count(&alac->gb) > 8) {
  428. av_log(avctx, AV_LOG_ERROR, "Error : %d bits left\n",
  429. avpkt->size * 8 - get_bits_count(&alac->gb));
  430. }
  431. if (alac->channels == ch)
  432. *got_frame_ptr = 1;
  433. else
  434. av_log(avctx, AV_LOG_WARNING, "Failed to decode all channels\n");
  435. return avpkt->size;
  436. }
  437. static av_cold int alac_decode_close(AVCodecContext *avctx)
  438. {
  439. ALACContext *alac = avctx->priv_data;
  440. int ch;
  441. for (ch = 0; ch < FFMIN(alac->channels, 2); ch++) {
  442. av_freep(&alac->predict_error_buffer[ch]);
  443. if (!alac->direct_output)
  444. av_freep(&alac->output_samples_buffer[ch]);
  445. av_freep(&alac->extra_bits_buffer[ch]);
  446. }
  447. return 0;
  448. }
  449. static int allocate_buffers(ALACContext *alac)
  450. {
  451. int ch;
  452. int buf_size = alac->max_samples_per_frame * sizeof(int32_t);
  453. for (ch = 0; ch < FFMIN(alac->channels, 2); ch++) {
  454. FF_ALLOC_OR_GOTO(alac->avctx, alac->predict_error_buffer[ch],
  455. buf_size, buf_alloc_fail);
  456. alac->direct_output = alac->sample_size > 16 && av_sample_fmt_is_planar(alac->avctx->sample_fmt);
  457. if (!alac->direct_output) {
  458. FF_ALLOC_OR_GOTO(alac->avctx, alac->output_samples_buffer[ch],
  459. buf_size, buf_alloc_fail);
  460. }
  461. FF_ALLOC_OR_GOTO(alac->avctx, alac->extra_bits_buffer[ch],
  462. buf_size, buf_alloc_fail);
  463. }
  464. return 0;
  465. buf_alloc_fail:
  466. alac_decode_close(alac->avctx);
  467. return AVERROR(ENOMEM);
  468. }
  469. static int alac_set_info(ALACContext *alac)
  470. {
  471. GetByteContext gb;
  472. bytestream2_init(&gb, alac->avctx->extradata,
  473. alac->avctx->extradata_size);
  474. bytestream2_skipu(&gb, 12); // size:4, alac:4, version:4
  475. alac->max_samples_per_frame = bytestream2_get_be32u(&gb);
  476. if (!alac->max_samples_per_frame ||
  477. alac->max_samples_per_frame > INT_MAX / sizeof(int32_t)) {
  478. av_log(alac->avctx, AV_LOG_ERROR,
  479. "max samples per frame invalid: %"PRIu32"\n",
  480. alac->max_samples_per_frame);
  481. return AVERROR_INVALIDDATA;
  482. }
  483. bytestream2_skipu(&gb, 1); // compatible version
  484. alac->sample_size = bytestream2_get_byteu(&gb);
  485. alac->rice_history_mult = bytestream2_get_byteu(&gb);
  486. alac->rice_initial_history = bytestream2_get_byteu(&gb);
  487. alac->rice_limit = bytestream2_get_byteu(&gb);
  488. alac->channels = bytestream2_get_byteu(&gb);
  489. bytestream2_get_be16u(&gb); // maxRun
  490. bytestream2_get_be32u(&gb); // max coded frame size
  491. bytestream2_get_be32u(&gb); // average bitrate
  492. bytestream2_get_be32u(&gb); // samplerate
  493. return 0;
  494. }
  495. static av_cold int alac_decode_init(AVCodecContext * avctx)
  496. {
  497. int ret;
  498. int req_packed;
  499. ALACContext *alac = avctx->priv_data;
  500. alac->avctx = avctx;
  501. /* initialize from the extradata */
  502. if (alac->avctx->extradata_size < ALAC_EXTRADATA_SIZE) {
  503. av_log(avctx, AV_LOG_ERROR, "extradata is too small\n");
  504. return AVERROR_INVALIDDATA;
  505. }
  506. if (alac_set_info(alac)) {
  507. av_log(avctx, AV_LOG_ERROR, "set_info failed\n");
  508. return -1;
  509. }
  510. req_packed = LIBAVCODEC_VERSION_MAJOR < 55 && !av_sample_fmt_is_planar(avctx->request_sample_fmt);
  511. switch (alac->sample_size) {
  512. case 16: avctx->sample_fmt = req_packed ? AV_SAMPLE_FMT_S16 : AV_SAMPLE_FMT_S16P;
  513. break;
  514. case 24:
  515. case 32: avctx->sample_fmt = req_packed ? AV_SAMPLE_FMT_S32 : AV_SAMPLE_FMT_S32P;
  516. break;
  517. default: avpriv_request_sample(avctx, "Sample depth %d", alac->sample_size);
  518. return AVERROR_PATCHWELCOME;
  519. }
  520. avctx->bits_per_raw_sample = alac->sample_size;
  521. if (alac->channels < 1) {
  522. av_log(avctx, AV_LOG_WARNING, "Invalid channel count\n");
  523. alac->channels = avctx->channels;
  524. } else {
  525. if (alac->channels > ALAC_MAX_CHANNELS)
  526. alac->channels = avctx->channels;
  527. else
  528. avctx->channels = alac->channels;
  529. }
  530. if (avctx->channels > ALAC_MAX_CHANNELS || avctx->channels <= 0 ) {
  531. av_log(avctx, AV_LOG_ERROR, "Unsupported channel count: %d\n",
  532. avctx->channels);
  533. return AVERROR_PATCHWELCOME;
  534. }
  535. avctx->channel_layout = ff_alac_channel_layouts[alac->channels - 1];
  536. if ((ret = allocate_buffers(alac)) < 0) {
  537. av_log(avctx, AV_LOG_ERROR, "Error allocating buffers\n");
  538. return ret;
  539. }
  540. return 0;
  541. }
  542. static int init_thread_copy(AVCodecContext *avctx)
  543. {
  544. ALACContext *alac = avctx->priv_data;
  545. alac->avctx = avctx;
  546. return allocate_buffers(alac);
  547. }
  548. AVCodec ff_alac_decoder = {
  549. .name = "alac",
  550. .long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"),
  551. .type = AVMEDIA_TYPE_AUDIO,
  552. .id = AV_CODEC_ID_ALAC,
  553. .priv_data_size = sizeof(ALACContext),
  554. .init = alac_decode_init,
  555. .close = alac_decode_close,
  556. .decode = alac_decode_frame,
  557. .init_thread_copy = ONLY_IF_THREADS_ENABLED(init_thread_copy),
  558. .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
  559. };