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.19 2002-12-12 10:37:44 suxen_drol Exp $ |
* $Id: decoder.c,v 1.37.2.27 2003-01-11 14:59:23 chl Exp $ |
59 |
* |
* |
60 |
*************************************************************************/ |
*************************************************************************/ |
61 |
|
|
62 |
|
#include <stdio.h> |
63 |
#include <stdlib.h> |
#include <stdlib.h> |
64 |
#include <string.h> |
#include <string.h> |
65 |
|
|
69 |
|
|
70 |
#include "xvid.h" |
#include "xvid.h" |
71 |
#include "portab.h" |
#include "portab.h" |
72 |
|
#include "global.h" |
73 |
|
|
74 |
#include "decoder.h" |
#include "decoder.h" |
75 |
#include "bitstream/bitstream.h" |
#include "bitstream/bitstream.h" |
99 |
{ |
{ |
100 |
/* free existing */ |
/* free existing */ |
101 |
|
|
102 |
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
103 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
104 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
105 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
106 |
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); |
107 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
|
108 |
|
image_destroy(&dec->gmc, dec->edged_width, dec->edged_height); |
109 |
|
|
110 |
if (dec->last_mbs) |
if (dec->last_mbs) |
111 |
xvid_free(dec->last_mbs); |
xvid_free(dec->last_mbs); |
139 |
xvid_free(dec); |
xvid_free(dec); |
140 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
141 |
} |
} |
142 |
if (image_create(&dec->refn[2], dec->edged_width, dec->edged_height)) { |
if (image_create(&dec->tmp, dec->edged_width, dec->edged_height)) { |
143 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
144 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
145 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
147 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
148 |
} |
} |
149 |
|
|
150 |
if (image_create(&dec->refh, dec->edged_width, dec->edged_height)) { |
if (image_create(&dec->qtmp, dec->edged_width, dec->edged_height)) { |
151 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
152 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
153 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
154 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
155 |
|
xvid_free(dec); |
156 |
|
return XVID_ERR_MEMORY; |
157 |
|
} |
158 |
|
|
159 |
|
if (image_create(&dec->gmc, dec->edged_width, dec->edged_height)) { |
160 |
|
image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); |
161 |
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
162 |
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
163 |
|
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
164 |
|
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
165 |
xvid_free(dec); |
xvid_free(dec); |
166 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
167 |
} |
} |
173 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
174 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
175 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
176 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
177 |
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); |
178 |
xvid_free(dec); |
xvid_free(dec); |
179 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
180 |
} |
} |
190 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
191 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
192 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
193 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
194 |
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); |
195 |
xvid_free(dec); |
xvid_free(dec); |
196 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
197 |
} |
} |
221 |
image_null(&dec->cur); |
image_null(&dec->cur); |
222 |
image_null(&dec->refn[0]); |
image_null(&dec->refn[0]); |
223 |
image_null(&dec->refn[1]); |
image_null(&dec->refn[1]); |
224 |
image_null(&dec->refn[2]); |
image_null(&dec->tmp); |
225 |
image_null(&dec->refh); |
image_null(&dec->qtmp); |
226 |
|
|
227 |
|
/* image based GMC */ |
228 |
|
image_null(&dec->gmc); |
229 |
|
|
230 |
|
|
231 |
dec->mbs = NULL; |
dec->mbs = NULL; |
232 |
dec->last_mbs = NULL; |
dec->last_mbs = NULL; |
254 |
{ |
{ |
255 |
xvid_free(dec->last_mbs); |
xvid_free(dec->last_mbs); |
256 |
xvid_free(dec->mbs); |
xvid_free(dec->mbs); |
257 |
|
|
258 |
|
image_destroy(&dec->gmc, dec->edged_width, dec->edged_height); /* image based GMC */ |
259 |
|
|
260 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
261 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
262 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
263 |
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); |
264 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
265 |
xvid_free(dec); |
xvid_free(dec); |
266 |
|
|
405 |
|
|
406 |
|
|
407 |
|
|
|
|
|
|
#define SIGN(X) (((X)>0)?1:-1) |
|
|
#define ABS(X) (((X)>0)?(X):-(X)) |
|
|
|
|
408 |
// decode an inter macroblock |
// decode an inter macroblock |
409 |
|
|
410 |
void |
void |
417 |
Bitstream * bs, |
Bitstream * bs, |
418 |
const uint32_t quant, |
const uint32_t quant, |
419 |
const uint32_t rounding, |
const uint32_t rounding, |
420 |
const int reduced_resolution) |
const int reduced_resolution, |
421 |
|
const int mcsel) |
422 |
{ |
{ |
423 |
|
|
424 |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
430 |
uint32_t i; |
uint32_t i; |
431 |
uint32_t iQuant = pMB->quant; |
uint32_t iQuant = pMB->quant; |
432 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
433 |
|
uint8_t *pY_Ref, *pU_Ref, *pV_Ref; /* ref for GMC is _not_ pRef itself */ |
434 |
|
|
435 |
int uv_dx, uv_dy; |
int uv_dx, uv_dy; |
436 |
VECTOR mv[4]; /* local copy of mvs */ |
VECTOR mv[4]; /* local copy of mvs */ |
451 |
mv[i] = pMB->mvs[i]; |
mv[i] = pMB->mvs[i]; |
452 |
} |
} |
453 |
|
|
454 |
|
if (mcsel) { |
455 |
|
mv[0].x = mv[0].y = mv[1].x = mv[1].y = mv[2].x = mv[2].y = mv[3].x = mv[3].y = 0; |
456 |
|
/* position in ref is same as the block, set vector to (0,0) */ |
457 |
|
pY_Ref = dec->gmc.y; |
458 |
|
pU_Ref = dec->gmc.u; |
459 |
|
pV_Ref = dec->gmc.v; |
460 |
|
/* but reference itself isn't. It's warped... */ |
461 |
|
/* Btw., this is too slow! For GMC it should simply be transfer_16to8add() */ |
462 |
|
} else { |
463 |
|
pY_Ref = dec->refn[0].y; |
464 |
|
pU_Ref = dec->refn[0].u; |
465 |
|
pV_Ref = dec->refn[0].v; |
466 |
|
} |
467 |
|
|
468 |
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) { |
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) { |
|
uv_dx = mv[0].x; |
|
|
uv_dy = mv[0].y; |
|
469 |
|
|
470 |
if (dec->quarterpel) |
uv_dx = mv[0].x / (1 + dec->quarterpel); |
471 |
{ |
uv_dy = mv[0].y / (1 + dec->quarterpel); |
|
uv_dx /= 2; |
|
|
uv_dy /= 2; |
|
|
} |
|
472 |
|
|
473 |
uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; |
uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; |
474 |
uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; |
uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; |
476 |
start_timer(); |
start_timer(); |
477 |
if (reduced_resolution) |
if (reduced_resolution) |
478 |
{ |
{ |
479 |
interpolate32x32_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos, |
interpolate32x32_switch(dec->cur.y, pY_Ref , 32*x_pos, 32*y_pos, |
480 |
mv[0].x, mv[0].y, stride, rounding); |
mv[0].x, mv[0].y, stride, rounding); |
481 |
interpolate16x16_switch(dec->cur.u, dec->refn[0].u, 16 * x_pos, 16 * y_pos, |
interpolate16x16_switch(dec->cur.u, pU_Ref , 16 * x_pos, 16 * y_pos, |
482 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
483 |
interpolate16x16_switch(dec->cur.v, dec->refn[0].v, 16 * x_pos, 16 * y_pos, |
interpolate16x16_switch(dec->cur.v, pV_Ref , 16 * x_pos, 16 * y_pos, |
484 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
485 |
|
|
486 |
} |
} |
487 |
else |
else |
488 |
{ |
{ |
489 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
490 |
interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
interpolate16x16_quarterpel(dec->cur.y, pY_Ref , dec->qtmp.y, dec->qtmp.y + 64, |
491 |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
492 |
mv[0].x, mv[0].y, stride, rounding); |
mv[0].x, mv[0].y, stride, rounding); |
493 |
} |
} |
494 |
else { |
else { |
495 |
interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos, |
interpolate16x16_switch(dec->cur.y, pY_Ref , 16*x_pos, 16*y_pos, |
496 |
mv[0].x, mv[0].y, stride, rounding); |
mv[0].x, mv[0].y, stride, rounding); |
497 |
} |
} |
498 |
|
|
499 |
interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos, |
interpolate8x8_switch(dec->cur.u, pU_Ref , 8 * x_pos, 8 * y_pos, |
500 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
501 |
interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos, |
interpolate8x8_switch(dec->cur.v, pV_Ref , 8 * x_pos, 8 * y_pos, |
502 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
503 |
} |
} |
504 |
stop_comp_timer(); |
stop_comp_timer(); |
523 |
start_timer(); |
start_timer(); |
524 |
if (reduced_resolution) |
if (reduced_resolution) |
525 |
{ |
{ |
526 |
interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos, |
interpolate16x16_switch(dec->cur.y, pY_Ref , 32*x_pos, 32*y_pos, |
527 |
mv[0].x, mv[0].y, stride, rounding); |
mv[0].x, mv[0].y, stride, rounding); |
528 |
interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos + 16, 32*y_pos, |
interpolate16x16_switch(dec->cur.y, pY_Ref , 32*x_pos + 16, 32*y_pos, |
529 |
mv[1].x, mv[1].y, stride, rounding); |
mv[1].x, mv[1].y, stride, rounding); |
530 |
interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos + 16, |
interpolate16x16_switch(dec->cur.y, pY_Ref , 32*x_pos, 32*y_pos + 16, |
531 |
mv[2].x, mv[2].y, stride, rounding); |
mv[2].x, mv[2].y, stride, rounding); |
532 |
interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos + 16, 32*y_pos + 16, |
interpolate16x16_switch(dec->cur.y, pY_Ref , 32*x_pos + 16, 32*y_pos + 16, |
533 |
mv[3].x, mv[3].y, stride, rounding); |
mv[3].x, mv[3].y, stride, rounding); |
534 |
interpolate16x16_switch(dec->cur.u, dec->refn[0].u, 16 * x_pos, 16 * y_pos, |
interpolate16x16_switch(dec->cur.u, pU_Ref , 16 * x_pos, 16 * y_pos, |
535 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
536 |
interpolate16x16_switch(dec->cur.v, dec->refn[0].v, 16 * x_pos, 16 * y_pos, |
interpolate16x16_switch(dec->cur.v, pV_Ref , 16 * x_pos, 16 * y_pos, |
537 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
538 |
|
|
539 |
// set_block(pY_Cur, stride, 32, 32, 127); |
// set_block(pY_Cur, stride, 32, 32, 127); |
541 |
else |
else |
542 |
{ |
{ |
543 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
544 |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, pY_Ref , dec->qtmp.y, dec->qtmp.y + 64, |
545 |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
546 |
mv[0].x, mv[0].y, stride, rounding); |
mv[0].x, mv[0].y, stride, rounding); |
547 |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, pY_Ref , dec->qtmp.y, dec->qtmp.y + 64, |
548 |
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos, |
549 |
mv[1].x, mv[1].y, stride, rounding); |
mv[1].x, mv[1].y, stride, rounding); |
550 |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, pY_Ref , dec->qtmp.y, dec->qtmp.y + 64, |
551 |
dec->refh.y + 128, 16*x_pos, 16*y_pos + 8, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8, |
552 |
mv[2].x, mv[2].y, stride, rounding); |
mv[2].x, mv[2].y, stride, rounding); |
553 |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, pY_Ref , dec->qtmp.y, dec->qtmp.y + 64, |
554 |
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
555 |
mv[3].x, mv[3].y, stride, rounding); |
mv[3].x, mv[3].y, stride, rounding); |
556 |
} |
} |
557 |
else { |
else { |
558 |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos, |
interpolate8x8_switch(dec->cur.y, pY_Ref , 16*x_pos, 16*y_pos, |
559 |
mv[0].x, mv[0].y, stride, rounding); |
mv[0].x, mv[0].y, stride, rounding); |
560 |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos, |
interpolate8x8_switch(dec->cur.y, pY_Ref , 16*x_pos + 8, 16*y_pos, |
561 |
mv[1].x, mv[1].y, stride, rounding); |
mv[1].x, mv[1].y, stride, rounding); |
562 |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8, |
interpolate8x8_switch(dec->cur.y, pY_Ref , 16*x_pos, 16*y_pos + 8, |
563 |
mv[2].x, mv[2].y, stride, rounding); |
mv[2].x, mv[2].y, stride, rounding); |
564 |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8, |
interpolate8x8_switch(dec->cur.y, pY_Ref , 16*x_pos + 8, 16*y_pos + 8, |
565 |
mv[3].x, mv[3].y, stride, rounding); |
mv[3].x, mv[3].y, stride, rounding); |
566 |
} |
} |
567 |
|
|
568 |
interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos, |
interpolate8x8_switch(dec->cur.u, pU_Ref , 8 * x_pos, 8 * y_pos, |
569 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
570 |
interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos, |
interpolate8x8_switch(dec->cur.v, pV_Ref , 8 * x_pos, 8 * y_pos, |
571 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
572 |
} |
} |
573 |
stop_comp_timer(); |
stop_comp_timer(); |
647 |
{ |
{ |
648 |
uint32_t bound; |
uint32_t bound; |
649 |
uint32_t x, y; |
uint32_t x, y; |
650 |
int mb_width = dec->mb_width; |
uint32_t mb_width = dec->mb_width; |
651 |
int mb_height = dec->mb_height; |
uint32_t mb_height = dec->mb_height; |
652 |
|
|
653 |
if (reduced_resolution) |
if (reduced_resolution) |
654 |
{ |
{ |
706 |
|
|
707 |
if (dec->interlacing) { |
if (dec->interlacing) { |
708 |
mb->field_dct = BitstreamGetBit(bs); |
mb->field_dct = BitstreamGetBit(bs); |
709 |
DEBUG1("deci: field_dct: ", mb->field_dct); |
DPRINTF(DPRINTF_MB,"deci: field_dct: %i", mb->field_dct); |
710 |
} |
} |
711 |
|
|
712 |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
744 |
mv.x = get_mv(bs, fcode); |
mv.x = get_mv(bs, fcode); |
745 |
mv.y = get_mv(bs, fcode); |
mv.y = get_mv(bs, fcode); |
746 |
|
|
747 |
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) result (%i,%i)", mv.x, mv.y, pmv.x, pmv.y, mv.x+pmv.x, mv.y+pmv.y); |
748 |
|
|
749 |
mv.x += pmv.x; |
mv.x += pmv.x; |
750 |
mv.y += pmv.y; |
mv.y += pmv.y; |
781 |
} |
} |
782 |
|
|
783 |
|
|
784 |
/* for P_VOP set gmc_mv to NULL */ |
/* for P_VOP set gmc_warp to NULL */ |
785 |
void |
void |
786 |
decoder_pframe(DECODER * dec, |
decoder_pframe(DECODER * dec, |
787 |
Bitstream * bs, |
Bitstream * bs, |
790 |
int quant, |
int quant, |
791 |
int fcode, |
int fcode, |
792 |
int intra_dc_threshold, |
int intra_dc_threshold, |
793 |
VECTOR * gmc_mv) |
const WARPPOINTS *const gmc_warp) |
794 |
{ |
{ |
795 |
|
|
796 |
uint32_t x, y; |
uint32_t x, y; |
797 |
uint32_t bound; |
uint32_t bound; |
798 |
int cp_mb, st_mb; |
int cp_mb, st_mb; |
799 |
int mb_width = dec->mb_width; |
uint32_t mb_width = dec->mb_width; |
800 |
int mb_height = dec->mb_height; |
uint32_t mb_height = dec->mb_height; |
801 |
|
|
802 |
|
static int framecount=0; |
803 |
if (reduced_resolution) |
if (reduced_resolution) |
804 |
{ |
{ |
805 |
mb_width = (dec->width + 31) / 32; |
mb_width = (dec->width + 31) / 32; |
811 |
dec->width, dec->height); |
dec->width, dec->height); |
812 |
stop_edges_timer(); |
stop_edges_timer(); |
813 |
|
|
814 |
|
if (gmc_warp) |
815 |
|
{ |
816 |
|
char filename[80]; |
817 |
|
sprintf(filename,"dGMC%05d.pgm",framecount); |
818 |
|
// accuracy: 0==1/2, 1=1/4, 2=1/8, 3=1/16 |
819 |
|
if ( (dec->sprite_warping_accuracy != 3) || (dec->sprite_warping_points != 2) ) |
820 |
|
{ |
821 |
|
fprintf(stderr,"Wrong GMC parameters acc=%d(-> 1/%d), %d!!!\n", |
822 |
|
dec->sprite_warping_accuracy,(2<<dec->sprite_warping_accuracy), |
823 |
|
dec->sprite_warping_points); |
824 |
|
} |
825 |
|
|
826 |
|
generate_GMCparameters( dec->sprite_warping_points, |
827 |
|
(2 << dec->sprite_warping_accuracy), gmc_warp, |
828 |
|
dec->width, dec->height, &dec->gmc_data); |
829 |
|
|
830 |
|
generate_GMCimage(&dec->gmc_data, &dec->refn[0], |
831 |
|
mb_width, mb_height, |
832 |
|
dec->edged_width, dec->edged_width/2, |
833 |
|
fcode, 0, 0, |
834 |
|
rounding, dec->mbs, &dec->gmc); |
835 |
|
|
836 |
|
/* |
837 |
|
sprintf(filename,"dGMC%05d.pgm",framecount); |
838 |
|
image_dump_yuvpgm(&dec->gmc, |
839 |
|
dec->edged_width, dec->width, dec->height, filename); |
840 |
|
|
841 |
|
sprintf(filename,"dREF%05d.pgm",framecount); |
842 |
|
image_dump_yuvpgm(&dec->refn[0], |
843 |
|
dec->edged_width, dec->width, dec->height, filename); |
844 |
|
sprintf(filename,"dCUR%05d.pgm",framecount); |
845 |
|
image_dump_yuvpgm(&dec->cur, |
846 |
|
dec->edged_width, dec->width, dec->height, filename); |
847 |
|
framecount++; |
848 |
|
*/ |
849 |
|
} |
850 |
|
|
851 |
bound = 0; |
bound = 0; |
852 |
|
|
853 |
for (y = 0; y < mb_height; y++) { |
for (y = 0; y < mb_height; y++) { |
871 |
DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32)); |
DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32)); |
872 |
|
|
873 |
//if (!(dec->mb_skip[y*dec->mb_width + x]=BitstreamGetBit(bs))) // not_coded |
//if (!(dec->mb_skip[y*dec->mb_width + x]=BitstreamGetBit(bs))) // not_coded |
874 |
if (!(BitstreamGetBit(bs))) // not_coded |
if (!(BitstreamGetBit(bs))) // block _is_ coded |
875 |
{ |
{ |
876 |
uint32_t mcbpc; |
uint32_t mcbpc; |
877 |
uint32_t cbpc; |
uint32_t cbpc; |
896 |
acpred_flag = BitstreamGetBit(bs); |
acpred_flag = BitstreamGetBit(bs); |
897 |
} |
} |
898 |
|
|
899 |
if (gmc_mv && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)) |
if (gmc_warp && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)) |
900 |
{ |
{ |
901 |
mcsel = BitstreamGetBit(bs); |
mcsel = BitstreamGetBit(bs); |
902 |
} |
} |
903 |
|
|
904 |
cbpy = get_cbpy(bs, intra); |
cbpy = get_cbpy(bs, intra); |
905 |
DPRINTF(DPRINTF_MB, "cbpy %i", cbpy); |
DPRINTF(DPRINTF_MB, "cbpy %i mcsel %i ", cbpy,mcsel); |
906 |
|
|
907 |
cbp = (cbpy << 2) | cbpc; |
cbp = (cbpy << 2) | cbpc; |
908 |
|
|
922 |
if (dec->interlacing) { |
if (dec->interlacing) { |
923 |
if (cbp || intra) { |
if (cbp || intra) { |
924 |
mb->field_dct = BitstreamGetBit(bs); |
mb->field_dct = BitstreamGetBit(bs); |
925 |
DEBUG1("decp: field_dct: ", mb->field_dct); |
DPRINTF(DPRINTF_MB,"decp: field_dct: %i", mb->field_dct); |
926 |
} |
} |
927 |
|
|
928 |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
929 |
mb->field_pred = BitstreamGetBit(bs); |
mb->field_pred = BitstreamGetBit(bs); |
930 |
DEBUG1("decp: field_pred: ", mb->field_pred); |
DPRINTF(DPRINTF_MB, "decp: field_pred: %i", mb->field_pred); |
931 |
|
|
932 |
if (mb->field_pred) { |
if (mb->field_pred) { |
933 |
mb->field_for_top = BitstreamGetBit(bs); |
mb->field_for_top = BitstreamGetBit(bs); |
934 |
DEBUG1("decp: field_for_top: ", mb->field_for_top); |
DPRINTF(DPRINTF_MB,"decp: field_for_top: %i", mb->field_for_top); |
935 |
mb->field_for_bot = BitstreamGetBit(bs); |
mb->field_for_bot = BitstreamGetBit(bs); |
936 |
DEBUG1("decp: field_for_bot: ", mb->field_for_bot); |
DPRINTF(DPRINTF_MB,"decp: field_for_bot: %i", mb->field_for_bot); |
937 |
} |
} |
938 |
} |
} |
939 |
} |
} |
942 |
|
|
943 |
if (mcsel) |
if (mcsel) |
944 |
{ |
{ |
945 |
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] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->amv; |
946 |
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); |
/* already clipped to fcode */ |
947 |
|
|
948 |
} else if (dec->interlacing && mb->field_pred) { |
} else if (dec->interlacing && mb->field_pred) { |
949 |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], |
953 |
} else { |
} else { |
954 |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], |
955 |
fcode, bound); |
fcode, bound); |
956 |
mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = |
mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; |
|
mb->mvs[0].x; |
|
|
mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = |
|
|
mb->mvs[0].y; |
|
957 |
} |
} |
958 |
} else if (mb->mode == MODE_INTER4V ) { |
} else if (mb->mode == MODE_INTER4V ) { |
959 |
|
|
973 |
} |
} |
974 |
|
|
975 |
decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
976 |
rounding, reduced_resolution); |
rounding, reduced_resolution, mcsel); |
977 |
|
|
978 |
} |
} |
979 |
else if (gmc_mv) /* not coded S_VOP macroblock */ |
else if (gmc_warp) /* a not coded S(GMC)-VOP macroblock */ |
980 |
{ |
{ |
981 |
mb->mode = MODE_NOT_CODED; |
mb->mode = MODE_NOT_CODED_GMC; |
982 |
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] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->amv; |
983 |
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); |
|
984 |
decoder_mbinter(dec, mb, x, y, 0, 0, bs, quant, rounding, reduced_resolution); |
start_timer(); |
985 |
|
|
986 |
|
transfer16x16_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x), |
987 |
|
dec->gmc.y + (16*y)*dec->edged_width + (16*x), |
988 |
|
dec->edged_width); |
989 |
|
|
990 |
|
transfer8x8_copy(dec->cur.u + (8*y)*dec->edged_width/2 + (8*x), |
991 |
|
dec->gmc.u + (8*y)*dec->edged_width/2 + (8*x), |
992 |
|
dec->edged_width/2); |
993 |
|
|
994 |
|
transfer8x8_copy(dec->cur.v + (8*y)*dec->edged_width/2 + (8*x), |
995 |
|
dec->gmc.v + (8*y)*dec->edged_width/2 + (8*x), |
996 |
|
dec->edged_width/2); |
997 |
|
|
998 |
|
stop_transfer_timer(); |
999 |
|
|
1000 |
|
if(dec->out_frm && cp_mb > 0) { |
1001 |
|
output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb); |
1002 |
|
cp_mb = 0; |
1003 |
|
} |
1004 |
|
st_mb = x+1; |
1005 |
} |
} |
1006 |
else /* not coded P_VOP macroblock */ |
else /* not coded P_VOP macroblock */ |
1007 |
{ |
{ |
1163 |
|
|
1164 |
start_timer(); |
start_timer(); |
1165 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
1166 |
interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->refh.y, dec->refh.y + 64, |
interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->qtmp.y, dec->qtmp.y + 64, |
1167 |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1168 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1169 |
} |
} |
1170 |
else { |
else { |
1318 |
start_timer(); |
start_timer(); |
1319 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
1320 |
if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) |
if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) |
1321 |
interpolate16x16_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64, |
interpolate16x16_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1322 |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1323 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1324 |
else { |
else { |
1325 |
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1326 |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1327 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1328 |
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1329 |
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos, |
1330 |
pMB->mvs[1].x, pMB->mvs[1].y, stride, 0); |
pMB->mvs[1].x, pMB->mvs[1].y, stride, 0); |
1331 |
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1332 |
dec->refh.y + 128, 16*x_pos, 16*y_pos + 8, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8, |
1333 |
pMB->mvs[2].x, pMB->mvs[2].y, stride, 0); |
pMB->mvs[2].x, pMB->mvs[2].y, stride, 0); |
1334 |
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1335 |
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
1336 |
pMB->mvs[3].x, pMB->mvs[3].y, stride, 0); |
pMB->mvs[3].x, pMB->mvs[3].y, stride, 0); |
1337 |
} |
} |
1338 |
} |
} |
1356 |
|
|
1357 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
1358 |
if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) |
if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) |
1359 |
interpolate16x16_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64, |
interpolate16x16_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1360 |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1361 |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
1362 |
else { |
else { |
1363 |
interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1364 |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1365 |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
1366 |
interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1367 |
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos, |
1368 |
pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0); |
pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0); |
1369 |
interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1370 |
dec->refh.y + 128, 16*x_pos, 16*y_pos + 8, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8, |
1371 |
pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0); |
pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0); |
1372 |
interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1373 |
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
1374 |
pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0); |
pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0); |
1375 |
} |
} |
1376 |
} |
} |
1377 |
else { |
else { |
1378 |
interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos, 16 * y_pos, |
interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos, 16 * y_pos, |
1379 |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
1380 |
interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8, |
interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8, |
1381 |
16 * y_pos, pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, |
16 * y_pos, pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, |
1382 |
0); |
0); |
1383 |
interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos, |
interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos, |
1384 |
16 * y_pos + 8, pMB->b_mvs[2].x, pMB->b_mvs[2].y, |
16 * y_pos + 8, pMB->b_mvs[2].x, pMB->b_mvs[2].y, |
1385 |
stride, 0); |
stride, 0); |
1386 |
interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8, |
interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8, |
1387 |
16 * y_pos + 8, pMB->b_mvs[3].x, pMB->b_mvs[3].y, |
16 * y_pos + 8, pMB->b_mvs[3].x, pMB->b_mvs[3].y, |
1388 |
stride, 0); |
stride, 0); |
1389 |
} |
} |
1390 |
|
|
1391 |
interpolate8x8_switch(dec->refn[2].u, backward.u, 8 * x_pos, 8 * y_pos, |
interpolate8x8_switch(dec->tmp.u, backward.u, 8 * x_pos, 8 * y_pos, |
1392 |
b_uv_dx, b_uv_dy, stride2, 0); |
b_uv_dx, b_uv_dy, stride2, 0); |
1393 |
interpolate8x8_switch(dec->refn[2].v, backward.v, 8 * x_pos, 8 * y_pos, |
interpolate8x8_switch(dec->tmp.v, backward.v, 8 * x_pos, 8 * y_pos, |
1394 |
b_uv_dx, b_uv_dy, stride2, 0); |
b_uv_dx, b_uv_dy, stride2, 0); |
1395 |
|
|
1396 |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
1397 |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
1398 |
dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos, |
dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos, |
1399 |
stride, 1, 8); |
stride, 1, 8); |
1400 |
|
|
1401 |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1402 |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1403 |
dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos + 8, |
dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1404 |
stride, 1, 8); |
stride, 1, 8); |
1405 |
|
|
1406 |
interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
1407 |
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
1408 |
dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
1409 |
stride, 1, 8); |
stride, 1, 8); |
1410 |
|
|
1411 |
interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
1412 |
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
1413 |
dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
1414 |
stride, 1, 8); |
stride, 1, 8); |
1415 |
|
|
1416 |
interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
1417 |
dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
1418 |
dec->refn[2].u + (8 * y_pos * stride2) + 8 * x_pos, |
dec->tmp.u + (8 * y_pos * stride2) + 8 * x_pos, |
1419 |
stride2, 1, 8); |
stride2, 1, 8); |
1420 |
|
|
1421 |
interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
1422 |
dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
1423 |
dec->refn[2].v + (8 * y_pos * stride2) + 8 * x_pos, |
dec->tmp.v + (8 * y_pos * stride2) + 8 * x_pos, |
1424 |
stride2, 1, 8); |
stride2, 1, 8); |
1425 |
|
|
1426 |
stop_comp_timer(); |
stop_comp_timer(); |
1550 |
mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = |
mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = |
1551 |
mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = zeromv; |
mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = zeromv; |
1552 |
|
|
1553 |
// the last P_VOP is skip macroblock ? |
// skip if the co-located P_VOP macroblock is not coded |
1554 |
|
// note: gmc+not_coded isn't skipped |
1555 |
|
|
1556 |
if (last_mb->mode == MODE_NOT_CODED) { |
if (last_mb->mode == MODE_NOT_CODED) { |
1557 |
//DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); |
//DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); |
1558 |
mb->cbp = 0; |
mb->cbp = 0; |
1666 |
break; |
break; |
1667 |
|
|
1668 |
default: |
default: |
1669 |
DEBUG1("Not support B-frame mb_type =", mb->mb_type); |
DPRINTF(DPRINTF_ERROR,"Not support B-frame mb_type = %i", mb->mb_type); |
1670 |
} |
} |
1671 |
|
|
1672 |
} // end of FOR |
} // end of FOR |
1692 |
} |
} |
1693 |
|
|
1694 |
|
|
1695 |
|
/* perform post processing if necessary, and output the image */ |
1696 |
|
void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs, |
1697 |
|
const XVID_DEC_FRAME * frame, int pp_disable) |
1698 |
|
{ |
1699 |
|
|
1700 |
|
if ((frame->general & (XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV)) && !pp_disable) /* post process */ |
1701 |
|
{ |
1702 |
|
/* note: image is stored to tmp */ |
1703 |
|
image_copy(&dec->tmp, img, dec->edged_width, dec->height); |
1704 |
|
image_deblock_rrv(&dec->tmp, dec->edged_width, |
1705 |
|
mbs, dec->mb_width, dec->mb_height, dec->mb_width, |
1706 |
|
8, frame->general); |
1707 |
|
img = &dec->tmp; |
1708 |
|
} |
1709 |
|
|
1710 |
|
image_output(img, dec->width, dec->height, |
1711 |
|
dec->edged_width, frame->image, frame->stride, |
1712 |
|
frame->colorspace, dec->interlacing); |
1713 |
|
} |
1714 |
|
|
1715 |
|
|
1716 |
int |
int |
1717 |
decoder_decode(DECODER * dec, |
decoder_decode(DECODER * dec, |
1718 |
XVID_DEC_FRAME * frame, XVID_DEC_STATS * stats) |
XVID_DEC_FRAME * frame, XVID_DEC_STATS * stats) |
1725 |
uint32_t fcode_forward; |
uint32_t fcode_forward; |
1726 |
uint32_t fcode_backward; |
uint32_t fcode_backward; |
1727 |
uint32_t intra_dc_threshold; |
uint32_t intra_dc_threshold; |
1728 |
VECTOR gmc_mv[5]; |
WARPPOINTS gmc_warp; |
1729 |
uint32_t vop_type; |
uint32_t vop_type; |
1730 |
int success = 0; |
int success = 0; |
1731 |
int output = 0; |
int output = 0; |
1734 |
start_global_timer(); |
start_global_timer(); |
1735 |
|
|
1736 |
dec->low_delay_default = (frame->general & XVID_DEC_LOWDELAY); |
dec->low_delay_default = (frame->general & XVID_DEC_LOWDELAY); |
|
|
|
1737 |
dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL; |
dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL; |
1738 |
|
|
1739 |
|
if ((frame->general & XVID_DEC_DISCONTINUITY)) |
1740 |
|
dec->frames = 0; |
1741 |
|
|
1742 |
|
if (frame->length < 0) /* decoder flush */ |
1743 |
|
{ |
1744 |
|
/* if not decoding "low_delay/packed", and this isn't low_delay and |
1745 |
|
we have a reference frame, then outout the reference frame */ |
1746 |
|
if (!(dec->low_delay_default && dec->packed_mode) && !dec->low_delay && dec->frames>0) |
1747 |
|
{ |
1748 |
|
decoder_output(dec, &dec->refn[0], dec->mbs, frame, dec->last_reduced_resolution); |
1749 |
|
output = 1; |
1750 |
|
} |
1751 |
|
|
1752 |
|
frame->length = 0; |
1753 |
|
if (stats) |
1754 |
|
{ |
1755 |
|
stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING; |
1756 |
|
stats->data.vop.time_base = (int)dec->time_base; |
1757 |
|
stats->data.vop.time_increment = 0; //XXX: todo |
1758 |
|
} |
1759 |
|
|
1760 |
|
emms(); |
1761 |
|
|
1762 |
|
stop_global_timer(); |
1763 |
|
return XVID_ERR_OK; |
1764 |
|
} |
1765 |
|
|
1766 |
BitstreamInit(&bs, frame->bitstream, frame->length); |
BitstreamInit(&bs, frame->bitstream, frame->length); |
1767 |
|
|
1768 |
// XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's |
// XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's |
1769 |
if(frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f) |
if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f) |
1770 |
{ |
{ |
1771 |
if (stats) |
if (stats) |
1772 |
stats->notify = XVID_DEC_VOP; |
stats->notify = XVID_DEC_VOP; |
1777 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
1778 |
} |
} |
1779 |
|
|
1780 |
start: |
repeat: |
|
// add by chenm001 <chenm001@163.com> |
|
|
// for support B-frame to reference last 2 frame |
|
1781 |
|
|
1782 |
xxx: |
vop_type = BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution, |
1783 |
vop_type = |
&quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp); |
|
BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution, |
|
|
&quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, gmc_mv); |
|
1784 |
|
|
1785 |
DPRINTF(DPRINTF_HEADER, "vop_type=%i, packed=%i, time=%i, time_pp=%i, time_bp=%i", |
DPRINTF(DPRINTF_HEADER, "vop_type=%i, packed=%i, time=%lli, time_pp=%i, time_bp=%i", |
1786 |
vop_type, dec->packed_mode, dec->time, dec->time_pp, dec->time_bp); |
vop_type, dec->packed_mode, dec->time, dec->time_pp, dec->time_bp); |
1787 |
|
|
1788 |
if (vop_type == - 1) |
if (vop_type == - 1) |
1789 |
{ |
{ |
1790 |
if (success) goto done; |
if (success) goto done; |
1791 |
|
emms(); |
1792 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
1793 |
} |
} |
1794 |
|
|
1809 |
stats->data.vol.par_width = dec->par_width; |
stats->data.vol.par_width = dec->par_width; |
1810 |
stats->data.vol.par_height = dec->par_height; |
stats->data.vol.par_height = dec->par_height; |
1811 |
frame->length = BitstreamPos(&bs) / 8; |
frame->length = BitstreamPos(&bs) / 8; |
1812 |
|
emms(); |
1813 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
1814 |
} |
} |
1815 |
goto xxx; |
goto repeat; |
1816 |
} |
} |
1817 |
|
|
1818 |
dec->p_bmv.x = dec->p_bmv.y = dec->p_fmv.y = dec->p_fmv.y = 0; // init pred vector to 0 |
dec->p_bmv.x = dec->p_bmv.y = dec->p_fmv.y = dec->p_fmv.y = 0; // init pred vector to 0 |
1821 |
/* packed_mode: special-N_VOP treament */ |
/* packed_mode: special-N_VOP treament */ |
1822 |
if (dec->packed_mode && vop_type == N_VOP) |
if (dec->packed_mode && vop_type == N_VOP) |
1823 |
{ |
{ |
1824 |
if (dec->low_delay_default) |
if (dec->low_delay_default && dec->frames > 0) |
1825 |
{ |
{ |
1826 |
image_output(&dec->refn[0], dec->width, dec->height, |
decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, dec->last_reduced_resolution); |
|
dec->edged_width, frame->image, frame->stride, |
|
|
frame->colorspace, dec->interlacing); |
|
1827 |
output = 1; |
output = 1; |
1828 |
} |
} |
1829 |
/* ignore otherwise */ |
/* ignore otherwise */ |
1841 |
break; |
break; |
1842 |
case S_VOP : |
case S_VOP : |
1843 |
decoder_pframe(dec, &bs, rounding, reduced_resolution, quant, |
decoder_pframe(dec, &bs, rounding, reduced_resolution, quant, |
1844 |
fcode_forward, intra_dc_threshold, gmc_mv); |
fcode_forward, intra_dc_threshold, &gmc_warp); |
1845 |
break; |
break; |
1846 |
case N_VOP : |
case N_VOP : |
1847 |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
1850 |
|
|
1851 |
if (reduced_resolution) |
if (reduced_resolution) |
1852 |
{ |
{ |
1853 |
image_deblock_rrv(&dec->refn[0], dec->edged_width, dec->mbs, |
image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs, |
1854 |
(dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width); |
(dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width, |
1855 |
|
16, XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV); |
1856 |
} |
} |
1857 |
|
|
1858 |
/* note: for packed_mode, output is performed when the special-N_VOP is decoded */ |
/* note: for packed_mode, output is performed when the special-N_VOP is decoded */ |
1860 |
{ |
{ |
1861 |
if (dec->low_delay) |
if (dec->low_delay) |
1862 |
{ |
{ |
1863 |
image_output(&dec->cur, dec->width, dec->height, |
decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution); |
|
dec->edged_width, frame->image, frame->stride, |
|
|
frame->colorspace, dec->interlacing); |
|
1864 |
output = 1; |
output = 1; |
1865 |
} |
} |
1866 |
else if (dec->frames > 0) /* is the reference frame valid? */ |
else if (dec->frames > 0) /* is the reference frame valid? */ |
1867 |
{ |
{ |
1868 |
image_output(&dec->refn[0], dec->width, dec->height, |
/* output the reference frame */ |
1869 |
dec->edged_width, frame->image, frame->stride, |
decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, dec->last_reduced_resolution); |
|
frame->colorspace, dec->interlacing); |
|
1870 |
output = 1; |
output = 1; |
1871 |
} |
} |
1872 |
} |
} |
1874 |
image_swap(&dec->refn[0], &dec->refn[1]); |
image_swap(&dec->refn[0], &dec->refn[1]); |
1875 |
image_swap(&dec->cur, &dec->refn[0]); |
image_swap(&dec->cur, &dec->refn[0]); |
1876 |
mb_swap(&dec->mbs, &dec->last_mbs); |
mb_swap(&dec->mbs, &dec->last_mbs); |
1877 |
|
dec->last_reduced_resolution = reduced_resolution; |
1878 |
|
|
1879 |
dec->frames++; |
dec->frames++; |
1880 |
seen_something = 1; |
seen_something = 1; |
1887 |
dec->low_delay = 1; |
dec->low_delay = 1; |
1888 |
} |
} |
1889 |
|
|
1890 |
if (dec->time_pp <= dec->time_bp) { |
if (dec->frames < 2) |
1891 |
|
{ |
1892 |
|
/* attemping to decode a bvop without atleast 2 reference frames */ |
1893 |
|
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, |
1894 |
|
"broken b-frame, mising ref frames"); |
1895 |
|
}else if (dec->time_pp <= dec->time_bp) { |
1896 |
/* this occurs when dx50_bvop_compatibility==0 sequences are |
/* this occurs when dx50_bvop_compatibility==0 sequences are |
1897 |
decoded in vfw. */ |
decoded in vfw. */ |
1898 |
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, |
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, |
1901 |
decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); |
decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); |
1902 |
} |
} |
1903 |
|
|
1904 |
image_output(&dec->cur, dec->width, dec->height, |
decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution); |
|
dec->edged_width, frame->image, frame->stride, |
|
|
frame->colorspace, dec->interlacing); |
|
1905 |
output = 1; |
output = 1; |
1906 |
dec->frames++; |
dec->frames++; |
1907 |
} |
} |
1908 |
|
|
|
emms(); |
|
|
|
|
1909 |
BitstreamByteAlign(&bs); |
BitstreamByteAlign(&bs); |
1910 |
|
|
1911 |
/* low_delay_default mode: repeat in packed_mode */ |
/* low_delay_default mode: repeat in packed_mode */ |
1912 |
if (dec->low_delay_default && dec->packed_mode && output == 0 && success == 0) |
if (dec->low_delay_default && dec->packed_mode && output == 0 && success == 0) |
1913 |
{ |
{ |
1914 |
success = 1; |
success = 1; |
1915 |
goto start; |
goto repeat; |
1916 |
} |
} |
1917 |
|
|
1918 |
done : |
done : |
1924 |
if (dec->packed_mode && seen_something) |
if (dec->packed_mode && seen_something) |
1925 |
{ |
{ |
1926 |
/* output the recently decoded frame */ |
/* output the recently decoded frame */ |
1927 |
image_output(&dec->refn[0], dec->width, dec->height, |
decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, dec->last_reduced_resolution); |
1928 |
dec->edged_width, frame->image, frame->stride, |
output = 1; |
|
frame->colorspace, dec->interlacing); |
|
1929 |
} |
} |
1930 |
else |
else |
1931 |
{ |
{ |
1932 |
|
image_clear(&dec->cur, dec->width, dec->height, dec->edged_width, 0, 128, 128); |
1933 |
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, |
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, |
1934 |
"warning: nothing to output"); |
"warning: nothing to output"); |
1935 |
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64, |
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64, |
1936 |
"bframe decoder lag"); |
"bframe decoder lag"); |
1937 |
|
|
1938 |
image_output(&dec->cur, dec->width, dec->height, |
decoder_output(dec, &dec->cur, NULL, frame, 1 /*disable pp*/); |
|
dec->edged_width, frame->image, frame->stride, |
|
|
frame->colorspace, dec->interlacing); |
|
1939 |
} |
} |
|
output = 1; |
|
1940 |
} |
} |
1941 |
|
|
1942 |
frame->length = BitstreamPos(&bs) / 8; |
frame->length = BitstreamPos(&bs) / 8; |