int ff_mpeg4_decode_video_packet_header(MpegEncContext *s)

{

    int mb_num_bits= av_log2(s->mb_num - 1) + 1;

    int header_extension=0, mb_num, len;



    /* is there enough space left for a video packet + header */

    if( get_bits_count(&s->gb) > s->gb.size_in_bits-20) return -1;



    for(len=0; len<32; len++){

        if(get_bits1(&s->gb)) break;

    }



    if(len!=ff_mpeg4_get_video_packet_prefix_length(s)){

        av_log(s->avctx, AV_LOG_ERROR, "marker does not match f_code\n");

        return -1;

    }



    if(s->shape != RECT_SHAPE){

        header_extension= get_bits1(&s->gb);

        //FIXME more stuff here

    }



    mb_num= get_bits(&s->gb, mb_num_bits);

    if(mb_num>=s->mb_num){

        av_log(s->avctx, AV_LOG_ERROR, "illegal mb_num in video packet (%d %d) \n", mb_num, s->mb_num);

        return -1;

    }

    if(s->pict_type == AV_PICTURE_TYPE_B){

        int mb_x = 0, mb_y = 0;



        while (s->next_picture.mbskip_table[s->mb_index2xy[mb_num]]) {

            if (!mb_x)

                ff_thread_await_progress(&s->next_picture_ptr->tf, mb_y++, 0);

            mb_num++;

            if (++mb_x == s->mb_width) mb_x = 0;

        }

        if(mb_num >= s->mb_num) return -1; // slice contains just skipped MBs which where already decoded

    }



    s->mb_x= mb_num % s->mb_width;

    s->mb_y= mb_num / s->mb_width;



    if(s->shape != BIN_ONLY_SHAPE){

        int qscale= get_bits(&s->gb, s->quant_precision);

        if(qscale)

            s->chroma_qscale=s->qscale= qscale;

    }



    if(s->shape == RECT_SHAPE){

        header_extension= get_bits1(&s->gb);

    }

    if(header_extension){

        int time_incr=0;



        while (get_bits1(&s->gb) != 0)

            time_incr++;



        check_marker(&s->gb, "before time_increment in video packed header");

        skip_bits(&s->gb, s->time_increment_bits); /* time_increment */

        check_marker(&s->gb, "before vop_coding_type in video packed header");



        skip_bits(&s->gb, 2); /* vop coding type */

        //FIXME not rect stuff here



        if(s->shape != BIN_ONLY_SHAPE){

            skip_bits(&s->gb, 3); /* intra dc vlc threshold */

//FIXME don't just ignore everything

            if(s->pict_type == AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE){

                mpeg4_decode_sprite_trajectory(s, &s->gb);

                av_log(s->avctx, AV_LOG_ERROR, "untested\n");

            }



            //FIXME reduced res stuff here



            if (s->pict_type != AV_PICTURE_TYPE_I) {

                int f_code = get_bits(&s->gb, 3);       /* fcode_for */

                if(f_code==0){

                    av_log(s->avctx, AV_LOG_ERROR, "Error, video packet header damaged (f_code=0)\n");

                }

            }

            if (s->pict_type == AV_PICTURE_TYPE_B) {

                int b_code = get_bits(&s->gb, 3);

                if(b_code==0){

                    av_log(s->avctx, AV_LOG_ERROR, "Error, video packet header damaged (b_code=0)\n");

                }

            }

        }

    }

    //FIXME new-pred stuff



    return 0;

}

int ff_mpeg4_decode_video_packet_header(MpegEncContext *s)

{

    int mb_num_bits= av_log2(s->mb_num - 1) + 1;

    int header_extension=0, mb_num, len;



    

    if( get_bits_count(&s->gb) > s->gb.size_in_bits-20) return -1;



    for(len=0; len<32; len++){

        if(get_bits1(&s->gb)) break;

    }



    if(len!=ff_mpeg4_get_video_packet_prefix_length(s)){

        av_log(s->avctx, AV_LOG_ERROR, "marker does not match f_code\n");

        return -1;

    }



    if(s->shape != RECT_SHAPE){

        header_extension= get_bits1(&s->gb);

        

    }



    mb_num= get_bits(&s->gb, mb_num_bits);

    if(mb_num>=s->mb_num){

        av_log(s->avctx, AV_LOG_ERROR, "illegal mb_num in video packet (%d %d) \n", mb_num, s->mb_num);

        return -1;

    }

    if(s->pict_type == AV_PICTURE_TYPE_B){

        int mb_x = 0, mb_y = 0;



        while (s->next_picture.mbskip_table[s->mb_index2xy[mb_num]]) {

            if (!mb_x)

                ff_thread_await_progress(&s->next_picture_ptr->tf, mb_y++, 0);

            mb_num++;

            if (++mb_x == s->mb_width) mb_x = 0;

        }

        if(mb_num >= s->mb_num) return -1; 

    }



    s->mb_x= mb_num % s->mb_width;

    s->mb_y= mb_num / s->mb_width;



    if(s->shape != BIN_ONLY_SHAPE){

        int qscale= get_bits(&s->gb, s->quant_precision);

        if(qscale)

            s->chroma_qscale=s->qscale= qscale;

    }



    if(s->shape == RECT_SHAPE){

        header_extension= get_bits1(&s->gb);

    }

    if(header_extension){

        int time_incr=0;



        while (get_bits1(&s->gb) != 0)

            time_incr++;



        check_marker(&s->gb, "before time_increment in video packed header");

        skip_bits(&s->gb, s->time_increment_bits); 

        check_marker(&s->gb, "before vop_coding_type in video packed header");



        skip_bits(&s->gb, 2); 

        



        if(s->shape != BIN_ONLY_SHAPE){

            skip_bits(&s->gb, 3); 



            if(s->pict_type == AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE){

                mpeg4_decode_sprite_trajectory(s, &s->gb);

                av_log(s->avctx, AV_LOG_ERROR, "untested\n");

            }



            



            if (s->pict_type != AV_PICTURE_TYPE_I) {

                int f_code = get_bits(&s->gb, 3);       

                if(f_code==0){

                    av_log(s->avctx, AV_LOG_ERROR, "Error, video packet header damaged (f_code=0)\n");

                }

            }

            if (s->pict_type == AV_PICTURE_TYPE_B) {

                int b_code = get_bits(&s->gb, 3);

                if(b_code==0){

                    av_log(s->avctx, AV_LOG_ERROR, "Error, video packet header damaged (b_code=0)\n");

                }

            }

        }

    }

    



    return 0;

}

                mpeg4_decode_sprite_trajectory(s, &s->gb);
int FUNC_0(MpegEncContext *VAR_0)

{

    int VAR_1= av_log2(VAR_0->VAR_3 - 1) + 1;

    int VAR_2=0, VAR_3, VAR_4;



    

    if( get_bits_count(&VAR_0->gb) > VAR_0->gb.size_in_bits-20) return -1;



    for(VAR_4=0; VAR_4<32; VAR_4++){

        if(get_bits1(&VAR_0->gb)) break;

    }



    if(VAR_4!=ff_mpeg4_get_video_packet_prefix_length(VAR_0)){

        av_log(VAR_0->avctx, AV_LOG_ERROR, "marker does not match VAR_9\n");

        return -1;

    }



    if(VAR_0->shape != RECT_SHAPE){

        VAR_2= get_bits1(&VAR_0->gb);

        

    }



    VAR_3= get_bits(&VAR_0->gb, VAR_1);

    if(VAR_3>=VAR_0->VAR_3){

        av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal VAR_3 in video packet (%d %d) \n", VAR_3, VAR_0->VAR_3);

        return -1;

    }

    if(VAR_0->pict_type == AV_PICTURE_TYPE_B){

        int VAR_5 = 0, VAR_6 = 0;



        while (VAR_0->next_picture.mbskip_table[VAR_0->mb_index2xy[VAR_3]]) {

            if (!VAR_5)

                ff_thread_await_progress(&VAR_0->next_picture_ptr->tf, VAR_6++, 0);

            VAR_3++;

            if (++VAR_5 == VAR_0->mb_width) VAR_5 = 0;

        }

        if(VAR_3 >= VAR_0->VAR_3) return -1; 

    }



    VAR_0->VAR_5= VAR_3 % VAR_0->mb_width;

    VAR_0->VAR_6= VAR_3 / VAR_0->mb_width;



    if(VAR_0->shape != BIN_ONLY_SHAPE){

        int VAR_7= get_bits(&VAR_0->gb, VAR_0->quant_precision);

        if(VAR_7)

            VAR_0->chroma_qscale=VAR_0->VAR_7= VAR_7;

    }



    if(VAR_0->shape == RECT_SHAPE){

        VAR_2= get_bits1(&VAR_0->gb);

    }

    if(VAR_2){

        int VAR_8=0;



        while (get_bits1(&VAR_0->gb) != 0)

            VAR_8++;



        check_marker(&VAR_0->gb, "before time_increment in video packed header");

        skip_bits(&VAR_0->gb, VAR_0->time_increment_bits); 

        check_marker(&VAR_0->gb, "before vop_coding_type in video packed header");



        skip_bits(&VAR_0->gb, 2); 

        



        if(VAR_0->shape != BIN_ONLY_SHAPE){

            skip_bits(&VAR_0->gb, 3); 



            if(VAR_0->pict_type == AV_PICTURE_TYPE_S && VAR_0->vol_sprite_usage==GMC_SPRITE){

                mpeg4_decode_sprite_trajectory(VAR_0, &VAR_0->gb);

                av_log(VAR_0->avctx, AV_LOG_ERROR, "untested\n");

            }



            



            if (VAR_0->pict_type != AV_PICTURE_TYPE_I) {

                int VAR_9 = get_bits(&VAR_0->gb, 3);       

                if(VAR_9==0){

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "Error, video packet header damaged (VAR_9=0)\n");

                }

            }

            if (VAR_0->pict_type == AV_PICTURE_TYPE_B) {

                int VAR_10 = get_bits(&VAR_0->gb, 3);

                if(VAR_10==0){

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "Error, video packet header damaged (VAR_10=0)\n");

                }

            }

        }

    }

    



    return 0;

}

int FUNC_0(MpegEncContext *VAR_0)
{ int VAR_1= av_log2(VAR_0->VAR_3 - 1) + 1; int VAR_2=0, VAR_3, VAR_4; if( get_bits_count(&VAR_0->gb) > VAR_0->gb.size_in_bits-20) return -1; for(VAR_4=0; VAR_4<32; VAR_4++){ if(get_bits1(&VAR_0->gb)) break; } if(VAR_4!=ff_mpeg4_get_video_packet_prefix_length(VAR_0)){ av_log(VAR_0->avctx, AV_LOG_ERROR, "marker does not match VAR_9\n"); return -1; } if(VAR_0->shape != RECT_SHAPE){ VAR_2= get_bits1(&VAR_0->gb); } VAR_3= get_bits(&VAR_0->gb, VAR_1); if(VAR_3>=VAR_0->VAR_3){ av_log(VAR_0->avctx, AV_LOG_ERROR, "illegal VAR_3 in video packet (%d %d) \n", VAR_3, VAR_0->VAR_3); return -1; } if(VAR_0->pict_type == AV_PICTURE_TYPE_B){ int VAR_5 = 0, VAR_6 = 0; while (VAR_0->next_picture.mbskip_table[VAR_0->mb_index2xy[VAR_3]]) { if (!VAR_5)
ff_thread_await_progress(&VAR_0->next_picture_ptr->tf, VAR_6++, 0); VAR_3++; if (++VAR_5 == VAR_0->mb_width) VAR_5 = 0; } if(VAR_3 >= VAR_0->VAR_3) return -1; } VAR_0->VAR_5= VAR_3 % VAR_0->mb_width; VAR_0->VAR_6= VAR_3 / VAR_0->mb_width; if(VAR_0->shape != BIN_ONLY_SHAPE){ int VAR_7= get_bits(&VAR_0->gb, VAR_0->quant_precision); if(VAR_7)
VAR_0->chroma_qscale=VAR_0->VAR_7= VAR_7; } if(VAR_0->shape == RECT_SHAPE){ VAR_2= get_bits1(&VAR_0->gb); } if(VAR_2){ int VAR_8=0; while (get_bits1(&VAR_0->gb) != 0)
VAR_8++; check_marker(&VAR_0->gb, "before time_increment in video packed header"); skip_bits(&VAR_0->gb, VAR_0->time_increment_bits); check_marker(&VAR_0->gb, "before vop_coding_type in video packed header"); skip_bits(&VAR_0->gb, 2); if(VAR_0->shape != BIN_ONLY_SHAPE){ skip_bits(&VAR_0->gb, 3); if(VAR_0->pict_type == AV_PICTURE_TYPE_S && VAR_0->vol_sprite_usage==GMC_SPRITE){ mpeg4_decode_sprite_trajectory(VAR_0, &VAR_0->gb); av_log(VAR_0->avctx, AV_LOG_ERROR, "untested\n"); } if (VAR_0->pict_type != AV_PICTURE_TYPE_I) { int VAR_9 = get_bits(&VAR_0->gb, 3); if(VAR_9==0){ av_log(VAR_0->avctx, AV_LOG_ERROR, "Error, video packet header damaged (VAR_9=0)\n"); } } if (VAR_0->pict_type == AV_PICTURE_TYPE_B) { int VAR_10 = get_bits(&VAR_0->gb, 3); if(VAR_10==0){ av_log(VAR_0->avctx, AV_LOG_ERROR, "Error, video packet header damaged (VAR_10=0)\n"); } } } } return 0; }