api: add 'query' field to RTMP, RTSP, SRT and WebRTC clients (#2689) (#2844)

This commit is contained in:
Alessandro Ros 2023-12-26 13:59:53 +01:00 committed by GitHub
parent 1341421412
commit 598fadc9fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 51 additions and 22 deletions

View File

@ -487,6 +487,8 @@ components:
enum: [idle, read, publish]
path:
type: string
query:
type: string
bytesReceived:
type: integer
format: int64
@ -544,6 +546,8 @@ components:
enum: [idle, read, publish]
path:
type: string
query:
type: string
transport:
type: string
nullable: true
@ -578,6 +582,8 @@ components:
enum: [idle, read, publish]
path:
type: string
query:
type: string
bytesReceived:
type: integer
format: int64
@ -615,6 +621,8 @@ components:
enum: [read, publish]
path:
type: string
query:
type: string
bytesReceived:
type: integer
format: int64

View File

@ -688,7 +688,7 @@ func TestAPIProtocolList(t *testing.T) {
case "rtsp conns", "rtsp sessions":
source := gortsplib.Client{}
err := source.StartRecording("rtsp://localhost:8554/mypath",
err := source.StartRecording("rtsp://localhost:8554/mypath?key=val",
&description.Session{Medias: []*description.Media{medi}})
require.NoError(t, err)
defer source.Close()
@ -698,7 +698,7 @@ func TestAPIProtocolList(t *testing.T) {
TLSConfig: &tls.Config{InsecureSkipVerify: true},
}
err := source.StartRecording("rtsps://localhost:8322/mypath",
err := source.StartRecording("rtsps://localhost:8322/mypath?key=val",
&description.Session{Medias: []*description.Media{medi}})
require.NoError(t, err)
defer source.Close()
@ -711,7 +711,7 @@ func TestAPIProtocolList(t *testing.T) {
port = "1936"
}
u, err := url.Parse("rtmp://127.0.0.1:" + port + "/mypath")
u, err := url.Parse("rtmp://127.0.0.1:" + port + "/mypath?key=val")
require.NoError(t, err)
nconn, err := func() (net.Conn, error) {
@ -795,7 +795,7 @@ func TestAPIProtocolList(t *testing.T) {
require.NoError(t, err)
defer source.Close()
u, err := url.Parse("http://localhost:8889/mypath/whep")
u, err := url.Parse("http://localhost:8889/mypath/whep?key=val")
require.NoError(t, err)
go func() {
@ -826,7 +826,7 @@ func TestAPIProtocolList(t *testing.T) {
case "srt":
conf := srt.DefaultConfig()
conf.StreamId = "publish:mypath"
conf.StreamId = "publish:mypath:::key=val"
conn, err := srt.Dial("srt", "localhost:8890", conf)
require.NoError(t, err)
@ -878,6 +878,7 @@ func TestAPIProtocolList(t *testing.T) {
type item struct {
State string `json:"state"`
Path string `json:"path"`
Query string `json:"query"`
}
var out struct {
@ -890,6 +891,7 @@ func TestAPIProtocolList(t *testing.T) {
require.Equal(t, item{
State: "publish",
Path: "mypath",
Query: "key=val",
}, out.Items[0])
}
@ -914,6 +916,7 @@ func TestAPIProtocolList(t *testing.T) {
PeerConnectionEstablished bool `json:"peerConnectionEstablished"`
State string `json:"state"`
Path string `json:"path"`
Query string `json:"query"`
}
var out struct {
@ -926,6 +929,7 @@ func TestAPIProtocolList(t *testing.T) {
PeerConnectionEstablished: true,
State: "read",
Path: "mypath",
Query: "key=val",
}, out.Items[0])
}
})

View File

@ -61,22 +61,6 @@ type APIHLSMuxerList struct {
Items []*APIHLSMuxer `json:"items"`
}
// 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"`
}
// APIRTSPConnsList is a list of RTSP connections.
type APIRTSPConnsList struct {
ItemCount int `json:"itemCount"`
PageCount int `json:"pageCount"`
Items []*APIRTSPConn `json:"items"`
}
// APIRTMPConnState is the state of a RTMP connection.
type APIRTMPConnState string
@ -94,6 +78,7 @@ type APIRTMPConn struct {
RemoteAddr string `json:"remoteAddr"`
State APIRTMPConnState `json:"state"`
Path string `json:"path"`
Query string `json:"query"`
BytesReceived uint64 `json:"bytesReceived"`
BytesSent uint64 `json:"bytesSent"`
}
@ -105,6 +90,22 @@ type APIRTMPConnList struct {
Items []*APIRTMPConn `json:"items"`
}
// 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"`
}
// APIRTSPConnsList is a list of RTSP connections.
type APIRTSPConnsList struct {
ItemCount int `json:"itemCount"`
PageCount int `json:"pageCount"`
Items []*APIRTSPConn `json:"items"`
}
// APIRTSPSessionState is the state of a RTSP session.
type APIRTSPSessionState string
@ -122,6 +123,7 @@ type APIRTSPSession struct {
RemoteAddr string `json:"remoteAddr"`
State APIRTSPSessionState `json:"state"`
Path string `json:"path"`
Query string `json:"query"`
Transport *string `json:"transport"`
BytesReceived uint64 `json:"bytesReceived"`
BytesSent uint64 `json:"bytesSent"`
@ -151,6 +153,7 @@ type APISRTConn struct {
RemoteAddr string `json:"remoteAddr"`
State APISRTConnState `json:"state"`
Path string `json:"path"`
Query string `json:"query"`
BytesReceived uint64 `json:"bytesReceived"`
BytesSent uint64 `json:"bytesSent"`
}
@ -181,6 +184,7 @@ type APIWebRTCSession struct {
RemoteCandidate string `json:"remoteCandidate"`
State APIWebRTCSessionState `json:"state"`
Path string `json:"path"`
Query string `json:"query"`
BytesReceived uint64 `json:"bytesReceived"`
BytesSent uint64 `json:"bytesSent"`
}

View File

@ -71,6 +71,7 @@ type conn struct {
rconn *rtmp.Conn
state connState
pathName string
query string
}
func (c *conn) initialize() {
@ -191,6 +192,7 @@ func (c *conn) runRead(conn *rtmp.Conn, u *url.URL) error {
c.mutex.Lock()
c.state = connStateRead
c.pathName = pathName
c.query = rawQuery
c.mutex.Unlock()
writer := asyncwriter.New(c.writeQueueSize, c)
@ -421,6 +423,7 @@ func (c *conn) runPublish(conn *rtmp.Conn, u *url.URL) error {
c.mutex.Lock()
c.state = connStatePublish
c.pathName = pathName
c.query = rawQuery
c.mutex.Unlock()
r, err := rtmp.NewReader(conn)
@ -594,6 +597,7 @@ func (c *conn) apiItem() *defs.APIRTMPConn {
}
}(),
Path: c.pathName,
Query: c.query,
BytesReceived: bytesReceived,
BytesSent: bytesSent,
}

View File

@ -40,6 +40,7 @@ type session struct {
state gortsplib.ServerSessionState
transport *gortsplib.Transport
pathName string
query string
decodeErrLogger logger.Writer
writeErrLogger logger.Writer
}
@ -140,6 +141,7 @@ func (s *session) onAnnounce(c *conn, ctx *gortsplib.ServerHandlerOnAnnounceCtx)
s.mutex.Lock()
s.state = gortsplib.ServerSessionStatePreRecord
s.pathName = ctx.Path
s.query = ctx.Query
s.mutex.Unlock()
return &base.Response{
@ -232,6 +234,7 @@ func (s *session) onSetup(c *conn, ctx *gortsplib.ServerHandlerOnSetupCtx,
s.mutex.Lock()
s.state = gortsplib.ServerSessionStatePrePlay
s.pathName = ctx.Path
s.query = ctx.Query
s.mutex.Unlock()
var stream *gortsplib.ServerStream
@ -400,7 +403,8 @@ func (s *session) apiItem() *defs.APIRTSPSession {
}
return defs.APIRTSPSessionStateIdle
}(),
Path: s.pathName,
Path: s.pathName,
Query: s.query,
Transport: func() *string {
if s.transport == nil {
return nil

View File

@ -72,6 +72,7 @@ type conn struct {
mutex sync.RWMutex
state connState
pathName string
query string
sconn srt.Conn
chNew chan srtNewConnReq
@ -218,6 +219,7 @@ func (c *conn) runPublish(req srtNewConnReq, pathName string, user string, pass
c.mutex.Lock()
c.state = connStatePublish
c.pathName = pathName
c.query = query
c.sconn = sconn
c.mutex.Unlock()
@ -317,6 +319,7 @@ func (c *conn) runRead(req srtNewConnReq, pathName string, user string, pass str
c.mutex.Lock()
c.state = connStateRead
c.pathName = pathName
c.query = query
c.sconn = sconn
c.mutex.Unlock()
@ -434,6 +437,7 @@ func (c *conn) apiItem() *defs.APISRTConn {
}
}(),
Path: c.pathName,
Query: c.query,
BytesReceived: bytesReceived,
BytesSent: bytesSent,
}

View File

@ -708,6 +708,7 @@ func (s *session) apiItem() *defs.APIWebRTCSession {
return defs.APIWebRTCSessionStateRead
}(),
Path: s.req.pathName,
Query: s.req.query,
BytesReceived: bytesReceived,
BytesSent: bytesSent,
}