• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

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

Generated on Fri Sep 16 2011 17:17:33 for FFmpeg by  doxygen 1.7.1