static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size,

                             const uint8_t * buf, int buf_size) {

    AVSContext *h = avctx->priv_data;

    MpegEncContext *s = &h->s;

    int input_size;

    const uint8_t *buf_end;

    const uint8_t *buf_ptr;

    AVFrame *picture = data;

    uint32_t stc = -1;



    s->avctx = avctx;



    if (buf_size == 0) {

        if(!s->low_delay && h->DPB[0].data[0]) {

            *data_size = sizeof(AVPicture);

            *picture = *(AVFrame *) &h->DPB[0];

        }

        return 0;

    }



    buf_ptr = buf;

    buf_end = buf + buf_size;

    for(;;) {

        buf_ptr = ff_find_start_code(buf_ptr,buf_end, &stc);

        if(stc & 0xFFFFFE00)

            return FFMAX(0, buf_ptr - buf - s->parse_context.last_index);

        input_size = (buf_end - buf_ptr)*8;

        switch(stc) {

        case CAVS_START_CODE:

            init_get_bits(&s->gb, buf_ptr, input_size);

            decode_seq_header(h);

            break;

        case PIC_I_START_CODE:

            if(!h->got_keyframe) {

                if(h->DPB[0].data[0])

                    avctx->release_buffer(avctx, (AVFrame *)&h->DPB[0]);

                if(h->DPB[1].data[0])

                    avctx->release_buffer(avctx, (AVFrame *)&h->DPB[1]);

                h->got_keyframe = 1;

            }

        case PIC_PB_START_CODE:

            *data_size = 0;

            if(!h->got_keyframe)

                break;

            init_get_bits(&s->gb, buf_ptr, input_size);

            h->stc = stc;

            if(decode_pic(h))

                break;

            *data_size = sizeof(AVPicture);

            if(h->pic_type != FF_B_TYPE) {

                if(h->DPB[1].data[0]) {

                    *picture = *(AVFrame *) &h->DPB[1];

                } else {

                    *data_size = 0;

                }

            } else

                *picture = *(AVFrame *) &h->picture;

            break;

        case EXT_START_CODE:

            //mpeg_decode_extension(avctx,buf_ptr, input_size);

            break;

        case USER_START_CODE:

            //mpeg_decode_user_data(avctx,buf_ptr, input_size);

            break;

        default:

            if (stc >= SLICE_MIN_START_CODE &&

                stc <= SLICE_MAX_START_CODE) {

                init_get_bits(&s->gb, buf_ptr, input_size);

                decode_slice_header(h, &s->gb);

            }

            break;

        }

    }

}

static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size,

                             const uint8_t * buf, int buf_size) {

    AVSContext *h = avctx->priv_data;

    MpegEncContext *s = &h->s;

    int input_size;

    const uint8_t *buf_end;

    const uint8_t *buf_ptr;

    AVFrame *picture = data;

    uint32_t stc = -1;



    s->avctx = avctx;



    if (buf_size == 0) {

        if(!s->low_delay && h->DPB[0].data[0]) {

            *data_size = sizeof(AVPicture);

            *picture = *(AVFrame *) &h->DPB[0];

        }

        return 0;

    }



    buf_ptr = buf;

    buf_end = buf + buf_size;

    for(;;) {

        buf_ptr = ff_find_start_code(buf_ptr,buf_end, &stc);

        if(stc & 0xFFFFFE00)

            return FFMAX(0, buf_ptr - buf - s->parse_context.last_index);

        input_size = (buf_end - buf_ptr)*8;

        switch(stc) {

        case CAVS_START_CODE:

            init_get_bits(&s->gb, buf_ptr, input_size);

            decode_seq_header(h);

            break;

        case PIC_I_START_CODE:

            if(!h->got_keyframe) {

                if(h->DPB[0].data[0])

                    avctx->release_buffer(avctx, (AVFrame *)&h->DPB[0]);

                if(h->DPB[1].data[0])

                    avctx->release_buffer(avctx, (AVFrame *)&h->DPB[1]);

                h->got_keyframe = 1;

            }

        case PIC_PB_START_CODE:

            *data_size = 0;

            if(!h->got_keyframe)

                break;

            init_get_bits(&s->gb, buf_ptr, input_size);

            h->stc = stc;

            if(decode_pic(h))

                break;

            *data_size = sizeof(AVPicture);

            if(h->pic_type != FF_B_TYPE) {

                if(h->DPB[1].data[0]) {

                    *picture = *(AVFrame *) &h->DPB[1];

                } else {

                    *data_size = 0;

                }

            } else

                *picture = *(AVFrame *) &h->picture;

            break;

        case EXT_START_CODE:

            

            break;

        case USER_START_CODE:

            

            break;

        default:

            if (stc >= SLICE_MIN_START_CODE &&

                stc <= SLICE_MAX_START_CODE) {

                init_get_bits(&s->gb, buf_ptr, input_size);

                decode_slice_header(h, &s->gb);

            }

            break;

        }

    }

}

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

                             const uint8_t * VAR_3, int VAR_4) {

    AVSContext *h = VAR_0->priv_data;

    MpegEncContext *s = &h->s;

    int VAR_5;

    const uint8_t *VAR_6;

    const uint8_t *VAR_7;

    AVFrame *picture = VAR_1;

    uint32_t stc = -1;



    s->VAR_0 = VAR_0;



    if (VAR_4 == 0) {

        if(!s->low_delay && h->DPB[0].VAR_1[0]) {

            *VAR_2 = sizeof(AVPicture);

            *picture = *(AVFrame *) &h->DPB[0];

        }

        return 0;

    }



    VAR_7 = VAR_3;

    VAR_6 = VAR_3 + VAR_4;

    for(;;) {

        VAR_7 = ff_find_start_code(VAR_7,VAR_6, &stc);

        if(stc & 0xFFFFFE00)

            return FFMAX(0, VAR_7 - VAR_3 - s->parse_context.last_index);

        VAR_5 = (VAR_6 - VAR_7)*8;

        switch(stc) {

        case CAVS_START_CODE:

            init_get_bits(&s->gb, VAR_7, VAR_5);

            decode_seq_header(h);

            break;

        case PIC_I_START_CODE:

            if(!h->got_keyframe) {

                if(h->DPB[0].VAR_1[0])

                    VAR_0->release_buffer(VAR_0, (AVFrame *)&h->DPB[0]);

                if(h->DPB[1].VAR_1[0])

                    VAR_0->release_buffer(VAR_0, (AVFrame *)&h->DPB[1]);

                h->got_keyframe = 1;

            }

        case PIC_PB_START_CODE:

            *VAR_2 = 0;

            if(!h->got_keyframe)

                break;

            init_get_bits(&s->gb, VAR_7, VAR_5);

            h->stc = stc;

            if(decode_pic(h))

                break;

            *VAR_2 = sizeof(AVPicture);

            if(h->pic_type != FF_B_TYPE) {

                if(h->DPB[1].VAR_1[0]) {

                    *picture = *(AVFrame *) &h->DPB[1];

                } else {

                    *VAR_2 = 0;

                }

            } else

                *picture = *(AVFrame *) &h->picture;

            break;

        case EXT_START_CODE:

            

            break;

        case USER_START_CODE:

            

            break;

        default:

            if (stc >= SLICE_MIN_START_CODE &&

                stc <= SLICE_MAX_START_CODE) {

                init_get_bits(&s->gb, VAR_7, VAR_5);

                decode_slice_header(h, &s->gb);

            }

            break;

        }

    }

}

static int FUNC_0(AVCodecContext * VAR_0,void *VAR_1, int *VAR_2,
const uint8_t * VAR_3, int VAR_4) { AVSContext *h = VAR_0->priv_data; MpegEncContext *s = &h->s; int VAR_5; const uint8_t *VAR_6; const uint8_t *VAR_7; AVFrame *picture = VAR_1; uint32_t stc = -1; s->VAR_0 = VAR_0; if (VAR_4 == 0) { if(!s->low_delay && h->DPB[0].VAR_1[0]) { *VAR_2 = sizeof(AVPicture); *picture = *(AVFrame *) &h->DPB[0]; } return 0; } VAR_7 = VAR_3; VAR_6 = VAR_3 + VAR_4; for(;;) { VAR_7 = ff_find_start_code(VAR_7,VAR_6, &stc); if(stc & 0xFFFFFE00)
return FFMAX(0, VAR_7 - VAR_3 - s->parse_context.last_index); VAR_5 = (VAR_6 - VAR_7)*8; switch(stc) { case CAVS_START_CODE:
init_get_bits(&s->gb, VAR_7, VAR_5); decode_seq_header(h); break; case PIC_I_START_CODE:
if(!h->got_keyframe) { if(h->DPB[0].VAR_1[0])
VAR_0->release_buffer(VAR_0, (AVFrame *)&h->DPB[0]); if(h->DPB[1].VAR_1[0])
VAR_0->release_buffer(VAR_0, (AVFrame *)&h->DPB[1]); h->got_keyframe = 1; } case PIC_PB_START_CODE:
*VAR_2 = 0; if(!h->got_keyframe)
break; init_get_bits(&s->gb, VAR_7, VAR_5); h->stc = stc; if(decode_pic(h))
break; *VAR_2 = sizeof(AVPicture); if(h->pic_type != FF_B_TYPE) { if(h->DPB[1].VAR_1[0]) { *picture = *(AVFrame *) &h->DPB[1]; } else { *VAR_2 = 0; } } else *picture = *(AVFrame *) &h->picture; break; case EXT_START_CODE:
break; case USER_START_CODE:
break; default:
if (stc >= SLICE_MIN_START_CODE &&
stc <= SLICE_MAX_START_CODE) { init_get_bits(&s->gb, VAR_7, VAR_5); decode_slice_header(h, &s->gb); } break; } } }