Skip to content

feat(audio): add optional Dolby Digital (AC-3 and E-AC-3) output to the Sunshine offerts - #5917

Open
fidoboy wants to merge 113 commits into
SunshineStream:masterfrom
fidoboy:pr/dolby-ac3-eac3
Open

fidoboy wants to merge 113 commits into
SunshineStream:masterfrom
fidoboy:pr/dolby-ac3-eac3

Conversation

@fidoboy

@fidoboy fidoboy commented Oct 13, 2026 •

Copy link
Copy Markdown

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 (see details in its website) implements the client-side Dolby offer/accept negotiation and passthrough through Tizen's native EMSS audio renderer. It is an independently maintained client and is linked here as an example of a client that uses this new 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.
  • Dolby bitrate quality tier is selected from the client's request; the host does not expose a separate High quality audio switch. Higher bitrates increase network bandwidth usage.
  • 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, client-requested quality tiers, 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 the quality tiers requested by the client.
  • 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 sunshinestream Read the Docs build passed (build 35163518).
  • Merged current upstream master into the feature branch in commit e7e57df; 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 (the repository's lb-update-clang-format helper has been run and a second pass produced no changes; other lint checks have 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.

@fidoboy
fidoboy marked this pull request as ready for review October 13, 2026 21:25

fidoboy commented Oct 14, 2026 •

Copy link
Copy Markdown
Author

Update: I retrieved the raw log for the sunshinestream Read the Docs build. The failure was caused by missing Doxygen documentation for launch_session_t::audio_negotiation_t and its fields, audio::dolby_bitrate_kbps parameters/return value, and the RTSP helper/handler functions cmd_option_impl, cmd_describe_impl, cmd_setup, and cmd_play_impl.

I added the missing comments in c9ad363. The new sunshinestream Read 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-sunshine check alone.

@ReenigneArcher

Copy link
Copy Markdown
Member

Could 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.

@ReenigneArcher ReenigneArcher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes on c9ad3637b48907316f3957f72ac46cb9c7155023: the settings page cannot see the advertised encoder capabilities, and the new backend/negotiation behavior has no added regression tests.

On FFmpeg packaging, I recommend using Sunshine's existing linked FFmpeg libraries for this feature. The pinned build-deps configuration enables the encoders, and its published macOS archive already contains both native encoders. I linked the PR's extracted encoder class to that archive and successfully encoded all eight combinations of AC-3/E-AC-3, stereo/5.1, and normal/high quality. This establishes that a second runtime FFmpeg distribution is unnecessary for those encoding operations; it is not a Windows DLL-loader test.

The native AC-3 and E-AC-3 implementations are LGPL-2.1-or-later, compatible with Sunshine's GPL-3.0 licensing. FFmpeg's legal page distinguishes copyright licensing from codec patents. I found no identified licensing requirement in this PR that mandates user-supplied DLLs. Dolby's 2007 filing listed original Dolby Digital patent expirations through 2017 and Dolby Digital Plus through 2022; that historical disclosure is not comprehensive present-day patent or trademark clearance.

Validation: 28 existing focused Vue tests passed, along with two temporary review reproductions showing the settings bug and verifying the proposed endpoint correction; all eight isolated encoding cases passed; whitespace checks passed for all 15 changed files. The reproductions and probes live outside the working checkout and are not tests contributed by this PR.

GitHub reports the head as mergeable and behind master (current branch tip a178f465e42f8e77102002e9156b8becd7b13628). The Sunshine documentation check passed. Full Windows builds, Windows DLL loading, client passthrough, and protocol interoperability were not verified locally; GitHub Actions await maintainer approval. The reported Sonar issue points to the unchanged permission-status test override, so it is not a new-code finding.

Review completed by Codex | Model: gpt-6.1-sol | Thinking: xhigh

Comment thread src/confighttp.cpp Resolved
Comment thread src/audio.cpp Resolved

fidoboy commented Oct 15, 2026

Copy link
Copy Markdown
Author

Thanks for the detailed review. I pushed a revision to address the requested changes:

  • Moved ac3_available and eac3_available into /api/config, which is the endpoint consumed by Config.vue.
  • Replaced the extra runtime FFmpeg DLL loader with calls to Sunshine's existing linked FFmpeg libraries and updated the configuration documentation and UI text accordingly.
  • Extracted the exact offer/accept and fallback decision into a helper used by RTSP and the native unit tests. Added coverage for bitrate selection, matching/mismatched or missing acceptance, unavailable encoders, unsupported channel counts, codec labels, and Windows x64 encoding without capture hardware.
  • Added Web UI regression tests for full, partial, and no Dolby encoder availability.

The code and tests are committed, but I have not run the revised Windows build or tests locally. I have updated the PR description to reflect that CI and playback re-validation of the linked-FFmpeg change are still pending. I have not attempted to start the Actions workflows, per your note about the runner pool.

fidoboy commented Oct 15, 2026

Copy link
Copy Markdown
Author

I extended the revision beyond the review fixes to remove the remaining Windows/runtime-DLL assumptions:

  • The Dolby encoder and FFmpeg headers are now compiled through Sunshine's existing FFmpeg linkage without a Windows x64 guard.
  • The audio-format selector and High quality audio control are visible on Windows, Linux, macOS, and FreeBSD. Capability metadata is no longer exposed just to gate the form; a saved Dolby selection is no longer rewritten to Opus while loading the page.
  • Runtime encoder detection and the RTSP offer/accept path still retain Opus as the safe streaming fallback if the linked build lacks an encoder or the client does not accept the offer.
  • Native encoder tests no longer have a Windows-only guard, and the Web UI test now checks the selector across the four platforms.
  • I updated the documentation and removed the obsolete external-DLL warning text. I also removed the old UI screenshots from the description because they showed the previous availability-gated selector.

The current branch head contains these changes. I have not run the revised build/tests or verified Dolby playback on other platforms; per the earlier request, I am leaving Actions for maintainer scheduling.

@fidoboy

fidoboy commented Nov 27, 2026 •

Copy link
Copy Markdown
Author

Hi @ReenigneArcher, is there anything more that needs to be changed or do I need to do anything more to get the PR approved?

Copy link
Copy Markdown
Member

Thanks. I don’t have any further code changes to request on 6858d25. The RTSP test signatures now match production, the packet-writer tests check the AES key and IV sizes, and there are no CI changes in the diff.

The remaining item from my earlier review is playback validation. If your existing test covered high-quality 5.1 AC-3 on a 1500-byte MTU path, please share the exact Sunshine and Tizen client revisions and whether playback stayed clean. If it didn’t cover that case, please retest it on the current PR head. The writer tests cover buffer capacity, not whether the larger audio packets reach the client and play correctly. Maintainer-gated CI is separate; there’s nothing for you to change there.

Review completed by Codex | Model: unavailable | Thinking: unavailable

Copy link
Copy Markdown
Member

One new fix is needed on c21f417. The ANNOUNCE responder now takes a fifth bool high_quality_audio_selected, but the test declaration and the test call still use four arguments. The test calls a symbol that production no longer defines, so it won’t link.

Please add the bool to the declaration and call, then extend the existing socket test to check that the serialized x-nv-audio.surround.AudioQuality header is 0 for standard Dolby, 1 for high-quality Dolby, and absent for Opus fallback. The focused GoogleTest filter is --gtest_filter=RtspAnnounceResponseTest.*. Please also document the new parameter in the responder’s Doxygen comment. I checked the signatures in source but didn’t run the test binary.

Review completed by Codex | Model: unavailable | Thinking: unavailable

@fidoboy

fidoboy commented Nov 27, 2026 •

Copy link
Copy Markdown
Author

Manual Dolby audio validation

Tested using Moonlight Tizen v1.3.2 stable and a Windows AMD64 build of Sunshine.

Sunshine build:

Results:

Audio codec Channels HQ indicator
Opus Stereo White
E-AC-3 Stereo Green
E-AC-3 5.1 Green

Both Dolby tests successfully reported HQ audio through Moonlight's statistics overlay.

The Opus result is included for comparison only; its existing behavior is outside the scope of this PR.

Copy link
Copy Markdown
Member

Thanks for pinning down the versions. I verified that the fork workflow checked out f768af9 and that both Windows test jobs passed. The green HQ indicator confirms the client saw the negotiated quality, but it doesn’t tell us how the audio played. Was the 5.1 AC-3 audio clean throughout the test (no dropouts), and was the network path using the standard 1500-byte MTU rather than jumbo frames? If you already checked both, a brief confirmation is enough; there’s no need to rebuild.

Review completed by Codex | Model: unavailable | Thinking: unavailable

@fidoboy

fidoboy commented Nov 27, 2026 •

Copy link
Copy Markdown
Author

Playback validation – E-AC-3 5.1 over a 1500-byte MTU path

Hi,

I have completed the playback validation requested.

Test environment

  • Sunshine: Windows AMD64 build from GitHub Actions run #46047673329
  • Sunshine source commit: f768af9ce72a5fb5b85239bf93a7fa594eb69cbe
  • Client: Moonlight Tizen v1.3.2 Stable
  • Sunshine host connected via Ethernet.
  • Tizen client connected via Wi-Fi.
  • Both devices are on the same local network.

MTU 1500 verification

The host Ethernet interface reports an MTU of 1500 bytes.

I also verified the complete path to the Tizen client (192.168.0.41) using:

ping 192.168.0.41 -f -l 1472

All four packets were received successfully, with no fragmentation and 0% packet loss. Since 1472 bytes of ICMP payload plus the 28-byte IPv4/ICMP headers equals 1500 bytes, this confirms that the path supports 1500-byte IPv4 packets without fragmentation.

Audio playback results

  • Codec tested: E-AC-3 (Dolby Digital Plus)
  • Channel configuration: 5.1
  • HQ indicator in Moonlight statistics overlay: Green
  • Audio playback: Clean and stable, with no audible dropouts or distortion.

The previous AC-3 stereo and 5.1 tests also showed the HQ indicator in green.

Conclusion

High-quality Dolby audio negotiation and playback work correctly on the tested 1500-byte MTU network path. No playback issues were observed.

Copy link
Copy Markdown
Member

Thanks, that confirms clean 5.1 E-AC-3 playback. Could you repeat the listening check on the same setup with AC-3 selected instead of E-AC-3, keeping 5.1 and HQ enabled? The host sends 640 kbps for HQ 5.1 AC-3 versus 384 kbps for HQ 5.1 E-AC-3, so the AC-3 case exercises larger packets. The existing build is fine; just note whether you hear dropouts or distortion. If you already listened to the earlier AC-3 run on this same setup, confirming that is enough.

Review completed by Codex | Model: unavailable | Thinking: unavailable

@fidoboy

fidoboy commented Nov 27, 2026 •

Copy link
Copy Markdown
Author

Test setup

  • Sunshine: Windows AMD64 build from workflow 46047673329, connected over 1 Gbps Ethernet.
  • Moonlight Tizen: v1.3.2 Stable Release, connected over Wi-Fi.
  • MTU: 1500.

Playback results

Audio format Channels Bitrate (HQ) HQ indicator Listening result
Opus Stereo — White —
AC-3 Stereo 192 kbps Green Clean
AC-3 5.1 640 kbps Green Clean — no dropouts or distortion
E-AC-3 Stereo 192 kbps Green Clean
E-AC-3 5.1 384 kbps Green Clean

The AC-3 5.1 playback sounded good, with no audible dropouts or distortion. The HQ indicator remained green throughout the test.

This confirms clean HQ playback with both AC-3 and E-AC-3 in stereo and 5.1 on the same MTU 1500 setup. All four Dolby HQ bitrates match the values configured in Sunshine.

@fidoboy

fidoboy commented Nov 27, 2026

Copy link
Copy Markdown
Author

@ReenigneArcher Do you need anything more?

@ReenigneArcher

Copy link
Copy Markdown
Member

Patience... there's 75 open PRs. I'm going as fast as I can.

@fidoboy

fidoboy commented Nov 27, 2026

Copy link
Copy Markdown
Author

Ok, Patience is something I have :) No problem

@fidoboy

fidoboy commented Nov 29, 2026 •

Copy link
Copy Markdown
Author

Patience... there's 75 open PRs. I'm going as fast as I can.

Hi @ReenigneArcher, This PR has been ready for merging for two days now. Please merge it soon. I'm concerned that new changes to the master branch might cause further issues that would prevent a conflict-free merge.

@fidoboy fidoboy left a comment •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @ReenigneArcher What happened? Why is this closed now without merge?

@ReenigneArcher

Copy link
Copy Markdown
Member

I don't have time to review this right now and you seem to not have patience.

@fidoboy

fidoboy commented Nov 29, 2026 •

Copy link
Copy Markdown
Author

I don't have time to review this right now and you seem to not have patience.

@ReenigneArcher I just wanted to make sure there wouldn't be any new conflicts with the target branch, as has happened before. I've put a lot of effort and work into this PR, so I didn't want to make it harder to merge. That's why I left another reminder with the warning. I didn't mean to sound impatient—just cautious. That's all. Please reactivate this PR so that it remains pending merge if everything is correct, as it appeared to be earlier.

@fidoboy

fidoboy commented Nov 29, 2026 •

Copy link
Copy Markdown
Author

@ReenigneArcher I don't really understand how the PR process works or how long it's reasonable for a pending merge to remain on hold. I'm not really familiar with how GitHub works, how pull requests are typically handled, or how long it takes to complete a successful merge. That's why I may have been a little too eager about this. I thought that two days after the last response, it was reasonable to check in and express interest in its status, just in case it had been forgotten. So, please reactivate the PR, and I'll wait as long as it takes. From now on, I'll consider it normal to have to wait several days for it to be processed.

@ReenigneArcher

Copy link
Copy Markdown
Member

This is one of the one most popular projects on all of GitHub, and we are inundated with PRs now that AI has made it so anyone can contribute. Unfortunately stuff is going to sit in review a lot longer now. We used to have 20-30 pending PRs at a time. Now it's 70-80 while I have AI reviewing issues and PRs basically 24/7.

I have not even really looked at this PR in detail, but I think to improve the chances of getting this merged it would be good if other moonlight clients supported these audio codecs. Right now it seems like your fork is the only one?

@fidoboy

fidoboy commented Nov 29, 2026

Copy link
Copy Markdown
Author

I

This is one of the one most popular projects on all of GitHub, and we are inundated with PRs now that AI has made it so anyone can contribute. Unfortunately stuff is going to sit in review a lot longer now. We used to have 20-30 pending PRs at a time. Now it's 70-80 while I have AI reviewing issues and PRs basically 24/7.

I have not even really looked at this PR in detail, but I think to improve the chances of getting this merged it would be good if other moonlight clients supported these audio codecs. Right now it seems like your fork is the only one?

You're right, and I understand. I apologize if I was too pushy. For my part, I've put a great deal of effort into the Moonlight client for Tizen to ensure it works properly with Dolby Digital audio. It's a project I conceived several years ago. Indeed, this is currently the only GameStream client that uses the audio stream in that format.

@sonarqubecloud

Copy link
Copy Markdown

@fidoboy

fidoboy commented Nov 29, 2026 •

Copy link
Copy Markdown
Author

@ReenigneArcher But you should also consider its importance—not just if you’re the only one who will be using the audio stream in this format. In the case of TizenOS (which is the operating system used by all Samsung TVs), using the AC-3 or E-AC-3 format is essential because, otherwise, you won’t be able to get 5.1-channel surround sound. On clients running Windows, macOS, or other Linux distributions, this may not be as important, since there are more routing options on the client side. But to ensure playback on any TV running TizenOS (which, as I mentioned, includes all Samsung TVs as well as some others), this aspect is crucial. Without this format, it’s impossible to achieve surround sound in any other way. And currently this is the only active Moonlight client being mantained and developed for this platform. There isn't any other. You can see detailed info about this here: https://fidoboy.github.io/moonlight-tizen-ac3/

This branch has not been deployed

No deployments
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.

2 participants