error_resilience.c
上传用户:jylinhe
上传日期:2022-07-11
资源大小:334k
文件大小:40k
源码类别:

多媒体编程

开发平台:

Visual C++

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