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 ¶
- type Ack
- type Config
- type Controller
- func (c *Controller) Ceiling() int
- func (c *Controller) DeliveredKbps() int
- func (c *Controller) Path() Path
- func (c *Controller) QueueDelay() time.Duration
- func (c *Controller) SetLimits(maxKbps, startKbps int)
- func (c *Controller) SetPath(p Path)
- func (c *Controller) TargetKbps() int
- func (c *Controller) Update(a Ack) Decision
- type Decision
- type Path
- type Usage
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
}
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 Path ¶
type Path uint8
func ClassifyAddr ¶
ClassifyAddr guesses the path from the peer's address. A Tailscale address is assumed direct; telling a DERP relay apart needs the Tailscale LocalAPI.