460 |
stop_transfer_timer(); |
stop_transfer_timer(); |
461 |
} |
} |
462 |
|
|
463 |
|
static void __inline |
464 |
|
validate_vector(VECTOR * mv, unsigned int x_pos, unsigned int y_pos, const DECODER * dec) |
465 |
|
{ |
466 |
|
/* clip a vector to valid range |
467 |
|
prevents crashes if bitstream is broken |
468 |
|
*/ |
469 |
|
int shift = 5 + dec->quarterpel; |
470 |
|
int xborder_high = (int)(dec->mb_width - x_pos) << shift; |
471 |
|
int xborder_low = (-(int)x_pos-1) << shift; |
472 |
|
int yborder_high = (int)(dec->mb_height - y_pos) << shift; |
473 |
|
int yborder_low = (-(int)y_pos-1) << shift; |
474 |
|
|
475 |
|
#define CHECK_MV(mv) \ |
476 |
|
do { \ |
477 |
|
if ((mv).x > xborder_high) { \ |
478 |
|
DPRINTF(XVID_DEBUG_MV, "mv.x > max -- %d > %d, MB %d, %d", (mv).x, xborder_high, x_pos, y_pos); \ |
479 |
|
(mv).x = xborder_high; \ |
480 |
|
} else if ((mv).x < xborder_low) { \ |
481 |
|
DPRINTF(XVID_DEBUG_MV, "mv.x < min -- %d < %d, MB %d, %d", (mv).x, xborder_low, x_pos, y_pos); \ |
482 |
|
(mv).x = xborder_low; \ |
483 |
|
} \ |
484 |
|
if ((mv).y > yborder_high) { \ |
485 |
|
DPRINTF(XVID_DEBUG_MV, "mv.y > max -- %d > %d, MB %d, %d", (mv).y, yborder_high, x_pos, y_pos); \ |
486 |
|
(mv).y = yborder_high; \ |
487 |
|
} else if ((mv).y < yborder_low) { \ |
488 |
|
DPRINTF(XVID_DEBUG_MV, "mv.y < min -- %d < %d, MB %d, %d", (mv).y, yborder_low, x_pos, y_pos); \ |
489 |
|
(mv).y = yborder_low; \ |
490 |
|
} \ |
491 |
|
} while (0) |
492 |
|
|
493 |
|
CHECK_MV(mv[0]); |
494 |
|
CHECK_MV(mv[1]); |
495 |
|
CHECK_MV(mv[2]); |
496 |
|
CHECK_MV(mv[3]); |
497 |
|
} |
498 |
|
|
499 |
/* decode an inter macroblock */ |
/* decode an inter macroblock */ |
500 |
static void |
static void |
501 |
decoder_mbinter(DECODER * dec, |
decoder_mbinter(DECODER * dec, |
533 |
mv[i] = pMB->mvs[i]; |
mv[i] = pMB->mvs[i]; |
534 |
} |
} |
535 |
|
|
536 |
for (i = 0; i < 4; i++) { |
validate_vector(mv, x_pos, y_pos, dec); |
|
/* clip to valid range */ |
|
|
int border = (int)(dec->mb_width - x_pos) << (5 + dec->quarterpel); |
|
|
if (mv[i].x > border) { |
|
|
DPRINTF(XVID_DEBUG_MV, "mv.x > max -- %d > %d, MB %d, %d", mv[i].x, border, x_pos, y_pos); |
|
|
mv[i].x = border; |
|
|
} else { |
|
|
border = (-(int)x_pos-1) << (5 + dec->quarterpel); |
|
|
if (mv[i].x < border) { |
|
|
DPRINTF(XVID_DEBUG_MV, "mv.x < min -- %d < %d, MB %d, %d", mv[i].x, border, x_pos, y_pos); |
|
|
mv[i].x = border; |
|
|
} |
|
|
} |
|
|
|
|
|
border = (int)(dec->mb_height - y_pos) << (5 + dec->quarterpel); |
|
|
if (mv[i].y > border) { |
|
|
DPRINTF(XVID_DEBUG_MV, "mv.y > max -- %d > %d, MB %d, %d", mv[i].y, border, x_pos, y_pos); |
|
|
mv[i].y = border; |
|
|
} else { |
|
|
border = (-(int)y_pos-1) << (5 + dec->quarterpel); |
|
|
if (mv[i].y < border) { |
|
|
DPRINTF(XVID_DEBUG_MV, "mv.y < min -- %d < %d, MB %d, %d", mv[i].y, border, x_pos, y_pos); |
|
|
mv[i].y = border; |
|
|
} |
|
|
} |
|
|
} |
|
537 |
|
|
538 |
start_timer(); |
start_timer(); |
539 |
|
|
1020 |
decoder_bf_interpolate_mbinter(DECODER * dec, |
decoder_bf_interpolate_mbinter(DECODER * dec, |
1021 |
IMAGE forward, |
IMAGE forward, |
1022 |
IMAGE backward, |
IMAGE backward, |
1023 |
const MACROBLOCK * pMB, |
MACROBLOCK * pMB, |
1024 |
const uint32_t x_pos, |
const uint32_t x_pos, |
1025 |
const uint32_t y_pos, |
const uint32_t y_pos, |
1026 |
Bitstream * bs, |
Bitstream * bs, |
1037 |
pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); |
pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); |
1038 |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
1039 |
|
|
1040 |
|
validate_vector(pMB->mvs, x_pos, y_pos, dec); |
1041 |
|
validate_vector(pMB->b_mvs, x_pos, y_pos, dec); |
1042 |
|
|
1043 |
if (!direct) { |
if (!direct) { |
1044 |
uv_dx = pMB->mvs[0].x; |
uv_dx = pMB->mvs[0].x; |
1045 |
uv_dy = pMB->mvs[0].y; |
uv_dy = pMB->mvs[0].y; |
1407 |
} |
} |
1408 |
} |
} |
1409 |
|
|
|
|
|
1410 |
int |
int |
1411 |
decoder_decode(DECODER * dec, |
decoder_decode(DECODER * dec, |
1412 |
xvid_dec_frame_t * frame, xvid_dec_stats_t * stats) |
xvid_dec_frame_t * frame, xvid_dec_stats_t * stats) |