config

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: AGPL-3.0 Imports: 5 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 config loads the TOML file that lists the cameras reostream serves. Unknown keys are a boot-time error rather than a warning: a typo in a camera's fields should fail loudly at startup, not silently drop the field and serve 404s at three in the morning.

Index

Constants

This section is empty.

Variables

View Source
var NotServedOrder = []struct{ Suffix, Stream string }{
	{"", "main"}, {"_sub", "sub"}, {"_extern", "extern"}, {"_zoom", "zoom"}, {"_zoom_sub", "zoom_sub"},
}

NotServedOrder is the order a "not served" reply lists a camera's streams in, main first, and Suffix is how each one's path ends.

Functions

func HowToServe added in v0.2.8

func HowToServe(stream string) string

HowToServe says how to turn a camera's stream on, for a reader that asked for one reostream does not serve. The RTSP log line used to stop at what was served, and a TrackMix owner whose camera had no zoom streams set up was left to find the config key on his own (YseanY, 11-02). The HTTP .ts 404 says the same since 11-04. It lives here, beside the keys it names, so both servers say it the same way.

func NormalizeAddr

func NormalizeAddr(addr string) string

NormalizeAddr applies the same default-port rule baichuan.Dial does, so "192.0.2.50" and "192.0.2.50:9000" compare equal as the same camera.

Exported so a caller outside this package that also needs to recognize "is this the same camera as one already configured" -- the setup page's probe guard is the current one -- compares addresses the same way Validate does below, rather than keeping a second implementation that can quietly drift from this one.

func ServedList added in v0.2.8

func ServedList(paths []ServedPath) string

ServedList is the "this camera serves" list of a "not served" reply. The two servers used to disagree: the HTTP .ts 404 listed every stream turned on, the RTSP one only those that had sent a keyframe, so with cam-19's main slots held elsewhere the RTSP 404 named only /cam-19_sub and the HTTP one named /cam-19.ts too, which then sent nothing (11-04). Both now list what the camera is set up to serve and say which has no video yet, so a reader is not sent to turn on a stream that is already on.

Types

type Camera

type Camera struct {
	Name     string
	Address  string
	Username string
	Password string
	Streams  []string

	// Channel picks one camera behind a device that serves several, a
	// Reolink Home Hub or NVR, where Address is the hub's and each paired
	// camera is a numbered channel from 0. A camera on its own is always
	// channel 0, which is also what leaving it out means.
	Channel int

	// UID marks a battery camera, reached over UDP by this id instead of
	// TCP port 9000.
	UID string

	// RTSP names which of this camera's streams to serve over RTSP. Absent
	// means none, and every stream still reaches the HTTP output either way.
	RTSP []string

	// HoldPicture keeps this camera's RTSP streams showing the last picture
	// while the camera sends no video (privacy mode, a dropout), instead of
	// going silent, so a recorder's ffmpeg is not restarted over and over
	// (#13). Off by default: a frozen picture also hides a real outage.
	HoldPicture bool `toml:"hold_picture"`

	// MotionTopic is an MQTT topic, on the [events] broker, where another
	// tool reports this camera's motion as ON / OFF: reoevent, which hears
	// a battery camera's own motion reports on the router. reostream
	// relays it like the camera's own alerts and, for a battery camera,
	// wakes it for the motion so its presence stream carries it live.
	MotionTopic string `toml:"motion_topic"`

	// AlwaysOn keeps a battery camera (one with a UID) streaming around the
	// clock, like a wired camera, instead of sleeping between viewers and
	// motion. Only for a battery camera on constant power: on its battery
	// it drains in days. Off by default.
	AlwaysOn bool `toml:"always_on"`

	// Rotate turns this camera's picture: 90, 180 or 270 degrees
	// anticlockwise, in reostream's own player and written into the H.265
	// stream as a display orientation note rather than re-encoded, which
	// ffmpeg (and so Frigate's detect) honors. Unset, the camera's own word
	// turns it in reostream's player only: the 16 MP dual-lens boards
	// encode their full resolution sideways and say so at login
	// (needRotate). Set it to 0 to leave a camera's picture alone whatever
	// it says.
	Rotate *int `toml:"rotate"`

	// TalkGainDB turns talk (the page's hold-to-talk and the RTSP back
	// channel) up or down before it reaches the camera's speaker: -12 to
	// +12 dB in steps of 3, 0 by default. A limiter holds peaks at -1 dBFS
	// whatever it is set to. A tester found full scale overdrove an E1
	// Zoom's speaker and -12 dB was clear and plenty loud.
	TalkGainDB int `toml:"talk_gain_db"`
}

Camera names one Reolink camera and the streams to pull from it.

type ClockConfig added in v0.2.0

type ClockConfig struct {
	// DailySync is the time of day, "HH:MM" on this machine's clock, at
	// which every wired camera's clock is set from this machine's. Empty
	// is off.
	DailySync string `toml:"daily_sync"`
}

ClockConfig keeps the cameras' clocks right.

type Config

type Config struct {
	Listen  string
	RTSP    *RTSPConfig    `toml:"rtsp"`
	Control *ControlConfig `toml:"control"`
	FTP     *FTPConfig     `toml:"ftp"`
	Events  *EventsConfig  `toml:"events"`
	Clock   *ClockConfig   `toml:"clock"`
	Cameras []Camera       `toml:"camera"`
}

Config is the top level shape of the TOML file.

func Load

func Load(path string) (*Config, error)

Load reads and validates the config file at path. A camera address, username or password, the control password, or the [rtsp] username or password, that starts with "$" is resolved from the named environment variable rather than stored in the file; an unset variable is an error rather than an empty password, because a camera that silently never authenticates is much harder to notice than a process that refuses to start.

This resolves [control]'s password too, which is right for the one process that both dials cameras and listens on the control port.

func LoadRaw

func LoadRaw(path string) (*Config, error)

LoadRaw decodes the TOML file at path with the same unknown-key rejection Load applies, but performs no environment resolution: a camera's Password field comes back exactly as written, including an unresolved "$NAME" reference, and no environment variable needs to be set for this to succeed.

This exists for callers that read a config only to write it back, such as the control page's camera form. Editing the file's text should not require the file's secrets to pass through the process first, and resolving them here would mean writing a real password back to disk in place of the "$NAME" reference that was deliberately keeping it out of the file.

Never use the Config this returns to actually connect to a camera; its passwords may not be passwords at all.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the constraints Load cannot express through decoding alone: names and addresses present, streams recognized, and no two cameras or streams that would fight over the same connection. A camera permits exactly one connection per stream, so a duplicate here is not a harmless redundancy, it is two runners that will fight for one session and the loser blocks the winner until the camera times the session out.

type ControlConfig

type ControlConfig struct {
	Listen   string
	Password string

	// AllowNoPassword runs the page with no authentication at all. It is a
	// separate opt-in rather than the meaning of an empty password because
	// an empty password is much more often a mistake, and this page can
	// read and write camera credentials.
	AllowNoPassword bool `toml:"allow_no_password"`

	// BasePath serves the page under a path prefix, such as "/reostream",
	// for a reverse proxy that puts it there. Empty is the root.
	BasePath string `toml:"base_path"`
}

ControlConfig configures the operator page's listener. Its absence turns the page off entirely, which is the default: a daemon that serves video should not start serving a credential store because it was upgraded.

type EventsConfig added in v0.2.0

type EventsConfig struct {
	// MQTT is the broker, host:port; MQTTUser and MQTTPassword its login.
	MQTT         string `toml:"mqtt"`
	MQTTUser     string `toml:"mqtt_user"`
	MQTTPassword string `toml:"mqtt_password"`
	// Prefix starts every topic; "reostream" when empty.
	Prefix string
	// Frigate is Frigate's API, e.g. "http://192.0.2.5:5000": an object the
	// camera sees becomes a Frigate event on the camera of the same name.
	Frigate string
	// FrigateMotion also sends plain motion to Frigate, which finds motion
	// itself, so it is off unless asked for.
	FrigateMotion bool `toml:"frigate_motion"`
	// HADiscovery announces each camera to Home Assistant over MQTT
	// discovery, so it appears there as a device with its sensors. It
	// needs MQTT set.
	HADiscovery bool `toml:"ha_discovery"`
}

EventsConfig relays each camera's own detections (motion, person, vehicle, animal) as they happen. Either destination may be left empty.

type FTPConfig added in v0.2.0

type FTPConfig struct {
	// Listen is the control port, ":2121" when empty.
	Listen string
	// Passive is the data port range, "2122-2131" when empty.
	Passive string
	// Host is the address cameras are told to send data to; set it when
	// reostream runs behind NAT (Docker's bridge network).
	Host string
	// Dir holds the clips, one folder per camera; "clips" next to the
	// config file when empty.
	Dir string
	// Password is what every camera logs in with.
	Password string
	// KeepDays deletes clips older than this; 0 keeps them forever.
	KeepDays int `toml:"keep_days"`
}

FTPConfig is the clip receiver: cameras upload each recording here over FTP, logging in with their own camera name and this password. Absent, no receiver runs.

type RTSPConfig

type RTSPConfig struct {
	Listen string

	// Username and Password, when set, are required of every reader of
	// the video outputs: RTSP (Basic or Digest) and the HTTP streaming
	// port (Basic). Unset is open, which is what every setup before them
	// was, so an upgrade does not lock a recorder out. They live here
	// rather than in a section of their own because a recorder holds one
	// login for reostream, whichever output it reads. Either may be
	// "$NAME", read from the environment like a camera's password.
	Username string
	Password string
}

RTSPConfig configures the RTSP listener. Its absence turns RTSP off entirely, which is the default: HTTP MPEG-TS is what this daemon has always served, and RTSP is opt-in for consumers that cannot take it.

func (*RTSPConfig) Credentials added in v0.2.5

func (r *RTSPConfig) Credentials() (user, pass string, ok bool)

Credentials reports whether the video outputs require a login, and which.

type ServedPath added in v0.2.8

type ServedPath struct {
	Path  string
	Video bool
}

ServedPath is one path a camera is set up to serve, and whether video has come for it yet.

Jump to

Keyboard shortcuts

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