You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1099 lines
41KB

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