client: open firewall before sending PLAY request (#821)

this prevents losing some initial packets.
This commit is contained in:
Alessandro Ros
2025-07-05 11:13:51 +02:00
committed by GitHub
parent 4f3337f56c
commit 2c2f99e1a3
2 changed files with 16 additions and 19 deletions

View File

@@ -1765,6 +1765,21 @@ func (c *Client) doPlay(ra *headers.Range) (*base.Response, error) {
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{
Method: base.Play,
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.lastRange = ra