server: allow to use WriteFrame() before providing the response of PLAY or RECORD

This commit is contained in:
aler9
2021-05-06 17:36:19 +02:00
parent df01c7049d
commit 3cd72fd830

View File

@@ -595,9 +595,15 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
path, query := base.PathSplitQuery(pathAndQuery) path, query := base.PathSplitQuery(pathAndQuery)
if ss.state != ServerSessionStatePlay && *ss.setupProtocol == StreamProtocolTCP { // allow to use WriteFrame() before response
if ss.state != ServerSessionStatePlay {
if *ss.setupProtocol == StreamProtocolUDP {
ss.udpIP = sc.ip()
ss.udpZone = sc.zone()
} else {
ss.linkedConn = sc ss.linkedConn = sc
} }
}
res, err := sc.s.Handler.(ServerHandlerOnPlay).OnPlay(&ServerHandlerOnPlayCtx{ res, err := sc.s.Handler.(ServerHandlerOnPlay).OnPlay(&ServerHandlerOnPlayCtx{
Session: ss, Session: ss,
@@ -607,14 +613,11 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
Query: query, Query: query,
}) })
if res.StatusCode == base.StatusOK {
if ss.state != ServerSessionStatePlay { if ss.state != ServerSessionStatePlay {
if res.StatusCode == base.StatusOK {
ss.state = ServerSessionStatePlay ss.state = ServerSessionStatePlay
if *ss.setupProtocol == StreamProtocolUDP { if *ss.setupProtocol == StreamProtocolUDP {
ss.udpIP = sc.ip()
ss.udpZone = sc.zone()
// readers can send RTCP frames, they cannot sent RTP frames // readers can send RTCP frames, they cannot sent RTP frames
for trackID, track := range ss.setuppedTracks { for trackID, track := range ss.setuppedTracks {
sc.s.udpRTCPListener.addClient(ss.udpIP, track.udpRTCPPort, ss, trackID, false) sc.s.udpRTCPListener.addClient(ss.udpIP, track.udpRTCPPort, ss, trackID, false)
@@ -625,7 +628,9 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
return res, liberrors.ErrServerTCPFramesEnable{} return res, liberrors.ErrServerTCPFramesEnable{}
} }
} else {
ss.udpIP = nil
ss.udpZone = ""
ss.linkedConn = nil ss.linkedConn = nil
} }
@@ -659,6 +664,14 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
path, query := base.PathSplitQuery(pathAndQuery) path, query := base.PathSplitQuery(pathAndQuery)
// allow to use WriteFrame() before response
if *ss.setupProtocol == StreamProtocolUDP {
ss.udpIP = sc.ip()
ss.udpZone = sc.zone()
} else {
ss.linkedConn = sc
}
res, err := ss.s.Handler.(ServerHandlerOnRecord).OnRecord(&ServerHandlerOnRecordCtx{ res, err := ss.s.Handler.(ServerHandlerOnRecord).OnRecord(&ServerHandlerOnRecordCtx{
Session: ss, Session: ss,
Conn: sc, Conn: sc,
@@ -671,9 +684,6 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
ss.state = ServerSessionStateRecord ss.state = ServerSessionStateRecord
if *ss.setupProtocol == StreamProtocolUDP { if *ss.setupProtocol == StreamProtocolUDP {
ss.udpIP = sc.ip()
ss.udpZone = sc.zone()
for trackID, track := range ss.setuppedTracks { for trackID, track := range ss.setuppedTracks {
ss.s.udpRTPListener.addClient(ss.udpIP, track.udpRTPPort, ss, trackID, true) ss.s.udpRTPListener.addClient(ss.udpIP, track.udpRTPPort, ss, trackID, true)
ss.s.udpRTCPListener.addClient(ss.udpIP, track.udpRTCPPort, ss, trackID, true) ss.s.udpRTCPListener.addClient(ss.udpIP, track.udpRTCPPort, ss, trackID, true)
@@ -688,10 +698,13 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
return res, err return res, err
} }
ss.linkedConn = sc
return res, liberrors.ErrServerTCPFramesEnable{} return res, liberrors.ErrServerTCPFramesEnable{}
} }
ss.udpIP = nil
ss.udpZone = ""
ss.linkedConn = nil
return res, err return res, err
case base.Pause: case base.Pause:
@@ -731,6 +744,8 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
switch ss.state { switch ss.state {
case ServerSessionStatePlay: case ServerSessionStatePlay:
ss.state = ServerSessionStatePrePlay ss.state = ServerSessionStatePrePlay
ss.udpIP = nil
ss.udpZone = ""
ss.linkedConn = nil ss.linkedConn = nil
if *ss.setupProtocol == StreamProtocolUDP { if *ss.setupProtocol == StreamProtocolUDP {
@@ -741,6 +756,8 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
case ServerSessionStateRecord: case ServerSessionStateRecord:
ss.state = ServerSessionStatePreRecord ss.state = ServerSessionStatePreRecord
ss.udpIP = nil
ss.udpZone = ""
ss.linkedConn = nil ss.linkedConn = nil
if *ss.setupProtocol == StreamProtocolUDP { if *ss.setupProtocol == StreamProtocolUDP {