libavcodec/alac.c
Go to the documentation of this file.
00001 /*
00002  * ALAC (Apple Lossless Audio Codec) decoder
00003  * Copyright (c) 2005 David Hammerton
00004  *
00005  * This file is part of Libav.
00006  *
00007  * Libav is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * Libav is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with Libav; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00049 #include "avcodec.h"
00050 #include "get_bits.h"
00051 #include "bytestream.h"
00052 #include "unary.h"
00053 #include "mathops.h"
00054 
00055 #define ALAC_EXTRADATA_SIZE 36
00056 #define MAX_CHANNELS 2
00057 
00058 typedef struct {
00059 
00060     AVCodecContext *avctx;
00061     AVFrame frame;
00062     GetBitContext gb;
00063 
00064     int numchannels;
00065 
00066     /* buffers */
00067     int32_t *predicterror_buffer[MAX_CHANNELS];
00068 
00069     int32_t *outputsamples_buffer[MAX_CHANNELS];
00070 
00071     int32_t *extra_bits_buffer[MAX_CHANNELS];
00072 
00073     /* stuff from setinfo */
00074     uint32_t setinfo_max_samples_per_frame; /* 0x1000 = 4096 */    /* max samples per frame? */
00075     uint8_t setinfo_sample_size; /* 0x10 */
00076     uint8_t setinfo_rice_historymult; /* 0x28 */
00077     uint8_t setinfo_rice_initialhistory; /* 0x0a */
00078     uint8_t setinfo_rice_kmodifier; /* 0x0e */
00079     /* end setinfo stuff */
00080 
00081     int extra_bits;                         
00082 } ALACContext;
00083 
00084 static inline int decode_scalar(GetBitContext *gb, int k, int limit, int readsamplesize){
00085     /* read x - number of 1s before 0 represent the rice */
00086     int x = get_unary_0_9(gb);
00087 
00088     if (x > 8) { /* RICE THRESHOLD */
00089         /* use alternative encoding */
00090         x = get_bits(gb, readsamplesize);
00091     } else {
00092         if (k >= limit)
00093             k = limit;
00094 
00095         if (k != 1) {
00096             int extrabits = show_bits(gb, k);
00097 
00098             /* multiply x by 2^k - 1, as part of their strange algorithm */
00099             x = (x << k) - x;
00100 
00101             if (extrabits > 1) {
00102                 x += extrabits - 1;
00103                 skip_bits(gb, k);
00104             } else
00105                 skip_bits(gb, k - 1);
00106         }
00107     }
00108     return x;
00109 }
00110 
00111 static void bastardized_rice_decompress(ALACContext *alac,
00112                                  int32_t *output_buffer,
00113                                  int output_size,
00114                                  int readsamplesize, /* arg_10 */
00115                                  int rice_initialhistory, /* arg424->b */
00116                                  int rice_kmodifier, /* arg424->d */
00117                                  int rice_historymult, /* arg424->c */
00118                                  int rice_kmodifier_mask /* arg424->e */
00119         )
00120 {
00121     int output_count;
00122     unsigned int history = rice_initialhistory;
00123     int sign_modifier = 0;
00124 
00125     for (output_count = 0; output_count < output_size; output_count++) {
00126         int32_t x;
00127         int32_t x_modified;
00128         int32_t final_val;
00129 
00130         /* standard rice encoding */
00131         int k; /* size of extra bits */
00132 
00133         /* read k, that is bits as is */
00134         k = av_log2((history >> 9) + 3);
00135         x= decode_scalar(&alac->gb, k, rice_kmodifier, readsamplesize);
00136 
00137         x_modified = sign_modifier + x;
00138         final_val = (x_modified + 1) / 2;
00139         if (x_modified & 1) final_val *= -1;
00140 
00141         output_buffer[output_count] = final_val;
00142 
00143         sign_modifier = 0;
00144 
00145         /* now update the history */
00146         history += x_modified * rice_historymult
00147                    - ((history * rice_historymult) >> 9);
00148 
00149         if (x_modified > 0xffff)
00150             history = 0xffff;
00151 
00152         /* special case: there may be compressed blocks of 0 */
00153         if ((history < 128) && (output_count+1 < output_size)) {
00154             int k;
00155             unsigned int block_size;
00156 
00157             sign_modifier = 1;
00158 
00159             k = 7 - av_log2(history) + ((history + 16) >> 6 /* / 64 */);
00160 
00161             block_size= decode_scalar(&alac->gb, k, rice_kmodifier, 16);
00162 
00163             if (block_size > 0) {
00164                 if(block_size >= output_size - output_count){
00165                     av_log(alac->avctx, AV_LOG_ERROR, "invalid zero block size of %d %d %d\n", block_size, output_size, output_count);
00166                     block_size= output_size - output_count - 1;
00167                 }
00168                 memset(&output_buffer[output_count+1], 0, block_size * 4);
00169                 output_count += block_size;
00170             }
00171 
00172             if (block_size > 0xffff)
00173                 sign_modifier = 0;
00174 
00175             history = 0;
00176         }
00177     }
00178 }
00179 
00180 static inline int sign_only(int v)
00181 {
00182     return v ? FFSIGN(v) : 0;
00183 }
00184 
00185 static void predictor_decompress_fir_adapt(int32_t *error_buffer,
00186                                            int32_t *buffer_out,
00187                                            int output_size,
00188                                            int readsamplesize,
00189                                            int16_t *predictor_coef_table,
00190                                            int predictor_coef_num,
00191                                            int predictor_quantitization)
00192 {
00193     int i;
00194 
00195     /* first sample always copies */
00196     *buffer_out = *error_buffer;
00197 
00198     if (!predictor_coef_num) {
00199         if (output_size <= 1)
00200             return;
00201 
00202         memcpy(buffer_out+1, error_buffer+1, (output_size-1) * 4);
00203         return;
00204     }
00205 
00206     if (predictor_coef_num == 0x1f) { /* 11111 - max value of predictor_coef_num */
00207       /* second-best case scenario for fir decompression,
00208        * error describes a small difference from the previous sample only
00209        */
00210         if (output_size <= 1)
00211             return;
00212         for (i = 0; i < output_size - 1; i++) {
00213             int32_t prev_value;
00214             int32_t error_value;
00215 
00216             prev_value = buffer_out[i];
00217             error_value = error_buffer[i+1];
00218             buffer_out[i+1] =
00219                 sign_extend((prev_value + error_value), readsamplesize);
00220         }
00221         return;
00222     }
00223 
00224     /* read warm-up samples */
00225     if (predictor_coef_num > 0)
00226         for (i = 0; i < predictor_coef_num; i++) {
00227             int32_t val;
00228 
00229             val = buffer_out[i] + error_buffer[i+1];
00230             val = sign_extend(val, readsamplesize);
00231             buffer_out[i+1] = val;
00232         }
00233 
00234     /* 4 and 8 are very common cases (the only ones i've seen). these
00235      * should be unrolled and optimized
00236      */
00237 
00238     /* general case */
00239     if (predictor_coef_num > 0) {
00240         for (i = predictor_coef_num + 1; i < output_size; i++) {
00241             int j;
00242             int sum = 0;
00243             int outval;
00244             int error_val = error_buffer[i];
00245 
00246             for (j = 0; j < predictor_coef_num; j++) {
00247                 sum += (buffer_out[predictor_coef_num-j] - buffer_out[0]) *
00248                        predictor_coef_table[j];
00249             }
00250 
00251             outval = (1 << (predictor_quantitization-1)) + sum;
00252             outval = outval >> predictor_quantitization;
00253             outval = outval + buffer_out[0] + error_val;
00254             outval = sign_extend(outval, readsamplesize);
00255 
00256             buffer_out[predictor_coef_num+1] = outval;
00257 
00258             if (error_val > 0) {
00259                 int predictor_num = predictor_coef_num - 1;
00260 
00261                 while (predictor_num >= 0 && error_val > 0) {
00262                     int val = buffer_out[0] - buffer_out[predictor_coef_num - predictor_num];
00263                     int sign = sign_only(val);
00264 
00265                     predictor_coef_table[predictor_num] -= sign;
00266 
00267                     val *= sign; /* absolute value */
00268 
00269                     error_val -= ((val >> predictor_quantitization) *
00270                                   (predictor_coef_num - predictor_num));
00271 
00272                     predictor_num--;
00273                 }
00274             } else if (error_val < 0) {
00275                 int predictor_num = predictor_coef_num - 1;
00276 
00277                 while (predictor_num >= 0 && error_val < 0) {
00278                     int val = buffer_out[0] - buffer_out[predictor_coef_num - predictor_num];
00279                     int sign = - sign_only(val);
00280 
00281                     predictor_coef_table[predictor_num] -= sign;
00282 
00283                     val *= sign; /* neg value */
00284 
00285                     error_val -= ((val >> predictor_quantitization) *
00286                                   (predictor_coef_num - predictor_num));
00287 
00288                     predictor_num--;
00289                 }
00290             }
00291 
00292             buffer_out++;
00293         }
00294     }
00295 }
00296 
00297 static void decorrelate_stereo(int32_t *buffer[MAX_CHANNELS],
00298                                int numsamples, uint8_t interlacing_shift,
00299                                uint8_t interlacing_leftweight)
00300 {
00301     int i;
00302 
00303     for (i = 0; i < numsamples; i++) {
00304         int32_t a, b;
00305 
00306         a = buffer[0][i];
00307         b = buffer[1][i];
00308 
00309         a -= (b * interlacing_leftweight) >> interlacing_shift;
00310         b += a;
00311 
00312         buffer[0][i] = b;
00313         buffer[1][i] = a;
00314     }
00315 }
00316 
00317 static void append_extra_bits(int32_t *buffer[MAX_CHANNELS],
00318                               int32_t *extra_bits_buffer[MAX_CHANNELS],
00319                               int extra_bits, int numchannels, int numsamples)
00320 {
00321     int i, ch;
00322 
00323     for (ch = 0; ch < numchannels; ch++)
00324         for (i = 0; i < numsamples; i++)
00325             buffer[ch][i] = (buffer[ch][i] << extra_bits) | extra_bits_buffer[ch][i];
00326 }
00327 
00328 static void interleave_stereo_16(int32_t *buffer[MAX_CHANNELS],
00329                                  int16_t *buffer_out, int numsamples)
00330 {
00331     int i;
00332 
00333     for (i = 0; i < numsamples; i++) {
00334         *buffer_out++ = buffer[0][i];
00335         *buffer_out++ = buffer[1][i];
00336     }
00337 }
00338 
00339 static void interleave_stereo_24(int32_t *buffer[MAX_CHANNELS],
00340                                  int32_t *buffer_out, int numsamples)
00341 {
00342     int i;
00343 
00344     for (i = 0; i < numsamples; i++) {
00345         *buffer_out++ = buffer[0][i] << 8;
00346         *buffer_out++ = buffer[1][i] << 8;
00347     }
00348 }
00349 
00350 static int alac_decode_frame(AVCodecContext *avctx, void *data,
00351                              int *got_frame_ptr, AVPacket *avpkt)
00352 {
00353     const uint8_t *inbuffer = avpkt->data;
00354     int input_buffer_size = avpkt->size;
00355     ALACContext *alac = avctx->priv_data;
00356 
00357     int channels;
00358     unsigned int outputsamples;
00359     int hassize;
00360     unsigned int readsamplesize;
00361     int isnotcompressed;
00362     uint8_t interlacing_shift;
00363     uint8_t interlacing_leftweight;
00364     int i, ch, ret;
00365 
00366     init_get_bits(&alac->gb, inbuffer, input_buffer_size * 8);
00367 
00368     channels = get_bits(&alac->gb, 3) + 1;
00369     if (channels != avctx->channels) {
00370         av_log(avctx, AV_LOG_ERROR, "frame header channel count mismatch\n");
00371         return AVERROR_INVALIDDATA;
00372     }
00373 
00374     /* 2^result = something to do with output waiting.
00375      * perhaps matters if we read > 1 frame in a pass?
00376      */
00377     skip_bits(&alac->gb, 4);
00378 
00379     skip_bits(&alac->gb, 12); /* unknown, skip 12 bits */
00380 
00381     /* the output sample size is stored soon */
00382     hassize = get_bits1(&alac->gb);
00383 
00384     alac->extra_bits = get_bits(&alac->gb, 2) << 3;
00385 
00386     /* whether the frame is compressed */
00387     isnotcompressed = get_bits1(&alac->gb);
00388 
00389     if (hassize) {
00390         /* now read the number of samples as a 32bit integer */
00391         outputsamples = get_bits_long(&alac->gb, 32);
00392         if(outputsamples > alac->setinfo_max_samples_per_frame){
00393             av_log(avctx, AV_LOG_ERROR, "outputsamples %d > %d\n", outputsamples, alac->setinfo_max_samples_per_frame);
00394             return -1;
00395         }
00396     } else
00397         outputsamples = alac->setinfo_max_samples_per_frame;
00398 
00399     /* get output buffer */
00400     if (outputsamples > INT32_MAX) {
00401         av_log(avctx, AV_LOG_ERROR, "unsupported block size: %u\n", outputsamples);
00402         return AVERROR_INVALIDDATA;
00403     }
00404     alac->frame.nb_samples = outputsamples;
00405     if ((ret = avctx->get_buffer(avctx, &alac->frame)) < 0) {
00406         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
00407         return ret;
00408     }
00409 
00410     readsamplesize = alac->setinfo_sample_size - alac->extra_bits + channels - 1;
00411     if (readsamplesize > MIN_CACHE_BITS) {
00412         av_log(avctx, AV_LOG_ERROR, "readsamplesize too big (%d)\n", readsamplesize);
00413         return -1;
00414     }
00415 
00416     if (!isnotcompressed) {
00417         /* so it is compressed */
00418         int16_t predictor_coef_table[MAX_CHANNELS][32];
00419         int predictor_coef_num[MAX_CHANNELS];
00420         int prediction_type[MAX_CHANNELS];
00421         int prediction_quantitization[MAX_CHANNELS];
00422         int ricemodifier[MAX_CHANNELS];
00423 
00424         interlacing_shift = get_bits(&alac->gb, 8);
00425         interlacing_leftweight = get_bits(&alac->gb, 8);
00426 
00427         for (ch = 0; ch < channels; ch++) {
00428             prediction_type[ch] = get_bits(&alac->gb, 4);
00429             prediction_quantitization[ch] = get_bits(&alac->gb, 4);
00430 
00431             ricemodifier[ch] = get_bits(&alac->gb, 3);
00432             predictor_coef_num[ch] = get_bits(&alac->gb, 5);
00433 
00434             /* read the predictor table */
00435             for (i = 0; i < predictor_coef_num[ch]; i++)
00436                 predictor_coef_table[ch][i] = (int16_t)get_bits(&alac->gb, 16);
00437         }
00438 
00439         if (alac->extra_bits) {
00440             for (i = 0; i < outputsamples; i++) {
00441                 for (ch = 0; ch < channels; ch++)
00442                     alac->extra_bits_buffer[ch][i] = get_bits(&alac->gb, alac->extra_bits);
00443             }
00444         }
00445         for (ch = 0; ch < channels; ch++) {
00446             bastardized_rice_decompress(alac,
00447                                         alac->predicterror_buffer[ch],
00448                                         outputsamples,
00449                                         readsamplesize,
00450                                         alac->setinfo_rice_initialhistory,
00451                                         alac->setinfo_rice_kmodifier,
00452                                         ricemodifier[ch] * alac->setinfo_rice_historymult / 4,
00453                                         (1 << alac->setinfo_rice_kmodifier) - 1);
00454 
00455             /* adaptive FIR filter */
00456             if (prediction_type[ch] == 15) {
00457                 /* Prediction type 15 runs the adaptive FIR twice.
00458                  * The first pass uses the special-case coef_num = 31, while
00459                  * the second pass uses the coefs from the bitstream.
00460                  *
00461                  * However, this prediction type is not currently used by the
00462                  * reference encoder.
00463                  */
00464                 predictor_decompress_fir_adapt(alac->predicterror_buffer[ch],
00465                                                alac->predicterror_buffer[ch],
00466                                                outputsamples, readsamplesize,
00467                                                NULL, 31, 0);
00468             } else if (prediction_type[ch] > 0) {
00469                 av_log(avctx, AV_LOG_WARNING, "unknown prediction type: %i\n",
00470                        prediction_type[ch]);
00471             }
00472             predictor_decompress_fir_adapt(alac->predicterror_buffer[ch],
00473                                            alac->outputsamples_buffer[ch],
00474                                            outputsamples, readsamplesize,
00475                                            predictor_coef_table[ch],
00476                                            predictor_coef_num[ch],
00477                                            prediction_quantitization[ch]);
00478         }
00479     } else {
00480         /* not compressed, easy case */
00481         for (i = 0; i < outputsamples; i++) {
00482             for (ch = 0; ch < channels; ch++) {
00483                 alac->outputsamples_buffer[ch][i] = get_sbits_long(&alac->gb,
00484                                                                    alac->setinfo_sample_size);
00485             }
00486         }
00487         alac->extra_bits = 0;
00488         interlacing_shift = 0;
00489         interlacing_leftweight = 0;
00490     }
00491     if (get_bits(&alac->gb, 3) != 7)
00492         av_log(avctx, AV_LOG_ERROR, "Error : Wrong End Of Frame\n");
00493 
00494     if (channels == 2 && interlacing_leftweight) {
00495         decorrelate_stereo(alac->outputsamples_buffer, outputsamples,
00496                            interlacing_shift, interlacing_leftweight);
00497     }
00498 
00499     if (alac->extra_bits) {
00500         append_extra_bits(alac->outputsamples_buffer, alac->extra_bits_buffer,
00501                           alac->extra_bits, alac->numchannels, outputsamples);
00502     }
00503 
00504     switch(alac->setinfo_sample_size) {
00505     case 16:
00506         if (channels == 2) {
00507             interleave_stereo_16(alac->outputsamples_buffer,
00508                                  (int16_t *)alac->frame.data[0], outputsamples);
00509         } else {
00510             int16_t *outbuffer = (int16_t *)alac->frame.data[0];
00511             for (i = 0; i < outputsamples; i++) {
00512                 outbuffer[i] = alac->outputsamples_buffer[0][i];
00513             }
00514         }
00515         break;
00516     case 24:
00517         if (channels == 2) {
00518             interleave_stereo_24(alac->outputsamples_buffer,
00519                                  (int32_t *)alac->frame.data[0], outputsamples);
00520         } else {
00521             int32_t *outbuffer = (int32_t *)alac->frame.data[0];
00522             for (i = 0; i < outputsamples; i++)
00523                 outbuffer[i] = alac->outputsamples_buffer[0][i] << 8;
00524         }
00525         break;
00526     }
00527 
00528     if (input_buffer_size * 8 - get_bits_count(&alac->gb) > 8)
00529         av_log(avctx, AV_LOG_ERROR, "Error : %d bits left\n", input_buffer_size * 8 - get_bits_count(&alac->gb));
00530 
00531     *got_frame_ptr   = 1;
00532     *(AVFrame *)data = alac->frame;
00533 
00534     return input_buffer_size;
00535 }
00536 
00537 static av_cold int alac_decode_close(AVCodecContext *avctx)
00538 {
00539     ALACContext *alac = avctx->priv_data;
00540 
00541     int ch;
00542     for (ch = 0; ch < alac->numchannels; ch++) {
00543         av_freep(&alac->predicterror_buffer[ch]);
00544         av_freep(&alac->outputsamples_buffer[ch]);
00545         av_freep(&alac->extra_bits_buffer[ch]);
00546     }
00547 
00548     return 0;
00549 }
00550 
00551 static int allocate_buffers(ALACContext *alac)
00552 {
00553     int ch;
00554     for (ch = 0; ch < alac->numchannels; ch++) {
00555         int buf_size = alac->setinfo_max_samples_per_frame * sizeof(int32_t);
00556 
00557         FF_ALLOC_OR_GOTO(alac->avctx, alac->predicterror_buffer[ch],
00558                          buf_size, buf_alloc_fail);
00559 
00560         FF_ALLOC_OR_GOTO(alac->avctx, alac->outputsamples_buffer[ch],
00561                          buf_size, buf_alloc_fail);
00562 
00563         FF_ALLOC_OR_GOTO(alac->avctx, alac->extra_bits_buffer[ch],
00564                          buf_size, buf_alloc_fail);
00565     }
00566     return 0;
00567 buf_alloc_fail:
00568     alac_decode_close(alac->avctx);
00569     return AVERROR(ENOMEM);
00570 }
00571 
00572 static int alac_set_info(ALACContext *alac)
00573 {
00574     const unsigned char *ptr = alac->avctx->extradata;
00575 
00576     ptr += 4; /* size */
00577     ptr += 4; /* alac */
00578     ptr += 4; /* version */
00579 
00580     if(AV_RB32(ptr) >= UINT_MAX/4){
00581         av_log(alac->avctx, AV_LOG_ERROR, "setinfo_max_samples_per_frame too large\n");
00582         return -1;
00583     }
00584 
00585     /* buffer size / 2 ? */
00586     alac->setinfo_max_samples_per_frame = bytestream_get_be32(&ptr);
00587     if (!alac->setinfo_max_samples_per_frame ||
00588         alac->setinfo_max_samples_per_frame > INT_MAX / sizeof(int32_t)) {
00589         av_log(alac->avctx, AV_LOG_ERROR, "max samples per frame invalid: %u\n",
00590                alac->setinfo_max_samples_per_frame);
00591         return AVERROR_INVALIDDATA;
00592     }
00593     ptr++;                          /* compatible version */
00594     alac->setinfo_sample_size           = *ptr++;
00595     alac->setinfo_rice_historymult      = *ptr++;
00596     alac->setinfo_rice_initialhistory   = *ptr++;
00597     alac->setinfo_rice_kmodifier        = *ptr++;
00598     alac->numchannels                   = *ptr++;
00599     bytestream_get_be16(&ptr);      /* maxRun */
00600     bytestream_get_be32(&ptr);      /* max coded frame size */
00601     bytestream_get_be32(&ptr);      /* average bitrate */
00602     bytestream_get_be32(&ptr);      /* samplerate */
00603 
00604     return 0;
00605 }
00606 
00607 static av_cold int alac_decode_init(AVCodecContext * avctx)
00608 {
00609     int ret;
00610     ALACContext *alac = avctx->priv_data;
00611     alac->avctx = avctx;
00612 
00613     /* initialize from the extradata */
00614     if (alac->avctx->extradata_size < ALAC_EXTRADATA_SIZE) {
00615         av_log(avctx, AV_LOG_ERROR, "alac: extradata is too small\n");
00616         return AVERROR_INVALIDDATA;
00617     }
00618     if (alac_set_info(alac)) {
00619         av_log(avctx, AV_LOG_ERROR, "alac: set_info failed\n");
00620         return -1;
00621     }
00622 
00623     switch (alac->setinfo_sample_size) {
00624     case 16: avctx->sample_fmt    = AV_SAMPLE_FMT_S16;
00625              break;
00626     case 24: avctx->sample_fmt    = AV_SAMPLE_FMT_S32;
00627              break;
00628     default: av_log_ask_for_sample(avctx, "Sample depth %d is not supported.\n",
00629                                    alac->setinfo_sample_size);
00630              return AVERROR_PATCHWELCOME;
00631     }
00632 
00633     if (alac->numchannels < 1) {
00634         av_log(avctx, AV_LOG_WARNING, "Invalid channel count\n");
00635         alac->numchannels = avctx->channels;
00636     } else {
00637         if (alac->numchannels > MAX_CHANNELS)
00638             alac->numchannels = avctx->channels;
00639         else
00640             avctx->channels = alac->numchannels;
00641     }
00642     if (avctx->channels > MAX_CHANNELS) {
00643         av_log(avctx, AV_LOG_ERROR, "Unsupported channel count: %d\n",
00644                avctx->channels);
00645         return AVERROR_PATCHWELCOME;
00646     }
00647 
00648     if ((ret = allocate_buffers(alac)) < 0) {
00649         av_log(avctx, AV_LOG_ERROR, "Error allocating buffers\n");
00650         return ret;
00651     }
00652 
00653     avcodec_get_frame_defaults(&alac->frame);
00654     avctx->coded_frame = &alac->frame;
00655 
00656     return 0;
00657 }
00658 
00659 AVCodec ff_alac_decoder = {
00660     .name           = "alac",
00661     .type           = AVMEDIA_TYPE_AUDIO,
00662     .id             = CODEC_ID_ALAC,
00663     .priv_data_size = sizeof(ALACContext),
00664     .init           = alac_decode_init,
00665     .close          = alac_decode_close,
00666     .decode         = alac_decode_frame,
00667     .capabilities   = CODEC_CAP_DR1,
00668     .long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"),
00669 };