4 |
* - Native API implementation - |
* - Native API implementation - |
5 |
* |
* |
6 |
* Copyright(C) 2001-2004 Peter Ross <pross@xvid.org> |
* Copyright(C) 2001-2004 Peter Ross <pross@xvid.org> |
7 |
|
* 2002-2010 Michael Militzer <isibaar@xvid.org> |
8 |
* |
* |
9 |
* This program is free software ; you can redistribute it and/or modify |
* This program is free software ; you can redistribute it and/or modify |
10 |
* 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 |
29 |
#include <string.h> |
#include <string.h> |
30 |
#include <time.h> |
#include <time.h> |
31 |
|
|
32 |
|
#if !defined(_WIN32) |
33 |
|
#include <unistd.h> |
34 |
|
#endif |
35 |
|
|
36 |
|
#if defined(__APPLE__) && defined(__MACH__) && !defined(_SC_NPROCESSORS_CONF) |
37 |
|
#include <sys/types.h> |
38 |
|
#include <sys/sysctl.h> |
39 |
|
#ifdef MAX |
40 |
|
#undef MAX |
41 |
|
#endif |
42 |
|
#ifdef MIN |
43 |
|
#undef MIN |
44 |
|
#endif |
45 |
|
#endif |
46 |
|
|
47 |
|
#if defined(__amigaos4__) |
48 |
|
#include <exec/exec.h> |
49 |
|
#include <proto/exec.h> |
50 |
|
#endif |
51 |
|
|
52 |
#include "xvid.h" |
#include "xvid.h" |
53 |
#include "decoder.h" |
#include "decoder.h" |
54 |
#include "encoder.h" |
#include "encoder.h" |
75 |
|
|
76 |
#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) |
77 |
# include <windows.h> |
# include <windows.h> |
78 |
#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__)) |
79 |
# include <signal.h> |
# include <signal.h> |
80 |
# include <setjmp.h> |
# include <setjmp.h> |
81 |
|
|
88 |
} |
} |
89 |
#endif |
#endif |
90 |
|
|
|
|
|
91 |
/* |
/* |
92 |
* Calls the funcptr, and returns whether SIGILL (illegal instruction) was |
* Calls the funcptr, and returns whether SIGILL (illegal instruction) was |
93 |
* signalled |
* signalled |
110 |
} |
} |
111 |
return(0); |
return(0); |
112 |
} |
} |
113 |
#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__)) |
114 |
static int |
static int |
115 |
sigill_check(void (*func)()) |
sigill_check(void (*func)()) |
116 |
{ |
{ |
162 |
#endif |
#endif |
163 |
|
|
164 |
#if defined(ARCH_IS_PPC) |
#if defined(ARCH_IS_PPC) |
165 |
|
#if defined(__amigaos4__) |
166 |
|
{ |
167 |
|
uint32_t vector_unit = VECTORTYPE_NONE; |
168 |
|
IExec->GetCPUInfoTags(GCIT_VectorUnit, &vector_unit, TAG_END); |
169 |
|
if (vector_unit == VECTORTYPE_ALTIVEC) { |
170 |
|
cpu_flags |= XVID_CPU_ALTIVEC; |
171 |
|
} |
172 |
|
} |
173 |
|
#else |
174 |
if (!sigill_check(altivec_trigger)) |
if (!sigill_check(altivec_trigger)) |
175 |
cpu_flags |= XVID_CPU_ALTIVEC; |
cpu_flags |= XVID_CPU_ALTIVEC; |
176 |
#endif |
#endif |
177 |
|
#endif |
178 |
|
|
179 |
return cpu_flags; |
return cpu_flags; |
180 |
} |
} |
181 |
|
|
182 |
|
|
183 |
/***************************************************************************** |
/***************************************************************************** |
184 |
* XviD Init Entry point |
* Xvid Init Entry point |
185 |
* |
* |
186 |
* Well this function initialize all internal function pointers according |
* Well this function initialize all internal function pointers according |
187 |
* to the CPU features forced by the library client or autodetected (depending |
* to the CPU features forced by the library client or autodetected (depending |
693 |
info->actual_version = XVID_VERSION; |
info->actual_version = XVID_VERSION; |
694 |
info->build = "xvid-1.3.0-dev"; |
info->build = "xvid-1.3.0-dev"; |
695 |
info->cpu_flags = detect_cpu_flags(); |
info->cpu_flags = detect_cpu_flags(); |
696 |
info->num_threads = 0; |
info->num_threads = 0; /* single-thread */ |
697 |
|
|
698 |
#if defined(_WIN32) |
#if defined(_WIN32) |
699 |
|
|
703 |
info->num_threads = siSysInfo.dwNumberOfProcessors; /* number of _logical_ cores */ |
info->num_threads = siSysInfo.dwNumberOfProcessors; /* number of _logical_ cores */ |
704 |
} |
} |
705 |
|
|
706 |
#else |
#elif defined(_SC_NPROCESSORS_CONF) /* should be available on Apple too actually */ |
707 |
|
|
|
#include <unistd.h> |
|
708 |
info->num_threads = sysconf(_SC_NPROCESSORS_CONF); |
info->num_threads = sysconf(_SC_NPROCESSORS_CONF); |
709 |
|
|
710 |
|
#elif defined(__APPLE__) && defined(__MACH__) |
711 |
|
|
712 |
|
{ |
713 |
|
size_t len; |
714 |
|
int mib[2], ncpu; |
715 |
|
|
716 |
|
mib[0] = CTL_HW; |
717 |
|
mib[1] = HW_NCPU; |
718 |
|
len = sizeof(ncpu); |
719 |
|
if (sysctl(mib, 2, &ncpu, &len, NULL, 0) == 0) |
720 |
|
info -> num_threads = ncpu; |
721 |
|
else |
722 |
|
info -> num_threads = 1; |
723 |
|
} |
724 |
|
|
725 |
|
#elif defined(__amigaos4__) |
726 |
|
|
727 |
|
{ |
728 |
|
uint32_t num_threads = 1; |
729 |
|
IExec->GetCPUInfoTags(GCIT_NumberOfCPUs, &num_threads, TAG_END); |
730 |
|
info->num_threads = num_threads; |
731 |
|
} |
732 |
|
|
733 |
#endif |
#endif |
734 |
|
|
735 |
return 0; |
return 0; |
777 |
} |
} |
778 |
|
|
779 |
/***************************************************************************** |
/***************************************************************************** |
780 |
* XviD Global Entry point |
* Xvid Global Entry point |
781 |
* |
* |
782 |
* Well this function initialize all internal function pointers according |
* Well this function initialize all internal function pointers according |
783 |
* to the CPU features forced by the library client or autodetected (depending |
* to the CPU features forced by the library client or autodetected (depending |
810 |
} |
} |
811 |
|
|
812 |
/***************************************************************************** |
/***************************************************************************** |
813 |
* XviD Native decoder entry point |
* Xvid Native decoder entry point |
814 |
* |
* |
815 |
* This function is just a wrapper to all the option cases. |
* This function is just a wrapper to all the option cases. |
816 |
* |
* |
842 |
|
|
843 |
|
|
844 |
/***************************************************************************** |
/***************************************************************************** |
845 |
* XviD Native encoder entry point |
* Xvid Native encoder entry point |
846 |
* |
* |
847 |
* This function is just a wrapper to all the option cases. |
* This function is just a wrapper to all the option cases. |
848 |
* |
* |