mirror of
https://github.com/aler9/gortsplib
synced 2025-12-24 13:38:08 +08:00
server: fix timeout when recording with FFmpeg and UDP (bluenviron/mediamtx#5100) (#921)
This commit is contained in:
@@ -204,7 +204,13 @@ func (cr *serverConnReader) handleTunneling(in io.ReadWriter) (io.ReadWriter, er
|
||||
|
||||
func (cr *serverConnReader) readFuncStandard() error {
|
||||
for {
|
||||
cr.sc.nconn.SetReadDeadline(time.Now().Add(cr.sc.s.IdleTimeout))
|
||||
// when FFmpeg is recording with UDP, it does not send keepalives, no matter what.
|
||||
// disable read deadline.
|
||||
if cr.sc.session != nil && cr.sc.session.state == ServerSessionStateRecord {
|
||||
cr.sc.nconn.SetReadDeadline(time.Time{})
|
||||
} else {
|
||||
cr.sc.nconn.SetReadDeadline(time.Now().Add(cr.sc.s.IdleTimeout))
|
||||
}
|
||||
|
||||
what, err := cr.sc.conn.Read()
|
||||
if err != nil {
|
||||
|
||||
@@ -585,7 +585,7 @@ func TestServerRecord(t *testing.T) {
|
||||
onConnClose: func(ctx *ServerHandlerOnConnCloseCtx) {
|
||||
s := ctx.Conn.Stats()
|
||||
require.Greater(t, s.BytesSent, uint64(510))
|
||||
require.Less(t, s.BytesSent, uint64(1100))
|
||||
require.Less(t, s.BytesSent, uint64(1150))
|
||||
require.Greater(t, s.BytesReceived, uint64(1000))
|
||||
require.Less(t, s.BytesReceived, uint64(1800))
|
||||
|
||||
|
||||
@@ -884,19 +884,7 @@ func (ss *ServerSession) runInner() error {
|
||||
|
||||
res.Header["Session"] = headers.Session{
|
||||
Session: ss.secretID,
|
||||
Timeout: func() *uint {
|
||||
// timeout controls the sending of RTCP keepalives.
|
||||
// these are needed only when the client is playing
|
||||
// and transport is UDP or UDP-multicast.
|
||||
if (ss.state == ServerSessionStatePrePlay ||
|
||||
ss.state == ServerSessionStatePlay) &&
|
||||
(ss.setuppedTransport.Protocol == ProtocolUDP ||
|
||||
ss.setuppedTransport.Protocol == ProtocolUDPMulticast) {
|
||||
v := uint(ss.s.IdleTimeout / time.Second)
|
||||
return &v
|
||||
}
|
||||
return nil
|
||||
}(),
|
||||
Timeout: ptrOf(uint(ss.s.IdleTimeout / time.Second)),
|
||||
}.Marshal()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user