use a single TCP outgoing buffer each client / session (#665)

this saves memory.
This commit is contained in:
Alessandro Ros
2024-12-24 10:24:24 +01:00
committed by GitHub
parent 6750427282
commit 5506eb2f7f
8 changed files with 78 additions and 87 deletions

View File

@@ -339,6 +339,8 @@ type Client struct {
reader *clientReader
timeDecoder *rtptime.GlobalDecoder2
mustClose bool
tcpFrame *base.InterleavedFrame
tcpBuffer []byte
// in
chOptions chan optionsReq
@@ -856,6 +858,11 @@ func (c *Client) startTransportRoutines() {
cm.start()
}
if *c.effectiveTransport == TransportTCP {
c.tcpFrame = &base.InterleavedFrame{}
c.tcpBuffer = make([]byte, c.MaxPacketSize+4)
}
if c.state == clientStatePlay && c.stdChannelSetupped {
c.keepaliveTimer = time.NewTimer(c.keepalivePeriod)
@@ -1902,8 +1909,18 @@ func (c *Client) WritePacketRTPWithNTP(medi *description.Media, pkt *rtp.Packet,
}
cm := c.medias[medi]
ct := cm.formats[pkt.PayloadType]
return ct.writePacketRTP(byts, pkt, ntp)
cf := cm.formats[pkt.PayloadType]
cf.rtcpSender.ProcessPacket(pkt, ntp, cf.format.PTSEqualsDTS(pkt))
ok := c.writer.push(func() error {
return cm.writePacketRTPInQueue(byts)
})
if !ok {
return liberrors.ErrClientWriteQueueFull{}
}
return nil
}
// WritePacketRTCP writes a RTCP packet to the server.
@@ -1920,7 +1937,15 @@ func (c *Client) WritePacketRTCP(medi *description.Media, pkt rtcp.Packet) error
}
cm := c.medias[medi]
return cm.writePacketRTCP(byts)
ok := c.writer.push(func() error {
return cm.writePacketRTCPInQueue(byts)
})
if !ok {
return liberrors.ErrClientWriteQueueFull{}
}
return nil
}
// PacketPTS returns the PTS of an incoming RTP packet.