Revision 137c8468

View differences:

libavcodec/error_resilience.c
45 45
{
46 46
    int dc, dcu, dcv, y, i;
47 47
    for(i=0; i<4; i++){
48
        dc= s->dc_val[0][mb_x*2+1 + (i&1) + (mb_y*2+1 + (i>>1))*(s->mb_width*2+2)];
48
        dc= s->dc_val[0][mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*s->b8_stride];
49 49
        if(dc<0) dc=0;
50 50
        else if(dc>2040) dc=2040;
51 51
        for(y=0; y<8; y++){
......
55 55
            }
56 56
        }
57 57
    }
58
    dcu = s->dc_val[1][mb_x+1 + (mb_y+1)*(s->mb_width+2)];
59
    dcv = s->dc_val[2][mb_x+1 + (mb_y+1)*(s->mb_width+2)];
58
    dcu = s->dc_val[1][mb_x + mb_y*s->mb_stride];
59
    dcv = s->dc_val[2][mb_x + mb_y*s->mb_stride];
60 60
    if     (dcu<0   ) dcu=0;
61 61
    else if(dcu>2040) dcu=2040;
62 62
    if     (dcv<0   ) dcv=0;
......
209 209
            int left_damage =  left_status&(DC_ERROR|AC_ERROR|MV_ERROR);
210 210
            int right_damage= right_status&(DC_ERROR|AC_ERROR|MV_ERROR);
211 211
            int offset= b_x*8 + b_y*stride*8;
212
            int16_t *left_mv=  s->current_picture.motion_val[0][s->block_wrap[0]*((b_y<<(1-is_luma)) + 1) + ( b_x   <<(1-is_luma))];
213
            int16_t *right_mv= s->current_picture.motion_val[0][s->block_wrap[0]*((b_y<<(1-is_luma)) + 1) + ((b_x+1)<<(1-is_luma))];
212
            int16_t *left_mv=  s->current_picture.motion_val[0][s->b8_stride*(b_y<<(1-is_luma)) + ( b_x   <<(1-is_luma))];
213
            int16_t *right_mv= s->current_picture.motion_val[0][s->b8_stride*(b_y<<(1-is_luma)) + ((b_x+1)<<(1-is_luma))];
214 214
            
215 215
            if(!(left_damage||right_damage)) continue; // both undamaged
216 216
            
......
269 269
            int top_damage =      top_status&(DC_ERROR|AC_ERROR|MV_ERROR);
270 270
            int bottom_damage= bottom_status&(DC_ERROR|AC_ERROR|MV_ERROR);
271 271
            int offset= b_x*8 + b_y*stride*8;
272
            int16_t *top_mv=    s->current_picture.motion_val[0][s->block_wrap[0]*(( b_y   <<(1-is_luma)) + 1) + (b_x<<(1-is_luma))];
273
            int16_t *bottom_mv= s->current_picture.motion_val[0][s->block_wrap[0]*(((b_y+1)<<(1-is_luma)) + 1) + (b_x<<(1-is_luma))];
272
            int16_t *top_mv=    s->current_picture.motion_val[0][s->b8_stride*( b_y   <<(1-is_luma)) + (b_x<<(1-is_luma))];
273
            int16_t *bottom_mv= s->current_picture.motion_val[0][s->b8_stride*((b_y+1)<<(1-is_luma)) + (b_x<<(1-is_luma))];
274 274
            
275 275
            if(!(top_damage||bottom_damage)) continue; // both undamaged
276 276
            
......
378 378
                    int j;
379 379
                    int best_score=256*256*256*64;
380 380
                    int best_pred=0;
381
                    const int mot_stride= mb_width*2+2;
382
                    const int mot_index= mb_x*2 + 1 + (mb_y*2+1)*mot_stride;
381
                    const int mot_stride= s->b8_stride;
382
                    const int mot_index= mb_x*2 + mb_y*2*mot_stride;
383 383
                    int prev_x= s->current_picture.motion_val[0][mot_index][0];
384 384
                    int prev_y= s->current_picture.motion_val[0][mot_index][1];
385 385

  
......
672 672
    av_log(s->avctx, AV_LOG_INFO, "concealing errors\n");
673 673
    
674 674
    if(s->current_picture.motion_val[0] == NULL){
675
        int size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2);
675
        int size = s->b8_stride * 2 * s->mb_height;
676 676
        Picture *pic= s->current_picture_ptr;
677 677
        
678 678
        av_log(s->avctx, AV_LOG_ERROR, "Warning MVs not available\n");
679 679
            
680 680
        for(i=0; i<2; i++){
681
            pic->motion_val_base[i]= av_mallocz((size+1) * 2 * sizeof(uint16_t)); //FIXME size
682
            pic->motion_val[i]= pic->motion_val_base[i]+1;
681
            pic->motion_val_base[i]= av_mallocz((size+2) * 2 * sizeof(uint16_t));
682
            pic->motion_val[i]= pic->motion_val_base[i]+2;
683 683
        }
684 684
        pic->motion_subsample_log2= 3;
685 685
        s->current_picture= *s->current_picture_ptr;
......
845 845
            s->mb_intra=0;
846 846
            s->mb_skiped=0;
847 847
            if(IS_8X8(mb_type)){
848
                int mb_index= mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0];
848
                int mb_index= mb_x*2 + mb_y*2*s->b8_stride;
849 849
                int j;
850 850
                s->mv_type = MV_TYPE_8X8;
851 851
                for(j=0; j<4; j++){
852
                    s->mv[0][j][0] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->block_wrap[0] ][0];
853
                    s->mv[0][j][1] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->block_wrap[0] ][1];
852
                    s->mv[0][j][0] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->b8_stride ][0];
853
                    s->mv[0][j][1] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->b8_stride ][1];
854 854
                }
855 855
            }else{
856 856
                s->mv_type = MV_TYPE_16X16;
857
                s->mv[0][0][0] = s->current_picture.motion_val[0][ mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0] ][0];
858
                s->mv[0][0][1] = s->current_picture.motion_val[0][ mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0] ][1];
857
                s->mv[0][0][0] = s->current_picture.motion_val[0][ mb_x*2 + mb_y*2*s->b8_stride ][0];
858
                s->mv[0][0][1] = s->current_picture.motion_val[0][ mb_x*2 + mb_y*2*s->b8_stride ][1];
859 859
            }
860 860
        
861 861
	    s->dsp.clear_blocks(s->block[0]);
......
870 870
    if(s->pict_type==B_TYPE){
871 871
        for(mb_y=0; mb_y<s->mb_height; mb_y++){
872 872
            for(mb_x=0; mb_x<s->mb_width; mb_x++){
873
                int xy= mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0];
873
                int xy= mb_x*2 + mb_y*2*s->b8_stride;
874 874
                const int mb_xy= mb_x + mb_y * s->mb_stride;
875 875
                const int mb_type= s->current_picture.mb_type[mb_xy];
876 876
                error= s->error_status_table[mb_xy];
......
930 930
            dest_cb= s->current_picture.data[1] + mb_x*8  + mb_y*8 *s->uvlinesize;
931 931
            dest_cr= s->current_picture.data[2] + mb_x*8  + mb_y*8 *s->uvlinesize;
932 932
           
933
            dc_ptr= &s->dc_val[0][mb_x*2+1 + (mb_y*2+1)*(s->mb_width*2+2)];
933
            dc_ptr= &s->dc_val[0][mb_x*2 + mb_y*2*s->b8_stride];
934 934
            for(n=0; n<4; n++){
935 935
                dc=0;
936 936
                for(y=0; y<8; y++){
......
939 939
                       dc+= dest_y[x + (n&1)*8 + (y + (n>>1)*8)*s->linesize];
940 940
                    }
941 941
                }
942
                dc_ptr[(n&1) + (n>>1)*(s->mb_width*2+2)]= (dc+4)>>3;
942
                dc_ptr[(n&1) + (n>>1)*s->b8_stride]= (dc+4)>>3;
943 943
            }
944 944

  
945 945
            dcu=dcv=0;
......
950 950
                    dcv+=dest_cr[x + y*(s->uvlinesize)];
951 951
                }
952 952
            }
953
            s->dc_val[1][mb_x+1 + (mb_y+1)*(s->mb_width+2)]= (dcu+4)>>3;
954
            s->dc_val[2][mb_x+1 + (mb_y+1)*(s->mb_width+2)]= (dcv+4)>>3;   
953
            s->dc_val[1][mb_x + mb_y*s->mb_stride]= (dcu+4)>>3;
954
            s->dc_val[2][mb_x + mb_y*s->mb_stride]= (dcv+4)>>3;   
955 955
        }
956 956
    }
957 957
#if 1
958 958
    /* guess DC for damaged blocks */
959
    guess_dc(s, s->dc_val[0] + s->mb_width*2+3, s->mb_width*2, s->mb_height*2, s->mb_width*2+2, 1);
960
    guess_dc(s, s->dc_val[1] + s->mb_width  +3, s->mb_width  , s->mb_height  , s->mb_width  +2, 0);
961
    guess_dc(s, s->dc_val[2] + s->mb_width  +3, s->mb_width  , s->mb_height  , s->mb_width  +2, 0);
959
    guess_dc(s, s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride, 1);
960
    guess_dc(s, s->dc_val[1], s->mb_width  , s->mb_height  , s->mb_stride, 0);
961
    guess_dc(s, s->dc_val[2], s->mb_width  , s->mb_height  , s->mb_stride, 0);
962 962
#endif   
963 963
    /* filter luma DC */
964
    filter181(s->dc_val[0] + s->mb_width*2+3, s->mb_width*2, s->mb_height*2, s->mb_width*2+2);
964
    filter181(s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride);
965 965
    
966 966
#if 1
967 967
    /* render DC only intra */
libavcodec/h263.c
610 610
void ff_h263_update_motion_val(MpegEncContext * s){
611 611
    const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
612 612
               //FIXME a lot of thet is only needed for !low_delay
613
    const int wrap = s->block_wrap[0];
613
    const int wrap = s->b8_stride;
614 614
    const int xy = s->block_index[0];
615 615
    
616 616
    s->current_picture.mbskip_table[mb_xy]= s->mb_skiped; 
......
985 985
                }
986 986

  
987 987
                /* motion vectors: 16x16 mode */
988
                h263_pred_motion(s, 0, &pred_x, &pred_y);
988
                h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
989 989
            
990 990
                h263_encode_motion(s, motion_x - pred_x, s->f_code);
991 991
                h263_encode_motion(s, motion_y - pred_y, s->f_code);
......
1009 1009
                }
1010 1010

  
1011 1011
                /* motion vectors: 16x8 interlaced mode */
1012
                h263_pred_motion(s, 0, &pred_x, &pred_y);
1012
                h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
1013 1013
                pred_y /=2;
1014 1014
                
1015 1015
                put_bits(&s->pb, 1, s->field_select[0][0]);
......
1037 1037

  
1038 1038
                for(i=0; i<4; i++){
1039 1039
                    /* motion vectors: 8x8 mode*/
1040
                    h263_pred_motion(s, i, &pred_x, &pred_y);
1040
                    h263_pred_motion(s, i, 0, &pred_x, &pred_y);
1041 1041

  
1042 1042
                    h263_encode_motion(s, s->current_picture.motion_val[0][ s->block_index[i] ][0] - pred_x, s->f_code);
1043 1043
                    h263_encode_motion(s, s->current_picture.motion_val[0][ s->block_index[i] ][1] - pred_y, s->f_code);
......
1185 1185
            }
1186 1186

  
1187 1187
            /* motion vectors: 16x16 mode */
1188
            h263_pred_motion(s, 0, &pred_x, &pred_y);
1188
            h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
1189 1189
            
1190 1190
            if (!s->umvplus) {  
1191 1191
                h263_encode_motion(s, motion_x - pred_x, 1);
......
1212 1212

  
1213 1213
            for(i=0; i<4; i++){
1214 1214
                /* motion vectors: 8x8 mode*/
1215
                h263_pred_motion(s, i, &pred_x, &pred_y);
1215
                h263_pred_motion(s, i, 0, &pred_x, &pred_y);
1216 1216

  
1217 1217
                motion_x= s->current_picture.motion_val[0][ s->block_index[i] ][0];
1218 1218
                motion_y= s->current_picture.motion_val[0][ s->block_index[i] ][1];
......
1435 1435

  
1436 1436
    /* find prediction */
1437 1437
    if (n < 4) {
1438
        x = 2 * s->mb_x + 1 + (n & 1);
1439
        y = 2 * s->mb_y + 1 + ((n & 2) >> 1);
1440
        wrap = s->mb_width * 2 + 2;
1438
        x = 2 * s->mb_x + (n & 1);
1439
        y = 2 * s->mb_y + ((n & 2) >> 1);
1440
        wrap = s->b8_stride;
1441 1441
        dc_val = s->dc_val[0];
1442 1442
        ac_val = s->ac_val[0][0];
1443 1443
        scale = s->y_dc_scale;
1444 1444
    } else {
1445
        x = s->mb_x + 1;
1446
        y = s->mb_y + 1;
1447
        wrap = s->mb_width + 2;
1445
        x = s->mb_x;
1446
        y = s->mb_y;
1447
        wrap = s->mb_stride;
1448 1448
        dc_val = s->dc_val[n - 4 + 1];
1449 1449
        ac_val = s->ac_val[n - 4 + 1][0];
1450 1450
        scale = s->c_dc_scale;
......
1482 1482

  
1483 1483
    /* find prediction */
1484 1484
    if (n < 4) {
1485
        x = 2 * s->mb_x + 1 + (n & 1);
1486
        y = 2 * s->mb_y + 1 + (n>> 1);
1487
        wrap = s->mb_width * 2 + 2;
1485
        x = 2 * s->mb_x + (n & 1);
1486
        y = 2 * s->mb_y + (n>> 1);
1487
        wrap = s->b8_stride;
1488 1488
        dc_val = s->dc_val[0];
1489 1489
        ac_val = s->ac_val[0][0];
1490 1490
        scale = s->y_dc_scale;
1491 1491
    } else {
1492
        x = s->mb_x + 1;
1493
        y = s->mb_y + 1;
1494
        wrap = s->mb_width + 2;
1492
        x = s->mb_x;
1493
        y = s->mb_y;
1494
        wrap = s->mb_stride;
1495 1495
        dc_val = s->dc_val[n - 4 + 1];
1496 1496
        ac_val = s->ac_val[n - 4 + 1][0];
1497 1497
        scale = s->c_dc_scale;
......
1562 1562
        ac_val1[8 + i] = block[s->dsp.idct_permutation[i   ]];
1563 1563
}
1564 1564

  
1565
int16_t *h263_pred_motion(MpegEncContext * s, int block, 
1565
int16_t *h263_pred_motion(MpegEncContext * s, int block, int dir,
1566 1566
                        int *px, int *py)
1567 1567
{
1568
    int xy, wrap;
1569
    int16_t *A, *B, *C, *mot_val;
1570
    static const int off[4]= {2, 1, 1, -1};
1571

  
1572
    wrap = s->block_wrap[0];
1573
    xy = s->block_index[block];
1574

  
1575
    mot_val = s->current_picture.motion_val[0][xy];
1576

  
1577
    A = s->current_picture.motion_val[0][xy - 1];
1578
    /* special case for first (slice) line */
1579
    if (s->first_slice_line && block<3) {
1580
        // we cant just change some MVs to simulate that as we need them for the B frames (and ME)
1581
        // and if we ever support non rectangular objects than we need to do a few ifs here anyway :(
1582
        if(block==0){ //most common case
1583
            if(s->mb_x  == s->resync_mb_x){ //rare
1584
                *px= *py = 0;
1585
            }else if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare
1586
                C = s->current_picture.motion_val[0][xy + off[block] - wrap];
1587
                if(s->mb_x==0){
1588
                    *px = C[0];
1589
                    *py = C[1];
1590
                }else{
1591
                    *px = mid_pred(A[0], 0, C[0]);
1592
                    *py = mid_pred(A[1], 0, C[1]);
1593
                }
1594
            }else{
1595
                *px = A[0];
1596
                *py = A[1];
1597
            }
1598
        }else if(block==1){
1599
            if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare
1600
                C = s->current_picture.motion_val[0][xy + off[block] - wrap];
1601
                *px = mid_pred(A[0], 0, C[0]);
1602
                *py = mid_pred(A[1], 0, C[1]);
1603
            }else{
1604
                *px = A[0];
1605
                *py = A[1];
1606
            }
1607
        }else{ /* block==2*/
1608
            B = s->current_picture.motion_val[0][xy - wrap];
1609
            C = s->current_picture.motion_val[0][xy + off[block] - wrap];
1610
            if(s->mb_x == s->resync_mb_x) //rare
1611
                A[0]=A[1]=0;
1612
    
1613
            *px = mid_pred(A[0], B[0], C[0]);
1614
            *py = mid_pred(A[1], B[1], C[1]);
1615
        }
1616
    } else {
1617
        B = s->current_picture.motion_val[0][xy - wrap];
1618
        C = s->current_picture.motion_val[0][xy + off[block] - wrap];
1619
        *px = mid_pred(A[0], B[0], C[0]);
1620
        *py = mid_pred(A[1], B[1], C[1]);
1621
    }
1622
    return mot_val;
1623
}
1624

  
1625
// identical to above but with s->current_picture->motion_val, the above one will be removed, and this renamed to it
1626
int16_t *h263_pred_motion2(MpegEncContext * s, int block, int dir,
1627
                        int *px, int *py)
1628
{
1629
    int xy, wrap;
1568
    int wrap;
1630 1569
    int16_t *A, *B, *C, (*mot_val)[2];
1631 1570
    static const int off[4]= {2, 1, 1, -1};
1632 1571

  
1633 1572
    wrap = s->b8_stride;
1634
    xy = 2*(s->mb_x + s->mb_y * wrap);
1635

  
1636
    mot_val = s->current_picture.motion_val[dir] + xy;
1573
    mot_val = s->current_picture.motion_val[dir] + s->block_index[block];
1637 1574

  
1638 1575
    A = mot_val[ - 1];
1639 1576
    /* special case for first (slice) line */
......
3198 3135
{
3199 3136
    int c_wrap, c_xy, l_wrap, l_xy;
3200 3137

  
3201
    l_wrap= s->block_wrap[0];
3202
    l_xy= s->mb_y*l_wrap*2 + s->mb_x*2;
3203
    c_wrap= s->block_wrap[4];
3204
    c_xy= s->mb_y*c_wrap + s->mb_x;
3138
    l_wrap= s->b8_stride;
3139
    l_xy= (2*s->mb_y-1)*l_wrap + s->mb_x*2 - 1;
3140
    c_wrap= s->mb_stride;
3141
    c_xy= (s->mb_y-1)*c_wrap + s->mb_x - 1;
3205 3142

  
3206 3143
#if 0
3207 3144
    /* clean DC */
......
3374 3311
            }else{ /* P/S_TYPE */
3375 3312
                int mx, my, pred_x, pred_y, bits;
3376 3313
                int16_t * const mot_val= s->current_picture.motion_val[0][s->block_index[0]];
3377
                const int stride= s->block_wrap[0]*2;
3314
                const int stride= s->b8_stride*2;
3378 3315

  
3379 3316
try_again:
3380 3317
                bits= show_bits(&s->gb, 17);
......
3432 3369
                    if ((cbpc & 16) == 0) {
3433 3370
                        /* 16x16 motion prediction */
3434 3371

  
3435
                        h263_pred_motion(s, 0, &pred_x, &pred_y);
3372
                        h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
3436 3373
                        if(!s->mcsel){
3437 3374
                            mx = h263_decode_motion(s, pred_x, s->f_code);
3438 3375
                            if (mx >= 0xffff)
......
3456 3393
                        int i;
3457 3394
                        s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0;
3458 3395
                        for(i=0;i<4;i++) {
3459
                            int16_t *mot_val= h263_pred_motion(s, i, &pred_x, &pred_y);
3396
                            int16_t *mot_val= h263_pred_motion(s, i, 0, &pred_x, &pred_y);
3460 3397
                            mx = h263_decode_motion(s, pred_x, s->f_code);
3461 3398
                            if (mx >= 0xffff)
3462 3399
                                return -1;
......
3710 3647
    int cbpc, i, pred_x, pred_y, mx, my;
3711 3648
    int16_t *mot_val;
3712 3649
    const int xy= s->mb_x + 1 + s->mb_y * s->mb_stride;
3713
    const int stride= s->block_wrap[0]*2;
3650
    const int stride= s->b8_stride*2;
3714 3651
    
3715 3652
    for(i=0; i<4; i++)
3716 3653
        s->block_index[i]+= 2;
......
3750 3687
        if ((cbpc & 16) == 0) {
3751 3688
                s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; 
3752 3689
                /* 16x16 motion prediction */
3753
                mot_val= h263_pred_motion(s, 0, &pred_x, &pred_y);
3690
                mot_val= h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
3754 3691
                if (s->umvplus)
3755 3692
                   mx = h263p_decode_umotion(s, pred_x);
3756 3693
                else
......
3768 3705
        } else {
3769 3706
            s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0; 
3770 3707
            for(i=0;i<4;i++) {
3771
                mot_val = h263_pred_motion(s, i, &pred_x, &pred_y);
3708
                mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y);
3772 3709
                if (s->umvplus)
3773 3710
                  mx = h263p_decode_umotion(s, pred_x);
3774 3711
                else
......
3860 3797
            s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; 
3861 3798
            /* 16x16 motion prediction */
3862 3799
            s->mv_type = MV_TYPE_16X16;
3863
            h263_pred_motion(s, 0, &pred_x, &pred_y);
3800
            h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
3864 3801
            if (s->umvplus)
3865 3802
               mx = h263p_decode_umotion(s, pred_x);
3866 3803
            else
......
3885 3822
            s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0; 
3886 3823
            s->mv_type = MV_TYPE_8X8;
3887 3824
            for(i=0;i<4;i++) {
3888
                mot_val = h263_pred_motion(s, i, &pred_x, &pred_y);
3825
                mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y);
3889 3826
                if (s->umvplus)
3890 3827
                  mx = h263p_decode_umotion(s, pred_x);
3891 3828
                else
......
3979 3916
//FIXME UMV
3980 3917

  
3981 3918
            if(USES_LIST(mb_type, 0)){
3982
                int16_t *mot_val= h263_pred_motion2(s, 0, 0, &mx, &my);
3919
                int16_t *mot_val= h263_pred_motion(s, 0, 0, &mx, &my);
3983 3920
                s->mv_dir = MV_DIR_FORWARD;
3984 3921

  
3985 3922
                mx = h263_decode_motion(s, mx, 1);
......
3992 3929
            }
3993 3930
    
3994 3931
            if(USES_LIST(mb_type, 1)){
3995
                int16_t *mot_val= h263_pred_motion2(s, 0, 1, &mx, &my);
3932
                int16_t *mot_val= h263_pred_motion(s, 0, 1, &mx, &my);
3996 3933
                s->mv_dir |= MV_DIR_BACKWARD;
3997 3934
                
3998 3935
                mx = h263_decode_motion(s, mx, 1);
......
4147 4084
                s->field_select[0][0]= get_bits1(&s->gb);
4148 4085
                s->field_select[0][1]= get_bits1(&s->gb);
4149 4086

  
4150
                h263_pred_motion(s, 0, &pred_x, &pred_y);
4087
                h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
4151 4088
                
4152 4089
                for(i=0; i<2; i++){
4153 4090
                    mx = h263_decode_motion(s, pred_x, s->f_code);
......
4165 4102
                s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; 
4166 4103
                /* 16x16 motion prediction */
4167 4104
                s->mv_type = MV_TYPE_16X16;
4168
                h263_pred_motion(s, 0, &pred_x, &pred_y);
4105
                h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
4169 4106
                mx = h263_decode_motion(s, pred_x, s->f_code);
4170 4107
            
4171 4108
                if (mx >= 0xffff)
......
4182 4119
            s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0; 
4183 4120
            s->mv_type = MV_TYPE_8X8;
4184 4121
            for(i=0;i<4;i++) {
4185
                mot_val = h263_pred_motion(s, i, &pred_x, &pred_y);
4122
                mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y);
4186 4123
                mx = h263_decode_motion(s, pred_x, s->f_code);
4187 4124
                if (mx >= 0xffff)
4188 4125
                    return -1;
libavcodec/motion_est.c
733 733
        s->current_picture.motion_val[0][mot_xy+1][0]= mx;
734 734
        s->current_picture.motion_val[0][mot_xy+1][1]= my;
735 735

  
736
        mot_xy += s->block_wrap[0];
736
        mot_xy += s->b8_stride;
737 737
        s->current_picture.motion_val[0][mot_xy  ][0]= mx;
738 738
        s->current_picture.motion_val[0][mot_xy  ][1]= my;
739 739
        s->current_picture.motion_val[0][mot_xy+1][0]= mx;
......
780 780
        int pred_x4, pred_y4;
781 781
        int dmin4;
782 782
        static const int off[4]= {2, 1, 1, -1};
783
        const int mot_stride = s->block_wrap[0];
783
        const int mot_stride = s->b8_stride;
784 784
        const int mot_xy = s->block_index[block];
785 785
        const int block_x= (block&1);
786 786
        const int block_y= (block>>1);
......
1102 1102
    case ME_X1:
1103 1103
    case ME_EPZS:
1104 1104
       {
1105
            const int mot_stride = s->block_wrap[0];
1105
            const int mot_stride = s->b8_stride;
1106 1106
            const int mot_xy = s->block_index[0];
1107 1107

  
1108 1108
            P_LEFT[0]       = s->current_picture.motion_val[0][mot_xy - 1][0];
......
1252 1252
                int mean;
1253 1253
                
1254 1254
                if(s->out_format == FMT_H263){
1255
                    mean= (s->dc_val[i][mb_x + (mb_y+1)*(s->mb_width+2)] + 4)>>3; //FIXME not exact but simple ;)
1255
                    mean= (s->dc_val[i][mb_x + mb_y*s->b8_stride] + 4)>>3; //FIXME not exact but simple ;)
1256 1256
                }else{
1257 1257
                    mean= (s->last_dc[i] + 4)>>3;
1258 1258
                }
......
1809 1809
    
1810 1810
//printf("%d no:%d %d//\n", clip, noclip, f_code);
1811 1811
    if(s->flags&CODEC_FLAG_4MV){
1812
        const int wrap= 2+ s->mb_width*2;
1812
        const int wrap= s->b8_stride;
1813 1813

  
1814 1814
        /* clip / convert to intra 8x8 type MVs */
1815 1815
        for(y=0; y<s->mb_height; y++){
1816
            int xy= (y*2 + 1)*wrap + 1;
1816
            int xy= y*2*wrap;
1817 1817
            int i= y*s->mb_stride;
1818 1818
            int x;
1819 1819

  
libavcodec/mpeg12.c
2324 2324
            return -1;
2325 2325

  
2326 2326
        if(s->current_picture.motion_val[0] && !s->encoding){ //note motion_val is normally NULL unless we want to extract the MVs
2327
            const int wrap = field_pic ? 2*s->block_wrap[0] : s->block_wrap[0];
2328
            int xy = s->mb_x*2 + 1 + (s->mb_y*2 +1)*wrap;
2327
            const int wrap = field_pic ? 2*s->b8_stride : s->b8_stride;
2328
            int xy = s->mb_x*2 + s->mb_y*2*wrap;
2329 2329
            int motion_x, motion_y, dir, i;
2330 2330
            if(field_pic && !s->first_field)
2331 2331
                xy += wrap/2;
libavcodec/mpegvideo.c
275 275
    dst->type= FF_BUFFER_TYPE_COPY;
276 276
}
277 277

  
278
static void copy_picture_attributes(AVFrame *dst, AVFrame *src){
278
static void copy_picture_attributes(MpegEncContext *s, AVFrame *dst, AVFrame *src){
279
    int i;
280

  
279 281
    dst->pict_type              = src->pict_type;
280 282
    dst->quality                = src->quality;
281 283
    dst->coded_picture_number   = src->coded_picture_number;
......
284 286
    dst->pts                    = src->pts;
285 287
    dst->interlaced_frame       = src->interlaced_frame;
286 288
    dst->top_field_first        = src->top_field_first;
289

  
290
    if(src->motion_val[0] && src->motion_val[0] != dst->motion_val[0]){
291
        if(src->motion_subsample_log2 != dst->motion_subsample_log2)
292
            av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_subsample_log2 doesnt match!\n");
293
        else{
294
            int stride= ((16*s->mb_width )>>src->motion_subsample_log2) + 1;
295
            int height= ((16*s->mb_height)>>src->motion_subsample_log2);
296

  
297
            for(i=0; i<2; i++)
298
                memcpy(dst->motion_val[i], src->motion_val[i], stride*height*sizeof(int16_t));
299
        }
300
    }
287 301
}
288 302

  
289 303
/**
......
347 361
            pic->motion_subsample_log2= 2;
348 362
        }else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&FF_DEBUG_MV) || (s->avctx->debug_mv)){
349 363
            for(i=0; i<2; i++){
350
                CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b8_array_size+2) * sizeof(int16_t)*2) //FIXME
364
                CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b8_array_size+2) * sizeof(int16_t))
351 365
                pic->motion_val[i]= pic->motion_val_base[i]+2;
352 366
            }
353 367
            pic->motion_subsample_log2= 3;
......
591 605
    s->block_wrap[0]=
592 606
    s->block_wrap[1]=
593 607
    s->block_wrap[2]=
594
    s->block_wrap[3]= s->mb_width*2 + 2;
608
    s->block_wrap[3]= s->b8_stride;
595 609
    s->block_wrap[4]=
596
    s->block_wrap[5]= s->mb_width + 2;
610
    s->block_wrap[5]= s->mb_stride;
597 611
 
598
    y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2);
599
    c_size = (s->mb_width + 2) * (s->mb_height + 2);
612
    y_size = s->b8_stride * (2 * s->mb_height + 1);
613
    c_size = s->mb_stride * (s->mb_height + 1);
600 614
    yc_size = y_size + 2 * c_size;
601 615
    
602 616
    /* convert fourcc to upper case */
......
678 692
    }
679 693
    if (s->out_format == FMT_H263) {
680 694
        /* ac values */
681
        CHECKED_ALLOCZ(s->ac_val[0], yc_size * sizeof(int16_t) * 16);
682
        s->ac_val[1] = s->ac_val[0] + y_size;
695
        CHECKED_ALLOCZ(s->ac_val_base, yc_size * sizeof(int16_t) * 16);
696
        s->ac_val[0] = s->ac_val_base + s->b8_stride + 1;
697
        s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1;
683 698
        s->ac_val[2] = s->ac_val[1] + c_size;
684 699
        
685 700
        /* cbp values */
686
        CHECKED_ALLOCZ(s->coded_block, y_size);
701
        CHECKED_ALLOCZ(s->coded_block_base, y_size);
702
        s->coded_block= s->coded_block_base + s->b8_stride + 1;
687 703
        
688 704
        /* divx501 bitstream reorder buffer */
689 705
        CHECKED_ALLOCZ(s->bitstream_buffer, BITSTREAM_BUFFER_SIZE);
......
696 712
    if (s->h263_pred || s->h263_plus || !s->encoding) {
697 713
        /* dc values */
698 714
        //MN: we need these for error resilience of intra-frames
699
        CHECKED_ALLOCZ(s->dc_val[0], yc_size * sizeof(int16_t));
700
        s->dc_val[1] = s->dc_val[0] + y_size;
715
        CHECKED_ALLOCZ(s->dc_val_base, yc_size * sizeof(int16_t));
716
        s->dc_val[0] = s->dc_val_base + s->b8_stride + 1;
717
        s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1;
701 718
        s->dc_val[2] = s->dc_val[1] + c_size;
702 719
        for(i=0;i<yc_size;i++)
703
            s->dc_val[0][i] = 1024;
720
            s->dc_val_base[i] = 1024;
704 721
    }
705 722

  
706 723
    /* which mb is a intra block */
......
781 798
        av_freep(&s->p_field_select_table[i]);
782 799
    }
783 800
    
784
    av_freep(&s->dc_val[0]);
785
    av_freep(&s->ac_val[0]);
786
    av_freep(&s->coded_block);
801
    av_freep(&s->dc_val_base);
802
    av_freep(&s->ac_val_base);
803
    av_freep(&s->coded_block_base);
787 804
    av_freep(&s->mbintra_table);
788 805
    av_freep(&s->cbp_table);
789 806
    av_freep(&s->pred_dir_table);
......
1684 1701
                    if(!USES_LIST(pict->mb_type[mb_index], direction))
1685 1702
                        continue;
1686 1703

  
1704
                    //FIXME for h264
1687 1705
                    if(IS_8X8(pict->mb_type[mb_index])){
1688 1706
                      int i;
1689 1707
                      for(i=0; i<4; i++){
1690 1708
                        int sx= mb_x*16 + 4 + 8*(i&1);
1691 1709
                        int sy= mb_y*16 + 4 + 8*(i>>1);
1692
                        int xy= 1 + mb_x*2 + (i&1) + (mb_y*2 + 1 + (i>>1))*(s->mb_width*2 + 2);
1710
                        int xy= mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*s->b8_stride;
1693 1711
                        int mx= (pict->motion_val[direction][xy][0]>>shift) + sx;
1694 1712
                        int my= (pict->motion_val[direction][xy][1]>>shift) + sy;
1695 1713
                        draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100);
......
1699 1717
                      for(i=0; i<2; i++){
1700 1718
                        int sx=mb_x*16 + 8;
1701 1719
                        int sy=mb_y*16 + 4 + 8*i;
1702
                        int xy=1 + mb_x*2 + (mb_y*2 + 1 + i)*(s->mb_width*2 + 2);
1720
                        int xy= mb_x*2 + (mb_y*2 + i)*s->b8_stride;
1703 1721
                        int mx=(pict->motion_val[direction][xy][0]>>shift) + sx;
1704 1722
                        int my=(pict->motion_val[direction][xy][1]>>shift) + sy;
1705 1723
                        draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100);
......
1707 1725
                    }else{
1708 1726
                      int sx= mb_x*16 + 8;
1709 1727
                      int sy= mb_y*16 + 8;
1710
                      int xy= 1 + mb_x*2 + (mb_y*2 + 1)*(s->mb_width*2 + 2);
1728
                      int xy= mb_x*2 + mb_y*2*s->b8_stride;
1711 1729
                      int mx= (pict->motion_val[direction][xy][0]>>shift) + sx;
1712 1730
                      int my= (pict->motion_val[direction][xy][1]>>shift) + sy;
1713 1731
                      draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100);
......
1884 1902
            }
1885 1903
        }
1886 1904
    }
1887
    copy_picture_attributes(pic, pic_arg);
1905
    copy_picture_attributes(s, pic, pic_arg);
1888 1906
    
1889 1907
    pic->display_picture_number= s->input_picture_number++;
1890 1908
    if(pic->pts != AV_NOPTS_VALUE){ 
......
2013 2031
                s->reordered_input_picture[0]->data[i]= NULL;
2014 2032
            s->reordered_input_picture[0]->type= 0;
2015 2033
            
2016
            copy_picture_attributes((AVFrame*)pic, (AVFrame*)s->reordered_input_picture[0]);
2034
            copy_picture_attributes(s, (AVFrame*)pic, (AVFrame*)s->reordered_input_picture[0]);
2017 2035
            pic->reference              = s->reordered_input_picture[0]->reference;
2018 2036
            
2019 2037
            alloc_picture(s, pic, 0);
......
2746 2764
    if(s->obmc && s->pict_type != B_TYPE){
2747 2765
        int16_t mv_cache[4][4][2];
2748 2766
        const int xy= s->mb_x + s->mb_y*s->mb_stride;
2749
        const int mot_stride= s->mb_width*2 + 2;
2750
        const int mot_xy= 1 + mb_x*2 + (mb_y*2 + 1)*mot_stride;
2767
        const int mot_stride= s->b8_stride;
2768
        const int mot_xy= mb_x*2 + mb_y*2*mot_stride;
2751 2769

  
2752 2770
        assert(!s->mb_skiped);
2753 2771
                
......
3003 3021
 */
3004 3022
void ff_clean_intra_table_entries(MpegEncContext *s)
3005 3023
{
3006
    int wrap = s->block_wrap[0];
3024
    int wrap = s->b8_stride;
3007 3025
    int xy = s->block_index[0];
3008 3026
    
3009 3027
    s->dc_val[0][xy           ] = 
......
3020 3038
        s->coded_block[xy + 1 + wrap] = 0;
3021 3039
    }
3022 3040
    /* chroma */
3023
    wrap = s->block_wrap[4];
3024
    xy = s->mb_x + 1 + (s->mb_y + 1) * wrap;
3041
    wrap = s->mb_stride;
3042
    xy = s->mb_x + s->mb_y * wrap;
3025 3043
    s->dc_val[1][xy] =
3026 3044
    s->dc_val[2][xy] = 1024;
3027 3045
    /* ac pred */
3028 3046
    memset(s->ac_val[1][xy], 0, 16 * sizeof(int16_t));
3029 3047
    memset(s->ac_val[2][xy], 0, 16 * sizeof(int16_t));
3030 3048
    
3031
    s->mbintra_table[s->mb_x + s->mb_y*s->mb_stride]= 0;
3049
    s->mbintra_table[xy]= 0;
3032 3050
}
3033 3051

  
3034 3052
/* generic function called after a macroblock has been parsed by the
......
3348 3366
    const int linesize= s->current_picture.linesize[0]; //not s->linesize as this woulnd be wrong for field pics
3349 3367
    const int uvlinesize= s->current_picture.linesize[1];
3350 3368
        
3351
    s->block_index[0]= s->block_wrap[0]*(s->mb_y*2 + 1) - 1 + s->mb_x*2;
3352
    s->block_index[1]= s->block_wrap[0]*(s->mb_y*2 + 1)     + s->mb_x*2;
3353
    s->block_index[2]= s->block_wrap[0]*(s->mb_y*2 + 2) - 1 + s->mb_x*2;
3354
    s->block_index[3]= s->block_wrap[0]*(s->mb_y*2 + 2)     + s->mb_x*2;
3355
    s->block_index[4]= s->block_wrap[4]*(s->mb_y + 1)                    + s->block_wrap[0]*(s->mb_height*2 + 2) + s->mb_x;
3356
    s->block_index[5]= s->block_wrap[4]*(s->mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2) + s->mb_x;
3369
    s->block_index[0]= s->b8_stride*(s->mb_y*2    ) - 2 + s->mb_x*2;
3370
    s->block_index[1]= s->b8_stride*(s->mb_y*2    ) - 1 + s->mb_x*2;
3371
    s->block_index[2]= s->b8_stride*(s->mb_y*2 + 1) - 2 + s->mb_x*2;
3372
    s->block_index[3]= s->b8_stride*(s->mb_y*2 + 1) - 1 + s->mb_x*2;
3373
    s->block_index[4]= s->mb_stride*(s->mb_y + 1)                + s->b8_stride*s->mb_height*2 + s->mb_x - 1;
3374
    s->block_index[5]= s->mb_stride*(s->mb_y + s->mb_height + 2) + s->b8_stride*s->mb_height*2 + s->mb_x - 1;
3357 3375
    
3358 3376
    if(s->pict_type==B_TYPE && s->avctx->draw_horiz_band && s->picture_structure==PICT_FRAME){
3359 3377
        s->dest[0] = s->current_picture.data[0] + s->mb_x * 16 - 16;
libavcodec/mpegvideo.h
321 321
    Picture *current_picture_ptr;  ///< pointer to the current picture
322 322
    uint8_t *visualization_buffer[3]; //< temporary buffer vor MV visualization
323 323
    int last_dc[3];                ///< last DC values for MPEG1 
324
    int16_t *dc_val_base;
324 325
    int16_t *dc_val[3];            ///< used for mpeg4 DC prediction, all 3 arrays must be continuous 
325 326
    int16_t dc_cache[4*5];
326 327
    int y_dc_scale, c_dc_scale;
327 328
    uint8_t *y_dc_scale_table;     ///< qscale -> y_dc_scale table 
328 329
    uint8_t *c_dc_scale_table;     ///< qscale -> c_dc_scale table 
329 330
    const uint8_t *chroma_qscale_table;  ///< qscale -> chroma_qscale (h263)
331
    uint8_t *coded_block_base;
330 332
    uint8_t *coded_block;          ///< used for coded block pattern prediction (msmpeg4v3, wmv1)
333
    int16_t (*ac_val_base)[16];
331 334
    int16_t (*ac_val[3])[16];      ///< used for for mpeg4 AC prediction, all 3 arrays must be continuous 
332 335
    int ac_pred;
333 336
    uint8_t *prev_pict_types;     ///< previous picture types in bitstream order, used for mb skip 
......
857 860
void h263_encode_picture_header(MpegEncContext *s, int picture_number);
858 861
void ff_flv_encode_picture_header(MpegEncContext *s, int picture_number);
859 862
void h263_encode_gob_header(MpegEncContext * s, int mb_line);
860
int16_t *h263_pred_motion(MpegEncContext * s, int block, 
863
int16_t *h263_pred_motion(MpegEncContext * s, int block, int dir,
861 864
                        int *px, int *py);
862 865
void mpeg4_pred_ac(MpegEncContext * s, DCTELEM *block, int n, 
863 866
                   int dir);
libavcodec/msmpeg4.c
449 449
    int xy, wrap, pred, a, b, c;
450 450

  
451 451
    xy = s->block_index[n];
452
    wrap = s->block_wrap[0];
452
    wrap = s->b8_stride;
453 453

  
454 454
    /* B C
455 455
     * A X 
......
567 567

  
568 568
            s->misc_bits += get_bits_diff(s);
569 569

  
570
            h263_pred_motion(s, 0, &pred_x, &pred_y);
570
            h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
571 571
            msmpeg4v2_encode_motion(s, motion_x - pred_x);
572 572
            msmpeg4v2_encode_motion(s, motion_y - pred_y);
573 573
        }else{
......
578 578
            s->misc_bits += get_bits_diff(s);
579 579

  
580 580
            /* motion vector */
581
            h263_pred_motion(s, 0, &pred_x, &pred_y);
581
            h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
582 582
            msmpeg4_encode_motion(s, motion_x - pred_x, 
583 583
                                  motion_y - pred_y);
584 584
        }
......
1549 1549
        cbp|= cbpy<<2;
1550 1550
        if(s->msmpeg4_version==1 || (cbp&3) != 3) cbp^= 0x3C;
1551 1551
        
1552
        h263_pred_motion(s, 0, &mx, &my);
1552
        h263_pred_motion(s, 0, 0, &mx, &my);
1553 1553
        mx= msmpeg4v2_decode_motion(s, mx, 1);
1554 1554
        my= msmpeg4v2_decode_motion(s, my, 1);
1555 1555
        
......
1637 1637
            s->rl_chroma_table_index = s->rl_table_index;
1638 1638
        }
1639 1639
        set_stat(ST_MV);
1640
        h263_pred_motion(s, 0, &mx, &my);
1640
        h263_pred_motion(s, 0, 0, &mx, &my);
1641 1641
        if (msmpeg4_decode_motion(s, &mx, &my) < 0)
1642 1642
            return -1;
1643 1643
        s->mv_dir = MV_DIR_FORWARD;
libavcodec/rv10.c
564 564
            return -1;
565 565
    }
566 566

  
567
    if(s->pict_type == B_TYPE){ //FIXME remove after cleaning mottion_val indexing
568
        memset(s->current_picture.motion_val[0], 0, sizeof(int16_t)*2*(s->mb_width*2+2)*(s->mb_height*2+2));
569
    }
570

  
571 567
#ifdef DEBUG
572 568
    printf("qscale=%d\n", s->qscale);
573 569
#endif
......
600 596
    s->block_wrap[0]=
601 597
    s->block_wrap[1]=
602 598
    s->block_wrap[2]=
603
    s->block_wrap[3]= s->mb_width*2 + 2;
599
    s->block_wrap[3]= s->b8_stride;
604 600
    s->block_wrap[4]=
605
    s->block_wrap[5]= s->mb_width + 2;
601
    s->block_wrap[5]= s->mb_stride;
606 602
    ff_init_block_index(s);
607 603
    /* decode each macroblock */
608 604

  
......
677 673
            return -1;
678 674
    }
679 675
    
680
    if(s->pict_type == B_TYPE){ //FIXME remove after cleaning mottion_val indexing
681
        memset(s->current_picture.motion_val[0], 0, sizeof(int16_t)*2*(s->mb_width*2+2)*(s->mb_height*2+2));
682
    }
683

  
684 676
    if(s->mb_y>=s->mb_height){
685 677
        MPV_frame_end(s);
686 678
    
libavcodec/wmv2.c
216 216
                 wmv2_inter_table[w->cbp_table_index][cbp + 64][0]);
217 217

  
218 218
        /* motion vector */
219
        h263_pred_motion(s, 0, &pred_x, &pred_y);
219
        h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
220 220
        msmpeg4_encode_motion(s, motion_x - pred_x, 
221 221
                              motion_y - pred_y);
222 222
    } else {
......
504 504
    int xy, wrap, diff, type;
505 505
    int16_t *A, *B, *C, *mot_val;
506 506

  
507
    wrap = s->block_wrap[0];
507
    wrap = s->b8_stride;
508 508
    xy = s->block_index[0];
509 509

  
510 510
    mot_val = s->current_picture.motion_val[0][xy];

Also available in: Unified diff