Documentation
¶
Overview ¶
Package inputagent carries a player's input into a standalone emulator's container. WittyPlay sends the same pad, pointer and touch messages a game runner gets (package ipc) over TCP to a small agent inside the container, which turns them into key and mouse events on the container's X display with xdotool.
Why keys and xdotool, not uinput: a virtual pad through /dev/uinput needs that device in the container, which the hardening refuses, and a program that reads raw pads would see the host's too. Every desktop emulator takes the keyboard, and its own settings map keys to the console's buttons. Each of four players has keys of their own (KeyMap), which an administrator can change; an image sets the emulator's settings to match. Analogue sticks become their directions' keys past a threshold, which is enough for menus and most games and is the known limit of this agent. There's no way back for rumble: a keyboard has none.
The protocol: the client sends the session's secret and a newline, then frames of one length byte and that many bytes. The agent closes a connection whose first line is wrong, and takes one connection at a time.
Index ¶
- Constants
- Variables
- func BitrateMessage(kbps int) []byte
- func Bridge(ctx context.Context, path, secret string, videoPort, audioPort int, ...) error
- func Serve(ctx context.Context, l net.Listener, secret string, sink Sink) error
- func ServeWith(ctx context.Context, l net.Listener, secret string, agent func() *Agent) error
- type Agent
- type Forwarder
- type Host
- type KeyMap
- type Sink
- type XDoTool
Constants ¶
const ( KindVideo = 'v' KindAudio = 'a' )
Kinds of packet the agent sends up.
const ( ControlMark = 0xB7 ControlSize = 3 )
ControlMark begins a message that isn't input: ControlMark, then a bitrate in kbit/s as two bytes, low first. Its length is no pad, pointer or touch message's.
const MaxFrame = 1 + 1 + ipc.MaxTouches*ipc.TouchSize
MaxFrame is the largest message: a touch message with every finger.
const MaxPlayers = 4
MaxPlayers is how many pads the agent gives keys to.
Variables ¶
var Buttons = []string{"b", "y", "select", "start", "up", "down", "left", "right", "a", "x", "l", "r", "l2", "r2", "l3", "r3",
"lup", "ldown", "lleft", "lright", "rup", "rdown", "rleft", "rright"}
Buttons names a pad's buttons by their bit in a pad message (libretro's joypad order), and then the two sticks' directions, which become keys past stickThreshold. These names are the keys of a KeyMap.
Functions ¶
func BitrateMessage ¶
BitrateMessage asks the agent to have the picture encoded at kbps from now on.
func Bridge ¶
Bridge is the agent's end: it connects to the socket at path, sends up what arrives on the two UDP ports of its own loopback, and applies the input that comes down. It returns when the connection ends or ctx does.
Types ¶
type Agent ¶
type Agent struct {
Sink Sink
// Keys is the key map; DefaultKeys if it was never set.
Keys *KeyMap
// Bitrate, if set, hears a request to change the encoder's bitrate.
Bitrate func(kbps int)
// contains filtered or unexported fields
}
Agent turns messages into Sink calls, remembering what's held so it only sends changes.
type Forwarder ¶
type Forwarder struct {
Addr string // host:port
Secret string
Dial func(ctx context.Context, network, addr string) (net.Conn, error)
// contains filtered or unexported fields
}
Forwarder sends input to one container's agent, connecting when it first has something to send and again after a failure. Send never blocks the caller for long: input that can't be sent is dropped, as a game drops a late frame.
type Host ¶
type Host struct {
Secret string
// OnPacket hears each RTP packet. The slice is only good until it returns.
OnPacket func(kind byte, pkt []byte)
// contains filtered or unexported fields
}
Host is WittyPlay's end of the bridge.
type KeyMap ¶
type KeyMap [MaxPlayers]map[string]string
KeyMap says which X key each button of each player presses. An administrator can change it (the "keys.p1" to "keys.p4" settings) to match the keys an emulator already knows.
func DefaultKeys ¶
func DefaultKeys() KeyMap
DefaultKeys is the map used when nothing else is set. An emulator's own settings have to map these keys to its pads; an image ships settings that do. Player 4's use the function keys, which some emulators keep for themselves, so those are the first to change.
type Sink ¶
type Sink interface {
Key(name string, down bool) error
Pointer(x, y float64, pressed bool) error // 0..1 across the display
}
Sink is what the agent does with input. XDoTool is the real one.