Revision 137c8468 libavcodec/h263.c

View differences:

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;

Also available in: Unified diff