static int is_intra_more_likely(MpegEncContext *s){

    int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y;



    if (!s->last_picture_ptr || !s->last_picture_ptr->f.data[0]) return 1; //no previous frame available -> use spatial prediction



    undamaged_count=0;

    for(i=0; i<s->mb_num; i++){

        const int mb_xy= s->mb_index2xy[i];

        const int error= s->error_status_table[mb_xy];

        if(!((error&DC_ERROR) && (error&MV_ERROR)))

            undamaged_count++;

    }



    if(s->codec_id == CODEC_ID_H264){

        H264Context *h= (void*)s;

        if (h->ref_count[0] <= 0 || !h->ref_list[0][0].f.data[0])

            return 1;

    }



    if(undamaged_count < 5) return 0; //almost all MBs damaged -> use temporal prediction



    //prevent dsp.sad() check, that requires access to the image

    if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration && s->pict_type == AV_PICTURE_TYPE_I)

        return 1;



    skip_amount= FFMAX(undamaged_count/50, 1); //check only upto 50 MBs

    is_intra_likely=0;



    j=0;

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

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

            int error;

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



            error= s->error_status_table[mb_xy];

            if((error&DC_ERROR) && (error&MV_ERROR))

                continue; //skip damaged



            j++;

            if((j%skip_amount) != 0) continue; //skip a few to speed things up



            if(s->pict_type==AV_PICTURE_TYPE_I){

                uint8_t *mb_ptr     = s->current_picture.f.data[0] + mb_x*16 + mb_y*16*s->linesize;

                uint8_t *last_mb_ptr= s->last_picture.f.data   [0] + mb_x*16 + mb_y*16*s->linesize;



                if (s->avctx->codec_id == CODEC_ID_H264) {

                    // FIXME

                } else {

                    ff_thread_await_progress((AVFrame *) s->last_picture_ptr,

                                             mb_y, 0);

                }

                is_intra_likely += s->dsp.sad[0](NULL, last_mb_ptr, mb_ptr                    , s->linesize, 16);

                // FIXME need await_progress() here

                is_intra_likely -= s->dsp.sad[0](NULL, last_mb_ptr, last_mb_ptr+s->linesize*16, s->linesize, 16);

            }else{

                if (IS_INTRA(s->current_picture.f.mb_type[mb_xy]))

                   is_intra_likely++;

                else

                   is_intra_likely--;

            }

        }

    }

//printf("is_intra_likely: %d type:%d\n", is_intra_likely, s->pict_type);

    return is_intra_likely > 0;

}

static int is_intra_more_likely(MpegEncContext *s){

    int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y;



    if (!s->last_picture_ptr || !s->last_picture_ptr->f.data[0]) return 1; 



    undamaged_count=0;

    for(i=0; i<s->mb_num; i++){

        const int mb_xy= s->mb_index2xy[i];

        const int error= s->error_status_table[mb_xy];

        if(!((error&DC_ERROR) && (error&MV_ERROR)))

            undamaged_count++;

    }



    if(s->codec_id == CODEC_ID_H264){

        H264Context *h= (void*)s;

        if (h->ref_count[0] <= 0 || !h->ref_list[0][0].f.data[0])

            return 1;

    }



    if(undamaged_count < 5) return 0; 



    

    if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration && s->pict_type == AV_PICTURE_TYPE_I)

        return 1;



    skip_amount= FFMAX(undamaged_count/50, 1); 

    is_intra_likely=0;



    j=0;

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

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

            int error;

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



            error= s->error_status_table[mb_xy];

            if((error&DC_ERROR) && (error&MV_ERROR))

                continue; 



            j++;

            if((j%skip_amount) != 0) continue; 



            if(s->pict_type==AV_PICTURE_TYPE_I){

                uint8_t *mb_ptr     = s->current_picture.f.data[0] + mb_x*16 + mb_y*16*s->linesize;

                uint8_t *last_mb_ptr= s->last_picture.f.data   [0] + mb_x*16 + mb_y*16*s->linesize;



                if (s->avctx->codec_id == CODEC_ID_H264) {

                    

                } else {

                    ff_thread_await_progress((AVFrame *) s->last_picture_ptr,

                                             mb_y, 0);

                }

                is_intra_likely += s->dsp.sad[0](NULL, last_mb_ptr, mb_ptr                    , s->linesize, 16);

                 need await_progress() here

                is_intra_likely -= s->dsp.sad[0](NULL, last_mb_ptr, last_mb_ptr+s->linesize*16, s->linesize, 16);

            }else{

                if (IS_INTRA(s->current_picture.f.mb_type[mb_xy]))

                   is_intra_likely++;

                else

                   is_intra_likely--;

            }

        }

    }



    return is_intra_likely > 0;

}

static int FUNC_0(MpegEncContext *VAR_0){

    int VAR_1, VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7;



    if (!VAR_0->last_picture_ptr || !VAR_0->last_picture_ptr->f.data[0]) return 1; 



    VAR_4=0;

    for(VAR_2=0; VAR_2<VAR_0->mb_num; VAR_2++){

        const int mb_xy= VAR_0->mb_index2xy[VAR_2];

        const int error= VAR_0->error_status_table[mb_xy];

        if(!((error&DC_ERROR) && (error&MV_ERROR)))

            VAR_4++;

    }



    if(VAR_0->codec_id == CODEC_ID_H264){

        H264Context *h= (void*)VAR_0;

        if (h->ref_count[0] <= 0 || !h->ref_list[0][0].f.data[0])

            return 1;

    }



    if(VAR_4 < 5) return 0; 



    

    if(CONFIG_MPEG_XVMC_DECODER && VAR_0->avctx->xvmc_acceleration && VAR_0->pict_type == AV_PICTURE_TYPE_I)

        return 1;



    VAR_5= FFMAX(VAR_4/50, 1); 

    VAR_1=0;



    VAR_3=0;

    for(VAR_7= 0; VAR_7<VAR_0->mb_height-1; VAR_7++){

        for(VAR_6= 0; VAR_6<VAR_0->mb_width; VAR_6++){

            int error;

            const int mb_xy= VAR_6 + VAR_7*VAR_0->mb_stride;



            error= VAR_0->error_status_table[mb_xy];

            if((error&DC_ERROR) && (error&MV_ERROR))

                continue; 



            VAR_3++;

            if((VAR_3%VAR_5) != 0) continue; 



            if(VAR_0->pict_type==AV_PICTURE_TYPE_I){

                uint8_t *mb_ptr     = VAR_0->current_picture.f.data[0] + VAR_6*16 + VAR_7*16*VAR_0->linesize;

                uint8_t *last_mb_ptr= VAR_0->last_picture.f.data   [0] + VAR_6*16 + VAR_7*16*VAR_0->linesize;



                if (VAR_0->avctx->codec_id == CODEC_ID_H264) {

                    

                } else {

                    ff_thread_await_progress((AVFrame *) VAR_0->last_picture_ptr,

                                             VAR_7, 0);

                }

                VAR_1 += VAR_0->dsp.sad[0](NULL, last_mb_ptr, mb_ptr                    , VAR_0->linesize, 16);

                 need await_progress() here

                VAR_1 -= VAR_0->dsp.sad[0](NULL, last_mb_ptr, last_mb_ptr+VAR_0->linesize*16, VAR_0->linesize, 16);

            }else{

                if (IS_INTRA(VAR_0->current_picture.f.mb_type[mb_xy]))

                   VAR_1++;

                else

                   VAR_1--;

            }

        }

    }



    return VAR_1 > 0;

}

static int FUNC_0(MpegEncContext *VAR_0){ int VAR_1, VAR_2, VAR_3, VAR_4, VAR_5, VAR_6, VAR_7; if (!VAR_0->last_picture_ptr || !VAR_0->last_picture_ptr->f.data[0]) return 1; VAR_4=0; for(VAR_2=0; VAR_2<VAR_0->mb_num; VAR_2++){ const int mb_xy= VAR_0->mb_index2xy[VAR_2]; const int error= VAR_0->error_status_table[mb_xy]; if(!((error&DC_ERROR) && (error&MV_ERROR)))
VAR_4++; } if(VAR_0->codec_id == CODEC_ID_H264){ H264Context *h= (void*)VAR_0; if (h->ref_count[0] <= 0 || !h->ref_list[0][0].f.data[0])
return 1; } if(VAR_4 < 5) return 0; if(CONFIG_MPEG_XVMC_DECODER && VAR_0->avctx->xvmc_acceleration && VAR_0->pict_type == AV_PICTURE_TYPE_I)
return 1; VAR_5= FFMAX(VAR_4/50, 1); VAR_1=0; VAR_3=0; for(VAR_7= 0; VAR_7<VAR_0->mb_height-1; VAR_7++){ for(VAR_6= 0; VAR_6<VAR_0->mb_width; VAR_6++){ int error; const int mb_xy= VAR_6 + VAR_7*VAR_0->mb_stride; error= VAR_0->error_status_table[mb_xy]; if((error&DC_ERROR) && (error&MV_ERROR))
continue; VAR_3++; if((VAR_3%VAR_5) != 0) continue; if(VAR_0->pict_type==AV_PICTURE_TYPE_I){ uint8_t *mb_ptr     = VAR_0->current_picture.f.data[0] + VAR_6*16 + VAR_7*16*VAR_0->linesize; uint8_t *last_mb_ptr= VAR_0->last_picture.f.data   [0] + VAR_6*16 + VAR_7*16*VAR_0->linesize; if (VAR_0->avctx->codec_id == CODEC_ID_H264) { } else { ff_thread_await_progress((AVFrame *) VAR_0->last_picture_ptr,
VAR_7, 0); } VAR_1 += VAR_0->dsp.sad[0](NULL, last_mb_ptr, mb_ptr                    , VAR_0->linesize, 16); need await_progress() here
VAR_1 -= VAR_0->dsp.sad[0](NULL, last_mb_ptr, last_mb_ptr+VAR_0->linesize*16, VAR_0->linesize, 16); }else{ if (IS_INTRA(VAR_0->current_picture.f.mb_type[mb_xy]))
VAR_1++; else
VAR_1--; } } } return VAR_1 > 0; }