From 53dc629fb172cd593a45e98c6ec590137f4b3c0b Mon Sep 17 00:00:00 2001 From: Saxon Date: Fri, 8 Nov 2019 10:06:51 +1030 Subject: [PATCH] revid: sender ring buffers flush only if write was successful --- revid/senders.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/revid/senders.go b/revid/senders.go index d1e1c18c..49399ef6 100644 --- a/revid/senders.go +++ b/revid/senders.go @@ -248,10 +248,12 @@ func (s *mtsSender) Write(d []byte) (int, error) { if time.Now().Sub(s.prev) >= s.clipDur && s.curPid == mts.PatPid && len(s.buf) > 0 { s.prev = time.Now() _, err := s.ring.Write(s.buf) + if err == nil { + s.ring.Flush() + } if err != nil { s.log(logger.Warning, pkg+"mtsSender: ringBuffer write error", "error", err.Error()) } - s.ring.Flush() s.buf = s.buf[:0] } return len(d), nil @@ -356,10 +358,12 @@ func (s *rtmpSender) output() { // Write implements io.Writer. func (s *rtmpSender) Write(d []byte) (int, error) { _, err := s.ring.Write(d) + if err == nil { + s.ring.Flush() + } if err != nil { s.log(logger.Warning, pkg+"rtmpSender: ring buffer write error", "error", err.Error()) } - s.ring.Flush() return len(d), nil }