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 ¶
- func Path(camera, stream string) string
- type OpusFeed
- type Server
- func (s *Server) Add(path string) *Stream
- func (s *Server) AddOpus(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) Readers(path string) int
- func (s *Server) RequireLogin(user, pass string)
- func (s *Server) SetBattery(battery func(camera string) bool)
- func (s *Server) Start() error
- type Stream
- type TalkSession
- type Talker
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 OpusFeed ¶ added in v0.2.17
type OpusFeed struct {
// contains filtered or unexported fields
}
OpusFeed implements stream.ConnectionSink for an Opus path.
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) AddOpus ¶ added in v0.2.17
AddOpus registers <camera>_opus, or returns it if the camera's other stream already did; each of the camera's streams feeds it through OpusFeed.
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. 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) 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.
func (*Server) RequireLogin ¶ added in v0.2.5
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
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.
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 ¶
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
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) OpusFeed ¶ added in v0.2.17
OpusFeed is the sink one of the camera's streams feeds its Opus path through. Both main and sub may: main's sound is used while it comes, and sub's only while main has sent none for mainSoundFresh, so the path is never fed twice and a camera serving only sub still has one.
func (*Stream) Ready ¶
Ready reports whether the stream has seen the keyframe it needs before it can describe itself.
func (*Stream) SetSpeaker ¶ added in v0.1.9
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.
type TalkSession ¶ added in v0.1.9
TalkSession is one open talk session. Write takes 16 bit mono PCM at rate.