3

I'm using Ubuntu for an HTPC and I wanted to kill a bunch of processes like the browser when the TV is turned off. This is because I have limited bandwidth and want to avoid chance of streaming content while TV is off, wasting bandwidth.

My solution was to have a cron task run every minute checking for off state. But I'm don't know how to detect HDMI disconnect/TV off.

I've been using this fix: HDMI Audio stops after TV turned off for HDMI sound fix when TV turns off. So I could modify the code such that when ELD_valid switches from 1 to 0, it's time to kill stuff. But I believe it's monitoring sound status over HDMI? Also it seems like a bug fix, so my script would work as long as bug is present?

xrandr looked promising but you have to run it as user connected to a display. So I couldn't test what output it gives when TV is off from an ssh connection.

HDMI CEC codes seemed like another solution but you have to buy an adapter and my TV doesn't support CEC.

Any suggestions? Thanks.

P.S. I'm using ATI catalyst drivers. I'd be happy with ATI specific solution.

Budric
  • 295
  • 2
  • 6
  • 15

2 Answers2

1

xrandr looked promising but you have to run it as user connected to a display.

This is, strictly speaking, not true. It must be able to connect to the X server, but all that requires is 1) the display number, and 2) permission to talk to the X server via the magic cookie or via xauth.

The easiest way to get the cookie is to run as the user that is currently logged onto the display. Giving the display number is as easy as passing $DISPLAY to the program.

sudo -u displayuser env DISPLAY=:0.0 xrandr | grep -q '^xxxx disconnected'
0

This drove me nuts.

The Fix

The solution is to prevent your HDMI audio switching on connect/disconnect so it never changes state. Edit your /etc/pulse/default.pa and comment out this line by adding a #:

#load-module module-switch-on-port-available

then reboot.

The Issue

Logout/in restores audio. Switching monitor on or off disables HDMI audio. Sometimes Ubuntu switches to "Dummy Output" and manually re-enabling HDMI audio sometimes restores stereo but no surround (7.2). Definitely affects Intel HDMI and Radeon HDMI, unsure about NVIDIA cards.

There are several states a broken audio can be in:

  • properly configured (usually after login)
  • dummy output with 1 or no audio devices found
  • broken with stereo output only (no surround)
  • stereo output selected with no actual output

History

This bug, present for at least ten years (Ubuntu 12.04 through 22.04), has been addressed in many questions (1,2,3,4) and has a related bug and thread.

Bad Solutions

  • Some recommend unplugging and replugging your HDMI -> pretty janky
  • Others have tried scripts that monitor the xrandr state, but I don't think that's reliable. I was neither able to detect the error state reliably, nor restore correct state this way.
  • Running killall pulseaudio may restore stereo sometimes, but not surround audio.
Teque5
  • 299