error_resilience.c
上传用户:hjq518
上传日期:2021-12-09
资源大小:5084k
文件大小:40k
源码类别:

Audio

开发平台:

Visual C++

  1. /*  * Error resilience / concealment  *  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>  *  * This library is free software; you can redistribute it and/or  * modify it under the terms of the GNU Lesser General Public  * License as published by the Free Software Foundation; either  * version 2 of the License, or (at your option) any later version.  *  * This library is distributed in the hope that it will be useful,  * but WITHOUT ANY WARRANTY; without even the implied warranty of  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  * Lesser General Public License for more details.  *  * You should have received a copy of the GNU Lesser General Public  * License along with this library; if not, write to the Free Software  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  */   /**  * @file error_resilience.c  * Error resilience / concealment.  */ #include <limits.h>   #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" #include "common.h" static void decode_mb(MpegEncContext *s){
  2.     s->dest[0] = s->current_picture.data[0] + (s->mb_y * 16* s->linesize  ) + s->mb_x * 16;
  3.     s->dest[1] = s->current_picture.data[1] + (s->mb_y * 8 * s->uvlinesize) + s->mb_x * 8;
  4.     s->dest[2] = s->current_picture.data[2] + (s->mb_y * 8 * s->uvlinesize) + s->mb_x * 8;
  5.     MPV_decode_mb(s, s->block);    
  6. }
  7. /**
  8.  * replaces the current MB with a flat dc only version.
  9.  */
  10. static void put_dc(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int mb_x, int mb_y)
  11. {
  12.     int dc, dcu, dcv, y, i;
  13.     for(i=0; i<4; i++){
  14.         dc= s->dc_val[0][mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*s->b8_stride];
  15.         if(dc<0) dc=0;
  16.         else if(dc>2040) dc=2040;
  17.         for(y=0; y<8; y++){
  18.             int x;
  19.             for(x=0; x<8; x++){
  20.                 dest_y[x + (i&1)*8 + (y + (i>>1)*8)*s->linesize]= dc/8;
  21.             }
  22.         }
  23.     }
  24.     dcu = s->dc_val[1][mb_x + mb_y*s->mb_stride];
  25.     dcv = s->dc_val[2][mb_x + mb_y*s->mb_stride];
  26.     if     (dcu<0   ) dcu=0;
  27.     else if(dcu>2040) dcu=2040;
  28.     if     (dcv<0   ) dcv=0;
  29.     else if(dcv>2040) dcv=2040;
  30.     for(y=0; y<8; y++){
  31.         int x;
  32.         for(x=0; x<8; x++){
  33.             dest_cb[x + y*(s->uvlinesize)]= dcu/8;
  34.             dest_cr[x + y*(s->uvlinesize)]= dcv/8;
  35.         }
  36.     }
  37. }
  38. static void filter181(int16_t *data, int width, int height, int stride){
  39.     int x,y;
  40.     /* horizontal filter */
  41.     for(y=1; y<height-1; y++){
  42.         int prev_dc= data[0 + y*stride];
  43.         for(x=1; x<width-1; x++){
  44.             int dc;
  45.             
  46.             dc= - prev_dc 
  47.                 + data[x     + y*stride]*8
  48.                 - data[x + 1 + y*stride];
  49.             dc= (dc*10923 + 32768)>>16;
  50.             prev_dc= data[x + y*stride];
  51.             data[x + y*stride]= dc;
  52.         }
  53.     }
  54.     
  55.     /* vertical filter */
  56.     for(x=1; x<width-1; x++){
  57.         int prev_dc= data[x];
  58.         for(y=1; y<height-1; y++){
  59.             int dc;
  60.             
  61.             dc= - prev_dc 
  62.                 + data[x +  y   *stride]*8
  63.                 - data[x + (y+1)*stride];
  64.             dc= (dc*10923 + 32768)>>16;
  65.             prev_dc= data[x + y*stride];
  66.             data[x + y*stride]= dc;
  67.         }
  68.     }
  69. }
  70. /**
  71.  * guess the dc of blocks which dont have a undamaged dc
  72.  * @param w width in 8 pixel blocks
  73.  * @param h height in 8 pixel blocks
  74.  */
  75. static void guess_dc(MpegEncContext *s, int16_t *dc, int w, int h, int stride, int is_luma){
  76.     int b_x, b_y;
  77.     for(b_y=0; b_y<h; b_y++){
  78.         for(b_x=0; b_x<w; b_x++){
  79.             int color[4]={1024,1024,1024,1024};
  80.             int distance[4]={9999,9999,9999,9999};
  81.             int mb_index, error, j;
  82.             int64_t guess, weight_sum;
  83.             
  84.             mb_index= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride;
  85.             
  86.             error= s->error_status_table[mb_index];
  87.             
  88.             if(IS_INTER(s->current_picture.mb_type[mb_index])) continue; //inter
  89.             if(!(error&DC_ERROR)) continue;           //dc-ok
  90.             
  91.             /* right block */
  92.             for(j=b_x+1; j<w; j++){
  93.                 int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride;
  94.                 int error_j= s->error_status_table[mb_index_j];
  95.                 int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
  96.                 if(intra_j==0 || !(error_j&DC_ERROR)){
  97.                     color[0]= dc[j + b_y*stride];
  98.                     distance[0]= j-b_x;
  99.                     break;
  100.                 }
  101.             }
  102.             
  103.             /* left block */
  104.             for(j=b_x-1; j>=0; j--){
  105.                 int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride;
  106.                 int error_j= s->error_status_table[mb_index_j];
  107.                 int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
  108.                 if(intra_j==0 || !(error_j&DC_ERROR)){
  109.                     color[1]= dc[j + b_y*stride];
  110.                     distance[1]= b_x-j;
  111.                     break;
  112.                 }
  113.             }
  114.             /* bottom block */
  115.             for(j=b_y+1; j<h; j++){
  116.                 int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride;
  117.                 int error_j= s->error_status_table[mb_index_j];
  118.                 int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
  119.                 if(intra_j==0 || !(error_j&DC_ERROR)){
  120.                     color[2]= dc[b_x + j*stride];
  121.                     distance[2]= j-b_y;
  122.                     break;
  123.                 }
  124.             }
  125.             /* top block */
  126.             for(j=b_y-1; j>=0; j--){
  127.                 int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride;
  128.                 int error_j= s->error_status_table[mb_index_j];
  129.                 int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
  130.                 if(intra_j==0 || !(error_j&DC_ERROR)){
  131.                     color[3]= dc[b_x + j*stride];
  132.                     distance[3]= b_y-j;
  133.                     break;
  134.                 }
  135.             }
  136.             
  137.             weight_sum=0;
  138.             guess=0;
  139.             for(j=0; j<4; j++){
  140.                 int64_t weight= 256*256*256*16/distance[j];
  141.                 guess+= weight*(int64_t)color[j];
  142.                 weight_sum+= weight;
  143.             }
  144.             guess= (guess + weight_sum/2) / weight_sum;
  145.             dc[b_x + b_y*stride]= guess;
  146.         }
  147.     }
  148. }
  149. /**
  150.  * simple horizontal deblocking filter used for error resilience
  151.  * @param w width in 8 pixel blocks
  152.  * @param h height in 8 pixel blocks
  153.  */
  154. static void h_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int stride, int is_luma){
  155.     int b_x, b_y;
  156.     uint8_t *cm = cropTbl + MAX_NEG_CROP;
  157.     for(b_y=0; b_y<h; b_y++){
  158.         for(b_x=0; b_x<w-1; b_x++){
  159.             int y;
  160.             int left_status = s->error_status_table[( b_x   >>is_luma) + (b_y>>is_luma)*s->mb_stride];
  161.             int right_status= s->error_status_table[((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride];
  162.             int left_intra=   IS_INTRA(s->current_picture.mb_type      [( b_x   >>is_luma) + (b_y>>is_luma)*s->mb_stride]);
  163.             int right_intra=  IS_INTRA(s->current_picture.mb_type      [((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride]);
  164.             int left_damage =  left_status&(DC_ERROR|AC_ERROR|MV_ERROR);
  165.             int right_damage= right_status&(DC_ERROR|AC_ERROR|MV_ERROR);
  166.             int offset= b_x*8 + b_y*stride*8;
  167.             int16_t *left_mv=  s->current_picture.motion_val[0][s->b8_stride*(b_y<<(1-is_luma)) + ( b_x   <<(1-is_luma))];
  168.             int16_t *right_mv= s->current_picture.motion_val[0][s->b8_stride*(b_y<<(1-is_luma)) + ((b_x+1)<<(1-is_luma))];
  169.             
  170.             if(!(left_damage||right_damage)) continue; // both undamaged
  171.             
  172.             if(   (!left_intra) && (!right_intra) 
  173.                && ABS(left_mv[0]-right_mv[0]) + ABS(left_mv[1]+right_mv[1]) < 2) continue;
  174.             
  175.             for(y=0; y<8; y++){
  176.                 int a,b,c,d;
  177.                 
  178.                 a= dst[offset + 7 + y*stride] - dst[offset + 6 + y*stride];
  179.                 b= dst[offset + 8 + y*stride] - dst[offset + 7 + y*stride];
  180.                 c= dst[offset + 9 + y*stride] - dst[offset + 8 + y*stride];
  181.                 
  182.                 d= ABS(b) - ((ABS(a) + ABS(c) + 1)>>1);
  183.                 d= FFMAX(d, 0);
  184.                 if(b<0) d= -d;
  185.                 
  186.                 if(d==0) continue;
  187.                 if(!(left_damage && right_damage))
  188.                     d= d*16/9;
  189.                 
  190.                 if(left_damage){
  191.                     dst[offset + 7 + y*stride] = cm[dst[offset + 7 + y*stride] + ((d*7)>>4)];
  192.                     dst[offset + 6 + y*stride] = cm[dst[offset + 6 + y*stride] + ((d*5)>>4)];
  193.                     dst[offset + 5 + y*stride] = cm[dst[offset + 5 + y*stride] + ((d*3)>>4)];
  194.                     dst[offset + 4 + y*stride] = cm[dst[offset + 4 + y*stride] + ((d*1)>>4)];
  195.                 }
  196.                 if(right_damage){
  197.                     dst[offset + 8 + y*stride] = cm[dst[offset + 8 + y*stride] - ((d*7)>>4)];
  198.                     dst[offset + 9 + y*stride] = cm[dst[offset + 9 + y*stride] - ((d*5)>>4)];
  199.                     dst[offset + 10+ y*stride] = cm[dst[offset +10 + y*stride] - ((d*3)>>4)];
  200.                     dst[offset + 11+ y*stride] = cm[dst[offset +11 + y*stride] - ((d*1)>>4)];
  201.                 }
  202.             }
  203.         }
  204.     }
  205. }
  206. /**
  207.  * simple vertical deblocking filter used for error resilience
  208.  * @param w width in 8 pixel blocks
  209.  * @param h height in 8 pixel blocks
  210.  */
  211. static void v_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int stride, int is_luma){
  212.     int b_x, b_y;
  213.     uint8_t *cm = cropTbl + MAX_NEG_CROP;
  214.     for(b_y=0; b_y<h-1; b_y++){
  215.         for(b_x=0; b_x<w; b_x++){
  216.             int x;
  217.             int top_status   = s->error_status_table[(b_x>>is_luma) + ( b_y   >>is_luma)*s->mb_stride];
  218.             int bottom_status= s->error_status_table[(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride];
  219.             int top_intra=     IS_INTRA(s->current_picture.mb_type      [(b_x>>is_luma) + ( b_y   >>is_luma)*s->mb_stride]);
  220.             int bottom_intra=  IS_INTRA(s->current_picture.mb_type      [(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride]);
  221.             int top_damage =      top_status&(DC_ERROR|AC_ERROR|MV_ERROR);
  222.             int bottom_damage= bottom_status&(DC_ERROR|AC_ERROR|MV_ERROR);
  223.             int offset= b_x*8 + b_y*stride*8;
  224.             int16_t *top_mv=    s->current_picture.motion_val[0][s->b8_stride*( b_y   <<(1-is_luma)) + (b_x<<(1-is_luma))];
  225.             int16_t *bottom_mv= s->current_picture.motion_val[0][s->b8_stride*((b_y+1)<<(1-is_luma)) + (b_x<<(1-is_luma))];
  226.             
  227.             if(!(top_damage||bottom_damage)) continue; // both undamaged
  228.             
  229.             if(   (!top_intra) && (!bottom_intra) 
  230.                && ABS(top_mv[0]-bottom_mv[0]) + ABS(top_mv[1]+bottom_mv[1]) < 2) continue;
  231.             
  232.             for(x=0; x<8; x++){
  233.                 int a,b,c,d;
  234.                 
  235.                 a= dst[offset + x + 7*stride] - dst[offset + x + 6*stride];
  236.                 b= dst[offset + x + 8*stride] - dst[offset + x + 7*stride];
  237.                 c= dst[offset + x + 9*stride] - dst[offset + x + 8*stride];
  238.                 
  239.                 d= ABS(b) - ((ABS(a) + ABS(c)+1)>>1);
  240.                 d= FFMAX(d, 0);
  241.                 if(b<0) d= -d;
  242.                 
  243.                 if(d==0) continue;
  244.                 if(!(top_damage && bottom_damage))
  245.                     d= d*16/9;
  246.                 
  247.                 if(top_damage){
  248.                     dst[offset + x +  7*stride] = cm[dst[offset + x +  7*stride] + ((d*7)>>4)];
  249.                     dst[offset + x +  6*stride] = cm[dst[offset + x +  6*stride] + ((d*5)>>4)];
  250.                     dst[offset + x +  5*stride] = cm[dst[offset + x +  5*stride] + ((d*3)>>4)];
  251.                     dst[offset + x +  4*stride] = cm[dst[offset + x +  4*stride] + ((d*1)>>4)];
  252.                 }
  253.                 if(bottom_damage){
  254.                     dst[offset + x +  8*stride] = cm[dst[offset + x +  8*stride] - ((d*7)>>4)];
  255.                     dst[offset + x +  9*stride] = cm[dst[offset + x +  9*stride] - ((d*5)>>4)];
  256.                     dst[offset + x + 10*stride] = cm[dst[offset + x + 10*stride] - ((d*3)>>4)];
  257.                     dst[offset + x + 11*stride] = cm[dst[offset + x + 11*stride] - ((d*1)>>4)];
  258.                 }
  259.             }
  260.         }
  261.     }
  262. }
  263. static void guess_mv(MpegEncContext *s){
  264. //********************CS by ty***********************Here is error
  265. //    uint8_t fixed[s->mb_stride * s->mb_height];
  266.     uint8_t fixed[3 * 18];
  267. //********************CE by ty***********************Here is error
  268. #define MV_FROZEN    3
  269. #define MV_CHANGED   2
  270. #define MV_UNCHANGED 1
  271.     const int mb_stride = s->mb_stride;
  272.     const int mb_width = s->mb_width;
  273.     const int mb_height= s->mb_height;
  274.     int i, depth, num_avail;
  275.     int mb_x, mb_y;
  276.    
  277.     num_avail=0;
  278.     for(i=0; i<s->mb_num; i++){
  279.         const int mb_xy= s->mb_index2xy[ i ];
  280.         int f=0;
  281.         int error= s->error_status_table[mb_xy];
  282.         if(IS_INTRA(s->current_picture.mb_type[mb_xy])) f=MV_FROZEN; //intra //FIXME check
  283.         if(!(error&MV_ERROR)) f=MV_FROZEN;           //inter with undamaged MV
  284.         
  285.         fixed[mb_xy]= f;
  286.         if(f==MV_FROZEN)
  287.             num_avail++;
  288.     }
  289.     
  290.     if((!(s->avctx->error_concealment&FF_EC_GUESS_MVS)) || num_avail <= mb_width/2){
  291.         for(mb_y=0; mb_y<s->mb_height; mb_y++){
  292.             for(mb_x=0; mb_x<s->mb_width; mb_x++){
  293.                 const int mb_xy= mb_x + mb_y*s->mb_stride;
  294.                 
  295.                 if(IS_INTRA(s->current_picture.mb_type[mb_xy]))  continue;
  296.                 if(!(s->error_status_table[mb_xy]&MV_ERROR)) continue;
  297.                 s->mv_dir = MV_DIR_FORWARD;
  298.                 s->mb_intra=0;
  299.                 s->mv_type = MV_TYPE_16X16;
  300.                 s->mb_skiped=0;
  301. s->dsp.clear_blocks(s->block[0]);
  302.                 s->mb_x= mb_x;
  303.                 s->mb_y= mb_y;
  304.                 s->mv[0][0][0]= 0;
  305.                 s->mv[0][0][1]= 0;
  306.                 decode_mb(s);
  307.             }
  308.         }
  309.         return;
  310.     }
  311.     
  312.     for(depth=0;; depth++){
  313.         int changed, pass, none_left;
  314.         none_left=1;
  315.         changed=1;
  316.         for(pass=0; (changed || pass<2) && pass<10; pass++){
  317.             int mb_x, mb_y;
  318. int score_sum=0;
  319.  
  320.             changed=0;
  321.             for(mb_y=0; mb_y<s->mb_height; mb_y++){
  322.                 for(mb_x=0; mb_x<s->mb_width; mb_x++){
  323.                     const int mb_xy= mb_x + mb_y*s->mb_stride;
  324.                     int mv_predictor[8][2]={{0}};
  325.                     int pred_count=0;
  326.                     int j;
  327.                     int best_score=256*256*256*64;
  328.                     int best_pred=0;
  329.                     const int mot_stride= s->b8_stride;
  330.                     const int mot_index= mb_x*2 + mb_y*2*mot_stride;
  331.                     int prev_x= s->current_picture.motion_val[0][mot_index][0];
  332.                     int prev_y= s->current_picture.motion_val[0][mot_index][1];
  333.                     if((mb_x^mb_y^pass)&1) continue;
  334.                     
  335.                     if(fixed[mb_xy]==MV_FROZEN) continue;
  336.                     assert(!IS_INTRA(s->current_picture.mb_type[mb_xy]));
  337.                     assert(s->last_picture_ptr && s->last_picture_ptr->data[0]);
  338.                     
  339.                     j=0;
  340.                     if(mb_x>0           && fixed[mb_xy-1        ]==MV_FROZEN) j=1;
  341.                     if(mb_x+1<mb_width  && fixed[mb_xy+1        ]==MV_FROZEN) j=1;
  342.                     if(mb_y>0           && fixed[mb_xy-mb_stride]==MV_FROZEN) j=1;
  343.                     if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_FROZEN) j=1;
  344.                     if(j==0) continue;
  345.                     j=0;
  346.                     if(mb_x>0           && fixed[mb_xy-1        ]==MV_CHANGED) j=1;
  347.                     if(mb_x+1<mb_width  && fixed[mb_xy+1        ]==MV_CHANGED) j=1;
  348.                     if(mb_y>0           && fixed[mb_xy-mb_stride]==MV_CHANGED) j=1;
  349.                     if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_CHANGED) j=1;
  350.                     if(j==0 && pass>1) continue;
  351.                     
  352.                     none_left=0;
  353.                     
  354.                     if(mb_x>0 && fixed[mb_xy-1]){
  355.                         mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - 2][0];
  356.                         mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - 2][1];
  357.                         pred_count++;
  358.                     }
  359.                     if(mb_x+1<mb_width && fixed[mb_xy+1]){
  360.                         mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + 2][0];
  361.                         mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + 2][1];
  362.                         pred_count++;
  363.                     }
  364.                     if(mb_y>0 && fixed[mb_xy-mb_stride]){
  365.                         mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - mot_stride*2][0];
  366.                         mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_stride*2][1];
  367.                         pred_count++;
  368.                     }
  369.                     if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){
  370.                         mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + mot_stride*2][0];
  371.                         mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_stride*2][1];
  372.                         pred_count++;
  373.                     }
  374.                     if(pred_count==0) continue;
  375.                     
  376.                     if(pred_count>1){
  377.                         int sum_x=0, sum_y=0;
  378.                         int max_x, max_y, min_x, min_y;
  379.                         for(j=0; j<pred_count; j++){
  380.                             sum_x+= mv_predictor[j][0];
  381.                             sum_y+= mv_predictor[j][1];
  382.                         }
  383.                     
  384.                         /* mean */
  385.                         mv_predictor[pred_count][0] = sum_x/j;
  386.                         mv_predictor[pred_count][1] = sum_y/j;
  387.                     
  388.                         /* median */
  389.                         if(pred_count>=3){
  390.                             min_y= min_x= 99999;
  391.                             max_y= max_x=-99999;
  392.                         }else{
  393.                             min_x=min_y=max_x=max_y=0;
  394.                         }
  395.                         for(j=0; j<pred_count; j++){
  396.                             max_x= FFMAX(max_x, mv_predictor[j][0]);
  397.                             max_y= FFMAX(max_y, mv_predictor[j][1]);
  398.                             min_x= FFMIN(min_x, mv_predictor[j][0]);
  399.                             min_y= FFMIN(min_y, mv_predictor[j][1]);
  400.                         }
  401.                         mv_predictor[pred_count+1][0] = sum_x - max_x - min_x;
  402.                         mv_predictor[pred_count+1][1] = sum_y - max_y - min_y;
  403.                         
  404.                         if(pred_count==4){
  405.                             mv_predictor[pred_count+1][0] /= 2;
  406.                             mv_predictor[pred_count+1][1] /= 2;
  407.                         }
  408.                         pred_count+=2;
  409.                     }
  410.                     
  411.                     /* zero MV */
  412.                     pred_count++;
  413.                     /* last MV */
  414.                     mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index][0];
  415.                     mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index][1];
  416.                     pred_count++;                    
  417.                     
  418.                     s->mv_dir = MV_DIR_FORWARD;
  419.                     s->mb_intra=0;
  420.                     s->mv_type = MV_TYPE_16X16;
  421.                     s->mb_skiped=0;
  422.     s->dsp.clear_blocks(s->block[0]);
  423.                     s->mb_x= mb_x;
  424.                     s->mb_y= mb_y;
  425.                     for(j=0; j<pred_count; j++){
  426.                         int score=0;
  427.                         uint8_t *src= s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
  428.                         s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[j][0];
  429.                         s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[j][1];
  430.                         decode_mb(s);
  431.                         
  432.                         if(mb_x>0 && fixed[mb_xy-1]){
  433.                             int k;
  434.                             for(k=0; k<16; k++)
  435.                                 score += ABS(src[k*s->linesize-1 ]-src[k*s->linesize   ]);
  436.                         }
  437.                         if(mb_x+1<mb_width && fixed[mb_xy+1]){
  438.                             int k;
  439.                             for(k=0; k<16; k++)
  440.                                 score += ABS(src[k*s->linesize+15]-src[k*s->linesize+16]);
  441.                         }
  442.                         if(mb_y>0 && fixed[mb_xy-mb_stride]){
  443.                             int k;
  444.                             for(k=0; k<16; k++)
  445.                                 score += ABS(src[k-s->linesize   ]-src[k               ]);
  446.                         }
  447.                         if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){
  448.                             int k;
  449.                             for(k=0; k<16; k++)
  450.                                 score += ABS(src[k+s->linesize*15]-src[k+s->linesize*16]);
  451.                         }
  452.                         
  453.                         if(score <= best_score){ // <= will favor the last MV
  454.                             best_score= score;
  455.                             best_pred= j;
  456.                         }
  457.                     }
  458. score_sum+= best_score;
  459. //FIXME no need to set s->current_picture.motion_val[0][mot_index][0] explicit
  460.                     s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[best_pred][0];
  461.                     s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[best_pred][1];
  462.                     decode_mb(s);
  463.                     
  464.                     if(s->mv[0][0][0] != prev_x || s->mv[0][0][1] != prev_y){
  465.                         fixed[mb_xy]=MV_CHANGED;
  466.                         changed++;
  467.                     }else
  468.                         fixed[mb_xy]=MV_UNCHANGED;
  469.                 }
  470.             }
  471. //            printf(".%d/%d", changed, score_sum); fflush(stdout);
  472.         }
  473.         
  474.         if(none_left) 
  475.             return;
  476.             
  477.         for(i=0; i<s->mb_num; i++){
  478.             int mb_xy= s->mb_index2xy[i];
  479.             if(fixed[mb_xy])
  480.                 fixed[mb_xy]=MV_FROZEN;
  481.         }
  482. //        printf(":"); fflush(stdout);
  483.     }
  484. }
  485.     
  486. static int is_intra_more_likely(MpegEncContext *s){
  487.     int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y;
  488.     
  489.     if(s->last_picture_ptr==NULL) return 1; //no previous frame available -> use spatial prediction
  490.     undamaged_count=0;
  491.     for(i=0; i<s->mb_num; i++){
  492.         const int mb_xy= s->mb_index2xy[i];
  493.         const int error= s->error_status_table[mb_xy];
  494.         if(!((error&DC_ERROR) && (error&MV_ERROR)))
  495.             undamaged_count++;
  496.     }
  497.     
  498.     if(undamaged_count < 5) return 0; //allmost all MBs damaged -> use temporal prediction
  499.     
  500.     skip_amount= FFMAX(undamaged_count/50, 1); //check only upto 50 MBs 
  501.     is_intra_likely=0;
  502.     j=0;
  503.     for(mb_y= 0; mb_y<s->mb_height-1; mb_y++){
  504.         for(mb_x= 0; mb_x<s->mb_width; mb_x++){
  505.             int error;
  506.             const int mb_xy= mb_x + mb_y*s->mb_stride;
  507.             error= s->error_status_table[mb_xy];
  508.             if((error&DC_ERROR) && (error&MV_ERROR))
  509.                 continue; //skip damaged
  510.         
  511.             j++;    
  512.             if((j%skip_amount) != 0) continue; //skip a few to speed things up
  513.     
  514.             if(s->pict_type==I_TYPE){
  515.                 uint8_t *mb_ptr     = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
  516.                 uint8_t *last_mb_ptr= s->last_picture.data   [0] + mb_x*16 + mb_y*16*s->linesize;
  517.     
  518. is_intra_likely += s->dsp.sad[0](NULL, last_mb_ptr, mb_ptr                    , s->linesize, 16);
  519.                 is_intra_likely -= s->dsp.sad[0](NULL, last_mb_ptr, last_mb_ptr+s->linesize*16, s->linesize, 16);
  520.             }else{
  521.                 if(IS_INTRA(s->current_picture.mb_type[mb_xy]))
  522.                    is_intra_likely++;
  523.                 else
  524.                    is_intra_likely--;
  525.             }
  526.         }
  527.     }
  528. //printf("is_intra_likely: %d type:%dn", is_intra_likely, s->pict_type);
  529.     return is_intra_likely > 0;    
  530. }
  531. void ff_er_frame_start(MpegEncContext *s){
  532.     if(!s->error_resilience) return;
  533.     memset(s->error_status_table, MV_ERROR|AC_ERROR|DC_ERROR|VP_START|AC_END|DC_END|MV_END, s->mb_stride*s->mb_height*sizeof(uint8_t));
  534.     s->error_count= 3*s->mb_num;
  535. }
  536. /**
  537.  * adds a slice.
  538.  * @param endx x component of the last macroblock, can be -1 for the last of the previous line
  539.  * @param status the status at the end (MV_END, AC_ERROR, ...), it is assumed that no earlier end or
  540.  *               error of the same type occured
  541.  */
  542. void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int endy, int status){
  543.     const int start_i= clip(startx + starty * s->mb_width    , 0, s->mb_num-1);
  544.     const int end_i  = clip(endx   + endy   * s->mb_width    , 0, s->mb_num);
  545.     const int start_xy= s->mb_index2xy[start_i];
  546.     const int end_xy  = s->mb_index2xy[end_i];
  547.     int mask= -1;
  548.     
  549.     if(!s->error_resilience) return;
  550.     mask &= ~VP_START;
  551.     if(status & (AC_ERROR|AC_END)){
  552.         mask &= ~(AC_ERROR|AC_END);
  553.         s->error_count -= end_i - start_i + 1;
  554.     }
  555.     if(status & (DC_ERROR|DC_END)){
  556.         mask &= ~(DC_ERROR|DC_END);
  557.         s->error_count -= end_i - start_i + 1;
  558.     }
  559.     if(status & (MV_ERROR|MV_END)){
  560.         mask &= ~(MV_ERROR|MV_END);
  561.         s->error_count -= end_i - start_i + 1;
  562.     }
  563.     if(status & (AC_ERROR|DC_ERROR|MV_ERROR)) s->error_count= INT_MAX;
  564.     if(mask == ~0x7F){
  565.         memset(&s->error_status_table[start_xy], 0, (end_xy - start_xy) * sizeof(uint8_t));
  566.     }else{
  567.         int i;
  568.         for(i=start_xy; i<end_xy; i++){
  569.             s->error_status_table[ i ] &= mask;
  570.         }
  571.     }
  572.     if(end_i == s->mb_num) 
  573.         s->error_count= INT_MAX;
  574.     else{
  575.         s->error_status_table[end_xy] &= mask;
  576.         s->error_status_table[end_xy] |= status;
  577.     }
  578.  
  579.     s->error_status_table[start_xy] |= VP_START;
  580.     if(start_xy > 0 && s->avctx->thread_count <= 1 && s->avctx->skip_top*s->mb_width < start_i){
  581.         int prev_status= s->error_status_table[ s->mb_index2xy[start_i - 1] ];
  582.         
  583.         prev_status &= ~ VP_START;
  584.         if(prev_status != (MV_END|DC_END|AC_END)) s->error_count= INT_MAX;
  585.     }
  586. }
  587. void ff_er_frame_end(MpegEncContext *s){
  588.     int i, mb_x, mb_y, error, error_type;
  589.     int distance;
  590.     int threshold_part[4]= {100,100,100};
  591.     int threshold= 50;
  592.     int is_intra_likely;
  593.     
  594.     if(!s->error_resilience || s->error_count==0 || 
  595.        s->error_count==3*s->mb_width*(s->avctx->skip_top + s->avctx->skip_bottom)) return;
  596.     av_log(s->avctx, AV_LOG_INFO, "concealing %d errorsn", s->error_count);
  597.     
  598.     if(s->current_picture.motion_val[0] == NULL){
  599.         int size = s->b8_stride * 2 * s->mb_height;
  600.         Picture *pic= s->current_picture_ptr;
  601.         
  602.         av_log(s->avctx, AV_LOG_ERROR, "Warning MVs not availablen");
  603.             
  604.         for(i=0; i<2; i++){
  605.             pic->ref_index[i]= av_mallocz(size * sizeof(uint8_t));
  606.             pic->motion_val_base[i]= av_mallocz((size+2) * 2 * sizeof(uint16_t));
  607.             pic->motion_val[i]= pic->motion_val_base[i]+2;
  608.         }
  609.         pic->motion_subsample_log2= 3;
  610.         s->current_picture= *s->current_picture_ptr;
  611.     }
  612.     
  613.     if(s->avctx->debug&FF_DEBUG_ER){
  614.         for(mb_y=0; mb_y<s->mb_height; mb_y++){
  615.             for(mb_x=0; mb_x<s->mb_width; mb_x++){
  616.                 int status= s->error_status_table[mb_x + mb_y*s->mb_stride];
  617.             
  618.                 av_log(s->avctx, AV_LOG_DEBUG, "%2X ", status); 
  619.             }
  620.             av_log(s->avctx, AV_LOG_DEBUG, "n");
  621.         }
  622.     }
  623.     
  624. #if 1
  625.     /* handle overlapping slices */
  626.     for(error_type=1; error_type<=3; error_type++){
  627.         int end_ok=0;
  628.         for(i=s->mb_num-1; i>=0; i--){
  629.             const int mb_xy= s->mb_index2xy[i];
  630.             int error= s->error_status_table[mb_xy];
  631.         
  632.             if(error&(1<<error_type))
  633.                 end_ok=1;
  634.             if(error&(8<<error_type))
  635.                 end_ok=1;
  636.             if(!end_ok)
  637.                 s->error_status_table[mb_xy]|= 1<<error_type;
  638.             if(error&VP_START)
  639.                 end_ok=0;
  640.         }
  641.     }
  642. #endif
  643. #if 1
  644.     /* handle slices with partitions of different length */
  645.     if(s->partitioned_frame){
  646.         int end_ok=0;
  647.         for(i=s->mb_num-1; i>=0; i--){
  648.             const int mb_xy= s->mb_index2xy[i];
  649.             int error= s->error_status_table[mb_xy];
  650.         
  651.             if(error&AC_END)
  652.                 end_ok=0;
  653.             if((error&MV_END) || (error&DC_END) || (error&AC_ERROR))
  654.                 end_ok=1;
  655.             if(!end_ok)
  656.                 s->error_status_table[mb_xy]|= AC_ERROR;
  657.             if(error&VP_START)
  658.                 end_ok=0;
  659.         }
  660.     }
  661. #endif
  662.     /* handle missing slices */
  663.     if(s->error_resilience>=4){
  664.         int end_ok=1;
  665.                 
  666.         for(i=s->mb_num-2; i>=s->mb_width+100; i--){ //FIXME +100 hack
  667.             const int mb_xy= s->mb_index2xy[i];
  668.             int error1= s->error_status_table[mb_xy  ];
  669.             int error2= s->error_status_table[s->mb_index2xy[i+1]];
  670.         
  671.             if(error1&VP_START)
  672.                 end_ok=1;
  673.              
  674.             if(   error2==(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END)
  675.                && error1!=(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END) 
  676.                && ((error1&AC_END) || (error1&DC_END) || (error1&MV_END))){ //end & uninited
  677.                 end_ok=0;
  678.             }
  679.         
  680.             if(!end_ok)
  681.                 s->error_status_table[mb_xy]|= DC_ERROR|AC_ERROR|MV_ERROR;
  682.         }
  683.     }
  684.     
  685. #if 1
  686.     /* backward mark errors */
  687.     distance=9999999;
  688.     for(error_type=1; error_type<=3; error_type++){
  689.         for(i=s->mb_num-1; i>=0; i--){
  690.             const int mb_xy= s->mb_index2xy[i];
  691.             int error= s->error_status_table[mb_xy];
  692.             
  693.             if(!s->mbskip_table[mb_xy]) //FIXME partition specific
  694.                 distance++;            
  695.             if(error&(1<<error_type))
  696.                 distance= 0;
  697.             if(s->partitioned_frame){
  698.                 if(distance < threshold_part[error_type-1])
  699.                     s->error_status_table[mb_xy]|= 1<<error_type;
  700.             }else{
  701.                 if(distance < threshold)
  702.                     s->error_status_table[mb_xy]|= 1<<error_type;
  703.             }
  704.             if(error&VP_START)
  705.                 distance= 9999999;
  706.         }
  707.     }
  708. #endif
  709.     /* forward mark errors */
  710.     error=0;
  711.     for(i=0; i<s->mb_num; i++){
  712.         const int mb_xy= s->mb_index2xy[i];
  713.         int old_error= s->error_status_table[mb_xy];
  714.         
  715.         if(old_error&VP_START)
  716.             error= old_error& (DC_ERROR|AC_ERROR|MV_ERROR);
  717.         else{
  718.             error|= old_error& (DC_ERROR|AC_ERROR|MV_ERROR);
  719.             s->error_status_table[mb_xy]|= error;
  720.         }
  721.     }
  722. #if 1
  723.     /* handle not partitioned case */
  724.     if(!s->partitioned_frame){
  725.         for(i=0; i<s->mb_num; i++){
  726.             const int mb_xy= s->mb_index2xy[i];
  727.             error= s->error_status_table[mb_xy];
  728.             if(error&(AC_ERROR|DC_ERROR|MV_ERROR))
  729.                 error|= AC_ERROR|DC_ERROR|MV_ERROR;
  730.             s->error_status_table[mb_xy]= error;
  731.         }
  732.     }
  733. #endif
  734.     is_intra_likely= is_intra_more_likely(s);
  735.     /* set unknown mb-type to most likely */
  736.     for(i=0; i<s->mb_num; i++){
  737.         const int mb_xy= s->mb_index2xy[i];
  738.         error= s->error_status_table[mb_xy];
  739.         if(!((error&DC_ERROR) && (error&MV_ERROR)))
  740.             continue;
  741.         if(is_intra_likely)
  742.             s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA4x4;
  743.         else
  744.             s->current_picture.mb_type[mb_xy]= MB_TYPE_16x16 | MB_TYPE_L0;
  745.     }
  746.     
  747.     /* handle inter blocks with damaged AC */
  748.     for(mb_y=0; mb_y<s->mb_height; mb_y++){
  749.         for(mb_x=0; mb_x<s->mb_width; mb_x++){
  750.             const int mb_xy= mb_x + mb_y * s->mb_stride;
  751.             const int mb_type= s->current_picture.mb_type[mb_xy];
  752.             error= s->error_status_table[mb_xy];
  753.             if(IS_INTRA(mb_type)) continue; //intra
  754.             if(error&MV_ERROR) continue;              //inter with damaged MV
  755.             if(!(error&AC_ERROR)) continue;           //undamaged inter
  756.             
  757.             s->mv_dir = MV_DIR_FORWARD;
  758.             s->mb_intra=0;
  759.             s->mb_skiped=0;
  760.             if(IS_8X8(mb_type)){
  761.                 int mb_index= mb_x*2 + mb_y*2*s->b8_stride;
  762.                 int j;
  763.                 s->mv_type = MV_TYPE_8X8;
  764.                 for(j=0; j<4; j++){
  765.                     s->mv[0][j][0] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->b8_stride ][0];
  766.                     s->mv[0][j][1] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->b8_stride ][1];
  767.                 }
  768.             }else{
  769.                 s->mv_type = MV_TYPE_16X16;
  770.                 s->mv[0][0][0] = s->current_picture.motion_val[0][ mb_x*2 + mb_y*2*s->b8_stride ][0];
  771.                 s->mv[0][0][1] = s->current_picture.motion_val[0][ mb_x*2 + mb_y*2*s->b8_stride ][1];
  772.             }
  773.         
  774.     s->dsp.clear_blocks(s->block[0]);
  775.             s->mb_x= mb_x;
  776.             s->mb_y= mb_y;
  777.             decode_mb(s);
  778.         }
  779.     }
  780.     /* guess MVs */
  781.     if(s->pict_type==B_TYPE){
  782.         for(mb_y=0; mb_y<s->mb_height; mb_y++){
  783.             for(mb_x=0; mb_x<s->mb_width; mb_x++){
  784.                 int xy= mb_x*2 + mb_y*2*s->b8_stride;
  785.                 const int mb_xy= mb_x + mb_y * s->mb_stride;
  786.                 const int mb_type= s->current_picture.mb_type[mb_xy];
  787.                 error= s->error_status_table[mb_xy];
  788.                 if(IS_INTRA(mb_type)) continue;
  789.                 if(!(error&MV_ERROR)) continue;           //inter with undamaged MV
  790.                 if(!(error&AC_ERROR)) continue;           //undamaged inter
  791.             
  792.                 s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD;
  793.                 s->mb_intra=0;
  794.                 s->mv_type = MV_TYPE_16X16;
  795.                 s->mb_skiped=0;
  796.                 
  797.                 if(s->pp_time){
  798.                     int time_pp= s->pp_time;
  799.                     int time_pb= s->pb_time;
  800.             
  801.                     s->mv[0][0][0] = s->next_picture.motion_val[0][xy][0]*time_pb/time_pp;
  802.                     s->mv[0][0][1] = s->next_picture.motion_val[0][xy][1]*time_pb/time_pp;
  803.                     s->mv[1][0][0] = s->next_picture.motion_val[0][xy][0]*(time_pb - time_pp)/time_pp;
  804.                     s->mv[1][0][1] = s->next_picture.motion_val[0][xy][1]*(time_pb - time_pp)/time_pp;
  805.                 }else{
  806.                     s->mv[0][0][0]= 0;
  807.                     s->mv[0][0][1]= 0;
  808.                     s->mv[1][0][0]= 0;
  809.                     s->mv[1][0][1]= 0;
  810.                 }
  811.                 s->dsp.clear_blocks(s->block[0]);
  812.                 s->mb_x= mb_x;
  813.                 s->mb_y= mb_y;
  814.                 decode_mb(s);
  815.             }
  816.         }
  817.     }else
  818.         guess_mv(s);
  819. #ifdef HAVE_XVMC
  820.     /* the filters below are not XvMC compatible, skip them */
  821.     if(s->avctx->xvmc_acceleration) goto ec_clean;
  822. #endif
  823.     /* fill DC for inter blocks */
  824.     for(mb_y=0; mb_y<s->mb_height; mb_y++){
  825.         for(mb_x=0; mb_x<s->mb_width; mb_x++){
  826.             int dc, dcu, dcv, y, n;
  827.             int16_t *dc_ptr;
  828.             uint8_t *dest_y, *dest_cb, *dest_cr;
  829.             const int mb_xy= mb_x + mb_y * s->mb_stride;
  830.             const int mb_type= s->current_picture.mb_type[mb_xy];
  831.            
  832.             error= s->error_status_table[mb_xy];
  833.             if(IS_INTRA(mb_type) && s->partitioned_frame) continue;
  834. //            if(error&MV_ERROR) continue; //inter data damaged FIXME is this good?
  835.             
  836.             dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
  837.             dest_cb= s->current_picture.data[1] + mb_x*8  + mb_y*8 *s->uvlinesize;
  838.             dest_cr= s->current_picture.data[2] + mb_x*8  + mb_y*8 *s->uvlinesize;
  839.            
  840.             dc_ptr= &s->dc_val[0][mb_x*2 + mb_y*2*s->b8_stride];
  841.             for(n=0; n<4; n++){
  842.                 dc=0;
  843.                 for(y=0; y<8; y++){
  844.                     int x;
  845.                     for(x=0; x<8; x++){
  846.                        dc+= dest_y[x + (n&1)*8 + (y + (n>>1)*8)*s->linesize];
  847.                     }
  848.                 }
  849.                 dc_ptr[(n&1) + (n>>1)*s->b8_stride]= (dc+4)>>3;
  850.             }
  851.             dcu=dcv=0;
  852.             for(y=0; y<8; y++){
  853.                 int x;
  854.                 for(x=0; x<8; x++){
  855.                     dcu+=dest_cb[x + y*(s->uvlinesize)];
  856.                     dcv+=dest_cr[x + y*(s->uvlinesize)];
  857.                 }
  858.             }
  859.             s->dc_val[1][mb_x + mb_y*s->mb_stride]= (dcu+4)>>3;
  860.             s->dc_val[2][mb_x + mb_y*s->mb_stride]= (dcv+4)>>3;   
  861.         }
  862.     }
  863. #if 1
  864.     /* guess DC for damaged blocks */
  865.     guess_dc(s, s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride, 1);
  866.     guess_dc(s, s->dc_val[1], s->mb_width  , s->mb_height  , s->mb_stride, 0);
  867.     guess_dc(s, s->dc_val[2], s->mb_width  , s->mb_height  , s->mb_stride, 0);
  868. #endif   
  869.     /* filter luma DC */
  870.     filter181(s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride);
  871.     
  872. #if 1
  873.     /* render DC only intra */
  874.     for(mb_y=0; mb_y<s->mb_height; mb_y++){
  875.         for(mb_x=0; mb_x<s->mb_width; mb_x++){
  876.             uint8_t *dest_y, *dest_cb, *dest_cr;
  877.             const int mb_xy= mb_x + mb_y * s->mb_stride;
  878.             const int mb_type= s->current_picture.mb_type[mb_xy];
  879.             error= s->error_status_table[mb_xy];
  880.             if(IS_INTER(mb_type)) continue;
  881.             if(!(error&AC_ERROR)) continue;              //undamaged
  882.             
  883.             dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
  884.             dest_cb= s->current_picture.data[1] + mb_x*8  + mb_y*8 *s->uvlinesize;
  885.             dest_cr= s->current_picture.data[2] + mb_x*8  + mb_y*8 *s->uvlinesize;
  886.             
  887.             put_dc(s, dest_y, dest_cb, dest_cr, mb_x, mb_y);
  888.         }
  889.     }
  890. #endif
  891.     
  892.     if(s->avctx->error_concealment&FF_EC_DEBLOCK){
  893.         /* filter horizontal block boundaries */
  894.         h_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize  , 1);
  895.         h_block_filter(s, s->current_picture.data[1], s->mb_width  , s->mb_height  , s->uvlinesize, 0);
  896.         h_block_filter(s, s->current_picture.data[2], s->mb_width  , s->mb_height  , s->uvlinesize, 0);
  897.         /* filter vertical block boundaries */
  898.         v_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize  , 1);
  899.         v_block_filter(s, s->current_picture.data[1], s->mb_width  , s->mb_height  , s->uvlinesize, 0);
  900.         v_block_filter(s, s->current_picture.data[2], s->mb_width  , s->mb_height  , s->uvlinesize, 0);
  901.     }
  902. #ifdef HAVE_XVMC
  903. ec_clean:
  904. #endif
  905.     /* clean a few tables */
  906.     for(i=0; i<s->mb_num; i++){
  907.         const int mb_xy= s->mb_index2xy[i];
  908.         int error= s->error_status_table[mb_xy];
  909.         
  910.         if(s->pict_type!=B_TYPE && (error&(DC_ERROR|MV_ERROR|AC_ERROR))){
  911.             s->mbskip_table[mb_xy]=0;
  912.         }
  913.         s->mbintra_table[mb_xy]=1;
  914.     }    
  915. }