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 |
* |
* |
136 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
137 |
} |
} |
138 |
|
|
|
if (image_create(&dec->refh, dec->edged_width, dec->edged_height)) { |
|
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
|
|
xvid_free(dec); |
|
|
return XVID_ERR_MEMORY; |
|
|
} |
|
|
|
|
139 |
dec->mbs = |
dec->mbs = |
140 |
xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, |
xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, |
141 |
CACHE_LINE); |
CACHE_LINE); |
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); |
146 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
|
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
|
147 |
xvid_free(dec); |
xvid_free(dec); |
148 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
149 |
} |
} |
161 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
162 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
163 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
|
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
|
164 |
xvid_free(dec); |
xvid_free(dec); |
165 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
166 |
} |
} |
186 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
187 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
188 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
|
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
|
189 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
190 |
xvid_free(dec); |
xvid_free(dec); |
191 |
|
|
268 |
start_timer(); |
start_timer(); |
269 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) // coded |
270 |
{ |
{ |
271 |
int direction = dec->alternate_vertical_scan ? |
get_intra_block(bs, &block[i * 64], pMB->acpred_directions[i], |
272 |
2 : pMB->acpred_directions[i]; |
start_coeff); |
|
|
|
|
get_intra_block(bs, &block[i * 64], direction, start_coeff); |
|
273 |
} |
} |
274 |
stop_coding_timer(); |
stop_coding_timer(); |
275 |
|
|
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; |
|
|
|
|
start_timer(); |
|
|
if(dec->quarterpel) { |
|
|
interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
|
|
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
|
|
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
|
|
} |
|
|
else { |
|
|
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos, |
|
|
pMB->mvs[0].x, pMB->mvs[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); |
|
|
} |
|
|
|
|
|
interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos, |
|
|
uv_dx, uv_dy, stride2, rounding); |
|
|
interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos, |
|
|
uv_dx, uv_dy, stride2, rounding); |
|
|
stop_comp_timer(); |
|
|
|
|
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; |
375 |
} |
} |
376 |
|
|
377 |
uv_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2)); |
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) { |
if(dec->quarterpel) { |
382 |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
DEBUG("QUARTERPEL"); |
383 |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
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); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
385 |
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, 16*x_pos + 8, 16*y_pos, |
|
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos, |
|
386 |
pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
387 |
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, 16*x_pos, 16*y_pos + 8, |
|
dec->refh.y + 128, 16*x_pos, 16*y_pos + 8, |
|
388 |
pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
389 |
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, 16*x_pos + 8, 16*y_pos + 8, |
|
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
|
390 |
pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); |
pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); |
391 |
} |
} |
392 |
else { |
else { |
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, |
406 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
407 |
stop_comp_timer(); |
stop_comp_timer(); |
|
} |
|
408 |
|
|
409 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
|
int direction = dec->alternate_vertical_scan ? 2 : 0; |
|
|
|
|
410 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) // coded |
411 |
{ |
{ |
412 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
413 |
|
|
414 |
start_timer(); |
start_timer(); |
415 |
get_inter_block(bs, &block[i * 64], direction); |
get_inter_block(bs, &block[i * 64]); |
416 |
stop_coding_timer(); |
stop_coding_timer(); |
417 |
|
|
418 |
start_timer(); |
start_timer(); |
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->width, dec->height, dec->interlacing); |
589 |
stop_edges_timer(); |
stop_edges_timer(); |
590 |
|
|
591 |
bound = 0; |
bound = 0; |
706 |
rounding); |
rounding); |
707 |
} else // not coded |
} else // not coded |
708 |
{ |
{ |
709 |
|
DEBUG2("P-frame MB at (X,Y)=",x,y); |
710 |
mb->mode = MODE_NOT_CODED; |
mb->mode = MODE_NOT_CODED; |
711 |
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; |
712 |
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; |
876 |
stop_comp_timer(); |
stop_comp_timer(); |
877 |
|
|
878 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
|
int direction = dec->alternate_vertical_scan ? 2 : 0; |
|
|
|
|
879 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) // coded |
880 |
{ |
{ |
881 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
882 |
|
|
883 |
start_timer(); |
start_timer(); |
884 |
get_inter_block(bs, &block[i * 64], direction); |
get_inter_block(bs, &block[i * 64]); |
885 |
stop_coding_timer(); |
stop_coding_timer(); |
886 |
|
|
887 |
start_timer(); |
start_timer(); |
919 |
stop_transfer_timer(); |
stop_transfer_timer(); |
920 |
} |
} |
921 |
|
|
922 |
|
|
923 |
// add by MinChen <chenm001@163.com> |
// add by MinChen <chenm001@163.com> |
924 |
// decode an B-frame direct & inter macroblock |
// decode an B-frame direct & inter macroblock |
925 |
void |
void |
1027 |
interpolate8x8_switch(dec->refn[2].v, backward.v, 8 * x_pos, 8 * y_pos, |
interpolate8x8_switch(dec->refn[2].v, backward.v, 8 * x_pos, 8 * y_pos, |
1028 |
b_uv_dx, b_uv_dy, stride2, 0); |
b_uv_dx, b_uv_dy, stride2, 0); |
1029 |
|
|
1030 |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos, 16 * y_pos, |
1031 |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
stride); |
1032 |
dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos, |
interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos + 8, 16 * y_pos, |
1033 |
stride, 0); |
stride); |
1034 |
|
interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos, 16 * y_pos + 8, |
1035 |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
stride); |
1036 |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos + 8, |
1037 |
dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos + 8, |
16 * y_pos + 8, stride); |
1038 |
stride, 0); |
interpolate8x8_c(dec->cur.u, dec->refn[2].u, 8 * x_pos, 8 * y_pos, |
1039 |
|
stride2); |
1040 |
interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
interpolate8x8_c(dec->cur.v, dec->refn[2].v, 8 * x_pos, 8 * y_pos, |
1041 |
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
stride2); |
|
dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
|
|
stride, 0); |
|
|
|
|
|
interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
|
|
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
|
|
dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
|
|
stride, 0); |
|
|
|
|
|
interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
|
|
dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
|
|
dec->refn[2].u + (8 * y_pos * stride2) + 8 * x_pos, |
|
|
stride2, 0); |
|
|
|
|
|
interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
|
|
dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
|
|
dec->refn[2].v + (8 * y_pos * stride2) + 8 * x_pos, |
|
|
stride2, 0); |
|
|
|
|
1042 |
stop_comp_timer(); |
stop_comp_timer(); |
1043 |
|
|
1044 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
|
int direction = dec->alternate_vertical_scan ? 2 : 0; |
|
|
|
|
1045 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) // coded |
1046 |
{ |
{ |
1047 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
1048 |
|
|
1049 |
start_timer(); |
start_timer(); |
1050 |
get_inter_block(bs, &block[i * 64], direction); |
get_inter_block(bs, &block[i * 64]); |
1051 |
stop_coding_timer(); |
stop_coding_timer(); |
1052 |
|
|
1053 |
start_timer(); |
start_timer(); |
1142 |
|
|
1143 |
start_timer(); |
start_timer(); |
1144 |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
1145 |
dec->width, dec->height); |
dec->width, dec->height, dec->interlacing); |
1146 |
image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, |
1147 |
dec->width, dec->height); |
dec->width, dec->height, dec->interlacing); |
1148 |
stop_edges_timer(); |
stop_edges_timer(); |
1149 |
|
|
1150 |
#ifdef BFRAMES_DEC_DEBUG |
#ifdef BFRAMES_DEC_DEBUG |
1322 |
|
|
1323 |
BitstreamInit(&bs, frame->bitstream, frame->length); |
BitstreamInit(&bs, frame->bitstream, frame->length); |
1324 |
|
|
|
if(BitstreamShowBits(&bs, 8) == 0x7f) |
|
|
return XVID_ERR_OK; |
|
|
|
|
1325 |
// add by chenm001 <chenm001@163.com> |
// add by chenm001 <chenm001@163.com> |
1326 |
// for support B-frame to reference last 2 frame |
// for support B-frame to reference last 2 frame |
1327 |
dec->frames++; |
dec->frames++; |
1363 |
case N_VOP: // vop not coded |
case N_VOP: // vop not coded |
1364 |
// when low_delay==0, N_VOP's should interpolate between the past and future frames |
// when low_delay==0, N_VOP's should interpolate between the past and future frames |
1365 |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
|
#ifdef BFRAMES_DEC |
|
|
DEBUG1("N_VOP Time=", dec->time); |
|
|
#endif |
|
1366 |
break; |
break; |
1367 |
|
|
1368 |
default: |
default: |