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 |
|
|
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 |
|
|
374 |
|
start_timer(); |
375 |
|
if(dec->quarterpel) { |
376 |
|
interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
377 |
|
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
378 |
|
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
379 |
|
} |
380 |
|
else { |
381 |
|
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos, |
382 |
|
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
383 |
|
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos, |
384 |
|
pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
385 |
|
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8, |
386 |
|
pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
387 |
|
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8, |
388 |
|
pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); |
389 |
|
} |
390 |
|
|
391 |
|
interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos, |
392 |
|
uv_dx, uv_dy, stride2, rounding); |
393 |
|
interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos, |
394 |
|
uv_dx, uv_dy, stride2, rounding); |
395 |
|
stop_comp_timer(); |
396 |
|
|
397 |
} else { |
} else { |
398 |
int sum; |
int sum; |
399 |
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; |
413 |
} |
} |
414 |
|
|
415 |
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)); |
|
} |
|
416 |
|
|
417 |
start_timer(); |
start_timer(); |
418 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
419 |
DEBUG("QUARTERPEL"); |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
420 |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos, |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
421 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
422 |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos, |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
423 |
|
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos, |
424 |
pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
425 |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8, |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
426 |
|
dec->refh.y + 128, 16*x_pos, 16*y_pos + 8, |
427 |
pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
428 |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8, |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
429 |
|
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
430 |
pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); |
pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); |
431 |
} |
} |
432 |
else { |
else { |
445 |
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, |
446 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
447 |
stop_comp_timer(); |
stop_comp_timer(); |
448 |
|
} |
449 |
|
|
450 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
451 |
|
int direction = dec->alternate_vertical_scan ? 2 : 0; |
452 |
|
|
453 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) // coded |
454 |
{ |
{ |
455 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
456 |
|
|
457 |
start_timer(); |
start_timer(); |
458 |
get_inter_block(bs, &block[i * 64]); |
get_inter_block(bs, &block[i * 64], direction); |
459 |
stop_coding_timer(); |
stop_coding_timer(); |
460 |
|
|
461 |
start_timer(); |
start_timer(); |
628 |
|
|
629 |
start_timer(); |
start_timer(); |
630 |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
631 |
dec->width, dec->height, dec->interlacing); |
dec->width, dec->height); |
632 |
stop_edges_timer(); |
stop_edges_timer(); |
633 |
|
|
634 |
bound = 0; |
bound = 0; |
749 |
rounding); |
rounding); |
750 |
} else // not coded |
} else // not coded |
751 |
{ |
{ |
|
DEBUG2("P-frame MB at (X,Y)=",x,y); |
|
752 |
mb->mode = MODE_NOT_CODED; |
mb->mode = MODE_NOT_CODED; |
753 |
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; |
754 |
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; |
918 |
stop_comp_timer(); |
stop_comp_timer(); |
919 |
|
|
920 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
921 |
|
int direction = dec->alternate_vertical_scan ? 2 : 0; |
922 |
|
|
923 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) // coded |
924 |
{ |
{ |
925 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
926 |
|
|
927 |
start_timer(); |
start_timer(); |
928 |
get_inter_block(bs, &block[i * 64]); |
get_inter_block(bs, &block[i * 64], direction); |
929 |
stop_coding_timer(); |
stop_coding_timer(); |
930 |
|
|
931 |
start_timer(); |
start_timer(); |
963 |
stop_transfer_timer(); |
stop_transfer_timer(); |
964 |
} |
} |
965 |
|
|
|
|
|
966 |
// add by MinChen <chenm001@163.com> |
// add by MinChen <chenm001@163.com> |
967 |
// decode an B-frame direct & inter macroblock |
// decode an B-frame direct & inter macroblock |
968 |
void |
void |
1070 |
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, |
1071 |
b_uv_dx, b_uv_dy, stride2, 0); |
b_uv_dx, b_uv_dy, stride2, 0); |
1072 |
|
|
1073 |
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, |
1074 |
stride); |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
1075 |
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, |
1076 |
stride); |
stride, 0); |
1077 |
interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos, 16 * y_pos + 8, |
|
1078 |
stride); |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1079 |
interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos + 8, |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1080 |
16 * y_pos + 8, stride); |
dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1081 |
interpolate8x8_c(dec->cur.u, dec->refn[2].u, 8 * x_pos, 8 * y_pos, |
stride, 0); |
1082 |
stride2); |
|
1083 |
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, |
1084 |
stride2); |
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
1085 |
|
dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
1086 |
|
stride, 0); |
1087 |
|
|
1088 |
|
interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
1089 |
|
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
1090 |
|
dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
1091 |
|
stride, 0); |
1092 |
|
|
1093 |
|
interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
1094 |
|
dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
1095 |
|
dec->refn[2].u + (8 * y_pos * stride2) + 8 * x_pos, |
1096 |
|
stride2, 0); |
1097 |
|
|
1098 |
|
interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
1099 |
|
dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
1100 |
|
dec->refn[2].v + (8 * y_pos * stride2) + 8 * x_pos, |
1101 |
|
stride2, 0); |
1102 |
|
|
1103 |
stop_comp_timer(); |
stop_comp_timer(); |
1104 |
|
|
1105 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
1106 |
|
int direction = dec->alternate_vertical_scan ? 2 : 0; |
1107 |
|
|
1108 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) // coded |
1109 |
{ |
{ |
1110 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
1111 |
|
|
1112 |
start_timer(); |
start_timer(); |
1113 |
get_inter_block(bs, &block[i * 64]); |
get_inter_block(bs, &block[i * 64], direction); |
1114 |
stop_coding_timer(); |
stop_coding_timer(); |
1115 |
|
|
1116 |
start_timer(); |
start_timer(); |
1205 |
|
|
1206 |
start_timer(); |
start_timer(); |
1207 |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
1208 |
dec->width, dec->height, dec->interlacing); |
dec->width, dec->height); |
1209 |
image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, |
1210 |
dec->width, dec->height, dec->interlacing); |
dec->width, dec->height); |
1211 |
stop_edges_timer(); |
stop_edges_timer(); |
1212 |
|
|
1213 |
#ifdef BFRAMES_DEC_DEBUG |
#ifdef BFRAMES_DEC_DEBUG |
1385 |
|
|
1386 |
BitstreamInit(&bs, frame->bitstream, frame->length); |
BitstreamInit(&bs, frame->bitstream, frame->length); |
1387 |
|
|
1388 |
|
if(BitstreamShowBits(&bs, 8) == 0x7f) { |
1389 |
|
BitstreamGetBits(&bs, 8); |
1390 |
|
return XVID_ERR_FAIL; |
1391 |
|
} |
1392 |
|
|
1393 |
// add by chenm001 <chenm001@163.com> |
// add by chenm001 <chenm001@163.com> |
1394 |
// for support B-frame to reference last 2 frame |
// for support B-frame to reference last 2 frame |
1395 |
dec->frames++; |
dec->frames++; |
1431 |
case N_VOP: // vop not coded |
case N_VOP: // vop not coded |
1432 |
// 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 |
1433 |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
1434 |
|
#ifdef BFRAMES_DEC |
1435 |
|
DEBUG1("N_VOP Time=", dec->time); |
1436 |
|
#endif |
1437 |
break; |
break; |
1438 |
|
|
1439 |
default: |
default: |