Repository navigation
feat(audio): hand TrueHD and DTS-HD passthrough to the host as spatial audio - #3
Open
kristofferR wants to merge 2 commits into
Open
kristofferR wants to merge 2 commits into
kristofferR wants to merge 2 commits into
Conversation
mpv's reload left the frame it had handed to the old output in the ao filter, which then never asked the chain for more, and never woke the output chain after resetting it, so the next output never opened. Both patches come from kristofferR/mpv-build (pool 0034 and 0102).
…l audio mpv decodes TrueHD and DTS-HD to PCM, so the Atmos objects and DTS:X never reach the receiver. Patch 0007 adds a "spatial" audio output that hands the passthrough bursts to a host sink (mpv/spatial_audio.h, sink version 2) and keeps mpv's clock on the AVSampleBufferRenderSynchronizer the host renders into. mpv's volume and mute reach the host through set_volume, and a stream the host fails on falls back to PCM. FFmpeg now builds its spdif muxer, which passthrough needs. The release workflow runs the output's unit test and checks the muxer is in the build. Every other format, and any player that doesn't set the sink, is unaffected.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
5 tasks done
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.
AI used: Claude Opus 5.5, extra high reasoning.
Description
mpv decodes TrueHD and DTS-HD to PCM, so the Atmos objects and DTS:X never reach the receiver. Players that want them as Apple spatial audio, through SpatialAudioBridge, need the compressed stream, and libmpv has no API for it.
Patch 0007 adds a
spatialaudio output for that:--audio-spdif=truehd,dts-hdand--ao=spatial,<pcm output>, it hands mpv's passthrough bursts, unchanged, to a host sink described in the new public headermpv/spatial_audio.hand passed as--ao-spatial-sink.AVSampleBufferRenderSynchronizer, gives it to the host to render into, and reports mpv's delay from its clock. The clock waits at the timeline's start until the host has enough queued, so video waits with it. Reset begins a new timeline and pause stops the clock. mpv queues at most 3 s ahead.set_volume, since a bitstream cannot be scaled.ao_set_gain()calls a new optionalset_gaindriver hook for that, so a change arrives at once, paused or not.has_failed. The output then latches that format and reloads, the reopen refuses it, and mpv decodes the track. The next PCM output clears the latch.loadfile replacebetween files. Gapless handoff to a queued next file is not supported.Patches 0008 and 0009 fix mpv's audio output reload, which left the frame held for the old output in the ao filter and never woke the output chain, so the next output never opened. The latch fallback needs them.
FFmpeg now builds its
spdifmuxer, which mpv's passthrough needs. The release workflow runs the output's unit test and checks that the muxer is in the build. The podspec version and the release notes are left for the release.Existing players are unaffected: Streamyfin's current develop needs no change for this release, because nothing selects the new output unless the app sets the sink. Streamyfin's spatial audio PR, streamyfin/streamyfin#2268, on the other hand, needs a release with this patch: its sink uses
mpv/spatial_audio.h's types, so it does not compile against 0.41.0-av5.The same sink interface (version 2) is in Plezy's mpv build, byte for byte, so one host sink works with both.
Testing
scripts/test-spatial-audio-output.shbuilds the output against the pinned mpv with every patch applied and drives it like mpv's push thread, against a fake sink and a real synchronizer: the clock hold, pause, underruns, seeks, the end of a stream, volume (including before open and while paused) and the latch. The release workflow runs it.spatial,audiounitas PCM; DTS-HD MA without DTS:X falls back to PCM.The
CIworkflow's Demo-macOS build fails here, as it already does onrelease/0.41.0-av5:Package.swiftpoints at an iOS and tvOS-only xcframework.