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.75 2008-11-26 01:04:34 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 |
} |
} |
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) |
#if defined(_WIN32) |
698 |
|
|
699 |
{ |
{ |
700 |
DWORD dwProcessAffinityMask, dwSystemAffinityMask; |
SYSTEM_INFO siSysInfo; |
701 |
if (GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR) &dwProcessAffinityMask, (PDWORD_PTR) &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 |
} |
} |
|
} |
|
|
#else |
|
704 |
|
|
705 |
#include <unistd.h> |
#elif defined(_SC_NPROCESSORS_CONF) /* should be available on Apple too actually */ |
706 |
|
|
707 |
info->num_threads = sysconf(_SC_NPROCESSORS_CONF); |
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; |