32 |
* |
* |
33 |
* History: |
* History: |
34 |
* |
* |
35 |
|
* 29.03.2002 interlacing fix - compensated block wasn't being used when |
36 |
|
* reconstructing blocks, thus artifacts |
37 |
|
* interlacing speedup - used transfers to re-interlace |
38 |
|
* interlaced decoding should be as fast as progressive now |
39 |
* 26.03.2002 interlacing support - moved transfers outside decode loop |
* 26.03.2002 interlacing support - moved transfers outside decode loop |
40 |
* 26.12.2001 decoder_mbinter: dequant/idct moved within if(coded) block |
* 26.12.2001 decoder_mbinter: dequant/idct moved within if(coded) block |
41 |
* 22.12.2001 block based interpolation |
* 22.12.2001 block based interpolation |
59 |
#include "dct/fdct.h" |
#include "dct/fdct.h" |
60 |
#include "utils/mem_transfer.h" |
#include "utils/mem_transfer.h" |
61 |
#include "image/interpolate8x8.h" |
#include "image/interpolate8x8.h" |
|
#include "utils/mbfunctions.h" |
|
62 |
|
|
63 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
64 |
#include "prediction/mbprediction.h" |
#include "prediction/mbprediction.h" |
111 |
} |
} |
112 |
|
|
113 |
init_timer(); |
init_timer(); |
|
create_vlc_tables(); |
|
114 |
|
|
115 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
116 |
} |
} |
123 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
124 |
xvid_free(dec); |
xvid_free(dec); |
125 |
|
|
|
destroy_vlc_tables(); |
|
|
|
|
126 |
write_timer(); |
write_timer(); |
127 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
128 |
} |
} |
147 |
const uint32_t quant, |
const uint32_t quant, |
148 |
const uint32_t intra_dc_threshold) |
const uint32_t intra_dc_threshold) |
149 |
{ |
{ |
150 |
#ifdef LINUX |
|
151 |
DECLARE_ALIGNED_MATRIX(block,6,64,int16_t,16); |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
152 |
DECLARE_ALIGNED_MATRIX(data,6,64,int16_t,16); |
DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE); |
153 |
#else |
|
154 |
CACHE_ALIGN int16_t block[6][64]; |
uint32_t stride = dec->edged_width; |
155 |
CACHE_ALIGN int16_t data[6][64]; |
uint32_t stride2 = stride / 2; |
156 |
#endif |
uint32_t next_block = stride * 8; |
|
const uint32_t stride = dec->edged_width; |
|
157 |
uint32_t i; |
uint32_t i; |
158 |
uint32_t iQuant = pMB->quant; |
uint32_t iQuant = pMB->quant; |
159 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
160 |
|
|
161 |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
162 |
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); |
163 |
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); |
164 |
|
|
165 |
#ifdef LINUX |
memset(block, 0, 6*64*sizeof(int16_t)); // clear |
|
memset(block,0,sizeof(int16_t)*6*64); |
|
|
#else |
|
|
memset(block, 0, sizeof(block)); // clear |
|
|
#endif |
|
166 |
|
|
167 |
for (i = 0; i < 6; i++) |
for (i = 0; i < 6; i++) |
168 |
{ |
{ |
171 |
int start_coeff; |
int start_coeff; |
172 |
|
|
173 |
start_timer(); |
start_timer(); |
174 |
predict_acdc(dec->mbs, x_pos, y_pos, dec->mb_width, i, block[i], iQuant, iDcScaler, predictors); |
predict_acdc(dec->mbs, x_pos, y_pos, dec->mb_width, i, &block[i*64], iQuant, iDcScaler, predictors); |
175 |
if (!acpred_flag) |
if (!acpred_flag) |
176 |
{ |
{ |
177 |
pMB->acpred_directions[i] = 0; |
pMB->acpred_directions[i] = 0; |
191 |
BitstreamSkip(bs, 1); // marker |
BitstreamSkip(bs, 1); // marker |
192 |
} |
} |
193 |
|
|
194 |
block[i][0] = dc_dif; |
block[i*64 + 0] = dc_dif; |
195 |
start_coeff = 1; |
start_coeff = 1; |
196 |
} |
} |
197 |
else |
else |
202 |
start_timer(); |
start_timer(); |
203 |
if (cbp & (1 << (5-i))) // coded |
if (cbp & (1 << (5-i))) // coded |
204 |
{ |
{ |
205 |
get_intra_block(bs, block[i], pMB->acpred_directions[i], start_coeff); |
get_intra_block(bs, &block[i*64], pMB->acpred_directions[i], start_coeff); |
206 |
} |
} |
207 |
stop_coding_timer(); |
stop_coding_timer(); |
208 |
|
|
209 |
start_timer(); |
start_timer(); |
210 |
add_acdc(pMB, i, block[i], iDcScaler, predictors); |
add_acdc(pMB, i, &block[i*64], iDcScaler, predictors); |
211 |
stop_prediction_timer(); |
stop_prediction_timer(); |
212 |
|
|
213 |
start_timer(); |
start_timer(); |
214 |
if (dec->quant_type == 0) |
if (dec->quant_type == 0) |
215 |
{ |
{ |
216 |
dequant_intra(data[i], block[i], iQuant, iDcScaler); |
dequant_intra(&data[i*64], &block[i*64], iQuant, iDcScaler); |
217 |
} |
} |
218 |
else |
else |
219 |
{ |
{ |
220 |
dequant4_intra(data[i], block[i], iQuant, iDcScaler); |
dequant4_intra(&data[i*64], &block[i*64], iQuant, iDcScaler); |
221 |
} |
} |
222 |
stop_iquant_timer(); |
stop_iquant_timer(); |
223 |
|
|
224 |
start_timer(); |
start_timer(); |
225 |
idct(data[i]); |
idct(&data[i*64]); |
226 |
stop_idct_timer(); |
stop_idct_timer(); |
227 |
} |
} |
228 |
|
|
|
start_timer(); |
|
229 |
if (dec->interlacing && pMB->field_dct) |
if (dec->interlacing && pMB->field_dct) |
230 |
{ |
{ |
231 |
MBFieldToFrame(data); |
next_block = stride; |
232 |
|
stride *= 2; |
233 |
} |
} |
|
stop_interlacing_timer(); |
|
234 |
|
|
235 |
start_timer(); |
start_timer(); |
236 |
transfer_16to8copy(pY_Cur, data[0], stride); |
transfer_16to8copy(pY_Cur, &data[0*64], stride); |
237 |
transfer_16to8copy(pY_Cur + 8, data[1], stride); |
transfer_16to8copy(pY_Cur + 8, &data[1*64], stride); |
238 |
transfer_16to8copy(pY_Cur + 8 * stride, data[2], stride); |
transfer_16to8copy(pY_Cur + next_block, &data[2*64], stride); |
239 |
transfer_16to8copy(pY_Cur + 8 + 8 * stride, data[3], stride); |
transfer_16to8copy(pY_Cur + 8 + next_block, &data[3*64], stride); |
240 |
transfer_16to8copy(pU_Cur, data[4], stride / 2); |
transfer_16to8copy(pU_Cur, &data[4*64], stride2); |
241 |
transfer_16to8copy(pV_Cur, data[5], stride / 2); |
transfer_16to8copy(pV_Cur, &data[5*64], stride2); |
242 |
stop_transfer_timer(); |
stop_transfer_timer(); |
243 |
} |
} |
244 |
|
|
264 |
const uint32_t quant, |
const uint32_t quant, |
265 |
const uint32_t rounding) |
const uint32_t rounding) |
266 |
{ |
{ |
|
#ifdef LINUX |
|
|
DECLARE_ALIGNED_MATRIX(block,6,64,int16_t,16); |
|
|
DECLARE_ALIGNED_MATRIX(data,6,64,int16_t,16); |
|
|
#else |
|
|
CACHE_ALIGN int16_t block[6][64]; |
|
|
CACHE_ALIGN int16_t data[6][64]; |
|
|
#endif |
|
267 |
|
|
268 |
const uint32_t stride = dec->edged_width; |
DECLARE_ALIGNED_MATRIX(block,6, 64, int16_t, CACHE_LINE); |
269 |
const uint32_t stride2 = dec->edged_width / 2; |
DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE); |
270 |
|
|
271 |
|
uint32_t stride = dec->edged_width; |
272 |
|
uint32_t stride2 = stride / 2; |
273 |
|
uint32_t next_block = stride * 8; |
274 |
uint32_t i; |
uint32_t i; |
275 |
uint32_t iQuant = pMB->quant; |
uint32_t iQuant = pMB->quant; |
276 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
277 |
int uv_dx, uv_dy; |
int uv_dx, uv_dy; |
278 |
|
|
279 |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
280 |
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); |
281 |
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); |
282 |
|
|
283 |
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) |
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) |
284 |
{ |
{ |
311 |
{ |
{ |
312 |
if (cbp & (1 << (5-i))) // coded |
if (cbp & (1 << (5-i))) // coded |
313 |
{ |
{ |
314 |
memset(block[i], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i*64], 0, 64 * sizeof(int16_t)); // clear |
315 |
|
|
316 |
start_timer(); |
start_timer(); |
317 |
get_inter_block(bs, block[i]); |
get_inter_block(bs, &block[i*64]); |
318 |
stop_coding_timer(); |
stop_coding_timer(); |
319 |
|
|
320 |
start_timer(); |
start_timer(); |
321 |
if (dec->quant_type == 0) |
if (dec->quant_type == 0) |
322 |
{ |
{ |
323 |
dequant_inter(data[i], block[i], iQuant); |
dequant_inter(&data[i*64], &block[i*64], iQuant); |
324 |
} |
} |
325 |
else |
else |
326 |
{ |
{ |
327 |
dequant4_inter(data[i], block[i], iQuant); |
dequant4_inter(&data[i*64], &block[i*64], iQuant); |
328 |
} |
} |
329 |
stop_iquant_timer(); |
stop_iquant_timer(); |
330 |
|
|
331 |
start_timer(); |
start_timer(); |
332 |
idct(data[i]); |
idct(&data[i*64]); |
333 |
stop_idct_timer(); |
stop_idct_timer(); |
334 |
} |
} |
335 |
} |
} |
336 |
|
|
337 |
start_timer(); |
if (dec->interlacing && pMB->field_dct) |
|
if (pMB->field_dct) |
|
338 |
{ |
{ |
339 |
MBFieldToFrame(data); |
next_block = stride; |
340 |
|
stride *= 2; |
341 |
} |
} |
|
stop_interlacing_timer(); |
|
342 |
|
|
343 |
start_timer(); |
start_timer(); |
344 |
if (cbp & 32) |
if (cbp & 32) |
345 |
transfer_16to8add(pY_Cur, data[0], stride); |
transfer_16to8add(pY_Cur, &data[0*64], stride); |
346 |
if (cbp & 16) |
if (cbp & 16) |
347 |
transfer_16to8add(pY_Cur + 8, data[1], stride); |
transfer_16to8add(pY_Cur + 8, &data[1*64], stride); |
348 |
if (cbp & 8) |
if (cbp & 8) |
349 |
transfer_16to8add(pY_Cur + 8 * stride, data[2], stride); |
transfer_16to8add(pY_Cur + next_block, &data[2*64], stride); |
350 |
if (cbp & 4) |
if (cbp & 4) |
351 |
transfer_16to8add(pY_Cur + 8 + 8 * stride, data[3], stride); |
transfer_16to8add(pY_Cur + 8 + next_block, &data[3*64], stride); |
352 |
if (cbp & 2) |
if (cbp & 2) |
353 |
transfer_16to8add(pU_Cur, data[4], stride / 2); |
transfer_16to8add(pU_Cur, &data[4*64], stride2); |
354 |
if (cbp & 1) |
if (cbp & 1) |
355 |
transfer_16to8add(pV_Cur, data[5], stride / 2); |
transfer_16to8add(pV_Cur, &data[5*64], stride2); |
356 |
stop_transfer_timer(); |
stop_transfer_timer(); |
357 |
} |
} |
358 |
|
|
359 |
|
|
360 |
void decoder_iframe(DECODER * dec, Bitstream * bs, int quant, int intra_dc_threshold) |
void decoder_iframe(DECODER * dec, Bitstream * bs, int quant, int intra_dc_threshold) |
361 |
{ |
{ |
362 |
|
|
363 |
uint32_t x, y; |
uint32_t x, y; |
364 |
|
|
365 |
for (y = 0; y < dec->mb_height; y++) |
for (y = 0; y < dec->mb_height; y++) |
412 |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, intra_dc_threshold); |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, intra_dc_threshold); |
413 |
} |
} |
414 |
} |
} |
415 |
|
|
416 |
} |
} |
417 |
|
|
418 |
|
|
419 |
void get_motion_vector(DECODER *dec, Bitstream *bs, int x, int y, int k, VECTOR * mv, int fcode) |
void get_motion_vector(DECODER *dec, Bitstream *bs, int x, int y, int k, VECTOR * mv, int fcode) |
420 |
{ |
{ |
421 |
|
|
422 |
int scale_fac = 1 << (fcode - 1); |
int scale_fac = 1 << (fcode - 1); |
423 |
int high = (32 * scale_fac) - 1; |
int high = (32 * scale_fac) - 1; |
424 |
int low = ((-32) * scale_fac); |
int low = ((-32) * scale_fac); |
468 |
|
|
469 |
void decoder_pframe(DECODER * dec, Bitstream * bs, int rounding, int quant, int fcode, int intra_dc_threshold) |
void decoder_pframe(DECODER * dec, Bitstream * bs, int rounding, int quant, int fcode, int intra_dc_threshold) |
470 |
{ |
{ |
471 |
|
|
472 |
uint32_t x, y; |
uint32_t x, y; |
473 |
|
|
474 |
image_swap(&dec->cur, &dec->refn); |
image_swap(&dec->cur, &dec->refn); |
621 |
|
|
622 |
int decoder_decode(DECODER * dec, XVID_DEC_FRAME * frame) |
int decoder_decode(DECODER * dec, XVID_DEC_FRAME * frame) |
623 |
{ |
{ |
624 |
|
|
625 |
Bitstream bs; |
Bitstream bs; |
626 |
uint32_t rounding; |
uint32_t rounding; |
627 |
uint32_t quant; |
uint32_t quant; |
665 |
stop_global_timer(); |
stop_global_timer(); |
666 |
|
|
667 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
668 |
|
|
669 |
} |
} |