Revision 39902a8c

View differences:

libavcodec/rv30.c
47 47
        return -1;
48 48
    si->quant = get_bits(gb, 5);
49 49
    skip_bits1(gb);
50
    skip_bits(gb, 13); // timestamp
50
    si->pts = get_bits(gb, 13);
51 51
    skip_bits(gb, r->rpr);
52 52
    si->width  = w;
53 53
    si->height = h;
libavcodec/rv34.c
466 466
    }
467 467
}
468 468

  
469
#define GET_PTS_DIFF(a, b) ((a - b + 8192) & 0x1FFF)
470

  
469 471
/**
470 472
 * Calculate motion vector component that should be added for direct blocks.
471 473
 */
472
static int calc_add_mv(MpegEncContext *s, int dir, int component)
474
static int calc_add_mv(RV34DecContext *r, int dir, int val)
473 475
{
474
    int mv_pos = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride;
475
    int sum;
476
    int refdist = GET_PTS_DIFF(r->next_pts, r->last_pts);
477
    int dist = dir ? GET_PTS_DIFF(r->next_pts, r->cur_pts) : GET_PTS_DIFF(r->cur_pts, r->last_pts);
476 478

  
477
    sum = (s->next_picture_ptr->motion_val[0][mv_pos][component] +
478
           s->next_picture_ptr->motion_val[0][mv_pos + 1][component] +
479
           s->next_picture_ptr->motion_val[0][mv_pos + s->b8_stride][component] +
480
           s->next_picture_ptr->motion_val[0][mv_pos + s->b8_stride + 1][component]) >> 2;
481
    return dir ? -(sum >> 1) : ((sum + 1) >> 1);
479
    if(!refdist) return 0;
480
    if(!dir)
481
        return (val * dist + refdist - 1) / refdist;
482
    else
483
        return -(val * dist / refdist);
482 484
}
483 485

  
484 486
/**
......
545 547
    mx += r->dmv[dir][0];
546 548
    my += r->dmv[dir][1];
547 549

  
548
    if(block_type == RV34_MB_B_DIRECT){
549
        mx += calc_add_mv(s, dir, 0);
550
        my += calc_add_mv(s, dir, 1);
551
    }
552 550
    for(j = 0; j < 2; j++){
553 551
        for(i = 0; i < 2; i++){
554 552
            cur_pic->motion_val[dir][mv_pos + i + j*s->b8_stride][0] = mx;
......
694 692
{
695 693
    MpegEncContext *s = &r->s;
696 694
    GetBitContext *gb = &s->gb;
697
    int i, j, k;
695
    int i, j, k, l;
698 696
    int mv_pos = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride;
699 697
    int next_bt;
700 698

  
......
719 717
        next_bt = s->next_picture_ptr->mb_type[s->mb_x + s->mb_y * s->mb_stride];
720 718
        for(j = 0; j < 2; j++)
721 719
            for(i = 0; i < 2; i++)
722
                for(k = 0; k < 2; k++){
723
                    s->current_picture_ptr->motion_val[0][mv_pos + i + j*s->b8_stride][k] =  (s->next_picture_ptr->motion_val[0][mv_pos + i + j*s->b8_stride][k] + 1) >> 1;
724
                    s->current_picture_ptr->motion_val[1][mv_pos + i + j*s->b8_stride][k] = -(s->next_picture_ptr->motion_val[0][mv_pos + i + j*s->b8_stride][k] >> 1);
725
                }
720
                for(k = 0; k < 2; k++)
721
                    for(l = 0; l < 2; l++)
722
                        s->current_picture_ptr->motion_val[l][mv_pos + i + j*s->b8_stride][k] = calc_add_mv(r, l, s->next_picture_ptr->motion_val[0][mv_pos + i + j*s->b8_stride][k]);
726 723
        if(IS_16X16(next_bt)) //we can use whole macroblock MC
727 724
            rv34_mc_2mv(r, block_type);
728 725
        else
......
1104 1101
    return si1->type   != si2->type  ||
1105 1102
           si1->start  >= si2->start ||
1106 1103
           si1->width  != si2->width ||
1107
           si1->height != si2->height;
1104
           si1->height != si2->height||
1105
           si1->pts    != si2->pts;
1108 1106
}
1109 1107

  
1110 1108
static int rv34_decode_slice(RV34DecContext *r, int end, uint8_t* buf, int buf_size)
......
1140 1138
            return -1;
1141 1139
        ff_er_frame_start(s);
1142 1140
        s->current_picture_ptr = &s->current_picture;
1141
        r->cur_pts = r->si.pts;
1142
        if(s->pict_type != FF_B_TYPE){
1143
            r->last_pts = r->next_pts;
1144
            r->next_pts = r->cur_pts;
1145
        }
1143 1146
        s->mb_x = s->mb_y = 0;
1144 1147
    }
1145 1148

  
libavcodec/rv34.h
74 74
    int start, end;        ///< start and end macroblocks of the slice
75 75
    int width;             ///< coded width
76 76
    int height;            ///< coded height
77
    int pts;               ///< frame timestamp
77 78
}SliceInfo;
78 79

  
79 80
/** decoder context */
......
99 100
    int rv30;                ///< indicates which RV variasnt is currently decoded
100 101
    int rpr;                 ///< one field size in RV30 slice header
101 102

  
103
    int cur_pts, last_pts, next_pts;
104

  
102 105
    uint16_t *cbp_luma;      ///< CBP values for luma subblocks
103 106
    uint8_t  *cbp_chroma;    ///< CBP values for chroma subblocks
104 107

  
libavcodec/rv40.c
103 103

  
104 104
static int rv40_parse_slice_header(RV34DecContext *r, GetBitContext *gb, SliceInfo *si)
105 105
{
106
    int t, mb_bits;
106
    int mb_bits;
107 107
    int w = r->s.width, h = r->s.height;
108 108
    int mb_size;
109 109

  
......
117 117
        return -1;
118 118
    si->vlc_set = get_bits(gb, 2);
119 119
    skip_bits1(gb);
120
    t = get_bits(gb, 13); /// ???
120
    si->pts = get_bits(gb, 13);
121 121
    if(!si->type || !get_bits1(gb))
122 122
        rv40_parse_picture_size(gb, &w, &h);
123 123
    if(avcodec_check_dimensions(r->s.avctx, w, h) < 0)

Also available in: Unified diff