static int dca_decode_frame(AVCodecContext * avctx,

                            void *data, int *data_size,

                            const uint8_t * buf, int buf_size)

{



    int i, j, k;

    int16_t *samples = data;

    DCAContext *s = avctx->priv_data;

    int channels;





    s->dca_buffer_size = dca_convert_bitstream(buf, buf_size, s->dca_buffer, DCA_MAX_FRAME_SIZE);

    if (s->dca_buffer_size == -1) {

        av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n");

        return -1;

    }



    init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);

    if (dca_parse_frame_header(s) < 0) {

        //seems like the frame is corrupt, try with the next one

        *data_size=0;

        return buf_size;

    }

    //set AVCodec values with parsed data

    avctx->sample_rate = s->sample_rate;

    avctx->bit_rate = s->bit_rate;



    channels = s->prim_channels + !!s->lfe;

    if(avctx->request_channels == 2 && s->prim_channels > 2) {

        channels = 2;

        s->output = DCA_STEREO;

    }



    avctx->channels = channels;

    if(*data_size < (s->sample_blocks / 8) * 256 * sizeof(int16_t) * channels)

        return -1;

    *data_size = 0;

    for (i = 0; i < (s->sample_blocks / 8); i++) {

        dca_decode_block(s);

        s->dsp.float_to_int16(s->tsamples, s->samples, 256 * channels);

        /* interleave samples */

        for (j = 0; j < 256; j++) {

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

                samples[k] = s->tsamples[j + k * 256];

            samples += channels;

        }

        *data_size += 256 * sizeof(int16_t) * channels;

    }



    return buf_size;

}

static int dca_decode_frame(AVCodecContext * avctx,

                            void *data, int *data_size,

                            const uint8_t * buf, int buf_size)

{



    int i, j, k;

    int16_t *samples = data;

    DCAContext *s = avctx->priv_data;

    int channels;





    s->dca_buffer_size = dca_convert_bitstream(buf, buf_size, s->dca_buffer, DCA_MAX_FRAME_SIZE);

    if (s->dca_buffer_size == -1) {

        av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n");

        return -1;

    }



    init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);

    if (dca_parse_frame_header(s) < 0) {

        

        *data_size=0;

        return buf_size;

    }

    

    avctx->sample_rate = s->sample_rate;

    avctx->bit_rate = s->bit_rate;



    channels = s->prim_channels + !!s->lfe;

    if(avctx->request_channels == 2 && s->prim_channels > 2) {

        channels = 2;

        s->output = DCA_STEREO;

    }



    avctx->channels = channels;

    if(*data_size < (s->sample_blocks / 8) * 256 * sizeof(int16_t) * channels)

        return -1;

    *data_size = 0;

    for (i = 0; i < (s->sample_blocks / 8); i++) {

        dca_decode_block(s);

        s->dsp.float_to_int16(s->tsamples, s->samples, 256 * channels);

        

        for (j = 0; j < 256; j++) {

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

                samples[k] = s->tsamples[j + k * 256];

            samples += channels;

        }

        *data_size += 256 * sizeof(int16_t) * channels;

    }



    return buf_size;

}

    avctx->channels = channels;
static int FUNC_0(AVCodecContext * VAR_0,

                            void *VAR_1, int *VAR_2,

                            const uint8_t * VAR_3, int VAR_4)

{



    int VAR_5, VAR_6, VAR_7;

    int16_t *samples = VAR_1;

    DCAContext *s = VAR_0->priv_data;

    int VAR_8;





    s->dca_buffer_size = dca_convert_bitstream(VAR_3, VAR_4, s->dca_buffer, DCA_MAX_FRAME_SIZE);

    if (s->dca_buffer_size == -1) {

        av_log(VAR_0, AV_LOG_ERROR, "Not a valid DCA frame\n");

        return -1;

    }



    init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8);

    if (dca_parse_frame_header(s) < 0) {

        

        *VAR_2=0;

        return VAR_4;

    }

    

    VAR_0->sample_rate = s->sample_rate;

    VAR_0->bit_rate = s->bit_rate;



    VAR_8 = s->prim_channels + !!s->lfe;

    if(VAR_0->request_channels == 2 && s->prim_channels > 2) {

        VAR_8 = 2;

        s->output = DCA_STEREO;

    }



    VAR_0->VAR_8 = VAR_8;

    if(*VAR_2 < (s->sample_blocks / 8) * 256 * sizeof(int16_t) * VAR_8)

        return -1;

    *VAR_2 = 0;

    for (VAR_5 = 0; VAR_5 < (s->sample_blocks / 8); VAR_5++) {

        dca_decode_block(s);

        s->dsp.float_to_int16(s->tsamples, s->samples, 256 * VAR_8);

        

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

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

                samples[VAR_7] = s->tsamples[VAR_6 + VAR_7 * 256];

            samples += VAR_8;

        }

        *VAR_2 += 256 * sizeof(int16_t) * VAR_8;

    }



    return VAR_4;

}

static int FUNC_0(AVCodecContext * VAR_0,
void *VAR_1, int *VAR_2,
const uint8_t * VAR_3, int VAR_4)
{ int VAR_5, VAR_6, VAR_7; int16_t *samples = VAR_1; DCAContext *s = VAR_0->priv_data; int VAR_8; s->dca_buffer_size = dca_convert_bitstream(VAR_3, VAR_4, s->dca_buffer, DCA_MAX_FRAME_SIZE); if (s->dca_buffer_size == -1) { av_log(VAR_0, AV_LOG_ERROR, "Not a valid DCA frame\n"); return -1; } init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8); if (dca_parse_frame_header(s) < 0) { *VAR_2=0; return VAR_4; } VAR_0->sample_rate = s->sample_rate; VAR_0->bit_rate = s->bit_rate; VAR_8 = s->prim_channels + !!s->lfe; if(VAR_0->request_channels == 2 && s->prim_channels > 2) { VAR_8 = 2; s->output = DCA_STEREO; } VAR_0->VAR_8 = VAR_8; if(*VAR_2 < (s->sample_blocks / 8) * 256 * sizeof(int16_t) * VAR_8)
return -1; *VAR_2 = 0; for (VAR_5 = 0; VAR_5 < (s->sample_blocks / 8); VAR_5++) { dca_decode_block(s); s->dsp.float_to_int16(s->tsamples, s->samples, 256 * VAR_8); for (VAR_6 = 0; VAR_6 < 256; VAR_6++) { for (VAR_7 = 0; VAR_7 < VAR_8; VAR_7++) samples[VAR_7] = s->tsamples[VAR_6 + VAR_7 * 256]; samples += VAR_8; } *VAR_2 += 256 * sizeof(int16_t) * VAR_8; } return VAR_4; }