mirror of
https://github.com/LizardByte/Sunshine.git
synced 2026-11-30 09:08:53 +00:00
The PulseAudio backend built the capture stream's channel map from the Opus channel mapping. That mapping is applied by the multistream encoder in audio.cpp and undone by the client when it decodes, so the two cancel out. Using it as the capture channel map makes PulseAudio reorder the samples as well, and that second reordering is never undone. It is invisible with the built-in mappings, which are all identities, so it went unnoticed until custom surround-params arrived in #2424. A client that requests its own mapping gets permuted channels: the webOS Moonlight client asks for 0,1,4,5,2,3 and ends up with centre on rear left, rear left on centre, LFE on rear right and rear right on the subwoofer. Capture in the canonical layout instead, which is what the WASAPI and macOS backends already do by ignoring the mapping argument entirely. Since map_stereo, map_surround51 and map_surround71 are all the identity over speaker_e, the canonical position of channel i is position_mapping[i], so the map is now filled directly from the channel index. Clients that do not send surroundParams are unaffected: the resulting pa_channel_map is identical to the current one for every layout in stream_configs. No other Moonlight client sends surroundParams today; android, ios, qt, embedded and tizen send only the standard surroundAudioInfo. The map construction moves into fill_canonical_channel_map() so it can be tested without a running PulseAudio server, and position_mapping becomes a std::array bounded by speaker::MAX_SPEAKERS so the parallel-array relationship with speaker_e is enforced by the compiler. Out-of-range channel counts are now rejected rather than read past the end. Refs: https://github.com/mariotaku/moonlight-tv/issues/575 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>