mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 07:06:58 +08:00
server: save RAM by releasing read buffers earlier
This commit is contained in:
@@ -17,7 +17,6 @@ import (
|
||||
"github.com/aler9/gortsplib/pkg/base"
|
||||
"github.com/aler9/gortsplib/pkg/headers"
|
||||
"github.com/aler9/gortsplib/pkg/liberrors"
|
||||
"github.com/aler9/gortsplib/pkg/multibuffer"
|
||||
"github.com/aler9/gortsplib/pkg/ringbuffer"
|
||||
"github.com/aler9/gortsplib/pkg/rtcpreceiver"
|
||||
)
|
||||
@@ -883,17 +882,12 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
|
||||
default: // TCP
|
||||
ss.tcpConn = sc
|
||||
ss.tcpConn.tcpSession = ss
|
||||
ss.tcpConn.tcpFrameEnabled = true
|
||||
ss.tcpConn.tcpFrameTimeout = false
|
||||
// when playing, tcpReadBuffer is only used to receive RTCP receiver reports,
|
||||
// that are much smaller than RTP packets and are sent at a fixed interval.
|
||||
// decrease RAM consumption by allocating less buffers.
|
||||
ss.tcpConn.tcpReadBuffer = multibuffer.New(8, uint64(sc.s.ReadBufferSize))
|
||||
ss.tcpConn.tcpProcessFunc = sc.tcpProcessPlay
|
||||
|
||||
ss.tcpConn.readFunc = ss.tcpConn.readFuncTCP
|
||||
err = errSwitchReadFunc
|
||||
|
||||
ss.writeBuffer = ringbuffer.New(uint64(ss.s.ReadBufferCount))
|
||||
// run writer after sending the response
|
||||
ss.tcpConn.tcpWriterRunning = false
|
||||
// runWriter() is called by conn after sending the response
|
||||
}
|
||||
|
||||
// add RTP-Info
|
||||
@@ -1016,18 +1010,15 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
|
||||
default: // TCP
|
||||
ss.tcpConn = sc
|
||||
ss.tcpConn.tcpSession = ss
|
||||
ss.tcpConn.tcpFrameEnabled = true
|
||||
ss.tcpConn.tcpFrameTimeout = true
|
||||
ss.tcpConn.tcpReadBuffer = multibuffer.New(uint64(sc.s.ReadBufferCount), uint64(sc.s.ReadBufferSize))
|
||||
ss.tcpConn.tcpRTPPacketBuffer = newRTPPacketMultiBuffer(uint64(sc.s.ReadBufferCount))
|
||||
ss.tcpConn.tcpProcessFunc = sc.tcpProcessRecord
|
||||
|
||||
ss.tcpConn.readFunc = ss.tcpConn.readFuncTCP
|
||||
err = errSwitchReadFunc
|
||||
|
||||
// when recording, writeBuffer is only used to send RTCP receiver reports,
|
||||
// that are much smaller than RTP packets and are sent at a fixed interval.
|
||||
// decrease RAM consumption by allocating less buffers.
|
||||
ss.writeBuffer = ringbuffer.New(uint64(8))
|
||||
// run writer after sending the response
|
||||
ss.tcpConn.tcpWriterRunning = false
|
||||
// runWriter() is called by conn after sending the response
|
||||
}
|
||||
|
||||
return res, err
|
||||
@@ -1089,9 +1080,10 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
|
||||
case TransportUDPMulticast:
|
||||
|
||||
default: // TCP
|
||||
ss.tcpConn.readFunc = ss.tcpConn.readFuncStandard
|
||||
err = errSwitchReadFunc
|
||||
|
||||
ss.tcpConn.tcpSession = nil
|
||||
ss.tcpConn.tcpFrameEnabled = false
|
||||
ss.tcpConn.tcpReadBuffer = nil
|
||||
ss.tcpConn = nil
|
||||
}
|
||||
|
||||
@@ -1108,10 +1100,10 @@ func (ss *ServerSession) handleRequest(sc *ServerConn, req *base.Request) (*base
|
||||
case TransportUDPMulticast:
|
||||
|
||||
default: // TCP
|
||||
ss.tcpConn.readFunc = ss.tcpConn.readFuncStandard
|
||||
err = errSwitchReadFunc
|
||||
|
||||
ss.tcpConn.tcpSession = nil
|
||||
ss.tcpConn.tcpFrameEnabled = false
|
||||
ss.tcpConn.tcpReadBuffer = nil
|
||||
ss.tcpConn.conn.SetReadDeadline(time.Time{})
|
||||
ss.tcpConn = nil
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user