mirror of
https://github.com/bluenviron/mediamtx
synced 2024-12-17 04:04:41 +00:00
expose path manager to clients
This commit is contained in:
parent
4f393700b6
commit
3636f0106a
@ -30,7 +30,7 @@ type Parent interface {
|
||||
Log(logger.Level, string, ...interface{})
|
||||
}
|
||||
|
||||
// ClientManager is a clientrtsp.Client manager.
|
||||
// ClientManager is a client manager.
|
||||
type ClientManager struct {
|
||||
rtspPort int
|
||||
readTimeout time.Duration
|
||||
@ -147,6 +147,7 @@ outer:
|
||||
&cm.wg,
|
||||
cm.stats,
|
||||
conn,
|
||||
cm.pathMan,
|
||||
cm)
|
||||
cm.clients[c] = struct{}{}
|
||||
|
||||
@ -161,6 +162,7 @@ outer:
|
||||
&cm.wg,
|
||||
cm.stats,
|
||||
conn,
|
||||
cm.pathMan,
|
||||
cm)
|
||||
cm.clients[c] = struct{}{}
|
||||
|
||||
@ -175,6 +177,7 @@ outer:
|
||||
&cm.wg,
|
||||
cm.stats,
|
||||
conn,
|
||||
cm.pathMan,
|
||||
cm)
|
||||
cm.clients[c] = struct{}{}
|
||||
|
||||
@ -219,22 +222,7 @@ outer:
|
||||
close(cm.clientClose)
|
||||
}
|
||||
|
||||
// OnClientClose is called by clientrtsp.Client.
|
||||
// OnClientClose is called by a client.
|
||||
func (cm *ClientManager) OnClientClose(c client.Client) {
|
||||
cm.clientClose <- c
|
||||
}
|
||||
|
||||
// OnClientDescribe is called by clientrtsp.Client.
|
||||
func (cm *ClientManager) OnClientDescribe(req client.DescribeReq) {
|
||||
cm.pathMan.OnClientDescribe(req)
|
||||
}
|
||||
|
||||
// OnClientAnnounce is called by clientrtsp.Client.
|
||||
func (cm *ClientManager) OnClientAnnounce(req client.AnnounceReq) {
|
||||
cm.pathMan.OnClientAnnounce(req)
|
||||
}
|
||||
|
||||
// OnClientSetupPlay is called by clientrtsp.Client.
|
||||
func (cm *ClientManager) OnClientSetupPlay(req client.SetupPlayReq) {
|
||||
cm.pathMan.OnClientSetupPlay(req)
|
||||
}
|
||||
|
@ -62,12 +62,16 @@ type trackIDBufPair struct {
|
||||
buf []byte
|
||||
}
|
||||
|
||||
// PathMan is implemented by pathman.PathMan.
|
||||
type PathMan interface {
|
||||
OnClientSetupPlay(client.SetupPlayReq)
|
||||
OnClientAnnounce(client.AnnounceReq)
|
||||
}
|
||||
|
||||
// Parent is implemented by clientman.ClientMan.
|
||||
type Parent interface {
|
||||
Log(logger.Level, string, ...interface{})
|
||||
OnClientClose(client.Client)
|
||||
OnClientSetupPlay(client.SetupPlayReq)
|
||||
OnClientAnnounce(client.AnnounceReq)
|
||||
}
|
||||
|
||||
// Client is a RTMP client.
|
||||
@ -81,6 +85,7 @@ type Client struct {
|
||||
stats *stats.Stats
|
||||
wg *sync.WaitGroup
|
||||
conn *rtmputils.Conn
|
||||
pathMan PathMan
|
||||
parent Parent
|
||||
|
||||
// read mode only
|
||||
@ -105,6 +110,7 @@ func New(
|
||||
wg *sync.WaitGroup,
|
||||
stats *stats.Stats,
|
||||
conn *rtmputils.Conn,
|
||||
pathMan PathMan,
|
||||
parent Parent) *Client {
|
||||
|
||||
c := &Client{
|
||||
@ -117,6 +123,7 @@ func New(
|
||||
wg: wg,
|
||||
stats: stats,
|
||||
conn: conn,
|
||||
pathMan: pathMan,
|
||||
parent: parent,
|
||||
terminate: make(chan struct{}),
|
||||
}
|
||||
@ -177,7 +184,7 @@ func (c *Client) runRead() {
|
||||
pathName, query := pathNameAndQuery(c.conn.URL())
|
||||
|
||||
resc := make(chan client.SetupPlayRes)
|
||||
c.parent.OnClientSetupPlay(client.SetupPlayReq{c, pathName, query, resc}) //nolint:govet
|
||||
c.pathMan.OnClientSetupPlay(client.SetupPlayReq{c, pathName, query, resc}) //nolint:govet
|
||||
res := <-resc
|
||||
|
||||
if res.Err != nil {
|
||||
@ -450,7 +457,7 @@ func (c *Client) runPublish() {
|
||||
pathName, query := pathNameAndQuery(c.conn.URL())
|
||||
|
||||
resc := make(chan client.AnnounceRes)
|
||||
c.parent.OnClientAnnounce(client.AnnounceReq{c, pathName, tracks, query, resc}) //nolint:govet
|
||||
c.pathMan.OnClientAnnounce(client.AnnounceReq{c, pathName, tracks, query, resc}) //nolint:govet
|
||||
res := <-resc
|
||||
|
||||
if res.Err != nil {
|
||||
|
@ -45,13 +45,17 @@ func ipEqualOrInRange(ip net.IP, ips []interface{}) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// PathMan is implemented by pathman.PathMan.
|
||||
type PathMan interface {
|
||||
OnClientDescribe(client.DescribeReq)
|
||||
OnClientSetupPlay(client.SetupPlayReq)
|
||||
OnClientAnnounce(client.AnnounceReq)
|
||||
}
|
||||
|
||||
// Parent is implemented by clientman.ClientMan.
|
||||
type Parent interface {
|
||||
Log(logger.Level, string, ...interface{})
|
||||
OnClientClose(client.Client)
|
||||
OnClientDescribe(client.DescribeReq)
|
||||
OnClientAnnounce(client.AnnounceReq)
|
||||
OnClientSetupPlay(client.SetupPlayReq)
|
||||
}
|
||||
|
||||
// Client is a RTSP client.
|
||||
@ -64,6 +68,7 @@ type Client struct {
|
||||
wg *sync.WaitGroup
|
||||
stats *stats.Stats
|
||||
conn *gortsplib.ServerConn
|
||||
pathMan PathMan
|
||||
parent Parent
|
||||
|
||||
path client.Path
|
||||
@ -95,6 +100,7 @@ func New(
|
||||
wg *sync.WaitGroup,
|
||||
stats *stats.Stats,
|
||||
conn *gortsplib.ServerConn,
|
||||
pathMan PathMan,
|
||||
parent Parent) *Client {
|
||||
|
||||
c := &Client{
|
||||
@ -106,6 +112,7 @@ func New(
|
||||
wg: wg,
|
||||
stats: stats,
|
||||
conn: conn,
|
||||
pathMan: pathMan,
|
||||
parent: parent,
|
||||
terminate: make(chan struct{}),
|
||||
}
|
||||
@ -168,7 +175,7 @@ func (c *Client) run() {
|
||||
|
||||
onDescribe := func(ctx *gortsplib.ServerConnDescribeCtx) (*base.Response, []byte, error) {
|
||||
resc := make(chan client.DescribeRes)
|
||||
c.parent.OnClientDescribe(client.DescribeReq{c, ctx.Path, ctx.Req, resc}) //nolint:govet
|
||||
c.pathMan.OnClientDescribe(client.DescribeReq{c, ctx.Path, ctx.Req, resc}) //nolint:govet
|
||||
res := <-resc
|
||||
|
||||
if res.Err != nil {
|
||||
@ -212,7 +219,7 @@ func (c *Client) run() {
|
||||
|
||||
onAnnounce := func(ctx *gortsplib.ServerConnAnnounceCtx) (*base.Response, error) {
|
||||
resc := make(chan client.AnnounceRes)
|
||||
c.parent.OnClientAnnounce(client.AnnounceReq{c, ctx.Path, ctx.Tracks, ctx.Req, resc}) //nolint:govet
|
||||
c.pathMan.OnClientAnnounce(client.AnnounceReq{c, ctx.Path, ctx.Tracks, ctx.Req, resc}) //nolint:govet
|
||||
res := <-resc
|
||||
|
||||
if res.Err != nil {
|
||||
@ -260,7 +267,7 @@ func (c *Client) run() {
|
||||
switch c.conn.State() {
|
||||
case gortsplib.ServerConnStateInitial, gortsplib.ServerConnStatePrePlay: // play
|
||||
resc := make(chan client.SetupPlayRes)
|
||||
c.parent.OnClientSetupPlay(client.SetupPlayReq{c, ctx.Path, ctx.Req, resc}) //nolint:govet
|
||||
c.pathMan.OnClientSetupPlay(client.SetupPlayReq{c, ctx.Path, ctx.Req, resc}) //nolint:govet
|
||||
res := <-resc
|
||||
|
||||
if res.Err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user