Documentation
¶
Overview ¶
Package host runs a standalone emulator on this machine's own desktop, boxed in by the system's own sandbox, and streams it the way a container's is: its window and its sound are captured, FFmpeg encodes them to H.264 and Opus and sends RTP to WittyPlay's relay on loopback, and the player's input becomes key presses sent to that one program.
Each system does it its own way (platform_*.go):
- macOS: the emulator runs under sandbox-exec (no network, writing only to its own settings and saves), ScreenCaptureKit captures its window and its sound, and CGEventPostToPid sends it keys. The server needs Screen Recording and Accessibility permission, which only the Mac's owner can give, in System Settings, Privacy & Security.
- Windows: a job object holds it to memory and process limits and ends it with the module, and it runs at low integrity, so it can write only to its own folder. Desktop Duplication (FFmpeg's ddagrab) captures the screen where its window is, WASAPI's loopback the sound, and SendInput sends it keys while its window is in front. It needs a signed-in desktop: a service has none.
- Linux has bubblewrap and a virtual X display of its own (sandbox/local), which is better than this, so this package isn't used there. FreeBSD uses that package too, without bubblewrap.
It's a docker.Runtime, so the lifecycle, limits and session code are the ones containers use. A Spec for it is built with docker.Request.Host set: the paths a container would see (/game, /saves, /bios, /opt/emulator) are turned back into this machine's own here.
Index ¶
- Constants
- func EncoderArgs(inputs []string, encoder string, fps, kbps, rtpVideo, rtpAudio int) []string
- func Encoders() []string
- type Permission
- type Runtime
- func (r *Runtime) Available(context.Context) docker.Status
- func (r *Runtime) Create(_ context.Context, s docker.Spec) (string, error)
- func (r *Runtime) EnsureNetwork(context.Context, docker.NetworkSpec) (docker.NetworkInfo, error)
- func (r *Runtime) Input(id string, msg []byte) error
- func (r *Runtime) Inspect(_ context.Context, id string) (docker.Info, error)
- func (r *Runtime) List(_ context.Context, labels map[string]string) ([]docker.Info, error)
- func (r *Runtime) Logs(_ context.Context, id string, tail int) (string, error)
- func (r *Runtime) Missing() []string
- func (r *Runtime) Pause(_ context.Context, id string) error
- func (r *Runtime) Permissions() []Permission
- func (r *Runtime) Pull(context.Context, string) error
- func (r *Runtime) ReleaseInput(id string)
- func (r *Runtime) Remove(ctx context.Context, id string) error
- func (r *Runtime) Start(_ context.Context, id string) error
- func (r *Runtime) Stop(ctx context.Context, id string, timeout time.Duration) error
- func (r *Runtime) Unpause(_ context.Context, id string) error
Constants ¶
const ( PermScreenRecording = "screen-recording" PermAccessibility = "accessibility" )
Permissions macOS asks for, by the names the log and the server use.
Variables ¶
This section is empty.
Functions ¶
func EncoderArgs ¶
EncoderArgs is FFmpeg's command line for a game on this machine: the same encoding a container's entrypoint uses (docker/images/base/entrypoint.sh), from whatever inputs this system's capture gives. What keeps the delay down: no input buffering, no B-frames, no lookahead, a keyframe a second, a rate buffer a quarter of a second deep, 10 ms Opus frames.
Types ¶
type Permission ¶
Permission is one of them, and whether the server has it.
type Runtime ¶
type Runtime struct {
// Dir is a folder of the module's own, for logs.
Dir string
// FFmpeg says where the encoder is (the one the server gave the module); found on PATH if it
// says nothing.
FFmpeg func() string
Log *slog.Logger
// Look finds a program; exec.LookPath if nil. For tests.
Look func(string) (string, error)
// contains filtered or unexported fields
}
Runtime runs emulators on this machine.
func (*Runtime) EnsureNetwork ¶
func (r *Runtime) EnsureNetwork(context.Context, docker.NetworkSpec) (docker.NetworkInfo, error)
EnsureNetwork has nothing to make: the system's sandbox is the emulator's network.
func (*Runtime) Input ¶
Input passes one message from the player to the emulator: keys, the pointer, or a request for another bitrate. It's how the session's input reaches an emulator here.
func (*Runtime) List ¶
List implements docker.Runtime. Only this module's own emulators are known: one left by a module that stopped went with it (a job object, a process group).
func (*Runtime) Logs ¶
Logs implements docker.Runtime: the end of the emulator's and the encoder's output.
func (*Runtime) Missing ¶
Missing says, in words a person can act on, what this machine lacks to run emulators here.
func (*Runtime) Pause ¶
Pause implements docker.Runtime: the emulator stops where it is, and the encoder keeps sending its last picture.
func (*Runtime) Permissions ¶
func (r *Runtime) Permissions() []Permission
Permissions says which of the system's permissions the server has, where the system asks for any (a Mac). Elsewhere it's empty.
func (*Runtime) ReleaseInput ¶
ReleaseInput lets go of every key held, when the player goes.
func (*Runtime) Start ¶
Start implements docker.Runtime: the emulator, then once its window is up, the capture and the encoder. It returns once the emulator has started; the rest follows in the background, and if it fails the emulator is stopped and its log says why.