host

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

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

View Source
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

func EncoderArgs(inputs []string, encoder string, fps, kbps, rtpVideo, rtpAudio int) []string

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.

func Encoders

func Encoders() []string

Encoders are the encoder choices on this system, for the emulator's stream.encoder setting.

Types

type Permission

type Permission struct {
	Name    string `json:"name"`
	Granted bool   `json:"granted"`
}

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) Available

func (r *Runtime) Available(context.Context) docker.Status

Available implements docker.Runtime.

func (*Runtime) Create

func (r *Runtime) Create(_ context.Context, s docker.Spec) (string, error)

Create implements docker.Runtime.

func (*Runtime) EnsureNetwork

EnsureNetwork has nothing to make: the system's sandbox is the emulator's network.

func (*Runtime) Input

func (r *Runtime) Input(id string, msg []byte) error

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) Inspect

func (r *Runtime) Inspect(_ context.Context, id string) (docker.Info, error)

Inspect implements docker.Runtime.

func (*Runtime) List

func (r *Runtime) List(_ context.Context, labels map[string]string) ([]docker.Info, error)

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

func (r *Runtime) Logs(_ context.Context, id string, tail int) (string, error)

Logs implements docker.Runtime: the end of the emulator's and the encoder's output.

func (*Runtime) Missing

func (r *Runtime) Missing() []string

Missing says, in words a person can act on, what this machine lacks to run emulators here.

func (*Runtime) Pause

func (r *Runtime) Pause(_ context.Context, id string) error

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) Pull

func (r *Runtime) Pull(context.Context, string) error

Pull has nothing to do: there are no images here.

func (*Runtime) ReleaseInput

func (r *Runtime) ReleaseInput(id string)

ReleaseInput lets go of every key held, when the player goes.

func (*Runtime) Remove

func (r *Runtime) Remove(ctx context.Context, id string) error

Remove implements docker.Runtime.

func (*Runtime) Start

func (r *Runtime) Start(_ context.Context, id string) error

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.

func (*Runtime) Stop

func (r *Runtime) Stop(ctx context.Context, id string, timeout time.Duration) error

Stop implements docker.Runtime.

func (*Runtime) Unpause

func (r *Runtime) Unpause(_ context.Context, id string) error

Unpause implements docker.Runtime.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL