diff --git a/internal/converterhls/converter.go b/internal/hlsconverter/converter.go similarity index 99% rename from internal/converterhls/converter.go rename to internal/hlsconverter/converter.go index 8c60fab9..deed3651 100644 --- a/internal/converterhls/converter.go +++ b/internal/hlsconverter/converter.go @@ -1,4 +1,4 @@ -package converterhls +package hlsconverter import ( "bytes" @@ -119,7 +119,7 @@ type PathMan interface { OnReadPublisherSetupPlay(readpublisher.SetupPlayReq) } -// Parent is implemented by serverhls.Server. +// Parent is implemented by hlsserver.Server. type Parent interface { Log(logger.Level, string, ...interface{}) OnConverterClose(*Converter) @@ -594,7 +594,7 @@ func (c *Converter) runRequestHandler(terminate chan struct{}, done chan struct{ } } -// OnRequest is called by serverhls.Server. +// OnRequest is called by hlsserver.Server. func (c *Converter) OnRequest(req Request) { c.request <- req } diff --git a/internal/converterhls/multiaccessbuffer.go b/internal/hlsconverter/multiaccessbuffer.go similarity index 98% rename from internal/converterhls/multiaccessbuffer.go rename to internal/hlsconverter/multiaccessbuffer.go index 18d2be01..5fd92116 100644 --- a/internal/converterhls/multiaccessbuffer.go +++ b/internal/hlsconverter/multiaccessbuffer.go @@ -1,4 +1,4 @@ -package converterhls +package hlsconverter import ( "bytes" diff --git a/internal/converterhls/multiaccessbuffer_test.go b/internal/hlsconverter/multiaccessbuffer_test.go similarity index 97% rename from internal/converterhls/multiaccessbuffer_test.go rename to internal/hlsconverter/multiaccessbuffer_test.go index 67b29c50..4b460d05 100644 --- a/internal/converterhls/multiaccessbuffer_test.go +++ b/internal/hlsconverter/multiaccessbuffer_test.go @@ -1,4 +1,4 @@ -package converterhls +package hlsconverter import ( "io" diff --git a/internal/converterhls/tsfile.go b/internal/hlsconverter/tsfile.go similarity index 99% rename from internal/converterhls/tsfile.go rename to internal/hlsconverter/tsfile.go index 930f770f..4b636abb 100644 --- a/internal/converterhls/tsfile.go +++ b/internal/hlsconverter/tsfile.go @@ -1,4 +1,4 @@ -package converterhls +package hlsconverter import ( "context" diff --git a/internal/serverhls/server.go b/internal/hlsserver/server.go similarity index 85% rename from internal/serverhls/server.go rename to internal/hlsserver/server.go index 75ab3511..deabb760 100644 --- a/internal/serverhls/server.go +++ b/internal/hlsserver/server.go @@ -1,4 +1,4 @@ -package serverhls +package hlsserver import ( "context" @@ -9,7 +9,7 @@ import ( "sync" "time" - "github.com/aler9/rtsp-simple-server/internal/converterhls" + "github.com/aler9/rtsp-simple-server/internal/hlsconverter" "github.com/aler9/rtsp-simple-server/internal/logger" "github.com/aler9/rtsp-simple-server/internal/pathman" "github.com/aler9/rtsp-simple-server/internal/stats" @@ -31,11 +31,11 @@ type Server struct { ln net.Listener wg sync.WaitGroup - converters map[string]*converterhls.Converter + converters map[string]*hlsconverter.Converter // in - request chan converterhls.Request - connClose chan *converterhls.Converter + request chan hlsconverter.Request + connClose chan *hlsconverter.Converter terminate chan struct{} // out @@ -66,9 +66,9 @@ func New( pathMan: pathMan, parent: parent, ln: ln, - converters: make(map[string]*converterhls.Converter), - request: make(chan converterhls.Request), - connClose: make(chan *converterhls.Converter), + converters: make(map[string]*hlsconverter.Converter), + request: make(chan hlsconverter.Request), + connClose: make(chan *hlsconverter.Converter), terminate: make(chan struct{}), done: make(chan struct{}), } @@ -103,7 +103,7 @@ outer: case req := <-s.request: c, ok := s.converters[req.Path] if !ok { - c = converterhls.New( + c = hlsconverter.New( s.hlsSegmentCount, s.hlsSegmentDuration, s.readBufferCount, @@ -174,7 +174,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } cres := make(chan io.Reader) - s.request <- converterhls.Request{ + s.request <- hlsconverter.Request{ Path: parts[0], Subpath: parts[1], Req: r, @@ -201,12 +201,12 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } -func (s *Server) doConverterClose(c *converterhls.Converter) { +func (s *Server) doConverterClose(c *hlsconverter.Converter) { delete(s.converters, c.PathName()) c.ParentClose() } -// OnConverterClose is called by converterhls.Converter. -func (s *Server) OnConverterClose(c *converterhls.Converter) { +// OnConverterClose is called by hlsconverter.Converter. +func (s *Server) OnConverterClose(c *hlsconverter.Converter) { s.connClose <- c } diff --git a/internal/path/path.go b/internal/path/path.go index 46e8f67b..1fe5d3d6 100644 --- a/internal/path/path.go +++ b/internal/path/path.go @@ -16,8 +16,8 @@ import ( "github.com/aler9/rtsp-simple-server/internal/logger" "github.com/aler9/rtsp-simple-server/internal/readpublisher" "github.com/aler9/rtsp-simple-server/internal/source" - "github.com/aler9/rtsp-simple-server/internal/sourcertmp" - "github.com/aler9/rtsp-simple-server/internal/sourcertsp" + "github.com/aler9/rtsp-simple-server/internal/rtmpsource" + "github.com/aler9/rtsp-simple-server/internal/rtspsource" "github.com/aler9/rtsp-simple-server/internal/stats" "github.com/aler9/rtsp-simple-server/internal/streamproc" ) @@ -403,7 +403,7 @@ func (pa *Path) hasExternalSource() bool { func (pa *Path) startExternalSource() { if strings.HasPrefix(pa.conf.Source, "rtsp://") || strings.HasPrefix(pa.conf.Source, "rtsps://") { - pa.source = sourcertsp.New( + pa.source = rtspsource.New( pa.conf.Source, pa.conf.SourceProtocolParsed, pa.conf.SourceFingerprint, @@ -416,7 +416,7 @@ func (pa *Path) startExternalSource() { pa) } else if strings.HasPrefix(pa.conf.Source, "rtmp://") { - pa.source = sourcertmp.New( + pa.source = rtmpsource.New( pa.conf.Source, pa.readTimeout, pa.writeTimeout, diff --git a/internal/connrtmp/conn.go b/internal/rtmpconn/conn.go similarity index 99% rename from internal/connrtmp/conn.go rename to internal/rtmpconn/conn.go index 11970111..3f5785cf 100644 --- a/internal/connrtmp/conn.go +++ b/internal/rtmpconn/conn.go @@ -1,4 +1,4 @@ -package connrtmp +package rtmpconn import ( "context" @@ -54,7 +54,7 @@ type PathMan interface { OnReadPublisherAnnounce(readpublisher.AnnounceReq) } -// Parent is implemented by serverrtmp.Server. +// Parent is implemented by rtmpserver.Server. type Parent interface { Log(logger.Level, string, ...interface{}) OnConnClose(*Conn) diff --git a/internal/serverrtmp/server.go b/internal/rtmpserver/server.go similarity index 88% rename from internal/serverrtmp/server.go rename to internal/rtmpserver/server.go index 227fdc24..51f04068 100644 --- a/internal/serverrtmp/server.go +++ b/internal/rtmpserver/server.go @@ -1,11 +1,11 @@ -package serverrtmp +package rtmpserver import ( "net" "sync" "time" - "github.com/aler9/rtsp-simple-server/internal/connrtmp" + "github.com/aler9/rtsp-simple-server/internal/rtmpconn" "github.com/aler9/rtsp-simple-server/internal/logger" "github.com/aler9/rtsp-simple-server/internal/pathman" "github.com/aler9/rtsp-simple-server/internal/stats" @@ -30,10 +30,10 @@ type Server struct { l net.Listener wg sync.WaitGroup - conns map[*connrtmp.Conn]struct{} + conns map[*rtmpconn.Conn]struct{} // in - connClose chan *connrtmp.Conn + connClose chan *rtmpconn.Conn terminate chan struct{} // out @@ -69,8 +69,8 @@ func New( pathMan: pathMan, parent: parent, l: l, - conns: make(map[*connrtmp.Conn]struct{}), - connClose: make(chan *connrtmp.Conn), + conns: make(map[*rtmpconn.Conn]struct{}), + connClose: make(chan *rtmpconn.Conn), terminate: make(chan struct{}), done: make(chan struct{}), } @@ -121,7 +121,7 @@ outer: break outer case nconn := <-connNew: - c := connrtmp.New( + c := rtmpconn.New( s.rtspAddress, s.readTimeout, s.writeTimeout, @@ -181,13 +181,13 @@ outer: close(s.connClose) } -func (s *Server) doConnClose(c *connrtmp.Conn) { +func (s *Server) doConnClose(c *rtmpconn.Conn) { delete(s.conns, c) c.ParentClose() c.Close() } -// OnConnClose is called by connrtmp.Conn. -func (s *Server) OnConnClose(c *connrtmp.Conn) { +// OnConnClose is called by rtmpconn.Conn. +func (s *Server) OnConnClose(c *rtmpconn.Conn) { s.connClose <- c } diff --git a/internal/sourcertmp/source.go b/internal/rtmpsource/source.go similarity index 99% rename from internal/sourcertmp/source.go rename to internal/rtmpsource/source.go index 8403c157..2c7a352b 100644 --- a/internal/sourcertmp/source.go +++ b/internal/rtmpsource/source.go @@ -1,4 +1,4 @@ -package sourcertmp +package rtmpsource import ( "context" diff --git a/internal/connrtsp/conn.go b/internal/rtspconn/conn.go similarity index 96% rename from internal/connrtsp/conn.go rename to internal/rtspconn/conn.go index 64b5a892..45a73647 100644 --- a/internal/connrtsp/conn.go +++ b/internal/rtspconn/conn.go @@ -1,4 +1,4 @@ -package connrtsp +package rtspconn import ( "errors" @@ -37,7 +37,7 @@ type PathMan interface { OnReadPublisherDescribe(readpublisher.DescribeReq) } -// Parent is implemented by serverrtsp.Server. +// Parent is implemented by rtspserver.Server. type Parent interface { Log(logger.Level, string, ...interface{}) } @@ -121,17 +121,17 @@ func (c *Conn) ip() net.IP { return c.conn.NetConn().RemoteAddr().(*net.TCPAddr).IP } -// OnRequest is called by serverrtsp.Server. +// OnRequest is called by rtspserver.Server. func (c *Conn) OnRequest(req *base.Request) { c.log(logger.Debug, "[c->s] %v", req) } -// OnResponse is called by serverrtsp.Server. +// OnResponse is called by rtspserver.Server. func (c *Conn) OnResponse(res *base.Response) { c.log(logger.Debug, "[s->c] %v", res) } -// OnDescribe is called by serverrtsp.Server. +// OnDescribe is called by rtspserver.Server. func (c *Conn) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, []byte, error) { resc := make(chan readpublisher.DescribeRes) c.pathMan.OnReadPublisherDescribe(readpublisher.DescribeReq{ diff --git a/internal/serverrtsp/server.go b/internal/rtspserver/server.go similarity index 93% rename from internal/serverrtsp/server.go rename to internal/rtspserver/server.go index ad823960..083d92ec 100644 --- a/internal/serverrtsp/server.go +++ b/internal/rtspserver/server.go @@ -1,4 +1,4 @@ -package serverrtsp +package rtspserver import ( "crypto/rand" @@ -11,14 +11,14 @@ import ( "github.com/aler9/gortsplib" "github.com/aler9/gortsplib/pkg/base" - "github.com/aler9/rtsp-simple-server/internal/connrtsp" + "github.com/aler9/rtsp-simple-server/internal/rtspconn" "github.com/aler9/rtsp-simple-server/internal/logger" "github.com/aler9/rtsp-simple-server/internal/pathman" - "github.com/aler9/rtsp-simple-server/internal/sessionrtsp" + "github.com/aler9/rtsp-simple-server/internal/rtspsession" "github.com/aler9/rtsp-simple-server/internal/stats" ) -func newSessionVisualID(sessions map[*gortsplib.ServerSession]*sessionrtsp.Session) (string, error) { +func newSessionVisualID(sessions map[*gortsplib.ServerSession]*rtspsession.Session) (string, error) { for { b := make([]byte, 4) _, err := rand.Read(b) @@ -61,8 +61,8 @@ type Server struct { srv *gortsplib.Server mutex sync.RWMutex - conns map[*gortsplib.ServerConn]*connrtsp.Conn - sessions map[*gortsplib.ServerSession]*sessionrtsp.Session + conns map[*gortsplib.ServerConn]*rtspconn.Conn + sessions map[*gortsplib.ServerSession]*rtspsession.Session // in terminate chan struct{} @@ -100,8 +100,8 @@ func New( stats: stats, pathMan: pathMan, parent: parent, - conns: make(map[*gortsplib.ServerConn]*connrtsp.Conn), - sessions: make(map[*gortsplib.ServerSession]*sessionrtsp.Session), + conns: make(map[*gortsplib.ServerConn]*rtspconn.Conn), + sessions: make(map[*gortsplib.ServerSession]*rtspsession.Session), terminate: make(chan struct{}), done: make(chan struct{}), } @@ -199,7 +199,7 @@ outer: // OnConnOpen implements gortsplib.ServerHandlerOnConnOpen. func (s *Server) OnConnOpen(ctx *gortsplib.ServerHandlerOnConnOpenCtx) { - c := connrtsp.New( + c := rtspconn.New( s.rtspAddress, s.readTimeout, s.runOnConnect, @@ -250,7 +250,7 @@ func (s *Server) OnSessionOpen(ctx *gortsplib.ServerHandlerOnSessionOpenCtx) { // use a new random ID visualID, _ := newSessionVisualID(s.sessions) - se := sessionrtsp.New( + se := rtspsession.New( s.rtspAddress, s.protocols, visualID, diff --git a/internal/sessionrtsp/session.go b/internal/rtspsession/session.go similarity index 94% rename from internal/sessionrtsp/session.go rename to internal/rtspsession/session.go index 1144325b..5620d198 100644 --- a/internal/sessionrtsp/session.go +++ b/internal/rtspsession/session.go @@ -1,4 +1,4 @@ -package sessionrtsp +package rtspsession import ( "errors" @@ -11,7 +11,7 @@ import ( "github.com/aler9/gortsplib/pkg/base" "github.com/aler9/gortsplib/pkg/headers" - "github.com/aler9/rtsp-simple-server/internal/connrtsp" + "github.com/aler9/rtsp-simple-server/internal/rtspconn" "github.com/aler9/rtsp-simple-server/internal/externalcmd" "github.com/aler9/rtsp-simple-server/internal/logger" "github.com/aler9/rtsp-simple-server/internal/readpublisher" @@ -30,7 +30,7 @@ type PathMan interface { OnReadPublisherAnnounce(readpublisher.AnnounceReq) } -// Parent is implemented by serverrtsp.Server. +// Parent is implemented by rtspserver.Server. type Parent interface { Log(logger.Level, string, ...interface{}) } @@ -119,8 +119,8 @@ func (s *Session) log(level logger.Level, format string, args ...interface{}) { s.parent.Log(level, "[session %s] "+format, append([]interface{}{s.visualID}, args...)...) } -// OnAnnounce is called by serverrtsp.Server. -func (s *Session) OnAnnounce(c *connrtsp.Conn, ctx *gortsplib.ServerHandlerOnAnnounceCtx) (*base.Response, error) { +// OnAnnounce is called by rtspserver.Server. +func (s *Session) OnAnnounce(c *rtspconn.Conn, ctx *gortsplib.ServerHandlerOnAnnounceCtx) (*base.Response, error) { resc := make(chan readpublisher.AnnounceRes) s.pathMan.OnReadPublisherAnnounce(readpublisher.AnnounceReq{ Author: s, @@ -159,8 +159,8 @@ func (s *Session) OnAnnounce(c *connrtsp.Conn, ctx *gortsplib.ServerHandlerOnAnn }, nil } -// OnSetup is called by serverrtsp.Server. -func (s *Session) OnSetup(c *connrtsp.Conn, ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, error) { +// OnSetup is called by rtspserver.Server. +func (s *Session) OnSetup(c *rtspconn.Conn, ctx *gortsplib.ServerHandlerOnSetupCtx) (*base.Response, error) { if ctx.Transport.Protocol == gortsplib.StreamProtocolUDP { if _, ok := s.protocols[gortsplib.StreamProtocolUDP]; !ok { return &base.Response{ @@ -232,7 +232,7 @@ func (s *Session) OnSetup(c *connrtsp.Conn, ctx *gortsplib.ServerHandlerOnSetupC }, nil } -// OnPlay is called by serverrtsp.Server. +// OnPlay is called by rtspserver.Server. func (s *Session) OnPlay(ctx *gortsplib.ServerHandlerOnPlayCtx) (*base.Response, error) { h := make(base.Header) @@ -309,7 +309,7 @@ func (s *Session) OnPlay(ctx *gortsplib.ServerHandlerOnPlayCtx) (*base.Response, }, nil } -// OnRecord is called by serverrtsp.Server. +// OnRecord is called by rtspserver.Server. func (s *Session) OnRecord(ctx *gortsplib.ServerHandlerOnRecordCtx) (*base.Response, error) { if ctx.Path != s.path.Name() { return &base.Response{ @@ -355,7 +355,7 @@ func (s *Session) OnRecord(ctx *gortsplib.ServerHandlerOnRecordCtx) (*base.Respo }, nil } -// OnPause is called by serverrtsp.Server. +// OnPause is called by rtspserver.Server. func (s *Session) OnPause(ctx *gortsplib.ServerHandlerOnPauseCtx) (*base.Response, error) { switch s.ss.State() { case gortsplib.ServerSessionStatePlay: @@ -391,7 +391,7 @@ func (s *Session) OnFrame(trackID int, streamType gortsplib.StreamType, payload s.ss.WriteFrame(trackID, streamType, payload) } -// OnIncomingFrame is called by serverrtsp.Server. +// OnIncomingFrame is called by rtspserver.Server. func (s *Session) OnIncomingFrame(ctx *gortsplib.ServerHandlerOnFrameCtx) { if s.ss.State() != gortsplib.ServerSessionStateRecord { return diff --git a/internal/sourcertsp/source.go b/internal/rtspsource/source.go similarity index 99% rename from internal/sourcertsp/source.go rename to internal/rtspsource/source.go index df4e9c0b..e90157a2 100644 --- a/internal/sourcertsp/source.go +++ b/internal/rtspsource/source.go @@ -1,4 +1,4 @@ -package sourcertsp +package rtspsource import ( "crypto/sha256" diff --git a/main.go b/main.go index f22cb61a..4417df97 100644 --- a/main.go +++ b/main.go @@ -16,9 +16,9 @@ import ( "github.com/aler9/rtsp-simple-server/internal/pathman" "github.com/aler9/rtsp-simple-server/internal/pprof" "github.com/aler9/rtsp-simple-server/internal/rlimit" - "github.com/aler9/rtsp-simple-server/internal/serverhls" - "github.com/aler9/rtsp-simple-server/internal/serverrtmp" - "github.com/aler9/rtsp-simple-server/internal/serverrtsp" + "github.com/aler9/rtsp-simple-server/internal/hlsserver" + "github.com/aler9/rtsp-simple-server/internal/rtmpserver" + "github.com/aler9/rtsp-simple-server/internal/rtspserver" "github.com/aler9/rtsp-simple-server/internal/stats" ) @@ -33,10 +33,10 @@ type program struct { metrics *metrics.Metrics pprof *pprof.PPROF pathMan *pathman.PathManager - serverRTSPPlain *serverrtsp.Server - serverRTSPTLS *serverrtsp.Server - serverRTMP *serverrtmp.Server - serverHLS *serverhls.Server + serverRTSPPlain *rtspserver.Server + serverRTSPTLS *rtspserver.Server + serverRTMP *rtmpserver.Server + serverHLS *hlsserver.Server confWatcher *confwatcher.ConfWatcher terminate chan struct{} @@ -206,7 +206,7 @@ func (p *program) createResources(initial bool) error { p.conf.EncryptionParsed == conf.EncryptionOptional) { if p.serverRTSPPlain == nil { _, useUDP := p.conf.ProtocolsParsed[gortsplib.StreamProtocolUDP] - p.serverRTSPPlain, err = serverrtsp.New( + p.serverRTSPPlain, err = rtspserver.New( p.conf.RTSPAddress, p.conf.ReadTimeout, p.conf.WriteTimeout, @@ -235,7 +235,7 @@ func (p *program) createResources(initial bool) error { (p.conf.EncryptionParsed == conf.EncryptionStrict || p.conf.EncryptionParsed == conf.EncryptionOptional) { if p.serverRTSPTLS == nil { - p.serverRTSPTLS, err = serverrtsp.New( + p.serverRTSPTLS, err = rtspserver.New( p.conf.RTSPSAddress, p.conf.ReadTimeout, p.conf.WriteTimeout, @@ -262,7 +262,7 @@ func (p *program) createResources(initial bool) error { if !p.conf.RTMPDisable { if p.serverRTMP == nil { - p.serverRTMP, err = serverrtmp.New( + p.serverRTMP, err = rtmpserver.New( p.conf.RTMPAddress, p.conf.ReadTimeout, p.conf.WriteTimeout, @@ -281,7 +281,7 @@ func (p *program) createResources(initial bool) error { if !p.conf.HLSDisable { if p.serverHLS == nil { - p.serverHLS, err = serverhls.New( + p.serverHLS, err = hlsserver.New( p.conf.HLSAddress, p.conf.HLSSegmentCount, p.conf.HLSSegmentDuration,