LCOV - code coverage report
Current view: top level - src/libavutil - cpu.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 23 34 67.6 %
Date: 2017-01-21 09:32:20 Functions: 5 7 71.4 %

          Line data    Source code
       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 <stdint.h>
      20             : #include <stdatomic.h>
      21             : 
      22             : #include "cpu.h"
      23             : #include "cpu_internal.h"
      24             : #include "config.h"
      25             : #include "opt.h"
      26             : #include "common.h"
      27             : 
      28             : #if HAVE_SCHED_GETAFFINITY
      29             : #ifndef _GNU_SOURCE
      30             : # define _GNU_SOURCE
      31             : #endif
      32             : #include <sched.h>
      33             : #endif
      34             : #if HAVE_GETPROCESSAFFINITYMASK || HAVE_WINRT
      35             : #include <windows.h>
      36             : #endif
      37             : #if HAVE_SYSCTL
      38             : #if HAVE_SYS_PARAM_H
      39             : #include <sys/param.h>
      40             : #endif
      41             : #include <sys/types.h>
      42             : #include <sys/sysctl.h>
      43             : #endif
      44             : #if HAVE_UNISTD_H
      45             : #include <unistd.h>
      46             : #endif
      47             : 
      48             : static atomic_int cpu_flags = ATOMIC_VAR_INIT(-1);
      49             : 
      50        5433 : static int get_cpu_flags(void)
      51             : {
      52             :     if (ARCH_AARCH64)
      53             :         return ff_get_cpu_flags_aarch64();
      54             :     if (ARCH_ARM)
      55             :         return ff_get_cpu_flags_arm();
      56             :     if (ARCH_PPC)
      57             :         return ff_get_cpu_flags_ppc();
      58             :     if (ARCH_X86)
      59        5433 :         return ff_get_cpu_flags_x86();
      60             :     return 0;
      61             : }
      62             : 
      63        5307 : void av_force_cpu_flags(int arg){
      64        5307 :     if (   (arg & ( AV_CPU_FLAG_3DNOW    |
      65             :                     AV_CPU_FLAG_3DNOWEXT |
      66             :                     AV_CPU_FLAG_MMXEXT   |
      67             :                     AV_CPU_FLAG_SSE      |
      68             :                     AV_CPU_FLAG_SSE2     |
      69             :                     AV_CPU_FLAG_SSE2SLOW |
      70             :                     AV_CPU_FLAG_SSE3     |
      71             :                     AV_CPU_FLAG_SSE3SLOW |
      72             :                     AV_CPU_FLAG_SSSE3    |
      73             :                     AV_CPU_FLAG_SSE4     |
      74             :                     AV_CPU_FLAG_SSE42    |
      75             :                     AV_CPU_FLAG_AVX      |
      76             :                     AV_CPU_FLAG_AVXSLOW  |
      77             :                     AV_CPU_FLAG_XOP      |
      78             :                     AV_CPU_FLAG_FMA3     |
      79             :                     AV_CPU_FLAG_FMA4     |
      80             :                     AV_CPU_FLAG_AVX2     ))
      81          33 :         && !(arg & AV_CPU_FLAG_MMX)) {
      82           0 :         av_log(NULL, AV_LOG_WARNING, "MMX implied by specified flags\n");
      83           0 :         arg |= AV_CPU_FLAG_MMX;
      84             :     }
      85             : 
      86        5307 :     atomic_store_explicit(&cpu_flags, arg, memory_order_relaxed);
      87        5307 : }
      88             : 
      89      127377 : int av_get_cpu_flags(void)
      90             : {
      91      127377 :     int flags = atomic_load_explicit(&cpu_flags, memory_order_relaxed);
      92      127377 :     if (flags == -1) {
      93        5433 :         flags = get_cpu_flags();
      94        5433 :         atomic_store_explicit(&cpu_flags, flags, memory_order_relaxed);
      95             :     }
      96      127377 :     return flags;
      97             : }
      98             : 
      99           0 : void av_set_cpu_flags_mask(int mask)
     100             : {
     101           0 :     atomic_store_explicit(&cpu_flags, get_cpu_flags() & mask,
     102             :                           memory_order_relaxed);
     103           0 : }
     104             : 
     105           0 : int av_parse_cpu_flags(const char *s)
     106             : {
     107             : #define CPUFLAG_MMXEXT   (AV_CPU_FLAG_MMX      | AV_CPU_FLAG_MMXEXT | AV_CPU_FLAG_CMOV)
     108             : #define CPUFLAG_3DNOW    (AV_CPU_FLAG_3DNOW    | AV_CPU_FLAG_MMX)
     109             : #define CPUFLAG_3DNOWEXT (AV_CPU_FLAG_3DNOWEXT | CPUFLAG_3DNOW)
     110             : #define CPUFLAG_SSE      (AV_CPU_FLAG_SSE      | CPUFLAG_MMXEXT)
     111             : #define CPUFLAG_SSE2     (AV_CPU_FLAG_SSE2     | CPUFLAG_SSE)
     112             : #define CPUFLAG_SSE2SLOW (AV_CPU_FLAG_SSE2SLOW | CPUFLAG_SSE2)
     113             : #define CPUFLAG_SSE3     (AV_CPU_FLAG_SSE3     | CPUFLAG_SSE2)
     114             : #define CPUFLAG_SSE3SLOW (AV_CPU_FLAG_SSE3SLOW | CPUFLAG_SSE3)
     115             : #define CPUFLAG_SSSE3    (AV_CPU_FLAG_SSSE3    | CPUFLAG_SSE3)
     116             : #define CPUFLAG_SSE4     (AV_CPU_FLAG_SSE4     | CPUFLAG_SSSE3)
     117             : #define CPUFLAG_SSE42    (AV_CPU_FLAG_SSE42    | CPUFLAG_SSE4)
     118             : #define CPUFLAG_AVX      (AV_CPU_FLAG_AVX      | CPUFLAG_SSE42)
     119             : #define CPUFLAG_AVXSLOW  (AV_CPU_FLAG_AVXSLOW  | CPUFLAG_AVX)
     120             : #define CPUFLAG_XOP      (AV_CPU_FLAG_XOP      | CPUFLAG_AVX)
     121             : #define CPUFLAG_FMA3     (AV_CPU_FLAG_FMA3     | CPUFLAG_AVX)
     122             : #define CPUFLAG_FMA4     (AV_CPU_FLAG_FMA4     | CPUFLAG_AVX)
     123             : #define CPUFLAG_AVX2     (AV_CPU_FLAG_AVX2     | CPUFLAG_AVX)
     124             : #define CPUFLAG_BMI2     (AV_CPU_FLAG_BMI2     | AV_CPU_FLAG_BMI1)
     125             : #define CPUFLAG_AESNI    (AV_CPU_FLAG_AESNI    | CPUFLAG_SSE42)
     126             :     static const AVOption cpuflags_opts[] = {
     127             :         { "flags"   , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" },
     128             : #if   ARCH_PPC
     129             :         { "altivec" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ALTIVEC  },    .unit = "flags" },
     130             : #elif ARCH_X86
     131             :         { "mmx"     , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_MMX      },    .unit = "flags" },
     132             :         { "mmxext"  , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_MMXEXT       },    .unit = "flags" },
     133             :         { "sse"     , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE          },    .unit = "flags" },
     134             :         { "sse2"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE2         },    .unit = "flags" },
     135             :         { "sse2slow", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE2SLOW     },    .unit = "flags" },
     136             :         { "sse3"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE3         },    .unit = "flags" },
     137             :         { "sse3slow", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE3SLOW     },    .unit = "flags" },
     138             :         { "ssse3"   , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSSE3        },    .unit = "flags" },
     139             :         { "atom"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ATOM     },    .unit = "flags" },
     140             :         { "sse4.1"  , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE4         },    .unit = "flags" },
     141             :         { "sse4.2"  , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_SSE42        },    .unit = "flags" },
     142             :         { "avx"     , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_AVX          },    .unit = "flags" },
     143             :         { "avxslow" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_AVXSLOW      },    .unit = "flags" },
     144             :         { "xop"     , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_XOP          },    .unit = "flags" },
     145             :         { "fma3"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_FMA3         },    .unit = "flags" },
     146             :         { "fma4"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_FMA4         },    .unit = "flags" },
     147             :         { "avx2"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_AVX2         },    .unit = "flags" },
     148             :         { "bmi1"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_BMI1     },    .unit = "flags" },
     149             :         { "bmi2"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_BMI2         },    .unit = "flags" },
     150             :         { "3dnow"   , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_3DNOW        },    .unit = "flags" },
     151             :         { "3dnowext", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_3DNOWEXT     },    .unit = "flags" },
     152             :         { "cmov",     NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_CMOV     },    .unit = "flags" },
     153             :         { "aesni"   , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPUFLAG_AESNI        },    .unit = "flags" },
     154             : #elif ARCH_ARM
     155             :         { "armv5te",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV5TE  },    .unit = "flags" },
     156             :         { "armv6",    NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV6    },    .unit = "flags" },
     157             :         { "armv6t2",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV6T2  },    .unit = "flags" },
     158             :         { "vfp",      NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFP      },    .unit = "flags" },
     159             :         { "vfp_vm",   NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFP_VM   },    .unit = "flags" },
     160             :         { "vfpv3",    NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFPV3    },    .unit = "flags" },
     161             :         { "neon",     NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_NEON     },    .unit = "flags" },
     162             : #elif ARCH_AARCH64
     163             :         { "armv8",    NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV8    },    .unit = "flags" },
     164             :         { "neon",     NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_NEON     },    .unit = "flags" },
     165             :         { "vfp",      NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFP      },    .unit = "flags" },
     166             : #endif
     167             :         { NULL },
     168             :     };
     169             :     static const AVClass class = {
     170             :         .class_name = "cpuflags",
     171             :         .item_name  = av_default_item_name,
     172             :         .option     = cpuflags_opts,
     173             :         .version    = LIBAVUTIL_VERSION_INT,
     174             :     };
     175             : 
     176           0 :     int flags = 0, ret;
     177           0 :     const AVClass *pclass = &class;
     178             : 
     179           0 :     if ((ret = av_opt_eval_flags(&pclass, &cpuflags_opts[0], s, &flags)) < 0)
     180           0 :         return ret;
     181             : 
     182           0 :     return flags & INT_MAX;
     183             : }
     184             : 
     185        5295 : int av_parse_cpu_caps(unsigned *flags, const char *s)
     186             : {
     187             :         static const AVOption cpuflags_opts[] = {
     188             :         { "flags"   , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" },
     189             : #if   ARCH_PPC
     190             :         { "altivec" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ALTIVEC  },    .unit = "flags" },
     191             : #elif ARCH_X86
     192             :         { "mmx"     , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_MMX      },    .unit = "flags" },
     193             :         { "mmx2"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_MMX2     },    .unit = "flags" },
     194             :         { "mmxext"  , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_MMX2     },    .unit = "flags" },
     195             :         { "sse"     , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_SSE      },    .unit = "flags" },
     196             :         { "sse2"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_SSE2     },    .unit = "flags" },
     197             :         { "sse2slow", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_SSE2SLOW },    .unit = "flags" },
     198             :         { "sse3"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_SSE3     },    .unit = "flags" },
     199             :         { "sse3slow", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_SSE3SLOW },    .unit = "flags" },
     200             :         { "ssse3"   , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_SSSE3    },    .unit = "flags" },
     201             :         { "atom"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ATOM     },    .unit = "flags" },
     202             :         { "sse4.1"  , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_SSE4     },    .unit = "flags" },
     203             :         { "sse4.2"  , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_SSE42    },    .unit = "flags" },
     204             :         { "avx"     , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_AVX      },    .unit = "flags" },
     205             :         { "avxslow" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_AVXSLOW  },    .unit = "flags" },
     206             :         { "xop"     , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_XOP      },    .unit = "flags" },
     207             :         { "fma3"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_FMA3     },    .unit = "flags" },
     208             :         { "fma4"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_FMA4     },    .unit = "flags" },
     209             :         { "avx2"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_AVX2     },    .unit = "flags" },
     210             :         { "bmi1"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_BMI1     },    .unit = "flags" },
     211             :         { "bmi2"    , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_BMI2     },    .unit = "flags" },
     212             :         { "3dnow"   , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_3DNOW    },    .unit = "flags" },
     213             :         { "3dnowext", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_3DNOWEXT },    .unit = "flags" },
     214             :         { "cmov",     NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_CMOV     },    .unit = "flags" },
     215             :         { "aesni",    NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_AESNI    },    .unit = "flags" },
     216             : 
     217             : #define CPU_FLAG_P2 AV_CPU_FLAG_CMOV | AV_CPU_FLAG_MMX
     218             : #define CPU_FLAG_P3 CPU_FLAG_P2 | AV_CPU_FLAG_MMX2 | AV_CPU_FLAG_SSE
     219             : #define CPU_FLAG_P4 CPU_FLAG_P3| AV_CPU_FLAG_SSE2
     220             :         { "pentium2", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P2          },    .unit = "flags" },
     221             :         { "pentium3", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P3          },    .unit = "flags" },
     222             :         { "pentium4", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_P4          },    .unit = "flags" },
     223             : 
     224             : #define CPU_FLAG_K62 AV_CPU_FLAG_MMX | AV_CPU_FLAG_3DNOW
     225             : #define CPU_FLAG_ATHLON   CPU_FLAG_K62 | AV_CPU_FLAG_CMOV | AV_CPU_FLAG_3DNOWEXT | AV_CPU_FLAG_MMX2
     226             : #define CPU_FLAG_ATHLONXP CPU_FLAG_ATHLON | AV_CPU_FLAG_SSE
     227             : #define CPU_FLAG_K8  CPU_FLAG_ATHLONXP | AV_CPU_FLAG_SSE2
     228             :         { "k6",       NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_MMX      },    .unit = "flags" },
     229             :         { "k62",      NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_K62         },    .unit = "flags" },
     230             :         { "athlon",   NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_ATHLON      },    .unit = "flags" },
     231             :         { "athlonxp", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_ATHLONXP    },    .unit = "flags" },
     232             :         { "k8",       NULL, 0, AV_OPT_TYPE_CONST, { .i64 = CPU_FLAG_K8          },    .unit = "flags" },
     233             : #elif ARCH_ARM
     234             :         { "armv5te",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV5TE  },    .unit = "flags" },
     235             :         { "armv6",    NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV6    },    .unit = "flags" },
     236             :         { "armv6t2",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV6T2  },    .unit = "flags" },
     237             :         { "vfp",      NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFP      },    .unit = "flags" },
     238             :         { "vfp_vm",   NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFP_VM   },    .unit = "flags" },
     239             :         { "vfpv3",    NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFPV3    },    .unit = "flags" },
     240             :         { "neon",     NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_NEON     },    .unit = "flags" },
     241             :         { "setend",   NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_SETEND   },    .unit = "flags" },
     242             : #elif ARCH_AARCH64
     243             :         { "armv8",    NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV8    },    .unit = "flags" },
     244             :         { "neon",     NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_NEON     },    .unit = "flags" },
     245             :         { "vfp",      NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFP      },    .unit = "flags" },
     246             : #endif
     247             :         { NULL },
     248             :     };
     249             :     static const AVClass class = {
     250             :         .class_name = "cpuflags",
     251             :         .item_name  = av_default_item_name,
     252             :         .option     = cpuflags_opts,
     253             :         .version    = LIBAVUTIL_VERSION_INT,
     254             :     };
     255        5295 :     const AVClass *pclass = &class;
     256             : 
     257        5295 :     return av_opt_eval_flags(&pclass, &cpuflags_opts[0], s, flags);
     258             : }
     259             : 
     260        2377 : int av_cpu_count(void)
     261             : {
     262             :     static volatile int printed;
     263             : 
     264        2377 :     int nb_cpus = 1;
     265             : #if HAVE_WINRT
     266             :     SYSTEM_INFO sysinfo;
     267             : #endif
     268             : #if HAVE_SCHED_GETAFFINITY && defined(CPU_COUNT)
     269             :     cpu_set_t cpuset;
     270             : 
     271             :     CPU_ZERO(&cpuset);
     272             : 
     273             :     if (!sched_getaffinity(0, sizeof(cpuset), &cpuset))
     274             :         nb_cpus = CPU_COUNT(&cpuset);
     275             : #elif HAVE_GETPROCESSAFFINITYMASK
     276             :     DWORD_PTR proc_aff, sys_aff;
     277             :     if (GetProcessAffinityMask(GetCurrentProcess(), &proc_aff, &sys_aff))
     278             :         nb_cpus = av_popcount64(proc_aff);
     279             : #elif HAVE_SYSCTL && defined(HW_NCPU)
     280             :     int mib[2] = { CTL_HW, HW_NCPU };
     281             :     size_t len = sizeof(nb_cpus);
     282             : 
     283             :     if (sysctl(mib, 2, &nb_cpus, &len, NULL, 0) == -1)
     284             :         nb_cpus = 0;
     285             : #elif HAVE_SYSCONF && defined(_SC_NPROC_ONLN)
     286             :     nb_cpus = sysconf(_SC_NPROC_ONLN);
     287             : #elif HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN)
     288        2377 :     nb_cpus = sysconf(_SC_NPROCESSORS_ONLN);
     289             : #elif HAVE_WINRT
     290             :     GetNativeSystemInfo(&sysinfo);
     291             :     nb_cpus = sysinfo.dwNumberOfProcessors;
     292             : #endif
     293             : 
     294        2377 :     if (!printed) {
     295        2212 :         av_log(NULL, AV_LOG_DEBUG, "detected %d logical cores\n", nb_cpus);
     296        2212 :         printed = 1;
     297             :     }
     298             : 
     299        2377 :     return nb_cpus;
     300             : }

Generated by: LCOV version 1.12