rtsp

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: AGPL-3.0 Imports: 15 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-resynchronising and the more forgiving of the two under a network blip. Both run; see docs/design/2026-09-09-rtsp-output.md.

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. Packetisation 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 packetising 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) 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, called once per camera connection. The clock is resumed (see ts.Clock.Resume), and the SDP is rebuilt if the next keyframe brings different parameter sets.

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

func (s *Stream) Ready() bool

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

Jump to

Keyboard shortcuts

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