Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: add 'session' field to RTSPConn (#3974) #4074

Merged
merged 1 commit into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apidocs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@ components:
bytesSent:
type: integer
format: int64
session:
type: string
nullable: true

RTSPConnList:
type: object
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/alecthomas/kong v1.6.0
github.com/asticode/go-astits v1.13.0
github.com/bluenviron/gohlslib/v2 v2.1.0
github.com/bluenviron/gortsplib/v4 v4.12.1-0.20241225143216-4d3d6bc108f3
github.com/bluenviron/gortsplib/v4 v4.12.1-0.20241225145501-66410517c85f
github.com/bluenviron/mediacommon v1.13.2
github.com/datarhei/gosrt v0.8.0
github.com/fsnotify/fsnotify v1.8.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ github.com/benburkert/openpgp v0.0.0-20160410205803-c2471f86866c h1:8XZeJrs4+ZYh
github.com/benburkert/openpgp v0.0.0-20160410205803-c2471f86866c/go.mod h1:x1vxHcL/9AVzuk5HOloOEPrtJY0MaalYr78afXZ+pWI=
github.com/bluenviron/gohlslib/v2 v2.1.0 h1:I0KXXPjnt7QxsR39z97fKe/x1yj22e1NhSqZ5P6FbWE=
github.com/bluenviron/gohlslib/v2 v2.1.0/go.mod h1:irD+TAdUsb400Gp8v80LKPPC4YumiAieUSO6ICykeWo=
github.com/bluenviron/gortsplib/v4 v4.12.1-0.20241225143216-4d3d6bc108f3 h1:9JqYzxhzIQhPqe5MIq2leJNARrs7VPNgL2o3qwmlgqA=
github.com/bluenviron/gortsplib/v4 v4.12.1-0.20241225143216-4d3d6bc108f3/go.mod h1:MwFrCmflxvLTMjgtnPJ2H4SQSB/r9wX8nsR5YPtUs7M=
github.com/bluenviron/gortsplib/v4 v4.12.1-0.20241225145501-66410517c85f h1:x+W67M2KMNCumzQ8XpIFXbVE+quKD/xP5PiaJhKwqTY=
github.com/bluenviron/gortsplib/v4 v4.12.1-0.20241225145501-66410517c85f/go.mod h1:MwFrCmflxvLTMjgtnPJ2H4SQSB/r9wX8nsR5YPtUs7M=
github.com/bluenviron/mediacommon v1.13.2 h1:Ssq+59ZtPm5f9iAVVugWNOyl89Vp0G758RMv033lkik=
github.com/bluenviron/mediacommon v1.13.2/go.mod h1:tffg+sPMErUIe7WMq7ZlYry/rPE6TyENWCrYT5JWcgs=
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
Expand Down
2 changes: 2 additions & 0 deletions internal/core/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ func TestAPIProtocolListGet(t *testing.T) {
"created": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["created"],
"id": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["id"],
"remoteAddr": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["remoteAddr"],
"session": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["session"],
},
},
}, out1)
Expand Down Expand Up @@ -644,6 +645,7 @@ func TestAPIProtocolListGet(t *testing.T) {
"created": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["created"],
"id": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["id"],
"remoteAddr": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["remoteAddr"],
"session": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["session"],
},
},
}, out1)
Expand Down
11 changes: 6 additions & 5 deletions internal/defs/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,12 @@ type APIRTMPConnList struct {

// APIRTSPConn is a RTSP connection.
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"`
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"`
}

// APIRTSPConnsList is a list of RTSP connections.
Expand Down
14 changes: 13 additions & 1 deletion internal/servers/rtsp/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
rtspAuthRealm = "IPCAM"
)

type connParent interface {
logger.Writer
findSessionByRSession(rsession *gortsplib.ServerSession) *session
}

type conn struct {
isTLS bool
rtspAddress string
Expand All @@ -35,7 +40,7 @@
pathManager serverPathManager
rconn *gortsplib.ServerConn
rserver *gortsplib.Server
parent *Server
parent connParent

uuid uuid.UUID
created time.Time
Expand Down Expand Up @@ -216,5 +221,12 @@
RemoteAddr: c.remoteAddr().String(),
BytesReceived: stats.BytesReceived,
BytesSent: stats.BytesSent,
Session: func() *uuid.UUID {
sx := c.parent.findSessionByRSession(c.rconn.Session())
if sx != nil {
return &sx.uuid
}
return nil

Check warning on line 229 in internal/servers/rtsp/conn.go

View check run for this annotation

Codecov / codecov/patch

internal/servers/rtsp/conn.go#L224-L229

Added lines #L224 - L229 were not covered by tests
}(),
}
}
7 changes: 7 additions & 0 deletions internal/servers/rtsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,13 @@
return nil, nil
}

func (s *Server) findSessionByRSession(rsession *gortsplib.ServerSession) *session {
s.mutex.RLock()
defer s.mutex.RUnlock()

return s.sessions[rsession]

Check warning on line 344 in internal/servers/rtsp/server.go

View check run for this annotation

Codecov / codecov/patch

internal/servers/rtsp/server.go#L340-L344

Added lines #L340 - L344 were not covered by tests
}

// APIConnsList is called by api and metrics.
func (s *Server) APIConnsList() (*defs.APIRTSPConnsList, error) {
select {
Expand Down
2 changes: 1 addition & 1 deletion internal/servers/rtsp/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type session struct {
rserver *gortsplib.Server
externalCmdPool *externalcmd.Pool
pathManager serverPathManager
parent *Server
parent logger.Writer

uuid uuid.UUID
created time.Time
Expand Down
Loading