static int decode_slice(MpegEncContext *s){

    const int part_mask= s->partitioned_frame ? (ER_AC_END|ER_AC_ERROR) : 0x7F;

    const int mb_size= 16>>s->avctx->lowres;

    int ret;



    s->last_resync_gb= s->gb;

    s->first_slice_line= 1;



    s->resync_mb_x= s->mb_x;

    s->resync_mb_y= s->mb_y;



    ff_set_qscale(s, s->qscale);



    if (s->avctx->hwaccel) {

        const uint8_t *start= s->gb.buffer + get_bits_count(&s->gb)/8;

        const uint8_t *end  = ff_h263_find_resync_marker(start + 1, s->gb.buffer_end);

        skip_bits_long(&s->gb, 8*(end - start));

        return s->avctx->hwaccel->decode_slice(s->avctx, start, end - start);

    }



    if(s->partitioned_frame){

        const int qscale= s->qscale;



        if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4){

            if ((ret = ff_mpeg4_decode_partitions(s)) < 0)

                return ret;

        }



        /* restore variables which were modified */

        s->first_slice_line=1;

        s->mb_x= s->resync_mb_x;

        s->mb_y= s->resync_mb_y;

        ff_set_qscale(s, qscale);

    }



    for(; s->mb_y < s->mb_height; s->mb_y++) {

        /* per-row end of slice checks */

        if(s->msmpeg4_version){

            if(s->resync_mb_y + s->slice_height == s->mb_y){

                ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END);



                return 0;

            }

        }



        if(s->msmpeg4_version==1){

            s->last_dc[0]=

            s->last_dc[1]=

            s->last_dc[2]= 128;

        }



        ff_init_block_index(s);

        for(; s->mb_x < s->mb_width; s->mb_x++) {

            int ret;



            ff_update_block_index(s);



            if(s->resync_mb_x == s->mb_x && s->resync_mb_y+1 == s->mb_y){

                s->first_slice_line=0;

            }



            /* DCT & quantize */



            s->mv_dir = MV_DIR_FORWARD;

            s->mv_type = MV_TYPE_16X16;

//            s->mb_skipped = 0;

            av_dlog(s, "%d %d %06X\n",

                    ret, get_bits_count(&s->gb), show_bits(&s->gb, 24));

            ret= s->decode_mb(s, s->block);



            if (s->pict_type!=AV_PICTURE_TYPE_B)

                ff_h263_update_motion_val(s);



            if(ret<0){

                const int xy= s->mb_x + s->mb_y*s->mb_stride;

                if(ret==SLICE_END){

                    ff_MPV_decode_mb(s, s->block);

                    if(s->loop_filter)

                        ff_h263_loop_filter(s);



                    ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_END&part_mask);



                    s->padding_bug_score--;



                    if(++s->mb_x >= s->mb_width){

                        s->mb_x=0;

                        ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size);

                        ff_MPV_report_decode_progress(s);

                        s->mb_y++;

                    }

                    return 0;

                }else if(ret==SLICE_NOEND){

                    av_log(s->avctx, AV_LOG_ERROR, "Slice mismatch at MB: %d\n", xy);

                    ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x+1, s->mb_y, ER_MB_END&part_mask);

                    return AVERROR_INVALIDDATA;

                }

                av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy);

                ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR&part_mask);



                return AVERROR_INVALIDDATA;

            }



            ff_MPV_decode_mb(s, s->block);

            if(s->loop_filter)

                ff_h263_loop_filter(s);

        }



        ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size);

        ff_MPV_report_decode_progress(s);



        s->mb_x= 0;

    }



    assert(s->mb_x==0 && s->mb_y==s->mb_height);



    if(s->codec_id==AV_CODEC_ID_MPEG4

       && (s->workaround_bugs&FF_BUG_AUTODETECT)

       && get_bits_left(&s->gb) >= 48

       && show_bits(&s->gb, 24)==0x4010

       && !s->data_partitioning)

        s->padding_bug_score+=32;



    /* try to detect the padding bug */

    if(      s->codec_id==AV_CODEC_ID_MPEG4

       &&   (s->workaround_bugs&FF_BUG_AUTODETECT)

       &&    get_bits_left(&s->gb) >=0

       &&    get_bits_left(&s->gb) < 137

//       &&   !s->resync_marker

       &&   !s->data_partitioning){



        const int bits_count= get_bits_count(&s->gb);

        const int bits_left = s->gb.size_in_bits - bits_count;



        if(bits_left==0){

            s->padding_bug_score+=16;

        } else if(bits_left != 1){

            int v= show_bits(&s->gb, 8);

            v|= 0x7F >> (7-(bits_count&7));



            if(v==0x7F && bits_left<=8)

                s->padding_bug_score--;

            else if(v==0x7F && ((get_bits_count(&s->gb)+8)&8) && bits_left<=16)

                s->padding_bug_score+= 4;

            else

                s->padding_bug_score++;

        }

    }



    if(s->workaround_bugs&FF_BUG_AUTODETECT){

        if(s->padding_bug_score > -2 && !s->data_partitioning /*&& (s->divx_version>=0 || !s->resync_marker)*/)

            s->workaround_bugs |=  FF_BUG_NO_PADDING;

        else

            s->workaround_bugs &= ~FF_BUG_NO_PADDING;

    }



    // handle formats which don't have unique end markers

    if(s->msmpeg4_version || (s->workaround_bugs&FF_BUG_NO_PADDING)){ //FIXME perhaps solve this more cleanly

        int left= get_bits_left(&s->gb);

        int max_extra=7;



        /* no markers in M$ crap */

        if(s->msmpeg4_version && s->pict_type==AV_PICTURE_TYPE_I)

            max_extra+= 17;



        /* buggy padding but the frame should still end approximately at the bitstream end */

        if((s->workaround_bugs&FF_BUG_NO_PADDING) && (s->err_recognition&(AV_EF_BUFFER|AV_EF_AGGRESSIVE)))

            max_extra+= 48;

        else if((s->workaround_bugs&FF_BUG_NO_PADDING))

            max_extra+= 256*256*256*64;



        if(left>max_extra){

            av_log(s->avctx, AV_LOG_ERROR, "discarding %d junk bits at end, next would be %X\n", left, show_bits(&s->gb, 24));

        }

        else if(left<0){

            av_log(s->avctx, AV_LOG_ERROR, "overreading %d bits\n", -left);

        }else

            ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END);



        return 0;

    }



    av_log(s->avctx, AV_LOG_ERROR, "slice end not reached but screenspace end (%d left %06X, score= %d)\n",

            get_bits_left(&s->gb),

            show_bits(&s->gb, 24), s->padding_bug_score);



    ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_END&part_mask);



    return AVERROR_INVALIDDATA;

}

static int decode_slice(MpegEncContext *s){

    const int part_mask= s->partitioned_frame ? (ER_AC_END|ER_AC_ERROR) : 0x7F;

    const int mb_size= 16>>s->avctx->lowres;

    int ret;



    s->last_resync_gb= s->gb;

    s->first_slice_line= 1;



    s->resync_mb_x= s->mb_x;

    s->resync_mb_y= s->mb_y;



    ff_set_qscale(s, s->qscale);



    if (s->avctx->hwaccel) {

        const uint8_t *start= s->gb.buffer + get_bits_count(&s->gb)/8;

        const uint8_t *end  = ff_h263_find_resync_marker(start + 1, s->gb.buffer_end);

        skip_bits_long(&s->gb, 8*(end - start));

        return s->avctx->hwaccel->decode_slice(s->avctx, start, end - start);

    }



    if(s->partitioned_frame){

        const int qscale= s->qscale;



        if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4){

            if ((ret = ff_mpeg4_decode_partitions(s)) < 0)

                return ret;

        }



        

        s->first_slice_line=1;

        s->mb_x= s->resync_mb_x;

        s->mb_y= s->resync_mb_y;

        ff_set_qscale(s, qscale);

    }



    for(; s->mb_y < s->mb_height; s->mb_y++) {

        

        if(s->msmpeg4_version){

            if(s->resync_mb_y + s->slice_height == s->mb_y){

                ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END);



                return 0;

            }

        }



        if(s->msmpeg4_version==1){

            s->last_dc[0]=

            s->last_dc[1]=

            s->last_dc[2]= 128;

        }



        ff_init_block_index(s);

        for(; s->mb_x < s->mb_width; s->mb_x++) {

            int ret;



            ff_update_block_index(s);



            if(s->resync_mb_x == s->mb_x && s->resync_mb_y+1 == s->mb_y){

                s->first_slice_line=0;

            }



            



            s->mv_dir = MV_DIR_FORWARD;

            s->mv_type = MV_TYPE_16X16;



            av_dlog(s, "%d %d %06X\n",

                    ret, get_bits_count(&s->gb), show_bits(&s->gb, 24));

            ret= s->decode_mb(s, s->block);



            if (s->pict_type!=AV_PICTURE_TYPE_B)

                ff_h263_update_motion_val(s);



            if(ret<0){

                const int xy= s->mb_x + s->mb_y*s->mb_stride;

                if(ret==SLICE_END){

                    ff_MPV_decode_mb(s, s->block);

                    if(s->loop_filter)

                        ff_h263_loop_filter(s);



                    ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_END&part_mask);



                    s->padding_bug_score--;



                    if(++s->mb_x >= s->mb_width){

                        s->mb_x=0;

                        ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size);

                        ff_MPV_report_decode_progress(s);

                        s->mb_y++;

                    }

                    return 0;

                }else if(ret==SLICE_NOEND){

                    av_log(s->avctx, AV_LOG_ERROR, "Slice mismatch at MB: %d\n", xy);

                    ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x+1, s->mb_y, ER_MB_END&part_mask);

                    return AVERROR_INVALIDDATA;

                }

                av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy);

                ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR&part_mask);



                return AVERROR_INVALIDDATA;

            }



            ff_MPV_decode_mb(s, s->block);

            if(s->loop_filter)

                ff_h263_loop_filter(s);

        }



        ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size);

        ff_MPV_report_decode_progress(s);



        s->mb_x= 0;

    }



    assert(s->mb_x==0 && s->mb_y==s->mb_height);



    if(s->codec_id==AV_CODEC_ID_MPEG4

       && (s->workaround_bugs&FF_BUG_AUTODETECT)

       && get_bits_left(&s->gb) >= 48

       && show_bits(&s->gb, 24)==0x4010

       && !s->data_partitioning)

        s->padding_bug_score+=32;



    

    if(      s->codec_id==AV_CODEC_ID_MPEG4

       &&   (s->workaround_bugs&FF_BUG_AUTODETECT)

       &&    get_bits_left(&s->gb) >=0

       &&    get_bits_left(&s->gb) < 137



       &&   !s->data_partitioning){



        const int bits_count= get_bits_count(&s->gb);

        const int bits_left = s->gb.size_in_bits - bits_count;



        if(bits_left==0){

            s->padding_bug_score+=16;

        } else if(bits_left != 1){

            int v= show_bits(&s->gb, 8);

            v|= 0x7F >> (7-(bits_count&7));



            if(v==0x7F && bits_left<=8)

                s->padding_bug_score--;

            else if(v==0x7F && ((get_bits_count(&s->gb)+8)&8) && bits_left<=16)

                s->padding_bug_score+= 4;

            else

                s->padding_bug_score++;

        }

    }



    if(s->workaround_bugs&FF_BUG_AUTODETECT){

        if(s->padding_bug_score > -2 && !s->data_partitioning )

            s->workaround_bugs |=  FF_BUG_NO_PADDING;

        else

            s->workaround_bugs &= ~FF_BUG_NO_PADDING;

    }



    

    if(s->msmpeg4_version || (s->workaround_bugs&FF_BUG_NO_PADDING)){ 

        int left= get_bits_left(&s->gb);

        int max_extra=7;



        

        if(s->msmpeg4_version && s->pict_type==AV_PICTURE_TYPE_I)

            max_extra+= 17;



        

        if((s->workaround_bugs&FF_BUG_NO_PADDING) && (s->err_recognition&(AV_EF_BUFFER|AV_EF_AGGRESSIVE)))

            max_extra+= 48;

        else if((s->workaround_bugs&FF_BUG_NO_PADDING))

            max_extra+= 256*256*256*64;



        if(left>max_extra){

            av_log(s->avctx, AV_LOG_ERROR, "discarding %d junk bits at end, next would be %X\n", left, show_bits(&s->gb, 24));

        }

        else if(left<0){

            av_log(s->avctx, AV_LOG_ERROR, "overreading %d bits\n", -left);

        }else

            ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END);



        return 0;

    }



    av_log(s->avctx, AV_LOG_ERROR, "slice end not reached but screenspace end (%d left %06X, score= %d)\n",

            get_bits_left(&s->gb),

            show_bits(&s->gb, 24), s->padding_bug_score);



    ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_END&part_mask);



    return AVERROR_INVALIDDATA;

}

static int FUNC_0(MpegEncContext *VAR_0){

    const int VAR_1= VAR_0->partitioned_frame ? (ER_AC_END|ER_AC_ERROR) : 0x7F;

    const int VAR_2= 16>>VAR_0->avctx->lowres;

    int VAR_3;



    VAR_0->last_resync_gb= VAR_0->gb;

    VAR_0->first_slice_line= 1;



    VAR_0->resync_mb_x= VAR_0->mb_x;

    VAR_0->resync_mb_y= VAR_0->mb_y;



    ff_set_qscale(VAR_0, VAR_0->VAR_6);



    if (VAR_0->avctx->hwaccel) {

        const uint8_t *VAR_4= VAR_0->gb.buffer + get_bits_count(&VAR_0->gb)/8;

        const uint8_t *VAR_5  = ff_h263_find_resync_marker(VAR_4 + 1, VAR_0->gb.buffer_end);

        skip_bits_long(&VAR_0->gb, 8*(VAR_5 - VAR_4));

        return VAR_0->avctx->hwaccel->FUNC_0(VAR_0->avctx, VAR_4, VAR_5 - VAR_4);

    }



    if(VAR_0->partitioned_frame){

        const int VAR_6= VAR_0->VAR_6;



        if(CONFIG_MPEG4_DECODER && VAR_0->codec_id==AV_CODEC_ID_MPEG4){

            if ((VAR_3 = ff_mpeg4_decode_partitions(VAR_0)) < 0)

                return VAR_3;

        }



        

        VAR_0->first_slice_line=1;

        VAR_0->mb_x= VAR_0->resync_mb_x;

        VAR_0->mb_y= VAR_0->resync_mb_y;

        ff_set_qscale(VAR_0, VAR_6);

    }



    for(; VAR_0->mb_y < VAR_0->mb_height; VAR_0->mb_y++) {

        

        if(VAR_0->msmpeg4_version){

            if(VAR_0->resync_mb_y + VAR_0->slice_height == VAR_0->mb_y){

                ff_er_add_slice(VAR_0, VAR_0->resync_mb_x, VAR_0->resync_mb_y, VAR_0->mb_x-1, VAR_0->mb_y, ER_MB_END);



                return 0;

            }

        }



        if(VAR_0->msmpeg4_version==1){

            VAR_0->last_dc[0]=

            VAR_0->last_dc[1]=

            VAR_0->last_dc[2]= 128;

        }



        ff_init_block_index(VAR_0);

        for(; VAR_0->mb_x < VAR_0->mb_width; VAR_0->mb_x++) {

            int VAR_3;



            ff_update_block_index(VAR_0);



            if(VAR_0->resync_mb_x == VAR_0->mb_x && VAR_0->resync_mb_y+1 == VAR_0->mb_y){

                VAR_0->first_slice_line=0;

            }



            



            VAR_0->mv_dir = MV_DIR_FORWARD;

            VAR_0->mv_type = MV_TYPE_16X16;



            av_dlog(VAR_0, "%d %d %06X\n",

                    VAR_3, get_bits_count(&VAR_0->gb), show_bits(&VAR_0->gb, 24));

            VAR_3= VAR_0->decode_mb(VAR_0, VAR_0->block);



            if (VAR_0->pict_type!=AV_PICTURE_TYPE_B)

                ff_h263_update_motion_val(VAR_0);



            if(VAR_3<0){

                const int xy= VAR_0->mb_x + VAR_0->mb_y*VAR_0->mb_stride;

                if(VAR_3==SLICE_END){

                    ff_MPV_decode_mb(VAR_0, VAR_0->block);

                    if(VAR_0->loop_filter)

                        ff_h263_loop_filter(VAR_0);



                    ff_er_add_slice(VAR_0, VAR_0->resync_mb_x, VAR_0->resync_mb_y, VAR_0->mb_x, VAR_0->mb_y, ER_MB_END&VAR_1);



                    VAR_0->padding_bug_score--;



                    if(++VAR_0->mb_x >= VAR_0->mb_width){

                        VAR_0->mb_x=0;

                        ff_draw_horiz_band(VAR_0, VAR_0->mb_y*VAR_2, VAR_2);

                        ff_MPV_report_decode_progress(VAR_0);

                        VAR_0->mb_y++;

                    }

                    return 0;

                }else if(VAR_3==SLICE_NOEND){

                    av_log(VAR_0->avctx, AV_LOG_ERROR, "Slice mismatch at MB: %d\n", xy);

                    ff_er_add_slice(VAR_0, VAR_0->resync_mb_x, VAR_0->resync_mb_y, VAR_0->mb_x+1, VAR_0->mb_y, ER_MB_END&VAR_1);

                    return AVERROR_INVALIDDATA;

                }

                av_log(VAR_0->avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy);

                ff_er_add_slice(VAR_0, VAR_0->resync_mb_x, VAR_0->resync_mb_y, VAR_0->mb_x, VAR_0->mb_y, ER_MB_ERROR&VAR_1);



                return AVERROR_INVALIDDATA;

            }



            ff_MPV_decode_mb(VAR_0, VAR_0->block);

            if(VAR_0->loop_filter)

                ff_h263_loop_filter(VAR_0);

        }



        ff_draw_horiz_band(VAR_0, VAR_0->mb_y*VAR_2, VAR_2);

        ff_MPV_report_decode_progress(VAR_0);



        VAR_0->mb_x= 0;

    }



    assert(VAR_0->mb_x==0 && VAR_0->mb_y==VAR_0->mb_height);



    if(VAR_0->codec_id==AV_CODEC_ID_MPEG4

       && (VAR_0->workaround_bugs&FF_BUG_AUTODETECT)

       && get_bits_left(&VAR_0->gb) >= 48

       && show_bits(&VAR_0->gb, 24)==0x4010

       && !VAR_0->data_partitioning)

        VAR_0->padding_bug_score+=32;



    

    if(      VAR_0->codec_id==AV_CODEC_ID_MPEG4

       &&   (VAR_0->workaround_bugs&FF_BUG_AUTODETECT)

       &&    get_bits_left(&VAR_0->gb) >=0

       &&    get_bits_left(&VAR_0->gb) < 137



       &&   !VAR_0->data_partitioning){



        const int VAR_7= get_bits_count(&VAR_0->gb);

        const int VAR_8 = VAR_0->gb.size_in_bits - VAR_7;



        if(VAR_8==0){

            VAR_0->padding_bug_score+=16;

        } else if(VAR_8 != 1){

            int VAR_9= show_bits(&VAR_0->gb, 8);

            VAR_9|= 0x7F >> (7-(VAR_7&7));



            if(VAR_9==0x7F && VAR_8<=8)

                VAR_0->padding_bug_score--;

            else if(VAR_9==0x7F && ((get_bits_count(&VAR_0->gb)+8)&8) && VAR_8<=16)

                VAR_0->padding_bug_score+= 4;

            else

                VAR_0->padding_bug_score++;

        }

    }



    if(VAR_0->workaround_bugs&FF_BUG_AUTODETECT){

        if(VAR_0->padding_bug_score > -2 && !VAR_0->data_partitioning )

            VAR_0->workaround_bugs |=  FF_BUG_NO_PADDING;

        else

            VAR_0->workaround_bugs &= ~FF_BUG_NO_PADDING;

    }



    

    if(VAR_0->msmpeg4_version || (VAR_0->workaround_bugs&FF_BUG_NO_PADDING)){ 

        int VAR_10= get_bits_left(&VAR_0->gb);

        int VAR_11=7;



        

        if(VAR_0->msmpeg4_version && VAR_0->pict_type==AV_PICTURE_TYPE_I)

            VAR_11+= 17;



        

        if((VAR_0->workaround_bugs&FF_BUG_NO_PADDING) && (VAR_0->err_recognition&(AV_EF_BUFFER|AV_EF_AGGRESSIVE)))

            VAR_11+= 48;

        else if((VAR_0->workaround_bugs&FF_BUG_NO_PADDING))

            VAR_11+= 256*256*256*64;



        if(VAR_10>VAR_11){

            av_log(VAR_0->avctx, AV_LOG_ERROR, "discarding %d junk bits at VAR_5, next would be %X\n", VAR_10, show_bits(&VAR_0->gb, 24));

        }

        else if(VAR_10<0){

            av_log(VAR_0->avctx, AV_LOG_ERROR, "overreading %d bits\n", -VAR_10);

        }else

            ff_er_add_slice(VAR_0, VAR_0->resync_mb_x, VAR_0->resync_mb_y, VAR_0->mb_x-1, VAR_0->mb_y, ER_MB_END);



        return 0;

    }



    av_log(VAR_0->avctx, AV_LOG_ERROR, "slice VAR_5 not reached but screenspace VAR_5 (%d VAR_10 %06X, score= %d)\n",

            get_bits_left(&VAR_0->gb),

            show_bits(&VAR_0->gb, 24), VAR_0->padding_bug_score);



    ff_er_add_slice(VAR_0, VAR_0->resync_mb_x, VAR_0->resync_mb_y, VAR_0->mb_x, VAR_0->mb_y, ER_MB_END&VAR_1);



    return AVERROR_INVALIDDATA;

}

static int FUNC_0(MpegEncContext *VAR_0){ const int VAR_1= VAR_0->partitioned_frame ? (ER_AC_END|ER_AC_ERROR) : 0x7F; const int VAR_2= 16>>VAR_0->avctx->lowres; int VAR_3; VAR_0->last_resync_gb= VAR_0->gb; VAR_0->first_slice_line= 1; VAR_0->resync_mb_x= VAR_0->mb_x; VAR_0->resync_mb_y= VAR_0->mb_y; ff_set_qscale(VAR_0, VAR_0->VAR_6); if (VAR_0->avctx->hwaccel) { const uint8_t *VAR_4= VAR_0->gb.buffer + get_bits_count(&VAR_0->gb)/8; const uint8_t *VAR_5  = ff_h263_find_resync_marker(VAR_4 + 1, VAR_0->gb.buffer_end); skip_bits_long(&VAR_0->gb, 8*(VAR_5 - VAR_4)); return VAR_0->avctx->hwaccel->FUNC_0(VAR_0->avctx, VAR_4, VAR_5 - VAR_4); } if(VAR_0->partitioned_frame){ const int VAR_6= VAR_0->VAR_6; if(CONFIG_MPEG4_DECODER && VAR_0->codec_id==AV_CODEC_ID_MPEG4){ if ((VAR_3 = ff_mpeg4_decode_partitions(VAR_0)) < 0)
return VAR_3; } VAR_0->first_slice_line=1; VAR_0->mb_x= VAR_0->resync_mb_x; VAR_0->mb_y= VAR_0->resync_mb_y; ff_set_qscale(VAR_0, VAR_6); } for(; VAR_0->mb_y < VAR_0->mb_height; VAR_0->mb_y++) { if(VAR_0->msmpeg4_version){ if(VAR_0->resync_mb_y + VAR_0->slice_height == VAR_0->mb_y){ ff_er_add_slice(VAR_0, VAR_0->resync_mb_x, VAR_0->resync_mb_y, VAR_0->mb_x-1, VAR_0->mb_y, ER_MB_END); return 0; } } if(VAR_0->msmpeg4_version==1){ VAR_0->last_dc[0]=
VAR_0->last_dc[1]=
VAR_0->last_dc[2]= 128; } ff_init_block_index(VAR_0); for(; VAR_0->mb_x < VAR_0->mb_width; VAR_0->mb_x++) { int VAR_3; ff_update_block_index(VAR_0); if(VAR_0->resync_mb_x == VAR_0->mb_x && VAR_0->resync_mb_y+1 == VAR_0->mb_y){ VAR_0->first_slice_line=0; } VAR_0->mv_dir = MV_DIR_FORWARD; VAR_0->mv_type = MV_TYPE_16X16; av_dlog(VAR_0, "%d %d %06X\n",
VAR_3, get_bits_count(&VAR_0->gb), show_bits(&VAR_0->gb, 24)); VAR_3= VAR_0->decode_mb(VAR_0, VAR_0->block); if (VAR_0->pict_type!=AV_PICTURE_TYPE_B)
ff_h263_update_motion_val(VAR_0); if(VAR_3<0){ const int xy= VAR_0->mb_x + VAR_0->mb_y*VAR_0->mb_stride; if(VAR_3==SLICE_END){ ff_MPV_decode_mb(VAR_0, VAR_0->block); if(VAR_0->loop_filter)
ff_h263_loop_filter(VAR_0); ff_er_add_slice(VAR_0, VAR_0->resync_mb_x, VAR_0->resync_mb_y, VAR_0->mb_x, VAR_0->mb_y, ER_MB_END&VAR_1); VAR_0->padding_bug_score--; if(++VAR_0->mb_x >= VAR_0->mb_width){ VAR_0->mb_x=0; ff_draw_horiz_band(VAR_0, VAR_0->mb_y*VAR_2, VAR_2); ff_MPV_report_decode_progress(VAR_0); VAR_0->mb_y++; } return 0; }else if(VAR_3==SLICE_NOEND){ av_log(VAR_0->avctx, AV_LOG_ERROR, "Slice mismatch at MB: %d\n", xy); ff_er_add_slice(VAR_0, VAR_0->resync_mb_x, VAR_0->resync_mb_y, VAR_0->mb_x+1, VAR_0->mb_y, ER_MB_END&VAR_1); return AVERROR_INVALIDDATA; } av_log(VAR_0->avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy); ff_er_add_slice(VAR_0, VAR_0->resync_mb_x, VAR_0->resync_mb_y, VAR_0->mb_x, VAR_0->mb_y, ER_MB_ERROR&VAR_1); return AVERROR_INVALIDDATA; } ff_MPV_decode_mb(VAR_0, VAR_0->block); if(VAR_0->loop_filter)
ff_h263_loop_filter(VAR_0); } ff_draw_horiz_band(VAR_0, VAR_0->mb_y*VAR_2, VAR_2); ff_MPV_report_decode_progress(VAR_0); VAR_0->mb_x= 0; } assert(VAR_0->mb_x==0 && VAR_0->mb_y==VAR_0->mb_height); if(VAR_0->codec_id==AV_CODEC_ID_MPEG4
&& (VAR_0->workaround_bugs&FF_BUG_AUTODETECT)
&& get_bits_left(&VAR_0->gb) >= 48
&& show_bits(&VAR_0->gb, 24)==0x4010
&& !VAR_0->data_partitioning)
VAR_0->padding_bug_score+=32; if(      VAR_0->codec_id==AV_CODEC_ID_MPEG4
&&   (VAR_0->workaround_bugs&FF_BUG_AUTODETECT)
&&    get_bits_left(&VAR_0->gb) >=0
&&    get_bits_left(&VAR_0->gb) < 137
&&   !VAR_0->data_partitioning){ const int VAR_7= get_bits_count(&VAR_0->gb); const int VAR_8 = VAR_0->gb.size_in_bits - VAR_7; if(VAR_8==0){ VAR_0->padding_bug_score+=16; } else if(VAR_8 != 1){ int VAR_9= show_bits(&VAR_0->gb, 8); VAR_9|= 0x7F >> (7-(VAR_7&7)); if(VAR_9==0x7F && VAR_8<=8)
VAR_0->padding_bug_score--; else if(VAR_9==0x7F && ((get_bits_count(&VAR_0->gb)+8)&8) && VAR_8<=16)
VAR_0->padding_bug_score+= 4; else
VAR_0->padding_bug_score++; } } if(VAR_0->workaround_bugs&FF_BUG_AUTODETECT){ if(VAR_0->padding_bug_score > -2 && !VAR_0->data_partitioning )
VAR_0->workaround_bugs |=  FF_BUG_NO_PADDING; else
VAR_0->workaround_bugs &= ~FF_BUG_NO_PADDING; } if(VAR_0->msmpeg4_version || (VAR_0->workaround_bugs&FF_BUG_NO_PADDING)){ int VAR_10= get_bits_left(&VAR_0->gb); int VAR_11=7; if(VAR_0->msmpeg4_version && VAR_0->pict_type==AV_PICTURE_TYPE_I)
VAR_11+= 17; if((VAR_0->workaround_bugs&FF_BUG_NO_PADDING) && (VAR_0->err_recognition&(AV_EF_BUFFER|AV_EF_AGGRESSIVE)))
VAR_11+= 48; else if((VAR_0->workaround_bugs&FF_BUG_NO_PADDING))
VAR_11+= 256*256*256*64; if(VAR_10>VAR_11){ av_log(VAR_0->avctx, AV_LOG_ERROR, "discarding %d junk bits at VAR_5, next would be %X\n", VAR_10, show_bits(&VAR_0->gb, 24)); } else if(VAR_10<0){ av_log(VAR_0->avctx, AV_LOG_ERROR, "overreading %d bits\n", -VAR_10); }else ff_er_add_slice(VAR_0, VAR_0->resync_mb_x, VAR_0->resync_mb_y, VAR_0->mb_x-1, VAR_0->mb_y, ER_MB_END); return 0; } av_log(VAR_0->avctx, AV_LOG_ERROR, "slice VAR_5 not reached but screenspace VAR_5 (%d VAR_10 %06X, score= %d)\n",
get_bits_left(&VAR_0->gb),
show_bits(&VAR_0->gb, 24), VAR_0->padding_bug_score); ff_er_add_slice(VAR_0, VAR_0->resync_mb_x, VAR_0->resync_mb_y, VAR_0->mb_x, VAR_0->mb_y, ER_MB_END&VAR_1); return AVERROR_INVALIDDATA; }