Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "Export compile commands for IDE
set(MOONLIGHT_BUILD_KIND "HOST" CACHE STRING "Internal Moonlight build mode")
set_property(CACHE MOONLIGHT_BUILD_KIND PROPERTY STRINGS HOST XBOX)
option(MOONLIGHT_BUILD_VIDEO_EXPERIMENTS "Build standalone GPU presentation and MPEG-2 sampling experiments" OFF)
option(MOONLIGHT_ENABLE_GPU_PRESENTATION "Enable experimental NV2A overlay presentation before software fallback" ON)
option(MOONLIGHT_INPUT_DIAGNOSTICS "Display digital controller state while diagnosing stream input" OFF)

if(MOONLIGHT_BUILD_KIND STREQUAL "XBOX")
Expand Down
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,16 @@ Only the required SVGs and their license are packaged on the ISO.
No network connection or JavaScript runtime is needed to display the icons on the console.


## Video presentation

**Settings → Display → Video Presentation** defaults to **Software**, which writes directly to the
framebuffer when available and performed better in xemu. **GPU** uses NV2A color conversion and scaling
with automatic software fallback. The setting is saved as `streaming.gpu_presentation` and both paths
are available in the same build.

## Streaming controls and statistics

The default stream profile is **640×480 at 60 FPS and 3 Mbps**. Saved settings take precedence.
Changing **Settings → Display → Stream Resolution** or **Stream Frame Rate** resets **Stream Bitrate**
to a default calculated with Moonlight Android's resolution factors and pixel-count interpolation,
scaled by the selected FPS and rounded to whole Mbps. At 30 / 60 FPS, the defaults are 1 / 3 Mbps for
Expand Down Expand Up @@ -158,12 +166,9 @@ including any scanout wait.
The stream menu can toggle these statistics for the current session; the saved setting sets the
initial state of the next session.

Video decoding runs on the CPU. Optional experimental GPU presentation accelerates color conversion
and scaling, with software fallback for unsupported frames or presentation failures. GPU
presentation is enabled by default; the build options below control its use.

Every stream summary reports GPU and software frame counts. **SOFTWARE FALLBACK USED** includes
the reason software presentation was selected, even when Performance Stats is disabled.
Video decoding runs on the CPU. Every stream summary reports GPU and software frame counts.
**SOFTWARE FALLBACK USED** includes the reason GPU presentation switched to software, even when
Performance Stats is disabled.

## 🛠️ Build

Expand Down Expand Up @@ -260,14 +265,13 @@ cmake -S . -B cmake-build-release -DBUILD_DOCS=OFF -DCMAKE_BUILD_TYPE=Release

Video build settings:

| CMake option | Default | Purpose |
| ----------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `MOONLIGHT_ENABLE_GPU_PRESENTATION` | `ON` | Enable experimental NV2A color conversion and scaling with software fallback. |
| `MOONLIGHT_BUILD_VIDEO_EXPERIMENTS` | `OFF` | Build the standalone probes described in [Video experiments](experiments/README.md). |
| `MOONLIGHT_INPUT_DIAGNOSTICS` | `OFF` | Show controller state and event counters for troubleshooting. Requires GPU presentation to be disabled so the strip is visible. |
| CMake option | Default | Purpose |
| ----------------------------------- | ------- | ---------------------------------------------------------------------------------------------- |
| `MOONLIGHT_BUILD_VIDEO_EXPERIMENTS` | `OFF` | Build the standalone probes described in [Video experiments](experiments/README.md). |
| `MOONLIGHT_INPUT_DIAGNOSTICS` | `OFF` | Show controller state and event counters. Select Software presentation to see the debug strip. |

Pass options when configuring, for example `-DMOONLIGHT_ENABLE_GPU_PRESENTATION=OFF` for software-only
presentation. Existing build directories retain their cached settings until explicitly reconfigured.
Pass these options when configuring. Existing build directories retain cached build options until
explicitly reconfigured.

### Build

Expand Down
1 change: 0 additions & 1 deletion cmake/nxdk.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ function(moonlight_add_xbox_build)
-DMOONLIGHT_TOOLCHAIN_FILE:FILEPATH=${toolchain_file}
-DMOONLIGHT_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DMOONLIGHT_BUILD_VIDEO_EXPERIMENTS:BOOL=${MOONLIGHT_BUILD_VIDEO_EXPERIMENTS}
-DMOONLIGHT_ENABLE_GPU_PRESENTATION:BOOL=${MOONLIGHT_ENABLE_GPU_PRESENTATION}
-DMOONLIGHT_INPUT_DIAGNOSTICS:BOOL=${MOONLIGHT_INPUT_DIAGNOSTICS}
-P "${driver_script}"
)
Expand Down
1 change: 0 additions & 1 deletion cmake/run-child-build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ if(MOONLIGHT_COMMAND_MODE STREQUAL "configure")
-B "${MOONLIGHT_BINARY_DIR}"
-DMOONLIGHT_BUILD_KIND:STRING=XBOX
"-DMOONLIGHT_BUILD_VIDEO_EXPERIMENTS:BOOL=${MOONLIGHT_BUILD_VIDEO_EXPERIMENTS}"
"-DMOONLIGHT_ENABLE_GPU_PRESENTATION:BOOL=${MOONLIGHT_ENABLE_GPU_PRESENTATION}"
"-DMOONLIGHT_INPUT_DIAGNOSTICS:BOOL=${MOONLIGHT_INPUT_DIAGNOSTICS}"
"-DMOONLIGHT_NXDK_DIR:PATH=${MOONLIGHT_NXDK_SOURCE_DIR}"
"-DMOONLIGHT_NXDK_BUILD_DIR:PATH=${MOONLIGHT_NXDK_DIR}"
Expand Down
1 change: 1 addition & 0 deletions cmake/sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ set(MOONLIGHT_TEST_EXCLUDED_SOURCES
"${MOONLIGHT_SOURCE_ROOT}/src/main.cpp"
"${MOONLIGHT_SOURCE_ROOT}/src/splash/splash_screen.cpp"
"${MOONLIGHT_SOURCE_ROOT}/src/streaming/ffmpeg_stream_backend.cpp"
"${MOONLIGHT_SOURCE_ROOT}/src/streaming/ffmpeg_video_frame.cpp"
"${MOONLIGHT_SOURCE_ROOT}/src/startup/memory_stats.cpp"
"${MOONLIGHT_SOURCE_ROOT}/src/streaming/session.cpp"
"${MOONLIGHT_SOURCE_ROOT}/src/streaming/stream_controls.cpp"
Expand Down
2 changes: 0 additions & 2 deletions cmake/xbox-build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ target_compile_definitions(${CMAKE_PROJECT_NAME}
USBH_USE_EXTERNAL_CONFIG="usbh_config_xbox.h"
TOML_EXCEPTIONS=0
TOML_ENABLE_WINDOWS_COMPAT=0)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
MOONLIGHT_ENABLE_GPU_PRESENTATION=$<BOOL:${MOONLIGHT_ENABLE_GPU_PRESENTATION}>)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
MOONLIGHT_INPUT_DIAGNOSTICS=$<BOOL:${MOONLIGHT_INPUT_DIAGNOSTICS}>)
add_dependencies(${CMAKE_PROJECT_NAME} moonlight-common-c)
Expand Down
4 changes: 2 additions & 2 deletions experiments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Launch an ISO with the repository's configured xemu installation, for example:
```

From a Windows command prompt, use `scripts\run-xemu.cmd --iso` with the same ISO path.
The probes use GPU presentation directly; `MOONLIGHT_ENABLE_GPU_PRESENTATION` controls the
streaming client independently.
The probes use GPU presentation directly. The streaming client selects its path in
**Settings → Display → Video Presentation**.

## Presentation probe

Expand Down
52 changes: 37 additions & 15 deletions src/app/client_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ namespace {
constexpr const char *SETTINGS_CATEGORY_PREFIX = "settings-category:";
constexpr std::array<char, 10> ADD_HOST_ADDRESS_KEYPAD_CHARACTERS {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
constexpr std::array<char, 10> ADD_HOST_PORT_KEYPAD_CHARACTERS {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
constexpr int DEFAULT_STREAM_FRAMERATE = 30;
constexpr int DEFAULT_STREAM_BITRATE_KBPS = 1000;
constexpr std::array<int, 6> STREAM_FRAMERATE_OPTIONS {15, 20, 24, 25, 30, 60};
constexpr std::array<int, 24> STREAM_BITRATE_OPTIONS {500, 750, 1000, 1500, 2000, 2500, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000};

Expand Down Expand Up @@ -230,7 +228,7 @@ namespace {
void cycle_stream_framerate(app::ClientState &state) {
const auto current = std::find(STREAM_FRAMERATE_OPTIONS.begin(), STREAM_FRAMERATE_OPTIONS.end(), state.settings.streamFramerate);
if (current == STREAM_FRAMERATE_OPTIONS.end()) {
state.settings.streamFramerate = DEFAULT_STREAM_FRAMERATE;
state.settings.streamFramerate = app::DEFAULT_STREAM_FRAMERATE;
} else {
const std::size_t nextIndex = (static_cast<std::size_t>(std::distance(STREAM_FRAMERATE_OPTIONS.begin(), current)) + 1U) % STREAM_FRAMERATE_OPTIONS.size();
state.settings.streamFramerate = STREAM_FRAMERATE_OPTIONS[nextIndex];
Expand Down Expand Up @@ -598,6 +596,12 @@ namespace {
"Cycle through the preferred video bitrate. Lower bitrates reduce bandwidth use. Changing resolution or frame rate resets this value to a recommended default.",
true,
},
{
"toggle-gpu-presentation",
std::string("Video Presentation: ") + (state.settings.presentation.gpuPresentation ? "GPU" : "Software"),
"Choose how new streams display decoded video. GPU uses NV2A with automatic software fallback. Software can be faster in xemu.",
true,
},
{
"toggle-play-audio-on-pc",
std::string("Play Audio on PC: ") + (state.settings.playAudioOnPc ? "On" : "Off"),
Expand All @@ -612,7 +616,7 @@ namespace {
},
{
"toggle-show-performance-stats",
std::string("Performance Stats: ") + (state.settings.showPerformanceStats ? "On" : "Off"),
std::string("Performance Stats: ") + (state.settings.presentation.showPerformanceStats ? "On" : "Off"),
"Show performance statistics during playback and after the stream ends.",
true,
},
Expand Down Expand Up @@ -1892,10 +1896,7 @@ namespace app {
state.settings.logViewerPlacement = LogViewerPlacement::full;
state.settings.loggingLevel = logging::LogLevel::none;
state.settings.xemuConsoleLoggingLevel = logging::LogLevel::none;
state.settings.streamFramerate = DEFAULT_STREAM_FRAMERATE;
state.settings.streamBitrateKbps = DEFAULT_STREAM_BITRATE_KBPS;
state.settings.playAudioOnPc = false;
state.settings.showPerformanceStats = false;
state.settings.playAudioOnXbox = true;
state.settings.controls.screenshotDirectory.clear();
state.settings.controls.keyboardDockTop = false;
Expand Down Expand Up @@ -2447,6 +2448,32 @@ namespace app {
return true;
}

/**
* @brief Toggle a presentation preference and refresh its selected menu row.
*
* @param state Client state containing the presentation preferences.
* @param itemId Activated menu row.
* @param update Update receiving the request to persist the change.
* @return True when the activated row changed a presentation preference.
*/
bool handle_presentation_setting_activation(ClientState &state, const std::string &itemId, AppUpdate &update) {
auto &presentation = state.settings.presentation;
if (itemId == "toggle-gpu-presentation") {
presentation.gpuPresentation = !presentation.gpuPresentation;
state.shell.statusMessage = std::string("Video presentation set to ") + (presentation.gpuPresentation ? "GPU" : "Software");
} else if (itemId == "toggle-show-performance-stats") {
presentation.showPerformanceStats = !presentation.showPerformanceStats;
state.shell.statusMessage = std::string("Performance stats ") + (presentation.showPerformanceStats ? "enabled" : "disabled");
} else {
return false;
}

state.settings.dirty = true;
update.persistence.settingsChanged = true;
rebuild_menu(state, itemId);
return true;
}

/**
* @brief Update settings inline or open the screenshot folder picker, emitting only required side effects.
*
Expand Down Expand Up @@ -2504,6 +2531,9 @@ namespace app {
rebuild_menu(state, "cycle-stream-bitrate");
return;
}
if (handle_presentation_setting_activation(state, detailUpdate.activatedItemId, *update)) {
return;
}
if (detailUpdate.activatedItemId == "toggle-play-audio-on-pc") {
state.settings.playAudioOnPc = !state.settings.playAudioOnPc;
state.settings.dirty = true;
Expand All @@ -2520,14 +2550,6 @@ namespace app {
rebuild_menu(state, "toggle-play-audio-on-xbox");
return;
}
if (detailUpdate.activatedItemId == "toggle-show-performance-stats") {
state.settings.showPerformanceStats = !state.settings.showPerformanceStats;
state.settings.dirty = true;
update->persistence.settingsChanged = true;
state.shell.statusMessage = std::string("Performance stats ") + (state.settings.showPerformanceStats ? "enabled" : "disabled");
rebuild_menu(state, "toggle-show-performance-stats");
return;
}
if (detailUpdate.activatedItemId == "screenshot-directory") {
state.directoryPicker = {};
state.directoryPicker.path = state.settings.controls.screenshotDirectory.empty() ? startup::default_storage_path("screenshots") : state.settings.controls.screenshotDirectory;
Expand Down
19 changes: 15 additions & 4 deletions src/app/client_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ namespace app {
right, ///< Dock the log viewer on the right side of the split layout.
};

inline constexpr int DEFAULT_STREAM_FRAMERATE = 60; ///< Stream frame rate at the default 640x480 resolution.
inline constexpr int DEFAULT_STREAM_BITRATE_KBPS = 3000; ///< Bitrate for the default 640x480, 60 FPS profile.

/**
* @brief Focus areas used by the two-pane settings screen.
*/
Expand Down Expand Up @@ -378,6 +381,14 @@ namespace app {
bool keyboardDockTop = false; ///< Dock the stream keyboard to the top instead of the bottom.
};

/**
* @brief Preferences for presenting decoded video and its on-screen statistics.
*/
struct VideoPresentationPreferences {
bool gpuPresentation = false; ///< Opt in to NV2A presentation with software fallback on new streams.
bool showPerformanceStats = false; ///< Display live performance telemetry and include it in the stream summary.
};

/**
* @brief State owned by the settings, log viewer, and saved-file workflows.
*/
Expand All @@ -393,10 +404,10 @@ namespace app {
std::vector<VIDEO_MODE> availableVideoModes; ///< Detected Xbox video modes exposed as stream-resolution choices.
VIDEO_MODE preferredVideoMode {}; ///< Preferred stream resolution requested from the host.
bool preferredVideoModeSet = false; ///< True when preferredVideoMode contains a user-selected or default mode.
int streamFramerate = 30; ///< Preferred stream frame rate in frames per second.
int streamBitrateKbps = 1000; ///< Preferred stream bitrate in kilobits per second.
int streamFramerate = DEFAULT_STREAM_FRAMERATE; ///< Preferred stream frame rate in frames per second.
int streamBitrateKbps = DEFAULT_STREAM_BITRATE_KBPS; ///< Preferred stream bitrate in kilobits per second.
VideoPresentationPreferences presentation; ///< Presentation path and statistics overlay preferences.
bool playAudioOnPc = false; ///< True when the host PC should continue local audio playback during streaming.
bool showPerformanceStats = false; ///< Display live performance telemetry and include it in the stream summary.
bool playAudioOnXbox = true; ///< True when the Xbox should decode and play streamed audio locally.
LocalStreamPreferences controls; ///< Screenshot storage and keyboard placement preferences.
bool dirty = false; ///< True when persisted TOML-backed settings changed and should be saved.
Expand Down Expand Up @@ -508,7 +519,7 @@ namespace app {
};

/**
* @brief Create the initial app state shown after startup.
* @brief Create the initial app state with the default stream preferences.
*
* @return The initial client state.
*/
Expand Down
8 changes: 7 additions & 1 deletion src/app/settings_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern "C" FILE *_wfopen(const wchar_t *path, const wchar_t *mode);
#include <toml++/toml.hpp>

// local includes
#include "src/app/stream_bitrate.h"
#include "src/platform/error_utils.h"
#include "src/platform/filesystem_utils.h"
#include "src/startup/storage_paths.h"
Expand Down Expand Up @@ -348,6 +349,7 @@ namespace {
content += "# Preferred streaming parameters.\n";
content += std::string("fps = ") + std::to_string(settings.streamFramerate) + "\n";
content += std::string("bitrate_kbps = ") + std::to_string(settings.streamBitrateKbps) + "\n";
content += std::string("gpu_presentation = ") + (settings.gpuPresentation ? "true" : "false") + "\n";
content += std::string("play_audio_on_pc = ") + (settings.playAudioOnPc ? "true" : "false") + "\n";
content += std::string("play_audio_on_xbox = ") + (settings.playAudioOnXbox ? "true" : "false") + "\n";
content += "# Show stream telemetry after streaming ends.\n";
Expand Down Expand Up @@ -399,7 +401,7 @@ namespace {
void inspect_streaming_keys(const toml::table &streamingTable, const std::string &filePath, app::LoadAppSettingsResult *result) {
for (const auto &[rawKey, node] : streamingTable) {
const std::string key(rawKey.str());
if (key == "video_width" || key == "video_height" || key == "video_bpp" || key == "video_refresh" || key == "video_mode_selected" || key == "fps" || key == "bitrate_kbps" || key == "play_audio_on_pc" || key == "play_audio_on_xbox" || key == "show_performance_stats" || key == "screenshot_directory" || key == "keyboard_dock_top") {
if (key == "video_width" || key == "video_height" || key == "video_bpp" || key == "video_refresh" || key == "video_mode_selected" || key == "fps" || key == "bitrate_kbps" || key == "gpu_presentation" || key == "play_audio_on_pc" || key == "play_audio_on_xbox" || key == "show_performance_stats" || key == "screenshot_directory" || key == "keyboard_dock_top") {
continue;
}

Expand Down Expand Up @@ -496,8 +498,12 @@ namespace app {
load_integer_setting(settingsTable["streaming"]["video_refresh"], filePath, "streaming.video_refresh", &result.settings.preferredVideoMode.refresh, &result.warnings);
load_boolean_setting(settingsTable["streaming"]["video_mode_selected"], filePath, "streaming.video_mode_selected", &result.settings.preferredVideoModeSet, &result.warnings);
load_integer_setting(settingsTable["streaming"]["fps"], filePath, "streaming.fps", &result.settings.streamFramerate, &result.warnings);
const auto &preferredMode = result.settings.preferredVideoMode;
const VIDEO_MODE bitrateMode = result.settings.preferredVideoModeSet && preferredMode.width > 0 && preferredMode.height > 0 ? preferredMode : VIDEO_MODE {640, 480, 32, 60};
result.settings.streamBitrateKbps = default_stream_bitrate_kbps(bitrateMode.width, bitrateMode.height, result.settings.streamFramerate);
load_integer_setting(settingsTable["streaming"]["bitrate_kbps"], filePath, "streaming.bitrate_kbps", &result.settings.streamBitrateKbps, &result.warnings);
load_boolean_setting(settingsTable["streaming"]["play_audio_on_pc"], filePath, "streaming.play_audio_on_pc", &result.settings.playAudioOnPc, &result.warnings);
load_boolean_setting(settingsTable["streaming"]["gpu_presentation"], filePath, "streaming.gpu_presentation", &result.settings.gpuPresentation, &result.warnings);
load_boolean_setting(settingsTable["streaming"]["play_audio_on_xbox"], filePath, "streaming.play_audio_on_xbox", &result.settings.playAudioOnXbox, &result.warnings);
load_boolean_setting(settingsTable["streaming"]["show_performance_stats"], filePath, "streaming.show_performance_stats", &result.settings.showPerformanceStats, &result.warnings);
load_boolean_setting(settingsTable["streaming"]["keyboard_dock_top"], filePath, "streaming.keyboard_dock_top", &result.settings.keyboardDockTop, &result.warnings);
Expand Down
Loading
Loading