Documentation
¶
Overview ¶
Package codec encodes swampcy's screen for the web viewer: AV1 through libaom and H.264 through OpenH264, both loaded at run time with purego, so swampcy needs no cgo and runs (without the viewer) where neither library is installed.
Index ¶
Constants ¶
This section is empty.
Variables ¶
ErrUnavailable means the codec's library could not be loaded.
Functions ¶
func ConvertXRGB ¶
func ConvertXRGB(f *Frame, src []byte, stride, width, height int, rects []image.Rectangle, yInvert bool)
ConvertXRGB converts the given rectangles of an XRGB8888 picture (little-endian, so bytes B, G, R, X: wl_shm's format 1, and ARGB8888's layout too) into f, which has the same size. Rectangles are widened to even coordinates so every 2x2 chroma block they touch is recomputed whole. yInvert reads the source bottom up.
Types ¶
type Config ¶
type Config struct {
Width, Height int
// FPS is the frame rate the rate control plans for. Frames arrive only when
// the screen changes, at most this often, each with its own timestamp.
FPS int
// BitrateKbps caps the stream; the network's estimate moves it at run time.
BitrateKbps int
// Quality is a constant-quality target where the codec has one (AV1's cq-level,
// 0 best to 63 worst). The bitrate cap still applies. 0 means the default (24).
Quality int
// Threads is how many threads the encoder may use; 0 means its default.
Threads int
// H264Profile is "high" (CABAC) or "baseline" (CAVLC, constrained baseline).
// Ignored by AV1.
H264Profile string
}
Config is what an encoder is opened with. Sizes are fixed for its life; the bitrate can change.
type Encoder ¶
type Encoder interface {
// Encode encodes f, as a keyframe when forceKey is set. The encoder does not
// keep f after returning.
Encode(f *Frame, forceKey bool) (Packet, error)
// SetBitrate changes the cap, in kbit/s, from the next frame on.
SetBitrate(kbps int) error
// Name is the codec's name as WebRTC knows it: "AV1" or "H264".
Name() string
Close() error
}
Encoder turns frames into packets, one per frame, with no lookahead.
func NewAV1 ¶
NewAV1 opens libaom's AV1 encoder in realtime mode with its screen-content tools, tuned as swampcy's codec benchmark found best for a desktop: speed 10, palette and intra block copy on, no lookahead, constrained quality at cfg.Quality with cfg.BitrateKbps as the cap, keyframes only on request, BT.709 full-range colour.