Documentation
¶
Overview ¶
Package phaselock lines the host's frames up with the client display's scan-out. The client's Estimator measures, from the refresh times its pictures reached the screen, how long before the next refresh each picture was ready and whether the system scanned it out directly or composited it first. The host's Controller moves the phase of the frames it captures so that pictures are ready a small target before a refresh: a picture ready just after one waits nearly a whole refresh.
Index ¶
Constants ¶
const (
LockTolerance = int64(500 * time.Microsecond)
)
Variables ¶
This section is empty.
Functions ¶
func Harmonic ¶
Harmonic brings a refresh period measured from screen times to the display's stated one, nominal: a period a whole number of times nominal is that many refreshes, as a 60 fps stream on a 120 Hz display shows every other one. It reports false for a period shorter than nominal, which no display refreshes at. With nominal 0 it keeps period.
Types ¶
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller turns the client's reports into small moves of the host's capture phase. Update and Advance may be called from different goroutines.
func NewController ¶
func NewController(cfg ControllerConfig) *Controller
func (*Controller) Advance ¶
func (c *Controller) Advance(frame uint32) int64
Advance is called once before each frame is captured, with its ID, and returns how much later than its cadence to capture it, earlier when below 0. Frames after it carry the move too.
func (*Controller) State ¶
func (c *Controller) State() State
State reports what the Controller is doing.
type ControllerConfig ¶
type ControllerConfig struct {
// FramePeriod is the stream's frame period.
FramePeriod int64
// Steerable is set when the source paces its own frames and can move
// them. A display capture runs on the display's refresh, which the
// host cannot move: capturing later only moves the wait from the
// client to the host.
Steerable bool
}
ControllerConfig is what the host knows of the stream it steers.
type Estimator ¶
type Estimator struct {
// contains filtered or unexported fields
}
Estimator measures the phase of pictures against the display's refreshes. Safe for concurrent use.
func (*Estimator) Observe ¶
Observe takes a picture that reached the screen and the display's refreshes as known then: a zero Grid where they are not.
func (*Estimator) Report ¶
Report summarizes the last pictures. Each call also moves the margin with the share of late pictures, so call it at a steady rate.
func (*Estimator) Reset ¶
func (e *Estimator) Reset()
Reset forgets every picture measured and the mode, as when the pictures start reaching the screen another way, such as a surface going direct: those of the old path would hold its mode for a whole modeSpan. The nominal period and whether the surface asked for direct scan-out stay.
func (*Estimator) SetDirectSurface ¶
SetDirectSurface tells whether the surface asked the system to scan its pictures out directly (see directSurfaceBelow).
func (*Estimator) SetNominalPeriod ¶
SetNominalPeriod gives the display's shortest refresh period as the system states it. The mode is read against it, and a grid of a shorter period, or of a whole multiple of it, is taken for a harmonic of the refresh.
type Grid ¶
type Grid struct{ Period, Anchor int64 }
Grid is a display's refreshes: Anchor + k*Period, on the client's screen clock.
type Report ¶
type Report struct {
// Valid is set once the refresh is known and enough pictures came.
Valid bool
// Locked is set while the phase error stays within LockTolerance.
Locked bool
Mode Mode
// PeriodNs is the display's refresh period.
PeriodNs int64
// SlackNs is the median time from a picture being ready to the next
// refresh, TargetNs the slack aimed at, and ErrorNs their difference,
// wrapped: above 0 pictures are ready too early and wait, so the host
// should capture later; below 0 they risk missing their refresh.
SlackNs, TargetNs, ErrorNs int64
// JitterNs is half the spread of the slack between its 10th and 90th
// percentiles.
JitterNs int64
// LatePct is the share of pictures that missed the refresh they were
// ready for, CompositedPct the share that took longer from the GPU
// finishing them to the screen than direct scan-out does, in percent.
LatePct, CompositedPct float64
// Oldest and Newest are the frames the slack was measured over.
Oldest, Newest uint32
Samples int
}
Report is the Estimator's view of the last pictures.
type Sample ¶
type Sample struct {
Frame uint32
// Ready is when the decoded picture was ready to present; GPUDone when
// the GPU finished drawing it into the drawable, 0 where the platform
// does not tell; Glass when it reached the screen.
Ready, GPUDone, Glass int64
}
Sample is one picture that reached the screen, on the screen clock.
type State ¶
type State struct {
Active bool
// Reason says why it is not active, or what it waits for.
Reason string
// ErrorNs is the phase error of the last report it acted on.
ErrorNs int64
// MovedNs is how far it moved the capture phase in all, later
// positive; TrimNs the rate trim it adds to every frame.
MovedNs, TrimNs int64
Corrections int
}
State is what the Controller is doing.