cgi

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0 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 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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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

func Dial(host, user, password string) (*Client, error)

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

func DialContext(ctx context.Context, host, user, password string) (*Client, error)

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.

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) GetFishEye

func (c *Client) GetFishEye(ctx context.Context, channel int) (FishEye, error)

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) Set

func (c *Client) Set(ctx context.Context, cmd string, param any) error

Set runs a write command, bounded by ctx the same way Get is.

func (*Client) SetFishEye

func (c *Client) SetFishEye(ctx context.Context, channel int, f FishEye) error

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.

func (*Client) SetStitch

func (c *Client) SetStitch(ctx context.Context, channel int, s Stitch) error

SetStitch writes the stitch settings. Unlike a fisheye mode change this is a numeric adjustment and does not reboot the camera.

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.

Jump to

Keyboard shortcuts

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