diff --git a/libobs/util/platform-cocoa.m b/libobs/util/platform-cocoa.m index af123101f..b19d569d3 100644 --- a/libobs/util/platform-cocoa.m +++ b/libobs/util/platform-cocoa.m @@ -185,3 +185,32 @@ void os_cpu_usage_info_destroy(os_cpu_usage_info_t info) if (info) bfree(info); } + +os_performance_token_t os_request_high_performance(const char *reason) +{ + @autoreleasepool { + NSProcessInfo *pi = [NSProcessInfo processInfo]; + SEL sel = @selector(beginActivityWithOptions:reason:); + if (![pi respondsToSelector:sel]) + return nil; + + //taken from http://stackoverflow.com/a/20100906 + id activity = [pi beginActivityWithOptions:0x00FFFFFF + reason:@(reason)]; + + return CFBridgingRetain(activity); + } +} + +void os_end_high_performance(os_performance_token_t token) +{ + @autoreleasepool { + NSProcessInfo *pi = [NSProcessInfo processInfo]; + SEL sel = @selector(beginActivityWithOptions:reason:); + if (![pi respondsToSelector:sel]) + return; + + [pi endActivity:CFBridgingRelease(token)]; + } +} + diff --git a/libobs/util/platform-nix.c b/libobs/util/platform-nix.c index 4102fa430..6757f0cc9 100644 --- a/libobs/util/platform-nix.c +++ b/libobs/util/platform-nix.c @@ -294,3 +294,17 @@ int os_mkdir(const char *path) return (errno == EEXIST) ? MKDIR_EXISTS : MKDIR_ERROR; } + +#if !defined(__APPLE__) +os_performance_token_t os_request_high_performance(const char *reason) +{ + UNUSED_PARAMETER(reason); + return NULL; +} + +void os_end_high_performance(os_performance_token_t token) +{ + UNUSED_PARAMETER(token); +} +#endif + diff --git a/libobs/util/platform-windows.c b/libobs/util/platform-windows.c index e840a965a..c755b57e3 100644 --- a/libobs/util/platform-windows.c +++ b/libobs/util/platform-windows.c @@ -432,3 +432,15 @@ BOOL WINAPI DllMain(HINSTANCE hinst_dll, DWORD reason, LPVOID reserved) UNUSED_PARAMETER(reserved); return true; } + +os_performance_token_t os_request_high_performance(const char *reason) +{ + UNUSED_PARAMETER(reason); + return NULL; +} + +void os_end_high_performance(os_performance_token_t token) +{ + UNUSED_PARAMETER(token); +} + diff --git a/libobs/util/platform.h b/libobs/util/platform.h index 3b224601a..6c42e6c87 100644 --- a/libobs/util/platform.h +++ b/libobs/util/platform.h @@ -76,6 +76,10 @@ EXPORT os_cpu_usage_info_t os_cpu_usage_info_start(void); EXPORT double os_cpu_usage_info_query(os_cpu_usage_info_t info); EXPORT void os_cpu_usage_info_destroy(os_cpu_usage_info_t info); +typedef const void *os_performance_token_t; +EXPORT os_performance_token_t os_request_high_performance(const char *reason); +EXPORT void os_end_high_performance(os_performance_token_t); + /** * Sleeps to a specific time (in nanoseconds). Doesn't have to be super * accurate in terms of actual slept time because the target time is ensured.