static int vmdaudio_decode_frame(AVCodecContext *avctx,

                                 void *data, int *data_size,

                                 AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    VmdAudioContext *s = avctx->priv_data;

    int block_type;

    unsigned char *output_samples = (unsigned char *)data;



    if (buf_size < 16) {

        av_log(avctx, AV_LOG_WARNING, "skipping small junk packet\n");

        *data_size = 0;

        return buf_size;

    }



    block_type = buf[6];

    if (block_type < BLOCK_TYPE_AUDIO || block_type > BLOCK_TYPE_SILENCE) {

        av_log(avctx, AV_LOG_ERROR, "unknown block type: %d\n", block_type);

        return AVERROR(EINVAL);

    }

    buf      += 16;

    buf_size -= 16;



    if (block_type == BLOCK_TYPE_AUDIO) {

        /* the chunk contains audio */

        *data_size = vmdaudio_loadsound(s, output_samples, buf, 0, buf_size);

    } else if (block_type == BLOCK_TYPE_INITIAL) {

        /* initial chunk, may contain audio and silence */

        uint32_t flags = AV_RB32(buf);

        int silent_chunks = av_popcount(flags);

        buf      += 4;

        buf_size -= 4;

        if(*data_size < (s->block_align*silent_chunks + buf_size) * 2)

            return -1;

        *data_size = vmdaudio_loadsound(s, output_samples, buf, silent_chunks, buf_size);

    } else if (block_type == BLOCK_TYPE_SILENCE) {

        /* silent chunk */

        *data_size = vmdaudio_loadsound(s, output_samples, buf, 1, 0);

    }



    return avpkt->size;

}

static int vmdaudio_decode_frame(AVCodecContext *avctx,

                                 void *data, int *data_size,

                                 AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size = avpkt->size;

    VmdAudioContext *s = avctx->priv_data;

    int block_type;

    unsigned char *output_samples = (unsigned char *)data;



    if (buf_size < 16) {

        av_log(avctx, AV_LOG_WARNING, "skipping small junk packet\n");

        *data_size = 0;

        return buf_size;

    }



    block_type = buf[6];

    if (block_type < BLOCK_TYPE_AUDIO || block_type > BLOCK_TYPE_SILENCE) {

        av_log(avctx, AV_LOG_ERROR, "unknown block type: %d\n", block_type);

        return AVERROR(EINVAL);

    }

    buf      += 16;

    buf_size -= 16;



    if (block_type == BLOCK_TYPE_AUDIO) {

        

        *data_size = vmdaudio_loadsound(s, output_samples, buf, 0, buf_size);

    } else if (block_type == BLOCK_TYPE_INITIAL) {

        

        uint32_t flags = AV_RB32(buf);

        int silent_chunks = av_popcount(flags);

        buf      += 4;

        buf_size -= 4;

        if(*data_size < (s->block_align*silent_chunks + buf_size) * 2)

            return -1;

        *data_size = vmdaudio_loadsound(s, output_samples, buf, silent_chunks, buf_size);

    } else if (block_type == BLOCK_TYPE_SILENCE) {

        

        *data_size = vmdaudio_loadsound(s, output_samples, buf, 1, 0);

    }



    return avpkt->size;

}

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;

    VmdAudioContext *s = VAR_0->priv_data;

    int VAR_6;

    unsigned char *VAR_7 = (unsigned char *)VAR_1;



    if (VAR_5 < 16) {

        av_log(VAR_0, AV_LOG_WARNING, "skipping small junk packet\n");

        *VAR_2 = 0;

        return VAR_5;

    }



    VAR_6 = VAR_4[6];

    if (VAR_6 < BLOCK_TYPE_AUDIO || VAR_6 > BLOCK_TYPE_SILENCE) {

        av_log(VAR_0, AV_LOG_ERROR, "unknown block type: %d\n", VAR_6);

        return AVERROR(EINVAL);

    }

    VAR_4      += 16;

    VAR_5 -= 16;



    if (VAR_6 == BLOCK_TYPE_AUDIO) {

        

        *VAR_2 = vmdaudio_loadsound(s, VAR_7, VAR_4, 0, VAR_5);

    } else if (VAR_6 == BLOCK_TYPE_INITIAL) {

        

        uint32_t flags = AV_RB32(VAR_4);

        int VAR_8 = av_popcount(flags);

        VAR_4      += 4;

        VAR_5 -= 4;

        if(*VAR_2 < (s->block_align*VAR_8 + VAR_5) * 2)

            return -1;

        *VAR_2 = vmdaudio_loadsound(s, VAR_7, VAR_4, VAR_8, VAR_5);

    } else if (VAR_6 == BLOCK_TYPE_SILENCE) {

        

        *VAR_2 = vmdaudio_loadsound(s, VAR_7, VAR_4, 1, 0);

    }



    return VAR_3->size;

}

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; VmdAudioContext *s = VAR_0->priv_data; int VAR_6; unsigned char *VAR_7 = (unsigned char *)VAR_1; if (VAR_5 < 16) { av_log(VAR_0, AV_LOG_WARNING, "skipping small junk packet\n"); *VAR_2 = 0; return VAR_5; } VAR_6 = VAR_4[6]; if (VAR_6 < BLOCK_TYPE_AUDIO || VAR_6 > BLOCK_TYPE_SILENCE) { av_log(VAR_0, AV_LOG_ERROR, "unknown block type: %d\n", VAR_6); return AVERROR(EINVAL); } VAR_4      += 16; VAR_5 -= 16; if (VAR_6 == BLOCK_TYPE_AUDIO) { *VAR_2 = vmdaudio_loadsound(s, VAR_7, VAR_4, 0, VAR_5); } else if (VAR_6 == BLOCK_TYPE_INITIAL) { uint32_t flags = AV_RB32(VAR_4); int VAR_8 = av_popcount(flags); VAR_4      += 4; VAR_5 -= 4; if(*VAR_2 < (s->block_align*VAR_8 + VAR_5) * 2)
return -1; *VAR_2 = vmdaudio_loadsound(s, VAR_7, VAR_4, VAR_8, VAR_5); } else if (VAR_6 == BLOCK_TYPE_SILENCE) { *VAR_2 = vmdaudio_loadsound(s, VAR_7, VAR_4, 1, 0); } return VAR_3->size; }