Commit 83a8085a authored by kostya's avatar kostya

Calculate motion vector information based on PTS provided in slice header

git-svn-id: file:///var/local/repositories/ffmpeg/trunk@13011 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 53162621
...@@ -47,7 +47,7 @@ static int rv30_parse_slice_header(RV34DecContext *r, GetBitContext *gb, SliceIn ...@@ -47,7 +47,7 @@ static int rv30_parse_slice_header(RV34DecContext *r, GetBitContext *gb, SliceIn
return -1; return -1;
si->quant = get_bits(gb, 5); si->quant = get_bits(gb, 5);
skip_bits1(gb); skip_bits1(gb);
skip_bits(gb, 13); // timestamp si->pts = get_bits(gb, 13);
skip_bits(gb, r->rpr); skip_bits(gb, r->rpr);
si->width = w; si->width = w;
si->height = h; si->height = h;
......
...@@ -466,19 +466,21 @@ static void rv34_pred_mv(RV34DecContext *r, int block_type, int subblock_no, int ...@@ -466,19 +466,21 @@ static void rv34_pred_mv(RV34DecContext *r, int block_type, int subblock_no, int
} }
} }
#define GET_PTS_DIFF(a, b) ((a - b + 8192) & 0x1FFF)
/** /**
* Calculate motion vector component that should be added for direct blocks. * Calculate motion vector component that should be added for direct blocks.
*/ */
static int calc_add_mv(MpegEncContext *s, int dir, int component) static int calc_add_mv(RV34DecContext *r, int dir, int val)
{ {
int mv_pos = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride; int refdist = GET_PTS_DIFF(r->next_pts, r->last_pts);
int sum; int dist = dir ? GET_PTS_DIFF(r->next_pts, r->cur_pts) : GET_PTS_DIFF(r->cur_pts, r->last_pts);
sum = (s->next_picture_ptr->motion_val[0][mv_pos][component] + if(!refdist) return 0;
s->next_picture_ptr->motion_val[0][mv_pos + 1][component] + if(!dir)
s->next_picture_ptr->motion_val[0][mv_pos + s->b8_stride][component] + return (val * dist + refdist - 1) / refdist;
s->next_picture_ptr->motion_val[0][mv_pos + s->b8_stride + 1][component]) >> 2; else
return dir ? -(sum >> 1) : ((sum + 1) >> 1); return -(val * dist / refdist);
} }
/** /**
...@@ -545,10 +547,6 @@ static void rv34_pred_mv_b(RV34DecContext *r, int block_type, int dir) ...@@ -545,10 +547,6 @@ static void rv34_pred_mv_b(RV34DecContext *r, int block_type, int dir)
mx += r->dmv[dir][0]; mx += r->dmv[dir][0];
my += r->dmv[dir][1]; my += r->dmv[dir][1];
if(block_type == RV34_MB_B_DIRECT){
mx += calc_add_mv(s, dir, 0);
my += calc_add_mv(s, dir, 1);
}
for(j = 0; j < 2; j++){ for(j = 0; j < 2; j++){
for(i = 0; i < 2; i++){ for(i = 0; i < 2; i++){
cur_pic->motion_val[dir][mv_pos + i + j*s->b8_stride][0] = mx; cur_pic->motion_val[dir][mv_pos + i + j*s->b8_stride][0] = mx;
...@@ -694,7 +692,7 @@ static int rv34_decode_mv(RV34DecContext *r, int block_type) ...@@ -694,7 +692,7 @@ static int rv34_decode_mv(RV34DecContext *r, int block_type)
{ {
MpegEncContext *s = &r->s; MpegEncContext *s = &r->s;
GetBitContext *gb = &s->gb; GetBitContext *gb = &s->gb;
int i, j, k; int i, j, k, l;
int mv_pos = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride; int mv_pos = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride;
int next_bt; int next_bt;
...@@ -719,10 +717,9 @@ static int rv34_decode_mv(RV34DecContext *r, int block_type) ...@@ -719,10 +717,9 @@ static int rv34_decode_mv(RV34DecContext *r, int block_type)
next_bt = s->next_picture_ptr->mb_type[s->mb_x + s->mb_y * s->mb_stride]; next_bt = s->next_picture_ptr->mb_type[s->mb_x + s->mb_y * s->mb_stride];
for(j = 0; j < 2; j++) for(j = 0; j < 2; j++)
for(i = 0; i < 2; i++) for(i = 0; i < 2; i++)
for(k = 0; k < 2; k++){ for(k = 0; k < 2; k++)
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; for(l = 0; l < 2; l++)
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); 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]);
}
if(IS_16X16(next_bt)) //we can use whole macroblock MC if(IS_16X16(next_bt)) //we can use whole macroblock MC
rv34_mc_2mv(r, block_type); rv34_mc_2mv(r, block_type);
else else
...@@ -1104,7 +1101,8 @@ static inline int slice_compare(SliceInfo *si1, SliceInfo *si2) ...@@ -1104,7 +1101,8 @@ static inline int slice_compare(SliceInfo *si1, SliceInfo *si2)
return si1->type != si2->type || return si1->type != si2->type ||
si1->start >= si2->start || si1->start >= si2->start ||
si1->width != si2->width || si1->width != si2->width ||
si1->height != si2->height; si1->height != si2->height||
si1->pts != si2->pts;
} }
static int rv34_decode_slice(RV34DecContext *r, int end, uint8_t* buf, int buf_size) static int rv34_decode_slice(RV34DecContext *r, int end, uint8_t* buf, int buf_size)
...@@ -1140,6 +1138,11 @@ static int rv34_decode_slice(RV34DecContext *r, int end, uint8_t* buf, int buf_s ...@@ -1140,6 +1138,11 @@ static int rv34_decode_slice(RV34DecContext *r, int end, uint8_t* buf, int buf_s
return -1; return -1;
ff_er_frame_start(s); ff_er_frame_start(s);
s->current_picture_ptr = &s->current_picture; s->current_picture_ptr = &s->current_picture;
r->cur_pts = r->si.pts;
if(s->pict_type != FF_B_TYPE){
r->last_pts = r->next_pts;
r->next_pts = r->cur_pts;
}
s->mb_x = s->mb_y = 0; s->mb_x = s->mb_y = 0;
} }
......
...@@ -74,6 +74,7 @@ typedef struct SliceInfo{ ...@@ -74,6 +74,7 @@ typedef struct SliceInfo{
int start, end; ///< start and end macroblocks of the slice int start, end; ///< start and end macroblocks of the slice
int width; ///< coded width int width; ///< coded width
int height; ///< coded height int height; ///< coded height
int pts; ///< frame timestamp
}SliceInfo; }SliceInfo;
/** decoder context */ /** decoder context */
...@@ -99,6 +100,8 @@ typedef struct RV34DecContext{ ...@@ -99,6 +100,8 @@ typedef struct RV34DecContext{
int rv30; ///< indicates which RV variasnt is currently decoded int rv30; ///< indicates which RV variasnt is currently decoded
int rpr; ///< one field size in RV30 slice header int rpr; ///< one field size in RV30 slice header
int cur_pts, last_pts, next_pts;
uint16_t *cbp_luma; ///< CBP values for luma subblocks uint16_t *cbp_luma; ///< CBP values for luma subblocks
uint8_t *cbp_chroma; ///< CBP values for chroma subblocks uint8_t *cbp_chroma; ///< CBP values for chroma subblocks
......
...@@ -103,7 +103,7 @@ static void rv40_parse_picture_size(GetBitContext *gb, int *w, int *h) ...@@ -103,7 +103,7 @@ static void rv40_parse_picture_size(GetBitContext *gb, int *w, int *h)
static int rv40_parse_slice_header(RV34DecContext *r, GetBitContext *gb, SliceInfo *si) static int rv40_parse_slice_header(RV34DecContext *r, GetBitContext *gb, SliceInfo *si)
{ {
int t, mb_bits; int mb_bits;
int w = r->s.width, h = r->s.height; int w = r->s.width, h = r->s.height;
int mb_size; int mb_size;
...@@ -117,7 +117,7 @@ static int rv40_parse_slice_header(RV34DecContext *r, GetBitContext *gb, SliceIn ...@@ -117,7 +117,7 @@ static int rv40_parse_slice_header(RV34DecContext *r, GetBitContext *gb, SliceIn
return -1; return -1;
si->vlc_set = get_bits(gb, 2); si->vlc_set = get_bits(gb, 2);
skip_bits1(gb); skip_bits1(gb);
t = get_bits(gb, 13); /// ??? si->pts = get_bits(gb, 13);
if(!si->type || !get_bits1(gb)) if(!si->type || !get_bits1(gb))
rv40_parse_picture_size(gb, &w, &h); rv40_parse_picture_size(gb, &w, &h);
if(avcodec_check_dimensions(r->s.avctx, w, h) < 0) if(avcodec_check_dimensions(r->s.avctx, w, h) < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment