diff options
author | sr55 <[email protected]> | 2013-02-04 19:44:40 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2013-02-04 19:44:40 +0000 |
commit | 4ea1e568a7ad2e8ae4068d76e00f30dd77e280bd (patch) | |
tree | 68346349bc30a460a601df550235dad3c0d7674f /libhb/ports.c | |
parent | a735c9046533954e1bba5cf8996d98e15b2e86cc (diff) |
Prevent OSX ML sleep during encoding, thanks to Jerome Lacube
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5238 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/ports.c')
-rw-r--r-- | libhb/ports.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/libhb/ports.c b/libhb/ports.c index f10c9d96c..11952c052 100644 --- a/libhb/ports.c +++ b/libhb/ports.c @@ -66,6 +66,10 @@ #include <sys/ioctl.h> #endif +#ifdef __APPLE__ +#include <IOKit/pwr_mgt/IOPMLib.h> +#endif + #include <stddef.h> #include <unistd.h> @@ -781,3 +785,70 @@ char *strtok_r(char *s, const char *delim, char **save_ptr) return token; } #endif + +/************************************************************************ +* OS Sleep Allow / Prevent +***********************************************************************/ + +#ifdef __APPLE__ +// 128 chars limit for IOPMAssertionCreateWithName +static CFStringRef reasonForActivity= CFSTR("HandBrake is currently scanning and/or encoding"); +#endif + +void* hb_system_sleep_opaque_init() +{ + void* opaque; +#ifdef __APPLE__ + opaque = calloc( sizeof( IOPMAssertionID ), 1); + IOPMAssertionID * assertionID = (IOPMAssertionID *)opaque; + *assertionID = -1; +#endif + + return opaque; +} + +void hb_system_sleep_opaque_close(void **_opaque) +{ +#ifdef __APPLE__ + IOPMAssertionID * assertionID = (IOPMAssertionID *) *_opaque; + free( assertionID ); +#endif + *_opaque = NULL; +} + +void hb_system_sleep_allow(void *opaque) +{ +#ifdef __APPLE__ + IOPMAssertionID * assertionID = (IOPMAssertionID *)opaque; + + if (*assertionID == -1) + return; + + IOReturn success = IOPMAssertionRelease(*assertionID); + + if (success == kIOReturnSuccess) { + hb_deep_log( 3, "osxsleep: IOPM assertion %d successfully released, sleep allowed", *assertionID ); + *assertionID = -1; + } else { + hb_log( "osxsleep: error while trying to unset power management assertion" ); + } +#endif +} + +void hb_system_sleep_prevent(void *opaque) +{ +#ifdef __APPLE__ + IOPMAssertionID * assertionID = (IOPMAssertionID *)opaque; + + if (*assertionID != -1) + return; + + IOReturn success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, + kIOPMAssertionLevelOn, reasonForActivity, assertionID); + if (success == kIOReturnSuccess) { + hb_deep_log( 3, "IOPM assertion %d successfully created, prevent sleep", *assertionID); + } else { + hb_log( "osxsleep: error while trying to set power management assertion" ); + } +#endif +} |