3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Native API implementation - |
* - Native API implementation - |
5 |
* |
* |
|
* This program is an implementation of a part of one or more MPEG-4 |
|
|
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
|
|
* to use this software module in hardware or software products are |
|
|
* advised that its use may infringe existing patents or copyrights, and |
|
|
* any such use would be at such party's own risk. The original |
|
|
* developer of this software module and his/her company, and subsequent |
|
|
* editors and their companies, will have no liability for use of this |
|
|
* software or modifications or derivatives thereof. |
|
|
* |
|
6 |
* This program is free software ; you can redistribute it and/or modify |
* This program is free software ; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation ; either version 2 of the License, or |
* the Free Software Foundation ; either version 2 of the License, or |
17 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
* |
* |
20 |
****************************************************************************/ |
* $Id: xvid.c,v 1.45 2003-02-21 00:00:57 edgomez Exp $ |
|
|
|
|
/***************************************************************************** |
|
|
* |
|
|
* History |
|
|
* |
|
|
* - 23.06.2002 added XVID_CPU_CHKONLY |
|
|
* - 17.03.2002 Added interpolate8x8_halfpel_hv_xmm |
|
|
* - 22.12.2001 API change: added xvid_init() - Isibaar |
|
|
* - 16.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
|
|
* |
|
|
* $Id: xvid.c,v 1.42 2003-02-16 05:11:39 suxen_drol Exp $ |
|
21 |
* |
* |
22 |
****************************************************************************/ |
****************************************************************************/ |
23 |
|
|
64 |
|
|
65 |
|
|
66 |
/* |
/* |
67 |
calls the funcptr, and returns whether SIGILL (illegal instruction) was signalled |
* Calls the funcptr, and returns whether SIGILL (illegal instruction) was |
68 |
return values: |
* signalled |
69 |
-1 : could not determine |
* |
70 |
0 : SIGILL was *not* signalled |
* Return values: |
71 |
1 : SIGILL was signalled |
* -1 : could not determine |
72 |
|
* 0 : SIGILL was *not* signalled |
73 |
|
* 1 : SIGILL was signalled |
74 |
*/ |
*/ |
75 |
|
|
76 |
int |
int |
298 |
dev16 = dev16_c; |
dev16 = dev16_c; |
299 |
sad16v = sad16v_c; |
sad16v = sad16v_c; |
300 |
|
|
301 |
// Halfpel8_Refine = Halfpel8_Refine_c; |
/* Halfpel8_Refine = Halfpel8_Refine_c; */ |
302 |
|
|
303 |
#if defined(ARCH_IS_IA32) |
#if defined(ARCH_IS_IA32) |
304 |
|
|
508 |
#endif |
#endif |
509 |
|
|
510 |
#if defined(ARCH_IS_IA64) |
#if defined(ARCH_IS_IA64) |
511 |
if ((cpu_flags & XVID_CPU_ASM)) { //use assembler routines? |
if ((cpu_flags & XVID_CPU_ASM)) { /* use assembler routines? */ |
512 |
idct_ia64_init(); |
idct_ia64_init(); |
513 |
fdct = fdct_ia64; |
fdct = fdct_ia64; |
514 |
idct = idct_ia64; //not yet working, crashes |
idct = idct_ia64; /*not yet working, crashes */ |
515 |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64; |
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_ia64; |
516 |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64; |
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_ia64; |
517 |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64; |
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_ia64; |
519 |
sad16bi = sad16bi_ia64; |
sad16bi = sad16bi_ia64; |
520 |
sad8 = sad8_ia64; |
sad8 = sad8_ia64; |
521 |
dev16 = dev16_ia64; |
dev16 = dev16_ia64; |
522 |
// Halfpel8_Refine = Halfpel8_Refine_ia64; |
/* Halfpel8_Refine = Halfpel8_Refine_ia64; */ |
523 |
quant_intra = quant_intra_ia64; |
quant_intra = quant_intra_ia64; |
524 |
dequant_intra = dequant_intra_ia64; |
dequant_intra = dequant_intra_ia64; |
525 |
quant_inter = quant_inter_ia64; |
quant_inter = quant_inter_ia64; |
530 |
transfer_8to16sub2 = transfer_8to16sub2_ia64; |
transfer_8to16sub2 = transfer_8to16sub2_ia64; |
531 |
transfer_16to8add = transfer_16to8add_ia64; |
transfer_16to8add = transfer_16to8add_ia64; |
532 |
transfer8x8_copy = transfer8x8_copy_ia64; |
transfer8x8_copy = transfer8x8_copy_ia64; |
533 |
DEBUG("Using IA-64 assembler routines.\n"); |
DPRINTF(DPRINTF_DEBUG, "Using IA-64 assembler routines."); |
534 |
} |
} |
535 |
#endif |
#endif |
536 |
|
|
560 |
static int |
static int |
561 |
xvid_init_convert(XVID_INIT_CONVERTINFO* convert) |
xvid_init_convert(XVID_INIT_CONVERTINFO* convert) |
562 |
{ |
{ |
563 |
// const int flip1 = (convert->input.colorspace & XVID_CSP_VFLIP) ^ (convert->output.colorspace & XVID_CSP_VFLIP); |
/* |
564 |
|
const int flip1 = |
565 |
|
(convert->input.colorspace & XVID_CSP_VFLIP) ^ |
566 |
|
(convert->output.colorspace & XVID_CSP_VFLIP); |
567 |
|
*/ |
568 |
const int width = convert->width; |
const int width = convert->width; |
569 |
const int height = convert->height; |
const int height = convert->height; |
570 |
const int width2 = convert->width/2; |
const int width2 = convert->width/2; |
737 |
int64_t timeSTART; |
int64_t timeSTART; |
738 |
int64_t timeA = 0; |
int64_t timeA = 0; |
739 |
int64_t timeB = 0; |
int64_t timeB = 0; |
740 |
int retA, retB; |
int retA = 0, retB = 0; |
741 |
DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(arrayX, 1, 64, int16_t, CACHE_LINE); |
742 |
DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(arrayA, 1, 64, int16_t, CACHE_LINE); |
743 |
DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(arrayB, 1, 64, int16_t, CACHE_LINE); |
811 |
|
|
812 |
int xvid_init_test(int flags) |
int xvid_init_test(int flags) |
813 |
{ |
{ |
814 |
|
#if defined(ARCH_IS_IA32) |
815 |
int cpu_flags; |
int cpu_flags; |
816 |
|
#endif |
817 |
|
|
818 |
srand(time(0)); |
printf("XviD tests\n\n"); |
|
|
|
|
printf("xvid_init_test\n"); |
|
819 |
|
|
820 |
#if defined(ARCH_IS_IA32) |
#if defined(ARCH_IS_IA32) |
821 |
cpu_flags = detect_cpu_flags(); |
cpu_flags = detect_cpu_flags(); |
822 |
|
#endif |
823 |
|
|
824 |
idct_int32_init(); |
idct_int32_init(); |
825 |
emms_mmx(); |
emms(); |
826 |
|
|
827 |
|
srand(time(0)); |
828 |
|
|
829 |
|
/* fDCT test */ |
830 |
printf("--- fdct ---\n"); |
printf("--- fdct ---\n"); |
831 |
test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags); |
test_transform(fdct_int32, fdct_int32, "c", TEST_FDCT, flags); |
832 |
|
|
833 |
|
#if defined(ARCH_IS_IA32) |
834 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
835 |
test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags); |
test_transform(fdct_int32, fdct_mmx, "mmx", TEST_FDCT, flags); |
836 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
837 |
test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags); |
test_transform(fdct_int32, fdct_sse2, "sse2", TEST_FDCT, flags); |
838 |
|
#endif |
839 |
|
|
840 |
|
/* iDCT test */ |
841 |
printf("\n--- idct ---\n"); |
printf("\n--- idct ---\n"); |
842 |
test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags); |
test_transform(idct_int32, idct_int32, "c", TEST_IDCT, flags); |
843 |
|
|
844 |
|
#if defined(ARCH_IS_IA32) |
845 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
846 |
test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags); |
test_transform(idct_int32, idct_mmx, "mmx", TEST_IDCT, flags); |
847 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
850 |
test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags); |
test_transform(idct_int32, idct_3dne, "3dne", TEST_IDCT, flags); |
851 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
852 |
test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags); |
test_transform(idct_int32, idct_sse2, "sse2", TEST_IDCT, flags); |
853 |
|
#endif |
854 |
|
|
855 |
|
/* Intra quantization test */ |
856 |
printf("\n--- quant intra ---\n"); |
printf("\n--- quant intra ---\n"); |
857 |
test_quant(quant_intra_c, quant_intra_c, "c", TEST_QUANT_INTRA, flags); |
test_quant(quant_intra_c, quant_intra_c, "c", TEST_QUANT_INTRA, flags); |
858 |
|
|
859 |
|
#if defined(ARCH_IS_IA32) |
860 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
861 |
test_quant(quant_intra_c, quant_intra_mmx, "mmx", TEST_QUANT_INTRA, flags); |
test_quant(quant_intra_c, quant_intra_mmx, "mmx", TEST_QUANT_INTRA, flags); |
862 |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
863 |
test_quant(quant_intra_c, quant_intra_3dne, "3dne", TEST_QUANT_INTRA, flags); |
test_quant(quant_intra_c, quant_intra_3dne, "3dne", TEST_QUANT_INTRA, flags); |
864 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
865 |
test_quant(quant_intra_c, quant_intra_sse2, "sse2", TEST_QUANT_INTRA, flags); |
test_quant(quant_intra_c, quant_intra_sse2, "sse2", TEST_QUANT_INTRA, flags); |
866 |
|
#endif |
867 |
|
|
868 |
|
/* Inter quantization test */ |
869 |
printf("\n--- quant inter ---\n"); |
printf("\n--- quant inter ---\n"); |
870 |
test_quant(quant_inter_c, quant_inter_c, "c", TEST_QUANT_INTER, flags); |
test_quant(quant_inter_c, quant_inter_c, "c", TEST_QUANT_INTER, flags); |
871 |
|
|
872 |
|
#if defined(ARCH_IS_IA32) |
873 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
874 |
test_quant(quant_inter_c, quant_inter_mmx, "mmx", TEST_QUANT_INTER, flags); |
test_quant(quant_inter_c, quant_inter_mmx, "mmx", TEST_QUANT_INTER, flags); |
875 |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
876 |
test_quant(quant_inter_c, quant_inter_3dne, "3dne", TEST_QUANT_INTER, flags); |
test_quant(quant_inter_c, quant_inter_3dne, "3dne", TEST_QUANT_INTER, flags); |
877 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
878 |
test_quant(quant_inter_c, quant_inter_sse2, "sse2", TEST_QUANT_INTER, flags); |
test_quant(quant_inter_c, quant_inter_sse2, "sse2", TEST_QUANT_INTER, flags); |
879 |
|
#endif |
880 |
|
|
881 |
|
/* Intra dequantization test */ |
882 |
printf("\n--- dequant intra ---\n"); |
printf("\n--- dequant intra ---\n"); |
883 |
test_quant(dequant_intra_c, dequant_intra_c, "c", TEST_DEQUANT_INTRA, flags); |
test_quant(dequant_intra_c, dequant_intra_c, "c", TEST_DEQUANT_INTRA, flags); |
884 |
|
|
885 |
|
#if defined(ARCH_IS_IA32) |
886 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
887 |
test_quant(dequant_intra_c, dequant_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags); |
test_quant(dequant_intra_c, dequant_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags); |
888 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
891 |
test_quant(dequant_intra_c, dequant_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags); |
test_quant(dequant_intra_c, dequant_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags); |
892 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
893 |
test_quant(dequant_intra_c, dequant_intra_sse2, "sse2", TEST_DEQUANT_INTRA, flags); |
test_quant(dequant_intra_c, dequant_intra_sse2, "sse2", TEST_DEQUANT_INTRA, flags); |
894 |
|
#endif |
895 |
|
|
896 |
|
/* Inter dequantization test */ |
897 |
printf("\n--- dequant inter ---\n"); |
printf("\n--- dequant inter ---\n"); |
898 |
test_quant(dequant_inter_c, dequant_inter_c, "c", TEST_DEQUANT_INTER, flags); |
test_quant(dequant_inter_c, dequant_inter_c, "c", TEST_DEQUANT_INTER, flags); |
899 |
|
|
900 |
|
#if defined(ARCH_IS_IA32) |
901 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
902 |
test_quant(dequant_inter_c, dequant_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags); |
test_quant(dequant_inter_c, dequant_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags); |
903 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
906 |
test_quant(dequant_inter_c, dequant_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags); |
test_quant(dequant_inter_c, dequant_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags); |
907 |
if (cpu_flags & XVID_CPU_SSE2) |
if (cpu_flags & XVID_CPU_SSE2) |
908 |
test_quant(dequant_inter_c, dequant_inter_sse2, "sse2", TEST_DEQUANT_INTER, flags); |
test_quant(dequant_inter_c, dequant_inter_sse2, "sse2", TEST_DEQUANT_INTER, flags); |
909 |
|
#endif |
910 |
|
|
911 |
printf("\n--- quant4_intra ---\n"); |
/* Intra quantization test */ |
912 |
|
printf("\n--- quant4 intra ---\n"); |
913 |
test_quant(quant4_intra_c, quant4_intra_c, "c", TEST_QUANT_INTRA, flags); |
test_quant(quant4_intra_c, quant4_intra_c, "c", TEST_QUANT_INTRA, flags); |
914 |
|
|
915 |
|
#if defined(ARCH_IS_IA32) |
916 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
917 |
test_quant(quant4_intra_c, quant4_intra_mmx, "mmx", TEST_QUANT_INTRA, flags); |
test_quant(quant4_intra_c, quant4_intra_mmx, "mmx", TEST_QUANT_INTRA, flags); |
918 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
919 |
test_quant(quant4_intra_c, quant4_intra_xmm, "xmm", TEST_QUANT_INTRA, flags); |
test_quant(quant4_intra_c, quant4_intra_xmm, "xmm", TEST_QUANT_INTRA, flags); |
920 |
|
#endif |
921 |
|
|
922 |
printf("\n--- quant4_inter ---\n"); |
/* Inter quantization test */ |
923 |
|
printf("\n--- quant4 inter ---\n"); |
924 |
test_quant(quant4_inter_c, quant4_inter_c, "c", TEST_QUANT_INTER, flags); |
test_quant(quant4_inter_c, quant4_inter_c, "c", TEST_QUANT_INTER, flags); |
925 |
|
|
926 |
|
#if defined(ARCH_IS_IA32) |
927 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
928 |
test_quant(quant4_inter_c, quant4_inter_mmx, "mmx", TEST_QUANT_INTER, flags); |
test_quant(quant4_inter_c, quant4_inter_mmx, "mmx", TEST_QUANT_INTER, flags); |
929 |
if (cpu_flags & XVID_CPU_MMXEXT) |
if (cpu_flags & XVID_CPU_MMXEXT) |
930 |
test_quant(quant4_inter_c, quant4_inter_xmm, "xmm", TEST_QUANT_INTER, flags); |
test_quant(quant4_inter_c, quant4_inter_xmm, "xmm", TEST_QUANT_INTER, flags); |
931 |
|
#endif |
932 |
|
|
933 |
printf("\n--- dequant4_intra ---\n"); |
/* Intra dequantization test */ |
934 |
|
printf("\n--- dequant4 intra ---\n"); |
935 |
test_quant(dequant4_intra_c, dequant4_intra_c, "c", TEST_DEQUANT_INTRA, flags); |
test_quant(dequant4_intra_c, dequant4_intra_c, "c", TEST_DEQUANT_INTRA, flags); |
936 |
|
|
937 |
|
#if defined(ARCH_IS_IA32) |
938 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
939 |
test_quant(dequant4_intra_c, dequant4_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags); |
test_quant(dequant4_intra_c, dequant4_intra_mmx, "mmx", TEST_DEQUANT_INTRA, flags); |
940 |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
941 |
test_quant(dequant4_intra_c, dequant4_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags); |
test_quant(dequant4_intra_c, dequant4_intra_3dne, "3dne", TEST_DEQUANT_INTRA, flags); |
942 |
|
#endif |
943 |
|
|
944 |
printf("\n--- dequant4_inter ---\n"); |
/* Inter dequantization test */ |
945 |
|
printf("\n--- dequant4 inter ---\n"); |
946 |
test_quant(dequant4_inter_c, dequant4_inter_c, "c", TEST_DEQUANT_INTER, flags); |
test_quant(dequant4_inter_c, dequant4_inter_c, "c", TEST_DEQUANT_INTER, flags); |
947 |
|
|
948 |
|
#if defined(ARCH_IS_IA32) |
949 |
if (cpu_flags & XVID_CPU_MMX) |
if (cpu_flags & XVID_CPU_MMX) |
950 |
test_quant(dequant4_inter_c, dequant4_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags); |
test_quant(dequant4_inter_c, dequant4_inter_mmx, "mmx", TEST_DEQUANT_INTER, flags); |
951 |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
if (cpu_flags & XVID_CPU_3DNOWEXT) |
952 |
test_quant(dequant4_inter_c, dequant4_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags); |
test_quant(dequant4_inter_c, dequant4_inter_3dne, "3dne", TEST_DEQUANT_INTER, flags); |
|
|
|
|
emms_mmx(); |
|
|
|
|
953 |
#endif |
#endif |
954 |
|
|
955 |
|
emms(); |
956 |
|
|
957 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
958 |
} |
} |
959 |
|
|
973 |
return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1); |
return xvid_init_convert((XVID_INIT_CONVERTINFO*)param1); |
974 |
|
|
975 |
case XVID_INIT_TEST : |
case XVID_INIT_TEST : |
976 |
return xvid_init_test((int)param1); |
{ |
977 |
|
ptr_t flags = (ptr_t)param1; |
978 |
|
return xvid_init_test((int)flags); |
979 |
|
} |
980 |
default : |
default : |
981 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
982 |
} |
} |
1034 |
case XVID_ENC_ENCODE: |
case XVID_ENC_ENCODE: |
1035 |
|
|
1036 |
if (((Encoder *) handle)->mbParam.max_bframes >= 0) |
if (((Encoder *) handle)->mbParam.max_bframes >= 0) |
1037 |
return encoder_encode_bframes((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
return encoder_encode_bframes((Encoder *) handle, |
1038 |
|
(XVID_ENC_FRAME *) param1, |
1039 |
(XVID_ENC_STATS *) param2); |
(XVID_ENC_STATS *) param2); |
1040 |
else |
else |
1041 |
return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1, |
return encoder_encode((Encoder *) handle, |
1042 |
|
(XVID_ENC_FRAME *) param1, |
1043 |
(XVID_ENC_STATS *) param2); |
(XVID_ENC_STATS *) param2); |
1044 |
|
|
1045 |
case XVID_ENC_CREATE: |
case XVID_ENC_CREATE: |