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

                               int *got_frame_ptr, AVPacket *avpkt)

{

    WSSndContext *s = avctx->priv_data;

    const uint8_t *buf = avpkt->data;

    int buf_size       = avpkt->size;



    int in_size, out_size, ret;

    int sample = 128;

    uint8_t *samples;

    uint8_t *samples_end;



    if (!buf_size)

        return 0;



    if (buf_size < 4) {

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

        return AVERROR(EINVAL);

    }



    out_size = AV_RL16(&buf[0]);

    in_size  = AV_RL16(&buf[2]);

    buf += 4;



    if (in_size > buf_size) {

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

        return -1;

    }



    /* get output buffer */

    s->frame.nb_samples = out_size;

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

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

        return ret;

    }

    samples     = s->frame.data[0];

    samples_end = samples + out_size;



    if (in_size == out_size) {

        memcpy(samples, buf, out_size);

        *got_frame_ptr   = 1;

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

        return buf_size;

    }



    while (samples < samples_end && buf - avpkt->data < buf_size) {

        int code, smp, size;

        uint8_t count;

        code  = *buf >> 6;

        count = *buf & 0x3F;

        buf++;



        /* make sure we don't write past the output buffer */

        switch (code) {

        case 0:  smp = 4;                              break;

        case 1:  smp = 2;                              break;

        case 2:  smp = (count & 0x20) ? 1 : count + 1; break;

        default: smp = count + 1;                      break;

        }

        if (samples_end - samples < smp)

            break;



        /* make sure we don't read past the input buffer */

        size = ((code == 2 && (count & 0x20)) || code == 3) ? 0 : count + 1;

        if ((buf - avpkt->data) + size > buf_size)

            break;



        switch (code) {

        case 0: /* ADPCM 2-bit */

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

                code = *buf++;

                sample += ( code       & 0x3) - 2;

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                sample += ((code >> 2) & 0x3) - 2;

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                sample += ((code >> 4) & 0x3) - 2;

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                sample +=  (code >> 6)        - 2;

                sample = av_clip_uint8(sample);

                *samples++ = sample;

            }

            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;

            }

            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;

            } else { /* copy */

                memcpy(samples, buf, smp);

                samples += smp;

                buf     += smp;

                sample = buf[-1];

            }

            break;

        default: /* run */

            memset(samples, sample, smp);

            samples += smp;

        }

    }



    s->frame.nb_samples = samples - s->frame.data[0];

    *got_frame_ptr   = 1;

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



    return buf_size;

}

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

                               int *got_frame_ptr, AVPacket *avpkt)

{

    WSSndContext *s = avctx->priv_data;

    const uint8_t *buf = avpkt->data;

    int buf_size       = avpkt->size;



    int in_size, out_size, ret;

    int sample = 128;

    uint8_t *samples;

    uint8_t *samples_end;



    if (!buf_size)

        return 0;



    if (buf_size < 4) {

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

        return AVERROR(EINVAL);

    }



    out_size = AV_RL16(&buf[0]);

    in_size  = AV_RL16(&buf[2]);

    buf += 4;



    if (in_size > buf_size) {

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

        return -1;

    }



    

    s->frame.nb_samples = out_size;

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

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

        return ret;

    }

    samples     = s->frame.data[0];

    samples_end = samples + out_size;



    if (in_size == out_size) {

        memcpy(samples, buf, out_size);

        *got_frame_ptr   = 1;

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

        return buf_size;

    }



    while (samples < samples_end && buf - avpkt->data < buf_size) {

        int code, smp, size;

        uint8_t count;

        code  = *buf >> 6;

        count = *buf & 0x3F;

        buf++;



        

        switch (code) {

        case 0:  smp = 4;                              break;

        case 1:  smp = 2;                              break;

        case 2:  smp = (count & 0x20) ? 1 : count + 1; break;

        default: smp = count + 1;                      break;

        }

        if (samples_end - samples < smp)

            break;



        

        size = ((code == 2 && (count & 0x20)) || code == 3) ? 0 : count + 1;

        if ((buf - avpkt->data) + size > buf_size)

            break;



        switch (code) {

        case 0: 

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

                code = *buf++;

                sample += ( code       & 0x3) - 2;

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                sample += ((code >> 2) & 0x3) - 2;

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                sample += ((code >> 4) & 0x3) - 2;

                sample = av_clip_uint8(sample);

                *samples++ = sample;

                sample +=  (code >> 6)        - 2;

                sample = av_clip_uint8(sample);

                *samples++ = sample;

            }

            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;

            }

            break;

        case 2: 

            if (count & 0x20) { 

                int8_t t;

                t = count;

                t <<= 3;

                sample += t >> 3;

                sample = av_clip_uint8(sample);

                *samples++ = sample;

            } else { 

                memcpy(samples, buf, smp);

                samples += smp;

                buf     += smp;

                sample = buf[-1];

            }

            break;

        default: 

            memset(samples, sample, smp);

            samples += smp;

        }

    }



    s->frame.nb_samples = samples - s->frame.data[0];

    *got_frame_ptr   = 1;

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



    return buf_size;

}

        case 0:  smp = 4;                              break;         case 1:  smp = 2;                              break;
static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,

                               int *VAR_2, AVPacket *VAR_3)

{

    WSSndContext *s = VAR_0->priv_data;

    const uint8_t *VAR_4 = VAR_3->VAR_1;

    int VAR_5       = VAR_3->VAR_12;



    int VAR_6, VAR_7, VAR_8;

    int VAR_9 = 128;

    uint8_t *samples;

    uint8_t *samples_end;



    if (!VAR_5)

        return 0;



    if (VAR_5 < 4) {

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

        return AVERROR(EINVAL);

    }



    VAR_7 = AV_RL16(&VAR_4[0]);

    VAR_6  = AV_RL16(&VAR_4[2]);

    VAR_4 += 4;



    if (VAR_6 > VAR_5) {

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

        return -1;

    }



    

    s->frame.nb_samples = VAR_7;

    if ((VAR_8 = VAR_0->get_buffer(VAR_0, &s->frame)) < 0) {

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

        return VAR_8;

    }

    samples     = s->frame.VAR_1[0];

    samples_end = samples + VAR_7;



    if (VAR_6 == VAR_7) {

        memcpy(samples, VAR_4, VAR_7);

        *VAR_2   = 1;

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

        return VAR_5;

    }



    while (samples < samples_end && VAR_4 - VAR_3->VAR_1 < VAR_5) {

        int VAR_10, VAR_11, VAR_12;

        uint8_t count;

        VAR_10  = *VAR_4 >> 6;

        count = *VAR_4 & 0x3F;

        VAR_4++;



        

        switch (VAR_10) {

        case 0:  VAR_11 = 4;                              break;

        case 1:  VAR_11 = 2;                              break;

        case 2:  VAR_11 = (count & 0x20) ? 1 : count + 1; break;

        default: VAR_11 = count + 1;                      break;

        }

        if (samples_end - samples < VAR_11)

            break;



        

        VAR_12 = ((VAR_10 == 2 && (count & 0x20)) || VAR_10 == 3) ? 0 : count + 1;

        if ((VAR_4 - VAR_3->VAR_1) + VAR_12 > VAR_5)

            break;



        switch (VAR_10) {

        case 0: 

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

                VAR_10 = *VAR_4++;

                VAR_9 += ( VAR_10       & 0x3) - 2;

                VAR_9 = av_clip_uint8(VAR_9);

                *samples++ = VAR_9;

                VAR_9 += ((VAR_10 >> 2) & 0x3) - 2;

                VAR_9 = av_clip_uint8(VAR_9);

                *samples++ = VAR_9;

                VAR_9 += ((VAR_10 >> 4) & 0x3) - 2;

                VAR_9 = av_clip_uint8(VAR_9);

                *samples++ = VAR_9;

                VAR_9 +=  (VAR_10 >> 6)        - 2;

                VAR_9 = av_clip_uint8(VAR_9);

                *samples++ = VAR_9;

            }

            break;

        case 1: 

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

                VAR_10 = *VAR_4++;

                VAR_9 += ws_adpcm_4bit[VAR_10 & 0xF];

                VAR_9 = av_clip_uint8(VAR_9);

                *samples++ = VAR_9;

                VAR_9 += ws_adpcm_4bit[VAR_10 >> 4];

                VAR_9 = av_clip_uint8(VAR_9);

                *samples++ = VAR_9;

            }

            break;

        case 2: 

            if (count & 0x20) { 

                int8_t t;

                t = count;

                t <<= 3;

                VAR_9 += t >> 3;

                VAR_9 = av_clip_uint8(VAR_9);

                *samples++ = VAR_9;

            } else { 

                memcpy(samples, VAR_4, VAR_11);

                samples += VAR_11;

                VAR_4     += VAR_11;

                VAR_9 = VAR_4[-1];

            }

            break;

        default: 

            memset(samples, VAR_9, VAR_11);

            samples += VAR_11;

        }

    }



    s->frame.nb_samples = samples - s->frame.VAR_1[0];

    *VAR_2   = 1;

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



    return VAR_5;

}

static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,
int *VAR_2, AVPacket *VAR_3)
{ WSSndContext *s = VAR_0->priv_data; const uint8_t *VAR_4 = VAR_3->VAR_1; int VAR_5       = VAR_3->VAR_12; int VAR_6, VAR_7, VAR_8; int VAR_9 = 128; uint8_t *samples; uint8_t *samples_end; if (!VAR_5)
return 0; if (VAR_5 < 4) { av_log(VAR_0, AV_LOG_ERROR, "packet is too small\n"); return AVERROR(EINVAL); } VAR_7 = AV_RL16(&VAR_4[0]); VAR_6  = AV_RL16(&VAR_4[2]); VAR_4 += 4; if (VAR_6 > VAR_5) { av_log(VAR_0, AV_LOG_ERROR, "Frame VAR_1 is larger than input buffer\n"); return -1; } s->frame.nb_samples = VAR_7; if ((VAR_8 = VAR_0->get_buffer(VAR_0, &s->frame)) < 0) { av_log(VAR_0, AV_LOG_ERROR, "get_buffer() failed\n"); return VAR_8; } samples     = s->frame.VAR_1[0]; samples_end = samples + VAR_7; if (VAR_6 == VAR_7) { memcpy(samples, VAR_4, VAR_7); *VAR_2   = 1; *(AVFrame *)VAR_1 = s->frame; return VAR_5; } while (samples < samples_end && VAR_4 - VAR_3->VAR_1 < VAR_5) { int VAR_10, VAR_11, VAR_12; uint8_t count; VAR_10  = *VAR_4 >> 6; count = *VAR_4 & 0x3F; VAR_4++; switch (VAR_10) { case 0:  VAR_11 = 4;                              break; case 1:  VAR_11 = 2;                              break; case 2:  VAR_11 = (count & 0x20) ? 1 : count + 1; break; default: VAR_11 = count + 1;                      break; } if (samples_end - samples < VAR_11)
break; VAR_12 = ((VAR_10 == 2 && (count & 0x20)) || VAR_10 == 3) ? 0 : count + 1; if ((VAR_4 - VAR_3->VAR_1) + VAR_12 > VAR_5)
break; switch (VAR_10) { case 0:
for (count++; count > 0; count--) { VAR_10 = *VAR_4++; VAR_9 += ( VAR_10       & 0x3) - 2; VAR_9 = av_clip_uint8(VAR_9); *samples++ = VAR_9; VAR_9 += ((VAR_10 >> 2) & 0x3) - 2; VAR_9 = av_clip_uint8(VAR_9); *samples++ = VAR_9; VAR_9 += ((VAR_10 >> 4) & 0x3) - 2; VAR_9 = av_clip_uint8(VAR_9); *samples++ = VAR_9; VAR_9 +=  (VAR_10 >> 6)        - 2; VAR_9 = av_clip_uint8(VAR_9); *samples++ = VAR_9; } break; case 1:
for (count++; count > 0; count--) { VAR_10 = *VAR_4++; VAR_9 += ws_adpcm_4bit[VAR_10 & 0xF]; VAR_9 = av_clip_uint8(VAR_9); *samples++ = VAR_9; VAR_9 += ws_adpcm_4bit[VAR_10 >> 4]; VAR_9 = av_clip_uint8(VAR_9); *samples++ = VAR_9; } break; case 2:
if (count & 0x20) { int8_t t; t = count; t <<= 3; VAR_9 += t >> 3; VAR_9 = av_clip_uint8(VAR_9); *samples++ = VAR_9; } else { memcpy(samples, VAR_4, VAR_11); samples += VAR_11; VAR_4     += VAR_11; VAR_9 = VAR_4[-1]; } break; default:
memset(samples, VAR_9, VAR_11); samples += VAR_11; } } s->frame.nb_samples = samples - s->frame.VAR_1[0]; *VAR_2   = 1; *(AVFrame *)VAR_1 = s->frame; return VAR_5; }