rtsp

package
v0.2.13 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: AGPL-3.0 Imports: 23 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 rtsp serves camera streams over RTSP.

It exists for compatibility with software that takes an RTSP URL and nothing else. It is not a replacement for the HTTP MPEG-TS output, which is stateless, self-resynchronizing and the more forgiving of the two under a network blip. Both run.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Path

func Path(camera, stream string) string

Path returns the RTSP path for one camera stream.

It mirrors the HTTP endpoints so the two outputs name the same feed the same way: main is the bare camera name, and the other two take the suffix they have on the HTTP side. A camera at http://host:8560/lounge_sub.ts is at rtsp://host:8554/lounge_sub.

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server serves camera streams over RTSP.

Paths mirror the HTTP endpoints, so a camera reachable at http://host:8560/lounge_sub.ts is also at rtsp://host:8554/lounge_sub.

func New

func New(listen string) *Server

New returns a server bound to listen. UDP is offered alongside TCP but is not preferred: a lost RTP packet is a corrupt frame with no retransmit, which is worse than the larger header interleaving over TCP costs. Clients that support both negotiate TCP first.

func (*Server) Add

func (s *Server) Add(path string) *Stream

Add registers a path and returns the stream that feeds it. The returned Stream implements stream.FrameSink. Call before Start.

func (*Server) Addr

func (s *Server) Addr() string

Addr reports the address actually bound, which matters when the configured port was 0.

func (*Server) Close

func (s *Server) Close()

Close stops the server and releases every stream.

func (*Server) OnPlay

OnPlay is where a reader starts counting. Packetization is gated on the count, so a session that has set up but not played still costs nothing.

func (*Server) OnSessionClose

func (s *Server) OnSessionClose(ctx *gortsplib.ServerHandlerOnSessionCloseCtx)

OnSessionClose has to drop the reader whatever ended the session, which includes a client that vanished without TEARDOWN. Leaving the count high would keep packetizing into a void for the life of the process.

func (*Server) OnStreamWriteError added in v0.1.3

func (s *Server) OnStreamWriteError(ctx *gortsplib.ServerHandlerOnStreamWriteErrorCtx)

OnStreamWriteError is called by gortsplib when a session's write queue is full and a packet has been dropped.

Implementing it at all is the point. Without this method gortsplib logs the error itself, one bare line per dropped packet, with no camera and no session on it; a build doing that logged about 2,400 lines a minute on this fleet. A dropped packet is not news on its own, the queue is drop-on-full by design, but a reader falling behind is worth knowing, so this counts them and says so once a minute per session.

func (*Server) Readers added in v0.2.10

func (s *Server) Readers(path string) int

Readers is how many readers are playing path now.

func (*Server) RequireLogin added in v0.2.5

func (s *Server) RequireLogin(user, pass string)

RequireLogin makes every DESCRIBE and SETUP carry this username and password, as RTSP Basic or Digest, whichever the client offers. Call before Start. Without it the server is open, as it always was.

SETUP is checked as well as DESCRIBE because a client may skip DESCRIBE when it already has the description, and SETUP is what attaches a session to a stream, the back channel included. Nothing else needs a check: PLAY needs a session, and only SETUP makes one.

func (*Server) SetBattery added in v0.2.9

func (s *Server) SetBattery(battery func(camera string) bool)

SetBattery tells the server which cameras are battery cameras. Over RTSP one serves only /<camera>, its presence stream, and a 404 for any other of its paths says so instead of telling the reader to list the stream in streams and rtsp, which no longer serves it and used to keep the camera awake around the clock (#38). Call before Start.

func (*Server) Start

func (s *Server) Start() error

Start begins listening.

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Stream is one camera stream served over RTSP. It implements stream.FrameSink.

It cannot describe itself until it has seen a keyframe: Reolink sends parameter sets inline in the elementary stream rather than out of band, and they belong in the SDP. Everything below stays nil until then.

func (*Stream) Connected added in v0.1.4

func (s *Stream) Connected()

Connected implements stream.ConnectionSink. The stream.Run feeding this Stream calls it once per camera connection, before any frame from it.

This session outlives the camera connection, so two things have to be re-examined when a new one starts. The timestamp clock: a rebooted camera counts microseconds from zero again, and a clock that is not told either freezes or jumps (ts.Clock.Resume has the measurements). And the parameter sets: the SDP carries the ones from the first keyframe, and a camera that comes back with different ones would leave every reader decoding against stale values, so the first keyframe of the new connection is compared and the description rebuilt only if they differ.

func (*Stream) Frame

func (s *Stream) Frame(f baichuan.Frame)

Frame is called on the camera goroutine for every decoded frame. It must not block: anything slow here stalls the read loop the media watchdog is watching, and a stalled read loop looks like a failing camera.

func (*Stream) Hold added in v0.2.2

func (s *Stream) Hold(ctx context.Context, enabled func() bool)

Hold keeps the stream showing its last picture while the camera sends no video, for a camera with hold_picture set (enabled reports whether it still is, so a config change takes effect without a restart). The last keyframe is repeated once a second, on the camera's own timeline carried forward, so the clock, and the reconnect rebase in videoFrame, see a stream that simply kept going. Live video takes over again as soon as it returns. It runs until ctx ends; a second call while one runs returns.

func (*Stream) Ready

func (s *Stream) Ready() bool

Ready reports whether the stream has seen the keyframe it needs before it can describe itself.

func (*Stream) SetSpeaker added in v0.1.9

func (s *Stream) SetSpeaker(has bool)

SetSpeaker records whether the camera has a speaker, from its own Support block. internal/stream calls it on each connection before asking for video, so it is known by the time the first keyframe builds the description.

func (*Stream) SetTalker added in v0.1.9

func (s *Stream) SetTalker(t Talker)

SetTalker gives the stream a way to reach its camera's speaker.

type TalkSession added in v0.1.9

type TalkSession interface {
	Write(rate int, pcm []int16) error
	Ping() error
	Close() error
}

TalkSession is one open talk session. Write takes 16 bit mono PCM at rate.

type Talker added in v0.1.9

type Talker interface {
	Open(ctx context.Context) (TalkSession, error)
}

Talker opens a two-way audio session on the camera behind a stream.

Jump to

Keyboard shortcuts

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