kyleneideck / BackgroundMusic

Background Music, a macOS audio utility: automatically pause your music, set individual apps' volumes and record system audio.
GNU General Public License v2.0
15.52k stars 664 forks source link

BGM prevents Mac from Sleep #189

Open JeemySBG opened 5 years ago

JeemySBG commented 5 years ago

Hi,

I was researching an issue where my Mac won't enter screensaver, and discovered if you go to Activity Monitor you can add a column "Prevents Sleep" to see what applications are, well, preventing sleep.

So BGM does. I can't see that this is desirable behaviour so I thought I would mention it.

All best,

Jamie

kyleneideck commented 5 years ago

BGM should only prevent sleep when it's playing audio, which it should only do when another app is playing audio. (Behind the scenes, the other app's audio goes to BGM and BGM sends it to your speakers.)

Are any of the other apps you have open also preventing sleep? Apps sometimes play continuous silent audio, for example, when you leave a video paused in VLC, which would prevent sleep. If so, does BGM still prevent sleep after you close the other apps?

It could be possible for apps to play audio without preventing sleep, but I haven't been able to find a way to do that. If it is possible, then BGM would prevent sleep anyway in those cases, so we would want to fix that. If it isn't possible, then BGM would only prevent sleep when another app is preventing sleep anyway.

I suspect it isn't possible, or at least isn't practical, because when I play audio the processes (programs) telling macOS to prevent sleep include coreaudiod, the process (userspace) audio drivers run in, and it prevents sleep while audio is playing whether BGM is open or not.

With BGM running:

$ pmset -g assertions
[...]
   pid 28350(QuickTime Player): [0x0002b6a300019936] 00:00:04 PreventUserIdleSystemSleep named: "com.apple.avkit.disableUserIdleSystemSleep"
    Details: disable user idle system sleep
   pid 214(coreaudiod): [0x0002b6a400019817] 00:00:04 PreventUserIdleSystemSleep named: "com.apple.audio.BGMDevice.context.preventuseridlesleep"
    Created for PID: 28260.
   pid 214(coreaudiod): [0x0002b6a300019823] 00:00:04 PreventUserIdleSystemSleep named: "com.apple.audio.AppleHDAEngineOutput:1F,3,0,1,1:0.context.preventuseridlesleep"
    Created for PID: 28260.
   pid 214(coreaudiod): [0x0002b6a3000198e2] 00:00:04 PreventUserIdleSystemSleep named: "com.apple.audio.BGMDevice.context.preventuseridlesleep"
    Created for PID: 28350.

Without BGM running:

$ pmset -g assertions
[...]
   pid 28350(QuickTime Player): [0x0002b8260001995d] 00:00:04 PreventUserIdleSystemSleep named: "com.apple.avkit.disableUserIdleSystemSleep"
    Details: disable user idle system sleep
   pid 214(coreaudiod): [0x0002b826000198ee] 00:00:04 PreventUserIdleSystemSleep named: "com.apple.audio.AppleHDAEngineOutput:1F,3,0,1,1:0.context.preventuseridlesleep"
    Created for PID: 28350.

Note that AppleHDAEngineOutput:1F,3,0,1,1:0 is my real audio output device and BGMDevice is Background Music's virtual audio device.