api: add conns to RTSP Sessions (#5454)
this allows to find connections associated with a RTSP session.
This commit is contained in:
+11
-6
@@ -778,18 +778,18 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
remoteAddr:
|
remoteAddr:
|
||||||
type: string
|
type: string
|
||||||
bytesReceived:
|
|
||||||
type: integer
|
|
||||||
format: uint64
|
|
||||||
bytesSent:
|
|
||||||
type: integer
|
|
||||||
format: uint64
|
|
||||||
session:
|
session:
|
||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
nullable: true
|
nullable: true
|
||||||
tunnel:
|
tunnel:
|
||||||
type: string
|
type: string
|
||||||
|
bytesReceived:
|
||||||
|
type: integer
|
||||||
|
format: uint64
|
||||||
|
bytesSent:
|
||||||
|
type: integer
|
||||||
|
format: uint64
|
||||||
|
|
||||||
RTSPConnList:
|
RTSPConnList:
|
||||||
type: object
|
type: object
|
||||||
@@ -828,6 +828,11 @@ components:
|
|||||||
profile:
|
profile:
|
||||||
type: string
|
type: string
|
||||||
nullable: true
|
nullable: true
|
||||||
|
conns:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
bytesReceived:
|
bytesReceived:
|
||||||
type: integer
|
type: integer
|
||||||
format: uint64
|
format: uint64
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ require (
|
|||||||
github.com/asticode/go-astits v1.14.0
|
github.com/asticode/go-astits v1.14.0
|
||||||
github.com/bluenviron/gohlslib/v2 v2.2.5
|
github.com/bluenviron/gohlslib/v2 v2.2.5
|
||||||
github.com/bluenviron/gortmplib v0.2.1
|
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/bluenviron/mediacommon/v2 v2.7.2
|
||||||
github.com/datarhei/gosrt v0.9.0
|
github.com/datarhei/gosrt v0.9.0
|
||||||
github.com/fsnotify/fsnotify v1.9.0
|
github.com/fsnotify/fsnotify v1.9.0
|
||||||
|
|||||||
@@ -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/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 h1:ep+Aq4WTqbXUsJqMMenaRth2ugG1u3cm/fG0jHoriYI=
|
||||||
github.com/bluenviron/gortmplib v0.2.1/go.mod h1:AMqbShthdHCzF6OFjcJ4LHTBbeZ5jSfDZvZBW1zaToA=
|
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.2-0.20260211202618-9aea8d6fc9d6 h1:Vnp5Lw784UU1jl7Xf0fcYkp2HMQDpOJpHQQRncD4ILg=
|
||||||
github.com/bluenviron/gortsplib/v5 v5.3.1/go.mod h1:pMia36dVdPoRMBxV/T1Z2xYxwI8bFkkd7xc2WM5KsOM=
|
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 h1:BA7X7YOKq4VC6Ygm5FIg2D2IYTt/Ud6T43anXkHbDE8=
|
||||||
github.com/bluenviron/mediacommon/v2 v2.7.2/go.mod h1:5V15TiOfeaNVmZPVuOqAwqQSWyvMV86/dijDKu5q9Zs=
|
github.com/bluenviron/mediacommon/v2 v2.7.2/go.mod h1:5V15TiOfeaNVmZPVuOqAwqQSWyvMV86/dijDKu5q9Zs=
|
||||||
github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ=
|
github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ=
|
||||||
|
|||||||
@@ -657,6 +657,7 @@ func TestAPIProtocolListGet(t *testing.T) {
|
|||||||
"rtcpPacketsReceived": float64(0),
|
"rtcpPacketsReceived": float64(0),
|
||||||
"rtcpPacketsSent": float64(0),
|
"rtcpPacketsSent": float64(0),
|
||||||
"rtcpPacketsInError": float64(0),
|
"rtcpPacketsInError": float64(0),
|
||||||
|
"conns": out1.(map[string]any)["items"].([]any)[0].(map[string]any)["conns"],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, out1)
|
}, out1)
|
||||||
@@ -702,6 +703,7 @@ func TestAPIProtocolListGet(t *testing.T) {
|
|||||||
"rtcpPacketsReceived": float64(0),
|
"rtcpPacketsReceived": float64(0),
|
||||||
"rtcpPacketsSent": float64(0),
|
"rtcpPacketsSent": float64(0),
|
||||||
"rtcpPacketsInError": float64(0),
|
"rtcpPacketsInError": float64(0),
|
||||||
|
"conns": out1.(map[string]any)["items"].([]any)[0].(map[string]any)["conns"],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, out1)
|
}, out1)
|
||||||
|
|||||||
@@ -159,10 +159,10 @@ type APIRTSPConn struct {
|
|||||||
ID uuid.UUID `json:"id"`
|
ID uuid.UUID `json:"id"`
|
||||||
Created time.Time `json:"created"`
|
Created time.Time `json:"created"`
|
||||||
RemoteAddr string `json:"remoteAddr"`
|
RemoteAddr string `json:"remoteAddr"`
|
||||||
BytesReceived uint64 `json:"bytesReceived"`
|
|
||||||
BytesSent uint64 `json:"bytesSent"`
|
|
||||||
Session *uuid.UUID `json:"session"`
|
Session *uuid.UUID `json:"session"`
|
||||||
Tunnel string `json:"tunnel"`
|
Tunnel string `json:"tunnel"`
|
||||||
|
BytesReceived uint64 `json:"bytesReceived"`
|
||||||
|
BytesSent uint64 `json:"bytesSent"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// APIRTSPConnsList is a list of RTSP connections.
|
// APIRTSPConnsList is a list of RTSP connections.
|
||||||
@@ -192,6 +192,7 @@ type APIRTSPSession struct {
|
|||||||
Query string `json:"query"`
|
Query string `json:"query"`
|
||||||
Transport *string `json:"transport"`
|
Transport *string `json:"transport"`
|
||||||
Profile *string `json:"profile"`
|
Profile *string `json:"profile"`
|
||||||
|
Conns []uuid.UUID `json:"conns"`
|
||||||
BytesReceived uint64 `json:"bytesReceived"`
|
BytesReceived uint64 `json:"bytesReceived"`
|
||||||
BytesSent uint64 `json:"bytesSent"`
|
BytesSent uint64 `json:"bytesSent"`
|
||||||
RTPPacketsReceived uint64 `json:"rtpPacketsReceived"`
|
RTPPacketsReceived uint64 `json:"rtpPacketsReceived"`
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func tunnelLabel(t gortsplib.Tunnel) string {
|
|||||||
|
|
||||||
type connParent interface {
|
type connParent interface {
|
||||||
logger.Writer
|
logger.Writer
|
||||||
findSessionByRSessionUnsafe(rsession *gortsplib.ServerSession) *session
|
getSessionByRSessionUnsafe(rsession *gortsplib.ServerSession) *session
|
||||||
}
|
}
|
||||||
|
|
||||||
type conn struct {
|
type conn struct {
|
||||||
@@ -222,18 +222,18 @@ func (c *conn) apiItem() *defs.APIRTSPConn {
|
|||||||
stats := c.rconn.Stats()
|
stats := c.rconn.Stats()
|
||||||
|
|
||||||
return &defs.APIRTSPConn{
|
return &defs.APIRTSPConn{
|
||||||
ID: c.uuid,
|
ID: c.uuid,
|
||||||
Created: c.created,
|
Created: c.created,
|
||||||
RemoteAddr: c.remoteAddr().String(),
|
RemoteAddr: c.remoteAddr().String(),
|
||||||
BytesReceived: stats.BytesReceived,
|
|
||||||
BytesSent: stats.BytesSent,
|
|
||||||
Session: func() *uuid.UUID {
|
Session: func() *uuid.UUID {
|
||||||
sx := c.parent.findSessionByRSessionUnsafe(c.rconn.Session())
|
sx := c.parent.getSessionByRSessionUnsafe(c.rconn.Session())
|
||||||
if sx != nil {
|
if sx != nil {
|
||||||
return &sx.uuid
|
return &sx.uuid
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}(),
|
}(),
|
||||||
Tunnel: tunnelLabel(c.rconn.Transport().Tunnel),
|
Tunnel: tunnelLabel(c.rconn.Transport().Tunnel),
|
||||||
|
BytesReceived: stats.BytesReceived,
|
||||||
|
BytesSent: stats.BytesSent,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -391,7 +391,11 @@ func (s *Server) findSessionByUUID(uuid uuid.UUID) (*gortsplib.ServerSession, *s
|
|||||||
return nil, nil
|
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]
|
return s.sessions[rsession]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,11 @@ func profileLabel(p headers.TransportProfile) string {
|
|||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type sessionParent interface {
|
||||||
|
logger.Writer
|
||||||
|
getConnByRConnUnsafe(rconn *gortsplib.ServerConn) *conn
|
||||||
|
}
|
||||||
|
|
||||||
type session struct {
|
type session struct {
|
||||||
isTLS bool
|
isTLS bool
|
||||||
transports conf.RTSPTransports
|
transports conf.RTSPTransports
|
||||||
@@ -44,7 +49,7 @@ type session struct {
|
|||||||
rserver *gortsplib.Server
|
rserver *gortsplib.Server
|
||||||
externalCmdPool *externalcmd.Pool
|
externalCmdPool *externalcmd.Pool
|
||||||
pathManager serverPathManager
|
pathManager serverPathManager
|
||||||
parent logger.Writer
|
parent sessionParent
|
||||||
|
|
||||||
uuid uuid.UUID
|
uuid uuid.UUID
|
||||||
created time.Time
|
created time.Time
|
||||||
@@ -447,6 +452,18 @@ func (s *session) apiItem() *defs.APIRTSPSession {
|
|||||||
v := profileLabel(transport.Profile)
|
v := profileLabel(transport.Profile)
|
||||||
return &v
|
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,
|
BytesReceived: stats.BytesReceived,
|
||||||
BytesSent: stats.BytesSent,
|
BytesSent: stats.BytesSent,
|
||||||
RTPPacketsReceived: stats.RTPPacketsReceived,
|
RTPPacketsReceived: stats.RTPPacketsReceived,
|
||||||
|
|||||||
Reference in New Issue
Block a user