Browse Source

rename client into clientrtsp

pull/235/head
aler9 6 years ago
parent
commit
50880bf07b
  1. 32
      internal/clientman/clientman.go
  2. 2
      internal/clientrtsp/client.go
  3. 2
      internal/clientrtsp/utils.go
  4. 124
      internal/path/path.go
  5. 54
      internal/pathman/pathman.go
  6. 34
      internal/serverrtmp/server.go

32
internal/clientman/clientman.go

@ -7,7 +7,7 @@ import ( @@ -7,7 +7,7 @@ import (
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/base"
"github.com/aler9/rtsp-simple-server/internal/client"
"github.com/aler9/rtsp-simple-server/internal/clientrtsp"
"github.com/aler9/rtsp-simple-server/internal/logger"
"github.com/aler9/rtsp-simple-server/internal/pathman"
"github.com/aler9/rtsp-simple-server/internal/serverrtsp"
@ -19,7 +19,7 @@ type Parent interface { @@ -19,7 +19,7 @@ type Parent interface {
Log(logger.Level, string, ...interface{})
}
// ClientManager is a client.Client manager.
// ClientManager is a clientrtsp.Client manager.
type ClientManager struct {
rtspPort int
readTimeout time.Duration
@ -32,11 +32,11 @@ type ClientManager struct { @@ -32,11 +32,11 @@ type ClientManager struct {
serverTLS *serverrtsp.Server
parent Parent
clients map[*client.Client]struct{}
clients map[*clientrtsp.Client]struct{}
wg sync.WaitGroup
// in
clientClose chan *client.Client
clientClose chan *clientrtsp.Client
terminate chan struct{}
// out
@ -67,8 +67,8 @@ func New( @@ -67,8 +67,8 @@ func New(
serverPlain: serverPlain,
serverTLS: serverTLS,
parent: parent,
clients: make(map[*client.Client]struct{}),
clientClose: make(chan *client.Client),
clients: make(map[*clientrtsp.Client]struct{}),
clientClose: make(chan *clientrtsp.Client),
terminate: make(chan struct{}),
done: make(chan struct{}),
}
@ -109,7 +109,7 @@ outer: @@ -109,7 +109,7 @@ outer:
for {
select {
case conn := <-tcpAccept:
c := client.New(false,
c := clientrtsp.New(false,
cm.rtspPort,
cm.readTimeout,
cm.runOnConnect,
@ -122,7 +122,7 @@ outer: @@ -122,7 +122,7 @@ outer:
cm.clients[c] = struct{}{}
case conn := <-tlsAccept:
c := client.New(true,
c := clientrtsp.New(true,
cm.rtspPort,
cm.readTimeout,
cm.runOnConnect,
@ -166,22 +166,22 @@ outer: @@ -166,22 +166,22 @@ outer:
close(cm.clientClose)
}
// OnClientClose is called by client.Client.
func (cm *ClientManager) OnClientClose(c *client.Client) {
// OnClientClose is called by clientrtsp.Client.
func (cm *ClientManager) OnClientClose(c *clientrtsp.Client) {
cm.clientClose <- c
}
// OnClientDescribe is called by client.Client.
func (cm *ClientManager) OnClientDescribe(req client.DescribeReq) {
// OnClientDescribe is called by clientrtsp.Client.
func (cm *ClientManager) OnClientDescribe(req clientrtsp.DescribeReq) {
cm.pathMan.OnClientDescribe(req)
}
// OnClientAnnounce is called by client.Client.
func (cm *ClientManager) OnClientAnnounce(req client.AnnounceReq) {
// OnClientAnnounce is called by clientrtsp.Client.
func (cm *ClientManager) OnClientAnnounce(req clientrtsp.AnnounceReq) {
cm.pathMan.OnClientAnnounce(req)
}
// OnClientSetupPlay is called by client.Client.
func (cm *ClientManager) OnClientSetupPlay(req client.SetupPlayReq) {
// OnClientSetupPlay is called by clientrtsp.Client.
func (cm *ClientManager) OnClientSetupPlay(req clientrtsp.SetupPlayReq) {
cm.pathMan.OnClientSetupPlay(req)
}

2
internal/client/client.go → internal/clientrtsp/client.go

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
package client
package clientrtsp
import (
"errors"

2
internal/client/utils.go → internal/clientrtsp/utils.go

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
package client
package clientrtsp
import (
"net"

124
internal/path/path.go

@ -10,7 +10,7 @@ import ( @@ -10,7 +10,7 @@ import (
"github.com/aler9/gortsplib"
"github.com/aler9/rtsp-simple-server/internal/client"
"github.com/aler9/rtsp-simple-server/internal/clientrtsp"
"github.com/aler9/rtsp-simple-server/internal/conf"
"github.com/aler9/rtsp-simple-server/internal/externalcmd"
"github.com/aler9/rtsp-simple-server/internal/logger"
@ -29,11 +29,11 @@ func newEmptyTimer() *time.Timer { @@ -29,11 +29,11 @@ func newEmptyTimer() *time.Timer {
type Parent interface {
Log(logger.Level, string, ...interface{})
OnPathClose(*Path)
OnPathClientClose(*client.Client)
OnPathClientClose(*clientrtsp.Client)
}
// a source can be
// * client.Client
// * clientrtsp.Client
// * sourcertsp.Source
// * sourcertmp.Source
// * sourceRedirect
@ -85,10 +85,10 @@ type Path struct { @@ -85,10 +85,10 @@ type Path struct {
stats *stats.Stats
parent Parent
clients map[*client.Client]clientState
clients map[*clientrtsp.Client]clientState
clientsWg sync.WaitGroup
describeRequests []client.DescribeReq
setupPlayRequests []client.SetupPlayReq
describeRequests []clientrtsp.DescribeReq
setupPlayRequests []clientrtsp.SetupPlayReq
source source
sourceTrackCount int
sourceSdp []byte
@ -105,15 +105,15 @@ type Path struct { @@ -105,15 +105,15 @@ type Path struct {
closeTimerStarted bool
// in
sourceSetReady chan struct{} // from source
sourceSetNotReady chan struct{} // from source
clientDescribe chan client.DescribeReq // from program
clientAnnounce chan client.AnnounceReq // from program
clientSetupPlay chan client.SetupPlayReq // from program
clientPlay chan client.PlayReq // from client
clientRecord chan client.RecordReq // from client
clientPause chan client.PauseReq // from client
clientRemove chan client.RemoveReq // from client
sourceSetReady chan struct{} // from source
sourceSetNotReady chan struct{} // from source
clientDescribe chan clientrtsp.DescribeReq // from program
clientAnnounce chan clientrtsp.AnnounceReq // from program
clientSetupPlay chan clientrtsp.SetupPlayReq // from program
clientPlay chan clientrtsp.PlayReq // from client
clientRecord chan clientrtsp.RecordReq // from client
clientPause chan clientrtsp.PauseReq // from client
clientRemove chan clientrtsp.RemoveReq // from client
terminate chan struct{}
}
@ -141,7 +141,7 @@ func New( @@ -141,7 +141,7 @@ func New(
wg: wg,
stats: stats,
parent: parent,
clients: make(map[*client.Client]clientState),
clients: make(map[*clientrtsp.Client]clientState),
readers: newReadersMap(),
describeTimer: newEmptyTimer(),
sourceCloseTimer: newEmptyTimer(),
@ -149,13 +149,13 @@ func New( @@ -149,13 +149,13 @@ func New(
closeTimer: newEmptyTimer(),
sourceSetReady: make(chan struct{}),
sourceSetNotReady: make(chan struct{}),
clientDescribe: make(chan client.DescribeReq),
clientAnnounce: make(chan client.AnnounceReq),
clientSetupPlay: make(chan client.SetupPlayReq),
clientPlay: make(chan client.PlayReq),
clientRecord: make(chan client.RecordReq),
clientPause: make(chan client.PauseReq),
clientRemove: make(chan client.RemoveReq),
clientDescribe: make(chan clientrtsp.DescribeReq),
clientAnnounce: make(chan clientrtsp.AnnounceReq),
clientSetupPlay: make(chan clientrtsp.SetupPlayReq),
clientPlay: make(chan clientrtsp.PlayReq),
clientRecord: make(chan clientrtsp.RecordReq),
clientPause: make(chan clientrtsp.PauseReq),
clientRemove: make(chan clientrtsp.RemoveReq),
terminate: make(chan struct{}),
}
@ -198,12 +198,12 @@ outer: @@ -198,12 +198,12 @@ outer:
select {
case <-pa.describeTimer.C:
for _, req := range pa.describeRequests {
req.Res <- client.DescribeRes{nil, "", fmt.Errorf("publisher of path '%s' has timed out", pa.name)} //nolint:govet
req.Res <- clientrtsp.DescribeRes{nil, "", fmt.Errorf("publisher of path '%s' has timed out", pa.name)} //nolint:govet
}
pa.describeRequests = nil
for _, req := range pa.setupPlayRequests {
req.Res <- client.SetupPlayRes{nil, fmt.Errorf("publisher of path '%s' has timed out", pa.name)} //nolint:govet
req.Res <- clientrtsp.SetupPlayRes{nil, fmt.Errorf("publisher of path '%s' has timed out", pa.name)} //nolint:govet
}
pa.setupPlayRequests = nil
@ -254,10 +254,10 @@ outer: @@ -254,10 +254,10 @@ outer:
case req := <-pa.clientAnnounce:
err := pa.onClientAnnounce(req.Client, req.Tracks)
if err != nil {
req.Res <- client.AnnounceRes{nil, err} //nolint:govet
req.Res <- clientrtsp.AnnounceRes{nil, err} //nolint:govet
continue
}
req.Res <- client.AnnounceRes{pa, nil} //nolint:govet
req.Res <- clientrtsp.AnnounceRes{pa, nil} //nolint:govet
case req := <-pa.clientRecord:
pa.onClientRecord(req.Client)
@ -309,11 +309,11 @@ outer: @@ -309,11 +309,11 @@ outer:
}
for _, req := range pa.describeRequests {
req.Res <- client.DescribeRes{nil, "", fmt.Errorf("terminated")} //nolint:govet
req.Res <- clientrtsp.DescribeRes{nil, "", fmt.Errorf("terminated")} //nolint:govet
}
for _, req := range pa.setupPlayRequests {
req.Res <- client.SetupPlayRes{nil, fmt.Errorf("terminated")} //nolint:govet
req.Res <- clientrtsp.SetupPlayRes{nil, fmt.Errorf("terminated")} //nolint:govet
}
for c, state := range pa.clients {
@ -360,19 +360,19 @@ func (pa *Path) exhaustChannels() { @@ -360,19 +360,19 @@ func (pa *Path) exhaustChannels() {
if !ok {
return
}
req.Res <- client.DescribeRes{nil, "", fmt.Errorf("terminated")} //nolint:govet
req.Res <- clientrtsp.DescribeRes{nil, "", fmt.Errorf("terminated")} //nolint:govet
case req, ok := <-pa.clientAnnounce:
if !ok {
return
}
req.Res <- client.AnnounceRes{nil, fmt.Errorf("terminated")} //nolint:govet
req.Res <- clientrtsp.AnnounceRes{nil, fmt.Errorf("terminated")} //nolint:govet
case req, ok := <-pa.clientSetupPlay:
if !ok {
return
}
req.Res <- client.SetupPlayRes{nil, fmt.Errorf("terminated")} //nolint:govet
req.Res <- clientrtsp.SetupPlayRes{nil, fmt.Errorf("terminated")} //nolint:govet
case req, ok := <-pa.clientPlay:
if !ok {
@ -457,7 +457,7 @@ func (pa *Path) hasClientsNotSources() bool { @@ -457,7 +457,7 @@ func (pa *Path) hasClientsNotSources() bool {
return false
}
func (pa *Path) addClient(c *client.Client, state clientState) {
func (pa *Path) addClient(c *clientrtsp.Client, state clientState) {
if _, ok := pa.clients[c]; ok {
panic("client already added")
}
@ -466,7 +466,7 @@ func (pa *Path) addClient(c *client.Client, state clientState) { @@ -466,7 +466,7 @@ func (pa *Path) addClient(c *client.Client, state clientState) {
pa.clientsWg.Add(1)
}
func (pa *Path) removeClient(c *client.Client) {
func (pa *Path) removeClient(c *clientrtsp.Client) {
state := pa.clients[c]
pa.clients[c] = clientStatePreRemove
@ -506,7 +506,7 @@ func (pa *Path) onSourceSetReady() { @@ -506,7 +506,7 @@ func (pa *Path) onSourceSetReady() {
pa.sourceState = sourceStateReady
for _, req := range pa.describeRequests {
req.Res <- client.DescribeRes{pa.sourceSdp, "", nil} //nolint:govet
req.Res <- clientrtsp.DescribeRes{pa.sourceSdp, "", nil} //nolint:govet
}
pa.describeRequests = nil
@ -576,9 +576,9 @@ func (pa *Path) fixedPublisherStart() { @@ -576,9 +576,9 @@ func (pa *Path) fixedPublisherStart() {
}
}
func (pa *Path) onClientDescribe(req client.DescribeReq) {
func (pa *Path) onClientDescribe(req clientrtsp.DescribeReq) {
if _, ok := pa.clients[req.Client]; ok {
req.Res <- client.DescribeRes{nil, "", fmt.Errorf("already subscribed")} //nolint:govet
req.Res <- clientrtsp.DescribeRes{nil, "", fmt.Errorf("already subscribed")} //nolint:govet
return
}
@ -586,13 +586,13 @@ func (pa *Path) onClientDescribe(req client.DescribeReq) { @@ -586,13 +586,13 @@ func (pa *Path) onClientDescribe(req client.DescribeReq) {
pa.scheduleClose()
if _, ok := pa.source.(*sourceRedirect); ok {
req.Res <- client.DescribeRes{nil, pa.conf.SourceRedirect, nil} //nolint:govet
req.Res <- clientrtsp.DescribeRes{nil, pa.conf.SourceRedirect, nil} //nolint:govet
return
}
switch pa.sourceState {
case sourceStateReady:
req.Res <- client.DescribeRes{pa.sourceSdp, "", nil} //nolint:govet
req.Res <- clientrtsp.DescribeRes{pa.sourceSdp, "", nil} //nolint:govet
return
case sourceStateWaitingDescribe:
@ -601,18 +601,18 @@ func (pa *Path) onClientDescribe(req client.DescribeReq) { @@ -601,18 +601,18 @@ func (pa *Path) onClientDescribe(req client.DescribeReq) {
case sourceStateNotReady:
if pa.conf.Fallback != "" {
req.Res <- client.DescribeRes{nil, pa.conf.Fallback, nil} //nolint:govet
req.Res <- clientrtsp.DescribeRes{nil, pa.conf.Fallback, nil} //nolint:govet
return
}
req.Res <- client.DescribeRes{nil, "", client.ErrNoOnePublishing{pa.name}} //nolint:govet
req.Res <- clientrtsp.DescribeRes{nil, "", clientrtsp.ErrNoOnePublishing{pa.name}} //nolint:govet
return
}
}
func (pa *Path) onClientSetupPlayPost(req client.SetupPlayReq) {
func (pa *Path) onClientSetupPlayPost(req clientrtsp.SetupPlayReq) {
if req.TrackID >= pa.sourceTrackCount {
req.Res <- client.SetupPlayRes{nil, fmt.Errorf("track %d does not exist", req.TrackID)} //nolint:govet
req.Res <- clientrtsp.SetupPlayRes{nil, fmt.Errorf("track %d does not exist", req.TrackID)} //nolint:govet
return
}
@ -632,10 +632,10 @@ func (pa *Path) onClientSetupPlayPost(req client.SetupPlayReq) { @@ -632,10 +632,10 @@ func (pa *Path) onClientSetupPlayPost(req client.SetupPlayReq) {
pa.addClient(req.Client, clientStatePrePlay)
}
req.Res <- client.SetupPlayRes{pa, nil} //nolint:govet
req.Res <- clientrtsp.SetupPlayRes{pa, nil} //nolint:govet
}
func (pa *Path) onClientSetupPlay(req client.SetupPlayReq) {
func (pa *Path) onClientSetupPlay(req clientrtsp.SetupPlayReq) {
pa.fixedPublisherStart()
pa.scheduleClose()
@ -649,12 +649,12 @@ func (pa *Path) onClientSetupPlay(req client.SetupPlayReq) { @@ -649,12 +649,12 @@ func (pa *Path) onClientSetupPlay(req client.SetupPlayReq) {
return
case sourceStateNotReady:
req.Res <- client.SetupPlayRes{nil, client.ErrNoOnePublishing{pa.name}} //nolint:govet
req.Res <- clientrtsp.SetupPlayRes{nil, clientrtsp.ErrNoOnePublishing{pa.name}} //nolint:govet
return
}
}
func (pa *Path) onClientPlay(c *client.Client) {
func (pa *Path) onClientPlay(c *clientrtsp.Client) {
state, ok := pa.clients[c]
if !ok {
return
@ -670,7 +670,7 @@ func (pa *Path) onClientPlay(c *client.Client) { @@ -670,7 +670,7 @@ func (pa *Path) onClientPlay(c *client.Client) {
pa.readers.add(c)
}
func (pa *Path) onClientAnnounce(c *client.Client, tracks gortsplib.Tracks) error {
func (pa *Path) onClientAnnounce(c *clientrtsp.Client, tracks gortsplib.Tracks) error {
if _, ok := pa.clients[c]; ok {
return fmt.Errorf("already subscribed")
}
@ -687,7 +687,7 @@ func (pa *Path) onClientAnnounce(c *client.Client, tracks gortsplib.Tracks) erro @@ -687,7 +687,7 @@ func (pa *Path) onClientAnnounce(c *client.Client, tracks gortsplib.Tracks) erro
return nil
}
func (pa *Path) onClientRecord(c *client.Client) {
func (pa *Path) onClientRecord(c *clientrtsp.Client) {
state, ok := pa.clients[c]
if !ok {
return
@ -703,7 +703,7 @@ func (pa *Path) onClientRecord(c *client.Client) { @@ -703,7 +703,7 @@ func (pa *Path) onClientRecord(c *client.Client) {
pa.onSourceSetReady()
}
func (pa *Path) onClientPause(c *client.Client) {
func (pa *Path) onClientPause(c *clientrtsp.Client) {
state, ok := pa.clients[c]
if !ok {
return
@ -803,41 +803,41 @@ func (pa *Path) OnSourceSetNotReady() { @@ -803,41 +803,41 @@ func (pa *Path) OnSourceSetNotReady() {
}
// OnPathManDescribe is called by pathman.PathMan.
func (pa *Path) OnPathManDescribe(req client.DescribeReq) {
func (pa *Path) OnPathManDescribe(req clientrtsp.DescribeReq) {
pa.clientDescribe <- req
}
// OnPathManSetupPlay is called by pathman.PathMan.
func (pa *Path) OnPathManSetupPlay(req client.SetupPlayReq) {
func (pa *Path) OnPathManSetupPlay(req clientrtsp.SetupPlayReq) {
pa.clientSetupPlay <- req
}
// OnPathManAnnounce is called by pathman.PathMan.
func (pa *Path) OnPathManAnnounce(req client.AnnounceReq) {
func (pa *Path) OnPathManAnnounce(req clientrtsp.AnnounceReq) {
pa.clientAnnounce <- req
}
// OnClientRemove is called by client.Client.
func (pa *Path) OnClientRemove(req client.RemoveReq) {
// OnClientRemove is called by clientrtsp.Client.
func (pa *Path) OnClientRemove(req clientrtsp.RemoveReq) {
pa.clientRemove <- req
}
// OnClientPlay is called by client.Client.
func (pa *Path) OnClientPlay(req client.PlayReq) {
// OnClientPlay is called by clientrtsp.Client.
func (pa *Path) OnClientPlay(req clientrtsp.PlayReq) {
pa.clientPlay <- req
}
// OnClientRecord is called by client.Client.
func (pa *Path) OnClientRecord(req client.RecordReq) {
// OnClientRecord is called by clientrtsp.Client.
func (pa *Path) OnClientRecord(req clientrtsp.RecordReq) {
pa.clientRecord <- req
}
// OnClientPause is called by client.Client.
func (pa *Path) OnClientPause(req client.PauseReq) {
// OnClientPause is called by clientrtsp.Client.
func (pa *Path) OnClientPause(req clientrtsp.PauseReq) {
pa.clientPause <- req
}
// OnFrame is called by a source or by a client.Client.
// OnFrame is called by a source or by a clientrtsp.Client.
func (pa *Path) OnFrame(trackID int, streamType gortsplib.StreamType, buf []byte) {
pa.readers.forwardFrame(trackID, streamType, buf)
}

54
internal/pathman/pathman.go

@ -8,7 +8,7 @@ import ( @@ -8,7 +8,7 @@ import (
"github.com/aler9/gortsplib/pkg/base"
"github.com/aler9/gortsplib/pkg/headers"
"github.com/aler9/rtsp-simple-server/internal/client"
"github.com/aler9/rtsp-simple-server/internal/clientrtsp"
"github.com/aler9/rtsp-simple-server/internal/conf"
"github.com/aler9/rtsp-simple-server/internal/logger"
"github.com/aler9/rtsp-simple-server/internal/path"
@ -37,13 +37,13 @@ type PathManager struct { @@ -37,13 +37,13 @@ type PathManager struct {
// in
confReload chan map[string]*conf.PathConf
pathClose chan *path.Path
clientDescribe chan client.DescribeReq
clientAnnounce chan client.AnnounceReq
clientSetupPlay chan client.SetupPlayReq
clientDescribe chan clientrtsp.DescribeReq
clientAnnounce chan clientrtsp.AnnounceReq
clientSetupPlay chan clientrtsp.SetupPlayReq
terminate chan struct{}
// out
clientClose chan *client.Client
clientClose chan *clientrtsp.Client
done chan struct{}
}
@ -70,11 +70,11 @@ func New( @@ -70,11 +70,11 @@ func New(
paths: make(map[string]*path.Path),
confReload: make(chan map[string]*conf.PathConf),
pathClose: make(chan *path.Path),
clientDescribe: make(chan client.DescribeReq),
clientAnnounce: make(chan client.AnnounceReq),
clientSetupPlay: make(chan client.SetupPlayReq),
clientDescribe: make(chan clientrtsp.DescribeReq),
clientAnnounce: make(chan clientrtsp.AnnounceReq),
clientSetupPlay: make(chan clientrtsp.SetupPlayReq),
terminate: make(chan struct{}),
clientClose: make(chan *client.Client),
clientClose: make(chan *clientrtsp.Client),
done: make(chan struct{}),
}
@ -149,14 +149,14 @@ outer: @@ -149,14 +149,14 @@ outer:
case req := <-pm.clientDescribe:
pathName, pathConf, err := pm.findPathConf(req.PathName)
if err != nil {
req.Res <- client.DescribeRes{nil, "", err} //nolint:govet
req.Res <- clientrtsp.DescribeRes{nil, "", err} //nolint:govet
continue
}
err = req.Client.Authenticate(pm.authMethods, pathConf.ReadIpsParsed,
pathConf.ReadUser, pathConf.ReadPass, req.Req, nil)
if err != nil {
req.Res <- client.DescribeRes{nil, "", err} //nolint:govet
req.Res <- clientrtsp.DescribeRes{nil, "", err} //nolint:govet
continue
}
@ -181,7 +181,7 @@ outer: @@ -181,7 +181,7 @@ outer:
case req := <-pm.clientAnnounce:
pathName, pathConf, err := pm.findPathConf(req.PathName)
if err != nil {
req.Res <- client.AnnounceRes{nil, err} //nolint:govet
req.Res <- clientrtsp.AnnounceRes{nil, err} //nolint:govet
continue
}
@ -189,7 +189,7 @@ outer: @@ -189,7 +189,7 @@ outer:
pathConf.PublishIpsParsed, pathConf.PublishUser,
pathConf.PublishPass, req.Req, nil)
if err != nil {
req.Res <- client.AnnounceRes{nil, err} //nolint:govet
req.Res <- clientrtsp.AnnounceRes{nil, err} //nolint:govet
continue
}
@ -214,7 +214,7 @@ outer: @@ -214,7 +214,7 @@ outer:
case req := <-pm.clientSetupPlay:
pathName, pathConf, err := pm.findPathConf(req.PathName)
if err != nil {
req.Res <- client.SetupPlayRes{nil, err} //nolint:govet
req.Res <- clientrtsp.SetupPlayRes{nil, err} //nolint:govet
continue
}
@ -230,7 +230,7 @@ outer: @@ -230,7 +230,7 @@ outer:
pathConf.ReadIpsParsed, pathConf.ReadUser, pathConf.ReadPass,
req.Req, altURL)
if err != nil {
req.Res <- client.SetupPlayRes{nil, err} //nolint:govet
req.Res <- clientrtsp.SetupPlayRes{nil, err} //nolint:govet
continue
}
@ -274,19 +274,19 @@ outer: @@ -274,19 +274,19 @@ outer:
if !ok {
return
}
req.Res <- client.DescribeRes{nil, "", fmt.Errorf("terminated")} //nolint:govet
req.Res <- clientrtsp.DescribeRes{nil, "", fmt.Errorf("terminated")} //nolint:govet
case req, ok := <-pm.clientAnnounce:
if !ok {
return
}
req.Res <- client.AnnounceRes{nil, fmt.Errorf("terminated")} //nolint:govet
req.Res <- clientrtsp.AnnounceRes{nil, fmt.Errorf("terminated")} //nolint:govet
case req, ok := <-pm.clientSetupPlay:
if !ok {
return
}
req.Res <- client.SetupPlayRes{nil, fmt.Errorf("terminated")} //nolint:govet
req.Res <- clientrtsp.SetupPlayRes{nil, fmt.Errorf("terminated")} //nolint:govet
}
}
}()
@ -355,26 +355,26 @@ func (pm *PathManager) OnPathClose(pa *path.Path) { @@ -355,26 +355,26 @@ func (pm *PathManager) OnPathClose(pa *path.Path) {
}
// OnPathClientClose is called by path.Path.
func (pm *PathManager) OnPathClientClose(c *client.Client) {
func (pm *PathManager) OnPathClientClose(c *clientrtsp.Client) {
pm.clientClose <- c
}
// OnClientDescribe is called by client.Client.
func (pm *PathManager) OnClientDescribe(req client.DescribeReq) {
// OnClientDescribe is called by clientrtsp.Client.
func (pm *PathManager) OnClientDescribe(req clientrtsp.DescribeReq) {
pm.clientDescribe <- req
}
// OnClientAnnounce is called by client.Client.
func (pm *PathManager) OnClientAnnounce(req client.AnnounceReq) {
// OnClientAnnounce is called by clientrtsp.Client.
func (pm *PathManager) OnClientAnnounce(req clientrtsp.AnnounceReq) {
pm.clientAnnounce <- req
}
// OnClientSetupPlay is called by client.Client.
func (pm *PathManager) OnClientSetupPlay(req client.SetupPlayReq) {
// OnClientSetupPlay is called by clientrtsp.Client.
func (pm *PathManager) OnClientSetupPlay(req clientrtsp.SetupPlayReq) {
pm.clientSetupPlay <- req
}
// ClientClose is called by client.Client.
func (pm *PathManager) ClientClose() chan *client.Client {
// ClientClose is called by clientrtsp.Client.
func (pm *PathManager) ClientClose() chan *clientrtsp.Client {
return pm.clientClose
}

34
internal/serverrtmp/server.go

@ -6,45 +6,11 @@ import ( @@ -6,45 +6,11 @@ import (
"strconv"
"sync"
"github.com/notedit/rtmp/av"
"github.com/notedit/rtmp/format/flv/flvio"
"github.com/notedit/rtmp/format/rtmp"
"github.com/aler9/rtsp-simple-server/internal/logger"
)
const (
codecH264 = 7
codecAAC = 10
)
func readMetadata(conn *rtmp.Conn) (flvio.AMFMap, error) {
pkt, err := conn.ReadPacket()
if err != nil {
return nil, err
}
if pkt.Type != av.Metadata {
return nil, fmt.Errorf("first packet must be metadata")
}
arr, err := flvio.ParseAMFVals(pkt.Data, false)
if err != nil {
return nil, err
}
if len(arr) != 1 {
return nil, fmt.Errorf("invalid metadata")
}
ma, ok := arr[0].(flvio.AMFMap)
if !ok {
return nil, fmt.Errorf("invalid metadata")
}
return ma, nil
}
// Parent is implemented by program.
type Parent interface {
Log(logger.Level, string, ...interface{})

Loading…
Cancel
Save