#if HAVE_SCHED_GETAFFINITY
#define _GNU_SOURCE
#include <sched.h>
-#elif HAVE_GETSYSTEMINFO
+#endif
+#if HAVE_GETSYSTEMINFO
#include <windows.h>
-#elif HAVE_SYSCTL
-#include <sys/sysctl.h>
+#endif
+#if HAVE_SYSCTL
+#if HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
+#if HAVE_SYSCONF
+#include <unistd.h>
#endif
#include "avcodec.h"
static int get_logical_cpus(AVCodecContext *avctx)
{
int ret, nb_cpus = 1;
-#if HAVE_SCHED_GETAFFINITY
+#if HAVE_SCHED_GETAFFINITY && defined(CPU_COUNT)
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
nb_cpus = sysinfo.dwNumberOfProcessors;
-#elif HAVE_SYSCTL
+#elif HAVE_SYSCTL && defined(HW_NCPU)
int mib[2] = { CTL_HW, HW_NCPU };
size_t len = sizeof(nb_cpus);
ret = sysctl(mib, 2, &nb_cpus, &len, NULL, 0);
if (ret == -1)
nb_cpus = 0;
+#elif HAVE_SYSCONF && defined(_SC_NPROC_ONLN)
+ nb_cpus = sysconf(_SC_NPROC_ONLN);
+#elif HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN)
+ nb_cpus = sysconf(_SC_NPROCESSORS_ONLN);
#endif
av_log(avctx, AV_LOG_DEBUG, "detected %d logical cores\n", nb_cpus);
- return FFMIN(nb_cpus, MAX_AUTO_THREADS);
+ return nb_cpus;
}
if (!thread_count) {
int nb_cpus = get_logical_cpus(avctx);
- // use number of cores + 1 as thread count if there is motre than one
+ // use number of cores + 1 as thread count if there is more than one
if (nb_cpus > 1)
- thread_count = avctx->thread_count = nb_cpus + 1;
+ thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS);
+ else
+ thread_count = avctx->thread_count = 1;
}
if (thread_count <= 1) {
*picture = p->frame;
*got_picture_ptr = p->got_frame;
picture->pkt_dts = p->avpkt.dts;
+ picture->sample_aspect_ratio = avctx->sample_aspect_ratio;
+ picture->width = avctx->width;
+ picture->height = avctx->height;
+ picture->format = avctx->pix_fmt;
/*
* A later call with avkpt->size == 0 may loop over all threads,
if (!thread_count) {
int nb_cpus = get_logical_cpus(avctx);
- // use number of cores + 1 as thread count if there is motre than one
+ // use number of cores + 1 as thread count if there is more than one
if (nb_cpus > 1)
- thread_count = avctx->thread_count = nb_cpus + 1;
+ thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS);
+ else
+ thread_count = avctx->thread_count = 1;
}
if (thread_count <= 1) {
} else if (avctx->codec->capabilities & CODEC_CAP_SLICE_THREADS &&
avctx->thread_type & FF_THREAD_SLICE) {
avctx->active_thread_type = FF_THREAD_SLICE;
+ } else if (!(avctx->codec->capabilities & CODEC_CAP_AUTO_THREADS)) {
+ avctx->thread_count = 1;
+ avctx->active_thread_type = 0;
}
}