53 |
* 26.03.2002 interlacing support - moved transfers outside decode loop |
* 26.03.2002 interlacing support - moved transfers outside decode loop |
54 |
* 26.12.2001 decoder_mbinter: dequant/idct moved within if(coded) block |
* 26.12.2001 decoder_mbinter: dequant/idct moved within if(coded) block |
55 |
* 22.12.2001 lock based interpolation |
* 22.12.2001 lock based interpolation |
56 |
* 01.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
* 01.12.2001 inital version; (c)2001 peter ross <pross@xvid.org> |
57 |
* |
* |
58 |
* $Id$ |
* $Id$ |
59 |
* |
* |
348 |
uv_dx = pMB->mvs[0].x; |
uv_dx = pMB->mvs[0].x; |
349 |
uv_dy = pMB->mvs[0].y; |
uv_dy = pMB->mvs[0].y; |
350 |
|
|
351 |
|
if (dec->quarterpel) |
352 |
|
{ |
353 |
|
uv_dx = (uv_dx >> 1) | (uv_dx & 1); |
354 |
|
uv_dy = (uv_dy >> 1) | (uv_dy & 1); |
355 |
|
} |
356 |
|
|
357 |
uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2; |
uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2; |
358 |
uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2; |
uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2; |
359 |
} else { |
} else { |
360 |
int sum; |
int sum; |
|
|
|
361 |
sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
362 |
uv_dx = |
|
363 |
(sum == |
if (dec->quarterpel) |
364 |
0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + |
{ |
365 |
(ABS(sum) / 16) * 2)); |
sum /= 2; |
366 |
|
} |
367 |
|
|
368 |
|
uv_dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2)); |
369 |
|
|
370 |
sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
371 |
uv_dy = |
|
372 |
(sum == |
if (dec->quarterpel) |
373 |
0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + |
{ |
374 |
(ABS(sum) / 16) * 2)); |
sum /= 2; |
375 |
|
} |
376 |
|
|
377 |
|
uv_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2)); |
378 |
} |
} |
379 |
|
|
380 |
start_timer(); |
start_timer(); |
381 |
|
if(dec->quarterpel) { |
382 |
|
DPRINTF(DPRINTF_DEBUG, "QUARTERPEL\n"); |
383 |
|
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos, |
384 |
|
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
385 |
|
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos, |
386 |
|
pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
387 |
|
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8, |
388 |
|
pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
389 |
|
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8, |
390 |
|
pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); |
391 |
|
} |
392 |
|
else { |
393 |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos, 16 * y_pos, |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos, 16 * y_pos, |
394 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
395 |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos + 8, |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos, |
396 |
16 * y_pos, pMB->mvs[1].x, pMB->mvs[1].y, stride, |
pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
397 |
rounding); |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8, |
398 |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos, |
pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
399 |
16 * y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride, |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8, |
400 |
rounding); |
pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); |
401 |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos + 8, |
} |
402 |
16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride, |
|
|
rounding); |
|
403 |
interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos, |
interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos, |
404 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
405 |
interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos, |
interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos, |
509 |
|
|
510 |
if (dec->interlacing) { |
if (dec->interlacing) { |
511 |
mb->field_dct = BitstreamGetBit(bs); |
mb->field_dct = BitstreamGetBit(bs); |
512 |
DEBUG1("deci: field_dct: ", mb->field_dct); |
DPRINTF(DPRINTF_DEBUG, "deci: field_dct: %d", mb->field_dct); |
513 |
} |
} |
514 |
|
|
515 |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
516 |
intra_dc_threshold, bound); |
intra_dc_threshold, bound); |
517 |
} |
} |
518 |
|
if(dec->out_frm) |
519 |
|
output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,0,y,dec->mb_width); |
520 |
|
|
521 |
} |
} |
522 |
|
|
523 |
} |
} |
581 |
|
|
582 |
uint32_t x, y; |
uint32_t x, y; |
583 |
uint32_t bound; |
uint32_t bound; |
584 |
|
int cp_mb, st_mb; |
585 |
|
|
586 |
start_timer(); |
start_timer(); |
587 |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
588 |
dec->width, dec->height, dec->interlacing); |
dec->width, dec->height); |
589 |
stop_edges_timer(); |
stop_edges_timer(); |
590 |
|
|
591 |
bound = 0; |
bound = 0; |
592 |
|
|
593 |
for (y = 0; y < dec->mb_height; y++) { |
for (y = 0; y < dec->mb_height; y++) { |
594 |
|
cp_mb = st_mb = 0; |
595 |
for (x = 0; x < dec->mb_width; x++) { |
for (x = 0; x < dec->mb_width; x++) { |
596 |
MACROBLOCK *mb; |
MACROBLOCK *mb; |
597 |
|
|
619 |
uint32_t cbp; |
uint32_t cbp; |
620 |
uint32_t intra; |
uint32_t intra; |
621 |
|
|
622 |
|
cp_mb++; |
623 |
mcbpc = get_mcbpc_inter(bs); |
mcbpc = get_mcbpc_inter(bs); |
624 |
mb->mode = mcbpc & 7; |
mb->mode = mcbpc & 7; |
625 |
cbpc = (mcbpc >> 4); |
cbpc = (mcbpc >> 4); |
653 |
mb->quant = quant; |
mb->quant = quant; |
654 |
|
|
655 |
if (dec->interlacing) { |
if (dec->interlacing) { |
656 |
|
if (cbp || intra) { |
657 |
mb->field_dct = BitstreamGetBit(bs); |
mb->field_dct = BitstreamGetBit(bs); |
658 |
DEBUG1("decp: field_dct: ", mb->field_dct); |
DPRINTF(DPRINTF_DEBUG, "decp: field_dct: %d", mb->field_dct); |
659 |
|
} |
660 |
|
|
661 |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
662 |
mb->field_pred = BitstreamGetBit(bs); |
mb->field_pred = BitstreamGetBit(bs); |
663 |
DEBUG1("decp: field_pred: ", mb->field_pred); |
DPRINTF(DPRINTF_DEBUG, "decp: field_pred: %d", mb->field_pred); |
664 |
|
|
665 |
if (mb->field_pred) { |
if (mb->field_pred) { |
666 |
mb->field_for_top = BitstreamGetBit(bs); |
mb->field_for_top = BitstreamGetBit(bs); |
667 |
DEBUG1("decp: field_for_top: ", mb->field_for_top); |
DPRINTF(DPRINTF_DEBUG, "decp: field_for_top: %d", mb->field_for_top); |
668 |
mb->field_for_bot = BitstreamGetBit(bs); |
mb->field_for_bot = BitstreamGetBit(bs); |
669 |
DEBUG1("decp: field_for_bot: ", mb->field_for_bot); |
DPRINTF(DPRINTF_DEBUG, "decp: field_for_bot: %d", mb->field_for_bot); |
670 |
} |
} |
671 |
} |
} |
672 |
} |
} |
685 |
mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = |
mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = |
686 |
mb->mvs[0].y; |
mb->mvs[0].y; |
687 |
} |
} |
688 |
} else if (mb->mode == |
} else if (mb->mode == MODE_INTER4V ) { |
689 |
MODE_INTER4V /* || mb->mode == MODE_INTER4V_Q */ ) { |
|
690 |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound); |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound); |
691 |
get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode, bound); |
get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode, bound); |
692 |
get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode, bound); |
get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode, bound); |
706 |
rounding); |
rounding); |
707 |
} else // not coded |
} else // not coded |
708 |
{ |
{ |
709 |
//DEBUG2("P-frame MB at (X,Y)=",x,y); |
DPRINTF(DPRINTF_DEBUG, "P-frame MB at (X,Y)=(%d,%d)", x, y); |
710 |
|
|
711 |
mb->mode = MODE_NOT_CODED; |
mb->mode = MODE_NOT_CODED; |
712 |
mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0; |
mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0; |
713 |
mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0; |
mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0; |
749 |
dec->refn[0].v + |
dec->refn[0].v + |
750 |
(8 * y) * dec->edged_width / 2 + (8 * x), |
(8 * y) * dec->edged_width / 2 + (8 * x), |
751 |
dec->edged_width / 2); |
dec->edged_width / 2); |
|
|
|
752 |
stop_transfer_timer(); |
stop_transfer_timer(); |
753 |
|
if(dec->out_frm && cp_mb > 0) { |
754 |
|
output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb); |
755 |
|
cp_mb = 0; |
756 |
|
} |
757 |
|
st_mb = x+1; |
758 |
} |
} |
759 |
} |
} |
760 |
|
if(dec->out_frm && cp_mb > 0) |
761 |
|
output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb); |
762 |
} |
} |
763 |
} |
} |
764 |
|
|
1143 |
|
|
1144 |
start_timer(); |
start_timer(); |
1145 |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
1146 |
dec->width, dec->height, dec->interlacing); |
dec->width, dec->height); |
1147 |
image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, |
1148 |
dec->width, dec->height, dec->interlacing); |
dec->width, dec->height); |
1149 |
stop_edges_timer(); |
stop_edges_timer(); |
1150 |
|
|
1151 |
#ifdef BFRAMES_DEC_DEBUG |
#ifdef BFRAMES_DEC_DEBUG |
1213 |
#ifdef BFRAMES_DEC_DEBUG |
#ifdef BFRAMES_DEC_DEBUG |
1214 |
BFRAME_DEBUG |
BFRAME_DEBUG |
1215 |
#endif |
#endif |
1216 |
|
|
1217 |
switch (mb->mb_type) { |
switch (mb->mb_type) { |
1218 |
case MODE_DIRECT: |
case MODE_DIRECT: |
1219 |
get_b_motion_vector(dec, bs, x, y, &mv, 1, zeromv); |
get_b_motion_vector(dec, bs, x, y, &mv, 1, zeromv); |
1220 |
|
|
1221 |
case MODE_DIRECT_NONE_MV: |
case MODE_DIRECT_NONE_MV: |
1222 |
{ // Because this file is a C file not C++ so I use '{' to define var |
{ |
1223 |
const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp; |
const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp; |
1224 |
int i; |
int i; |
1225 |
|
|
1279 |
break; |
break; |
1280 |
|
|
1281 |
default: |
default: |
1282 |
//DEBUG1("Not support B-frame mb_type =", mb->mb_type); |
DPRINTF(DPRINTF_ERROR, "Not support B-frame mb_type = %d", mb->mb_type); |
|
; |
|
1283 |
} |
} |
1284 |
|
|
1285 |
} // end of FOR |
} // end of FOR |
1319 |
|
|
1320 |
start_global_timer(); |
start_global_timer(); |
1321 |
|
|
1322 |
|
dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL; |
1323 |
|
|
1324 |
BitstreamInit(&bs, frame->bitstream, frame->length); |
BitstreamInit(&bs, frame->bitstream, frame->length); |
1325 |
|
|
1326 |
// add by chenm001 <chenm001@163.com> |
// add by chenm001 <chenm001@163.com> |
1337 |
decoder_pframe(dec, &bs, rounding, quant, fcode_forward, |
decoder_pframe(dec, &bs, rounding, quant, fcode_forward, |
1338 |
intra_dc_threshold); |
intra_dc_threshold); |
1339 |
#ifdef BFRAMES_DEC |
#ifdef BFRAMES_DEC |
1340 |
DEBUG1("P_VOP Time=", dec->time); |
DPRINTF(DPRINTF_DEBUG, "P_VOP Time=%d", dec->time); |
1341 |
#endif |
#endif |
1342 |
break; |
break; |
1343 |
|
|
1344 |
case I_VOP: |
case I_VOP: |
1345 |
decoder_iframe(dec, &bs, quant, intra_dc_threshold); |
decoder_iframe(dec, &bs, quant, intra_dc_threshold); |
1346 |
#ifdef BFRAMES_DEC |
#ifdef BFRAMES_DEC |
1347 |
DEBUG1("I_VOP Time=", dec->time); |
DPRINTF(DPRINTF_DEBUG, "I_VOP Time=%d", dec->time); |
1348 |
#endif |
#endif |
1349 |
break; |
break; |
1350 |
|
|
1351 |
case B_VOP: |
case B_VOP: |
1352 |
#ifdef BFRAMES_DEC |
#ifdef BFRAMES_DEC |
1353 |
if (dec->time_pp > dec->time_bp) { |
if (dec->time_pp > dec->time_bp) { |
1354 |
DEBUG1("B_VOP Time=", dec->time); |
DPRINTF(DPRINTF_DEBUG, "B_VOP Time=%d", dec->time); |
1355 |
decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); |
decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); |
1356 |
} else { |
} else { |
1357 |
DEBUG("broken B-frame!"); |
DPRINTF(DPRINTF_DEBUG, "Broken B_VOP"); |
1358 |
} |
} |
1359 |
#else |
#else |
1360 |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
1372 |
|
|
1373 |
#ifdef BFRAMES_DEC_DEBUG |
#ifdef BFRAMES_DEC_DEBUG |
1374 |
if (frame->length != BitstreamPos(&bs) / 8){ |
if (frame->length != BitstreamPos(&bs) / 8){ |
1375 |
DEBUG2("InLen/UseLen",frame->length, BitstreamPos(&bs) / 8); |
DPRINTF(DPRINTF_DEBUG, "InLen: %d / UseLen: %d", frame->length, BitstreamPos(&bs) / 8); |
1376 |
} |
} |
1377 |
#endif |
#endif |
1378 |
frame->length = BitstreamPos(&bs) / 8; |
frame->length = BitstreamPos(&bs) / 8; |
1380 |
|
|
1381 |
#ifdef BFRAMES_DEC |
#ifdef BFRAMES_DEC |
1382 |
// test if no B_VOP |
// test if no B_VOP |
1383 |
if (dec->low_delay) { |
if (dec->low_delay || dec->frames == 0) { |
1384 |
#endif |
#endif |
1385 |
image_output(&dec->cur, dec->width, dec->height, dec->edged_width, |
image_output(&dec->cur, dec->width, dec->height, dec->edged_width, |
1386 |
frame->image, frame->stride, frame->colorspace); |
frame->image, frame->stride, frame->colorspace); |
1387 |
|
|
1388 |
#ifdef BFRAMES_DEC |
#ifdef BFRAMES_DEC |
1389 |
} else { |
} else { |
1390 |
if (dec->frames >= 0) { |
if (dec->frames >= 1) { |
1391 |
start_timer(); |
start_timer(); |
1392 |
if ((vop_type == I_VOP || vop_type == P_VOP)) { |
if ((vop_type == I_VOP || vop_type == P_VOP)) { |
1393 |
image_output(&dec->refn[0], dec->width, dec->height, |
image_output(&dec->refn[0], dec->width, dec->height, |
1406 |
if (vop_type == I_VOP || vop_type == P_VOP) { |
if (vop_type == I_VOP || vop_type == P_VOP) { |
1407 |
image_swap(&dec->refn[0], &dec->refn[1]); |
image_swap(&dec->refn[0], &dec->refn[1]); |
1408 |
image_swap(&dec->cur, &dec->refn[0]); |
image_swap(&dec->cur, &dec->refn[0]); |
1409 |
|
|
1410 |
// swap MACROBLOCK |
// swap MACROBLOCK |
1411 |
if (!dec->low_delay && vop_type == P_VOP) |
// the Divx will not set the low_delay flage some times |
1412 |
|
// so follow code will wrong to not swap at that time |
1413 |
|
// this will broken bitstream! so I'm change it, |
1414 |
|
// But that is not the best way! can anyone tell me how |
1415 |
|
// to do another way? |
1416 |
|
// 18-07-2002 MinChen<chenm001@163.com> |
1417 |
|
//if (!dec->low_delay && vop_type == P_VOP) |
1418 |
|
if (vop_type == P_VOP) |
1419 |
mb_swap(&dec->mbs, &dec->last_mbs); |
mb_swap(&dec->mbs, &dec->last_mbs); |
1420 |
} |
} |
1421 |
|
|