add and use MultiBuffer

This commit is contained in:
aler9
2020-09-20 13:48:08 +02:00
7 changed files with 107 additions and 56 deletions

View File

@@ -7,14 +7,17 @@ import (
"time"
)
// connClientUDPListener is a UDP listener created by SetupUDP() to receive UDP frames.
// UDPReadFunc is a function used to read UDP packets.
type UDPReadFunc func() ([]byte, error)
type connClientUDPListener struct {
c *ConnClient
pc net.PacketConn
trackId int
streamType StreamType
publisherIp net.IP
publisherPort int
c *ConnClient
pc net.PacketConn
trackId int
streamType StreamType
publisherIp net.IP
publisherPort int
udpFrameReadBuf *MultiBuffer
}
func newConnClientUDPListener(c *ConnClient, port int, trackId int, streamType StreamType) (*connClientUDPListener, error) {
@@ -24,10 +27,11 @@ func newConnClientUDPListener(c *ConnClient, port int, trackId int, streamType S
}
return &connClientUDPListener{
c: c,
pc: pc,
trackId: trackId,
streamType: streamType,
c: c,
pc: pc,
trackId: trackId,
streamType: streamType,
udpFrameReadBuf: NewMultiBuffer(c.conf.ReadBufferCount, 2048),
}, nil
}
@@ -35,11 +39,12 @@ func (l *connClientUDPListener) close() {
l.pc.Close()
}
func (l *connClientUDPListener) read(buf []byte) (int, error) {
func (l *connClientUDPListener) read() ([]byte, error) {
for {
buf := l.udpFrameReadBuf.Next()
n, addr, err := l.pc.ReadFrom(buf)
if err != nil {
return 0, err
return nil, err
}
uaddr := addr.(*net.UDPAddr)
@@ -52,6 +57,6 @@ func (l *connClientUDPListener) read(buf []byte) (int, error) {
l.c.rtcpReceivers[l.trackId].OnFrame(l.streamType, buf[:n])
return n, nil
return buf[:n], nil
}
}