ratectl

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ratectl picks the video bitrate from receiver feedback, in the style of Google Congestion Control: a delay-gradient trendline detects queue build-up early, loss caps the rate when the path drops packets, and a per-path ceiling bounds both.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ack

type Ack struct {
	// Now is the sender's monotonic clock when the feedback was processed.
	Now int64
	// SendTS is the sender's clock when the frame's last packet left, and
	// ArrivalTS the receiver's clock when the frame completed. Only
	// differences between frames are used, so the clocks need not agree.
	// ArrivalTS 0 means the ack carries no delay sample.
	SendTS    int64
	ArrivalTS int64
	Bytes     int
	// RTT is the current round-trip estimate; 0 if unknown.
	RTT time.Duration
	// Loss is the pre-FEC packet loss fraction in this report; negative
	// if the report has none. Reports are averaged before use.
	Loss float64
	// FrameLost reports a frame that FEC could not rebuild.
	FrameLost bool
}

Ack is the feedback for one video frame, in the sender's terms.

type Config

type Config struct {
	MinKbps   int
	MaxKbps   int
	StartKbps int
	// TailscaleDirectKbps and TailscaleRelayKbps cap the rate on those
	// paths. Spike 3 saw Tailscale direct hold 50 to 100 Mbps with extra
	// tail latency; DERP relays are far slower.
	TailscaleDirectKbps int
	TailscaleRelayKbps  int
	// MinKeyframeInterval spaces keyframe recommendations; the effective
	// spacing is at least two RTTs.
	MinKeyframeInterval time.Duration
}

func DefaultConfig

func DefaultConfig() Config

DefaultConfig suits 1080p to 1440p game streaming.

type Controller

type Controller struct {
	// contains filtered or unexported fields
}

Controller is the sender-side bitrate controller. Not safe for concurrent use.

func New

func New(cfg Config) *Controller

func (*Controller) Ceiling

func (c *Controller) Ceiling() int

Ceiling is the highest rate allowed on the current path.

func (*Controller) DeliveredKbps

func (c *Controller) DeliveredKbps() int

DeliveredKbps is the receive rate over the last half second of acks, or 0 before there is enough history.

func (*Controller) Path

func (c *Controller) Path() Path

func (*Controller) QueueDelay

func (c *Controller) QueueDelay() time.Duration

QueueDelay is the current standing-queue estimate.

func (*Controller) SetLimits

func (c *Controller) SetLimits(maxKbps, startKbps int)

SetLimits takes a new stream's cap and, when start is positive, starts it there; otherwise the target only moves under the new cap.

func (*Controller) SetPath

func (c *Controller) SetPath(p Path)

SetPath changes the path and applies its ceiling at once.

func (*Controller) TargetKbps

func (c *Controller) TargetKbps() int

func (*Controller) Update

func (c *Controller) Update(a Ack) Decision

Update folds one ack into the estimate and returns the new decision.

type Decision

type Decision struct {
	TargetKbps int
	// RequestKeyframe recommends a keyframe (or reference invalidation)
	// because a frame was lost.
	RequestKeyframe bool
	Usage           Usage
}

type Path

type Path uint8
const (
	PathUnknown Path = iota
	PathLAN
	PathTailscaleDirect
	PathTailscaleRelay
)

func ClassifyAddr

func ClassifyAddr(a netip.Addr) Path

ClassifyAddr guesses the path from the peer's address. A Tailscale address is assumed direct; telling a DERP relay apart needs the Tailscale LocalAPI.

func (Path) String

func (p Path) String() string

type Usage

type Usage uint8
const (
	UsageNormal Usage = iota
	UsageOver
	UsageUnder
)

Jump to

Keyboard shortcuts

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