Revision 673fc638

View differences:

libavcodec/error_resilience.c
38 38
 */
39 39
#undef mb_intra
40 40

  
41
static void decode_mb(MpegEncContext *s){
41
static void decode_mb(MpegEncContext *s, int ref){
42 42
    s->dest[0] = s->current_picture.data[0] + (s->mb_y * 16* s->linesize  ) + s->mb_x * 16;
43 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);
44 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);
......
47 47
        H264Context *h= (void*)s;
48 48
        h->mb_xy= s->mb_x + s->mb_y*s->mb_stride;
49 49
        memset(h->non_zero_count_cache, 0, sizeof(h->non_zero_count_cache));
50
        fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1);
50
        assert(ref>=0);
51
        if(ref >= h->ref_count[0]) //FIXME it is posible albeit uncommon that slice references differ between slices, we take the easy approuch and ignore it for now. If this turns out to have any relevance in practice then correct remapping should be added
52
            ref=0;
53
        fill_rectangle(&s->current_picture.ref_index[0][4*h->mb_xy], 2, 2, 2, ref, 1);
54
        fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
51 55
        fill_rectangle(h->mv_cache[0][ scan8[0] ], 4, 4, 8, pack16to32(s->mv[0][0][0],s->mv[0][0][1]), 4);
52
        assert(h->list_count==1);
53 56
        assert(!FRAME_MBAFF);
54 57
        ff_h264_hl_decode_mb(h);
55 58
    }else{
59
        assert(ref==0);
56 60
    MPV_decode_mb(s, s->block);
57 61
    }
58 62
}
......
397 401
                s->mb_y= mb_y;
398 402
                s->mv[0][0][0]= 0;
399 403
                s->mv[0][0][1]= 0;
400
                decode_mb(s);
404
                decode_mb(s, 0);
401 405
            }
402 406
        }
403 407
        return;
......
417 421
                for(mb_x=0; mb_x<s->mb_width; mb_x++){
418 422
                    const int mb_xy= mb_x + mb_y*s->mb_stride;
419 423
                    int mv_predictor[8][2]={{0}};
424
                    int ref[8]={0};
420 425
                    int pred_count=0;
421 426
                    int j;
422 427
                    int best_score=256*256*256*64;
......
450 455
                    if(mb_x>0 && fixed[mb_xy-1]){
451 456
                        mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - mot_step][0];
452 457
                        mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_step][1];
458
                        ref         [pred_count]   = s->current_picture.ref_index[0][4*(mb_xy-1)];
453 459
                        pred_count++;
454 460
                    }
455 461
                    if(mb_x+1<mb_width && fixed[mb_xy+1]){
456 462
                        mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + mot_step][0];
457 463
                        mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_step][1];
464
                        ref         [pred_count]   = s->current_picture.ref_index[0][4*(mb_xy+1)];
458 465
                        pred_count++;
459 466
                    }
460 467
                    if(mb_y>0 && fixed[mb_xy-mb_stride]){
461 468
                        mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - mot_stride*mot_step][0];
462 469
                        mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_stride*mot_step][1];
470
                        ref         [pred_count]   = s->current_picture.ref_index[0][4*(mb_xy-s->mb_stride)];
463 471
                        pred_count++;
464 472
                    }
465 473
                    if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){
466 474
                        mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + mot_stride*mot_step][0];
467 475
                        mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_stride*mot_step][1];
476
                        ref         [pred_count]   = s->current_picture.ref_index[0][4*(mb_xy+s->mb_stride)];
468 477
                        pred_count++;
469 478
                    }
470 479
                    if(pred_count==0) continue;
471 480

  
472 481
                    if(pred_count>1){
473
                        int sum_x=0, sum_y=0;
474
                        int max_x, max_y, min_x, min_y;
482
                        int sum_x=0, sum_y=0, sum_r=0;
483
                        int max_x, max_y, min_x, min_y, max_r, min_r;
475 484

  
476 485
                        for(j=0; j<pred_count; j++){
477 486
                            sum_x+= mv_predictor[j][0];
478 487
                            sum_y+= mv_predictor[j][1];
488
                            sum_r+= ref[j];
489
                            if(j && ref[j] != ref[j-1])
490
                                goto skip_mean_and_median;
479 491
                        }
480 492

  
481 493
                        /* mean */
482 494
                        mv_predictor[pred_count][0] = sum_x/j;
483 495
                        mv_predictor[pred_count][1] = sum_y/j;
496
                        ref         [pred_count]    = sum_r/j;
484 497

  
485 498
                        /* median */
486 499
                        if(pred_count>=3){
487
                            min_y= min_x= 99999;
488
                            max_y= max_x=-99999;
500
                            min_y= min_x= min_r= 99999;
501
                            max_y= max_x= max_r=-99999;
489 502
                        }else{
490
                            min_x=min_y=max_x=max_y=0;
503
                            min_x=min_y=max_x=max_y=min_r=max_r=0;
491 504
                        }
492 505
                        for(j=0; j<pred_count; j++){
493 506
                            max_x= FFMAX(max_x, mv_predictor[j][0]);
494 507
                            max_y= FFMAX(max_y, mv_predictor[j][1]);
508
                            max_r= FFMAX(max_r, ref[j]);
495 509
                            min_x= FFMIN(min_x, mv_predictor[j][0]);
496 510
                            min_y= FFMIN(min_y, mv_predictor[j][1]);
511
                            min_r= FFMIN(min_r, ref[j]);
497 512
                        }
498 513
                        mv_predictor[pred_count+1][0] = sum_x - max_x - min_x;
499 514
                        mv_predictor[pred_count+1][1] = sum_y - max_y - min_y;
515
                        ref         [pred_count+1]    = sum_r - max_r - min_r;
500 516

  
501 517
                        if(pred_count==4){
502 518
                            mv_predictor[pred_count+1][0] /= 2;
503 519
                            mv_predictor[pred_count+1][1] /= 2;
520
                            ref         [pred_count+1]    /= 2;
504 521
                        }
505 522
                        pred_count+=2;
506 523
                    }
524
skip_mean_and_median:
507 525

  
508 526
                    /* zero MV */
509 527
                    pred_count++;
......
511 529
                    /* last MV */
512 530
                    mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index][0];
513 531
                    mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index][1];
532
                    ref         [pred_count]   = s->current_picture.ref_index[0][4*mb_xy];
514 533
                    pred_count++;
515 534

  
516 535
                    s->mv_dir = MV_DIR_FORWARD;
......
530 549
                        s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[j][0];
531 550
                        s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[j][1];
532 551

  
533
                        decode_mb(s);
552
                        if(ref[j]<0) //predictor intra or otherwise not available
553
                            continue;
554

  
555
                        decode_mb(s, ref[j]);
534 556

  
535 557
                        if(mb_x>0 && fixed[mb_xy-1]){
536 558
                            int k;
......
568 590
                            s->current_picture.motion_val[0][mot_index+i+j*mot_stride][1]= s->mv[0][0][1];
569 591
                        }
570 592

  
571
                    decode_mb(s);
593
                    decode_mb(s, ref[best_pred]);
572 594

  
573 595

  
574 596
                    if(s->mv[0][0][0] != prev_x || s->mv[0][0][1] != prev_y){
......
746 768
        s->current_picture= *s->current_picture_ptr;
747 769
    }
748 770

  
749
    for(i=0; i<2; i++){
750
        if(pic->ref_index[i])
751
            memset(pic->ref_index[i], 0, size * sizeof(uint8_t));
752
    }
753

  
754 771
    if(s->avctx->debug&FF_DEBUG_ER){
755 772
        for(mb_y=0; mb_y<s->mb_height; mb_y++){
756 773
            for(mb_x=0; mb_x<s->mb_width; mb_x++){
......
948 965

  
949 966
            s->mb_x= mb_x;
950 967
            s->mb_y= mb_y;
951
            decode_mb(s);
968
            decode_mb(s, 0/*FIXME h264 partitioned slices need this set*/);
952 969
        }
953 970
    }
954 971

  
......
990 1007
                s->dsp.clear_blocks(s->block[0]);
991 1008
                s->mb_x= mb_x;
992 1009
                s->mb_y= mb_y;
993
                decode_mb(s);
1010
                decode_mb(s, 0);
994 1011
            }
995 1012
        }
996 1013
    }else

Also available in: Unified diff