static int cmv_decode_frame(AVCodecContext *avctx,
                            void *data, int *data_size,
                            AVPacket *avpkt)
{
    const uint8_t *buf = avpkt->data;
    int buf_size = avpkt->size;
    CmvContext *s = avctx->priv_data;
    const uint8_t *buf_end = buf + buf_size;
    if (AV_RL32(buf)==MVIh_TAG||AV_RB32(buf)==MVIh_TAG) {
        cmv_process_header(s, buf+EA_PREAMBLE_SIZE, buf_end);
        return buf_size;
    }
    if (av_image_check_size(s->width, s->height, 0, s->avctx))
        return -1;
    /* shuffle */
    if (s->last2_frame.data[0])
        avctx->release_buffer(avctx, &s->last2_frame);
    FFSWAP(AVFrame, s->last_frame, s->last2_frame);
    FFSWAP(AVFrame, s->frame, s->last_frame);
    s->frame.reference = 1;
    s->frame.buffer_hints = FF_BUFFER_HINTS_VALID;
    if (avctx->get_buffer(avctx, &s->frame)<0) {
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
        return -1;
    }
    memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE);
    buf += EA_PREAMBLE_SIZE;
    if ((buf[0]&1)) {  // subtype
        cmv_decode_inter(s, buf+2, buf_end);
        s->frame.key_frame = 0;
        s->frame.pict_type = AV_PICTURE_TYPE_P;
    }else{
        s->frame.key_frame = 1;
        s->frame.pict_type = AV_PICTURE_TYPE_I;
        cmv_decode_intra(s, buf+2, buf_end);
    }
    *data_size = sizeof(AVFrame);
    *(AVFrame*)data = s->frame;
    return buf_size;
}
static int cmv_decode_frame(AVCodecContext *avctx,
                            void *data, int *data_size,
                            AVPacket *avpkt)
{
    const uint8_t *buf = avpkt->data;
    int buf_size = avpkt->size;
    CmvContext *s = avctx->priv_data;
    const uint8_t *buf_end = buf + buf_size;
    if (AV_RL32(buf)==MVIh_TAG||AV_RB32(buf)==MVIh_TAG) {
        cmv_process_header(s, buf+EA_PREAMBLE_SIZE, buf_end);
        return buf_size;
    }
    if (av_image_check_size(s->width, s->height, 0, s->avctx))
        return -1;
    
    if (s->last2_frame.data[0])
        avctx->release_buffer(avctx, &s->last2_frame);
    FFSWAP(AVFrame, s->last_frame, s->last2_frame);
    FFSWAP(AVFrame, s->frame, s->last_frame);
    s->frame.reference = 1;
    s->frame.buffer_hints = FF_BUFFER_HINTS_VALID;
    if (avctx->get_buffer(avctx, &s->frame)<0) {
        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
        return -1;
    }
    memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE);
    buf += EA_PREAMBLE_SIZE;
    if ((buf[0]&1)) {  
        cmv_decode_inter(s, buf+2, buf_end);
        s->frame.key_frame = 0;
        s->frame.pict_type = AV_PICTURE_TYPE_P;
    }else{
        s->frame.key_frame = 1;
        s->frame.pict_type = AV_PICTURE_TYPE_I;
        cmv_decode_intra(s, buf+2, buf_end);
    }
    *data_size = sizeof(AVFrame);
    *(AVFrame*)data = s->frame;
    return buf_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;
    CmvContext *s = VAR_0->priv_data;
    const uint8_t *VAR_6 = VAR_4 + VAR_5;
    if (AV_RL32(VAR_4)==MVIh_TAG||AV_RB32(VAR_4)==MVIh_TAG) {
        cmv_process_header(s, VAR_4+EA_PREAMBLE_SIZE, VAR_6);
        return VAR_5;
    }
    if (av_image_check_size(s->width, s->height, 0, s->VAR_0))
        return -1;
    
    if (s->last2_frame.VAR_1[0])
        VAR_0->release_buffer(VAR_0, &s->last2_frame);
    FFSWAP(AVFrame, s->last_frame, s->last2_frame);
    FFSWAP(AVFrame, s->frame, s->last_frame);
    s->frame.reference = 1;
    s->frame.buffer_hints = FF_BUFFER_HINTS_VALID;
    if (VAR_0->get_buffer(VAR_0, &s->frame)<0) {
        av_log(VAR_0, AV_LOG_ERROR, "get_buffer() failed\n");
        return -1;
    }
    memcpy(s->frame.VAR_1[1], s->palette, AVPALETTE_SIZE);
    VAR_4 += EA_PREAMBLE_SIZE;
    if ((VAR_4[0]&1)) {  
        cmv_decode_inter(s, VAR_4+2, VAR_6);
        s->frame.key_frame = 0;
        s->frame.pict_type = AV_PICTURE_TYPE_P;
    }else{
        s->frame.key_frame = 1;
        s->frame.pict_type = AV_PICTURE_TYPE_I;
        cmv_decode_intra(s, VAR_4+2, VAR_6);
    }
    *VAR_2 = sizeof(AVFrame);
    *(AVFrame*)VAR_1 = s->frame;
    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; CmvContext *s = VAR_0->priv_data; const uint8_t *VAR_6 = VAR_4 + VAR_5; if (AV_RL32(VAR_4)==MVIh_TAG||AV_RB32(VAR_4)==MVIh_TAG) { cmv_process_header(s, VAR_4+EA_PREAMBLE_SIZE, VAR_6); return VAR_5; } if (av_image_check_size(s->width, s->height, 0, s->VAR_0))
return -1; if (s->last2_frame.VAR_1[0])
VAR_0->release_buffer(VAR_0, &s->last2_frame); FFSWAP(AVFrame, s->last_frame, s->last2_frame); FFSWAP(AVFrame, s->frame, s->last_frame); s->frame.reference = 1; s->frame.buffer_hints = FF_BUFFER_HINTS_VALID; if (VAR_0->get_buffer(VAR_0, &s->frame)<0) { av_log(VAR_0, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } memcpy(s->frame.VAR_1[1], s->palette, AVPALETTE_SIZE); VAR_4 += EA_PREAMBLE_SIZE; if ((VAR_4[0]&1)) { cmv_decode_inter(s, VAR_4+2, VAR_6); s->frame.key_frame = 0; s->frame.pict_type = AV_PICTURE_TYPE_P; }else{ s->frame.key_frame = 1; s->frame.pict_type = AV_PICTURE_TYPE_I; cmv_decode_intra(s, VAR_4+2, VAR_6); } *VAR_2 = sizeof(AVFrame); *(AVFrame*)VAR_1 = s->frame; return VAR_5; }