int ff_rv34_decode_frame(AVCodecContext *avctx,

                            void *data, int *data_size,

                            uint8_t *buf, int buf_size)

{

    RV34DecContext *r = avctx->priv_data;

    MpegEncContext *s = &r->s;

    AVFrame *pict = data;

    SliceInfo si;

    int i;

    int slice_count;

    uint8_t *slices_hdr = NULL;

    int last = 0;



    /* no supplementary picture */

    if (buf_size == 0) {

        /* special case for last picture */

        if (s->low_delay==0 && s->next_picture_ptr) {

            *pict= *(AVFrame*)s->next_picture_ptr;

            s->next_picture_ptr= NULL;



            *data_size = sizeof(AVFrame);

        }

        return 0;

    }



    if(!avctx->slice_count){

        slice_count = (*buf++) + 1;

        slices_hdr = buf + 4;

        buf += 8 * slice_count;

    }else

        slice_count = avctx->slice_count;



    for(i=0; i<slice_count; i++){

        int offset= get_slice_offset(avctx, slices_hdr, i);

        int size;

        if(i+1 == slice_count)

            size= buf_size - offset;

        else

            size= get_slice_offset(avctx, slices_hdr, i+1) - offset;



        r->si.end = s->mb_width * s->mb_height;

        if(i+1 < slice_count){

            init_get_bits(&s->gb, buf+get_slice_offset(avctx, slices_hdr, i+1), (buf_size-get_slice_offset(avctx, slices_hdr, i+1))*8);

            if(r->parse_slice_header(r, &r->s.gb, &si) < 0){

                if(i+2 < slice_count)

                    size = get_slice_offset(avctx, slices_hdr, i+2) - offset;

                else

                    size = buf_size - offset;

            }else

                r->si.end = si.start;

        }

        last = rv34_decode_slice(r, r->si.end, buf + offset, size);

        s->mb_num_left = r->s.mb_x + r->s.mb_y*r->s.mb_width - r->si.start;

        if(last)

            break;

    }



    if(last){

        if(r->loop_filter)

            r->loop_filter(r);

        ff_er_frame_end(s);

        MPV_frame_end(s);

        if (s->pict_type == FF_B_TYPE || s->low_delay) {

            *pict= *(AVFrame*)s->current_picture_ptr;

        } else if (s->last_picture_ptr != NULL) {

            *pict= *(AVFrame*)s->last_picture_ptr;

        }



        if(s->last_picture_ptr || s->low_delay){

            *data_size = sizeof(AVFrame);

            ff_print_debug_info(s, pict);

        }

        s->current_picture_ptr= NULL; //so we can detect if frame_end wasnt called (find some nicer solution...)

    }

    return buf_size;

}

int ff_rv34_decode_frame(AVCodecContext *avctx,

                            void *data, int *data_size,

                            uint8_t *buf, int buf_size)

{

    RV34DecContext *r = avctx->priv_data;

    MpegEncContext *s = &r->s;

    AVFrame *pict = data;

    SliceInfo si;

    int i;

    int slice_count;

    uint8_t *slices_hdr = NULL;

    int last = 0;



    

    if (buf_size == 0) {

        

        if (s->low_delay==0 && s->next_picture_ptr) {

            *pict= *(AVFrame*)s->next_picture_ptr;

            s->next_picture_ptr= NULL;



            *data_size = sizeof(AVFrame);

        }

        return 0;

    }



    if(!avctx->slice_count){

        slice_count = (*buf++) + 1;

        slices_hdr = buf + 4;

        buf += 8 * slice_count;

    }else

        slice_count = avctx->slice_count;



    for(i=0; i<slice_count; i++){

        int offset= get_slice_offset(avctx, slices_hdr, i);

        int size;

        if(i+1 == slice_count)

            size= buf_size - offset;

        else

            size= get_slice_offset(avctx, slices_hdr, i+1) - offset;



        r->si.end = s->mb_width * s->mb_height;

        if(i+1 < slice_count){

            init_get_bits(&s->gb, buf+get_slice_offset(avctx, slices_hdr, i+1), (buf_size-get_slice_offset(avctx, slices_hdr, i+1))*8);

            if(r->parse_slice_header(r, &r->s.gb, &si) < 0){

                if(i+2 < slice_count)

                    size = get_slice_offset(avctx, slices_hdr, i+2) - offset;

                else

                    size = buf_size - offset;

            }else

                r->si.end = si.start;

        }

        last = rv34_decode_slice(r, r->si.end, buf + offset, size);

        s->mb_num_left = r->s.mb_x + r->s.mb_y*r->s.mb_width - r->si.start;

        if(last)

            break;

    }



    if(last){

        if(r->loop_filter)

            r->loop_filter(r);

        ff_er_frame_end(s);

        MPV_frame_end(s);

        if (s->pict_type == FF_B_TYPE || s->low_delay) {

            *pict= *(AVFrame*)s->current_picture_ptr;

        } else if (s->last_picture_ptr != NULL) {

            *pict= *(AVFrame*)s->last_picture_ptr;

        }



        if(s->last_picture_ptr || s->low_delay){

            *data_size = sizeof(AVFrame);

            ff_print_debug_info(s, pict);

        }

        s->current_picture_ptr= NULL; 

    }

    return buf_size;

}

int FUNC_0(AVCodecContext *VAR_0,

                            void *VAR_1, int *VAR_2,

                            uint8_t *VAR_3, int VAR_4)

{

    RV34DecContext *r = VAR_0->priv_data;

    MpegEncContext *s = &r->s;

    AVFrame *pict = VAR_1;

    SliceInfo si;

    int VAR_5;

    int VAR_6;

    uint8_t *slices_hdr = NULL;

    int VAR_7 = 0;



    

    if (VAR_4 == 0) {

        

        if (s->low_delay==0 && s->next_picture_ptr) {

            *pict= *(AVFrame*)s->next_picture_ptr;

            s->next_picture_ptr= NULL;



            *VAR_2 = sizeof(AVFrame);

        }

        return 0;

    }



    if(!VAR_0->VAR_6){

        VAR_6 = (*VAR_3++) + 1;

        slices_hdr = VAR_3 + 4;

        VAR_3 += 8 * VAR_6;

    }else

        VAR_6 = VAR_0->VAR_6;



    for(VAR_5=0; VAR_5<VAR_6; VAR_5++){

        int VAR_8= get_slice_offset(VAR_0, slices_hdr, VAR_5);

        int VAR_9;

        if(VAR_5+1 == VAR_6)

            VAR_9= VAR_4 - VAR_8;

        else

            VAR_9= get_slice_offset(VAR_0, slices_hdr, VAR_5+1) - VAR_8;



        r->si.end = s->mb_width * s->mb_height;

        if(VAR_5+1 < VAR_6){

            init_get_bits(&s->gb, VAR_3+get_slice_offset(VAR_0, slices_hdr, VAR_5+1), (VAR_4-get_slice_offset(VAR_0, slices_hdr, VAR_5+1))*8);

            if(r->parse_slice_header(r, &r->s.gb, &si) < 0){

                if(VAR_5+2 < VAR_6)

                    VAR_9 = get_slice_offset(VAR_0, slices_hdr, VAR_5+2) - VAR_8;

                else

                    VAR_9 = VAR_4 - VAR_8;

            }else

                r->si.end = si.start;

        }

        VAR_7 = rv34_decode_slice(r, r->si.end, VAR_3 + VAR_8, VAR_9);

        s->mb_num_left = r->s.mb_x + r->s.mb_y*r->s.mb_width - r->si.start;

        if(VAR_7)

            break;

    }



    if(VAR_7){

        if(r->loop_filter)

            r->loop_filter(r);

        ff_er_frame_end(s);

        MPV_frame_end(s);

        if (s->pict_type == FF_B_TYPE || s->low_delay) {

            *pict= *(AVFrame*)s->current_picture_ptr;

        } else if (s->last_picture_ptr != NULL) {

            *pict= *(AVFrame*)s->last_picture_ptr;

        }



        if(s->last_picture_ptr || s->low_delay){

            *VAR_2 = sizeof(AVFrame);

            ff_print_debug_info(s, pict);

        }

        s->current_picture_ptr= NULL; 

    }

    return VAR_4;

}

int FUNC_0(AVCodecContext *VAR_0,
void *VAR_1, int *VAR_2,
uint8_t *VAR_3, int VAR_4)
{ RV34DecContext *r = VAR_0->priv_data; MpegEncContext *s = &r->s; AVFrame *pict = VAR_1; SliceInfo si; int VAR_5; int VAR_6; uint8_t *slices_hdr = NULL; int VAR_7 = 0; if (VAR_4 == 0) { if (s->low_delay==0 && s->next_picture_ptr) { *pict= *(AVFrame*)s->next_picture_ptr; s->next_picture_ptr= NULL; *VAR_2 = sizeof(AVFrame); } return 0; } if(!VAR_0->VAR_6){ VAR_6 = (*VAR_3++) + 1; slices_hdr = VAR_3 + 4; VAR_3 += 8 * VAR_6; }else VAR_6 = VAR_0->VAR_6; for(VAR_5=0; VAR_5<VAR_6; VAR_5++){ int VAR_8= get_slice_offset(VAR_0, slices_hdr, VAR_5); int VAR_9; if(VAR_5+1 == VAR_6)
VAR_9= VAR_4 - VAR_8; else
VAR_9= get_slice_offset(VAR_0, slices_hdr, VAR_5+1) - VAR_8; r->si.end = s->mb_width * s->mb_height; if(VAR_5+1 < VAR_6){ init_get_bits(&s->gb, VAR_3+get_slice_offset(VAR_0, slices_hdr, VAR_5+1), (VAR_4-get_slice_offset(VAR_0, slices_hdr, VAR_5+1))*8); if(r->parse_slice_header(r, &r->s.gb, &si) < 0){ if(VAR_5+2 < VAR_6)
VAR_9 = get_slice_offset(VAR_0, slices_hdr, VAR_5+2) - VAR_8; else
VAR_9 = VAR_4 - VAR_8; }else r->si.end = si.start; } VAR_7 = rv34_decode_slice(r, r->si.end, VAR_3 + VAR_8, VAR_9); s->mb_num_left = r->s.mb_x + r->s.mb_y*r->s.mb_width - r->si.start; if(VAR_7)
break; } if(VAR_7){ if(r->loop_filter)
r->loop_filter(r); ff_er_frame_end(s); MPV_frame_end(s); if (s->pict_type == FF_B_TYPE || s->low_delay) { *pict= *(AVFrame*)s->current_picture_ptr; } else if (s->last_picture_ptr != NULL) { *pict= *(AVFrame*)s->last_picture_ptr; } if(s->last_picture_ptr || s->low_delay){ *VAR_2 = sizeof(AVFrame); ff_print_debug_info(s, pict); } s->current_picture_ptr= NULL; } return VAR_4; }