static int cook_decode_frame(AVCodecContext *avctx,

            void *data, int *data_size,

            AVPacket *avpkt) {

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    COOKContext *q = avctx->priv_data;

    int i;

    int offset = 0;

    int chidx = 0;



    if (buf_size < avctx->block_align)

        return buf_size;



    /* estimate subpacket sizes */

    q->subpacket[0].size = avctx->block_align;



    for(i=1;i<q->num_subpackets;i++){

        q->subpacket[i].size = 2 * buf[avctx->block_align - q->num_subpackets + i];

        q->subpacket[0].size -= q->subpacket[i].size + 1;

        if (q->subpacket[0].size < 0) {

            av_log(avctx,AV_LOG_DEBUG,"frame subpacket size total > avctx->block_align!\n");

            return AVERROR_INVALIDDATA;

        }

    }



    /* decode supbackets */

    for(i=0;i<q->num_subpackets;i++){

        q->subpacket[i].bits_per_subpacket = (q->subpacket[i].size*8)>>q->subpacket[i].bits_per_subpdiv;

        q->subpacket[i].ch_idx = chidx;

        av_log(avctx,AV_LOG_DEBUG,"subpacket[%i] size %i js %i %i block_align %i\n",i,q->subpacket[i].size,q->subpacket[i].joint_stereo,offset,avctx->block_align);

        decode_subpacket(q, &q->subpacket[i], buf + offset, data);

        offset += q->subpacket[i].size;

        chidx += q->subpacket[i].num_channels;

        av_log(avctx,AV_LOG_DEBUG,"subpacket[%i] %i %i\n",i,q->subpacket[i].size * 8,get_bits_count(&q->gb));

    }

    *data_size = q->nb_channels * q->samples_per_channel *

                 av_get_bytes_per_sample(avctx->sample_fmt);



    /* Discard the first two frames: no valid audio. */

    if (avctx->frame_number < 2) *data_size = 0;



    return avctx->block_align;

}

static int cook_decode_frame(AVCodecContext *avctx,

            void *data, int *data_size,

            AVPacket *avpkt) {

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    COOKContext *q = avctx->priv_data;

    int i;

    int offset = 0;

    int chidx = 0;



    if (buf_size < avctx->block_align)

        return buf_size;



    

    q->subpacket[0].size = avctx->block_align;



    for(i=1;i<q->num_subpackets;i++){

        q->subpacket[i].size = 2 * buf[avctx->block_align - q->num_subpackets + i];

        q->subpacket[0].size -= q->subpacket[i].size + 1;

        if (q->subpacket[0].size < 0) {

            av_log(avctx,AV_LOG_DEBUG,"frame subpacket size total > avctx->block_align!\n");

            return AVERROR_INVALIDDATA;

        }

    }



    

    for(i=0;i<q->num_subpackets;i++){

        q->subpacket[i].bits_per_subpacket = (q->subpacket[i].size*8)>>q->subpacket[i].bits_per_subpdiv;

        q->subpacket[i].ch_idx = chidx;

        av_log(avctx,AV_LOG_DEBUG,"subpacket[%i] size %i js %i %i block_align %i\n",i,q->subpacket[i].size,q->subpacket[i].joint_stereo,offset,avctx->block_align);

        decode_subpacket(q, &q->subpacket[i], buf + offset, data);

        offset += q->subpacket[i].size;

        chidx += q->subpacket[i].num_channels;

        av_log(avctx,AV_LOG_DEBUG,"subpacket[%i] %i %i\n",i,q->subpacket[i].size * 8,get_bits_count(&q->gb));

    }

    *data_size = q->nb_channels * q->samples_per_channel *

                 av_get_bytes_per_sample(avctx->sample_fmt);



    

    if (avctx->frame_number < 2) *data_size = 0;



    return avctx->block_align;

}

static int FUNC_0(AVCodecContext *VAR_0,

            void *VAR_1, int *VAR_2,

            AVPacket *VAR_3) {

    const uint8_t *VAR_4 = VAR_3->VAR_1;

    int VAR_5 = VAR_3->size;

    COOKContext *q = VAR_0->priv_data;

    int VAR_6;

    int VAR_7 = 0;

    int VAR_8 = 0;



    if (VAR_5 < VAR_0->block_align)

        return VAR_5;



    

    q->subpacket[0].size = VAR_0->block_align;



    for(VAR_6=1;VAR_6<q->num_subpackets;VAR_6++){

        q->subpacket[VAR_6].size = 2 * VAR_4[VAR_0->block_align - q->num_subpackets + VAR_6];

        q->subpacket[0].size -= q->subpacket[VAR_6].size + 1;

        if (q->subpacket[0].size < 0) {

            av_log(VAR_0,AV_LOG_DEBUG,"frame subpacket size total > VAR_0->block_align!\n");

            return AVERROR_INVALIDDATA;

        }

    }



    

    for(VAR_6=0;VAR_6<q->num_subpackets;VAR_6++){

        q->subpacket[VAR_6].bits_per_subpacket = (q->subpacket[VAR_6].size*8)>>q->subpacket[VAR_6].bits_per_subpdiv;

        q->subpacket[VAR_6].ch_idx = VAR_8;

        av_log(VAR_0,AV_LOG_DEBUG,"subpacket[%VAR_6] size %VAR_6 js %VAR_6 %VAR_6 block_align %VAR_6\n",VAR_6,q->subpacket[VAR_6].size,q->subpacket[VAR_6].joint_stereo,VAR_7,VAR_0->block_align);

        decode_subpacket(q, &q->subpacket[VAR_6], VAR_4 + VAR_7, VAR_1);

        VAR_7 += q->subpacket[VAR_6].size;

        VAR_8 += q->subpacket[VAR_6].num_channels;

        av_log(VAR_0,AV_LOG_DEBUG,"subpacket[%VAR_6] %VAR_6 %VAR_6\n",VAR_6,q->subpacket[VAR_6].size * 8,get_bits_count(&q->gb));

    }

    *VAR_2 = q->nb_channels * q->samples_per_channel *

                 av_get_bytes_per_sample(VAR_0->sample_fmt);



    

    if (VAR_0->frame_number < 2) *VAR_2 = 0;



    return VAR_0->block_align;

}

static int FUNC_0(AVCodecContext *VAR_0,
void *VAR_1, int *VAR_2,
AVPacket *VAR_3) { const uint8_t *VAR_4 = VAR_3->VAR_1; int VAR_5 = VAR_3->size; COOKContext *q = VAR_0->priv_data; int VAR_6; int VAR_7 = 0; int VAR_8 = 0; if (VAR_5 < VAR_0->block_align)
return VAR_5; q->subpacket[0].size = VAR_0->block_align; for(VAR_6=1;VAR_6<q->num_subpackets;VAR_6++){ q->subpacket[VAR_6].size = 2 * VAR_4[VAR_0->block_align - q->num_subpackets + VAR_6]; q->subpacket[0].size -= q->subpacket[VAR_6].size + 1; if (q->subpacket[0].size < 0) { av_log(VAR_0,AV_LOG_DEBUG,"frame subpacket size total > VAR_0->block_align!\n"); return AVERROR_INVALIDDATA; } } for(VAR_6=0;VAR_6<q->num_subpackets;VAR_6++){ q->subpacket[VAR_6].bits_per_subpacket = (q->subpacket[VAR_6].size*8)>>q->subpacket[VAR_6].bits_per_subpdiv; q->subpacket[VAR_6].ch_idx = VAR_8; av_log(VAR_0,AV_LOG_DEBUG,"subpacket[%VAR_6] size %VAR_6 js %VAR_6 %VAR_6 block_align %VAR_6\n",VAR_6,q->subpacket[VAR_6].size,q->subpacket[VAR_6].joint_stereo,VAR_7,VAR_0->block_align); decode_subpacket(q, &q->subpacket[VAR_6], VAR_4 + VAR_7, VAR_1); VAR_7 += q->subpacket[VAR_6].size; VAR_8 += q->subpacket[VAR_6].num_channels; av_log(VAR_0,AV_LOG_DEBUG,"subpacket[%VAR_6] %VAR_6 %VAR_6\n",VAR_6,q->subpacket[VAR_6].size * 8,get_bits_count(&q->gb)); } *VAR_2 = q->nb_channels * q->samples_per_channel *
av_get_bytes_per_sample(VAR_0->sample_fmt); if (VAR_0->frame_number < 2) *VAR_2 = 0; return VAR_0->block_align; }