Control Idle Sleep from Audio Virtual Driver - Mac OSX

We have a virtual audio device driver similar to Sound flower. This virtual device will be listed in the sound system settings. Whenever our device is selected in system settings, it prevents sleep idleness. If we switch the selection to the default output device, everything works as expected.

If we execute the command "pmset -g assertions" in terminal it gives below output

Assertion status system-wide:  
   ChargeInhibit                           0
   PreventUserIdleDisplaySleep             0
   PreventUserIdleSystemSleep              1
   NoRealPowerSources_debug                0
   CPUBoundAssertion                       0
   EnableIdleSleep                         1
   PreventSystemSleep                      0
   DisableInflow                           0
   DisableLowPowerBatteryWarnings          0
   ExternalMedia                           0

Listed by owning process:

   pid 115: [0x0000012c00000073] PreventUserIdleSystemSleep named: MY_DRIVER_IDENTIFER.noidlesleep" 

      

Can anyone please provide me with some guidance to solve this problem.

+3


source to share


1 answer


I think this is controlled by a flag kIOPMPreventIdleSleep

that is in the capabilityFlags

structure field IOPMPowerState

.

To participate in power management decisions, you need to add a device driver to the power plane, usually in your overridden method IOService::start(provider)

:

PMinit();
provider->joinPMtree(this);
registerPowerDriver(this, powerStates, numPowerStates);

      

where powerStates

u numPowerStates

specifies an array of power states that you want your device to be in. You probably don't need more than 2 for a virtual device, and maybe you even need one. I suspect your class's superclass is setting states that block sleep. Once you register for power management, your driver will work with power management methods such as IOService::setPowerState()

.



Depending on how you want your device to behave, you may need to create 2 power states, one "live" when playing or capturing audio (and inhibiting sleep) and the other "idle" when the device is not doing anything , and allow sleep.

The topic of power management is too big to fully cover the StackOverflow answer, so I suggest you read the docs about what I mentioned above and try to clear the corresponding flag in your states (states).

Hope it helps.

+1


source







All Articles