19 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
* |
* |
22 |
* $Id: xvid.c,v 1.74 2008-11-14 15:43:27 Isibaar Exp $ |
* $Id: xvid.c,v 1.82 2009-06-05 07:58:41 Isibaar Exp $ |
23 |
* |
* |
24 |
****************************************************************************/ |
****************************************************************************/ |
25 |
|
|
28 |
#include <string.h> |
#include <string.h> |
29 |
#include <time.h> |
#include <time.h> |
30 |
|
|
31 |
|
#if !defined(_WIN32) |
32 |
|
#include <unistd.h> |
33 |
|
#endif |
34 |
|
|
35 |
|
#if defined(__APPLE__) && defined(__MACH__) && !defined(_SC_NPROCESSORS_CONF) |
36 |
|
#include <sys/types.h> |
37 |
|
#include <sys/sysctl.h> |
38 |
|
#ifdef MAX |
39 |
|
#undef MAX |
40 |
|
#endif |
41 |
|
#ifdef MIN |
42 |
|
#undef MIN |
43 |
|
#endif |
44 |
|
#endif |
45 |
|
|
46 |
|
#if defined(__amigaos4__) |
47 |
|
#include <exec/exec.h> |
48 |
|
#include <proto/exec.h> |
49 |
|
#endif |
50 |
|
|
51 |
#include "xvid.h" |
#include "xvid.h" |
52 |
#include "decoder.h" |
#include "decoder.h" |
53 |
#include "encoder.h" |
#include "encoder.h" |
74 |
|
|
75 |
#if (defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64)) && defined(_MSC_VER) |
#if (defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64)) && defined(_MSC_VER) |
76 |
# include <windows.h> |
# include <windows.h> |
77 |
#elif defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64) || defined(ARCH_IS_PPC) |
#elif defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64) || (defined(ARCH_IS_PPC) && !defined(__amigaos4__)) |
78 |
# include <signal.h> |
# include <signal.h> |
79 |
# include <setjmp.h> |
# include <setjmp.h> |
80 |
|
|
87 |
} |
} |
88 |
#endif |
#endif |
89 |
|
|
|
|
|
90 |
/* |
/* |
91 |
* Calls the funcptr, and returns whether SIGILL (illegal instruction) was |
* Calls the funcptr, and returns whether SIGILL (illegal instruction) was |
92 |
* signalled |
* signalled |
109 |
} |
} |
110 |
return(0); |
return(0); |
111 |
} |
} |
112 |
#elif defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64) || defined(ARCH_IS_PPC) |
#elif defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64) || (defined(ARCH_IS_PPC) && !defined(__amigaos4__)) |
113 |
static int |
static int |
114 |
sigill_check(void (*func)()) |
sigill_check(void (*func)()) |
115 |
{ |
{ |
161 |
#endif |
#endif |
162 |
|
|
163 |
#if defined(ARCH_IS_PPC) |
#if defined(ARCH_IS_PPC) |
164 |
|
#if defined(__amigaos4__) |
165 |
|
{ |
166 |
|
uint32_t vector_unit = VECTORTYPE_NONE; |
167 |
|
IExec->GetCPUInfoTags(GCIT_VectorUnit, &vector_unit, TAG_END); |
168 |
|
if (vector_unit == VECTORTYPE_ALTIVEC) { |
169 |
|
cpu_flags |= XVID_CPU_ALTIVEC; |
170 |
|
} |
171 |
|
} |
172 |
|
#else |
173 |
if (!sigill_check(altivec_trigger)) |
if (!sigill_check(altivec_trigger)) |
174 |
cpu_flags |= XVID_CPU_ALTIVEC; |
cpu_flags |= XVID_CPU_ALTIVEC; |
175 |
#endif |
#endif |
176 |
|
#endif |
177 |
|
|
178 |
return cpu_flags; |
return cpu_flags; |
179 |
} |
} |
340 |
|
|
341 |
init_GMC(cpu_flags); |
init_GMC(cpu_flags); |
342 |
|
|
343 |
#if defined(ARCH_IS_IA32) |
#if defined(ARCH_IS_IA32) || defined(ARCH_IS_X86_64) |
344 |
|
|
345 |
if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) || |
if ((cpu_flags & XVID_CPU_MMX) || (cpu_flags & XVID_CPU_MMXEXT) || |
346 |
(cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) || |
(cpu_flags & XVID_CPU_3DNOW) || (cpu_flags & XVID_CPU_3DNOWEXT) || |
366 |
quant_h263_inter = quant_h263_inter_mmx; |
quant_h263_inter = quant_h263_inter_mmx; |
367 |
dequant_h263_intra = dequant_h263_intra_mmx; |
dequant_h263_intra = dequant_h263_intra_mmx; |
368 |
dequant_h263_inter = dequant_h263_inter_mmx; |
dequant_h263_inter = dequant_h263_inter_mmx; |
|
|
|
369 |
quant_mpeg_intra = quant_mpeg_intra_mmx; |
quant_mpeg_intra = quant_mpeg_intra_mmx; |
370 |
quant_mpeg_inter = quant_mpeg_inter_mmx; |
quant_mpeg_inter = quant_mpeg_inter_mmx; |
371 |
dequant_mpeg_intra = dequant_mpeg_intra_mmx; |
dequant_mpeg_intra = dequant_mpeg_intra_mmx; |
372 |
dequant_mpeg_inter = dequant_mpeg_inter_mmx; |
dequant_mpeg_inter = dequant_mpeg_inter_mmx; |
373 |
|
|
374 |
|
|
375 |
/* Block related functions */ |
/* Block related functions */ |
376 |
transfer_8to16copy = transfer_8to16copy_mmx; |
transfer_8to16copy = transfer_8to16copy_mmx; |
377 |
transfer_16to8copy = transfer_16to8copy_mmx; |
transfer_16to8copy = transfer_16to8copy_mmx; |
409 |
image_brightness = image_brightness_mmx; |
image_brightness = image_brightness_mmx; |
410 |
|
|
411 |
/* image input xxx_to_yv12 related functions */ |
/* image input xxx_to_yv12 related functions */ |
412 |
|
|
413 |
yv12_to_yv12 = yv12_to_yv12_mmx; |
yv12_to_yv12 = yv12_to_yv12_mmx; |
414 |
|
|
415 |
bgr_to_yv12 = bgr_to_yv12_mmx; |
bgr_to_yv12 = bgr_to_yv12_mmx; |
416 |
rgb_to_yv12 = rgb_to_yv12_mmx; |
rgb_to_yv12 = rgb_to_yv12_mmx; |
417 |
bgra_to_yv12 = bgra_to_yv12_mmx; |
bgra_to_yv12 = bgra_to_yv12_mmx; |
451 |
|
|
452 |
yuyv_to_yv12 = yuyv_to_yv12_3dn; |
yuyv_to_yv12 = yuyv_to_yv12_3dn; |
453 |
uyvy_to_yv12 = uyvy_to_yv12_3dn; |
uyvy_to_yv12 = uyvy_to_yv12_3dn; |
454 |
|
|
455 |
} |
} |
456 |
|
|
457 |
|
|
486 |
transfer_8to16sub2ro = transfer_8to16sub2ro_xmm; |
transfer_8to16sub2ro = transfer_8to16sub2ro_xmm; |
487 |
|
|
488 |
/* Colorspace transformation */ |
/* Colorspace transformation */ |
489 |
yv12_to_yv12 = yv12_to_yv12_xmm; |
/* yv12_to_yv12 = yv12_to_yv12_xmm; */ /* appears to be slow on many machines */ |
490 |
yuyv_to_yv12 = yuyv_to_yv12_xmm; |
yuyv_to_yv12 = yuyv_to_yv12_xmm; |
491 |
uyvy_to_yv12 = uyvy_to_yv12_xmm; |
uyvy_to_yv12 = uyvy_to_yv12_xmm; |
492 |
|
|
547 |
dequant_h263_inter = dequant_h263_inter_3dne; |
dequant_h263_inter = dequant_h263_inter_3dne; |
548 |
|
|
549 |
/* ME functions */ |
/* ME functions */ |
|
calc_cbp = calc_cbp_3dne; |
|
|
|
|
550 |
sad16 = sad16_3dne; |
sad16 = sad16_3dne; |
551 |
sad8 = sad8_3dne; |
sad8 = sad8_3dne; |
552 |
sad16bi = sad16bi_3dne; |
sad16bi = sad16bi_3dne; |
575 |
|
|
576 |
/* postprocessing */ |
/* postprocessing */ |
577 |
image_brightness = image_brightness_sse2; |
image_brightness = image_brightness_sse2; |
578 |
|
|
579 |
} |
} |
580 |
|
|
581 |
if ((cpu_flags & XVID_CPU_SSE3)) { |
if ((cpu_flags & XVID_CPU_SSE3)) { |
675 |
} |
} |
676 |
#endif |
#endif |
677 |
|
|
|
#if defined(ARCH_IS_X86_64) |
|
|
/* For now, only XVID_CPU_ASM is looked for, so user can still |
|
|
* disable asm usage the usual way. When Intel EMT64 cpus will |
|
|
* be out, maybe we'll have to check more precisely what cpu |
|
|
* features there really are. */ |
|
|
if (cpu_flags & XVID_CPU_ASM) { |
|
|
/* SIMD state flusher */ |
|
|
emms = emms_mmx; |
|
|
|
|
|
/* DCT operators */ |
|
|
fdct = fdct_skal_x86_64; |
|
|
idct = idct_x86_64; |
|
|
|
|
|
/* SAD operators */ |
|
|
sad16 = sad16_x86_64; |
|
|
sad8 = sad8_x86_64; |
|
|
sad16bi = sad16bi_x86_64; |
|
|
sad8bi = sad8bi_x86_64; |
|
|
dev16 = dev16_x86_64; |
|
|
sad16v = sad16v_x86_64; |
|
|
sse8_16bit = sse8_16bit_x86_64; |
|
|
sse8_8bit = sse8_8bit_x86_64; |
|
|
|
|
|
/* Interpolation operators */ |
|
|
interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_x86_64; |
|
|
interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_x86_64; |
|
|
interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_x86_64; |
|
|
|
|
|
interpolate8x8_halfpel_add = interpolate8x8_halfpel_add_x86_64; |
|
|
interpolate8x8_halfpel_h_add = interpolate8x8_halfpel_h_add_x86_64; |
|
|
interpolate8x8_halfpel_v_add = interpolate8x8_halfpel_v_add_x86_64; |
|
|
interpolate8x8_halfpel_hv_add = interpolate8x8_halfpel_hv_add_x86_64; |
|
|
|
|
|
interpolate8x8_6tap_lowpass_h = interpolate8x8_6tap_lowpass_h_x86_64; |
|
|
interpolate8x8_6tap_lowpass_v = interpolate8x8_6tap_lowpass_v_x86_64; |
|
|
|
|
|
interpolate8x8_avg2 = interpolate8x8_avg2_x86_64; |
|
|
interpolate8x8_avg4 = interpolate8x8_avg4_x86_64; |
|
|
|
|
|
/* Quantization related functions */ |
|
|
quant_h263_intra = quant_h263_intra_x86_64; |
|
|
quant_h263_inter = quant_h263_inter_x86_64; |
|
|
dequant_h263_intra = dequant_h263_intra_x86_64; |
|
|
dequant_h263_inter = dequant_h263_inter_x86_64; |
|
|
/*quant_mpeg_intra = quant_mpeg_intra_x86_64; fix me! */ |
|
|
quant_mpeg_inter = quant_mpeg_inter_x86_64; |
|
|
dequant_mpeg_intra = dequant_mpeg_intra_x86_64; |
|
|
dequant_mpeg_inter = dequant_mpeg_inter_x86_64; |
|
|
|
|
|
/* Block related functions */ |
|
|
transfer_8to16copy = transfer_8to16copy_x86_64; |
|
|
transfer_16to8copy = transfer_16to8copy_x86_64; |
|
|
transfer_8to16sub = transfer_8to16sub_x86_64; |
|
|
transfer_8to16subro = transfer_8to16subro_x86_64; |
|
|
transfer_8to16sub2 = transfer_8to16sub2_x86_64; |
|
|
transfer_8to16sub2ro= transfer_8to16sub2ro_x86_64; |
|
|
transfer_16to8add = transfer_16to8add_x86_64; |
|
|
transfer8x8_copy = transfer8x8_copy_x86_64; |
|
|
|
|
|
/* Qpel stuff */ |
|
|
xvid_QP_Funcs = &xvid_QP_Funcs_x86_64; |
|
|
xvid_QP_Add_Funcs = &xvid_QP_Add_Funcs_x86_64; |
|
|
|
|
|
/* Interlacing Functions */ |
|
|
MBFieldTest = MBFieldTest_x86_64; |
|
|
} |
|
|
#endif |
|
|
|
|
678 |
#if defined(_DEBUG) |
#if defined(_DEBUG) |
679 |
xvid_debug = init->debug; |
xvid_debug = init->debug; |
680 |
#endif |
#endif |
690 |
return XVID_ERR_VERSION; |
return XVID_ERR_VERSION; |
691 |
|
|
692 |
info->actual_version = XVID_VERSION; |
info->actual_version = XVID_VERSION; |
693 |
info->build = "xvid-1.2.0-dev"; |
info->build = "xvid-1.3.0-dev"; |
694 |
info->cpu_flags = detect_cpu_flags(); |
info->cpu_flags = detect_cpu_flags(); |
695 |
info->num_threads = 0; |
info->num_threads = 0; /* single-thread */ |
696 |
|
|
697 |
|
#if defined(_WIN32) |
698 |
|
|
|
#if defined(WIN32) |
|
699 |
{ |
{ |
700 |
DWORD dwProcessAffinityMask, dwSystemAffinityMask; |
SYSTEM_INFO siSysInfo; |
701 |
if (GetProcessAffinityMask(GetCurrentProcess(), &dwProcessAffinityMask, &dwSystemAffinityMask)) { |
GetSystemInfo(&siSysInfo); |
702 |
int i; |
info->num_threads = siSysInfo.dwNumberOfProcessors; /* number of _logical_ cores */ |
|
for(i=0; i<32; i++) { |
|
|
if ((dwProcessAffinityMask & (1<<i))) |
|
|
info->num_threads++; |
|
703 |
} |
} |
704 |
|
|
705 |
|
#elif defined(_SC_NPROCESSORS_CONF) /* should be available on Apple too actually */ |
706 |
|
|
707 |
|
info->num_threads = sysconf(_SC_NPROCESSORS_CONF); |
708 |
|
|
709 |
|
#elif defined(__APPLE__) && defined(__MACH__) |
710 |
|
|
711 |
|
{ |
712 |
|
size_t len; |
713 |
|
int mib[2], ncpu; |
714 |
|
|
715 |
|
mib[0] = CTL_HW; |
716 |
|
mib[1] = HW_NCPU; |
717 |
|
len = sizeof(ncpu); |
718 |
|
if (sysctl(mib, 2, &ncpu, &len, NULL, 0) == 0) |
719 |
|
info -> num_threads = ncpu; |
720 |
|
else |
721 |
|
info -> num_threads = 1; |
722 |
} |
} |
723 |
|
|
724 |
|
#elif defined(__amigaos4__) |
725 |
|
|
726 |
|
{ |
727 |
|
uint32_t num_threads = 1; |
728 |
|
IExec->GetCPUInfoTags(GCIT_NumberOfCPUs, &num_threads, TAG_END); |
729 |
|
info->num_threads = num_threads; |
730 |
} |
} |
731 |
|
|
732 |
#endif |
#endif |
733 |
|
|
734 |
return 0; |
return 0; |