static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,

                                 int *got_frame_ptr, AVPacket *avpkt)

{

    EightSvxContext *esc = avctx->priv_data;

    int n, out_data_size;

    int ch, ret;

    uint8_t *src;



    /* decode and interleave the first packet */

    if (!esc->samples && avpkt) {

        int packet_size = avpkt->size;



        if (packet_size % avctx->channels) {

            av_log(avctx, AV_LOG_WARNING, "Packet with odd size, ignoring last byte\n");

            if (packet_size < avctx->channels)

                return packet_size;

            packet_size -= packet_size % avctx->channels;

        }

        esc->samples_size = !esc->table ?

            packet_size : avctx->channels + (packet_size-avctx->channels) * 2;

        if (!(esc->samples = av_malloc(esc->samples_size)))

            return AVERROR(ENOMEM);



        /* decompress */

        if (esc->table) {

            const uint8_t *buf = avpkt->data;

            uint8_t *dst;

            int buf_size = avpkt->size;

            int i, n = esc->samples_size;



            if (buf_size < 2) {

                av_log(avctx, AV_LOG_ERROR, "packet size is too small\n");

                return AVERROR(EINVAL);

            }



            /* the uncompressed starting value is contained in the first byte */

            dst = esc->samples;

            for (i = 0; i < avctx->channels; i++) {

                *(dst++) = buf[0]+128;

                delta_decode(dst, buf + 1, buf_size / avctx->channels - 1, (buf[0]+128)&0xFF, esc->table);

                buf += buf_size / avctx->channels;

                dst += n / avctx->channels - 1;

            }

        } else {

            raw_decode(esc->samples, avpkt->data, esc->samples_size);

        }

    }



    /* get output buffer */

    av_assert1(!(esc->samples_size % avctx->channels || esc->samples_idx % avctx->channels));

    esc->frame.nb_samples = FFMIN(MAX_FRAME_SIZE, esc->samples_size - esc->samples_idx)  / avctx->channels;

    if ((ret = avctx->get_buffer(avctx, &esc->frame)) < 0) {

        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");

        return ret;

    }



    *got_frame_ptr   = 1;

    *(AVFrame *)data = esc->frame;



    out_data_size = esc->frame.nb_samples;

    for (ch = 0; ch<avctx->channels; ch++) {

        src = esc->samples + esc->samples_idx / avctx->channels + ch * esc->samples_size / avctx->channels;

        memcpy(esc->frame.data[ch], src, out_data_size);

    }

    out_data_size *= avctx->channels;

    esc->samples_idx += out_data_size;



    return esc->table ?

        (avctx->frame_number == 0)*2 + out_data_size / 2 :

        out_data_size;

}

static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,

                                 int *got_frame_ptr, AVPacket *avpkt)

{

    EightSvxContext *esc = avctx->priv_data;

    int n, out_data_size;

    int ch, ret;

    uint8_t *src;



    

    if (!esc->samples && avpkt) {

        int packet_size = avpkt->size;



        if (packet_size % avctx->channels) {

            av_log(avctx, AV_LOG_WARNING, "Packet with odd size, ignoring last byte\n");

            if (packet_size < avctx->channels)

                return packet_size;

            packet_size -= packet_size % avctx->channels;

        }

        esc->samples_size = !esc->table ?

            packet_size : avctx->channels + (packet_size-avctx->channels) * 2;

        if (!(esc->samples = av_malloc(esc->samples_size)))

            return AVERROR(ENOMEM);



        

        if (esc->table) {

            const uint8_t *buf = avpkt->data;

            uint8_t *dst;

            int buf_size = avpkt->size;

            int i, n = esc->samples_size;



            if (buf_size < 2) {

                av_log(avctx, AV_LOG_ERROR, "packet size is too small\n");

                return AVERROR(EINVAL);

            }



            

            dst = esc->samples;

            for (i = 0; i < avctx->channels; i++) {

                *(dst++) = buf[0]+128;

                delta_decode(dst, buf + 1, buf_size / avctx->channels - 1, (buf[0]+128)&0xFF, esc->table);

                buf += buf_size / avctx->channels;

                dst += n / avctx->channels - 1;

            }

        } else {

            raw_decode(esc->samples, avpkt->data, esc->samples_size);

        }

    }



    

    av_assert1(!(esc->samples_size % avctx->channels || esc->samples_idx % avctx->channels));

    esc->frame.nb_samples = FFMIN(MAX_FRAME_SIZE, esc->samples_size - esc->samples_idx)  / avctx->channels;

    if ((ret = avctx->get_buffer(avctx, &esc->frame)) < 0) {

        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");

        return ret;

    }



    *got_frame_ptr   = 1;

    *(AVFrame *)data = esc->frame;



    out_data_size = esc->frame.nb_samples;

    for (ch = 0; ch<avctx->channels; ch++) {

        src = esc->samples + esc->samples_idx / avctx->channels + ch * esc->samples_size / avctx->channels;

        memcpy(esc->frame.data[ch], src, out_data_size);

    }

    out_data_size *= avctx->channels;

    esc->samples_idx += out_data_size;



    return esc->table ?

        (avctx->frame_number == 0)*2 + out_data_size / 2 :

        out_data_size;

}

static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,

                                 int *VAR_2, AVPacket *VAR_3)

{

    EightSvxContext *esc = VAR_0->priv_data;

    int VAR_12, VAR_5;

    int VAR_6, VAR_7;

    uint8_t *src;



    

    if (!esc->samples && VAR_3) {

        int VAR_8 = VAR_3->size;



        if (VAR_8 % VAR_0->channels) {

            av_log(VAR_0, AV_LOG_WARNING, "Packet with odd size, ignoring last byte\VAR_12");

            if (VAR_8 < VAR_0->channels)

                return VAR_8;

            VAR_8 -= VAR_8 % VAR_0->channels;

        }

        esc->samples_size = !esc->table ?

            VAR_8 : VAR_0->channels + (VAR_8-VAR_0->channels) * 2;

        if (!(esc->samples = av_malloc(esc->samples_size)))

            return AVERROR(ENOMEM);



        

        if (esc->table) {

            const uint8_t *VAR_9 = VAR_3->VAR_1;

            uint8_t *dst;

            int VAR_10 = VAR_3->size;

            int VAR_11, VAR_12 = esc->samples_size;



            if (VAR_10 < 2) {

                av_log(VAR_0, AV_LOG_ERROR, "packet size is too small\VAR_12");

                return AVERROR(EINVAL);

            }



            

            dst = esc->samples;

            for (VAR_11 = 0; VAR_11 < VAR_0->channels; VAR_11++) {

                *(dst++) = VAR_9[0]+128;

                delta_decode(dst, VAR_9 + 1, VAR_10 / VAR_0->channels - 1, (VAR_9[0]+128)&0xFF, esc->table);

                VAR_9 += VAR_10 / VAR_0->channels;

                dst += VAR_12 / VAR_0->channels - 1;

            }

        } else {

            raw_decode(esc->samples, VAR_3->VAR_1, esc->samples_size);

        }

    }



    

    av_assert1(!(esc->samples_size % VAR_0->channels || esc->samples_idx % VAR_0->channels));

    esc->frame.nb_samples = FFMIN(MAX_FRAME_SIZE, esc->samples_size - esc->samples_idx)  / VAR_0->channels;

    if ((VAR_7 = VAR_0->get_buffer(VAR_0, &esc->frame)) < 0) {

        av_log(VAR_0, AV_LOG_ERROR, "get_buffer() failed\VAR_12");

        return VAR_7;

    }



    *VAR_2   = 1;

    *(AVFrame *)VAR_1 = esc->frame;



    VAR_5 = esc->frame.nb_samples;

    for (VAR_6 = 0; VAR_6<VAR_0->channels; VAR_6++) {

        src = esc->samples + esc->samples_idx / VAR_0->channels + VAR_6 * esc->samples_size / VAR_0->channels;

        memcpy(esc->frame.VAR_1[VAR_6], src, VAR_5);

    }

    VAR_5 *= VAR_0->channels;

    esc->samples_idx += VAR_5;



    return esc->table ?

        (VAR_0->frame_number == 0)*2 + VAR_5 / 2 :

        VAR_5;

}

static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,
int *VAR_2, AVPacket *VAR_3)
{ EightSvxContext *esc = VAR_0->priv_data; int VAR_12, VAR_5; int VAR_6, VAR_7; uint8_t *src; if (!esc->samples && VAR_3) { int VAR_8 = VAR_3->size; if (VAR_8 % VAR_0->channels) { av_log(VAR_0, AV_LOG_WARNING, "Packet with odd size, ignoring last byte\VAR_12"); if (VAR_8 < VAR_0->channels)
return VAR_8; VAR_8 -= VAR_8 % VAR_0->channels; } esc->samples_size = !esc->table ?
VAR_8 : VAR_0->channels + (VAR_8-VAR_0->channels) * 2; if (!(esc->samples = av_malloc(esc->samples_size)))
return AVERROR(ENOMEM); if (esc->table) { const uint8_t *VAR_9 = VAR_3->VAR_1; uint8_t *dst; int VAR_10 = VAR_3->size; int VAR_11, VAR_12 = esc->samples_size; if (VAR_10 < 2) { av_log(VAR_0, AV_LOG_ERROR, "packet size is too small\VAR_12"); return AVERROR(EINVAL); } dst = esc->samples; for (VAR_11 = 0; VAR_11 < VAR_0->channels; VAR_11++) { *(dst++) = VAR_9[0]+128; delta_decode(dst, VAR_9 + 1, VAR_10 / VAR_0->channels - 1, (VAR_9[0]+128)&0xFF, esc->table); VAR_9 += VAR_10 / VAR_0->channels; dst += VAR_12 / VAR_0->channels - 1; } } else { raw_decode(esc->samples, VAR_3->VAR_1, esc->samples_size); } } av_assert1(!(esc->samples_size % VAR_0->channels || esc->samples_idx % VAR_0->channels)); esc->frame.nb_samples = FFMIN(MAX_FRAME_SIZE, esc->samples_size - esc->samples_idx)  / VAR_0->channels; if ((VAR_7 = VAR_0->get_buffer(VAR_0, &esc->frame)) < 0) { av_log(VAR_0, AV_LOG_ERROR, "get_buffer() failed\VAR_12"); return VAR_7; } *VAR_2   = 1; *(AVFrame *)VAR_1 = esc->frame; VAR_5 = esc->frame.nb_samples; for (VAR_6 = 0; VAR_6<VAR_0->channels; VAR_6++) { src = esc->samples + esc->samples_idx / VAR_0->channels + VAR_6 * esc->samples_size / VAR_0->channels; memcpy(esc->frame.VAR_1[VAR_6], src, VAR_5); } VAR_5 *= VAR_0->channels; esc->samples_idx += VAR_5; return esc->table ?
(VAR_0->frame_number == 0)*2 + VAR_5 / 2 :
VAR_5; }