32 |
* |
* |
33 |
* History: |
* History: |
34 |
* |
* |
35 |
|
* 22.04.2002 add some B-frame decode support; chenm001 <chenm001@163.com> |
36 |
|
* 29.03.2002 interlacing fix - compensated block wasn't being used when |
37 |
|
* reconstructing blocks, thus artifacts |
38 |
|
* interlacing speedup - used transfers to re-interlace |
39 |
|
* interlaced decoding should be as fast as progressive now |
40 |
* 26.03.2002 interlacing support - moved transfers outside decode loop |
* 26.03.2002 interlacing support - moved transfers outside decode loop |
41 |
* 26.12.2001 decoder_mbinter: dequant/idct moved within if(coded) block |
* 26.12.2001 decoder_mbinter: dequant/idct moved within if(coded) block |
42 |
* 22.12.2001 block based interpolation |
* 22.12.2001 block based interpolation |
60 |
#include "dct/fdct.h" |
#include "dct/fdct.h" |
61 |
#include "utils/mem_transfer.h" |
#include "utils/mem_transfer.h" |
62 |
#include "image/interpolate8x8.h" |
#include "image/interpolate8x8.h" |
|
#include "utils/mbfunctions.h" |
|
63 |
|
|
64 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
65 |
#include "prediction/mbprediction.h" |
#include "prediction/mbprediction.h" |
96 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
97 |
} |
} |
98 |
|
|
99 |
if (image_create(&dec->refn, dec->edged_width, dec->edged_height)) |
if (image_create(&dec->refn[0], dec->edged_width, dec->edged_height)) |
100 |
{ |
{ |
101 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
102 |
xvid_free(dec); |
xvid_free(dec); |
103 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
104 |
} |
} |
105 |
|
// add by chenm001 <chenm001@163.com> |
106 |
|
// for support B-frame to reference last 2 frame |
107 |
|
if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) |
108 |
|
{ |
109 |
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
110 |
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
111 |
|
xvid_free(dec); |
112 |
|
return XVID_ERR_MEMORY; |
113 |
|
} |
114 |
|
|
115 |
dec->mbs = xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, CACHE_LINE); |
dec->mbs = xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, CACHE_LINE); |
116 |
if (dec->mbs == NULL) |
if (dec->mbs == NULL) |
121 |
} |
} |
122 |
|
|
123 |
init_timer(); |
init_timer(); |
|
create_vlc_tables(); |
|
124 |
|
|
125 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
126 |
} |
} |
129 |
int decoder_destroy(DECODER * dec) |
int decoder_destroy(DECODER * dec) |
130 |
{ |
{ |
131 |
xvid_free(dec->mbs); |
xvid_free(dec->mbs); |
132 |
image_destroy(&dec->refn, dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
133 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
134 |
xvid_free(dec); |
xvid_free(dec); |
135 |
|
|
|
destroy_vlc_tables(); |
|
|
|
|
136 |
write_timer(); |
write_timer(); |
137 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
138 |
} |
} |
161 |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
162 |
DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE); |
163 |
|
|
164 |
const uint32_t stride = dec->edged_width; |
uint32_t stride = dec->edged_width; |
165 |
|
uint32_t stride2 = stride / 2; |
166 |
|
uint32_t next_block = stride * 8; |
167 |
uint32_t i; |
uint32_t i; |
168 |
uint32_t iQuant = pMB->quant; |
uint32_t iQuant = pMB->quant; |
169 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
170 |
|
|
171 |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
172 |
pU_Cur = dec->cur.u + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); |
173 |
pV_Cur = dec->cur.v + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
174 |
|
|
175 |
memset(block, 0, 6*64*sizeof(int16_t)); // clear |
memset(block, 0, 6*64*sizeof(int16_t)); // clear |
176 |
|
|
236 |
stop_idct_timer(); |
stop_idct_timer(); |
237 |
} |
} |
238 |
|
|
|
start_timer(); |
|
239 |
if (dec->interlacing && pMB->field_dct) |
if (dec->interlacing && pMB->field_dct) |
240 |
{ |
{ |
241 |
MBFieldToFrame(data); |
next_block = stride; |
242 |
|
stride *= 2; |
243 |
} |
} |
|
stop_interlacing_timer(); |
|
244 |
|
|
245 |
start_timer(); |
start_timer(); |
246 |
transfer_16to8copy(pY_Cur, &data[0*64], stride); |
transfer_16to8copy(pY_Cur, &data[0*64], stride); |
247 |
transfer_16to8copy(pY_Cur + 8, &data[1*64], stride); |
transfer_16to8copy(pY_Cur + 8, &data[1*64], stride); |
248 |
transfer_16to8copy(pY_Cur + 8 * stride, &data[2*64], stride); |
transfer_16to8copy(pY_Cur + next_block, &data[2*64], stride); |
249 |
transfer_16to8copy(pY_Cur + 8 + 8 * stride, &data[3*64], stride); |
transfer_16to8copy(pY_Cur + 8 + next_block, &data[3*64], stride); |
250 |
transfer_16to8copy(pU_Cur, &data[4*64], stride / 2); |
transfer_16to8copy(pU_Cur, &data[4*64], stride2); |
251 |
transfer_16to8copy(pV_Cur, &data[5*64], stride / 2); |
transfer_16to8copy(pV_Cur, &data[5*64], stride2); |
252 |
stop_transfer_timer(); |
stop_transfer_timer(); |
253 |
} |
} |
254 |
|
|
278 |
DECLARE_ALIGNED_MATRIX(block,6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(block,6, 64, int16_t, CACHE_LINE); |
279 |
DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE); |
280 |
|
|
281 |
const uint32_t stride = dec->edged_width; |
uint32_t stride = dec->edged_width; |
282 |
const uint32_t stride2 = dec->edged_width / 2; |
uint32_t stride2 = stride / 2; |
283 |
|
uint32_t next_block = stride * 8; |
284 |
uint32_t i; |
uint32_t i; |
285 |
uint32_t iQuant = pMB->quant; |
uint32_t iQuant = pMB->quant; |
286 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
287 |
int uv_dx, uv_dy; |
int uv_dx, uv_dy; |
288 |
|
|
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) * (stride >> 1) + (x_pos << 3); |
pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); |
291 |
pV_Cur = dec->cur.v + (y_pos << 3) * (stride >> 1) + (x_pos << 3); |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
292 |
|
|
293 |
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) |
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) |
294 |
{ |
{ |
309 |
} |
} |
310 |
|
|
311 |
start_timer(); |
start_timer(); |
312 |
interpolate8x8_switch(dec->cur.y, dec->refn.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, 16*y_pos , pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
313 |
interpolate8x8_switch(dec->cur.y, dec->refn.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 + 8, 16*y_pos , pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
314 |
interpolate8x8_switch(dec->cur.y, dec->refn.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, 16*y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
315 |
interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x_pos + 8, 16*y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].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); |
316 |
interpolate8x8_switch(dec->cur.u, dec->refn.u, 8*x_pos, 8*y_pos, uv_dx, uv_dy, stride2, rounding); |
interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8*x_pos, 8*y_pos, uv_dx, uv_dy, stride2, rounding); |
317 |
interpolate8x8_switch(dec->cur.v, dec->refn.v, 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); |
318 |
stop_comp_timer(); |
stop_comp_timer(); |
319 |
|
|
320 |
for (i = 0; i < 6; i++) |
for (i = 0; i < 6; i++) |
344 |
} |
} |
345 |
} |
} |
346 |
|
|
347 |
start_timer(); |
if (dec->interlacing && pMB->field_dct) |
|
if (pMB->field_dct) |
|
348 |
{ |
{ |
349 |
MBFieldToFrame(data); |
next_block = stride; |
350 |
|
stride *= 2; |
351 |
} |
} |
|
stop_interlacing_timer(); |
|
352 |
|
|
353 |
start_timer(); |
start_timer(); |
354 |
if (cbp & 32) |
if (cbp & 32) |
356 |
if (cbp & 16) |
if (cbp & 16) |
357 |
transfer_16to8add(pY_Cur + 8, &data[1*64], stride); |
transfer_16to8add(pY_Cur + 8, &data[1*64], stride); |
358 |
if (cbp & 8) |
if (cbp & 8) |
359 |
transfer_16to8add(pY_Cur + 8 * stride, &data[2*64], stride); |
transfer_16to8add(pY_Cur + next_block, &data[2*64], stride); |
360 |
if (cbp & 4) |
if (cbp & 4) |
361 |
transfer_16to8add(pY_Cur + 8 + 8 * stride, &data[3*64], stride); |
transfer_16to8add(pY_Cur + 8 + next_block, &data[3*64], stride); |
362 |
if (cbp & 2) |
if (cbp & 2) |
363 |
transfer_16to8add(pU_Cur, &data[4*64], stride / 2); |
transfer_16to8add(pU_Cur, &data[4*64], stride2); |
364 |
if (cbp & 1) |
if (cbp & 1) |
365 |
transfer_16to8add(pV_Cur, &data[5*64], stride / 2); |
transfer_16to8add(pV_Cur, &data[5*64], stride2); |
366 |
stop_transfer_timer(); |
stop_transfer_timer(); |
367 |
} |
} |
368 |
|
|
481 |
|
|
482 |
uint32_t x, y; |
uint32_t x, y; |
483 |
|
|
|
image_swap(&dec->cur, &dec->refn); |
|
|
|
|
484 |
start_timer(); |
start_timer(); |
485 |
image_setedges(&dec->refn, dec->edged_width, dec->edged_height, dec->width, dec->height, dec->interlacing); |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, dec->width, dec->height, dec->interlacing); |
486 |
stop_edges_timer(); |
stop_edges_timer(); |
487 |
|
|
488 |
for (y = 0; y < dec->mb_height; y++) |
for (y = 0; y < dec->mb_height; y++) |
598 |
start_timer(); |
start_timer(); |
599 |
|
|
600 |
transfer8x8_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x), |
transfer8x8_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x), |
601 |
dec->refn.y + (16*y)*dec->edged_width + (16*x), |
dec->refn[0].y + (16*y)*dec->edged_width + (16*x), |
602 |
dec->edged_width); |
dec->edged_width); |
603 |
|
|
604 |
transfer8x8_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x+8), |
transfer8x8_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x+8), |
605 |
dec->refn.y + (16*y)*dec->edged_width + (16*x+8), |
dec->refn[0].y + (16*y)*dec->edged_width + (16*x+8), |
606 |
dec->edged_width); |
dec->edged_width); |
607 |
|
|
608 |
transfer8x8_copy(dec->cur.y + (16*y+8)*dec->edged_width + (16*x), |
transfer8x8_copy(dec->cur.y + (16*y+8)*dec->edged_width + (16*x), |
609 |
dec->refn.y + (16*y+8)*dec->edged_width + (16*x), |
dec->refn[0].y + (16*y+8)*dec->edged_width + (16*x), |
610 |
dec->edged_width); |
dec->edged_width); |
611 |
|
|
612 |
transfer8x8_copy(dec->cur.y + (16*y+8)*dec->edged_width + (16*x+8), |
transfer8x8_copy(dec->cur.y + (16*y+8)*dec->edged_width + (16*x+8), |
613 |
dec->refn.y + (16*y+8)*dec->edged_width + (16*x+8), |
dec->refn[0].y + (16*y+8)*dec->edged_width + (16*x+8), |
614 |
dec->edged_width); |
dec->edged_width); |
615 |
|
|
616 |
transfer8x8_copy(dec->cur.u + (8*y)*dec->edged_width/2 + (8*x), |
transfer8x8_copy(dec->cur.u + (8*y)*dec->edged_width/2 + (8*x), |
617 |
dec->refn.u + (8*y)*dec->edged_width/2 + (8*x), |
dec->refn[0].u + (8*y)*dec->edged_width/2 + (8*x), |
618 |
dec->edged_width/2); |
dec->edged_width/2); |
619 |
|
|
620 |
transfer8x8_copy(dec->cur.v + (8*y)*dec->edged_width/2 + (8*x), |
transfer8x8_copy(dec->cur.v + (8*y)*dec->edged_width/2 + (8*x), |
621 |
dec->refn.v + (8*y)*dec->edged_width/2 + (8*x), |
dec->refn[0].v + (8*y)*dec->edged_width/2 + (8*x), |
622 |
dec->edged_width/2); |
dec->edged_width/2); |
623 |
|
|
624 |
stop_transfer_timer(); |
stop_transfer_timer(); |
635 |
uint32_t quant; |
uint32_t quant; |
636 |
uint32_t fcode; |
uint32_t fcode; |
637 |
uint32_t intra_dc_threshold; |
uint32_t intra_dc_threshold; |
638 |
|
uint32_t vop_type; |
639 |
|
|
640 |
start_global_timer(); |
start_global_timer(); |
641 |
|
|
642 |
BitstreamInit(&bs, frame->bitstream, frame->length); |
BitstreamInit(&bs, frame->bitstream, frame->length); |
643 |
|
|
644 |
switch (BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode, &intra_dc_threshold)) |
// add by chenm001 <chenm001@163.com> |
645 |
|
// for support B-frame to reference last 2 frame |
646 |
|
vop_type=BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode, &intra_dc_threshold); |
647 |
|
|
648 |
|
if (vop_type==I_VOP || vop_type==P_VOP){ |
649 |
|
image_swap(&dec->refn[0], &dec->refn[1]); |
650 |
|
image_swap(&dec->cur, &dec->refn[0]); |
651 |
|
} |
652 |
|
|
653 |
|
switch (vop_type) |
654 |
{ |
{ |
655 |
case P_VOP : |
case P_VOP : |
656 |
decoder_pframe(dec, &bs, rounding, quant, fcode, intra_dc_threshold); |
decoder_pframe(dec, &bs, rounding, quant, fcode, intra_dc_threshold); |