merge serverWriter and clientWriter

This commit is contained in:
aler9
2022-12-11 22:54:16 +01:00
parent a1396206b5
commit 256877086b
11 changed files with 80 additions and 147 deletions

View File

@@ -13,7 +13,6 @@ import (
"net"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
@@ -243,8 +242,7 @@ type Client struct {
tcpLastFrameTime *int64
keepaliveTimer *time.Timer
closeError error
writer clientWriter
writeMutex sync.RWMutex
writer writer
// connCloser channels
connCloserTerminate chan struct{}
@@ -649,14 +647,21 @@ func (c *Client) playRecordStart() {
}
}
if c.state == clientStatePlay {
// when reading, buffer 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.
c.writer.allocateBuffer(8)
} else {
c.writer.allocateBuffer(c.WriteBufferCount)
}
c.writer.start()
for _, cm := range c.medias {
cm.start()
}
c.writeMutex.Lock()
c.writer.start(c)
c.writeMutex.Unlock()
// for some reason, SetReadDeadline() must always be called in the same
// goroutine, otherwise Read() freezes.
// therefore, we disable the deadline and perform a check with a ticker.
@@ -721,9 +726,7 @@ func (c *Client) playRecordStop(isClosing bool) {
c.checkStreamTimer = emptyTimer()
c.keepaliveTimer = emptyTimer()
c.writeMutex.Lock()
c.writer.stop()
c.writeMutex.Unlock()
for _, cm := range c.medias {
cm.stop()