How moonlight-stream/moonlight-android works
Project type and purpose
• Moonlight Android is a native Android client application for NVIDIA GameStream and the open-source Sunshine server.
• It is not a web service or back-end system; it is a mobile (Android) full-feature media-streaming application with a Java/Kotlin UI layer, platform bindings, networking, and a native (C/C++) streaming core.
File structure
• Top-level “app” folder: Android Studio project with Gradle build scripts, Java source under app/src/main/java, resources under app/src/main/res, and JNI code under app/src/main/jni.
• LuaScripts directory: additional scripts for parsing, not core to Android build.
• JNI folder “moonlight-core”: the native streaming engine, with OpenSSL, libopus, SDL-like layers.
• Subdirectories under java/com/limelight:
• binding – platform abstractions (audio, crypto, input, video)
• nvstream – implementation of the streaming protocol (connection management, packet handling, HTTP pairing, MDNS discovery, WOL)
• ui – Android Activities, Views, Adapters, Fragments
• utils, grid, preferences, discovery, computers – support services and models
Key insights from README
• Confirms purpose: “stream your full collection of games from your Windows PC to your Android device.”
• Requires Android NDK for native core.
• Mentions two external servers: NVIDIA GameStream (on PC) and Sunshine.
Main components
a. Frontend/UI Layer (Java/Kotlin)
• Activities & Views (AppView, StreamView, PcView, GridAdapters)
• Preferences & Configuration UI
b. Platform Binding Layer
• Audio: AndroidAudioRenderer → AudioTrack
• Video: MediaCodecDecoderRenderer → SurfaceView/TextureView
• Crypto: AndroidCryptoProvider → JNI/OpenSSL
• Input capture & translation (touch, virtual controllers, external game controllers via USB/Bluetooth)
c. Networking & Protocol Layer (pure Java under nvstream)
• PairingManager & NvHTTP (HTTP pairing & authentication)
• NvConnection & StreamConfiguration (TCP/UDP transport of RTP-like A/V data)
• MDNS discovery agents (JmDNS, Android NSD)
• Wake-on-LAN sender
d. Native Streaming Core (JNI + C/C++)
• moonlight-core library: implements core GameStream protocol, packetization, encryption/decryption using OpenSSL, audio codec via libopus, minimal SDL glue
• JNI bridge (MoonBridge) connecting Java nvstream code to native core
e. External Services
• Windows PC GameStream server or Sunshine server
• Network (local LAN or Internet)
• mDNS / DNS-SD for local discovery
Relationships & interactions
• UI triggers discovery → Platform Binding (DiscoveryService) → MDNS → lists available hosts
• UI initiates pairing → NvHTTP → server → returns credentials → stored via CryptoProvider
• UI starts streaming → NvConnection (Java) calls native moonlight-core (MoonBridge) → sets up RTP/DTLS over UDP
• Incoming video/audio packets arrive in native core → decrypted (OpenSSL) → decoded (libopus for audio, passed back to Java for MediaCodec video)
• Decoded frames → Platform Binding renderers → displayed in UI / AudioTrack output
• UI feeds input events (touch/controller) into InputCaptureManager → ControllerPacket/KeyboardPacket → NvConnection → native core → sends to server
• Settings, preferences, logs handled by Util classes and stored in ContentProvider
Architectural patterns & design principles
• Layered architecture: UI → Platform Binding → Protocol/Service → Native Core
• Separation of concerns:
• Java code handles Android-specific APIs, lifecycle, high-level protocol
• Native C/C++ code focuses purely on streaming protocol, performance-critical code
• Plug-in binding modules: each platform capability (audio, video, crypto, input) implemented behind an interface to allow testing or stubbing (NullCaptureProvider)
• Use of JNI as boundary: minimizes native footprints to one library (moonlight-core)
Detailing
• Resource files (layouts, drawables) and scripts (LuaScripts) as annotations or side-notes if needed, but focus on runtime architecture.