diff --git a/api/openapi.yaml b/api/openapi.yaml index e677b2c6..23dccf8c 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -778,18 +778,18 @@ components: type: string remoteAddr: type: string - bytesReceived: - type: integer - format: uint64 - bytesSent: - type: integer - format: uint64 session: type: string format: uuid nullable: true tunnel: type: string + bytesReceived: + type: integer + format: uint64 + bytesSent: + type: integer + format: uint64 RTSPConnList: type: object @@ -828,6 +828,11 @@ components: profile: type: string nullable: true + conns: + type: array + items: + type: string + format: uuid bytesReceived: type: integer format: uint64 diff --git a/go.mod b/go.mod index 6c76e8a4..2d66129c 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/asticode/go-astits v1.14.0 github.com/bluenviron/gohlslib/v2 v2.2.5 github.com/bluenviron/gortmplib v0.2.1 - github.com/bluenviron/gortsplib/v5 v5.3.1 + github.com/bluenviron/gortsplib/v5 v5.3.2-0.20260211202618-9aea8d6fc9d6 github.com/bluenviron/mediacommon/v2 v2.7.2 github.com/datarhei/gosrt v0.9.0 github.com/fsnotify/fsnotify v1.9.0 diff --git a/go.sum b/go.sum index 77a3611e..62ea9d22 100644 --- a/go.sum +++ b/go.sum @@ -39,8 +39,8 @@ github.com/bluenviron/gohlslib/v2 v2.2.5 h1:gQyVmymInXSwm7QgMBwaq6eZZAM0FaT+hX41 github.com/bluenviron/gohlslib/v2 v2.2.5/go.mod h1:4ZQMhQ1m9SMFWfh65lptaz0YwHbRxDIza7mM9OZsydo= github.com/bluenviron/gortmplib v0.2.1 h1:ep+Aq4WTqbXUsJqMMenaRth2ugG1u3cm/fG0jHoriYI= github.com/bluenviron/gortmplib v0.2.1/go.mod h1:AMqbShthdHCzF6OFjcJ4LHTBbeZ5jSfDZvZBW1zaToA= -github.com/bluenviron/gortsplib/v5 v5.3.1 h1:PYqx29mr6C1uzQgUvj2dCCrPn4lieklt/ZOw5nGE75Q= -github.com/bluenviron/gortsplib/v5 v5.3.1/go.mod h1:pMia36dVdPoRMBxV/T1Z2xYxwI8bFkkd7xc2WM5KsOM= +github.com/bluenviron/gortsplib/v5 v5.3.2-0.20260211202618-9aea8d6fc9d6 h1:Vnp5Lw784UU1jl7Xf0fcYkp2HMQDpOJpHQQRncD4ILg= +github.com/bluenviron/gortsplib/v5 v5.3.2-0.20260211202618-9aea8d6fc9d6/go.mod h1:pMia36dVdPoRMBxV/T1Z2xYxwI8bFkkd7xc2WM5KsOM= github.com/bluenviron/mediacommon/v2 v2.7.2 h1:BA7X7YOKq4VC6Ygm5FIg2D2IYTt/Ud6T43anXkHbDE8= github.com/bluenviron/mediacommon/v2 v2.7.2/go.mod h1:5V15TiOfeaNVmZPVuOqAwqQSWyvMV86/dijDKu5q9Zs= github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ= diff --git a/internal/core/api_test.go b/internal/core/api_test.go index 27b65dc9..22408467 100644 --- a/internal/core/api_test.go +++ b/internal/core/api_test.go @@ -657,6 +657,7 @@ func TestAPIProtocolListGet(t *testing.T) { "rtcpPacketsReceived": float64(0), "rtcpPacketsSent": float64(0), "rtcpPacketsInError": float64(0), + "conns": out1.(map[string]any)["items"].([]any)[0].(map[string]any)["conns"], }, }, }, out1) @@ -702,6 +703,7 @@ func TestAPIProtocolListGet(t *testing.T) { "rtcpPacketsReceived": float64(0), "rtcpPacketsSent": float64(0), "rtcpPacketsInError": float64(0), + "conns": out1.(map[string]any)["items"].([]any)[0].(map[string]any)["conns"], }, }, }, out1) diff --git a/internal/defs/api.go b/internal/defs/api.go index 924bd2da..627d7ed4 100644 --- a/internal/defs/api.go +++ b/internal/defs/api.go @@ -159,10 +159,10 @@ type APIRTSPConn struct { ID uuid.UUID `json:"id"` Created time.Time `json:"created"` RemoteAddr string `json:"remoteAddr"` - BytesReceived uint64 `json:"bytesReceived"` - BytesSent uint64 `json:"bytesSent"` Session *uuid.UUID `json:"session"` Tunnel string `json:"tunnel"` + BytesReceived uint64 `json:"bytesReceived"` + BytesSent uint64 `json:"bytesSent"` } // APIRTSPConnsList is a list of RTSP connections. @@ -192,6 +192,7 @@ type APIRTSPSession struct { Query string `json:"query"` Transport *string `json:"transport"` Profile *string `json:"profile"` + Conns []uuid.UUID `json:"conns"` BytesReceived uint64 `json:"bytesReceived"` BytesSent uint64 `json:"bytesSent"` RTPPacketsReceived uint64 `json:"rtpPacketsReceived"` diff --git a/internal/servers/rtsp/conn.go b/internal/servers/rtsp/conn.go index 7992c8b8..29819c30 100644 --- a/internal/servers/rtsp/conn.go +++ b/internal/servers/rtsp/conn.go @@ -50,7 +50,7 @@ func tunnelLabel(t gortsplib.Tunnel) string { type connParent interface { logger.Writer - findSessionByRSessionUnsafe(rsession *gortsplib.ServerSession) *session + getSessionByRSessionUnsafe(rsession *gortsplib.ServerSession) *session } type conn struct { @@ -222,18 +222,18 @@ func (c *conn) apiItem() *defs.APIRTSPConn { stats := c.rconn.Stats() return &defs.APIRTSPConn{ - ID: c.uuid, - Created: c.created, - RemoteAddr: c.remoteAddr().String(), - BytesReceived: stats.BytesReceived, - BytesSent: stats.BytesSent, + ID: c.uuid, + Created: c.created, + RemoteAddr: c.remoteAddr().String(), Session: func() *uuid.UUID { - sx := c.parent.findSessionByRSessionUnsafe(c.rconn.Session()) + sx := c.parent.getSessionByRSessionUnsafe(c.rconn.Session()) if sx != nil { return &sx.uuid } return nil }(), - Tunnel: tunnelLabel(c.rconn.Transport().Tunnel), + Tunnel: tunnelLabel(c.rconn.Transport().Tunnel), + BytesReceived: stats.BytesReceived, + BytesSent: stats.BytesSent, } } diff --git a/internal/servers/rtsp/server.go b/internal/servers/rtsp/server.go index 4fb916a1..159b34ab 100644 --- a/internal/servers/rtsp/server.go +++ b/internal/servers/rtsp/server.go @@ -391,7 +391,11 @@ func (s *Server) findSessionByUUID(uuid uuid.UUID) (*gortsplib.ServerSession, *s return nil, nil } -func (s *Server) findSessionByRSessionUnsafe(rsession *gortsplib.ServerSession) *session { +func (s *Server) getConnByRConnUnsafe(rconn *gortsplib.ServerConn) *conn { + return s.conns[rconn] +} + +func (s *Server) getSessionByRSessionUnsafe(rsession *gortsplib.ServerSession) *session { return s.sessions[rsession] } diff --git a/internal/servers/rtsp/session.go b/internal/servers/rtsp/session.go index d02aee87..95f28943 100644 --- a/internal/servers/rtsp/session.go +++ b/internal/servers/rtsp/session.go @@ -36,6 +36,11 @@ func profileLabel(p headers.TransportProfile) string { return "unknown" } +type sessionParent interface { + logger.Writer + getConnByRConnUnsafe(rconn *gortsplib.ServerConn) *conn +} + type session struct { isTLS bool transports conf.RTSPTransports @@ -44,7 +49,7 @@ type session struct { rserver *gortsplib.Server externalCmdPool *externalcmd.Pool pathManager serverPathManager - parent logger.Writer + parent sessionParent uuid uuid.UUID created time.Time @@ -447,6 +452,18 @@ func (s *session) apiItem() *defs.APIRTSPSession { v := profileLabel(transport.Profile) return &v }(), + Conns: func() []uuid.UUID { + ret := []uuid.UUID{} + + for _, rconn := range s.rsession.Conns() { + conn := s.parent.getConnByRConnUnsafe(rconn) + if conn != nil { + ret = append(ret, conn.uuid) + } + } + + return ret + }(), BytesReceived: stats.BytesReceived, BytesSent: stats.BytesSent, RTPPacketsReceived: stats.RTPPacketsReceived,