0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 13:08:50 +02:00

Add platform functions to request high performance modes

Specifically, this disables App Nap and related features
on OSX 10.9+
This commit is contained in:
Palana 2014-08-22 05:21:27 +02:00
parent e3ddfec818
commit 571dd0f166
4 changed files with 59 additions and 0 deletions

View File

@ -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)];
}
}

View File

@ -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

View File

@ -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);
}

View File

@ -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.