Skip to content

Fix HDMI audio detection on Pi4 with dual HDMI ports#2667

Open
Alex1981-tech wants to merge 2 commits intoScreenly:masterfrom
Alex1981-tech:fix/hdmi-audio-detection
Open

Fix HDMI audio detection on Pi4 with dual HDMI ports#2667
Alex1981-tech wants to merge 2 commits intoScreenly:masterfrom
Alex1981-tech:fix/hdmi-audio-detection

Conversation

@Alex1981-tech
Copy link

Summary

  • Pi4 has two HDMI ports (HDMI-A-1 / HDMI-A-2), but VLC audio always targets default:CARD=vc4hdmi0 regardless of which port has a display connected. This causes no audio when using HDMI-A-2.
  • The default:CARD= ALSA device name can be unreliable when PulseAudio or dmix is involved.

Changes

  • Add _detect_hdmi_audio_device() function that reads /sys/class/drm/cardN-HDMI-A-N/status to detect which HDMI port is connected
  • Switch from default:CARD= to sysdefault:CARD= for direct hardware access
  • Apply auto-detection for Pi4 and Pi5 HDMI output
  • Headphones and Pi1-3 paths are unchanged

Test plan

  • Tested on Pi4 Model B Rev 1.5, Raspberry Pi OS, single HDMI connected to HDMI-A-1
  • Audio plays correctly through HDMI
  • Fallback works when no HDMI status file is found
  • Needs testing with HDMI-A-2 only
  • Needs testing on Pi5

Pi4 has two HDMI ports (HDMI-A-1 and HDMI-A-2), but the existing code
always hardcodes `default:CARD=vc4hdmi0` regardless of which port has
a display connected. This causes no audio when using HDMI-A-2.

Changes:
- Add `_detect_hdmi_audio_device()` that reads
  `/sys/class/drm/cardN-HDMI-A-N/status` to find which HDMI port
  is connected and returns the correct ALSA device
- Use `sysdefault:CARD=` instead of `default:CARD=` for more
  reliable audio output (avoids PulseAudio/dmix interference)
- Apply detection for Pi4 and Pi5 HDMI output
- Keep headphones and Pi1-3 paths unchanged

Tested on Pi4 Model B with single HDMI connected to HDMI-A-1.
@Alex1981-tech Alex1981-tech requested a review from a team as a code owner February 15, 2026 07:35
@nicomiguelino
Copy link
Contributor

@Alex1981-tech, thank you for opening a pull request! I will test the changes when I get the chance.
In the meantime, please continue testing your changes and fix failures in checks—linting & formatting, tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Alex1981-tech
Copy link
Author

CI update: Fixed ruff format. The remaining test failure (test_add_asset_url) is a pre-existing flaky Selenium integration test unrelated to this PR — it fails on other PRs as well (e.g. Dependabot).

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants