Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Shyamalp16/CloudGaming/llms.txt
Use this file to discover all available pages before exploring further.
System Architecture
CloudGaming uses a hybrid architecture: centralized signaling with decentralized peer-to-peer streaming. This design minimizes server costs while maintaining ultra-low latency.Architecture Overview
Core Components
Host Runtime
The host is a hybrid C++/Go application running on Windows that captures, encodes, and streams the desktop.C++ Layer (Host/)
C++ Layer (Host/)
Responsibilities:
- Windows Graphics Capture (WGC) for screen capture
- D3D11 texture management and GPU memory copy
- FFmpeg integration for H.264 encoding (NVENC/QSV/AMF)
- WASAPI audio capture with Opus encoding
- Input injection via SendInput API
- Configuration management and matchmaker client
Host/main.cpp- Application entry pointHost/GraphicsAndCapture.cpp- WGC capture setupHost/Encoder.cpp- FFmpeg encoding pipelineHost/AudioCapturer.cpp- WASAPI + Opus audioHost/KeyInputHandler.cpp- Keyboard input injectionHost/MouseInputHandler.cpp- Mouse input injection
Go Layer (gortc_main/main.go)
Go Layer (gortc_main/main.go)
Responsibilities:
- WebRTC peer connection via Pion library
- RTP packet handling and SRTP encryption
- DataChannel management for input
- RTCP feedback (TWCC, PLI, NACK)
- Network quality monitoring
Capture Pipeline
Capture Pipeline
- WGC Capture (
Windows.Graphics.CaptureAPI)- Captures target window/process at configured FPS
- Outputs D3D11 textures in GPU memory
- D3D11 Copy Pool (8 textures)
- Asynchronous GPU-to-GPU copy to avoid stalls
- Ring buffer prevents encoder blocking capture
- FFmpeg Encoding
- Hardware-accelerated H.264 (NVENC preferred)
- CBR rate control for consistent bitrate
- B-frames disabled (bf=0) for minimum latency
- Frame Pacing
MinUpdateIntervalenforces frame timing- Adaptive backoff when encoder saturated
Audio Pipeline
Audio Pipeline
- WASAPI Loopback Capture
- Process-specific audio (Windows 11)
- 48kHz stereo, 10ms frames
- Opus Encoding
- 80kbps bitrate, complexity 6
- Forward Error Correction (FEC) enabled
- 10ms frame size for low latency
- RTP Transmission
- Sent via WebRTC audio track
- Synchronized with video via NTP timestamps
Signaling Server
Node.js WebSocket server that coordinates WebRTC connection setup. File:Server/ScalableSignalingServer.js
The signaling server uses Redis pub/sub to enable horizontal scaling. Multiple signaling instances can run simultaneously, with messages routed via Redis channels.
- WebSocket server on port 3002
- Room-based peer routing
- Rate limiting (100 msg/min per connection)
- Schema validation with circuit breaker
- Health checks and Prometheus metrics
- Atomic join/leave operations via Lua scripts
Matchmaker
Express.js API that tracks host availability and assigns clients. File:Server/mm_server/Matchmaker.js
| Endpoint | Method | Description |
|---|---|---|
/api/host/heartbeat | POST | Host registration/keepalive (20s interval) |
/api/host/status | POST | Update host status (idle/busy) |
/api/match/find | POST | Find available host for client |
Hosts send heartbeats every 20 seconds. If a host crashes, the Redis key expires after 30 seconds and it’s automatically removed from the pool.
Web Client
Pure HTML/JavaScript client using native WebRTC APIs. File:Client/html-server/index.html
- Canvas-based video rendering
- Web Audio API for low-latency playback
- Keyboard/mouse event capture
- Pointer lock for FPS games
- Immersive fullscreen mode (F11)
WebRTC P2P Connection
Connection Establishment
ICE Candidate Exchange
Both peers discover their network addresses (local, STUN reflexive, TURN relay) and exchange them via the signaling server.
Network Quality Monitoring
The Go layer monitors WebRTC statistics and reports to C++:Data Flow Summary
Downstream (Host → Client)
Upstream (Client → Host)
Scaling Considerations
Horizontal Scaling
Multiple signaling server instances share load via Redis pub/sub. Add more instances behind a load balancer.
Geographic Distribution
Deploy signaling servers and matchmakers in multiple regions. Route clients to nearest region.
Host Pooling
Matchmaker tracks hosts across regions. Scale by adding more gaming PCs to the pool.
TURN Fallback
Use Metered.ca or Coturn for TURN relay when P2P fails. Costs scale with relayed bandwidth.
Performance Characteristics
| Metric | Value | Notes |
|---|---|---|
| Glass-to-glass latency | 30-50ms | P2P on LAN/good internet |
| Encoding latency | 8-15ms | With NVENC p2 preset |
| Network latency | 10-30ms | Depends on peer distance |
| Video bitrate | 8-80 Mbps | Adaptive based on network |
| Audio bitrate | 80 kbps | Opus with FEC |
| CPU usage (host) | 5-15% | With GPU encoding |
| GPU usage (host) | 15-30% | Includes game rendering |
Next Steps
Configuration Reference
Detailed config.json documentation
API Reference
Matchmaker and signaling API specs