195 |
dec->low_delay = 0; |
dec->low_delay = 0; |
196 |
dec->packed_mode = 0; |
dec->packed_mode = 0; |
197 |
dec->time_inc_resolution = 1; /* until VOL header says otherwise */ |
dec->time_inc_resolution = 1; /* until VOL header says otherwise */ |
198 |
|
dec->ver_id = 1; |
199 |
|
|
200 |
|
dec->bs_version = 0xffff; /* Initialize to very high value -> assume bugfree stream */ |
201 |
|
|
202 |
dec->fixed_dimensions = (dec->width > 0 && dec->height > 0); |
dec->fixed_dimensions = (dec->width > 0 && dec->height > 0); |
203 |
|
|
204 |
if (dec->fixed_dimensions) |
if (dec->fixed_dimensions) { |
205 |
return decoder_resize(dec); |
int ret = decoder_resize(dec); |
206 |
|
if (ret == XVID_ERR_MEMORY) create->handle = NULL; |
207 |
|
return ret; |
208 |
|
} |
209 |
else |
else |
210 |
return 0; |
return 0; |
211 |
} |
} |
472 |
const uint32_t cbp, |
const uint32_t cbp, |
473 |
Bitstream * bs, |
Bitstream * bs, |
474 |
const uint32_t rounding, |
const uint32_t rounding, |
475 |
const int ref) |
const int ref, |
476 |
|
const int bvop) |
477 |
{ |
{ |
478 |
uint32_t stride = dec->edged_width; |
uint32_t stride = dec->edged_width; |
479 |
uint32_t stride2 = stride / 2; |
uint32_t stride2 = stride / 2; |
494 |
|
|
495 |
start_timer(); |
start_timer(); |
496 |
|
|
497 |
if (pMB->mode != MODE_INTER4V) { /* INTER, INTER_Q, NOT_CODED, FORWARD, BACKWARD */ |
if ((pMB->mode != MODE_INTER4V) || (bvop)) { /* INTER, INTER_Q, NOT_CODED, FORWARD, BACKWARD */ |
498 |
|
|
499 |
uv_dx = mv[0].x; |
uv_dx = mv[0].x; |
500 |
uv_dy = mv[0].y; |
uv_dy = mv[0].y; |
588 |
const uint32_t cbp, |
const uint32_t cbp, |
589 |
Bitstream * bs, |
Bitstream * bs, |
590 |
const uint32_t rounding, |
const uint32_t rounding, |
591 |
const int ref) |
const int ref, |
592 |
|
const int bvop) |
593 |
{ |
{ |
594 |
uint32_t stride = dec->edged_width; |
uint32_t stride = dec->edged_width; |
595 |
uint32_t stride2 = stride / 2; |
uint32_t stride2 = stride / 2; |
613 |
|
|
614 |
start_timer(); |
start_timer(); |
615 |
|
|
616 |
if(pMB->mode!=MODE_INTER4V) /* INTER, INTER_Q, NOT_CODED, FORWARD, BACKWARD */ |
if((pMB->mode!=MODE_INTER4V) || (bvop)) /* INTER, INTER_Q, NOT_CODED, FORWARD, BACKWARD */ |
617 |
{ |
{ |
618 |
/* Prepare top field vector */ |
/* Prepare top field vector */ |
619 |
uvtop_dx = DIV2ROUND(mv[0].x); |
uvtop_dx = DIV2ROUND(mv[0].x); |
751 |
bound = read_video_packet_header(bs, dec, 0, |
bound = read_video_packet_header(bs, dec, 0, |
752 |
&quant, NULL, NULL, &intra_dc_threshold); |
&quant, NULL, NULL, &intra_dc_threshold); |
753 |
x = bound % mb_width; |
x = bound % mb_width; |
754 |
y = bound / mb_width; |
y = MIN((bound / mb_width), (mb_height-1)); |
755 |
} |
} |
756 |
mb = &dec->mbs[y * dec->mb_width + x]; |
mb = &dec->mbs[y * dec->mb_width + x]; |
757 |
|
|
978 |
bound = read_video_packet_header(bs, dec, fcode - 1, |
bound = read_video_packet_header(bs, dec, fcode - 1, |
979 |
&quant, &fcode, NULL, &intra_dc_threshold); |
&quant, &fcode, NULL, &intra_dc_threshold); |
980 |
x = bound % mb_width; |
x = bound % mb_width; |
981 |
y = bound / mb_width; |
y = MIN((bound / mb_width), (mb_height-1)); |
982 |
} |
} |
983 |
mb = &dec->mbs[y * dec->mb_width + x]; |
mb = &dec->mbs[y * dec->mb_width + x]; |
984 |
|
|
1071 |
|
|
1072 |
/* See how to decode */ |
/* See how to decode */ |
1073 |
if(!mb->field_pred) |
if(!mb->field_pred) |
1074 |
decoder_mbinter(dec, mb, x, y, cbp, bs, rounding, 0); |
decoder_mbinter(dec, mb, x, y, cbp, bs, rounding, 0, 0); |
1075 |
else |
else |
1076 |
decoder_mbinter_field(dec, mb, x, y, cbp, bs, rounding, 0); |
decoder_mbinter_field(dec, mb, x, y, cbp, bs, rounding, 0, 0); |
1077 |
|
|
1078 |
} else if (gmc_warp) { /* a not coded S(GMC)-VOP macroblock */ |
} else if (gmc_warp) { /* a not coded S(GMC)-VOP macroblock */ |
1079 |
mb->mode = MODE_NOT_CODED_GMC; |
mb->mode = MODE_NOT_CODED_GMC; |
1094 |
mb->field_pred=0; /* (!) */ |
mb->field_pred=0; /* (!) */ |
1095 |
|
|
1096 |
decoder_mbinter(dec, mb, x, y, 0, bs, |
decoder_mbinter(dec, mb, x, y, 0, bs, |
1097 |
rounding, 0); |
rounding, 0, 0); |
1098 |
|
|
1099 |
if(dec->out_frm && cp_mb > 0) { |
if(dec->out_frm && cp_mb > 0) { |
1100 |
output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb); |
output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb); |
1196 |
b_uv_dy = (b_uv_dy >> 1) + roundtab_79[b_uv_dy & 0x3]; |
b_uv_dy = (b_uv_dy >> 1) + roundtab_79[b_uv_dy & 0x3]; |
1197 |
|
|
1198 |
} else { |
} else { |
1199 |
uv_dx = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
if (dec->quarterpel) { /* for qpel the /2 shall be done before summation. We've done it right in the encoder in the past. */ |
1200 |
uv_dy = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
/* TODO: figure out if we ever did it wrong on the encoder side. If yes, add some workaround */ |
|
b_uv_dx = pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x + pMB->b_mvs[3].x; |
|
|
b_uv_dy = pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + pMB->b_mvs[3].y; |
|
|
|
|
|
if (dec->quarterpel) { |
|
1201 |
if (dec->bs_version <= BS_VERSION_BUGGY_CHROMA_ROUNDING) { |
if (dec->bs_version <= BS_VERSION_BUGGY_CHROMA_ROUNDING) { |
1202 |
uv_dx = (uv_dx>>1) | (uv_dx&1); |
int z; |
1203 |
uv_dy = (uv_dy>>1) | (uv_dy&1); |
uv_dx = 0; uv_dy = 0; |
1204 |
b_uv_dx = (b_uv_dx>>1) | (b_uv_dx&1); |
b_uv_dx = 0; b_uv_dy = 0; |
1205 |
b_uv_dy = (b_uv_dy>>1) | (b_uv_dy&1); |
for (z = 0; z < 4; z++) { |
1206 |
|
uv_dx += ((pMB->mvs[z].x>>1) | (pMB->mvs[z].x&1)); |
1207 |
|
uv_dy += ((pMB->mvs[z].y>>1) | (pMB->mvs[z].y&1)); |
1208 |
|
b_uv_dx += ((pMB->b_mvs[z].x>>1) | (pMB->b_mvs[z].x&1)); |
1209 |
|
b_uv_dy += ((pMB->b_mvs[z].y>>1) | (pMB->b_mvs[z].y&1)); |
1210 |
|
} |
1211 |
} |
} |
1212 |
else { |
else { |
1213 |
uv_dx /= 2; |
uv_dx = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2); |
1214 |
uv_dy /= 2; |
uv_dy = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2); |
1215 |
b_uv_dx /= 2; |
b_uv_dx = (pMB->b_mvs[0].x / 2) + (pMB->b_mvs[1].x / 2) + (pMB->b_mvs[2].x / 2) + (pMB->b_mvs[3].x / 2); |
1216 |
b_uv_dy /= 2; |
b_uv_dy = (pMB->b_mvs[0].y / 2) + (pMB->b_mvs[1].y / 2) + (pMB->b_mvs[2].y / 2) + (pMB->b_mvs[3].y / 2); |
1217 |
} |
} |
1218 |
|
} else { |
1219 |
|
uv_dx = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
1220 |
|
uv_dy = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
1221 |
|
b_uv_dx = pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x + pMB->b_mvs[3].x; |
1222 |
|
b_uv_dy = pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + pMB->b_mvs[3].y; |
1223 |
} |
} |
1224 |
|
|
1225 |
uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf]; |
uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf]; |
1338 |
return -1; |
return -1; |
1339 |
} |
} |
1340 |
|
|
1341 |
|
static int __inline get_resync_len_b(const int fcode_backward, |
1342 |
|
const int fcode_forward) { |
1343 |
|
int resync_len = ((fcode_forward>fcode_backward) ? fcode_forward : fcode_backward) - 1; |
1344 |
|
if (resync_len < 1) resync_len = 1; |
1345 |
|
return resync_len; |
1346 |
|
} |
1347 |
|
|
1348 |
static void |
static void |
1349 |
decoder_bframe(DECODER * dec, |
decoder_bframe(DECODER * dec, |
1350 |
Bitstream * bs, |
Bitstream * bs, |
1356 |
VECTOR mv; |
VECTOR mv; |
1357 |
const VECTOR zeromv = {0,0}; |
const VECTOR zeromv = {0,0}; |
1358 |
int i; |
int i; |
1359 |
|
int resync_len; |
1360 |
|
|
1361 |
if (!dec->is_edged[0]) { |
if (!dec->is_edged[0]) { |
1362 |
start_timer(); |
start_timer(); |
1374 |
stop_edges_timer(); |
stop_edges_timer(); |
1375 |
} |
} |
1376 |
|
|
1377 |
|
resync_len = get_resync_len_b(fcode_backward, fcode_forward); |
1378 |
for (y = 0; y < dec->mb_height; y++) { |
for (y = 0; y < dec->mb_height; y++) { |
1379 |
/* Initialize Pred Motion Vector */ |
/* Initialize Pred Motion Vector */ |
1380 |
dec->p_fmv = dec->p_bmv = zeromv; |
dec->p_fmv = dec->p_bmv = zeromv; |
1381 |
for (x = 0; x < dec->mb_width; x++) { |
for (x = 0; x < dec->mb_width; x++) { |
1382 |
MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x]; |
MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x]; |
1383 |
MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x]; |
MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x]; |
|
const int fcode_max = (fcode_forward>fcode_backward) ? fcode_forward : fcode_backward; |
|
1384 |
int intra_dc_threshold; /* fake variable */ |
int intra_dc_threshold; /* fake variable */ |
1385 |
|
|
1386 |
if (check_resync_marker(bs, fcode_max - 1)) { |
if (check_resync_marker(bs, resync_len)) { |
1387 |
int bound = read_video_packet_header(bs, dec, fcode_max - 1, &quant, |
int bound = read_video_packet_header(bs, dec, resync_len, &quant, |
1388 |
&fcode_forward, &fcode_backward, &intra_dc_threshold); |
&fcode_forward, &fcode_backward, &intra_dc_threshold); |
1389 |
x = bound % dec->mb_width; |
x = bound % dec->mb_width; |
1390 |
y = bound / dec->mb_width; |
y = MIN((bound / dec->mb_width), (dec->mb_height-1)); |
1391 |
/* reset predicted macroblocks */ |
/* reset predicted macroblocks */ |
1392 |
dec->p_fmv = dec->p_bmv = zeromv; |
dec->p_fmv = dec->p_bmv = zeromv; |
1393 |
|
/* update resync len with new fcodes */ |
1394 |
|
resync_len = get_resync_len_b(fcode_backward, fcode_forward); |
1395 |
} |
} |
1396 |
|
|
1397 |
mv = |
mv = |
1408 |
if (last_mb->mode == MODE_NOT_CODED) { |
if (last_mb->mode == MODE_NOT_CODED) { |
1409 |
mb->cbp = 0; |
mb->cbp = 0; |
1410 |
mb->mode = MODE_FORWARD; |
mb->mode = MODE_FORWARD; |
1411 |
decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 1); |
decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 1, 1); |
1412 |
continue; |
continue; |
1413 |
} |
} |
1414 |
|
|
1491 |
get_b_motion_vector(bs, &mb->mvs[0], fcode_backward, dec->p_bmv, dec, x, y); |
get_b_motion_vector(bs, &mb->mvs[0], fcode_backward, dec->p_bmv, dec, x, y); |
1492 |
dec->p_bmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; |
dec->p_bmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; |
1493 |
|
|
1494 |
decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0); |
decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 1); |
1495 |
break; |
break; |
1496 |
|
|
1497 |
case MODE_FORWARD: |
case MODE_FORWARD: |
1498 |
get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv, dec, x, y); |
get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv, dec, x, y); |
1499 |
dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; |
dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; |
1500 |
|
|
1501 |
decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 1); |
decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 1, 1); |
1502 |
break; |
break; |
1503 |
|
|
1504 |
default: |
default: |
1631 |
if (coding_type == -2 || coding_type == -3) { /* vol and/or resize */ |
if (coding_type == -2 || coding_type == -3) { /* vol and/or resize */ |
1632 |
|
|
1633 |
if (coding_type == -3) |
if (coding_type == -3) |
1634 |
decoder_resize(dec); |
if (decoder_resize(dec)) return XVID_ERR_MEMORY; |
1635 |
|
|
1636 |
if(stats) { |
if(stats) { |
1637 |
stats->type = XVID_TYPE_VOL; |
stats->type = XVID_TYPE_VOL; |