api: add path to RTMP connections, RTSP sessions, WebRTC sessions (#1962) (#2022)

* api: add path to rtmp response

* add 'path' to RTSP and WebRTC sessions too

* add tests

---------

Co-authored-by: aler9 <46489434+aler9@users.noreply.github.com>
This commit is contained in:
Volodymyr Borodin
2023-07-05 12:20:26 -07:00
committed by GitHub
parent f0a4bd4e5d
commit 47317ea8e5
6 changed files with 93 additions and 77 deletions

View File

@@ -210,12 +210,13 @@ type rtmpConn struct {
pathManager rtmpConnPathManager
parent rtmpConnParent
ctx context.Context
ctxCancel func()
uuid uuid.UUID
created time.Time
state rtmpConnState
stateMutex sync.Mutex
ctx context.Context
ctxCancel func()
uuid uuid.UUID
created time.Time
mutex sync.Mutex
state rtmpConnState
pathName string
}
func newRTMPConn(
@@ -279,12 +280,6 @@ func (c *rtmpConn) ip() net.IP {
return c.nconn.RemoteAddr().(*net.TCPAddr).IP
}
func (c *rtmpConn) safeState() rtmpConnState {
c.stateMutex.Lock()
defer c.stateMutex.Unlock()
return c.state
}
func (c *rtmpConn) run() {
defer c.wg.Done()
@@ -380,9 +375,10 @@ func (c *rtmpConn) runRead(ctx context.Context, u *url.URL) error {
defer res.path.readerRemove(pathReaderRemoveReq{author: c})
c.stateMutex.Lock()
c.mutex.Lock()
c.state = rtmpConnStateRead
c.stateMutex.Unlock()
c.pathName = pathName
c.mutex.Unlock()
ringBuffer, _ := ringbuffer.New(uint64(c.readBufferCount))
go func() {
@@ -794,9 +790,10 @@ func (c *rtmpConn) runPublish(u *url.URL) error {
defer res.path.publisherRemove(pathPublisherRemoveReq{author: c})
c.stateMutex.Lock()
c.mutex.Lock()
c.state = rtmpConnStatePublish
c.stateMutex.Unlock()
c.pathName = pathName
c.mutex.Unlock()
videoFormat, audioFormat, err := c.conn.ReadTracks()
if err != nil {
@@ -892,12 +889,15 @@ func (c *rtmpConn) apiSourceDescribe() pathAPISourceOrReader {
}
func (c *rtmpConn) apiItem() *apiRTMPConn {
c.mutex.Lock()
defer c.mutex.Unlock()
return &apiRTMPConn{
ID: c.uuid,
Created: c.created,
RemoteAddr: c.remoteAddr().String(),
State: func() string {
switch c.safeState() {
switch c.state {
case rtmpConnStateRead:
return "read"
@@ -906,6 +906,7 @@ func (c *rtmpConn) apiItem() *apiRTMPConn {
}
return "idle"
}(),
Path: c.pathName,
BytesReceived: c.conn.BytesReceived(),
BytesSent: c.conn.BytesSent(),
}