mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 23:26:54 +08:00
server: add methods SetuppedStream, SetuppedPath, SetuppedQuery (#444)
This commit is contained in:
@@ -78,7 +78,7 @@ func absoluteControlAttribute(md *psdp.MediaDescription) string {
|
|||||||
func doDescribe(t *testing.T, conn *conn.Conn) *sdp.SessionDescription {
|
func doDescribe(t *testing.T, conn *conn.Conn) *sdp.SessionDescription {
|
||||||
res, err := writeReqReadRes(conn, base.Request{
|
res, err := writeReqReadRes(conn, base.Request{
|
||||||
Method: base.Describe,
|
Method: base.Describe,
|
||||||
URL: mustParseURL("rtsp://localhost:8554/teststream"),
|
URL: mustParseURL("rtsp://localhost:8554/teststream?param=value"),
|
||||||
Header: base.Header{
|
Header: base.Header{
|
||||||
"CSeq": base.HeaderValue{"1"},
|
"CSeq": base.HeaderValue{"1"},
|
||||||
},
|
},
|
||||||
@@ -553,6 +553,23 @@ func TestServerPlay(t *testing.T) {
|
|||||||
}, stream, nil
|
}, stream, nil
|
||||||
},
|
},
|
||||||
onPlay: func(ctx *ServerHandlerOnPlayCtx) (*base.Response, error) {
|
onPlay: func(ctx *ServerHandlerOnPlayCtx) (*base.Response, error) {
|
||||||
|
switch transport {
|
||||||
|
case "udp":
|
||||||
|
v := TransportUDP
|
||||||
|
require.Equal(t, &v, ctx.Session.SetuppedTransport())
|
||||||
|
|
||||||
|
case "tcp", "tls":
|
||||||
|
v := TransportTCP
|
||||||
|
require.Equal(t, &v, ctx.Session.SetuppedTransport())
|
||||||
|
|
||||||
|
case "multicast":
|
||||||
|
v := TransportUDPMulticast
|
||||||
|
require.Equal(t, &v, ctx.Session.SetuppedTransport())
|
||||||
|
}
|
||||||
|
|
||||||
|
require.Equal(t, "param=value", ctx.Session.SetuppedQuery())
|
||||||
|
require.Equal(t, stream.Description().Medias, ctx.Session.SetuppedMedias())
|
||||||
|
|
||||||
// send RTCP packets directly to the session.
|
// send RTCP packets directly to the session.
|
||||||
// these are sent after the response, only if onPlay returns StatusOK.
|
// these are sent after the response, only if onPlay returns StatusOK.
|
||||||
if transport != "multicast" {
|
if transport != "multicast" {
|
||||||
|
@@ -519,6 +519,19 @@ func TestServerRecord(t *testing.T) {
|
|||||||
}, nil, nil
|
}, nil, nil
|
||||||
},
|
},
|
||||||
onRecord: func(ctx *ServerHandlerOnRecordCtx) (*base.Response, error) {
|
onRecord: func(ctx *ServerHandlerOnRecordCtx) (*base.Response, error) {
|
||||||
|
switch transport {
|
||||||
|
case "udp":
|
||||||
|
v := TransportUDP
|
||||||
|
require.Equal(t, &v, ctx.Session.SetuppedTransport())
|
||||||
|
|
||||||
|
case "tcp", "tls":
|
||||||
|
v := TransportTCP
|
||||||
|
require.Equal(t, &v, ctx.Session.SetuppedTransport())
|
||||||
|
}
|
||||||
|
|
||||||
|
require.Equal(t, "param=value", ctx.Session.SetuppedQuery())
|
||||||
|
require.Equal(t, ctx.Session.AnnouncedDescription().Medias, ctx.Session.SetuppedMedias())
|
||||||
|
|
||||||
// queue sending of RTCP packets.
|
// queue sending of RTCP packets.
|
||||||
// these are sent after the response, only if onRecord returns StatusOK.
|
// these are sent after the response, only if onRecord returns StatusOK.
|
||||||
err := ctx.Session.WritePacketRTCP(ctx.Session.AnnouncedDescription().Medias[0], &testRTCPPacket)
|
err := ctx.Session.WritePacketRTCP(ctx.Session.AnnouncedDescription().Medias[0], &testRTCPPacket)
|
||||||
@@ -602,7 +615,7 @@ func TestServerRecord(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
doAnnounce(t, conn, "rtsp://localhost:8554/teststream", medias)
|
doAnnounce(t, conn, "rtsp://localhost:8554/teststream?param=value", medias)
|
||||||
|
|
||||||
<-sessionOpened
|
<-sessionOpened
|
||||||
|
|
||||||
@@ -639,7 +652,7 @@ func TestServerRecord(t *testing.T) {
|
|||||||
inTH.InterleavedIDs = &[2]int{2 + i*2, 3 + i*2}
|
inTH.InterleavedIDs = &[2]int{2 + i*2, 3 + i*2}
|
||||||
}
|
}
|
||||||
|
|
||||||
res, th := doSetup(t, conn, "rtsp://localhost:8554/teststream/"+medias[i].Control, inTH, "")
|
res, th := doSetup(t, conn, "rtsp://localhost:8554/teststream?param=value/"+medias[i].Control, inTH, "")
|
||||||
|
|
||||||
session = readSession(t, res)
|
session = readSession(t, res)
|
||||||
|
|
||||||
|
@@ -194,7 +194,7 @@ type ServerSession struct {
|
|||||||
tcpCallbackByChannel map[int]readFunc
|
tcpCallbackByChannel map[int]readFunc
|
||||||
setuppedTransport *Transport
|
setuppedTransport *Transport
|
||||||
setuppedStream *ServerStream // read
|
setuppedStream *ServerStream // read
|
||||||
setuppedPath *string
|
setuppedPath string
|
||||||
setuppedQuery string
|
setuppedQuery string
|
||||||
lastRequestTime time.Time
|
lastRequestTime time.Time
|
||||||
tcpConn *ServerConn
|
tcpConn *ServerConn
|
||||||
@@ -266,6 +266,21 @@ func (ss *ServerSession) SetuppedTransport() *Transport {
|
|||||||
return ss.setuppedTransport
|
return ss.setuppedTransport
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetuppedStream returns the stream associated with the session.
|
||||||
|
func (ss *ServerSession) SetuppedStream() *ServerStream {
|
||||||
|
return ss.setuppedStream
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetuppedPath returns the path sent during SETUP or ANNOUNCE.
|
||||||
|
func (ss *ServerSession) SetuppedPath() string {
|
||||||
|
return ss.setuppedPath
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetuppedQuery returns the query sent during SETUP or ANNOUNCE.
|
||||||
|
func (ss *ServerSession) SetuppedQuery() string {
|
||||||
|
return ss.setuppedQuery
|
||||||
|
}
|
||||||
|
|
||||||
// AnnouncedDescription returns the announced stream description.
|
// AnnouncedDescription returns the announced stream description.
|
||||||
func (ss *ServerSession) AnnouncedDescription() *description.Session {
|
func (ss *ServerSession) AnnouncedDescription() *description.Session {
|
||||||
return ss.announcedDesc
|
return ss.announcedDesc
|
||||||
@@ -624,7 +639,7 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
ss.state = ServerSessionStatePreRecord
|
ss.state = ServerSessionStatePreRecord
|
||||||
ss.setuppedPath = &path
|
ss.setuppedPath = path
|
||||||
ss.setuppedQuery = query
|
ss.setuppedQuery = query
|
||||||
ss.announcedDesc = &desc
|
ss.announcedDesc = &desc
|
||||||
|
|
||||||
@@ -670,14 +685,14 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
|||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if ss.setuppedPath != nil && path != *ss.setuppedPath {
|
if ss.state == ServerSessionStatePrePlay && path != ss.setuppedPath {
|
||||||
return &base.Response{
|
return &base.Response{
|
||||||
StatusCode: base.StatusBadRequest,
|
StatusCode: base.StatusBadRequest,
|
||||||
}, liberrors.ErrServerMediasDifferentPaths{}
|
}, liberrors.ErrServerMediasDifferentPaths{}
|
||||||
}
|
}
|
||||||
|
|
||||||
default: // record
|
default: // record
|
||||||
path = *ss.setuppedPath
|
path = ss.setuppedPath
|
||||||
query = ss.setuppedQuery
|
query = ss.setuppedQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -799,7 +814,8 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
ss.state = ServerSessionStatePrePlay
|
ss.state = ServerSessionStatePrePlay
|
||||||
ss.setuppedPath = &path
|
ss.setuppedPath = path
|
||||||
|
ss.setuppedQuery = query
|
||||||
ss.setuppedStream = stream
|
ss.setuppedStream = stream
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -886,10 +902,10 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
|||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if ss.State() == ServerSessionStatePrePlay && path != *ss.setuppedPath {
|
if ss.State() == ServerSessionStatePrePlay && path != ss.setuppedPath {
|
||||||
return &base.Response{
|
return &base.Response{
|
||||||
StatusCode: base.StatusBadRequest,
|
StatusCode: base.StatusBadRequest,
|
||||||
}, liberrors.ErrServerPathHasChanged{Prev: *ss.setuppedPath, Cur: path}
|
}, liberrors.ErrServerPathHasChanged{Prev: ss.setuppedPath, Cur: path}
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate writeBuffer before calling OnPlay().
|
// allocate writeBuffer before calling OnPlay().
|
||||||
@@ -950,7 +966,7 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
|||||||
ss.s.timeNow(),
|
ss.s.timeNow(),
|
||||||
ss.setuppedMediasOrdered,
|
ss.setuppedMediasOrdered,
|
||||||
ss.setuppedStream,
|
ss.setuppedStream,
|
||||||
*ss.setuppedPath,
|
ss.setuppedPath,
|
||||||
req.URL)
|
req.URL)
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
@@ -978,10 +994,10 @@ func (ss *ServerSession) handleRequestInner(sc *ServerConn, req *base.Request) (
|
|||||||
}, liberrors.ErrServerNotAllAnnouncedMediasSetup{}
|
}, liberrors.ErrServerNotAllAnnouncedMediasSetup{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if path != *ss.setuppedPath {
|
if path != ss.setuppedPath {
|
||||||
return &base.Response{
|
return &base.Response{
|
||||||
StatusCode: base.StatusBadRequest,
|
StatusCode: base.StatusBadRequest,
|
||||||
}, liberrors.ErrServerPathHasChanged{Prev: *ss.setuppedPath, Cur: path}
|
}, liberrors.ErrServerPathHasChanged{Prev: ss.setuppedPath, Cur: path}
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate writeBuffer before calling OnRecord().
|
// allocate writeBuffer before calling OnRecord().
|
||||||
|
Reference in New Issue
Block a user