mirror of
https://github.com/aler9/gortsplib
synced 2025-10-13 19:03:53 +08:00
add and use MultiBuffer
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user