api: add conns to RTSP Sessions (#5454)

this allows to find connections associated with a RTSP session.
This commit is contained in:
Alessandro Ros
2026-02-12 15:45:34 +01:00
committed by GitHub
parent ea6977d918
commit 832cc05f39
8 changed files with 50 additions and 21 deletions
+11 -6
View File
@@ -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
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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=
+2
View File
@@ -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)
+3 -2
View File
@@ -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"`
+8 -8
View File
@@ -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,
}
}
+5 -1
View File
@@ -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]
}
+18 -1
View File
@@ -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,