Mercurial > libavcodec.hg
comparison error_resilience.c @ 11467:c9f240e43ef9 libavcodec
Fix guess_mv() so that it works correctly with 4x4 MV blocks.
author | michael |
---|---|
date | Fri, 12 Mar 2010 16:59:21 +0000 |
parents | 411ab09ada91 |
children | b16c5c5705df |
comparison
equal
deleted
inserted
replaced
11466:049a0c71e5a3 | 11467:c9f240e43ef9 |
---|---|
28 #include <limits.h> | 28 #include <limits.h> |
29 | 29 |
30 #include "avcodec.h" | 30 #include "avcodec.h" |
31 #include "dsputil.h" | 31 #include "dsputil.h" |
32 #include "mpegvideo.h" | 32 #include "mpegvideo.h" |
33 #include "h264.h" | |
34 | |
35 /* | |
36 * H264 redefines mb_intra so it is not mistakely used (its uninitialized in h264) | |
37 * but error concealment must support both h264 and h263 thus we must undo this | |
38 */ | |
39 #undef mb_intra | |
33 | 40 |
34 static void decode_mb(MpegEncContext *s){ | 41 static void decode_mb(MpegEncContext *s){ |
35 s->dest[0] = s->current_picture.data[0] + (s->mb_y * 16* s->linesize ) + s->mb_x * 16; | 42 s->dest[0] = s->current_picture.data[0] + (s->mb_y * 16* s->linesize ) + s->mb_x * 16; |
36 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); | 43 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); |
37 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); | 44 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); |
38 | 45 |
39 MPV_decode_mb(s, s->block); | 46 MPV_decode_mb(s, s->block); |
47 } | |
48 | |
49 /** | |
50 * @param stride the number of MVs to get to the next row | |
51 * @param mv_step the number of MVs per row or column in a macroblock | |
52 */ | |
53 static void set_mv_strides(MpegEncContext *s, int *mv_step, int *stride){ | |
54 if(s->codec_id == CODEC_ID_H264){ | |
55 H264Context *h= (void*)s; | |
56 assert(s->quarter_sample); | |
57 *mv_step= 4; | |
58 *stride= h->b_stride; | |
59 }else{ | |
60 *mv_step= 2; | |
61 *stride= s->b8_stride; | |
62 } | |
40 } | 63 } |
41 | 64 |
42 /** | 65 /** |
43 * replaces the current MB with a flat dc only version. | 66 * replaces the current MB with a flat dc only version. |
44 */ | 67 */ |
318 #define MV_UNCHANGED 1 | 341 #define MV_UNCHANGED 1 |
319 const int mb_stride = s->mb_stride; | 342 const int mb_stride = s->mb_stride; |
320 const int mb_width = s->mb_width; | 343 const int mb_width = s->mb_width; |
321 const int mb_height= s->mb_height; | 344 const int mb_height= s->mb_height; |
322 int i, depth, num_avail; | 345 int i, depth, num_avail; |
323 int mb_x, mb_y; | 346 int mb_x, mb_y, mot_step, mot_stride; |
347 | |
348 set_mv_strides(s, &mot_step, &mot_stride); | |
324 | 349 |
325 num_avail=0; | 350 num_avail=0; |
326 for(i=0; i<s->mb_num; i++){ | 351 for(i=0; i<s->mb_num; i++){ |
327 const int mb_xy= s->mb_index2xy[ i ]; | 352 const int mb_xy= s->mb_index2xy[ i ]; |
328 int f=0; | 353 int f=0; |
377 int mv_predictor[8][2]={{0}}; | 402 int mv_predictor[8][2]={{0}}; |
378 int pred_count=0; | 403 int pred_count=0; |
379 int j; | 404 int j; |
380 int best_score=256*256*256*64; | 405 int best_score=256*256*256*64; |
381 int best_pred=0; | 406 int best_pred=0; |
382 const int mot_stride= s->b8_stride; | 407 const int mot_index= (mb_x + mb_y*mot_stride) * mot_step; |
383 const int mot_index= mb_x*2 + mb_y*2*mot_stride; | |
384 int prev_x= s->current_picture.motion_val[0][mot_index][0]; | 408 int prev_x= s->current_picture.motion_val[0][mot_index][0]; |
385 int prev_y= s->current_picture.motion_val[0][mot_index][1]; | 409 int prev_y= s->current_picture.motion_val[0][mot_index][1]; |
386 | 410 |
387 if((mb_x^mb_y^pass)&1) continue; | 411 if((mb_x^mb_y^pass)&1) continue; |
388 | 412 |
405 if(j==0 && pass>1) continue; | 429 if(j==0 && pass>1) continue; |
406 | 430 |
407 none_left=0; | 431 none_left=0; |
408 | 432 |
409 if(mb_x>0 && fixed[mb_xy-1]){ | 433 if(mb_x>0 && fixed[mb_xy-1]){ |
410 mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - 2][0]; | 434 mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - mot_step][0]; |
411 mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - 2][1]; | 435 mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_step][1]; |
412 pred_count++; | 436 pred_count++; |
413 } | 437 } |
414 if(mb_x+1<mb_width && fixed[mb_xy+1]){ | 438 if(mb_x+1<mb_width && fixed[mb_xy+1]){ |
415 mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + 2][0]; | 439 mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + mot_step][0]; |
416 mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + 2][1]; | 440 mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_step][1]; |
417 pred_count++; | 441 pred_count++; |
418 } | 442 } |
419 if(mb_y>0 && fixed[mb_xy-mb_stride]){ | 443 if(mb_y>0 && fixed[mb_xy-mb_stride]){ |
420 mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - mot_stride*2][0]; | 444 mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - mot_stride*mot_step][0]; |
421 mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_stride*2][1]; | 445 mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_stride*mot_step][1]; |
422 pred_count++; | 446 pred_count++; |
423 } | 447 } |
424 if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){ | 448 if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){ |
425 mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + mot_stride*2][0]; | 449 mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + mot_stride*mot_step][0]; |
426 mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_stride*2][1]; | 450 mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_stride*mot_step][1]; |
427 pred_count++; | 451 pred_count++; |
428 } | 452 } |
429 if(pred_count==0) continue; | 453 if(pred_count==0) continue; |
430 | 454 |
431 if(pred_count>1){ | 455 if(pred_count>1){ |