Host Runtime
The CloudGaming host is a high-performance C++ application that captures game video/audio and streams it to clients via WebRTC.Architecture Overview
The host runtime consists of several specialized subsystems:- Video Capture: Windows Graphics Capture (WGC) + D3D11
- Audio Capture: WASAPI with process loopback
- Video Encoding: FFmpeg with hardware acceleration (NVENC/QSV/AMF)
- Audio Encoding: Opus codec
- WebRTC Transport: Go/Pion for peer connection management
- Input Handling: Direct input injection
- Video Pipeline
- Audio Pipeline
- WebRTC Integration
- Input System
Video Capture & Encoding Pipeline
Windows Graphics Capture (WGC)
The host uses Windows Graphics Capture API to capture the game window at the compositor level:- Compositor-level capture (no game modification needed)
- Hardware-accelerated texture sharing
- Support for windowed and fullscreen modes
- Configurable frame pacing via
MinUpdateInterval
D3D11 Video Processing
BGRA textures from WGC are converted to NV12 using D3D11 VideoProcessor for optimal encoder compatibility:- LRU cache for D3D11 views (avoids per-frame allocations)
- Pre-validated format support
- Primed texture views for first-frame performance
Hardware Encoding
The encoder automatically selects the best hardware encoder based on GPU vendor:NVIDIA NVENC Configuration
NVIDIA NVENC Configuration
- VBV buffer = 1x bitrate (minimal buffering)
- B-frames disabled
- Repeat headers enabled for keyframe recovery
- BT.709 color metadata in SPS VUI
Intel QSV Configuration
Intel QSV Configuration
AMD AMF Configuration
AMD AMF Configuration
Frame Ring Buffer
A ring buffer of hardware frames minimizes allocation overhead:Bitrate Adaptation
Adaptive bitrate control responds to network congestion:- Start: 8 Mbps
- Min: 4 Mbps
- Max: 12 Mbps
- Increase step: +1 Mbps
- Decrease cooldown: 1000ms
Key Source Files
Encoder.cpp
Video encoding pipeline with hardware acceleration and adaptive bitrate control.
AudioCapturer.cpp
WASAPI audio capture with Opus encoding and dedicated processing threads.
main.cpp
Main entry point with configuration loading and component initialization.
main.go
Go/Pion WebRTC integration with buffer pool and RTP packet handling.
Performance Tips:
- Use NVENC preset
p5for best latency/quality balance - Set audio frame size to 5ms for ultra-low-latency
- Enable adaptive bitrate control for WAN deployments
- Monitor EAGAIN events to detect encoder congestion