Documentation
¶
Overview ¶
Package constraints solves MediaStreamConstraints against what the capture providers can really do.
It follows the SelectSettings algorithm of the Media Capture spec: hard constraints (min, max, exact) remove candidates, "advanced" sets are applied in order when they leave something, and among the survivors the candidate with the smallest fitness distance to the "ideal" values wins. The result is always a mode the device really has, so MediaStreamTrack.getSettings() reports what the camera delivers rather than what was asked.
The package has no dependency on the engine or on any device API; the engine feeds it JSON-decoded constraints.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AudioDevice ¶
type AudioDevice struct {
ID, GroupID string
Rates []int
MinChannels, MaxChannels int
DefaultRate, DefaultChans int
}
AudioDevice is one microphone as the solver sees it.
type AudioResult ¶
type AudioResult struct {
Device int
Rate int
Channels int
// the voice processing of the track (it runs on the WebRTC send path, internal/rtcmedia/audioproc)
EchoCancellation, AutoGainControl, NoiseSuppression bool
}
AudioResult is the winning combination.
func SolveAudio ¶
func SolveAudio(c Constraints, devs []AudioDevice) (AudioResult, error)
SolveAudio picks the microphone. Echo cancellation, noise suppression and gain control are each available on and off; as in Chrome they are on unless the page says otherwise (the candidates with everything on come first).
type Constraints ¶
Constraints is a parsed MediaTrackConstraints.
func Parse ¶
func Parse(v any) (Constraints, error)
Parse reads a JSON-decoded MediaTrackConstraints: true (or nil) means "no constraints", an object is read key by key, unknown keys are ignored like browsers do.
type DisplayResult ¶
DisplayResult is the size and rate a display source should deliver.
func SolveDisplay ¶
func SolveDisplay(c Constraints, w, h int) (DisplayResult, error)
SolveDisplay applies width/height/frameRate to a surface of native size w x h. Dimensions are upper bounds: the surface is scaled down (never up) to fit, keeping its aspect ratio. frameRate defaults to 30 and is capped at 60.
type Num ¶
type Num struct{ Min, Max, Exact, Ideal *float64 }
Num is a ConstrainDouble: a plain number is an ideal.
type Overconstrained ¶
type Overconstrained struct{ Constraint string }
Overconstrained is returned when no device/mode satisfies the hard constraints. Constraint names the property that removed the last candidates.
func (*Overconstrained) Error ¶
func (e *Overconstrained) Error() string
type Set ¶
type Set struct {
Width, Height, FrameRate, AspectRatio Num
FacingMode, ResizeMode Str
DeviceID, GroupID Str
DisplaySurface Str
SampleRate, SampleSize, ChannelCount, Latency Num
EchoCancellation, AutoGainControl Bool
NoiseSuppression Bool
}
Set is one constraint dictionary (the basic set or one "advanced" entry).
type TypeError ¶
type TypeError struct{ Msg string }
TypeError is returned for malformed constraints; the engine turns it into a JS TypeError.
type VideoDevice ¶
type VideoDevice struct {
ID, GroupID string
Facing string // "user", "environment" or "" (a laptop webcam: treated as "user")
Modes []Mode
}
VideoDevice is one camera as the solver sees it. ID and GroupID are the identifiers the page sees (already hashed per origin); the caller maps the result back with Device.
type VideoResult ¶
VideoResult is the winning combination.
func SolveVideo ¶
func SolveVideo(c Constraints, devs []VideoDevice) (VideoResult, error)
SolveVideo picks the device and mode for a video request.