mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
de265dec: use g_get_num_processors() if available
And provide home-made fallback for older GLib versions, so that we can later find these and remove them when we bump the GLib requirement (which is certainly going to happen before 2.0). https://bugzilla.gnome.org/show_bug.cgi?id=748495
This commit is contained in:
parent
f0a9c246a3
commit
c754b8526b
1 changed files with 48 additions and 36 deletions
|
@ -36,17 +36,62 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "libde265-dec.h"
|
||||||
|
|
||||||
|
#if !GLIB_CHECK_VERSION(2, 36, 0)
|
||||||
|
#include <stdio.h>
|
||||||
#ifdef HAVE_UNISTD_H
|
#ifdef HAVE_UNISTD_H
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
#define g_get_num_processors gst_g_get_num_processors
|
||||||
|
static guint
|
||||||
|
gst_g_get_num_processors (void)
|
||||||
|
{
|
||||||
|
guint threads = 0;
|
||||||
|
|
||||||
#include "libde265-dec.h"
|
#if defined(_SC_NPROC_ONLN)
|
||||||
|
threads = sysconf (_SC_NPROC_ONLN);
|
||||||
|
#elif defined(_SC_NPROCESSORS_ONLN)
|
||||||
|
threads = sysconf (_SC_NPROCESSORS_ONLN);
|
||||||
|
#elif defined(G_OS_WIN32)
|
||||||
|
{
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#warning "Don't know how to get number of CPU cores, will use the default thread count"
|
||||||
|
threads = DEFAULT_THREAD_COUNT;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (threads > 0)
|
||||||
|
return threads;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif /* !GLIB_CHECK_VERSION(2, 36, 0) */
|
||||||
|
|
||||||
/* use two decoder threads if no information about
|
/* use two decoder threads if no information about
|
||||||
* available CPU cores can be retrieved */
|
* available CPU cores can be retrieved */
|
||||||
|
@ -377,41 +422,8 @@ gst_libde265_dec_start (GstVideoDecoder * decoder)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (threads == 0) {
|
if (threads == 0) {
|
||||||
#if defined(_SC_NPROC_ONLN)
|
threads = g_get_num_processors ();
|
||||||
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;
|
|
||||||
#endif
|
|
||||||
if (threads <= 0) {
|
|
||||||
threads = DEFAULT_THREAD_COUNT;
|
|
||||||
}
|
|
||||||
/* NOTE: We start more threads than cores for now, as some threads
|
/* NOTE: We start more threads than cores for now, as some threads
|
||||||
* might get blocked while waiting for dependent data. Having more
|
* might get blocked while waiting for dependent data. Having more
|
||||||
* threads increases decoding speed by about 10% */
|
* threads increases decoding speed by about 10% */
|
||||||
|
|
Loading…
Reference in a new issue