Browser part
The main component of the service is the Janus WebRTC server. Out of the box, it provides a simple API for connecting to the server, and supporting the WebRTC protocol. Therefore, the browser part turned out to be as simple as possible, in the form of a wrapper over the Janus API .
Server part
On the server side dosbox , ffmpeg and Janus are used . They are all collected together in a docker container.
The current version of the service uses:
- Latest dosbox version
- Latest version of ffmpeg compiled with vp9 and opus codec support
- The latest version of janus with minor additions (about them below)
Audio and video streaming
When docker starts, the supervisor starts all three programs. Dosbox launches the game and starts generating frames and sounds continuously. This data is redirected to ffmpeg, which creates two RTP streams (sound, video). Janus streaming plugin ( standard component ) listens to these streams and generates WebRTC data for the browser.
{dosbox} --> {ffmpeg} --> {janus streaming plugin} --> {browser}
Keyboard support
WebRTC data feeds are used to support game actions (button clicks). Each time the player clicks the button, the browser's keyboard handler is triggered. It sends text commands through the data channel to the server.
- pipe kdown - when the button is clicked
- pipe kup - when the button is released
On the server, this data is processed by my extension ( source code ). A named pipe is created in which incoming commands are recorded. On the other hand, dosbox constantly reads this pipe and adds keyboard events to the queue for processing. Data channels operate in an ordered mode, the lifetime of one packet is 16 ms. Those. keyboard events will be delivered in the order in which they were pressed.
{browser} --> {janus data text channel} --> {pipe} --> {dosbox}
Infrastructure
The service is launched on the Amazon platform. A new Fargate task is created for each client. After starting, the task receives a public IP, which is sent to the browser. Upon receiving an IP, the browser initiates a WebRTC connection to the Janus server. When dosbox finishes, the Fargate task stops automatically. There is technically no limit to the number of concurrent players.
{browser} --> {+fargate} --> {ip} --> {browser}
...
{browser} --> {stop} --> {-fargate}
Instead of a conclusion
It turned out quite superficially,
It turned out quite superficially, until I understand what to write about in more detail. In general, the architecture proved to be quite working. The service is free, you can try it here .
Review article: DOS Cloud Gaming