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@cs.rmit.edu.au> |
57 |
* |
* |
58 |
* $Id: decoder.c,v 1.37.2.14 2002-11-20 22:28:25 Isibaar Exp $ |
* $Id: decoder.c,v 1.37.2.15 2002-12-08 05:38:56 suxen_drol Exp $ |
59 |
* |
* |
60 |
*************************************************************************/ |
*************************************************************************/ |
61 |
|
|
79 |
#include "dct/fdct.h" |
#include "dct/fdct.h" |
80 |
#include "utils/mem_transfer.h" |
#include "utils/mem_transfer.h" |
81 |
#include "image/interpolate8x8.h" |
#include "image/interpolate8x8.h" |
82 |
|
#include "image/reduced.h" |
83 |
|
|
84 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
85 |
#include "prediction/mbprediction.h" |
#include "prediction/mbprediction.h" |
219 |
dec->frames = -1; |
dec->frames = -1; |
220 |
dec->time = dec->time_base = dec->last_time_base = 0; |
dec->time = dec->time_base = dec->last_time_base = 0; |
221 |
dec->low_delay = 0; |
dec->low_delay = 0; |
222 |
|
dec->packed_mode = 0; |
223 |
|
|
224 |
dec->fixed_dimensions = (dec->width > 0 && dec->height > 0); |
dec->fixed_dimensions = (dec->width > 0 && dec->height > 0); |
225 |
|
|
267 |
Bitstream * bs, |
Bitstream * bs, |
268 |
const uint32_t quant, |
const uint32_t quant, |
269 |
const uint32_t intra_dc_threshold, |
const uint32_t intra_dc_threshold, |
270 |
const unsigned int bound) |
const unsigned int bound, |
271 |
|
const int reduced_resolution) |
272 |
{ |
{ |
273 |
|
|
274 |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
281 |
uint32_t iQuant = pMB->quant; |
uint32_t iQuant = pMB->quant; |
282 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
283 |
|
|
284 |
|
if (reduced_resolution) { |
285 |
|
pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5); |
286 |
|
pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4); |
287 |
|
pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4); |
288 |
|
}else{ |
289 |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
290 |
pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); |
pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); |
291 |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
292 |
|
} |
293 |
|
|
294 |
memset(block, 0, 6 * 64 * sizeof(int16_t)); // clear |
memset(block, 0, 6 * 64 * sizeof(int16_t)); // clear |
295 |
|
|
350 |
start_timer(); |
start_timer(); |
351 |
idct(&data[i * 64]); |
idct(&data[i * 64]); |
352 |
stop_idct_timer(); |
stop_idct_timer(); |
353 |
|
|
354 |
} |
} |
355 |
|
|
356 |
if (dec->interlacing && pMB->field_dct) { |
if (dec->interlacing && pMB->field_dct) { |
359 |
} |
} |
360 |
|
|
361 |
start_timer(); |
start_timer(); |
362 |
|
|
363 |
|
if (reduced_resolution) |
364 |
|
{ |
365 |
|
next_block*=2; |
366 |
|
copy_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride); |
367 |
|
copy_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride); |
368 |
|
copy_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride); |
369 |
|
copy_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride); |
370 |
|
copy_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2); |
371 |
|
copy_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2); |
372 |
|
}else{ |
373 |
transfer_16to8copy(pY_Cur, &data[0 * 64], stride); |
transfer_16to8copy(pY_Cur, &data[0 * 64], stride); |
374 |
transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride); |
transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride); |
375 |
transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride); |
transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride); |
376 |
transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride); |
transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride); |
377 |
transfer_16to8copy(pU_Cur, &data[4 * 64], stride2); |
transfer_16to8copy(pU_Cur, &data[4 * 64], stride2); |
378 |
transfer_16to8copy(pV_Cur, &data[5 * 64], stride2); |
transfer_16to8copy(pV_Cur, &data[5 * 64], stride2); |
379 |
|
} |
380 |
stop_transfer_timer(); |
stop_transfer_timer(); |
381 |
} |
} |
382 |
|
|
389 |
|
|
390 |
// decode an inter macroblock |
// decode an inter macroblock |
391 |
|
|
392 |
|
static void |
393 |
|
set_block(uint8_t * dst, int stride, int width, int height, int color) |
394 |
|
{ |
395 |
|
int i; |
396 |
|
for (i = 0; i < height; i++) |
397 |
|
{ |
398 |
|
memset(dst, color, width); |
399 |
|
dst += stride; |
400 |
|
} |
401 |
|
} |
402 |
|
|
403 |
|
static void |
404 |
|
rrv_mv_scaleup(VECTOR * mv) |
405 |
|
{ |
406 |
|
if (mv->x > 0) { |
407 |
|
mv->x = 2*mv->x - 1; |
408 |
|
} else if (mv->x < 0) { |
409 |
|
mv->x = 2*mv->x + 1; |
410 |
|
} |
411 |
|
|
412 |
|
if (mv->y > 0) { |
413 |
|
mv->y = 2*mv->y - 1; |
414 |
|
} else if (mv->y < 0) { |
415 |
|
mv->y = 2*mv->y + 1; |
416 |
|
} |
417 |
|
} |
418 |
|
|
419 |
|
|
420 |
|
|
421 |
void |
void |
422 |
decoder_mbinter(DECODER * dec, |
decoder_mbinter(DECODER * dec, |
423 |
const MACROBLOCK * pMB, |
const MACROBLOCK * pMB, |
427 |
const uint32_t cbp, |
const uint32_t cbp, |
428 |
Bitstream * bs, |
Bitstream * bs, |
429 |
const uint32_t quant, |
const uint32_t quant, |
430 |
const uint32_t rounding) |
const uint32_t rounding, |
431 |
|
const int reduced_resolution) |
432 |
{ |
{ |
433 |
|
|
434 |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
436 |
|
|
437 |
uint32_t stride = dec->edged_width; |
uint32_t stride = dec->edged_width; |
438 |
uint32_t stride2 = stride / 2; |
uint32_t stride2 = stride / 2; |
439 |
uint32_t next_block = stride * 8; |
uint32_t next_block = stride * (reduced_resolution ? 16 : 8); |
440 |
uint32_t i; |
uint32_t i; |
441 |
uint32_t iQuant = pMB->quant; |
uint32_t iQuant = pMB->quant; |
442 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
443 |
|
|
444 |
int uv_dx, uv_dy; |
int uv_dx, uv_dy; |
445 |
|
VECTOR mv[4]; |
446 |
|
|
447 |
|
for (i = 0; i < 4; i++) |
448 |
|
{ |
449 |
|
mv[i] = pMB->mvs[i]; |
450 |
|
//DPRINTF(DPRINTF_MB, "mv[%i] orig=%i,%i local=%i", i, pMB->mvs[i].x, pMB->mvs[i].y, mv[i].x, mv[i].y); |
451 |
|
} |
452 |
|
|
453 |
|
if (reduced_resolution) { |
454 |
|
pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5); |
455 |
|
pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4); |
456 |
|
pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4); |
457 |
|
DPRINTF(DPRINTF_MB,"[%i,%i] %i,%i %i,%i %i,%i %i,%i", |
458 |
|
x_pos, y_pos, |
459 |
|
mv[0].x, mv[0].y, |
460 |
|
mv[1].x, mv[1].y, |
461 |
|
mv[2].x, mv[2].y, |
462 |
|
mv[3].x, mv[3].y); |
463 |
|
|
464 |
|
rrv_mv_scaleup(&mv[0]); |
465 |
|
rrv_mv_scaleup(&mv[1]); |
466 |
|
rrv_mv_scaleup(&mv[2]); |
467 |
|
rrv_mv_scaleup(&mv[3]); |
468 |
|
|
469 |
|
DPRINTF(DPRINTF_MB," %i,%i %i,%i %i,%i %i,%i", |
470 |
|
mv[0].x, mv[0].y, |
471 |
|
mv[1].x, mv[1].y, |
472 |
|
mv[2].x, mv[2].y, |
473 |
|
mv[3].x, mv[3].y); |
474 |
|
}else{ |
475 |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
476 |
pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); |
pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); |
477 |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
478 |
|
} |
479 |
|
|
480 |
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) { |
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) { |
481 |
uv_dx = pMB->mvs[0].x; |
uv_dx = mv[0].x; |
482 |
uv_dy = pMB->mvs[0].y; |
uv_dy = mv[0].y; |
483 |
|
|
484 |
if (dec->quarterpel) |
if (dec->quarterpel) |
485 |
{ |
{ |
491 |
uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; |
uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; |
492 |
|
|
493 |
start_timer(); |
start_timer(); |
494 |
|
if (reduced_resolution) |
495 |
|
{ |
496 |
|
interpolate32x32_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos, |
497 |
|
mv[0].x, mv[0].y, stride, rounding); |
498 |
|
interpolate16x16_switch(dec->cur.u, dec->refn[0].u, 16 * x_pos, 16 * y_pos, |
499 |
|
uv_dx, uv_dy, stride2, rounding); |
500 |
|
interpolate16x16_switch(dec->cur.v, dec->refn[0].v, 16 * x_pos, 16 * y_pos, |
501 |
|
uv_dx, uv_dy, stride2, rounding); |
502 |
|
|
503 |
|
} |
504 |
|
else |
505 |
|
{ |
506 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
507 |
interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
508 |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
509 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
mv[0].x, mv[0].y, stride, rounding); |
510 |
} |
} |
511 |
else { |
else { |
512 |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos, |
interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos, |
513 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
mv[0].x, mv[0].y, stride, rounding); |
|
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos, |
|
|
pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
|
|
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8, |
|
|
pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
|
|
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8, |
|
|
pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); |
|
514 |
} |
} |
515 |
|
|
516 |
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, |
517 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
518 |
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, |
519 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
520 |
|
} |
521 |
stop_comp_timer(); |
stop_comp_timer(); |
522 |
|
|
523 |
} else { |
} else { /* MODE_INTER4V */ |
524 |
int sum; |
int sum; |
525 |
|
|
526 |
if(dec->quarterpel) |
if(dec->quarterpel) |
527 |
sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2); |
sum = (mv[0].x / 2) + (mv[1].x / 2) + (mv[2].x / 2) + (mv[3].x / 2); |
528 |
else |
else |
529 |
sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
sum = mv[0].x + mv[1].x + mv[2].x + mv[3].x; |
530 |
|
|
531 |
uv_dx = (sum >> 3) + roundtab_76[sum & 0xf]; |
uv_dx = (sum >> 3) + roundtab_76[sum & 0xf]; |
532 |
|
|
533 |
if(dec->quarterpel) |
if(dec->quarterpel) |
534 |
sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2); |
sum = (mv[0].y / 2) + (mv[1].y / 2) + (mv[2].y / 2) + (mv[3].y / 2); |
535 |
else |
else |
536 |
sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
sum = mv[0].y + mv[1].y + mv[2].y + mv[3].y; |
537 |
|
|
538 |
uv_dy = (sum >> 3) + roundtab_76[sum & 0xf]; |
uv_dy = (sum >> 3) + roundtab_76[sum & 0xf]; |
539 |
|
|
540 |
start_timer(); |
start_timer(); |
541 |
|
if (reduced_resolution) |
542 |
|
{ |
543 |
|
interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos, |
544 |
|
mv[0].x, mv[0].y, stride, rounding); |
545 |
|
interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos + 16, 32*y_pos, |
546 |
|
mv[1].x, mv[1].y, stride, rounding); |
547 |
|
interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos + 16, |
548 |
|
mv[2].x, mv[2].y, stride, rounding); |
549 |
|
interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos + 16, 32*y_pos + 16, |
550 |
|
mv[3].x, mv[3].y, stride, rounding); |
551 |
|
interpolate16x16_switch(dec->cur.u, dec->refn[0].u, 16 * x_pos, 16 * y_pos, |
552 |
|
uv_dx, uv_dy, stride2, rounding); |
553 |
|
interpolate16x16_switch(dec->cur.v, dec->refn[0].v, 16 * x_pos, 16 * y_pos, |
554 |
|
uv_dx, uv_dy, stride2, rounding); |
555 |
|
|
556 |
|
// set_block(pY_Cur, stride, 32, 32, 127); |
557 |
|
} |
558 |
|
else |
559 |
|
{ |
560 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
561 |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
562 |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
563 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
mv[0].x, mv[0].y, stride, rounding); |
564 |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
565 |
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos, |
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos, |
566 |
pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
mv[1].x, mv[1].y, stride, rounding); |
567 |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
568 |
dec->refh.y + 128, 16*x_pos, 16*y_pos + 8, |
dec->refh.y + 128, 16*x_pos, 16*y_pos + 8, |
569 |
pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
mv[2].x, mv[2].y, stride, rounding); |
570 |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
571 |
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
572 |
pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); |
mv[3].x, mv[3].y, stride, rounding); |
573 |
} |
} |
574 |
else { |
else { |
575 |
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, |
576 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
mv[0].x, mv[0].y, stride, rounding); |
577 |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos, |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos, |
578 |
pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
mv[1].x, mv[1].y, stride, rounding); |
579 |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8, |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8, |
580 |
pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
mv[2].x, mv[2].y, stride, rounding); |
581 |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8, |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8, |
582 |
pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); |
mv[3].x, mv[3].y, stride, rounding); |
583 |
} |
} |
584 |
|
|
585 |
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, |
586 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
587 |
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, |
588 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
589 |
|
} |
590 |
stop_comp_timer(); |
stop_comp_timer(); |
591 |
} |
} |
592 |
|
|
621 |
} |
} |
622 |
|
|
623 |
start_timer(); |
start_timer(); |
624 |
|
if (reduced_resolution) |
625 |
|
{ |
626 |
|
if (cbp & 32) |
627 |
|
add_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride); |
628 |
|
if (cbp & 16) |
629 |
|
add_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride); |
630 |
|
if (cbp & 8) |
631 |
|
add_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride); |
632 |
|
if (cbp & 4) |
633 |
|
add_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride); |
634 |
|
if (cbp & 2) |
635 |
|
add_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2); |
636 |
|
if (cbp & 1) |
637 |
|
add_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2); |
638 |
|
} |
639 |
|
else |
640 |
|
{ |
641 |
if (cbp & 32) |
if (cbp & 32) |
642 |
transfer_16to8add(pY_Cur, &data[0 * 64], stride); |
transfer_16to8add(pY_Cur, &data[0 * 64], stride); |
643 |
if (cbp & 16) |
if (cbp & 16) |
650 |
transfer_16to8add(pU_Cur, &data[4 * 64], stride2); |
transfer_16to8add(pU_Cur, &data[4 * 64], stride2); |
651 |
if (cbp & 1) |
if (cbp & 1) |
652 |
transfer_16to8add(pV_Cur, &data[5 * 64], stride2); |
transfer_16to8add(pV_Cur, &data[5 * 64], stride2); |
653 |
|
} |
654 |
stop_transfer_timer(); |
stop_transfer_timer(); |
655 |
} |
} |
656 |
|
|
691 |
{ |
{ |
692 |
bound = read_video_packet_header(bs, dec, 0, |
bound = read_video_packet_header(bs, dec, 0, |
693 |
&quant, NULL, NULL, &intra_dc_threshold); |
&quant, NULL, NULL, &intra_dc_threshold); |
694 |
x = bound % dec->mb_width; |
x = bound % mb_width; |
695 |
y = bound / dec->mb_width; |
y = bound / mb_width; |
696 |
} |
} |
697 |
mb = &dec->mbs[y * dec->mb_width + x]; |
mb = &dec->mbs[y * dec->mb_width + x]; |
698 |
|
|
727 |
} |
} |
728 |
|
|
729 |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
730 |
intra_dc_threshold, bound); |
intra_dc_threshold, bound, reduced_resolution); |
731 |
|
|
732 |
} |
} |
733 |
if(dec->out_frm) |
if(dec->out_frm) |
734 |
output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,0,y,dec->mb_width); |
output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,0,y,mb_width); |
735 |
} |
} |
736 |
|
|
737 |
} |
} |
743 |
int x, |
int x, |
744 |
int y, |
int y, |
745 |
int k, |
int k, |
746 |
VECTOR * mv, |
VECTOR * ret_mv, |
747 |
int fcode, |
int fcode, |
748 |
const int bound) |
const int bound) |
749 |
{ |
{ |
754 |
int range = (64 * scale_fac); |
int range = (64 * scale_fac); |
755 |
|
|
756 |
VECTOR pmv; |
VECTOR pmv; |
757 |
int mv_x, mv_y; |
VECTOR mv; |
758 |
|
|
759 |
pmv = get_pmv2(dec->mbs, dec->mb_width, bound, x, y, k); |
pmv = get_pmv2(dec->mbs, dec->mb_width, bound, x, y, k); |
760 |
|
|
761 |
mv_x = get_mv(bs, fcode); |
mv.x = get_mv(bs, fcode); |
762 |
mv_y = get_mv(bs, fcode); |
mv.y = get_mv(bs, fcode); |
763 |
|
|
764 |
DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i)", mv_x, mv_y, pmv.x, pmv.y); |
DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i)", mv.x, mv.y, pmv.x, pmv.y); |
765 |
|
|
766 |
mv_x += pmv.x; |
mv.x += pmv.x; |
767 |
mv_y += pmv.y; |
mv.y += pmv.y; |
768 |
|
|
769 |
if (mv_x < low) { |
if (mv.x < low) { |
770 |
mv_x += range; |
mv.x += range; |
771 |
} else if (mv_x > high) { |
} else if (mv.x > high) { |
772 |
mv_x -= range; |
mv.x -= range; |
773 |
} |
} |
774 |
|
|
775 |
if (mv_y < low) { |
if (mv.y < low) { |
776 |
mv_y += range; |
mv.y += range; |
777 |
} else if (mv_y > high) { |
} else if (mv.y > high) { |
778 |
mv_y -= range; |
mv.y -= range; |
779 |
} |
} |
780 |
|
|
781 |
mv->x = mv_x; |
ret_mv->x = mv.x; |
782 |
mv->y = mv_y; |
ret_mv->y = mv.y; |
783 |
} |
} |
784 |
|
|
785 |
|
|
813 |
uint32_t x, y; |
uint32_t x, y; |
814 |
uint32_t bound; |
uint32_t bound; |
815 |
int cp_mb, st_mb; |
int cp_mb, st_mb; |
816 |
|
int mb_width = dec->mb_width; |
817 |
|
int mb_height = dec->mb_height; |
818 |
|
|
819 |
|
if (reduced_resolution) |
820 |
|
{ |
821 |
|
mb_width /= 2; |
822 |
|
mb_height /= 2; |
823 |
|
} |
824 |
|
|
825 |
start_timer(); |
start_timer(); |
826 |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
829 |
|
|
830 |
bound = 0; |
bound = 0; |
831 |
|
|
832 |
for (y = 0; y < dec->mb_height; y++) { |
for (y = 0; y < mb_height; y++) { |
833 |
cp_mb = st_mb = 0; |
cp_mb = st_mb = 0; |
834 |
for (x = 0; x < dec->mb_width; x++) { |
for (x = 0; x < mb_width; x++) { |
835 |
MACROBLOCK *mb; |
MACROBLOCK *mb; |
836 |
|
|
837 |
// skip stuffing |
// skip stuffing |
842 |
{ |
{ |
843 |
bound = read_video_packet_header(bs, dec, fcode - 1, |
bound = read_video_packet_header(bs, dec, fcode - 1, |
844 |
&quant, &fcode, NULL, &intra_dc_threshold); |
&quant, &fcode, NULL, &intra_dc_threshold); |
845 |
x = bound % dec->mb_width; |
x = bound % mb_width; |
846 |
y = bound / dec->mb_width; |
y = bound / mb_width; |
847 |
} |
} |
848 |
mb = &dec->mbs[y * dec->mb_width + x]; |
mb = &dec->mbs[y * dec->mb_width + x]; |
849 |
|
|
950 |
mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = |
mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = |
951 |
0; |
0; |
952 |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
953 |
intra_dc_threshold, bound); |
intra_dc_threshold, bound, reduced_resolution); |
954 |
continue; |
continue; |
955 |
} |
} |
956 |
|
|
957 |
decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
958 |
rounding); |
rounding, reduced_resolution); |
959 |
|
|
960 |
} |
} |
961 |
else if (gmc_mv) /* not coded S_VOP macroblock */ |
else if (gmc_mv) /* not coded S_VOP macroblock */ |
963 |
mb->mode = MODE_NOT_CODED; |
mb->mode = MODE_NOT_CODED; |
964 |
mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = gmc_sanitize(gmc_mv[0].x, dec->quarterpel, fcode); |
mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = gmc_sanitize(gmc_mv[0].x, dec->quarterpel, fcode); |
965 |
mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = gmc_sanitize(gmc_mv[0].y, dec->quarterpel, fcode); |
mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = gmc_sanitize(gmc_mv[0].y, dec->quarterpel, fcode); |
966 |
decoder_mbinter(dec, mb, x, y, 0, 0, bs, quant, rounding); |
decoder_mbinter(dec, mb, x, y, 0, 0, bs, quant, rounding, reduced_resolution); |
967 |
} |
} |
968 |
else /* not coded P_VOP macroblock */ |
else /* not coded P_VOP macroblock */ |
969 |
{ |
{ |
970 |
mb->mode = MODE_NOT_CODED; |
mb->mode = MODE_NOT_CODED; |
971 |
|
|
972 |
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; |
973 |
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; |
974 |
// copy macroblock directly from ref to cur |
// copy macroblock directly from ref to cur |
975 |
|
|
976 |
start_timer(); |
start_timer(); |
977 |
|
|
978 |
transfer8x8_copy(dec->cur.y + (16 * y) * dec->edged_width + |
if (reduced_resolution) |
979 |
(16 * x), |
{ |
980 |
dec->refn[0].y + (16 * y) * dec->edged_width + |
transfer32x32_copy(dec->cur.y + (32*y)*dec->edged_width + (32*x), |
981 |
(16 * x), dec->edged_width); |
dec->refn[0].y + (32*y)*dec->edged_width + (32*x), |
982 |
|
dec->edged_width); |
983 |
transfer8x8_copy(dec->cur.y + (16 * y) * dec->edged_width + |
|
984 |
(16 * x + 8), |
transfer16x16_copy(dec->cur.u + (16*y)*dec->edged_width/2 + (16*x), |
985 |
dec->refn[0].y + (16 * y) * dec->edged_width + |
dec->refn[0].u + (16*y)*dec->edged_width/2 + (16*x), |
986 |
(16 * x + 8), dec->edged_width); |
dec->edged_width/2); |
987 |
|
|
988 |
transfer8x8_copy(dec->cur.y + (16 * y + 8) * dec->edged_width + |
transfer16x16_copy(dec->cur.v + (16*y)*dec->edged_width/2 + (16*x), |
989 |
(16 * x), |
dec->refn[0].v + (16*y)*dec->edged_width/2 + (16*x), |
990 |
dec->refn[0].y + (16 * y + |
dec->edged_width/2); |
991 |
8) * dec->edged_width + |
} |
992 |
(16 * x), dec->edged_width); |
else |
993 |
|
{ |
994 |
transfer8x8_copy(dec->cur.y + (16 * y + 8) * dec->edged_width + |
transfer16x16_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x), |
995 |
(16 * x + 8), |
dec->refn[0].y + (16*y)*dec->edged_width + (16*x), |
996 |
dec->refn[0].y + (16 * y + |
dec->edged_width); |
997 |
8) * dec->edged_width + |
|
998 |
(16 * x + 8), dec->edged_width); |
transfer8x8_copy(dec->cur.u + (8*y)*dec->edged_width/2 + (8*x), |
999 |
|
dec->refn[0].u + (8*y)*dec->edged_width/2 + (8*x), |
|
transfer8x8_copy(dec->cur.u + (8 * y) * dec->edged_width / 2 + |
|
|
(8 * x), |
|
|
dec->refn[0].u + |
|
|
(8 * y) * dec->edged_width / 2 + (8 * x), |
|
1000 |
dec->edged_width / 2); |
dec->edged_width / 2); |
1001 |
|
|
1002 |
transfer8x8_copy(dec->cur.v + (8 * y) * dec->edged_width / 2 + |
transfer8x8_copy(dec->cur.v + (8*y)*dec->edged_width/2 + (8*x), |
1003 |
(8 * x), |
dec->refn[0].v + (8*y)*dec->edged_width/2 + (8*x), |
|
dec->refn[0].v + |
|
|
(8 * y) * dec->edged_width / 2 + (8 * x), |
|
1004 |
dec->edged_width / 2); |
dec->edged_width / 2); |
1005 |
|
} |
1006 |
|
|
1007 |
stop_transfer_timer(); |
stop_transfer_timer(); |
1008 |
|
|
1695 |
BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution, |
BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution, |
1696 |
&quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, gmc_mv); |
&quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, gmc_mv); |
1697 |
|
|
1698 |
DPRINTF(DPRINTF_HEADER, "vop_type=%i", vop_type); |
//DPRINTF(DPRINTF_HEADER, "vop_type=%i", vop_type); |
1699 |
|
|
1700 |
if (vop_type == -1 && success) |
if (vop_type == -1 && success) |
1701 |
goto done; |
goto done; |
1774 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
1775 |
} |
} |
1776 |
|
|
1777 |
|
|
1778 |
|
/* reduced resolution deblocking filter */ |
1779 |
|
|
1780 |
|
if (reduced_resolution) |
1781 |
|
{ |
1782 |
|
const int rmb_height = dec->mb_height / 2; |
1783 |
|
const int rmb_width = dec->mb_width / 2; |
1784 |
|
const int edged_width2 = dec->edged_width /2; |
1785 |
|
int i,j; |
1786 |
|
|
1787 |
|
/* horizontal deblocking */ |
1788 |
|
|
1789 |
|
for (j = 1; j < rmb_height*2; j++) // luma: j,i in block units |
1790 |
|
for (i = 0; i < rmb_width*2; i++) |
1791 |
|
{ |
1792 |
|
if (dec->mbs[(j-1)/2*dec->mb_width + (i/2)].mode != MODE_NOT_CODED || |
1793 |
|
dec->mbs[(j+0)/2*dec->mb_width + (i/2)].mode != MODE_NOT_CODED) |
1794 |
|
{ |
1795 |
|
xvid_HFilter_31_C(dec->cur.y + (j*16 - 1)*dec->edged_width + i*16, |
1796 |
|
dec->cur.y + (j*16 + 0)*dec->edged_width + i*16, 2); |
1797 |
|
} |
1798 |
|
} |
1799 |
|
|
1800 |
|
for (j = 1; j < rmb_height; j++) // chroma |
1801 |
|
for (i = 0; i < rmb_width; i++) |
1802 |
|
{ |
1803 |
|
if (dec->mbs[(j-1)*dec->mb_width + i].mode != MODE_NOT_CODED || |
1804 |
|
dec->mbs[(j+0)*dec->mb_width + i].mode != MODE_NOT_CODED) |
1805 |
|
{ |
1806 |
|
hfilter_31(dec->cur.u + (j*16 - 1)*edged_width2 + i*16, |
1807 |
|
dec->cur.u + (j*16 + 0)*edged_width2 + i*16, 2); |
1808 |
|
hfilter_31(dec->cur.v + (j*16 - 1)*edged_width2 + i*16, |
1809 |
|
dec->cur.v + (j*16 + 0)*edged_width2 + i*16, 2); |
1810 |
|
} |
1811 |
|
} |
1812 |
|
|
1813 |
|
/* vertical deblocking */ |
1814 |
|
|
1815 |
|
for (j = 0; j < rmb_height*2; j++) // luma: i,j in block units |
1816 |
|
for (i = 1; i < rmb_width*2; i++) |
1817 |
|
{ |
1818 |
|
if (dec->mbs[(j/2)*dec->mb_width + (i-1)/2].mode != MODE_NOT_CODED || |
1819 |
|
dec->mbs[(j/2)*dec->mb_width + (i+0)/2].mode != MODE_NOT_CODED) |
1820 |
|
{ |
1821 |
|
vfilter_31(dec->cur.y + (j*16)*dec->edged_width + i*16 - 1, |
1822 |
|
dec->cur.y + (j*16)*dec->edged_width + i*16 + 0, |
1823 |
|
dec->edged_width, 2); |
1824 |
|
} |
1825 |
|
} |
1826 |
|
|
1827 |
|
for (j = 0; j < rmb_height; j++) // chroma |
1828 |
|
for (i = 1; i < rmb_width; i++) |
1829 |
|
{ |
1830 |
|
if (dec->mbs[j*dec->mb_width + i - 1].mode != MODE_NOT_CODED || |
1831 |
|
dec->mbs[j*dec->mb_width + i + 0].mode != MODE_NOT_CODED) |
1832 |
|
{ |
1833 |
|
vfilter_31(dec->cur.u + (j*16)*edged_width2 + i*16 - 1, |
1834 |
|
dec->cur.u + (j*16)*edged_width2 + i*16 + 0, |
1835 |
|
edged_width2, 2); |
1836 |
|
vfilter_31(dec->cur.v + (j*16)*edged_width2 + i*16 - 1, |
1837 |
|
dec->cur.v + (j*16)*edged_width2 + i*16 + 0, |
1838 |
|
edged_width2, 2); |
1839 |
|
} |
1840 |
|
} |
1841 |
|
} |
1842 |
|
|
1843 |
BitstreamByteAlign(&bs); |
BitstreamByteAlign(&bs); |
1844 |
|
|
1845 |
#ifdef BFRAMES_DEC |
#ifdef BFRAMES_DEC |
1883 |
mb_swap(&dec->mbs, &dec->last_mbs); |
mb_swap(&dec->mbs, &dec->last_mbs); |
1884 |
} |
} |
1885 |
|
|
|
success = 1; |
|
1886 |
|
|
1887 |
if (frame->length > BitstreamPos(&bs) / 8) // multiple vops packed together |
if (success == 0 && dec->packed_mode) |
1888 |
|
{ |
1889 |
|
success = 1; |
1890 |
|
// if (frame->length > BitstreamPos(&bs) / 8) // multiple vops packed together |
1891 |
goto start; |
goto start; |
1892 |
|
} |
1893 |
|
|
1894 |
done : |
done : |
1895 |
|
|