INTERACT FORUM

More => Old Versions => JRiver Media Center 21 for Linux => Topic started by: terrym@tassie on June 06, 2016, 05:12:16 pm

Title: Any prospect of Media Center preventing idling to suspend during playback?
Post by: terrym@tassie on June 06, 2016, 05:12:16 pm
With MC22 looming I thought I would raise again the issue I originally reported here http://yabb.jriver.com/interact/index.php?topic=99466.0

It is very annoying that when using MC on Linux Mint or Debian Jessie that the system will idle to suspend state even if MC is playing back a file.
It is a standard feature of the Windows version that it keeps the system awake during playback but allows it to suspend if inactive.

As far as I am aware from the discussion the last time I raised this, the only Linux distro that MC can keep awake during playback is Debian Wheezy.
Is this still correct?

I would really like to be able set my Linux clients to aggressive suspend settings so that if I wander off and the playlist I was playing finishes then the system will rapidly idle to suspend state with the consequent savings in power.
Title: Re: Any prospect of Media Center preventing idling to suspend during playback?
Post by: BryanC on June 06, 2016, 05:19:50 pm
If you are comfortable with shell commands, you could repurpose something similar to this (http://ubuntuforums.org/showthread.php?t=2322822), depending on your distro.

Edit: This is also an option: https://github.com/hobarrera/caffeine-ng or https://launchpad.net/caffeine/
Title: Re: Any prospect of Media Center preventing idling to suspend during playback?
Post by: terrym@tassie on June 06, 2016, 06:40:47 pm
Thanks for the further work around suggestions Bryan, but  I was asking that this be done WITHIN MC, not as scripted add-ons that rely on mcws to detect whether MC is playing etc etc.

It just seems fundamental to me that a media player doesn't appear to be idle to the OS if it is playing something.

(or perhaps the rest of the world just leave their Linux boxes on 24/7?)
Title: Re: Any prospect of Media Center preventing idling to suspend during playback?
Post by: BryanC on June 06, 2016, 09:41:50 pm
It's actually kind of a funky problem since it appears (by my limited research) that systemd uses a measure of idle time that is dependent on the mouse and keyboard movement. Hence the need for caffeine (Mac OSX actually has this built in) or other workarounds.

I wrote a pretty simple systemd service file that checks whether or not Pulse is playing audio and then inhibits the suspend if it is. This has the added benefit of being a system-wide change so if you are (for instance) playing music through YouTube the computer won't sleep.

Place into /etc/systemd/system/prevent_sleep.service

Code: [Select]
[Unit]
Description=Inhibit suspend when pulse is playing audio
Before=sleep.target

[Service]
Type=oneshot
ExecStart=/usr/bin/sh -c "! pacmd list-sink-inputs | grep -q -c 'state: RUNNING'"

[Install]
RequiredBy=sleep.target

systemctl daemon-reload
systemctl enable prevent_sleep.service

That should work and be about as elegant a solution as you can get at this point I think.
Title: Re: Any prospect of Media Center preventing idling to suspend during playback?
Post by: mwillems on June 06, 2016, 11:09:26 pm
It's actually kind of a funky problem since it appears (by my limited research) that systemd uses a measure of idle time that is dependent on the mouse and keyboard movement. Hence the need for caffeine (Mac OSX actually has this built in) or other workarounds.

I wrote a pretty simple systemd service file that checks whether or not Pulse is playing audio and then inhibits the suspend if it is. This has the added benefit of being a system-wide change so if you are (for instance) playing music through YouTube the computer won't sleep.

Place into /etc/systemd/system/prevent_sleep.service

Code: [Select]
[Unit]
Description=Inhibit suspend when pulse is playing audio
Before=sleep.target

[Service]
Type=oneshot
ExecStart=/usr/bin/sh -c "! pacmd list-sink-inputs | grep -q -c 'state: RUNNING'"

[Install]
RequiredBy=sleep.target

systemctl daemon-reload
systemctl enable prevent_sleep.service

That should work and be about as elegant a solution as you can get at this point I think.

Just wanted to chime in and say that's really elegant Bryan.  I'm setting it up tomorrow  ;D
Title: Re: Any prospect of Media Center preventing idling to suspend during playback?
Post by: terrym@tassie on June 07, 2016, 03:52:01 pm
BryanC I'd like to try your elegant solution but I've hit a snag on Linux Mint 17.3 as there is no systemctl command.

Any suggestions on how I enable the service? (I have created the file prevent_sleep.service in /etc/systemd/system).

What I can't do is execute the commands:
systemctl daemon-reload
systemctl enable prevent_sleep.service

Thanks

Terry
Title: Re: Any prospect of Media Center preventing idling to suspend during playback?
Post by: BryanC on June 07, 2016, 04:12:26 pm
BryanC I'd like to try your elegant solution but I've hit a snag on Linux Mint 17.3 as there is no systemctl command.

Any suggestions on how I enable the service? (I have created the file prevent_sleep.service in /etc/systemd/system).

What I can't do is execute the commands:
systemctl daemon-reload
systemctl enable prevent_sleep.service

Thanks

Terry

Ah you are using a distro based on a legacy LTS version of Ubuntu that is using upstart and not systemd. Although I'm not familiar with upstart, something like this is much easier to implement if upstart does in fact still use pm-utils (unlike systemd).

Simply create:

/etc/pm/sleep.d/00check_audio.sh
Code: [Select]
#!/bin/bash
if `pacmd list-sink-inputs | grep --quiet -c 'state: RUNNING'` ; then
    exit 1
else
    exit 0
fi

You will need to sudo chmod +x /etc/pm/sleep.d/00check_audio.sh in order to make it executable and then pm-utils should check the playback state automatically when the system tries to sleep.

Title: Re: Any prospect of Media Center preventing idling to suspend during playback?
Post by: terrym@tassie on June 07, 2016, 06:03:51 pm
Well done BryanC!     Using the script in /etc/pm/sleep.d does indeed inhibit suspend on Mint 17.3 xfce. Kudos to you.

I don't actually use Pulse, preferring to go direct to the alsa device without resampling so my script looks this:
Code: [Select]
#!/bin/bash
if `cat /proc/asound/card0/pcm0p/sub0/status | grep --quiet -c 'state: RUNNING'` ; then
    exit 1
else
    exit 0
fi

Thanks again for a simple and elegant solution to the problem. (Note: I think this should be stickied, it is bound to be of use to other users)

Terry
Title: Re: Any prospect of Media Center preventing idling to suspend during playback?
Post by: Mike Noe on June 10, 2016, 08:34:07 am
FYI, somewhat related, I just moved to Linux 4.7.0-rc2-1.gfd100c9-default (openSuse TW x86-64) and for whatever reason, the screen turn off inhibit seems to be working now without disabling power management in the DE.  I've only tested Plasma5 at this point.

I have a two screen setup, monitor is DVI, HDTV is connected thru a Receiver, HDMI from the video card.  Playback is thru the HDMI.  Before, this update, even when playing audio via HDMI, the power managment would turn off both outputs (HDMI/DVI) at the specified timeout for idle, thus interrupting playback.  After this kernel update, there is a small hiccup when the power management kicks in to disable card outputs, but then it comes right back and continues playing.