136 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
137 |
} |
} |
138 |
|
|
139 |
|
if (image_create(&dec->refh, dec->edged_width, dec->edged_height)) { |
140 |
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
141 |
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
142 |
|
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
143 |
|
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
144 |
|
xvid_free(dec); |
145 |
|
return XVID_ERR_MEMORY; |
146 |
|
} |
147 |
|
|
148 |
dec->mbs = |
dec->mbs = |
149 |
xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, |
xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, |
150 |
CACHE_LINE); |
CACHE_LINE); |
153 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
154 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
155 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
156 |
|
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
157 |
xvid_free(dec); |
xvid_free(dec); |
158 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
159 |
} |
} |
171 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
172 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
173 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
174 |
|
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
175 |
xvid_free(dec); |
xvid_free(dec); |
176 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
177 |
} |
} |
197 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
198 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
199 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
200 |
|
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
201 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
202 |
xvid_free(dec); |
xvid_free(dec); |
203 |
|
|
280 |
start_timer(); |
start_timer(); |
281 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) // coded |
282 |
{ |
{ |
283 |
get_intra_block(bs, &block[i * 64], pMB->acpred_directions[i], |
int direction = dec->alternate_vertical_scan ? |
284 |
start_coeff); |
2 : pMB->acpred_directions[i]; |
285 |
|
|
286 |
|
get_intra_block(bs, &block[i * 64], direction, start_coeff); |
287 |
} |
} |
288 |
stop_coding_timer(); |
stop_coding_timer(); |
289 |
|
|
362 |
uv_dx = pMB->mvs[0].x; |
uv_dx = pMB->mvs[0].x; |
363 |
uv_dy = pMB->mvs[0].y; |
uv_dy = pMB->mvs[0].y; |
364 |
|
|
365 |
|
if (dec->quarterpel) |
366 |
|
{ |
367 |
|
uv_dx = (uv_dx >> 1) | (uv_dx & 1); |
368 |
|
uv_dy = (uv_dy >> 1) | (uv_dy & 1); |
369 |
|
} |
370 |
|
|
371 |
uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2; |
uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2; |
372 |
uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2; |
uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2; |
373 |
} else { |
} else { |
374 |
int sum; |
int sum; |
|
|
|
375 |
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; |
376 |
uv_dx = |
|
377 |
(sum == |
if (dec->quarterpel) |
378 |
0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + |
{ |
379 |
(ABS(sum) / 16) * 2)); |
sum /= 2; |
380 |
|
} |
381 |
|
|
382 |
|
uv_dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2)); |
383 |
|
|
384 |
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; |
385 |
uv_dy = |
|
386 |
(sum == |
if (dec->quarterpel) |
387 |
0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + |
{ |
388 |
(ABS(sum) / 16) * 2)); |
sum /= 2; |
389 |
|
} |
390 |
|
|
391 |
|
uv_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2)); |
392 |
} |
} |
393 |
|
|
394 |
start_timer(); |
start_timer(); |
395 |
|
if(dec->quarterpel) { |
396 |
|
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
397 |
|
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
398 |
|
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
399 |
|
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
400 |
|
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos, |
401 |
|
pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
402 |
|
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
403 |
|
dec->refh.y + 128, 16*x_pos, 16*y_pos + 8, |
404 |
|
pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
405 |
|
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
406 |
|
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
407 |
|
pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); |
408 |
|
} |
409 |
|
else { |
410 |
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, |
411 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
412 |
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, |
413 |
16 * y_pos, pMB->mvs[1].x, pMB->mvs[1].y, stride, |
pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
414 |
rounding); |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8, |
415 |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos, |
pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
416 |
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, |
417 |
rounding); |
pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); |
418 |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos + 8, |
} |
419 |
16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride, |
|
|
rounding); |
|
420 |
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, |
421 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
422 |
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, |
424 |
stop_comp_timer(); |
stop_comp_timer(); |
425 |
|
|
426 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
427 |
|
int direction = dec->alternate_vertical_scan ? 2 : 0; |
428 |
|
|
429 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) // coded |
430 |
{ |
{ |
431 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
432 |
|
|
433 |
start_timer(); |
start_timer(); |
434 |
get_inter_block(bs, &block[i * 64]); |
get_inter_block(bs, &block[i * 64], direction); |
435 |
stop_coding_timer(); |
stop_coding_timer(); |
436 |
|
|
437 |
start_timer(); |
start_timer(); |
604 |
|
|
605 |
start_timer(); |
start_timer(); |
606 |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
607 |
dec->width, dec->height, dec->interlacing); |
dec->width, dec->height); |
608 |
stop_edges_timer(); |
stop_edges_timer(); |
609 |
|
|
610 |
bound = 0; |
bound = 0; |
672 |
mb->quant = quant; |
mb->quant = quant; |
673 |
|
|
674 |
if (dec->interlacing) { |
if (dec->interlacing) { |
675 |
|
if (cbp || intra) { |
676 |
mb->field_dct = BitstreamGetBit(bs); |
mb->field_dct = BitstreamGetBit(bs); |
677 |
DEBUG1("decp: field_dct: ", mb->field_dct); |
DEBUG1("decp: field_dct: ", mb->field_dct); |
678 |
|
} |
679 |
|
|
680 |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
681 |
mb->field_pred = BitstreamGetBit(bs); |
mb->field_pred = BitstreamGetBit(bs); |
704 |
mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = |
mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = |
705 |
mb->mvs[0].y; |
mb->mvs[0].y; |
706 |
} |
} |
707 |
} else if (mb->mode == |
} else if (mb->mode == MODE_INTER4V ) { |
708 |
MODE_INTER4V /* || mb->mode == MODE_INTER4V_Q */ ) { |
|
709 |
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); |
710 |
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); |
711 |
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); |
725 |
rounding); |
rounding); |
726 |
} else // not coded |
} else // not coded |
727 |
{ |
{ |
728 |
//DEBUG2("P-frame MB at (X,Y)=",x,y); |
DEBUG2("P-frame MB at (X,Y)=",x,y); |
729 |
mb->mode = MODE_NOT_CODED; |
mb->mode = MODE_NOT_CODED; |
730 |
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; |
731 |
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; |
895 |
stop_comp_timer(); |
stop_comp_timer(); |
896 |
|
|
897 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
898 |
|
int direction = dec->alternate_vertical_scan ? 2 : 0; |
899 |
|
|
900 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) // coded |
901 |
{ |
{ |
902 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
903 |
|
|
904 |
start_timer(); |
start_timer(); |
905 |
get_inter_block(bs, &block[i * 64]); |
get_inter_block(bs, &block[i * 64], direction); |
906 |
stop_coding_timer(); |
stop_coding_timer(); |
907 |
|
|
908 |
start_timer(); |
start_timer(); |
1048 |
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, |
1049 |
b_uv_dx, b_uv_dy, stride2, 0); |
b_uv_dx, b_uv_dy, stride2, 0); |
1050 |
|
|
1051 |
interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos, 16 * y_pos, |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
1052 |
stride); |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
1053 |
interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos + 8, 16 * y_pos, |
dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos, |
1054 |
stride); |
stride, 0); |
1055 |
interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos, 16 * y_pos + 8, |
|
1056 |
stride); |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1057 |
interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos + 8, |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1058 |
16 * y_pos + 8, stride); |
dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1059 |
interpolate8x8_c(dec->cur.u, dec->refn[2].u, 8 * x_pos, 8 * y_pos, |
stride, 0); |
1060 |
stride2); |
|
1061 |
interpolate8x8_c(dec->cur.v, dec->refn[2].v, 8 * x_pos, 8 * y_pos, |
interpolate8x8_avg2(dec->cur.y + (16 * (y_pos + 8) * stride) + 16 * x_pos, |
1062 |
stride2); |
dec->cur.y + (16 * (y_pos + 8) * stride) + 16 * x_pos, |
1063 |
|
dec->refn[2].y + (16 * (y_pos + 8) * stride) + 16 * x_pos, |
1064 |
|
stride, 0); |
1065 |
|
|
1066 |
|
interpolate8x8_avg2(dec->cur.y + (16 * (y_pos + 8) * stride) + 16 * x_pos + 8, |
1067 |
|
dec->cur.y + (16 * (y_pos + 8) * stride) + 16 * x_pos + 8, |
1068 |
|
dec->refn[2].y + (16 * (y_pos + 8) * stride) + 16 * x_pos + 8, |
1069 |
|
stride, 0); |
1070 |
|
|
1071 |
|
interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride) + 8 * x_pos, |
1072 |
|
dec->cur.u + (8 * y_pos * stride) + 8 * x_pos, |
1073 |
|
dec->refn[2].u + (8 * y_pos * stride) + 8 * x_pos, |
1074 |
|
stride2, 0); |
1075 |
|
|
1076 |
|
interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride) + 8 * x_pos, |
1077 |
|
dec->cur.v + (8 * y_pos * stride) + 8 * x_pos, |
1078 |
|
dec->refn[2].v + (8 * y_pos * stride) + 8 * x_pos, |
1079 |
|
stride2, 0); |
1080 |
|
|
1081 |
stop_comp_timer(); |
stop_comp_timer(); |
1082 |
|
|
1083 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
1084 |
|
int direction = dec->alternate_vertical_scan ? 2 : 0; |
1085 |
|
|
1086 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) // coded |
1087 |
{ |
{ |
1088 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
1089 |
|
|
1090 |
start_timer(); |
start_timer(); |
1091 |
get_inter_block(bs, &block[i * 64]); |
get_inter_block(bs, &block[i * 64], direction); |
1092 |
stop_coding_timer(); |
stop_coding_timer(); |
1093 |
|
|
1094 |
start_timer(); |
start_timer(); |
1183 |
|
|
1184 |
start_timer(); |
start_timer(); |
1185 |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
1186 |
dec->width, dec->height, dec->interlacing); |
dec->width, dec->height); |
1187 |
image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, |
1188 |
dec->width, dec->height, dec->interlacing); |
dec->width, dec->height); |
1189 |
stop_edges_timer(); |
stop_edges_timer(); |
1190 |
|
|
1191 |
#ifdef BFRAMES_DEC_DEBUG |
#ifdef BFRAMES_DEC_DEBUG |
1320 |
|
|
1321 |
default: |
default: |
1322 |
DEBUG1("Not support B-frame mb_type =", mb->mb_type); |
DEBUG1("Not support B-frame mb_type =", mb->mb_type); |
|
; |
|
1323 |
} |
} |
1324 |
|
|
|
if ( (x==19) && (y==8) ) |
|
|
{ |
|
|
fprintf(stderr,"D %d %d %d %d %d %d \n",0, mb->mb_type, |
|
|
mb->mvs[0].x, mb->mvs[0].y,mb->b_mvs[0].x, mb->b_mvs[0].y ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
1325 |
} // end of FOR |
} // end of FOR |
1326 |
} |
} |
1327 |
#ifdef BFRAMES_DEC_DEBUG |
#ifdef BFRAMES_DEC_DEBUG |
1420 |
|
|
1421 |
#ifdef BFRAMES_DEC |
#ifdef BFRAMES_DEC |
1422 |
// test if no B_VOP |
// test if no B_VOP |
1423 |
if (dec->low_delay) { |
if (dec->low_delay || dec->frames == 0) { |
1424 |
#endif |
#endif |
1425 |
image_output(&dec->cur, dec->width, dec->height, dec->edged_width, |
image_output(&dec->cur, dec->width, dec->height, dec->edged_width, |
1426 |
frame->image, frame->stride, frame->colorspace); |
frame->image, frame->stride, frame->colorspace); |
1427 |
|
|
1428 |
#ifdef BFRAMES_DEC |
#ifdef BFRAMES_DEC |
1429 |
} else { |
} else { |
1430 |
if (dec->frames >= 0) { |
if (dec->frames >= 1) { |
1431 |
start_timer(); |
start_timer(); |
1432 |
if ((vop_type == I_VOP || vop_type == P_VOP)) { |
if ((vop_type == I_VOP || vop_type == P_VOP)) { |
1433 |
image_output(&dec->refn[0], dec->width, dec->height, |
image_output(&dec->refn[0], dec->width, dec->height, |