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 ¶
- func Path(camera, stream string) string
- type Server
- func (s *Server) Add(path string) *Stream
- func (s *Server) Addr() string
- func (s *Server) Close()
- func (s *Server) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error)
- func (s *Server) OnPlay(ctx *gortsplib.ServerHandlerOnPlayCtx) (*base.Response, error)
- func (s *Server) OnSessionClose(ctx *gortsplib.ServerHandlerOnSessionCloseCtx)
- func (s *Server) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error)
- func (s *Server) OnStreamWriteError(ctx *gortsplib.ServerHandlerOnStreamWriteErrorCtx)
- func (s *Server) Start() error
- type Stream
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Path ¶
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 ¶
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 ¶
Add registers a path and returns the stream that feeds it. The returned Stream implements stream.FrameSink. Call before Start.
func (*Server) Addr ¶
Addr reports the address actually bound, which matters when the configured port was 0.
func (*Server) OnDescribe ¶
func (s *Server) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error)
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) OnSetup ¶
func (s *Server) OnSetup(ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, *gortsplib.ServerStream, error)
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.
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.