Description
This PR adds optional Dolby Digital (AC-3) and Dolby Digital Plus (E-AC-3) encoded audio output to Sunshine on platforms whose linked FFmpeg build contains the corresponding encoders. Compatible Moonlight clients can negotiate these formats as an alternative to Opus when they need a compressed Dolby bitstream for native decoding or passthrough.
The main use case is Moonlight running directly on a Smart TV connected to a receiver or sound system through optical S/PDIF. AC-3 can provide Dolby Digital stereo or 5.1 output over compatible TV audio paths. Actual output depends on the TV model, its audio settings, the receiver, and client support; E-AC-3 passthrough over optical output is model-dependent.
Related client implementation
The companion Moonlight Tizen with AC-3 support implements the client-side Dolby offer/accept negotiation and passthrough through Tizen's native EMSS audio renderer. It is an independently maintained client fork and is linked here as an example of a client that uses this host feature. This PR changes Sunshine only; other clients need their own support for the optional negotiation and playback/passthrough path.
Implementation
- AC-3 and E-AC-3 encoding through Sunshine's existing linked FFmpeg libraries; no separate FFmpeg runtime distribution or external DLLs are required.
- Encoder availability detection as part of host-side codec negotiation.
- Audio format settings for Opus (default), AC-3, and E-AC-3 on supported platforms. If the active FFmpeg build lacks the selected encoder, Sunshine falls back to Opus.
- RTSP offer/accept negotiation: Sunshine selects Dolby only when the client explicitly accepts the exact codec offered; otherwise it uses Opus.
- Stereo and 5.1 channel support for both Dolby formats.
- A
High quality audioswitch, disabled by default, for higher Dolby bitrates at the cost of increased network bandwidth. It has no effect on Opus and is disabled in the UI while Opus is selected. - 32 ms Dolby access units and an increased audio packet buffer size for Dolby frames.
- Configuration documentation and English UI strings.
The existing Opus encoder and its normal negotiation path are intended to remain behaviorally unchanged. This is a host-side feature, not a Tizen-only or Windows-only server feature.
Testing
- Added native regression tests for channel-aware bitrates, exact AC-3/E-AC-3 acceptance, missing or mismatched acceptance, unavailable encoders, unsupported channel counts, packet duration, quality flags, codec labels, and encoding without capture hardware.
- Added Web UI regression tests for the Dolby selector across Windows, Linux, macOS, and FreeBSD, including preservation of a saved Dolby selection without capability metadata.
- Manually tested end-to-end AC-3 and E-AC-3 playback with a Windows Sunshine host and the companion Moonlight Tizen client, including stereo/5.1 and normal/high-quality bitrate settings.
- Windows AMD64 and ARM64 build and native tests passed on the merged feature tree in validation run 38719776826.
- SonarCloud Quality Gate passed with zero new issues.
- The primary
sunshinestreamRead the Docs build passed (build 35163518). - Merged current upstream
masterinto the feature branch in commite7e57df; GitHub reports no merge conflicts.
Type of Change
- feat: New feature (non-breaking change which adds functionality)
- fix: Bug fix
- docs: Documentation only changes
- style: Changes that do not affect the meaning of the code
- refactor: Code change that does not fix a bug or add a feature
- perf: Code change that improves performance
- build: Changes that affect the build system or external dependencies
- ci: Changes to CI configuration files and scripts
- chore: Other changes that do not modify src or test files
- revert: Reverts a previous commit
Checklist
- Code follows the project's style guidelines (format/lint has not been run on the latest revision).
- Code has been self-reviewed.
- Code has comments in key parts of the implementation.
- Documentation for the new configuration options has been added.
- Tests have been added or updated, and the latest Windows build/test validation is complete.
AI Usage
- AI tools were used while preparing this PR.
The contributor remains responsible for reviewing the implementation, verifying test results, and addressing review feedback.
Activity
40Could a maintainer approve/enable these workflow runs for this PR?
We only get 20 runners from GitHub and these are basically running all day long, so I'll run it when I'm ready to merge the code.
Docs failures are here: https://app.readthedocs.org/projects/sunshinestream/builds/35131897/
Don't worry about the other already reported failure.
Your agent can lint and build the docs if it follows the AGENTS.md file.
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
@ReenigneArcher I've addressed the four SonarCloud findings in the latest revision (4b10f9a): the FFmpeg encoder class now explicitly deletes copy/move operations, channel_layout is scoped in the if init-statement, and the two enum-verbosity findings use C++20 using enum. SonarCloud's Quality Gate is now green, and the latest Windows validation passed both build and tests on AMD64 and ARM64 (run 38719776826). The sunshinestream Read the Docs build also passes. Could you please review the updated PR again? Thank you.
Quality Gate failed
Failed conditions
30 New issues
B Maintainability Rating on New Code (required ≥ A)
30 New Code Smells (required ≤ 0)
See analysis details on SonarQube Cloud
Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE
Hi @ReenigneArcher, just following up on this PR. I've addressed the requested changes and tested the Windows build locally; it's working correctly with Opus, AC-3, and E-AC-3. When you have a chance, could you please take another look and approve it if everything looks good? Thanks!
Update: I retrieved the raw log for the
sunshinestreamRead the Docs build. The failure was caused by missing Doxygen documentation forlaunch_session_t::audio_negotiation_tand its fields,audio::dolby_bitrate_kbpsparameters/return value, and the RTSP helper/handler functionscmd_option_impl,cmd_describe_impl,cmd_setup, andcmd_play_impl.I added the missing comments in c9ad363. The new
sunshinestreamRead the Docs check is now successful for that commit. The PR's status links to the rendered preview: https://lizardbyte--5917.org.readthedocs.build/projects/sunshine/5917/.Per your guidance, I have not started the GitHub Actions workflows. I have also left the separate
lizardbyte-gh-pages-sunshinecheck alone.