1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "config.h"
20
21 #if HAVE_SCHED_GETAFFINITY
22 #ifndef _GNU_SOURCE
23 # define _GNU_SOURCE
24 #endif
25 #include <sched.h>
26 #endif
27
28 #include <stddef.h>
29 #include <stdint.h>
30 #include <stdatomic.h>
31
37
38 #if HAVE_GETPROCESSAFFINITYMASK || HAVE_WINRT
39 #include <windows.h>
40 #endif
41 #if HAVE_SYSCTL
42 #if HAVE_SYS_PARAM_H
43 #include <sys/param.h>
44 #endif
45 #include <sys/types.h>
46 #include <sys/sysctl.h>
47 #endif
48 #if HAVE_UNISTD_H
49 #include <unistd.h>
50 #endif
51
54
56 {
57 #if ARCH_MIPS
59 #elif ARCH_AARCH64
61 #elif ARCH_ARM
63 #elif ARCH_PPC
65 #elif ARCH_RISCV
67 #elif ARCH_X86
69 #elif ARCH_LOONGARCH
71 #endif
72 return 0;
73 }
74
76 if (ARCH_X86 &&
98 }
99
101 }
102
104 {
109 }
111 }
112
114 {
115 static const AVOption cpuflags_opts[] = {
117 #if ARCH_PPC
119 #elif ARCH_X86
147
148 #define CPU_FLAG_P2 AV_CPU_FLAG_CMOV | AV_CPU_FLAG_MMX
149 #define CPU_FLAG_P3 CPU_FLAG_P2 | AV_CPU_FLAG_MMX2 | AV_CPU_FLAG_SSE
150 #define CPU_FLAG_P4 CPU_FLAG_P3| AV_CPU_FLAG_SSE2
154
155 #define CPU_FLAG_K62 AV_CPU_FLAG_MMX | AV_CPU_FLAG_3DNOW
156 #define CPU_FLAG_ATHLON CPU_FLAG_K62 | AV_CPU_FLAG_CMOV | AV_CPU_FLAG_3DNOWEXT | AV_CPU_FLAG_MMX2
157 #define CPU_FLAG_ATHLONXP CPU_FLAG_ATHLON | AV_CPU_FLAG_SSE
158 #define CPU_FLAG_K8 CPU_FLAG_ATHLONXP | AV_CPU_FLAG_SSE2
164 #elif ARCH_ARM
173 #elif ARCH_AARCH64
179 #elif ARCH_MIPS
182 #elif ARCH_LOONGARCH
185 #elif ARCH_RISCV
195 #endif
197 };
201 .option = cpuflags_opts,
203 };
204 const AVClass *pclass = &
class;
205
207 }
208
210 {
212
213 int nb_cpus = 1;
214 int count = 0;
215 #if HAVE_WINRT
216 SYSTEM_INFO sysinfo;
217 #endif
218 #if HAVE_SCHED_GETAFFINITY && defined(CPU_COUNT)
219 cpu_set_t cpuset;
220
221 CPU_ZERO(&cpuset);
222
223 if (!sched_getaffinity(0, sizeof(cpuset), &cpuset))
224 nb_cpus = CPU_COUNT(&cpuset);
225 #elif HAVE_GETPROCESSAFFINITYMASK
226 DWORD_PTR proc_aff, sys_aff;
227 if (GetProcessAffinityMask(GetCurrentProcess(), &proc_aff, &sys_aff))
229 #elif HAVE_SYSCTL && defined(HW_NCPUONLINE)
230 int mib[2] = { CTL_HW, HW_NCPUONLINE };
231 size_t len =
sizeof(nb_cpus);
232
233 if (sysctl(mib, 2, &nb_cpus, &
len,
NULL, 0) == -1)
234 nb_cpus = 0;
235 #elif HAVE_SYSCTL && defined(HW_NCPU)
236 int mib[2] = { CTL_HW, HW_NCPU };
237 size_t len =
sizeof(nb_cpus);
238
239 if (sysctl(mib, 2, &nb_cpus, &
len,
NULL, 0) == -1)
240 nb_cpus = 0;
241 #elif HAVE_SYSCONF && defined(_SC_NPROC_ONLN)
242 nb_cpus = sysconf(_SC_NPROC_ONLN);
243 #elif HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN)
244 nb_cpus = sysconf(_SC_NPROCESSORS_ONLN);
245 #elif HAVE_WINRT
246 GetNativeSystemInfo(&sysinfo);
247 nb_cpus = sysinfo.dwNumberOfProcessors;
248 #endif
249
252
254
255 if (count > 0) {
256 nb_cpus = count;
258 }
259
260 return nb_cpus;
261 }
262
264 {
266 }
267
269 {
270 #if ARCH_MIPS
272 #elif ARCH_AARCH64
274 #elif ARCH_ARM
276 #elif ARCH_PPC
278 #elif ARCH_X86
280 #elif ARCH_LOONGARCH
282 #endif
283
284 return 8;
285 }