stream

package
v0.0.0-...-ac3687d Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package stream serves one game window to a browser over WebRTC (rtc.go): video and an Opus audio track on one connection, and input sent back as JSON (data channel, or POST when it is not open) and replayed through XTEST (xdotool when the display cannot be reached).

Index

Constants

View Source
const (
	EncAuto  = "auto"
	EncVAAPI = "vaapi"
	EncNVENC = "nvenc"
	EncX264  = "x264"
)

H.264 encoders, in order of preference when RTCConfig.Encoder is "auto": the GPU's when it works (VAAPI on Intel / AMD, NVENC on NVIDIA), otherwise libx264 on the CPU.

Variables

This section is empty.

Functions

func ConfigureRTC

func ConfigureRTC(c RTCConfig) error

ConfigureRTC sets the WebRTC network settings; call once before serving.

func ParseEncoder

func ParseEncoder(s string) (string, bool)

ParseEncoder checks an -encoder value.

func ParseICE

func ParseICE(s string) (webrtc.ICEServer, error)

ParseICE turns "stun:host:3478" or "turn:user:pass@host:3478" into an ICE server.

func Snapshot

func Snapshot(ctx context.Context, display string, width int) ([]byte, error)

Snapshot returns one JPEG frame of the game window scaled to at most width pixels wide.

Types

type Game

type Game struct {
	Display string
	Sink    string
	FPS     int
	// contains filtered or unexported fields
}

Game is the stream source.

func (*Game) Handler

func (g *Game) Handler() http.Handler

Handler serves "", "input", "rtc" and "rtc-config" relative to where it is mounted.

func (*Game) Snapshot

func (g *Game) Snapshot(ctx context.Context, width int) ([]byte, error)

Snapshot returns one JPEG frame of this game.

type Input

type Input struct {
	T      string `json:"t"` // "click", "move", "key", "keydown", "keyup" or "text"
	X, Y   int
	B      int    `json:"b"`
	NoMove int    `json:"nomove"`
	K      string `json:"k"`
	S      string `json:"s"` // text for "text"
}

Input is one browser event.

type RTCConfig

type RTCConfig struct {
	ICEServers []webrtc.ICEServer // STUN / TURN for viewers behind NAT
	PublicIPs  []string           // announce these instead of the local addresses (1:1 NAT, port forward)
	Port       int                // single UDP and TCP port for all media (0 = random UDP ports, no TCP)
	Bitrate    int                // video kbit/s ceiling (default 3000); each viewer's connection may lower it (abr.go)
	Encoder    string             // H.264 encoder: auto (GPU when it works) / vaapi / nvenc / x264 (encoder.go)
}

RTCConfig is how peers reach this server. The zero value works on a LAN.

Jump to

Keyboard shortcuts

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