static int ws_snd_decode_frame(AVCodecContext *avctx,

                void *data, int *data_size,

                AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

//    WSSNDContext *c = avctx->priv_data;



    int in_size, out_size;

    int sample = 128;

    int i;

    uint8_t *samples = data;



    if (!buf_size)

        return 0;



    out_size = AV_RL16(&buf[0]);

    in_size = AV_RL16(&buf[2]);

    buf += 4;



    if (out_size > *data_size) {

        av_log(avctx, AV_LOG_ERROR, "Frame is too large to fit in buffer\n");

        return -1;

    }

    if (in_size > buf_size) {

        av_log(avctx, AV_LOG_ERROR, "Frame data is larger than input buffer\n");

        return -1;

    }



    *data_size = out_size;



    if (in_size == out_size) {

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

            *samples++ = *buf++;

        return buf_size;

    }



    while (out_size > 0) {

        int code;

        uint8_t count;

        code = (*buf) >> 6;

        count = (*buf) & 0x3F;

        buf++;

        switch(code) {

        case 0: /* ADPCM 2-bit */

            for (count++; count > 0; count--) {

                code = *buf++;

                sample += ws_adpcm_2bit[code & 0x3];

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                sample += ws_adpcm_2bit[(code >> 2) & 0x3];

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                sample += ws_adpcm_2bit[(code >> 4) & 0x3];

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                sample += ws_adpcm_2bit[(code >> 6) & 0x3];

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                out_size -= 4;

            }

            break;

        case 1: /* ADPCM 4-bit */

            for (count++; count > 0; count--) {

                code = *buf++;

                sample += ws_adpcm_4bit[code & 0xF];

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                sample += ws_adpcm_4bit[code >> 4];

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                out_size -= 2;

            }

            break;

        case 2: /* no compression */

            if (count & 0x20) { /* big delta */

                int8_t t;

                t = count;

                t <<= 3;

                sample += t >> 3;

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                out_size--;

            } else { /* copy */

                for (count++; count > 0; count--) {

                    *samples++ = *buf++;

                    out_size--;

                }

                sample = buf[-1];

            }

            break;

        default: /* run */

            for(count++; count > 0; count--) {

                *samples++ = sample;

                out_size--;

            }

        }

    }



    return buf_size;

}

static int ws_snd_decode_frame(AVCodecContext *avctx,

                void *data, int *data_size,

                AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;





    int in_size, out_size;

    int sample = 128;

    int i;

    uint8_t *samples = data;



    if (!buf_size)

        return 0;



    out_size = AV_RL16(&buf[0]);

    in_size = AV_RL16(&buf[2]);

    buf += 4;



    if (out_size > *data_size) {

        av_log(avctx, AV_LOG_ERROR, "Frame is too large to fit in buffer\n");

        return -1;

    }

    if (in_size > buf_size) {

        av_log(avctx, AV_LOG_ERROR, "Frame data is larger than input buffer\n");

        return -1;

    }



    *data_size = out_size;



    if (in_size == out_size) {

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

            *samples++ = *buf++;

        return buf_size;

    }



    while (out_size > 0) {

        int code;

        uint8_t count;

        code = (*buf) >> 6;

        count = (*buf) & 0x3F;

        buf++;

        switch(code) {

        case 0: 

            for (count++; count > 0; count--) {

                code = *buf++;

                sample += ws_adpcm_2bit[code & 0x3];

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                sample += ws_adpcm_2bit[(code >> 2) & 0x3];

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                sample += ws_adpcm_2bit[(code >> 4) & 0x3];

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                sample += ws_adpcm_2bit[(code >> 6) & 0x3];

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                out_size -= 4;

            }

            break;

        case 1: 

            for (count++; count > 0; count--) {

                code = *buf++;

                sample += ws_adpcm_4bit[code & 0xF];

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                sample += ws_adpcm_4bit[code >> 4];

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                out_size -= 2;

            }

            break;

        case 2: 

            if (count & 0x20) { 

                int8_t t;

                t = count;

                t <<= 3;

                sample += t >> 3;

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                out_size--;

            } else { 

                for (count++; count > 0; count--) {

                    *samples++ = *buf++;

                    out_size--;

                }

                sample = buf[-1];

            }

            break;

        default: 

            for(count++; count > 0; count--) {

                *samples++ = sample;

                out_size--;

            }

        }

    }



    return buf_size;

}

    *data_size = out_size;     while (out_size > 0) {         int code;
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;





    int VAR_6, VAR_7;

    int VAR_8 = 128;

    int VAR_9;

    uint8_t *samples = VAR_1;



    if (!VAR_5)

        return 0;



    VAR_7 = AV_RL16(&VAR_4[0]);

    VAR_6 = AV_RL16(&VAR_4[2]);

    VAR_4 += 4;



    if (VAR_7 > *VAR_2) {

        av_log(VAR_0, AV_LOG_ERROR, "Frame is too large to fit in buffer\n");

        return -1;

    }

    if (VAR_6 > VAR_5) {

        av_log(VAR_0, AV_LOG_ERROR, "Frame VAR_1 is larger than input buffer\n");

        return -1;

    }



    *VAR_2 = VAR_7;



    if (VAR_6 == VAR_7) {

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

            *samples++ = *VAR_4++;

        return VAR_5;

    }



    while (VAR_7 > 0) {

        int VAR_10;

        uint8_t count;

        VAR_10 = (*VAR_4) >> 6;

        count = (*VAR_4) & 0x3F;

        VAR_4++;

        switch(VAR_10) {

        case 0: 

            for (count++; count > 0; count--) {

                VAR_10 = *VAR_4++;

                VAR_8 += ws_adpcm_2bit[VAR_10 & 0x3];

                VAR_8 = av_clip_uint8(VAR_8);

                *samples++ = VAR_8;

                VAR_8 += ws_adpcm_2bit[(VAR_10 >> 2) & 0x3];

                VAR_8 = av_clip_uint8(VAR_8);

                *samples++ = VAR_8;

                VAR_8 += ws_adpcm_2bit[(VAR_10 >> 4) & 0x3];

                VAR_8 = av_clip_uint8(VAR_8);

                *samples++ = VAR_8;

                VAR_8 += ws_adpcm_2bit[(VAR_10 >> 6) & 0x3];

                VAR_8 = av_clip_uint8(VAR_8);

                *samples++ = VAR_8;

                VAR_7 -= 4;

            }

            break;

        case 1: 

            for (count++; count > 0; count--) {

                VAR_10 = *VAR_4++;

                VAR_8 += ws_adpcm_4bit[VAR_10 & 0xF];

                VAR_8 = av_clip_uint8(VAR_8);

                *samples++ = VAR_8;

                VAR_8 += ws_adpcm_4bit[VAR_10 >> 4];

                VAR_8 = av_clip_uint8(VAR_8);

                *samples++ = VAR_8;

                VAR_7 -= 2;

            }

            break;

        case 2: 

            if (count & 0x20) { 

                int8_t t;

                t = count;

                t <<= 3;

                VAR_8 += t >> 3;

                VAR_8 = av_clip_uint8(VAR_8);

                *samples++ = VAR_8;

                VAR_7--;

            } else { 

                for (count++; count > 0; count--) {

                    *samples++ = *VAR_4++;

                    VAR_7--;

                }

                VAR_8 = VAR_4[-1];

            }

            break;

        default: 

            for(count++; count > 0; count--) {

                *samples++ = VAR_8;

                VAR_7--;

            }

        }

    }



    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->VAR_1; int VAR_5 = VAR_3->size; int VAR_6, VAR_7; int VAR_8 = 128; int VAR_9; uint8_t *samples = VAR_1; if (!VAR_5)
return 0; VAR_7 = AV_RL16(&VAR_4[0]); VAR_6 = AV_RL16(&VAR_4[2]); VAR_4 += 4; if (VAR_7 > *VAR_2) { av_log(VAR_0, AV_LOG_ERROR, "Frame is too large to fit in buffer\n"); return -1; } if (VAR_6 > VAR_5) { av_log(VAR_0, AV_LOG_ERROR, "Frame VAR_1 is larger than input buffer\n"); return -1; } *VAR_2 = VAR_7; if (VAR_6 == VAR_7) { for (VAR_9 = 0; VAR_9 < VAR_7; VAR_9++) *samples++ = *VAR_4++; return VAR_5; } while (VAR_7 > 0) { int VAR_10; uint8_t count; VAR_10 = (*VAR_4) >> 6; count = (*VAR_4) & 0x3F; VAR_4++; switch(VAR_10) { case 0:
for (count++; count > 0; count--) { VAR_10 = *VAR_4++; VAR_8 += ws_adpcm_2bit[VAR_10 & 0x3]; VAR_8 = av_clip_uint8(VAR_8); *samples++ = VAR_8; VAR_8 += ws_adpcm_2bit[(VAR_10 >> 2) & 0x3]; VAR_8 = av_clip_uint8(VAR_8); *samples++ = VAR_8; VAR_8 += ws_adpcm_2bit[(VAR_10 >> 4) & 0x3]; VAR_8 = av_clip_uint8(VAR_8); *samples++ = VAR_8; VAR_8 += ws_adpcm_2bit[(VAR_10 >> 6) & 0x3]; VAR_8 = av_clip_uint8(VAR_8); *samples++ = VAR_8; VAR_7 -= 4; } break; case 1:
for (count++; count > 0; count--) { VAR_10 = *VAR_4++; VAR_8 += ws_adpcm_4bit[VAR_10 & 0xF]; VAR_8 = av_clip_uint8(VAR_8); *samples++ = VAR_8; VAR_8 += ws_adpcm_4bit[VAR_10 >> 4]; VAR_8 = av_clip_uint8(VAR_8); *samples++ = VAR_8; VAR_7 -= 2; } break; case 2:
if (count & 0x20) { int8_t t; t = count; t <<= 3; VAR_8 += t >> 3; VAR_8 = av_clip_uint8(VAR_8); *samples++ = VAR_8; VAR_7--; } else { for (count++; count > 0; count--) { *samples++ = *VAR_4++; VAR_7--; } VAR_8 = VAR_4[-1]; } break; default:
for(count++; count > 0; count--) { *samples++ = VAR_8; VAR_7--; } } } return VAR_5; }