Repository navigation
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
E-AC-3 and TrueHD passthrough fail with
--ao=audiotrackand fall back to PCM, so the receiver never gets Dolby Digital Plus or TrueHD.ao_audiotracknow limits theAudioTrack.getNativeOutputSampleRateclamp to PCM (skippingaf_fmt_is_spdifformats). ForENCODING_IEC61937streams with more than two channels, it opens the track withCHANNEL_OUT_7POINT1_SURROUNDinstead of stereo.Previously,
ao_audiotrackclamped 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_audiotrackalso opened every passthrough stream withCHANNEL_OUT_STEREO, even though TrueHD and DTS-HD MA use 8 channels.If a device cannot open the stream, creating the
AudioTrackfails 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):Passthrough format unsupported.; falls back to PCMPassthrough format unsupported.; falls back to PCME-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
Connect an Android device over HDMI to a receiver or soundbar that accepts E-AC-3 or TrueHD.
Play a file with an E-AC-3 or TrueHD track using
--ao=audiotrack --audio-spdif=eac3,truehd.Check the mpv log. Without this patch, mpv logs these lines and sends PCM:
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.