revid/senders.go: remember previously adjusted RB element sizes

This commit is contained in:
Saxon Nelson-Milton 2020-04-10 17:32:44 +01:00
parent 2bfb4d6b95
commit 4d5a85b853
1 changed files with 13 additions and 2 deletions

View File

@ -57,6 +57,11 @@ const (
maxBuffLen = 50000000 maxBuffLen = 50000000
) )
var (
adjustedRTMPRBElementSize int
adjustedMTSRBElementSize int
)
// httpSender provides an implemntation of io.Writer to perform sends to a http // httpSender provides an implemntation of io.Writer to perform sends to a http
// destination. // destination.
type httpSender struct { type httpSender struct {
@ -270,7 +275,10 @@ func (s *mtsSender) Write(d []byte) (int, error) {
if err != nil { if err != nil {
s.log(logger.Warning, "ringBuffer write error", "error", err.Error(), "n", n, "size", len(s.buf)) s.log(logger.Warning, "ringBuffer write error", "error", err.Error(), "n", n, "size", len(s.buf))
if err == ring.ErrTooLong { if err == ring.ErrTooLong {
s.ring = ring.NewBuffer(maxBuffLen/len(d), len(d), 5*time.Second) adjustedMTSRBElementSize = len(d)*2
numElements := maxBuffLen/adjustedMTSRBElementSize
s.ring = ring.NewBuffer(maxBuffLen/adjustedMTSRBElementSize, adjustedMTSRBElementSize, 5*time.Second)
s.log(logger.Info,"adjusted MTS ring buffer element size","new size",adjustedMTSRBElementSize,"num elements",numElements,"size(MB)",numElements*adjustedMTSRBElementSize)
} }
} }
s.buf = s.buf[:0] s.buf = s.buf[:0]
@ -389,7 +397,10 @@ func (s *rtmpSender) Write(d []byte) (int, error) {
} else { } else {
s.log(logger.Warning, "ring buffer write error", "error", err.Error()) s.log(logger.Warning, "ring buffer write error", "error", err.Error())
if err == ring.ErrTooLong { if err == ring.ErrTooLong {
s.ring = ring.NewBuffer(maxBuffLen/len(d), len(d), 5*time.Second) adjustedRTMPRBElementSize = len(d)*2
numElements := maxBuffLen/adjustedRTMPRBElementSize
s.ring = ring.NewBuffer(numElements, adjustedRTMPRBElementSize, 5*time.Second)
s.log(logger.Info,"adjusted RTMP ring buffer element size","new size",adjustedRTMPRBElementSize,"num elements",numElements,"size(MB)",numElements*adjustedRTMPRBElementSize)
} }
} }
s.report(len(d)) s.report(len(d))