summaryrefslogtreecommitdiff
path: root/ext/libde265
diff options
context:
space:
mode:
authorРуслан Ижбулатов <lrn1986@gmail.com>2015-04-26 20:55:03 +0000
committerNicolas Dufresne <nicolas.dufresne@collabora.co.uk>2015-04-27 10:26:33 -0400
commit0a95a4ea248047a51c665d6214236c560d2aa46f (patch)
treebbfc5971e983bed8fb163b49331e5e906093f58a /ext/libde265
parent283fc200c608472d67f6aff4212a0c2cf0cfa8d0 (diff)
downloadgstreamer-plugins-bad-0a95a4ea248047a51c665d6214236c560d2aa46f.tar.gz
libde265: W32 thread count support
This code is imported from GLib g_get_num_processors(). This function was added in 2.36 but we depend on 2.32. https://bugzilla.gnome.org/show_bug.cgi?id=748495
Diffstat (limited to 'ext/libde265')
-rw-r--r--ext/libde265/libde265-dec.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/ext/libde265/libde265-dec.c b/ext/libde265/libde265-dec.c
index c47917b19..d52e8ce25 100644
--- a/ext/libde265/libde265-dec.c
+++ b/ext/libde265/libde265-dec.c
@@ -42,6 +42,9 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
#include "libde265-dec.h"
@@ -378,6 +381,30 @@ gst_libde265_dec_start (GstVideoDecoder * decoder)
threads = sysconf (_SC_NPROC_ONLN);
#elif defined(_SC_NPROCESSORS_ONLN)
threads = sysconf (_SC_NPROCESSORS_ONLN);
+#elif defined(G_OS_WIN32)
+ /* FIXME 2.0, use g_get_num_processors() */
+ SYSTEM_INFO sysinfo;
+ DWORD_PTR process_cpus;
+ DWORD_PTR system_cpus;
+
+ /* This *never* fails, but doesn't take CPU affinity into account */
+ GetSystemInfo (&sysinfo);
+ threads = (int) sysinfo.dwNumberOfProcessors;
+
+ /* This *can* fail, but produces correct results if affinity mask is used,
+ * unlike the simpler code above.
+ */
+ if (GetProcessAffinityMask (GetCurrentProcess (),
+ &process_cpus, &system_cpus)) {
+ unsigned int count;
+
+ for (count = 0; process_cpus != 0; process_cpus >>= 1)
+ if (process_cpus & 1)
+ count++;
+
+ if (count > 0)
+ threads = (int) count;
+ }
#else
#warning "Don't know how to get number of CPU cores, will use the default thread count"
threads = DEFAULT_THREAD_COUNT;