INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Any prospect of Media Center preventing idling to suspend during playback?  (Read 6556 times)

terrym@tassie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 504

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.
Logged
Good manners cost nothing.
Bad manners can cost you your reputation
― B.D.Hawkey

BryanC

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2661

If you are comfortable with shell commands, you could repurpose something similar to this, depending on your distro.

Edit: This is also an option: https://github.com/hobarrera/caffeine-ng or https://launchpad.net/caffeine/
Logged

terrym@tassie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 504

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?)
Logged
Good manners cost nothing.
Bad manners can cost you your reputation
― B.D.Hawkey

BryanC

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2661

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

mwillems

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 5234
  • "Linux Merit Badge" Recipient

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
Logged

terrym@tassie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 504

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
Logged
Good manners cost nothing.
Bad manners can cost you your reputation
― B.D.Hawkey

BryanC

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2661

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.

Logged

terrym@tassie

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 504

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
Logged
Good manners cost nothing.
Bad manners can cost you your reputation
― B.D.Hawkey

Mike Noe

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 792

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.
Logged
openSUSE TW/Plasma5 x86_64 | Win10Pro/RX560
S.M.S.L USB-DAC => Transcendent GG Pre (kit) => Transcendent mono OTLs (kit)
(heavily modded) Hammer Dynamics Super-12s (kit)
(optionally) VonSchweikert VR8s
Pages: [1]   Go Up