mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
client: open firewall before sending PLAY request (#821)
this prevents losing some initial packets.
This commit is contained in:
31
client.go
31
client.go
@@ -1765,6 +1765,21 @@ func (c *Client) doPlay(ra *headers.Range) (*base.Response, error) {
|
|||||||
header["Require"] = base.HeaderValue{"www.onvif.org/ver20/backchannel"}
|
header["Require"] = base.HeaderValue{"www.onvif.org/ver20/backchannel"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// when protocol is UDP,
|
||||||
|
// open the firewall by sending empty packets to the remote part.
|
||||||
|
// do this before sending the PLAY request.
|
||||||
|
if *c.effectiveTransport == TransportUDP {
|
||||||
|
for _, cm := range c.setuppedMedias {
|
||||||
|
if !cm.media.IsBackChannel {
|
||||||
|
byts, _ := (&rtp.Packet{Header: rtp.Header{Version: 2}}).Marshal()
|
||||||
|
cm.udpRTPListener.write(byts) //nolint:errcheck
|
||||||
|
|
||||||
|
byts, _ = (&rtcp.ReceiverReport{}).Marshal()
|
||||||
|
cm.udpRTCPListener.write(byts) //nolint:errcheck
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
res, err := c.do(&base.Request{
|
res, err := c.do(&base.Request{
|
||||||
Method: base.Play,
|
Method: base.Play,
|
||||||
URL: c.baseURL,
|
URL: c.baseURL,
|
||||||
@@ -1786,22 +1801,6 @@ func (c *Client) doPlay(ra *headers.Range) (*base.Response, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// open the firewall by sending empty packets to the counterpart.
|
|
||||||
// do this before sending the request.
|
|
||||||
// don't do this with multicast, otherwise the RTP packet is going to be broadcasted
|
|
||||||
// to all listeners, including us, messing up the stream.
|
|
||||||
if *c.effectiveTransport == TransportUDP {
|
|
||||||
for _, cm := range c.setuppedMedias {
|
|
||||||
if !cm.media.IsBackChannel {
|
|
||||||
byts, _ := (&rtp.Packet{Header: rtp.Header{Version: 2}}).Marshal()
|
|
||||||
cm.udpRTPListener.write(byts) //nolint:errcheck
|
|
||||||
|
|
||||||
byts, _ = (&rtcp.ReceiverReport{}).Marshal()
|
|
||||||
cm.udpRTCPListener.write(byts) //nolint:errcheck
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
c.startWriter()
|
c.startWriter()
|
||||||
|
|
||||||
c.lastRange = ra
|
c.lastRange = ra
|
||||||
|
@@ -72,14 +72,12 @@ func (sm *serverSessionMedia) start() {
|
|||||||
|
|
||||||
if *sm.ss.setuppedTransport == TransportUDP {
|
if *sm.ss.setuppedTransport == TransportUDP {
|
||||||
if sm.ss.state == ServerSessionStatePlay {
|
if sm.ss.state == ServerSessionStatePlay {
|
||||||
// firewall opening is performed with RTCP sender reports generated by ServerStream
|
|
||||||
|
|
||||||
if sm.media.IsBackChannel {
|
if sm.media.IsBackChannel {
|
||||||
sm.ss.s.udpRTPListener.addClient(sm.ss.author.ip(), sm.udpRTPReadPort, sm.readPacketRTPUDPPlay)
|
sm.ss.s.udpRTPListener.addClient(sm.ss.author.ip(), sm.udpRTPReadPort, sm.readPacketRTPUDPPlay)
|
||||||
}
|
}
|
||||||
sm.ss.s.udpRTCPListener.addClient(sm.ss.author.ip(), sm.udpRTCPReadPort, sm.readPacketRTCPUDPPlay)
|
sm.ss.s.udpRTCPListener.addClient(sm.ss.author.ip(), sm.udpRTCPReadPort, sm.readPacketRTCPUDPPlay)
|
||||||
} else {
|
} else {
|
||||||
// open the firewall by sending empty packets to the counterpart.
|
// open the firewall by sending empty packets to the remote part.
|
||||||
byts, _ := (&rtp.Packet{Header: rtp.Header{Version: 2}}).Marshal()
|
byts, _ := (&rtp.Packet{Header: rtp.Header{Version: 2}}).Marshal()
|
||||||
sm.ss.s.udpRTPListener.write(byts, sm.udpRTPWriteAddr) //nolint:errcheck
|
sm.ss.s.udpRTPListener.write(byts, sm.udpRTPWriteAddr) //nolint:errcheck
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user