]> git.sesse.net Git - ffmpeg/blob - libavcodec/alac.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libavcodec / alac.c
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 /**
23  * @file
24  * ALAC (Apple Lossless Audio Codec) decoder
25  * @author 2005 David Hammerton
26  * @see http://crazney.net/programs/itunes/alac.html
27  *
28  * Note: This decoder expects a 36-byte QuickTime atom to be
29  * passed through the extradata[_size] fields. This atom is tacked onto
30  * the end of an 'alac' stsd atom and has the following format:
31  *
32  * 32bit  atom size
33  * 32bit  tag                  ("alac")
34  * 32bit  tag version          (0)
35  * 32bit  samples per frame    (used when not set explicitly in the frames)
36  *  8bit  compatible version   (0)
37  *  8bit  sample size
38  *  8bit  history mult         (40)
39  *  8bit  initial history      (14)
40  *  8bit  kmodifier            (10)
41  *  8bit  channels
42  * 16bit  maxRun               (255)
43  * 32bit  max coded frame size (0 means unknown)
44  * 32bit  average bitrate      (0 means unknown)
45  * 32bit  samplerate
46  */
47
48
49 #include "avcodec.h"
50 #include "get_bits.h"
51 #include "bytestream.h"
52 #include "unary.h"
53 #include "mathops.h"
54
55 #define ALAC_EXTRADATA_SIZE 36
56 #define MAX_CHANNELS 2
57
58 typedef struct {
59
60     AVCodecContext *avctx;
61     AVFrame frame;
62     GetBitContext gb;
63
64     int numchannels;
65
66     /* buffers */
67     int32_t *predicterror_buffer[MAX_CHANNELS];
68
69     int32_t *outputsamples_buffer[MAX_CHANNELS];
70
71     int32_t *extra_bits_buffer[MAX_CHANNELS];
72
73     /* stuff from setinfo */
74     uint32_t setinfo_max_samples_per_frame; /* 0x1000 = 4096 */    /* max samples per frame? */
75     uint8_t setinfo_sample_size; /* 0x10 */
76     uint8_t setinfo_rice_historymult; /* 0x28 */
77     uint8_t setinfo_rice_initialhistory; /* 0x0a */
78     uint8_t setinfo_rice_kmodifier; /* 0x0e */
79     /* end setinfo stuff */
80
81     int extra_bits;                         /**< number of extra bits beyond 16-bit */
82 } ALACContext;
83
84 static inline int decode_scalar(GetBitContext *gb, int k, int limit, int readsamplesize){
85     /* read x - number of 1s before 0 represent the rice */
86     int x = get_unary_0_9(gb);
87
88     if (x > 8) { /* RICE THRESHOLD */
89         /* use alternative encoding */
90         x = get_bits(gb, readsamplesize);
91     } else {
92         if (k >= limit)
93             k = limit;
94
95         if (k != 1) {
96             int extrabits = show_bits(gb, k);
97
98             /* multiply x by 2^k - 1, as part of their strange algorithm */
99             x = (x << k) - x;
100
101             if (extrabits > 1) {
102                 x += extrabits - 1;
103                 skip_bits(gb, k);
104             } else
105                 skip_bits(gb, k - 1);
106         }
107     }
108     return x;
109 }
110
111 static int bastardized_rice_decompress(ALACContext *alac,
112                                  int32_t *output_buffer,
113                                  int output_size,
114                                  int readsamplesize, /* arg_10 */
115                                  int rice_initialhistory, /* arg424->b */
116                                  int rice_kmodifier, /* arg424->d */
117                                  int rice_historymult, /* arg424->c */
118                                  int rice_kmodifier_mask /* arg424->e */
119         )
120 {
121     int output_count;
122     unsigned int history = rice_initialhistory;
123     int sign_modifier = 0;
124
125     for (output_count = 0; output_count < output_size; output_count++) {
126         int32_t x;
127         int32_t x_modified;
128         int32_t final_val;
129
130         /* standard rice encoding */
131         int k; /* size of extra bits */
132
133         if(get_bits_left(&alac->gb) <= 0)
134             return -1;
135
136         /* read k, that is bits as is */
137         k = av_log2((history >> 9) + 3);
138         x= decode_scalar(&alac->gb, k, rice_kmodifier, readsamplesize);
139
140         x_modified = sign_modifier + x;
141         final_val = (x_modified + 1) / 2;
142         if (x_modified & 1) final_val *= -1;
143
144         output_buffer[output_count] = final_val;
145
146         sign_modifier = 0;
147
148         /* now update the history */
149         history += x_modified * rice_historymult
150                    - ((history * rice_historymult) >> 9);
151
152         if (x_modified > 0xffff)
153             history = 0xffff;
154
155         /* special case: there may be compressed blocks of 0 */
156         if ((history < 128) && (output_count+1 < output_size)) {
157             int k;
158             unsigned int block_size;
159
160             sign_modifier = 1;
161
162             k = 7 - av_log2(history) + ((history + 16) >> 6 /* / 64 */);
163
164             block_size= decode_scalar(&alac->gb, k, rice_kmodifier, 16);
165
166             if (block_size > 0) {
167                 if(block_size >= output_size - output_count){
168                     av_log(alac->avctx, AV_LOG_ERROR, "invalid zero block size of %d %d %d\n", block_size, output_size, output_count);
169                     block_size= output_size - output_count - 1;
170                 }
171                 memset(&output_buffer[output_count+1], 0, block_size * 4);
172                 output_count += block_size;
173             }
174
175             if (block_size > 0xffff)
176                 sign_modifier = 0;
177
178             history = 0;
179         }
180     }
181     return 0;
182 }
183
184 static inline int sign_only(int v)
185 {
186     return v ? FFSIGN(v) : 0;
187 }
188
189 static void predictor_decompress_fir_adapt(int32_t *error_buffer,
190                                            int32_t *buffer_out,
191                                            int output_size,
192                                            int readsamplesize,
193                                            int16_t *predictor_coef_table,
194                                            int predictor_coef_num,
195                                            int predictor_quantitization)
196 {
197     int i;
198
199     /* first sample always copies */
200     *buffer_out = *error_buffer;
201
202     if (!predictor_coef_num) {
203         if (output_size <= 1)
204             return;
205
206         memcpy(buffer_out+1, error_buffer+1, (output_size-1) * 4);
207         return;
208     }
209
210     if (predictor_coef_num == 0x1f) { /* 11111 - max value of predictor_coef_num */
211       /* second-best case scenario for fir decompression,
212        * error describes a small difference from the previous sample only
213        */
214         if (output_size <= 1)
215             return;
216         for (i = 0; i < output_size - 1; i++) {
217             int32_t prev_value;
218             int32_t error_value;
219
220             prev_value = buffer_out[i];
221             error_value = error_buffer[i+1];
222             buffer_out[i+1] =
223                 sign_extend((prev_value + error_value), readsamplesize);
224         }
225         return;
226     }
227
228     /* read warm-up samples */
229     if (predictor_coef_num > 0)
230         for (i = 0; i < predictor_coef_num; i++) {
231             int32_t val;
232
233             val = buffer_out[i] + error_buffer[i+1];
234             val = sign_extend(val, readsamplesize);
235             buffer_out[i+1] = val;
236         }
237
238     /* 4 and 8 are very common cases (the only ones i've seen). these
239      * should be unrolled and optimized
240      */
241
242     /* general case */
243     if (predictor_coef_num > 0) {
244         for (i = predictor_coef_num + 1; i < output_size; i++) {
245             int j;
246             int sum = 0;
247             int outval;
248             int error_val = error_buffer[i];
249
250             for (j = 0; j < predictor_coef_num; j++) {
251                 sum += (buffer_out[predictor_coef_num-j] - buffer_out[0]) *
252                        predictor_coef_table[j];
253             }
254
255             outval = (1 << (predictor_quantitization-1)) + sum;
256             outval = outval >> predictor_quantitization;
257             outval = outval + buffer_out[0] + error_val;
258             outval = sign_extend(outval, readsamplesize);
259
260             buffer_out[predictor_coef_num+1] = outval;
261
262             if (error_val > 0) {
263                 int predictor_num = predictor_coef_num - 1;
264
265                 while (predictor_num >= 0 && error_val > 0) {
266                     int val = buffer_out[0] - buffer_out[predictor_coef_num - predictor_num];
267                     int sign = sign_only(val);
268
269                     predictor_coef_table[predictor_num] -= sign;
270
271                     val *= sign; /* absolute value */
272
273                     error_val -= ((val >> predictor_quantitization) *
274                                   (predictor_coef_num - predictor_num));
275
276                     predictor_num--;
277                 }
278             } else if (error_val < 0) {
279                 int predictor_num = predictor_coef_num - 1;
280
281                 while (predictor_num >= 0 && error_val < 0) {
282                     int val = buffer_out[0] - buffer_out[predictor_coef_num - predictor_num];
283                     int sign = - sign_only(val);
284
285                     predictor_coef_table[predictor_num] -= sign;
286
287                     val *= sign; /* neg value */
288
289                     error_val -= ((val >> predictor_quantitization) *
290                                   (predictor_coef_num - predictor_num));
291
292                     predictor_num--;
293                 }
294             }
295
296             buffer_out++;
297         }
298     }
299 }
300
301 static void decorrelate_stereo(int32_t *buffer[MAX_CHANNELS],
302                                int numsamples, uint8_t interlacing_shift,
303                                uint8_t interlacing_leftweight)
304 {
305     int i;
306
307     for (i = 0; i < numsamples; i++) {
308         int32_t a, b;
309
310         a = buffer[0][i];
311         b = buffer[1][i];
312
313         a -= (b * interlacing_leftweight) >> interlacing_shift;
314         b += a;
315
316         buffer[0][i] = b;
317         buffer[1][i] = a;
318     }
319 }
320
321 static void append_extra_bits(int32_t *buffer[MAX_CHANNELS],
322                               int32_t *extra_bits_buffer[MAX_CHANNELS],
323                               int extra_bits, int numchannels, int numsamples)
324 {
325     int i, ch;
326
327     for (ch = 0; ch < numchannels; ch++)
328         for (i = 0; i < numsamples; i++)
329             buffer[ch][i] = (buffer[ch][i] << extra_bits) | extra_bits_buffer[ch][i];
330 }
331
332 static void interleave_stereo_16(int32_t *buffer[MAX_CHANNELS],
333                                  int16_t *buffer_out, int numsamples)
334 {
335     int i;
336
337     for (i = 0; i < numsamples; i++) {
338         *buffer_out++ = buffer[0][i];
339         *buffer_out++ = buffer[1][i];
340     }
341 }
342
343 static void interleave_stereo_24(int32_t *buffer[MAX_CHANNELS],
344                                  int32_t *buffer_out, int numsamples)
345 {
346     int i;
347
348     for (i = 0; i < numsamples; i++) {
349         *buffer_out++ = buffer[0][i] << 8;
350         *buffer_out++ = buffer[1][i] << 8;
351     }
352 }
353
354 static void interleave_stereo_32(int32_t *buffer[MAX_CHANNELS],
355                                  int32_t *buffer_out, int numsamples)
356 {
357     int i;
358
359     for (i = 0; i < numsamples; i++) {
360         *buffer_out++ = buffer[0][i];
361         *buffer_out++ = buffer[1][i];
362     }
363 }
364
365 static int alac_decode_frame(AVCodecContext *avctx, void *data,
366                              int *got_frame_ptr, AVPacket *avpkt)
367 {
368     const uint8_t *inbuffer = avpkt->data;
369     int input_buffer_size = avpkt->size;
370     ALACContext *alac = avctx->priv_data;
371
372     int channels;
373     unsigned int outputsamples;
374     int hassize;
375     unsigned int readsamplesize;
376     int isnotcompressed;
377     uint8_t interlacing_shift;
378     uint8_t interlacing_leftweight;
379     int i, ch, ret;
380
381     init_get_bits(&alac->gb, inbuffer, input_buffer_size * 8);
382
383     channels = get_bits(&alac->gb, 3) + 1;
384     if (channels != avctx->channels) {
385         av_log(avctx, AV_LOG_ERROR, "frame header channel count mismatch\n");
386         return AVERROR_INVALIDDATA;
387     }
388
389     /* 2^result = something to do with output waiting.
390      * perhaps matters if we read > 1 frame in a pass?
391      */
392     skip_bits(&alac->gb, 4);
393
394     skip_bits(&alac->gb, 12); /* unknown, skip 12 bits */
395
396     /* the output sample size is stored soon */
397     hassize = get_bits1(&alac->gb);
398
399     alac->extra_bits = get_bits(&alac->gb, 2) << 3;
400
401     /* whether the frame is compressed */
402     isnotcompressed = get_bits1(&alac->gb);
403
404     if (hassize) {
405         /* now read the number of samples as a 32bit integer */
406         outputsamples = get_bits_long(&alac->gb, 32);
407         if(outputsamples > alac->setinfo_max_samples_per_frame){
408             av_log(avctx, AV_LOG_ERROR, "outputsamples %d > %d\n", outputsamples, alac->setinfo_max_samples_per_frame);
409             return -1;
410         }
411     } else
412         outputsamples = alac->setinfo_max_samples_per_frame;
413
414     /* get output buffer */
415     if (outputsamples > INT32_MAX) {
416         av_log(avctx, AV_LOG_ERROR, "unsupported block size: %u\n", outputsamples);
417         return AVERROR_INVALIDDATA;
418     }
419     alac->frame.nb_samples = outputsamples;
420     if ((ret = avctx->get_buffer(avctx, &alac->frame)) < 0) {
421         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
422         return ret;
423     }
424
425     readsamplesize = alac->setinfo_sample_size - alac->extra_bits + channels - 1;
426     if (readsamplesize > MIN_CACHE_BITS) {
427         av_log(avctx, AV_LOG_ERROR, "readsamplesize too big (%d)\n", readsamplesize);
428         return -1;
429     }
430
431     if (!isnotcompressed) {
432         /* so it is compressed */
433         int16_t predictor_coef_table[MAX_CHANNELS][32];
434         int predictor_coef_num[MAX_CHANNELS];
435         int prediction_type[MAX_CHANNELS];
436         int prediction_quantitization[MAX_CHANNELS];
437         int ricemodifier[MAX_CHANNELS];
438
439         interlacing_shift = get_bits(&alac->gb, 8);
440         interlacing_leftweight = get_bits(&alac->gb, 8);
441
442         for (ch = 0; ch < channels; ch++) {
443             prediction_type[ch] = get_bits(&alac->gb, 4);
444             prediction_quantitization[ch] = get_bits(&alac->gb, 4);
445
446             ricemodifier[ch] = get_bits(&alac->gb, 3);
447             predictor_coef_num[ch] = get_bits(&alac->gb, 5);
448
449             /* read the predictor table */
450             for (i = 0; i < predictor_coef_num[ch]; i++)
451                 predictor_coef_table[ch][i] = (int16_t)get_bits(&alac->gb, 16);
452         }
453
454         if (alac->extra_bits) {
455             for (i = 0; i < outputsamples; i++) {
456                 if(get_bits_left(&alac->gb) <= 0)
457                     return -1;
458                 for (ch = 0; ch < channels; ch++)
459                     alac->extra_bits_buffer[ch][i] = get_bits(&alac->gb, alac->extra_bits);
460             }
461         }
462         for (ch = 0; ch < channels; ch++) {
463             int ret = bastardized_rice_decompress(alac,
464                                         alac->predicterror_buffer[ch],
465                                         outputsamples,
466                                         readsamplesize,
467                                         alac->setinfo_rice_initialhistory,
468                                         alac->setinfo_rice_kmodifier,
469                                         ricemodifier[ch] * alac->setinfo_rice_historymult / 4,
470                                         (1 << alac->setinfo_rice_kmodifier) - 1);
471             if(ret<0)
472                 return ret;
473
474             /* adaptive FIR filter */
475             if (prediction_type[ch] == 15) {
476                 /* Prediction type 15 runs the adaptive FIR twice.
477                  * The first pass uses the special-case coef_num = 31, while
478                  * the second pass uses the coefs from the bitstream.
479                  *
480                  * However, this prediction type is not currently used by the
481                  * reference encoder.
482                  */
483                 predictor_decompress_fir_adapt(alac->predicterror_buffer[ch],
484                                                alac->predicterror_buffer[ch],
485                                                outputsamples, readsamplesize,
486                                                NULL, 31, 0);
487             } else if (prediction_type[ch] > 0) {
488                 av_log(avctx, AV_LOG_WARNING, "unknown prediction type: %i\n",
489                        prediction_type[ch]);
490             }
491             predictor_decompress_fir_adapt(alac->predicterror_buffer[ch],
492                                            alac->outputsamples_buffer[ch],
493                                            outputsamples, readsamplesize,
494                                            predictor_coef_table[ch],
495                                            predictor_coef_num[ch],
496                                            prediction_quantitization[ch]);
497         }
498     } else {
499         /* not compressed, easy case */
500         for (i = 0; i < outputsamples; i++) {
501             if(get_bits_left(&alac->gb) <= 0)
502                 return -1;
503             for (ch = 0; ch < channels; ch++) {
504                 alac->outputsamples_buffer[ch][i] = get_sbits_long(&alac->gb,
505                                                                    alac->setinfo_sample_size);
506             }
507         }
508         alac->extra_bits = 0;
509         interlacing_shift = 0;
510         interlacing_leftweight = 0;
511     }
512     if (get_bits(&alac->gb, 3) != 7)
513         av_log(avctx, AV_LOG_ERROR, "Error : Wrong End Of Frame\n");
514
515     if (channels == 2 && interlacing_leftweight) {
516         decorrelate_stereo(alac->outputsamples_buffer, outputsamples,
517                            interlacing_shift, interlacing_leftweight);
518     }
519
520     if (alac->extra_bits) {
521         append_extra_bits(alac->outputsamples_buffer, alac->extra_bits_buffer,
522                           alac->extra_bits, alac->numchannels, outputsamples);
523     }
524
525     switch(alac->setinfo_sample_size) {
526     case 16:
527         if (channels == 2) {
528             interleave_stereo_16(alac->outputsamples_buffer,
529                                  (int16_t *)alac->frame.data[0], outputsamples);
530         } else {
531             int16_t *outbuffer = (int16_t *)alac->frame.data[0];
532             for (i = 0; i < outputsamples; i++) {
533                 outbuffer[i] = alac->outputsamples_buffer[0][i];
534             }
535         }
536         break;
537     case 24:
538         if (channels == 2) {
539             interleave_stereo_24(alac->outputsamples_buffer,
540                                  (int32_t *)alac->frame.data[0], outputsamples);
541         } else {
542             int32_t *outbuffer = (int32_t *)alac->frame.data[0];
543             for (i = 0; i < outputsamples; i++)
544                 outbuffer[i] = alac->outputsamples_buffer[0][i] << 8;
545         }
546         break;
547     case 32:
548         if (channels == 2) {
549             interleave_stereo_32(alac->outputsamples_buffer,
550                                  (int32_t *)alac->frame.data[0], outputsamples);
551         } else {
552             int32_t *outbuffer = (int32_t *)alac->frame.data[0];
553             for (i = 0; i < outputsamples; i++)
554                 outbuffer[i] = alac->outputsamples_buffer[0][i];
555         }
556         break;
557     }
558
559     if (input_buffer_size * 8 - get_bits_count(&alac->gb) > 8)
560         av_log(avctx, AV_LOG_ERROR, "Error : %d bits left\n", input_buffer_size * 8 - get_bits_count(&alac->gb));
561
562     *got_frame_ptr   = 1;
563     *(AVFrame *)data = alac->frame;
564
565     return input_buffer_size;
566 }
567
568 static av_cold int alac_decode_close(AVCodecContext *avctx)
569 {
570     ALACContext *alac = avctx->priv_data;
571
572     int ch;
573     for (ch = 0; ch < alac->numchannels; ch++) {
574         av_freep(&alac->predicterror_buffer[ch]);
575         av_freep(&alac->outputsamples_buffer[ch]);
576         av_freep(&alac->extra_bits_buffer[ch]);
577     }
578
579     return 0;
580 }
581
582 static int allocate_buffers(ALACContext *alac)
583 {
584     int ch;
585     for (ch = 0; ch < alac->numchannels; ch++) {
586         int buf_size = alac->setinfo_max_samples_per_frame * sizeof(int32_t);
587
588         FF_ALLOC_OR_GOTO(alac->avctx, alac->predicterror_buffer[ch],
589                          buf_size, buf_alloc_fail);
590
591         FF_ALLOC_OR_GOTO(alac->avctx, alac->outputsamples_buffer[ch],
592                          buf_size, buf_alloc_fail);
593
594         FF_ALLOC_OR_GOTO(alac->avctx, alac->extra_bits_buffer[ch],
595                          buf_size, buf_alloc_fail);
596     }
597     return 0;
598 buf_alloc_fail:
599     alac_decode_close(alac->avctx);
600     return AVERROR(ENOMEM);
601 }
602
603 static int alac_set_info(ALACContext *alac)
604 {
605     const unsigned char *ptr = alac->avctx->extradata;
606
607     ptr += 4; /* size */
608     ptr += 4; /* alac */
609     ptr += 4; /* version */
610
611     if(AV_RB32(ptr) >= UINT_MAX/4){
612         av_log(alac->avctx, AV_LOG_ERROR, "setinfo_max_samples_per_frame too large\n");
613         return -1;
614     }
615
616     /* buffer size / 2 ? */
617     alac->setinfo_max_samples_per_frame = bytestream_get_be32(&ptr);
618     ptr++;                          /* compatible version */
619     alac->setinfo_sample_size           = *ptr++;
620     alac->setinfo_rice_historymult      = *ptr++;
621     alac->setinfo_rice_initialhistory   = *ptr++;
622     alac->setinfo_rice_kmodifier        = *ptr++;
623     alac->numchannels                   = *ptr++;
624     bytestream_get_be16(&ptr);      /* maxRun */
625     bytestream_get_be32(&ptr);      /* max coded frame size */
626     bytestream_get_be32(&ptr);      /* average bitrate */
627     bytestream_get_be32(&ptr);      /* samplerate */
628
629     return 0;
630 }
631
632 static av_cold int alac_decode_init(AVCodecContext * avctx)
633 {
634     int ret;
635     ALACContext *alac = avctx->priv_data;
636     alac->avctx = avctx;
637
638     /* initialize from the extradata */
639     if (alac->avctx->extradata_size != ALAC_EXTRADATA_SIZE) {
640         av_log(avctx, AV_LOG_ERROR, "alac: expected %d extradata bytes\n",
641             ALAC_EXTRADATA_SIZE);
642         return -1;
643     }
644     if (alac_set_info(alac)) {
645         av_log(avctx, AV_LOG_ERROR, "alac: set_info failed\n");
646         return -1;
647     }
648
649     switch (alac->setinfo_sample_size) {
650     case 16: avctx->sample_fmt    = AV_SAMPLE_FMT_S16;
651              break;
652     case 32:
653     case 24: avctx->sample_fmt    = AV_SAMPLE_FMT_S32;
654              break;
655     default: av_log_ask_for_sample(avctx, "Sample depth %d is not supported.\n",
656                                    alac->setinfo_sample_size);
657              return AVERROR_PATCHWELCOME;
658     }
659
660     if (alac->numchannels < 1) {
661         av_log(avctx, AV_LOG_WARNING, "Invalid channel count\n");
662         alac->numchannels = avctx->channels;
663     } else {
664         if (alac->numchannels > MAX_CHANNELS)
665             alac->numchannels = avctx->channels;
666         else
667             avctx->channels = alac->numchannels;
668     }
669     if (avctx->channels > MAX_CHANNELS) {
670         av_log(avctx, AV_LOG_ERROR, "Unsupported channel count: %d\n",
671                avctx->channels);
672         return AVERROR_PATCHWELCOME;
673     }
674
675     if ((ret = allocate_buffers(alac)) < 0) {
676         av_log(avctx, AV_LOG_ERROR, "Error allocating buffers\n");
677         return ret;
678     }
679
680     avcodec_get_frame_defaults(&alac->frame);
681     avctx->coded_frame = &alac->frame;
682
683     return 0;
684 }
685
686 AVCodec ff_alac_decoder = {
687     .name           = "alac",
688     .type           = AVMEDIA_TYPE_AUDIO,
689     .id             = CODEC_ID_ALAC,
690     .priv_data_size = sizeof(ALACContext),
691     .init           = alac_decode_init,
692     .close          = alac_decode_close,
693     .decode         = alac_decode_frame,
694     .capabilities   = CODEC_CAP_DR1,
695     .long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"),
696 };