41 |
* |
* |
42 |
****************************************************************************/ |
****************************************************************************/ |
43 |
|
|
44 |
|
#include <stdlib.h> |
45 |
|
#include <time.h> |
46 |
|
|
47 |
#include "xvid.h" |
#include "xvid.h" |
48 |
#include "decoder.h" |
#include "decoder.h" |
49 |
#include "encoder.h" |
#include "encoder.h" |
52 |
#include "dct/fdct.h" |
#include "dct/fdct.h" |
53 |
#include "image/colorspace.h" |
#include "image/colorspace.h" |
54 |
#include "image/interpolate8x8.h" |
#include "image/interpolate8x8.h" |
55 |
|
#include "image/reduced.h" |
56 |
#include "utils/mem_transfer.h" |
#include "utils/mem_transfer.h" |
57 |
|
#include "utils/mbfunctions.h" |
58 |
#include "quant/quant_h263.h" |
#include "quant/quant_h263.h" |
59 |
#include "quant/quant_mpeg4.h" |
#include "quant/quant_mpeg4.h" |
60 |
#include "motion/motion.h" |
#include "motion/motion.h" |
144 |
* |
* |
145 |
****************************************************************************/ |
****************************************************************************/ |
146 |
|
|
147 |
int |
|
148 |
xvid_init(void *handle, |
static |
149 |
int opt, |
int xvid_init_init(XVID_INIT_PARAM * init_param) |
|
void *param1, |
|
|
void *param2) |
|
150 |
{ |
{ |
151 |
int cpu_flags; |
int cpu_flags; |
|
XVID_INIT_PARAM *init_param; |
|
|
|
|
|
init_param = (XVID_INIT_PARAM *) param1; |
|
152 |
|
|
153 |
/* Inform the client the API version */ |
/* Inform the client the API version */ |
154 |
init_param->api_version = API_VERSION; |
init_param->api_version = API_VERSION; |
216 |
transfer_16to8add = transfer_16to8add_c; |
transfer_16to8add = transfer_16to8add_c; |
217 |
transfer8x8_copy = transfer8x8_copy_c; |
transfer8x8_copy = transfer8x8_copy_c; |
218 |
|
|
219 |
|
/* Interlacing functions */ |
220 |
|
MBFieldTest = MBFieldTest_c; |
221 |
|
|
222 |
/* Image interpolation related functions */ |
/* Image interpolation related functions */ |
223 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_c; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_c; |
224 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_c; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_c; |
225 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_c; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_c; |
226 |
|
|
227 |
|
interpolate16x16_lowpass_h = interpolate16x16_lowpass_h_c; |
228 |
|
interpolate16x16_lowpass_v = interpolate16x16_lowpass_v_c; |
229 |
|
interpolate16x16_lowpass_hv = interpolate16x16_lowpass_hv_c; |
230 |
|
|
231 |
|
interpolate8x8_lowpass_h = interpolate8x8_lowpass_h_c; |
232 |
|
interpolate8x8_lowpass_v = interpolate8x8_lowpass_v_c; |
233 |
|
interpolate8x8_lowpass_hv = interpolate8x8_lowpass_hv_c; |
234 |
|
|
235 |
|
interpolate8x8_6tap_lowpass_h = interpolate8x8_6tap_lowpass_h_c; |
236 |
|
interpolate8x8_6tap_lowpass_v = interpolate8x8_6tap_lowpass_v_c; |
237 |
|
|
238 |
|
interpolate8x8_avg2 = interpolate8x8_avg2_c; |
239 |
|
interpolate8x8_avg4 = interpolate8x8_avg4_c; |
240 |
|
|
241 |
|
/* reduced resoltuion */ |
242 |
|
|
243 |
|
copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_C; |
244 |
|
add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_C; |
245 |
|
#ifdef ARCH_X86 |
246 |
|
vfilter_31 = xvid_VFilter_31_x86; |
247 |
|
hfilter_31 = xvid_HFilter_31_x86; |
248 |
|
#else |
249 |
|
vfilter_31 = xvid_VFilter_31_C; |
250 |
|
hfilter_31 = xvid_HFilter_31_C; |
251 |
|
#endif |
252 |
|
filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_C; |
253 |
|
filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_C; |
254 |
|
|
255 |
/* Initialize internal colorspace transformation tables */ |
/* Initialize internal colorspace transformation tables */ |
256 |
colorspace_init(); |
colorspace_init(); |
257 |
|
|
258 |
/* All colorspace transformation functions User Format->YV12 */ |
/* All colorspace transformation functions User Format->YV12 */ |
259 |
|
yv12_to_yv12 = yv12_to_yv12_c; |
260 |
rgb555_to_yv12 = rgb555_to_yv12_c; |
rgb555_to_yv12 = rgb555_to_yv12_c; |
261 |
rgb565_to_yv12 = rgb565_to_yv12_c; |
rgb565_to_yv12 = rgb565_to_yv12_c; |
262 |
rgb24_to_yv12 = rgb24_to_yv12_c; |
bgr_to_yv12 = bgr_to_yv12_c; |
263 |
rgb32_to_yv12 = rgb32_to_yv12_c; |
bgra_to_yv12 = bgra_to_yv12_c; |
264 |
yuv_to_yv12 = yuv_to_yv12_c; |
abgr_to_yv12 = abgr_to_yv12_c; |
265 |
|
rgba_to_yv12 = rgba_to_yv12_c; |
266 |
yuyv_to_yv12 = yuyv_to_yv12_c; |
yuyv_to_yv12 = yuyv_to_yv12_c; |
267 |
uyvy_to_yv12 = uyvy_to_yv12_c; |
uyvy_to_yv12 = uyvy_to_yv12_c; |
268 |
|
|
269 |
|
rgb555i_to_yv12 = rgb555i_to_yv12_c; |
270 |
|
rgb565i_to_yv12 = rgb565i_to_yv12_c; |
271 |
|
bgri_to_yv12 = bgri_to_yv12_c; |
272 |
|
bgrai_to_yv12 = bgrai_to_yv12_c; |
273 |
|
abgri_to_yv12 = abgri_to_yv12_c; |
274 |
|
rgbai_to_yv12 = rgbai_to_yv12_c; |
275 |
|
yuyvi_to_yv12 = yuyvi_to_yv12_c; |
276 |
|
uyvyi_to_yv12 = uyvyi_to_yv12_c; |
277 |
|
|
278 |
|
|
279 |
/* All colorspace transformation functions YV12->User format */ |
/* All colorspace transformation functions YV12->User format */ |
280 |
yv12_to_rgb555 = yv12_to_rgb555_c; |
yv12_to_rgb555 = yv12_to_rgb555_c; |
281 |
yv12_to_rgb565 = yv12_to_rgb565_c; |
yv12_to_rgb565 = yv12_to_rgb565_c; |
282 |
yv12_to_rgb24 = yv12_to_rgb24_c; |
yv12_to_bgr = yv12_to_bgr_c; |
283 |
yv12_to_rgb32 = yv12_to_rgb32_c; |
yv12_to_bgra = yv12_to_bgra_c; |
284 |
yv12_to_yuv = yv12_to_yuv_c; |
yv12_to_abgr = yv12_to_abgr_c; |
285 |
|
yv12_to_rgba = yv12_to_rgba_c; |
286 |
yv12_to_yuyv = yv12_to_yuyv_c; |
yv12_to_yuyv = yv12_to_yuyv_c; |
287 |
yv12_to_uyvy = yv12_to_uyvy_c; |
yv12_to_uyvy = yv12_to_uyvy_c; |
288 |
|
|
289 |
|
yv12_to_rgb555i = yv12_to_rgb555i_c; |
290 |
|
yv12_to_rgb565i = yv12_to_rgb565i_c; |
291 |
|
yv12_to_bgri = yv12_to_bgri_c; |
292 |
|
yv12_to_bgrai = yv12_to_bgrai_c; |
293 |
|
yv12_to_abgri = yv12_to_abgri_c; |
294 |
|
yv12_to_rgbai = yv12_to_rgbai_c; |
295 |
|
yv12_to_yuyvi = yv12_to_yuyvi_c; |
296 |
|
yv12_to_uyvyi = yv12_to_uyvyi_c; |
297 |
|
|
298 |
/* Functions used in motion estimation algorithms */ |
/* Functions used in motion estimation algorithms */ |
299 |
calc_cbp = calc_cbp_c; |
calc_cbp = calc_cbp_c; |
300 |
sad16 = sad16_c; |
sad16 = sad16_c; |
307 |
// Halfpel8_Refine = Halfpel8_Refine_c; |
// Halfpel8_Refine = Halfpel8_Refine_c; |
308 |
|
|
309 |
#ifdef ARCH_X86 |
#ifdef ARCH_X86 |
310 |
|
|
311 |
|
if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) || |
312 |
|
(cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) || |
313 |
|
(cpu_flags & XVID_CPU_SSE) || (cpu_flags & XVID_CPU_SSE2)) |
314 |
|
{ |
315 |
|
/* Restore FPU context : emms_c is a nop functions */ |
316 |
|
emms = emms_mmx; |
317 |
|
} |
318 |
|
|
319 |
if ((cpu_flags & XVID_CPU_MMX) > 0) { |
if ((cpu_flags & XVID_CPU_MMX) > 0) { |
320 |
|
|
321 |
/* Forward and Inverse Discrete Cosine Transformation functions */ |
/* Forward and Inverse Discrete Cosine Transformation functions */ |
322 |
fdct = fdct_mmx; |
fdct = fdct_mmx; |
323 |
idct = idct_mmx; |
idct = idct_mmx; |
324 |
|
|
|
/* To restore FPU context after mmx use */ |
|
|
emms = emms_mmx; |
|
|
|
|
325 |
/* Quantization related functions */ |
/* Quantization related functions */ |
326 |
quant_intra = quant_intra_mmx; |
quant_intra = quant_intra_mmx; |
327 |
dequant_intra = dequant_intra_mmx; |
dequant_intra = dequant_intra_mmx; |
341 |
transfer_16to8add = transfer_16to8add_mmx; |
transfer_16to8add = transfer_16to8add_mmx; |
342 |
transfer8x8_copy = transfer8x8_copy_mmx; |
transfer8x8_copy = transfer8x8_copy_mmx; |
343 |
|
|
344 |
|
/* Interlacing Functions */ |
345 |
|
MBFieldTest = MBFieldTest_mmx; |
346 |
|
|
347 |
/* Image Interpolation related functions */ |
/* Image Interpolation related functions */ |
348 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx; |
349 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx; |
350 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_mmx; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_mmx; |
351 |
|
|
352 |
/* Image RGB->YV12 related functions */ |
interpolate8x8_6tap_lowpass_h = interpolate8x8_6tap_lowpass_h_mmx; |
353 |
rgb24_to_yv12 = rgb24_to_yv12_mmx; |
interpolate8x8_6tap_lowpass_v = interpolate8x8_6tap_lowpass_v_mmx; |
354 |
rgb32_to_yv12 = rgb32_to_yv12_mmx; |
|
355 |
yuv_to_yv12 = yuv_to_yv12_mmx; |
interpolate8x8_avg2 = interpolate8x8_avg2_mmx; |
356 |
|
interpolate8x8_avg4 = interpolate8x8_avg4_mmx; |
357 |
|
|
358 |
|
/* reduced resolution */ |
359 |
|
copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_mmx; |
360 |
|
add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_mmx; |
361 |
|
hfilter_31 = xvid_HFilter_31_mmx; |
362 |
|
filter_18x18_to_8x8 = xvid_Filter_18x18_To_8x8_mmx; |
363 |
|
filter_diff_18x18_to_8x8 = xvid_Filter_Diff_18x18_To_8x8_mmx; |
364 |
|
|
365 |
|
/* image input xxx_to_yv12 related functions */ |
366 |
|
yv12_to_yv12 = yv12_to_yv12_mmx; |
367 |
|
bgr_to_yv12 = bgr_to_yv12_mmx; |
368 |
|
bgra_to_yv12 = bgra_to_yv12_mmx; |
369 |
yuyv_to_yv12 = yuyv_to_yv12_mmx; |
yuyv_to_yv12 = yuyv_to_yv12_mmx; |
370 |
uyvy_to_yv12 = uyvy_to_yv12_mmx; |
uyvy_to_yv12 = uyvy_to_yv12_mmx; |
371 |
|
|
372 |
/* Image YV12->RGB related functions */ |
/* image output yv12_to_xxx related functions */ |
373 |
yv12_to_rgb24 = yv12_to_rgb24_mmx; |
yv12_to_bgr = yv12_to_bgr_mmx; |
374 |
yv12_to_rgb32 = yv12_to_rgb32_mmx; |
yv12_to_bgra = yv12_to_bgra_mmx; |
375 |
yv12_to_yuyv = yv12_to_yuyv_mmx; |
yv12_to_yuyv = yv12_to_yuyv_mmx; |
376 |
yv12_to_uyvy = yv12_to_uyvy_mmx; |
yv12_to_uyvy = yv12_to_uyvy_mmx; |
377 |
|
|
378 |
|
yv12_to_yuyvi = yv12_to_yuyvi_mmx; |
379 |
|
yv12_to_uyvyi = yv12_to_uyvyi_mmx; |
380 |
|
|
381 |
/* Motion estimation related functions */ |
/* Motion estimation related functions */ |
382 |
calc_cbp = calc_cbp_mmx; |
calc_cbp = calc_cbp_mmx; |
383 |
sad16 = sad16_mmx; |
sad16 = sad16_mmx; |
385 |
sad16bi = sad16bi_mmx; |
sad16bi = sad16bi_mmx; |
386 |
sad8bi = sad8bi_mmx; |
sad8bi = sad8bi_mmx; |
387 |
dev16 = dev16_mmx; |
dev16 = dev16_mmx; |
388 |
|
sad16v = sad16v_mmx; |
389 |
|
|
390 |
} |
} |
391 |
|
|
395 |
/* ME functions */ |
/* ME functions */ |
396 |
sad16bi = sad16bi_3dn; |
sad16bi = sad16bi_3dn; |
397 |
sad8bi = sad8bi_3dn; |
sad8bi = sad8bi_3dn; |
398 |
|
|
399 |
|
yuyv_to_yv12 = yuyv_to_yv12_3dn; |
400 |
|
uyvy_to_yv12 = uyvy_to_yv12_3dn; |
401 |
} |
} |
402 |
|
|
403 |
|
|
411 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm; |
412 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm; |
413 |
|
|
414 |
|
/* reduced resolution */ |
415 |
|
copy_upsampled_8x8_16to8 = xvid_Copy_Upsampled_8x8_16To8_xmm; |
416 |
|
add_upsampled_8x8_16to8 = xvid_Add_Upsampled_8x8_16To8_xmm; |
417 |
|
|
418 |
/* Quantization */ |
/* Quantization */ |
419 |
|
quant4_intra = quant4_intra_xmm; |
420 |
|
quant4_inter = quant4_inter_xmm; |
421 |
|
|
422 |
dequant_intra = dequant_intra_xmm; |
dequant_intra = dequant_intra_xmm; |
423 |
dequant_inter = dequant_inter_xmm; |
dequant_inter = dequant_inter_xmm; |
424 |
|
|
426 |
transfer_8to16sub2 = transfer_8to16sub2_xmm; |
transfer_8to16sub2 = transfer_8to16sub2_xmm; |
427 |
|
|
428 |
/* Colorspace transformation */ |
/* Colorspace transformation */ |
429 |
yuv_to_yv12 = yuv_to_yv12_xmm; |
yv12_to_yv12 = yv12_to_yv12_xmm; |
430 |
|
yuyv_to_yv12 = yuyv_to_yv12_xmm; |
431 |
|
uyvy_to_yv12 = uyvy_to_yv12_xmm; |
432 |
|
|
433 |
/* ME functions */ |
/* ME functions */ |
434 |
sad16 = sad16_xmm; |
sad16 = sad16_xmm; |
437 |
sad8bi = sad8bi_xmm; |
sad8bi = sad8bi_xmm; |
438 |
dev16 = dev16_xmm; |
dev16 = dev16_xmm; |
439 |
sad16v = sad16v_xmm; |
sad16v = sad16v_xmm; |
|
fprintf(stderr,"sad16v=XMM\n"); |
|
|
|
|
440 |
} |
} |
441 |
|
|
442 |
if ((cpu_flags & XVID_CPU_3DNOW) > 0) { |
if ((cpu_flags & XVID_CPU_3DNOW) > 0) { |
447 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn; |
448 |
} |
} |
449 |
|
|
450 |
|
if ((cpu_flags & XVID_CPU_3DNOWEXT) > 0) { |
451 |
|
|
452 |
|
/* Inverse DCT */ |
453 |
|
idct = idct_3dne; |
454 |
|
|
455 |
|
/* Buffer transfer */ |
456 |
|
transfer_8to16copy = transfer_8to16copy_3dne; |
457 |
|
transfer_16to8copy = transfer_16to8copy_3dne; |
458 |
|
transfer_8to16sub = transfer_8to16sub_3dne; |
459 |
|
transfer_8to16sub2 = transfer_8to16sub2_3dne; |
460 |
|
transfer_16to8add = transfer_16to8add_3dne; |
461 |
|
transfer8x8_copy = transfer8x8_copy_3dne; |
462 |
|
|
463 |
|
/* Quantization */ |
464 |
|
dequant4_intra = dequant4_intra_3dne; |
465 |
|
dequant4_inter = dequant4_inter_3dne; |
466 |
|
quant_intra = quant_intra_3dne; |
467 |
|
quant_inter = quant_inter_3dne; |
468 |
|
dequant_intra = dequant_intra_3dne; |
469 |
|
dequant_inter = dequant_inter_3dne; |
470 |
|
|
471 |
|
/* ME functions */ |
472 |
|
calc_cbp = calc_cbp_3dne; |
473 |
|
sad16 = sad16_3dne; |
474 |
|
sad8 = sad8_3dne; |
475 |
|
sad16bi = sad16bi_3dne; |
476 |
|
sad8bi = sad8bi_3dne; |
477 |
|
dev16 = dev16_3dne; |
478 |
|
|
479 |
|
/* Interpolation */ |
480 |
|
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dne; |
481 |
|
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dne; |
482 |
|
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dne; |
483 |
|
} |
484 |
|
|
485 |
|
|
486 |
if ((cpu_flags & XVID_CPU_SSE2) > 0) { |
if ((cpu_flags & XVID_CPU_SSE2) > 0) { |
487 |
#ifdef EXPERIMENTAL_SSE2_CODE |
#ifdef EXPERIMENTAL_SSE2_CODE |
488 |
|
|
550 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
551 |
} |
} |
552 |
|
|
553 |
|
|
554 |
|
|
555 |
|
static int |
556 |
|
xvid_init_convert(XVID_INIT_CONVERTINFO* convert) |
557 |
|
{ |
558 |
|
// const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP); |
559 |
|
const int width = convert->width; |
560 |
|
const int height = convert->height; |
561 |
|
const int width2 = convert->width/2; |
562 |
|
const int height2 = convert->height/2; |
563 |
|
IMAGE img; |
564 |
|
|
565 |
|
switch (convert->input.colorspace & ~XVID_CSP_VFLIP) |
566 |
|
{ |
567 |
|
case XVID_CSP_YV12 : |
568 |
|
img.y = convert->input.y; |
569 |
|
img.v = (uint8_t*)convert->input.y + width*height; |
570 |
|
img.u = (uint8_t*)convert->input.y + width*height + width2*height2; |
571 |
|
image_output(&img, width, height, width, |
572 |
|
convert->output.y, convert->output.y_stride, |
573 |
|
convert->output.colorspace, convert->interlacing); |
574 |
|
break; |
575 |
|
|
576 |
|
default : |
577 |
|
return XVID_ERR_FORMAT; |
578 |
|
} |
579 |
|
|
580 |
|
|
581 |
|
emms(); |
582 |
|
return XVID_ERR_OK; |
583 |
|
} |
584 |
|
|
585 |
|
|
586 |
|
|
587 |
|
void fill8(uint8_t * block, int size, int value) |
588 |
|
{ |
589 |
|
int i; |
590 |
|
for (i = 0; i < size; i++) |
591 |
|
block[i] = value; |
592 |
|
} |
593 |
|
|
594 |
|
void fill16(int16_t * block, int size, int value) |
595 |
|
{ |
596 |
|
int i; |
597 |
|
for (i = 0; i < size; i++) |
598 |
|
block[i] = value; |
599 |
|
} |
600 |
|
|
601 |
|
#define RANDOM(min,max) min + (rand() % (max-min)) |
602 |
|
|
603 |
|
void random8(uint8_t * block, int size, int min, int max) |
604 |
|
{ |
605 |
|
int i; |
606 |
|
for (i = 0; i < size; i++) |
607 |
|
block[i] = RANDOM(min,max); |
608 |
|
} |
609 |
|
|
610 |
|
void random16(int16_t * block, int size, int min, int max) |
611 |
|
{ |
612 |
|
int i; |
613 |
|
for (i = 0; i < size; i++) |
614 |
|
block[i] = RANDOM(min,max); |
615 |
|
} |
616 |
|
|
617 |
|
int compare16(const int16_t * blockA, const int16_t * blockB, int size) |
618 |
|
{ |
619 |
|
int i; |
620 |
|
for (i = 0; i < size; i++) |
621 |
|
if (blockA[i] != blockB[i]) |
622 |
|
return 1; |
623 |
|
|
624 |
|
return 0; |
625 |
|
} |
626 |
|
|
627 |
|
int diff16(const int16_t * blockA, const int16_t * blockB, int size) |
628 |
|
{ |
629 |
|
int i, diff = 0; |
630 |
|
for (i = 0; i < size; i++) |
631 |
|
diff += ABS(blockA[i]-blockB[i]); |
632 |
|
return diff; |
633 |
|
} |
634 |
|
|
635 |
|
|
636 |
|
#define XVID_TEST_RANDOM 0x00000001 /* random input data */ |
637 |
|
#define XVID_TEST_VERBOSE 0x00000002 /* verbose error output */ |
638 |
|
|
639 |
|
|
640 |
|
#define TEST_FORWARD 0x00000001 /* intra */ |
641 |
|
#define TEST_FDCT (TEST_FORWARD) |
642 |
|
#define TEST_IDCT (0) |
643 |
|
|
644 |
|
int test_transform(void * funcA, void * funcB, const char * nameB, |
645 |
|
int test, int flags) |
646 |
|
{ |
647 |
|
int i; |
648 |
|
int64_t timeSTART; |
649 |
|
int64_t timeA = 0; |
650 |
|
int64_t timeB = 0; |
651 |
|
DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); |
652 |
|
DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); |
653 |
|
int min, max; |
654 |
|
int count = 0; |
655 |
|
|
656 |
|
int tmp; |
657 |
|
int min_error = 0x10000*64; |
658 |
|
int max_error = 0; |
659 |
|
|
660 |
|
|
661 |
|
if ((test & TEST_FORWARD)) /* forward */ |
662 |
|
{ |
663 |
|
min = -256; |
664 |
|
max = 255; |
665 |
|
}else{ /* inverse */ |
666 |
|
min = -2048; |
667 |
|
max = 2047; |
668 |
|
} |
669 |
|
|
670 |
|
for (i = 0; i < 64*64; i++) |
671 |
|
{ |
672 |
|
if ((flags & XVID_TEST_RANDOM)) |
673 |
|
{ |
674 |
|
random16(arrayA, 64, min, max); |
675 |
|
}else{ |
676 |
|
fill16(arrayA, 64, i); |
677 |
|
} |
678 |
|
memcpy(arrayB, arrayA, 64*sizeof(int16_t)); |
679 |
|
|
680 |
|
if ((test & TEST_FORWARD)) |
681 |
|
{ |
682 |
|
timeSTART = read_counter(); |
683 |
|
((fdctFunc*)funcA)(arrayA); |
684 |
|
timeA += read_counter() - timeSTART; |
685 |
|
|
686 |
|
timeSTART = read_counter(); |
687 |
|
((fdctFunc*)funcB)(arrayB); |
688 |
|
timeB += read_counter() - timeSTART; |
689 |
|
} |
690 |
|
else |
691 |
|
{ |
692 |
|
timeSTART = read_counter(); |
693 |
|
((idctFunc*)funcA)(arrayA); |
694 |
|
timeA += read_counter() - timeSTART; |
695 |
|
|
696 |
|
timeSTART = read_counter(); |
697 |
|
((idctFunc*)funcB)(arrayB); |
698 |
|
timeB += read_counter() - timeSTART; |
699 |
|
} |
700 |
|
|
701 |
|
tmp = diff16(arrayA, arrayB, 64) / 64; |
702 |
|
if (tmp > max_error) |
703 |
|
max_error = tmp; |
704 |
|
if (tmp < min_error) |
705 |
|
min_error = tmp; |
706 |
|
|
707 |
|
count++; |
708 |
|
} |
709 |
|
|
710 |
|
/* print the "average difference" of best/worst transforms */ |
711 |
|
printf("%s:\t%I64i\t(min_error:%i, max_error:%i)\n", nameB, timeB / count, min_error, max_error); |
712 |
|
|
713 |
|
return 0; |
714 |
|
} |
715 |
|
|
716 |
|
|
717 |
|
#define TEST_QUANT 0x00000001 /* forward quantization */ |
718 |
|
#define TEST_INTRA 0x00000002 /* intra */ |
719 |
|
#define TEST_QUANT_INTRA (TEST_QUANT|TEST_INTRA) |
720 |
|
#define TEST_QUANT_INTER (TEST_QUANT) |
721 |
|
#define TEST_DEQUANT_INTRA (TEST_INTRA) |
722 |
|
#define TEST_DEQUANT_INTER (0) |
723 |
|
|
724 |
|
int test_quant(void * funcA, void * funcB, const char * nameB, |
725 |
|
int test, int flags) |
726 |
|
{ |
727 |
|
int q,i; |
728 |
|
int64_t timeSTART; |
729 |
|
int64_t timeA = 0; |
730 |
|
int64_t timeB = 0; |
731 |
|
int retA, retB; |
732 |
|
DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE); |
733 |
|
DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); |
734 |
|
DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); |
735 |
|
int min, max; |
736 |
|
int count = 0; |
737 |
|
int errors = 0; |
738 |
|
|
739 |
|
if ((test & TEST_QUANT)) /* quant */ |
740 |
|
{ |
741 |
|
min = -2048; |
742 |
|
max = 2047; |
743 |
|
}else{ /* dequant */ |
744 |
|
min = -256; |
745 |
|
max = 255; |
746 |
|
} |
747 |
|
|
748 |
|
for (q = 1; q <= 31; q++) /* quantizer */ |
749 |
|
{ |
750 |
|
for (i = min; i < max; i++) /* input coeff */ |
751 |
|
{ |
752 |
|
if ((flags & XVID_TEST_RANDOM)) |
753 |
|
{ |
754 |
|
random16(arrayX, 64, min, max); |
755 |
|
}else{ |
756 |
|
fill16(arrayX, 64, i); |
757 |
|
} |
758 |
|
|
759 |
|
if ((test & TEST_INTRA)) /* intra */ |
760 |
|
{ |
761 |
|
timeSTART = read_counter(); |
762 |
|
((quanth263_intraFunc*)funcA)(arrayA, arrayX, q, q); |
763 |
|
timeA += read_counter() - timeSTART; |
764 |
|
|
765 |
|
timeSTART = read_counter(); |
766 |
|
((quanth263_intraFunc*)funcB)(arrayB, arrayX, q, q); |
767 |
|
timeB += read_counter() - timeSTART; |
768 |
|
} |
769 |
|
else /* inter */ |
770 |
|
{ |
771 |
|
timeSTART = read_counter(); |
772 |
|
retA = ((quanth263_interFunc*)funcA)(arrayA, arrayX, q); |
773 |
|
timeA += read_counter() - timeSTART; |
774 |
|
|
775 |
|
timeSTART = read_counter(); |
776 |
|
retB = ((quanth263_interFunc*)funcB)(arrayB, arrayX, q); |
777 |
|
timeB += read_counter() - timeSTART; |
778 |
|
} |
779 |
|
|
780 |
|
/* compare return value from quant_inter, and compare (de)quantiz'd arrays */ |
781 |
|
if ( ((test&TEST_QUANT) && !(test&TEST_INTRA) && retA != retB ) || |
782 |
|
compare16(arrayA, arrayB, 64)) |
783 |
|
{ |
784 |
|
errors++; |
785 |
|
if ((flags & XVID_TEST_VERBOSE)) |
786 |
|
printf("%s error: q=%i, i=%i\n", nameB, q, i); |
787 |
|
} |
788 |
|
|
789 |
|
count++; |
790 |
|
} |
791 |
|
} |
792 |
|
|
793 |
|
printf("%s:\t%I64i", nameB, timeB / count); |
794 |
|
if (errors>0) |
795 |
|
printf("\t(%i errors out of %i)", errors, count); |
796 |
|
printf("\n"); |
797 |
|
|
798 |
|
return 0; |
799 |
|
} |
800 |
|
|
801 |
|
|
802 |
|
|
803 |
|
int xvid_init_test(int flags) |
804 |
|
{ |
805 |
|
int cpu_flags; |
806 |
|
|
807 |
|
srand(time(0)); |
808 |
|
|
809 |
|
printf("xvid_init_test\n"); |
810 |
|
|
811 |
|
#if defined(ARCH_X86) |
812 |
|
cpu_flags = check_cpu_features(); |
813 |
|
idct_int32_init(); |
814 |
|
emms_mmx(); |
815 |
|
|
816 |
|
printf("--- fdct ---\n"); |
817 |
|
test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags); |
818 |
|
if (cpu_flags & XVID_CPU_MMX) |
819 |
|
test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags); |
820 |
|
if (cpu_flags & XVID_CPU_SSE2) |
821 |
|
test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags); |
822 |
|
|
823 |
|
printf("\n--- idct ---\n"); |
824 |
|
test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags); |
825 |
|
if (cpu_flags & XVID_CPU_MMX) |
826 |
|
test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags); |
827 |
|
if (cpu_flags & XVID_CPU_MMXEXT) |
828 |
|
test_transform(idct_int32, idct_xmm, "xmm", TEST_IDCT, flags); |
829 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
830 |
|
test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags); |
831 |
|
if (cpu_flags & XVID_CPU_SSE2) |
832 |
|
test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags); |
833 |
|
|
834 |
|
printf("\n--- quant intra ---\n"); |
835 |
|
test_quant(quant_intra_c, quant_intra_c, "c", TEST_QUANT_INTRA, flags); |
836 |
|
if (cpu_flags & XVID_CPU_MMX) |
837 |
|
test_quant(quant_intra_c, quant_intra_mmx, "mmx", TEST_QUANT_INTRA, flags); |
838 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
839 |
|
test_quant(quant_intra_c, quant_intra_3dne, "3dne", TEST_QUANT_INTRA, flags); |
840 |
|
if (cpu_flags & XVID_CPU_SSE2) |
841 |
|
test_quant(quant_intra_c, quant_intra_sse2, "sse2", TEST_QUANT_INTRA, flags); |
842 |
|
|
843 |
|
printf("\n--- quant inter ---\n"); |
844 |
|
test_quant(quant_inter_c, quant_inter_c, "c", TEST_QUANT_INTER, flags); |
845 |
|
if (cpu_flags & XVID_CPU_MMX) |
846 |
|
test_quant(quant_inter_c, quant_inter_mmx, "mmx", TEST_QUANT_INTER, flags); |
847 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
848 |
|
test_quant(quant_inter_c, quant_inter_3dne, "3dne", TEST_QUANT_INTER, flags); |
849 |
|
if (cpu_flags & XVID_CPU_SSE2) |
850 |
|
test_quant(quant_inter_c, quant_inter_sse2, "sse2", TEST_QUANT_INTER, flags); |
851 |
|
|
852 |
|
printf("\n--- dequant intra ---\n"); |
853 |
|
test_quant(dequant_intra_c, dequant_intra_c, "c", TEST_DEQUANT_INTRA, flags); |
854 |
|
if (cpu_flags & XVID_CPU_MMX) |
855 |
|
test_quant(dequant_intra_c, dequant_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags); |
856 |
|
if (cpu_flags & XVID_CPU_MMXEXT) |
857 |
|
test_quant(dequant_intra_c, dequant_intra_xmm, "xmm", TEST_DEQUANT_INTRA, flags); |
858 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
859 |
|
test_quant(dequant_intra_c, dequant_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags); |
860 |
|
if (cpu_flags & XVID_CPU_SSE2) |
861 |
|
test_quant(dequant_intra_c, dequant_intra_sse2, "sse2", TEST_DEQUANT_INTRA, flags); |
862 |
|
|
863 |
|
printf("\n--- dequant inter ---\n"); |
864 |
|
test_quant(dequant_inter_c, dequant_inter_c, "c", TEST_DEQUANT_INTER, flags); |
865 |
|
if (cpu_flags & XVID_CPU_MMX) |
866 |
|
test_quant(dequant_inter_c, dequant_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags); |
867 |
|
if (cpu_flags & XVID_CPU_MMXEXT) |
868 |
|
test_quant(dequant_inter_c, dequant_inter_xmm, "xmm", TEST_DEQUANT_INTER, flags); |
869 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
870 |
|
test_quant(dequant_inter_c, dequant_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags); |
871 |
|
if (cpu_flags & XVID_CPU_SSE2) |
872 |
|
test_quant(dequant_inter_c, dequant_inter_sse2, "sse2", TEST_DEQUANT_INTER, flags); |
873 |
|
|
874 |
|
printf("\n--- quant4_intra ---\n"); |
875 |
|
test_quant(quant4_intra_c, quant4_intra_c, "c", TEST_QUANT_INTRA, flags); |
876 |
|
if (cpu_flags & XVID_CPU_MMX) |
877 |
|
test_quant(quant4_intra_c, quant4_intra_mmx, "mmx", TEST_QUANT_INTRA, flags); |
878 |
|
if (cpu_flags & XVID_CPU_MMXEXT) |
879 |
|
test_quant(quant4_intra_c, quant4_intra_xmm, "xmm", TEST_QUANT_INTRA, flags); |
880 |
|
|
881 |
|
printf("\n--- quant4_inter ---\n"); |
882 |
|
test_quant(quant4_inter_c, quant4_inter_c, "c", TEST_QUANT_INTER, flags); |
883 |
|
if (cpu_flags & XVID_CPU_MMX) |
884 |
|
test_quant(quant4_inter_c, quant4_inter_mmx, "mmx", TEST_QUANT_INTER, flags); |
885 |
|
if (cpu_flags & XVID_CPU_MMXEXT) |
886 |
|
test_quant(quant4_inter_c, quant4_inter_xmm, "xmm", TEST_QUANT_INTER, flags); |
887 |
|
|
888 |
|
printf("\n--- dequant4_intra ---\n"); |
889 |
|
test_quant(dequant4_intra_c, dequant4_intra_c, "c", TEST_DEQUANT_INTRA, flags); |
890 |
|
if (cpu_flags & XVID_CPU_MMX) |
891 |
|
test_quant(dequant4_intra_c, dequant4_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags); |
892 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
893 |
|
test_quant(dequant4_intra_c, dequant4_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags); |
894 |
|
|
895 |
|
printf("\n--- dequant4_inter ---\n"); |
896 |
|
test_quant(dequant4_inter_c, dequant4_inter_c, "c", TEST_DEQUANT_INTER, flags); |
897 |
|
if (cpu_flags & XVID_CPU_MMX) |
898 |
|
test_quant(dequant4_inter_c, dequant4_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags); |
899 |
|
if (cpu_flags & XVID_CPU_3DNOWEXT) |
900 |
|
test_quant(dequant4_inter_c, dequant4_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags); |
901 |
|
|
902 |
|
emms_mmx(); |
903 |
|
|
904 |
|
#endif |
905 |
|
|
906 |
|
return XVID_ERR_OK; |
907 |
|
} |
908 |
|
|
909 |
|
|
910 |
|
int |
911 |
|
xvid_init(void *handle, |
912 |
|
int opt, |
913 |
|
void *param1, |
914 |
|
void *param2) |
915 |
|
{ |
916 |
|
switch(opt) |
917 |
|
{ |
918 |
|
case XVID_INIT_INIT : |
919 |
|
return xvid_init_init((XVID_INIT_PARAM*)param1); |
920 |
|
|
921 |
|
case XVID_INIT_CONVERT : |
922 |
|
return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1); |
923 |
|
|
924 |
|
case XVID_INIT_TEST : |
925 |
|
return xvid_init_test((int)param1); |
926 |
|
|
927 |
|
default : |
928 |
|
return XVID_ERR_FAIL; |
929 |
|
} |
930 |
|
} |
931 |
|
|
932 |
/***************************************************************************** |
/***************************************************************************** |
933 |
* XviD Native decoder entry point |
* XviD Native decoder entry point |
934 |
* |
* |
947 |
{ |
{ |
948 |
switch (opt) { |
switch (opt) { |
949 |
case XVID_DEC_DECODE: |
case XVID_DEC_DECODE: |
950 |
return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1); |
return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1, (XVID_DEC_STATS*) param2); |
951 |
|
|
952 |
case XVID_DEC_CREATE: |
case XVID_DEC_CREATE: |
953 |
return decoder_create((XVID_DEC_PARAM *) param1); |
return decoder_create((XVID_DEC_PARAM *) param1); |
979 |
{ |
{ |
980 |
switch (opt) { |
switch (opt) { |
981 |
case XVID_ENC_ENCODE: |
case XVID_ENC_ENCODE: |
982 |
#ifdef BFRAMES |
|
983 |
if (((Encoder *) handle)->mbParam.max_bframes >= 0) |
if (((Encoder *) handle)->mbParam.max_bframes >= 0) |
984 |
return encoder_encode_bframes((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
return encoder_encode_bframes((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
985 |
(XVID_ENC_STATS *) param2); |
(XVID_ENC_STATS *) param2); |
986 |
else |
else |
|
#endif |
|
987 |
return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
988 |
(XVID_ENC_STATS *) param2); |
(XVID_ENC_STATS *) param2); |
989 |
|
|