Skip to content

ao_audiotrack: fix E-AC-3 and TrueHD passthrough - #18913

Open
Jercik wants to merge 2 commits into
mpv-player:masterfrom
Jercik:ao_audiotrack-spdif-rate
Open

Jercik wants to merge 2 commits into
mpv-player:masterfrom
Jercik:ao_audiotrack-spdif-rate

Conversation

@Jercik

@Jercik Jercik commented Nov 27, 2026

Copy link
Copy Markdown

E-AC-3 and TrueHD passthrough fail with --ao=audiotrack and fall back to PCM, so the receiver never gets Dolby Digital Plus or TrueHD. ao_audiotrack now limits the AudioTrack.getNativeOutputSampleRate clamp to PCM (skipping af_fmt_is_spdif formats). For ENCODING_IEC61937 streams with more than two channels, it opens the track with CHANNEL_OUT_7POINT1_SURROUND instead of stereo.

Previously, ao_audiotrack clamped every format to Android's PCM mixer rate (48000 Hz on the test device). These formats are carried at 192000 Hz, so opening at the lowered rate caused mpv to reject passthrough. ao_audiotrack also opened every passthrough stream with CHANNEL_OUT_STEREO, even though TrueHD and DTS-HD MA use 8 channels.

If a device cannot open the stream, creating the AudioTrack fails and mpv falls back to PCM as before.

The 8-channel change is the first commit so that lifting the sample rate clamp in the second commit does not leave an intermediate state where TrueHD plays silent with video at a quarter speed.

Device testing

Tested on master (d32c910be) on an NVIDIA Shield TV Pro 2019 (Android 11):

Track Before After
E-AC-3 5.1 Logs Passthrough format unsupported.; falls back to PCM Reaches soundbar as Dolby Digital Plus 5.1; survives pause and seeks
TrueHD Atmos Logs Passthrough format unsupported.; falls back to PCM Reaches soundbar as Dolby Atmos (TrueHD); survives pause and seeks
96000 Hz PCM Opens at 48000 Hz Opens at 48000 Hz

E-AC-3 was also tested on mpv 0.41.0 and 0.42.0. DTS-HD was not tested because my television does not pass DTS.

To reproduce

  1. Connect an Android device over HDMI to a receiver or soundbar that accepts E-AC-3 or TrueHD.

  2. Play a file with an E-AC-3 or TrueHD track using --ao=audiotrack --audio-spdif=eac3,truehd.

  3. Check the mpv log. Without this patch, mpv logs these lines and sends PCM:

    requested format: 192000 Hz, stereo channels, spdif-eac3
    AudioTrack.nativeOutputSampleRate = 48000
    Passthrough format unsupported.
    

The sample rate change is based on a patch by Maksym Vasylchuk for libmpv-android-video-build.

AI disclosure: written with Claude Code using Claude Fable 5.2, Claude Opus 5.5, and Claude Sonnet 5.5. Claude Code also ran the tests above on my device.

init() creates every IEC 61937 AudioTrack as stereo. TrueHD and DTS-HD
MA are carried at 192000 Hz in 8 channels, so a stereo track takes
their data at a quarter of its rate.

Use CHANNEL_OUT_7POINT1_SURROUND when the spdif format has more than
two channels.

These streams don't open today: init() also lowers their sample rate
to the PCM mixer's, and player/audio.c then rejects the output. The
next commit removes that limit. With it but without this change, a
TrueHD track plays silent with video at a quarter speed (seen on an
NVIDIA Shield TV Pro 2019, Android 11).
init() clamped every format to AudioTrack.getNativeOutputSampleRate(),
spdif included. E-AC-3, TrueHD and DTS-HD MA are carried as IEC 61937
at 192000 Hz, above the rate of the PCM mixer that AudioTrack reports,
so the AO opened at the mixer's rate, player/audio.c rejected it, and
mpv fell back to PCM:

    requested format: 192000 Hz, stereo channels, spdif-eac3
    AudioTrack.nativeOutputSampleRate = 48000
    Passthrough format unsupported.

The rate of an IEC 61937 stream is set by the codec, not by the mixer,
so the clamp now applies to PCM only. If the device cannot open the
stream at that rate, creating the AudioTrack fails and mpv falls back
to PCM as before.

Tested on master on an NVIDIA Shield TV Pro 2019 (Android 11) with
--audio-spdif=ac3,eac3,truehd: E-AC-3 5.1 reaches the soundbar as
Dolby Digital Plus 5.1 and a TrueHD Atmos track as Dolby Atmos
(TrueHD), and both survive pause and seeks. A 96000 Hz PCM track
still opens at 48000 Hz. DTS-HD is not tested: the television in
between does not pass DTS. E-AC-3 was also tested with mpv 0.41.0 and
0.42.0.

Based on a patch by Maksym Vasylchuk for the
libmpv-android-video-build project (BuzzTV-Dev, pull request 5).
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.

1 participant