static int alac_decode_frame(AVCodecContext *avctx,

                             void *outbuffer, int *outputsize,

                             AVPacket *avpkt)

{

    const uint8_t *inbuffer = avpkt->data;

    int input_buffer_size = avpkt->size;

    ALACContext *alac = avctx->priv_data;



    int channels;

    unsigned int outputsamples;

    int hassize;

    unsigned int readsamplesize;

    int isnotcompressed;

    uint8_t interlacing_shift;

    uint8_t interlacing_leftweight;



    /* short-circuit null buffers */

    if (!inbuffer || !input_buffer_size)

        return input_buffer_size;



    /* initialize from the extradata */

    if (!alac->context_initialized) {

        if (alac->avctx->extradata_size != ALAC_EXTRADATA_SIZE) {

            av_log(avctx, AV_LOG_ERROR, "alac: expected %d extradata bytes\n",

                ALAC_EXTRADATA_SIZE);

            return input_buffer_size;

        }

        if (alac_set_info(alac)) {

            av_log(avctx, AV_LOG_ERROR, "alac: set_info failed\n");

            return input_buffer_size;

        }

        alac->context_initialized = 1;

    }



    init_get_bits(&alac->gb, inbuffer, input_buffer_size * 8);



    channels = get_bits(&alac->gb, 3) + 1;

    if (channels > MAX_CHANNELS) {

        av_log(avctx, AV_LOG_ERROR, "channels > %d not supported\n",

               MAX_CHANNELS);

        return input_buffer_size;

    }



    /* 2^result = something to do with output waiting.

     * perhaps matters if we read > 1 frame in a pass?

     */

    skip_bits(&alac->gb, 4);



    skip_bits(&alac->gb, 12); /* unknown, skip 12 bits */



    /* the output sample size is stored soon */

    hassize = get_bits1(&alac->gb);



    alac->wasted_bits = get_bits(&alac->gb, 2) << 3;



    /* whether the frame is compressed */

    isnotcompressed = get_bits1(&alac->gb);



    if (hassize) {

        /* now read the number of samples as a 32bit integer */

        outputsamples = get_bits_long(&alac->gb, 32);

        if(outputsamples > alac->setinfo_max_samples_per_frame){

            av_log(avctx, AV_LOG_ERROR, "outputsamples %d > %d\n", outputsamples, alac->setinfo_max_samples_per_frame);

            return -1;

        }

    } else

        outputsamples = alac->setinfo_max_samples_per_frame;



    switch (alac->setinfo_sample_size) {

    case 16: avctx->sample_fmt    = SAMPLE_FMT_S16;

             alac->bytespersample = channels << 1;

             break;

    case 24: avctx->sample_fmt    = SAMPLE_FMT_S32;

             alac->bytespersample = channels << 2;

             break;

    default: av_log(avctx, AV_LOG_ERROR, "Sample depth %d is not supported.\n",

                    alac->setinfo_sample_size);

             return -1;

    }



    if(outputsamples > *outputsize / alac->bytespersample){

        av_log(avctx, AV_LOG_ERROR, "sample buffer too small\n");

        return -1;

    }



    *outputsize = outputsamples * alac->bytespersample;

    readsamplesize = alac->setinfo_sample_size - (alac->wasted_bits) + channels - 1;

    if (readsamplesize > MIN_CACHE_BITS) {

        av_log(avctx, AV_LOG_ERROR, "readsamplesize too big (%d)\n", readsamplesize);

        return -1;

    }



    if (!isnotcompressed) {

        /* so it is compressed */

        int16_t predictor_coef_table[MAX_CHANNELS][32];

        int predictor_coef_num[MAX_CHANNELS];

        int prediction_type[MAX_CHANNELS];

        int prediction_quantitization[MAX_CHANNELS];

        int ricemodifier[MAX_CHANNELS];

        int i, chan;



        interlacing_shift = get_bits(&alac->gb, 8);

        interlacing_leftweight = get_bits(&alac->gb, 8);



        for (chan = 0; chan < channels; chan++) {

            prediction_type[chan] = get_bits(&alac->gb, 4);

            prediction_quantitization[chan] = get_bits(&alac->gb, 4);



            ricemodifier[chan] = get_bits(&alac->gb, 3);

            predictor_coef_num[chan] = get_bits(&alac->gb, 5);



            /* read the predictor table */

            for (i = 0; i < predictor_coef_num[chan]; i++)

                predictor_coef_table[chan][i] = (int16_t)get_bits(&alac->gb, 16);

        }



        if (alac->wasted_bits) {

            int i, ch;

            for (i = 0; i < outputsamples; i++) {

                for (ch = 0; ch < channels; ch++)

                    alac->wasted_bits_buffer[ch][i] = get_bits(&alac->gb, alac->wasted_bits);

            }

        }

        for (chan = 0; chan < channels; chan++) {

            bastardized_rice_decompress(alac,

                                        alac->predicterror_buffer[chan],

                                        outputsamples,

                                        readsamplesize,

                                        alac->setinfo_rice_initialhistory,

                                        alac->setinfo_rice_kmodifier,

                                        ricemodifier[chan] * alac->setinfo_rice_historymult / 4,

                                        (1 << alac->setinfo_rice_kmodifier) - 1);



            if (prediction_type[chan] == 0) {

                /* adaptive fir */

                predictor_decompress_fir_adapt(alac->predicterror_buffer[chan],

                                               alac->outputsamples_buffer[chan],

                                               outputsamples,

                                               readsamplesize,

                                               predictor_coef_table[chan],

                                               predictor_coef_num[chan],

                                               prediction_quantitization[chan]);

            } else {

                av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type[chan]);

                /* I think the only other prediction type (or perhaps this is

                 * just a boolean?) runs adaptive fir twice.. like:

                 * predictor_decompress_fir_adapt(predictor_error, tempout, ...)

                 * predictor_decompress_fir_adapt(predictor_error, outputsamples ...)

                 * little strange..

                 */

            }

        }

    } else {

        /* not compressed, easy case */

        int i, chan;

        if (alac->setinfo_sample_size <= 16) {

        for (i = 0; i < outputsamples; i++)

            for (chan = 0; chan < channels; chan++) {

                int32_t audiobits;



                audiobits = get_sbits_long(&alac->gb, alac->setinfo_sample_size);



                alac->outputsamples_buffer[chan][i] = audiobits;

            }

        } else {

            for (i = 0; i < outputsamples; i++) {

                for (chan = 0; chan < channels; chan++) {

                    alac->outputsamples_buffer[chan][i] = get_bits(&alac->gb,

                                                          alac->setinfo_sample_size);

                    alac->outputsamples_buffer[chan][i] = sign_extend(alac->outputsamples_buffer[chan][i],

                                                                      alac->setinfo_sample_size);

                }

            }

        }

        alac->wasted_bits = 0;

        interlacing_shift = 0;

        interlacing_leftweight = 0;

    }

    if (get_bits(&alac->gb, 3) != 7)

        av_log(avctx, AV_LOG_ERROR, "Error : Wrong End Of Frame\n");



    switch(alac->setinfo_sample_size) {

    case 16:

        if (channels == 2) {

            reconstruct_stereo_16(alac->outputsamples_buffer,

                                  (int16_t*)outbuffer,

                                  alac->numchannels,

                                  outputsamples,

                                  interlacing_shift,

                                  interlacing_leftweight);

        } else {

            int i;

            for (i = 0; i < outputsamples; i++) {

                ((int16_t*)outbuffer)[i] = alac->outputsamples_buffer[0][i];

            }

        }

        break;

    case 24:

        if (channels == 2) {

            decorrelate_stereo_24(alac->outputsamples_buffer,

                                  outbuffer,

                                  alac->wasted_bits_buffer,

                                  alac->wasted_bits,

                                  alac->numchannels,

                                  outputsamples,

                                  interlacing_shift,

                                  interlacing_leftweight);

        } else {

            int i;

            for (i = 0; i < outputsamples; i++)

                ((int32_t *)outbuffer)[i] = alac->outputsamples_buffer[0][i] << 8;

        }

        break;

    }



    if (input_buffer_size * 8 - get_bits_count(&alac->gb) > 8)

        av_log(avctx, AV_LOG_ERROR, "Error : %d bits left\n", input_buffer_size * 8 - get_bits_count(&alac->gb));



    return input_buffer_size;

}

static int alac_decode_frame(AVCodecContext *avctx,

                             void *outbuffer, int *outputsize,

                             AVPacket *avpkt)

{

    const uint8_t *inbuffer = avpkt->data;

    int input_buffer_size = avpkt->size;

    ALACContext *alac = avctx->priv_data;



    int channels;

    unsigned int outputsamples;

    int hassize;

    unsigned int readsamplesize;

    int isnotcompressed;

    uint8_t interlacing_shift;

    uint8_t interlacing_leftweight;



    

    if (!inbuffer || !input_buffer_size)

        return input_buffer_size;



    

    if (!alac->context_initialized) {

        if (alac->avctx->extradata_size != ALAC_EXTRADATA_SIZE) {

            av_log(avctx, AV_LOG_ERROR, "alac: expected %d extradata bytes\n",

                ALAC_EXTRADATA_SIZE);

            return input_buffer_size;

        }

        if (alac_set_info(alac)) {

            av_log(avctx, AV_LOG_ERROR, "alac: set_info failed\n");

            return input_buffer_size;

        }

        alac->context_initialized = 1;

    }



    init_get_bits(&alac->gb, inbuffer, input_buffer_size * 8);



    channels = get_bits(&alac->gb, 3) + 1;

    if (channels > MAX_CHANNELS) {

        av_log(avctx, AV_LOG_ERROR, "channels > %d not supported\n",

               MAX_CHANNELS);

        return input_buffer_size;

    }



    





    skip_bits(&alac->gb, 4);



    skip_bits(&alac->gb, 12); 



    

    hassize = get_bits1(&alac->gb);



    alac->wasted_bits = get_bits(&alac->gb, 2) << 3;



    

    isnotcompressed = get_bits1(&alac->gb);



    if (hassize) {

        

        outputsamples = get_bits_long(&alac->gb, 32);

        if(outputsamples > alac->setinfo_max_samples_per_frame){

            av_log(avctx, AV_LOG_ERROR, "outputsamples %d > %d\n", outputsamples, alac->setinfo_max_samples_per_frame);

            return -1;

        }

    } else

        outputsamples = alac->setinfo_max_samples_per_frame;



    switch (alac->setinfo_sample_size) {

    case 16: avctx->sample_fmt    = SAMPLE_FMT_S16;

             alac->bytespersample = channels << 1;

             break;

    case 24: avctx->sample_fmt    = SAMPLE_FMT_S32;

             alac->bytespersample = channels << 2;

             break;

    default: av_log(avctx, AV_LOG_ERROR, "Sample depth %d is not supported.\n",

                    alac->setinfo_sample_size);

             return -1;

    }



    if(outputsamples > *outputsize / alac->bytespersample){

        av_log(avctx, AV_LOG_ERROR, "sample buffer too small\n");

        return -1;

    }



    *outputsize = outputsamples * alac->bytespersample;

    readsamplesize = alac->setinfo_sample_size - (alac->wasted_bits) + channels - 1;

    if (readsamplesize > MIN_CACHE_BITS) {

        av_log(avctx, AV_LOG_ERROR, "readsamplesize too big (%d)\n", readsamplesize);

        return -1;

    }



    if (!isnotcompressed) {

        

        int16_t predictor_coef_table[MAX_CHANNELS][32];

        int predictor_coef_num[MAX_CHANNELS];

        int prediction_type[MAX_CHANNELS];

        int prediction_quantitization[MAX_CHANNELS];

        int ricemodifier[MAX_CHANNELS];

        int i, chan;



        interlacing_shift = get_bits(&alac->gb, 8);

        interlacing_leftweight = get_bits(&alac->gb, 8);



        for (chan = 0; chan < channels; chan++) {

            prediction_type[chan] = get_bits(&alac->gb, 4);

            prediction_quantitization[chan] = get_bits(&alac->gb, 4);



            ricemodifier[chan] = get_bits(&alac->gb, 3);

            predictor_coef_num[chan] = get_bits(&alac->gb, 5);



            

            for (i = 0; i < predictor_coef_num[chan]; i++)

                predictor_coef_table[chan][i] = (int16_t)get_bits(&alac->gb, 16);

        }



        if (alac->wasted_bits) {

            int i, ch;

            for (i = 0; i < outputsamples; i++) {

                for (ch = 0; ch < channels; ch++)

                    alac->wasted_bits_buffer[ch][i] = get_bits(&alac->gb, alac->wasted_bits);

            }

        }

        for (chan = 0; chan < channels; chan++) {

            bastardized_rice_decompress(alac,

                                        alac->predicterror_buffer[chan],

                                        outputsamples,

                                        readsamplesize,

                                        alac->setinfo_rice_initialhistory,

                                        alac->setinfo_rice_kmodifier,

                                        ricemodifier[chan] * alac->setinfo_rice_historymult / 4,

                                        (1 << alac->setinfo_rice_kmodifier) - 1);



            if (prediction_type[chan] == 0) {

                

                predictor_decompress_fir_adapt(alac->predicterror_buffer[chan],

                                               alac->outputsamples_buffer[chan],

                                               outputsamples,

                                               readsamplesize,

                                               predictor_coef_table[chan],

                                               predictor_coef_num[chan],

                                               prediction_quantitization[chan]);

            } else {

                av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type[chan]);

                











            }

        }

    } else {

        

        int i, chan;

        if (alac->setinfo_sample_size <= 16) {

        for (i = 0; i < outputsamples; i++)

            for (chan = 0; chan < channels; chan++) {

                int32_t audiobits;



                audiobits = get_sbits_long(&alac->gb, alac->setinfo_sample_size);



                alac->outputsamples_buffer[chan][i] = audiobits;

            }

        } else {

            for (i = 0; i < outputsamples; i++) {

                for (chan = 0; chan < channels; chan++) {

                    alac->outputsamples_buffer[chan][i] = get_bits(&alac->gb,

                                                          alac->setinfo_sample_size);

                    alac->outputsamples_buffer[chan][i] = sign_extend(alac->outputsamples_buffer[chan][i],

                                                                      alac->setinfo_sample_size);

                }

            }

        }

        alac->wasted_bits = 0;

        interlacing_shift = 0;

        interlacing_leftweight = 0;

    }

    if (get_bits(&alac->gb, 3) != 7)

        av_log(avctx, AV_LOG_ERROR, "Error : Wrong End Of Frame\n");



    switch(alac->setinfo_sample_size) {

    case 16:

        if (channels == 2) {

            reconstruct_stereo_16(alac->outputsamples_buffer,

                                  (int16_t*)outbuffer,

                                  alac->numchannels,

                                  outputsamples,

                                  interlacing_shift,

                                  interlacing_leftweight);

        } else {

            int i;

            for (i = 0; i < outputsamples; i++) {

                ((int16_t*)outbuffer)[i] = alac->outputsamples_buffer[0][i];

            }

        }

        break;

    case 24:

        if (channels == 2) {

            decorrelate_stereo_24(alac->outputsamples_buffer,

                                  outbuffer,

                                  alac->wasted_bits_buffer,

                                  alac->wasted_bits,

                                  alac->numchannels,

                                  outputsamples,

                                  interlacing_shift,

                                  interlacing_leftweight);

        } else {

            int i;

            for (i = 0; i < outputsamples; i++)

                ((int32_t *)outbuffer)[i] = alac->outputsamples_buffer[0][i] << 8;

        }

        break;

    }



    if (input_buffer_size * 8 - get_bits_count(&alac->gb) > 8)

        av_log(avctx, AV_LOG_ERROR, "Error : %d bits left\n", input_buffer_size * 8 - get_bits_count(&alac->gb));



    return input_buffer_size;

}

        return input_buffer_size;     if (!alac->context_initialized) {         if (alac->avctx->extradata_size != ALAC_EXTRADATA_SIZE) {             av_log(avctx, AV_LOG_ERROR, "alac: expected %d extradata bytes\n",                 ALAC_EXTRADATA_SIZE);             return input_buffer_size;         if (alac_set_info(alac)) {             av_log(avctx, AV_LOG_ERROR, "alac: set_info failed\n");             return input_buffer_size;         alac->context_initialized = 1;         return input_buffer_size;
static int FUNC_0(AVCodecContext *VAR_0,

                             void *VAR_1, int *VAR_2,

                             AVPacket *VAR_3)

{

    const uint8_t *VAR_4 = VAR_3->data;

    int VAR_5 = VAR_3->size;

    ALACContext *alac = VAR_0->priv_data;



    int VAR_6;

    unsigned int VAR_7;

    int VAR_8;

    unsigned int VAR_9;

    int VAR_10;

    uint8_t interlacing_shift;

    uint8_t interlacing_leftweight;



    

    if (!VAR_4 || !VAR_5)

        return VAR_5;



    

    if (!alac->context_initialized) {

        if (alac->VAR_0->extradata_size != ALAC_EXTRADATA_SIZE) {

            av_log(VAR_0, AV_LOG_ERROR, "alac: expected %d extradata bytes\n",

                ALAC_EXTRADATA_SIZE);

            return VAR_5;

        }

        if (alac_set_info(alac)) {

            av_log(VAR_0, AV_LOG_ERROR, "alac: set_info failed\n");

            return VAR_5;

        }

        alac->context_initialized = 1;

    }



    init_get_bits(&alac->gb, VAR_4, VAR_5 * 8);



    VAR_6 = get_bits(&alac->gb, 3) + 1;

    if (VAR_6 > MAX_CHANNELS) {

        av_log(VAR_0, AV_LOG_ERROR, "VAR_6 > %d not supported\n",

               MAX_CHANNELS);

        return VAR_5;

    }



    





    skip_bits(&alac->gb, 4);



    skip_bits(&alac->gb, 12); 



    

    VAR_8 = get_bits1(&alac->gb);



    alac->wasted_bits = get_bits(&alac->gb, 2) << 3;



    

    VAR_10 = get_bits1(&alac->gb);



    if (VAR_8) {

        

        VAR_7 = get_bits_long(&alac->gb, 32);

        if(VAR_7 > alac->setinfo_max_samples_per_frame){

            av_log(VAR_0, AV_LOG_ERROR, "VAR_7 %d > %d\n", VAR_7, alac->setinfo_max_samples_per_frame);

            return -1;

        }

    } else

        VAR_7 = alac->setinfo_max_samples_per_frame;



    switch (alac->setinfo_sample_size) {

    case 16: VAR_0->sample_fmt    = SAMPLE_FMT_S16;

             alac->bytespersample = VAR_6 << 1;

             break;

    case 24: VAR_0->sample_fmt    = SAMPLE_FMT_S32;

             alac->bytespersample = VAR_6 << 2;

             break;

    default: av_log(VAR_0, AV_LOG_ERROR, "Sample depth %d is not supported.\n",

                    alac->setinfo_sample_size);

             return -1;

    }



    if(VAR_7 > *VAR_2 / alac->bytespersample){

        av_log(VAR_0, AV_LOG_ERROR, "sample buffer too small\n");

        return -1;

    }



    *VAR_2 = VAR_7 * alac->bytespersample;

    VAR_9 = alac->setinfo_sample_size - (alac->wasted_bits) + VAR_6 - 1;

    if (VAR_9 > MIN_CACHE_BITS) {

        av_log(VAR_0, AV_LOG_ERROR, "VAR_9 too big (%d)\n", VAR_9);

        return -1;

    }



    if (!VAR_10) {

        

        int16_t predictor_coef_table[MAX_CHANNELS][32];

        int VAR_11[MAX_CHANNELS];

        int VAR_12[MAX_CHANNELS];

        int VAR_13[MAX_CHANNELS];

        int VAR_14[MAX_CHANNELS];

        int VAR_18, VAR_18;



        interlacing_shift = get_bits(&alac->gb, 8);

        interlacing_leftweight = get_bits(&alac->gb, 8);



        for (VAR_18 = 0; VAR_18 < VAR_6; VAR_18++) {

            VAR_12[VAR_18] = get_bits(&alac->gb, 4);

            VAR_13[VAR_18] = get_bits(&alac->gb, 4);



            VAR_14[VAR_18] = get_bits(&alac->gb, 3);

            VAR_11[VAR_18] = get_bits(&alac->gb, 5);



            

            for (VAR_18 = 0; VAR_18 < VAR_11[VAR_18]; VAR_18++)

                predictor_coef_table[VAR_18][VAR_18] = (int16_t)get_bits(&alac->gb, 16);

        }



        if (alac->wasted_bits) {

            int VAR_18, VAR_17;

            for (VAR_18 = 0; VAR_18 < VAR_7; VAR_18++) {

                for (VAR_17 = 0; VAR_17 < VAR_6; VAR_17++)

                    alac->wasted_bits_buffer[VAR_17][VAR_18] = get_bits(&alac->gb, alac->wasted_bits);

            }

        }

        for (VAR_18 = 0; VAR_18 < VAR_6; VAR_18++) {

            bastardized_rice_decompress(alac,

                                        alac->predicterror_buffer[VAR_18],

                                        VAR_7,

                                        VAR_9,

                                        alac->setinfo_rice_initialhistory,

                                        alac->setinfo_rice_kmodifier,

                                        VAR_14[VAR_18] * alac->setinfo_rice_historymult / 4,

                                        (1 << alac->setinfo_rice_kmodifier) - 1);



            if (VAR_12[VAR_18] == 0) {

                

                predictor_decompress_fir_adapt(alac->predicterror_buffer[VAR_18],

                                               alac->outputsamples_buffer[VAR_18],

                                               VAR_7,

                                               VAR_9,

                                               predictor_coef_table[VAR_18],

                                               VAR_11[VAR_18],

                                               VAR_13[VAR_18]);

            } else {

                av_log(VAR_0, AV_LOG_ERROR, "FIXME: unhandled prediction type: %VAR_18\n", VAR_12[VAR_18]);

                











            }

        }

    } else {

        

        int VAR_18, VAR_18;

        if (alac->setinfo_sample_size <= 16) {

        for (VAR_18 = 0; VAR_18 < VAR_7; VAR_18++)

            for (VAR_18 = 0; VAR_18 < VAR_6; VAR_18++) {

                int32_t audiobits;



                audiobits = get_sbits_long(&alac->gb, alac->setinfo_sample_size);



                alac->outputsamples_buffer[VAR_18][VAR_18] = audiobits;

            }

        } else {

            for (VAR_18 = 0; VAR_18 < VAR_7; VAR_18++) {

                for (VAR_18 = 0; VAR_18 < VAR_6; VAR_18++) {

                    alac->outputsamples_buffer[VAR_18][VAR_18] = get_bits(&alac->gb,

                                                          alac->setinfo_sample_size);

                    alac->outputsamples_buffer[VAR_18][VAR_18] = sign_extend(alac->outputsamples_buffer[VAR_18][VAR_18],

                                                                      alac->setinfo_sample_size);

                }

            }

        }

        alac->wasted_bits = 0;

        interlacing_shift = 0;

        interlacing_leftweight = 0;

    }

    if (get_bits(&alac->gb, 3) != 7)

        av_log(VAR_0, AV_LOG_ERROR, "Error : Wrong End Of Frame\n");



    switch(alac->setinfo_sample_size) {

    case 16:

        if (VAR_6 == 2) {

            reconstruct_stereo_16(alac->outputsamples_buffer,

                                  (int16_t*)VAR_1,

                                  alac->numchannels,

                                  VAR_7,

                                  interlacing_shift,

                                  interlacing_leftweight);

        } else {

            int VAR_18;

            for (VAR_18 = 0; VAR_18 < VAR_7; VAR_18++) {

                ((int16_t*)VAR_1)[VAR_18] = alac->outputsamples_buffer[0][VAR_18];

            }

        }

        break;

    case 24:

        if (VAR_6 == 2) {

            decorrelate_stereo_24(alac->outputsamples_buffer,

                                  VAR_1,

                                  alac->wasted_bits_buffer,

                                  alac->wasted_bits,

                                  alac->numchannels,

                                  VAR_7,

                                  interlacing_shift,

                                  interlacing_leftweight);

        } else {

            int VAR_18;

            for (VAR_18 = 0; VAR_18 < VAR_7; VAR_18++)

                ((int32_t *)VAR_1)[VAR_18] = alac->outputsamples_buffer[0][VAR_18] << 8;

        }

        break;

    }



    if (VAR_5 * 8 - get_bits_count(&alac->gb) > 8)

        av_log(VAR_0, AV_LOG_ERROR, "Error : %d bits left\n", VAR_5 * 8 - get_bits_count(&alac->gb));



    return VAR_5;

}

static int FUNC_0(AVCodecContext *VAR_0,
void *VAR_1, int *VAR_2,
AVPacket *VAR_3)
{ const uint8_t *VAR_4 = VAR_3->data; int VAR_5 = VAR_3->size; ALACContext *alac = VAR_0->priv_data; int VAR_6; unsigned int VAR_7; int VAR_8; unsigned int VAR_9; int VAR_10; uint8_t interlacing_shift; uint8_t interlacing_leftweight; if (!VAR_4 || !VAR_5)
return VAR_5; if (!alac->context_initialized) { if (alac->VAR_0->extradata_size != ALAC_EXTRADATA_SIZE) { av_log(VAR_0, AV_LOG_ERROR, "alac: expected %d extradata bytes\n",
ALAC_EXTRADATA_SIZE); return VAR_5; } if (alac_set_info(alac)) { av_log(VAR_0, AV_LOG_ERROR, "alac: set_info failed\n"); return VAR_5; } alac->context_initialized = 1; } init_get_bits(&alac->gb, VAR_4, VAR_5 * 8); VAR_6 = get_bits(&alac->gb, 3) + 1; if (VAR_6 > MAX_CHANNELS) { av_log(VAR_0, AV_LOG_ERROR, "VAR_6 > %d not supported\n",
MAX_CHANNELS); return VAR_5; } skip_bits(&alac->gb, 4); skip_bits(&alac->gb, 12); VAR_8 = get_bits1(&alac->gb); alac->wasted_bits = get_bits(&alac->gb, 2) << 3; VAR_10 = get_bits1(&alac->gb); if (VAR_8) { VAR_7 = get_bits_long(&alac->gb, 32); if(VAR_7 > alac->setinfo_max_samples_per_frame){ av_log(VAR_0, AV_LOG_ERROR, "VAR_7 %d > %d\n", VAR_7, alac->setinfo_max_samples_per_frame); return -1; } } else VAR_7 = alac->setinfo_max_samples_per_frame; switch (alac->setinfo_sample_size) { case 16: VAR_0->sample_fmt    = SAMPLE_FMT_S16; alac->bytespersample = VAR_6 << 1; break; case 24: VAR_0->sample_fmt    = SAMPLE_FMT_S32; alac->bytespersample = VAR_6 << 2; break; default: av_log(VAR_0, AV_LOG_ERROR, "Sample depth %d is not supported.\n",
alac->setinfo_sample_size); return -1; } if(VAR_7 > *VAR_2 / alac->bytespersample){ av_log(VAR_0, AV_LOG_ERROR, "sample buffer too small\n"); return -1; } *VAR_2 = VAR_7 * alac->bytespersample; VAR_9 = alac->setinfo_sample_size - (alac->wasted_bits) + VAR_6 - 1; if (VAR_9 > MIN_CACHE_BITS) { av_log(VAR_0, AV_LOG_ERROR, "VAR_9 too big (%d)\n", VAR_9); return -1; } if (!VAR_10) { int16_t predictor_coef_table[MAX_CHANNELS][32]; int VAR_11[MAX_CHANNELS]; int VAR_12[MAX_CHANNELS]; int VAR_13[MAX_CHANNELS]; int VAR_14[MAX_CHANNELS]; int VAR_18, VAR_18; interlacing_shift = get_bits(&alac->gb, 8); interlacing_leftweight = get_bits(&alac->gb, 8); for (VAR_18 = 0; VAR_18 < VAR_6; VAR_18++) { VAR_12[VAR_18] = get_bits(&alac->gb, 4); VAR_13[VAR_18] = get_bits(&alac->gb, 4); VAR_14[VAR_18] = get_bits(&alac->gb, 3); VAR_11[VAR_18] = get_bits(&alac->gb, 5); for (VAR_18 = 0; VAR_18 < VAR_11[VAR_18]; VAR_18++) predictor_coef_table[VAR_18][VAR_18] = (int16_t)get_bits(&alac->gb, 16); } if (alac->wasted_bits) { int VAR_18, VAR_17; for (VAR_18 = 0; VAR_18 < VAR_7; VAR_18++) { for (VAR_17 = 0; VAR_17 < VAR_6; VAR_17++) alac->wasted_bits_buffer[VAR_17][VAR_18] = get_bits(&alac->gb, alac->wasted_bits); } } for (VAR_18 = 0; VAR_18 < VAR_6; VAR_18++) { bastardized_rice_decompress(alac,
alac->predicterror_buffer[VAR_18],
VAR_7,
VAR_9,
alac->setinfo_rice_initialhistory,
alac->setinfo_rice_kmodifier,
VAR_14[VAR_18] * alac->setinfo_rice_historymult / 4,
(1 << alac->setinfo_rice_kmodifier) - 1); if (VAR_12[VAR_18] == 0) { predictor_decompress_fir_adapt(alac->predicterror_buffer[VAR_18],
alac->outputsamples_buffer[VAR_18],
VAR_7,
VAR_9,
predictor_coef_table[VAR_18],
VAR_11[VAR_18],
VAR_13[VAR_18]); } else { av_log(VAR_0, AV_LOG_ERROR, "FIXME: unhandled prediction type: %VAR_18\n", VAR_12[VAR_18]); } } } else { int VAR_18, VAR_18; if (alac->setinfo_sample_size <= 16) { for (VAR_18 = 0; VAR_18 < VAR_7; VAR_18++) for (VAR_18 = 0; VAR_18 < VAR_6; VAR_18++) { int32_t audiobits; audiobits = get_sbits_long(&alac->gb, alac->setinfo_sample_size); alac->outputsamples_buffer[VAR_18][VAR_18] = audiobits; } } else { for (VAR_18 = 0; VAR_18 < VAR_7; VAR_18++) { for (VAR_18 = 0; VAR_18 < VAR_6; VAR_18++) { alac->outputsamples_buffer[VAR_18][VAR_18] = get_bits(&alac->gb,
alac->setinfo_sample_size); alac->outputsamples_buffer[VAR_18][VAR_18] = sign_extend(alac->outputsamples_buffer[VAR_18][VAR_18],
alac->setinfo_sample_size); } } } alac->wasted_bits = 0; interlacing_shift = 0; interlacing_leftweight = 0; } if (get_bits(&alac->gb, 3) != 7)
av_log(VAR_0, AV_LOG_ERROR, "Error : Wrong End Of Frame\n"); switch(alac->setinfo_sample_size) { case 16:
if (VAR_6 == 2) { reconstruct_stereo_16(alac->outputsamples_buffer,
(int16_t*)VAR_1,
alac->numchannels,
VAR_7,
interlacing_shift,
interlacing_leftweight); } else { int VAR_18; for (VAR_18 = 0; VAR_18 < VAR_7; VAR_18++) { ((int16_t*)VAR_1)[VAR_18] = alac->outputsamples_buffer[0][VAR_18]; } } break; case 24:
if (VAR_6 == 2) { decorrelate_stereo_24(alac->outputsamples_buffer,
VAR_1,
alac->wasted_bits_buffer,
alac->wasted_bits,
alac->numchannels,
VAR_7,
interlacing_shift,
interlacing_leftweight); } else { int VAR_18; for (VAR_18 = 0; VAR_18 < VAR_7; VAR_18++) ((int32_t *)VAR_1)[VAR_18] = alac->outputsamples_buffer[0][VAR_18] << 8; } break; } if (VAR_5 * 8 - get_bits_count(&alac->gb) > 8)
av_log(VAR_0, AV_LOG_ERROR, "Error : %d bits left\n", VAR_5 * 8 - get_bits_count(&alac->gb)); return VAR_5; }