Skip to content

Commit 558d1c3

Browse files
authored
api: add tunnel and profile to RTSP conns and sessions (#4985)
1 parent 890d427 commit 558d1c3

File tree

8 files changed

+54
-6
lines changed

8 files changed

+54
-6
lines changed

api/openapi.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,8 @@ components:
746746
session:
747747
type: string
748748
nullable: true
749+
tunnel:
750+
type: string
749751

750752
RTSPConnList:
751753
type: object
@@ -780,6 +782,9 @@ components:
780782
transport:
781783
type: string
782784
nullable: true
785+
profile:
786+
type: string
787+
nullable: true
783788
bytesReceived:
784789
type: integer
785790
format: int64

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/asticode/go-astits v1.13.0
1212
github.com/bluenviron/gohlslib/v2 v2.2.3
1313
github.com/bluenviron/gortmplib v0.0.0-20250916095243-72b6eaffb6a4
14-
github.com/bluenviron/gortsplib/v5 v5.0.0-20250916102828-1616c8c63415
14+
github.com/bluenviron/gortsplib/v5 v5.0.0-20250917174653-288b637b2301
1515
github.com/bluenviron/mediacommon/v2 v2.4.2
1616
github.com/datarhei/gosrt v0.9.0
1717
github.com/fsnotify/fsnotify v1.9.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ github.com/bluenviron/gohlslib/v2 v2.2.3 h1:1R/Jnh1kNR9UB09KAX6xjS2GcdKFRLuPd9wM
3535
github.com/bluenviron/gohlslib/v2 v2.2.3/go.mod h1:z4Viks+Mdgcl7OcOVJ1fgSmuUwCCJBxYJPLN49n7Vnw=
3636
github.com/bluenviron/gortmplib v0.0.0-20250916095243-72b6eaffb6a4 h1:ZDsCiFpmOoEy2eWcJBEhV8jb0sA9MxO/BzYmyrmm4hE=
3737
github.com/bluenviron/gortmplib v0.0.0-20250916095243-72b6eaffb6a4/go.mod h1:73VbUEJLkaixSRPRI/imEkVRkBccvR1GKrd6SUOdkrQ=
38-
github.com/bluenviron/gortsplib/v5 v5.0.0-20250916102828-1616c8c63415 h1:FErClZLSuXkZEPfIsAtD4DH6CKmQ6z7gtod1eHi4Efg=
39-
github.com/bluenviron/gortsplib/v5 v5.0.0-20250916102828-1616c8c63415/go.mod h1:un/XrjuE+yaglJw4Fd75OUXowPxioaHHqNOUC28byFA=
38+
github.com/bluenviron/gortsplib/v5 v5.0.0-20250917174653-288b637b2301 h1:dLEqNi4/uTN6lUM3djwWXhO0uqs9/TbRSg4AfDOJjH8=
39+
github.com/bluenviron/gortsplib/v5 v5.0.0-20250917174653-288b637b2301/go.mod h1:zp5tDI2tkjVMgyWiy+B2tRQowqYq/GwHjdAdYFQAxrU=
4040
github.com/bluenviron/mediacommon/v2 v2.4.2 h1:rggs61nTaqPcR1+RhlIE8/nDqfF5PO57QxpxBzSFfrw=
4141
github.com/bluenviron/mediacommon/v2 v2.4.2/go.mod h1:zy1fODPuS/kBd93ftgJS1Jhvjq7LFWfAo32KP7By9AE=
4242
github.com/bytedance/sonic v1.13.2 h1:8/H1FempDZqC4VqjptGo14QQlJx8VdZJegxs6wwfqpQ=

internal/core/api_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ func TestAPIProtocolListGet(t *testing.T) {
367367

368368
switch ca {
369369
case "rtsps conns", "rtsps sessions":
370-
conf += "rtspTransports: [tcp]\n" +
371-
"rtspEncryption: strict\n" +
370+
conf += "rtspEncryption: strict\n" +
372371
"rtspServerCert: " + serverCertFpath + "\n" +
373372
"rtspServerKey: " + serverKeyFpath + "\n"
374373

@@ -621,6 +620,7 @@ func TestAPIProtocolListGet(t *testing.T) {
621620
"id": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["id"],
622621
"remoteAddr": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["remoteAddr"],
623622
"session": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["session"],
623+
"tunnel": "none",
624624
},
625625
},
626626
}, out1)
@@ -640,6 +640,7 @@ func TestAPIProtocolListGet(t *testing.T) {
640640
"remoteAddr": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["remoteAddr"],
641641
"state": "publish",
642642
"transport": "UDP",
643+
"profile": "AVP",
643644
"rtpPacketsReceived": float64(0),
644645
"rtpPacketsSent": float64(0),
645646
"rtpPacketsLost": float64(0),
@@ -664,6 +665,7 @@ func TestAPIProtocolListGet(t *testing.T) {
664665
"id": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["id"],
665666
"remoteAddr": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["remoteAddr"],
666667
"session": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["session"],
668+
"tunnel": "none",
667669
},
668670
},
669671
}, out1)
@@ -682,7 +684,8 @@ func TestAPIProtocolListGet(t *testing.T) {
682684
"query": "key=val",
683685
"remoteAddr": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["remoteAddr"],
684686
"state": "publish",
685-
"transport": "TCP",
687+
"transport": "UDP",
688+
"profile": "SAVP",
686689
"rtpPacketsReceived": float64(0),
687690
"rtpPacketsSent": float64(0),
688691
"rtpPacketsLost": float64(0),

internal/defs/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ type APIRTSPConn struct {
140140
BytesReceived uint64 `json:"bytesReceived"`
141141
BytesSent uint64 `json:"bytesSent"`
142142
Session *uuid.UUID `json:"session"`
143+
Tunnel string `json:"tunnel"`
143144
}
144145

145146
// APIRTSPConnsList is a list of RTSP connections.
@@ -168,6 +169,7 @@ type APIRTSPSession struct {
168169
Path string `json:"path"`
169170
Query string `json:"query"`
170171
Transport *string `json:"transport"`
172+
Profile *string `json:"profile"`
171173
BytesReceived uint64 `json:"bytesReceived"`
172174
BytesSent uint64 `json:"bytesSent"`
173175
RTPPacketsReceived uint64 `json:"rtpPacketsReceived"`

internal/servers/rtsp/conn.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ func credentialsProvided(req *base.Request) bool {
4343
return err == nil && auth.Username != ""
4444
}
4545

46+
func tunnelLabel(t gortsplib.Tunnel) string {
47+
switch t {
48+
case gortsplib.TunnelHTTP:
49+
return "http"
50+
case gortsplib.TunnelWebSocket:
51+
return "websocket"
52+
case gortsplib.TunnelNone:
53+
return "none"
54+
}
55+
return "unknown"
56+
}
57+
4658
type connParent interface {
4759
logger.Writer
4860
findSessionByRSessionUnsafe(rsession *gortsplib.ServerSession) *session
@@ -229,5 +241,6 @@ func (c *conn) apiItem() *defs.APIRTSPConn {
229241
}
230242
return nil
231243
}(),
244+
Tunnel: tunnelLabel(c.rconn.Transport().Tunnel),
232245
}
233246
}

internal/servers/rtsp/session.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/bluenviron/gortsplib/v5"
1212
rtspauth "github.com/bluenviron/gortsplib/v5/pkg/auth"
1313
"github.com/bluenviron/gortsplib/v5/pkg/base"
14+
"github.com/bluenviron/gortsplib/v5/pkg/headers"
1415
"github.com/google/uuid"
1516

1617
"github.com/bluenviron/mediamtx/internal/auth"
@@ -24,6 +25,16 @@ import (
2425
"github.com/bluenviron/mediamtx/internal/stream"
2526
)
2627

28+
func profileLabel(p headers.TransportProfile) string {
29+
switch p {
30+
case headers.TransportProfileSAVP:
31+
return "SAVP"
32+
case headers.TransportProfileAVP:
33+
return "AVP"
34+
}
35+
return "unknown"
36+
}
37+
2738
type session struct {
2839
isTLS bool
2940
transports conf.RTSPTransports
@@ -408,6 +419,14 @@ func (s *session) apiItem() *defs.APIRTSPSession {
408419
v := transport.Protocol.String()
409420
return &v
410421
}(),
422+
Profile: func() *string {
423+
transport := s.rsession.Transport()
424+
if transport == nil {
425+
return nil
426+
}
427+
v := profileLabel(transport.Profile)
428+
return &v
429+
}(),
411430
BytesReceived: stats.BytesReceived,
412431
BytesSent: stats.BytesSent,
413432
RTPPacketsReceived: stats.RTPPacketsReceived,

internal/testapidocs/apidocs_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ func TestAPIDocs(t *testing.T) {
157157
case sf.Type == reflect.TypeOf(""):
158158
content2.Properties[js] = openAPIProperty{Type: "string"}
159159

160+
case sf.Type == reflect.PointerTo(reflect.TypeOf("")):
161+
content2.Properties[js] = openAPIProperty{
162+
Type: "string",
163+
Nullable: true,
164+
}
165+
160166
case sf.Type == reflect.TypeOf(int(0)):
161167
content2.Properties[js] = openAPIProperty{Type: "integer", Format: "int64"}
162168

0 commit comments

Comments
 (0)