Documentation
¶
Overview ¶
Package cgi talks to a Reolink camera's HTTP API.
Baichuan is the better transport and carries everything reostream needs for streaming, but a handful of camera settings have no Baichuan message id we have recovered: the fisheye view modes and the dual lens stitch parameters are both reachable only here for now. The message ids exist, since the official NVR sets both over Baichuan; finding them needs a capture of an NVR talking to a camera, or disassembly of the dispatch code, and neither is done. This package is what makes those features usable meanwhile.
Index ¶
- func AudioAlarmEnabled(doc map[string]any) bool
- type AudioCfg
- type Client
- func (c *Client) Close() error
- func (c *Client) Get(ctx context.Context, cmd string, channel int) (value, initial, rng json.RawMessage, err error)
- func (c *Client) GetAudioAlarm(ctx context.Context, channel int) (map[string]any, error)
- func (c *Client) GetAudioCfg(ctx context.Context, channel int) (AudioCfg, VolumeRange, error)
- func (c *Client) GetEnc(ctx context.Context, channel int) (current Enc, options []EncOptions, err error)
- func (c *Client) GetFishEye(ctx context.Context, channel int) (FishEye, error)
- func (c *Client) GetStitch(ctx context.Context, channel int) (current, factory Stitch, limits StitchLimits, err error)
- func (c *Client) Set(ctx context.Context, cmd string, param any) error
- func (c *Client) SetAudioAlarmEnabled(ctx context.Context, channel int, doc map[string]any, on bool) error
- func (c *Client) SetAudioCfg(ctx context.Context, channel, volume int) error
- func (c *Client) SetEnc(ctx context.Context, channel int, e Enc) error
- func (c *Client) SetFishEye(ctx context.Context, channel int, f FishEye) error
- func (c *Client) SetStitch(ctx context.Context, channel int, s Stitch) error
- type Enc
- type EncOptions
- type EncStream
- type EncStreamOptions
- type FishEye
- type FishEyeMode
- type Stitch
- type StitchLimits
- type VolumeRange
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AudioAlarmEnabled ¶ added in v0.1.4
AudioAlarmEnabled reads the on/off out of that document.
Types ¶
type AudioCfg ¶ added in v0.1.4
type AudioCfg struct {
Volume int `json:"volume"`
}
AudioCfg is the camera's speaker volume.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a logged in session against one camera.
The credentials are kept because a camera will intermittently forget a session it has just issued, and the only way through that is to log in again.
func Dial ¶
Dial logs in and returns a session, with no deadline of its own beyond the 20 second per-call timeout every Client carries. DialContext is the same call with a caller-supplied bound; this is that call with context.Background(), for the many call sites that predate ctx threading through this package and have no deadline of their own to hand down.
The password goes in the request body. Passing it in the query string instead fails with "password wrong", which reads like a credential problem and is not.
func DialContext ¶
DialContext is Dial with a context that bounds the login call itself, so a caller with its own deadline (a fleet apply's per-camera timeout, for one) can have it actually interrupt a hung login rather than only bound the gap between calls.
It tries HTTP first, then HTTPS. Newer firmware ships with HTTP turned off, and HTTPS uses a self-signed certificate, so it is not verified. Only a failure to reach the API falls through to HTTPS; a camera that answers and refuses the login is reported as it is.
func (*Client) Close ¶ added in v0.1.4
Close logs out. Cameras allow only a few CGI sessions and hold abandoned ones for minutes, after which every login fails with "max session". Safe to call on a nil or closed client.
func (*Client) Get ¶
func (c *Client) Get(ctx context.Context, cmd string, channel int) (value, initial, rng json.RawMessage, err error)
Get runs a read command. action 1 asks the camera to return the valid range and the factory default alongside the current value, which is what makes a setting adjustable without guessing at bounds.
ctx bounds this call and, if the session needs a retry, the login that follows it: cancelling ctx aborts whichever of those is in flight, rather than only being honoured between round trips the way a caller-side context.WithTimeout that this method never looked at would be.
func (*Client) GetAudioAlarm ¶ added in v0.1.4
GetAudioAlarm reads the alarm sound document as a map, since the schedule entries differ by model. Callers change a field and write it back whole.
func (*Client) GetAudioCfg ¶ added in v0.1.4
GetAudioCfg reads the speaker volume and the range it may take.
func (*Client) GetEnc ¶ added in v0.1.4
func (c *Client) GetEnc(ctx context.Context, channel int) (current Enc, options []EncOptions, err error)
GetEnc reads the encoder settings and the options the camera accepts.
func (*Client) GetFishEye ¶
GetFishEye reads the fisheye view configuration.
func (*Client) GetStitch ¶
func (c *Client) GetStitch(ctx context.Context, channel int) (current, factory Stitch, limits StitchLimits, err error)
GetStitch reads the stitch settings along with the factory defaults and the valid range, which is everything needed to adjust it without guessing.
func (*Client) SetAudioAlarmEnabled ¶ added in v0.1.4
func (c *Client) SetAudioAlarmEnabled(ctx context.Context, channel int, doc map[string]any, on bool) error
SetAudioAlarmEnabled turns the alarm sound on or off. It writes back the camera's document with only that field changed, keeping the schedule.
func (*Client) SetAudioCfg ¶ added in v0.1.4
SetAudioCfg writes the speaker volume.
func (*Client) SetEnc ¶ added in v0.1.4
SetEnc writes the full encoder block. Streams restart with the new parameters, so readers may need to reconnect.
func (*Client) SetFishEye ¶
SetFishEye changes the view mode.
**This reboots the camera.** That is normal for this setting rather than a fault, and it has consequences worth planning for: the HTTP API returns 502 or nothing for roughly 15 to 20 seconds, the auth token is invalidated so anything afterwards needs a fresh login, and any recorder consuming the camera loses the stream and reconnects. A fixed sleep is the wrong tool for waiting it out; poll until the camera answers.
It also invalidates any motion mask or detection zone drawn against the previous geometry, because those coordinates are normalised to the frame. A fisheye with zones drawn on the circular view will have them pointing at the wrong places after a switch to quad or dual.
type Enc ¶ added in v0.1.4
type Enc struct {
Audio int `json:"audio"`
Main EncStream `json:"mainStream"`
Sub EncStream `json:"subStream"`
Extern EncStream `json:"extStream"`
}
Enc is a channel's encoder settings: one block per stream, plus whether audio is encoded at all.
type EncOptions ¶ added in v0.1.4
type EncOptions struct {
Main EncStreamOptions
Sub EncStreamOptions
}
EncOptions is one resolution the camera supports. The camera returns one per resolution, and bitrate/frame rate options depend on the resolution.
type EncStream ¶ added in v0.1.4
type EncStream struct {
BitRate int `json:"bitRate"`
FrameRate int `json:"frameRate"`
GOP int `json:"gop"`
Width int `json:"width"`
Height int `json:"height"`
Size string `json:"size"`
Profile string `json:"profile"`
VType string `json:"vType"`
}
EncStream is one stream's encoder settings. Size is the camera's string ("4096*1152"); Width and Height must agree with it. GOP is the camera's "interframe space" setting, a small number (1-2), not frames per GOP.
type EncStreamOptions ¶ added in v0.1.4
type EncStreamOptions struct {
Size string
Width int
Height int
BitRates []int
FrameRates []int
GOPMin int
GOPMax int
Profiles []string
VTypes []string
// Default is the camera's default for this size, not the current value.
DefaultBitRate int
DefaultFrameRate int
DefaultGOP int
}
EncStreamOptions is what one stream accepts at a given Size. BitRates, FrameRates, Profiles and VTypes are exact lists; other values are refused.
type FishEye ¶
type FishEye struct {
ImageType FishEyeMode `json:"imageType"`
InstallType int `json:"installType"`
RotationAngle int `json:"rotationAngle"`
}
FishEye is the camera's current view configuration.
type FishEyeMode ¶
type FishEyeMode int
FishEyeMode is what the camera does to the circular image before encoding it. All four produce the same frame size; modes 1 to 3 are dewarped by the camera, so a client cropping regions out of the raw circle and correcting them itself is redoing work the camera will do properly.
const ( FishEyeRaw FishEyeMode = 0 // the circle, uncorrected FishEyePanorama FishEyeMode = 1 // the circle unwrapped into a flat band FishEyeQuad FishEyeMode = 2 // four dewarped sub views in a 2x2 grid FishEyeDual FishEyeMode = 3 // two dewarped halves, stacked )
func (FishEyeMode) String ¶
func (m FishEyeMode) String() string
type Stitch ¶
type Stitch struct {
Distance float64 `json:"distance"`
XMove int `json:"stitchXMove"`
YMove int `json:"stitchYMove"`
}
Stitch is the dual lens alignment on a two lens camera.
The two fields are not two flavours of the same control. Distance is a physical measurement and the moves are offsets, and they correct different errors:
The lenses sit a few centimetres apart, so in the region where their views overlap an object appears in a different place in each image by an amount that depends on how far away it is. Near objects shift a lot, distant ones barely. No single alignment is therefore correct for a whole scene: a seam can only be made to disappear at one depth, and Distance chooses which. Objects much nearer than it duplicate across the seam, objects much further are clipped out of it.
XMove and YMove are a fixed nudge of one image against the other, correcting mechanical tolerance in how the lens modules are mounted. That error is the same whatever the camera is looking at, which is why it is a constant rather than a function of depth.
So: a seam misaligned the same way everywhere is XMove and YMove. A seam that lines up at one depth and splits at another is Distance, and no value fixes every depth at once.
type StitchLimits ¶
type StitchLimits struct {
Distance struct{ Min, Max float64 }
XMove struct{ Min, Max int }
YMove struct{ Min, Max int }
}
StitchLimits is the valid range for each field, as the camera reports it.
type VolumeRange ¶ added in v0.1.4
VolumeRange is the volume range the camera reports.