← All work

WORK

CloudStation3

PS3 games, in a browser tab.

Solo (MEng capstone) · Nov 2023 – Sep 2024

Why I built it

When I moved to Barcelona for my master’s, I couldn’t bring my PlayStation, and I’m a big PlayStation fan. So I wanted a way to play my games from whatever device I had, with a controller. It also became my MEng capstone, and a test of how much of a cloud gaming service one person could put together from parts: an open-source emulator, a normal GPU and the WebRTC support every browser already has. My own rules were no rewriting the emulator, no paid streaming SDK, and a controller that feels like a controller.

It’s a tech demo, not a service. No games or firmware are included, so bring your own.

How the picture gets to your browser

CloudStation3 streaming pipelineemulatorpatched hookshared mem3.7 MB / frameNVENC H.264GPU encodebrowserWebRTC videouinput padvirtual joystickGamepad APIevdev events
Frames go through shared memory to a hardware encoder, then over WebRTC. Controller input comes back on a DataChannel to a virtual joystick.

I added a small hook to RPCS3, the PS3 emulator, so every finished frame gets copied into shared memory. A 720p frame is about 3.7 MB, and at 25 frames a second I didn’t want to push that through a socket just to move it from one process to the next.

A C++ program on the same machine reads each frame from there, converts it from BGRA to YUV, and encodes it as H.264 on the GPU with NVENC. I turned off B-frames, which make the encoder wait for future frames, kept keyframes close together so a lost packet recovers quickly, and kept the bitrate around 1 Mbps. The video then goes out over WebRTC using libdatachannel, which gives you encryption, congestion control and hardware decoding in the browser for free.

A small Python signalling server introduces each browser to the streamer and then gets out of the way.

How your controller gets back

The browser reads your gamepad through the Gamepad API and sends button and stick changes back over a WebRTC DataChannel. On the Linux side the streamer creates a virtual joystick with uinput, so as far as the emulator knows, someone just plugged in a USB controller. The emulator needed no changes at all for input.

This started as a separate experiment I called joystream, a browser joystick over WebSocket, and later moved into the same WebRTC connection as the video.

What I’d fix

The streamer polls shared memory every 10 ms instead of using a proper signal. I tried a semaphore first and dropped it, so it can very occasionally read a half-written frame. Audio is captured but never streamed. Without a TURN server, some networks can’t connect at all. And I never properly measured the delay from button press to picture, which is the first thing I’d add.

Stack

C++ with FFmpeg (libswscale and h264_nvenc) and libdatachannel for WebRTC. Python asyncio for signalling, Vue 3 and Vuetify for the player, and Linux libevdev and uinput for input. Deployed with Docker and Let’s Encrypt.