From ccd4c32ff63d8c5420eff0982c9045e05f999a39 Mon Sep 17 00:00:00 2001 From: saxon Date: Tue, 1 Jan 2019 16:03:04 +1030 Subject: [PATCH] revid: revid now has it's own rtpSender seperate from the loadSender slice used for multiple outputs, therefore, we can now bypass the ringbuffer in this case with a check if the rtpSender exists in the packer write method --- revid/revid.go | 15 ++++++++++++--- revid/senders.go | 14 +++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/revid/revid.go b/revid/revid.go index 9e9efbd1..b4f7ac9d 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -118,6 +118,9 @@ type Revid struct { // destination is the target endpoint. destination []loadSender + // rtpSender + rtpSndr *rtpSender + // bitrate hold the last send bitrate calculation result. bitrate int @@ -147,6 +150,13 @@ func (p *packer) Write(frame []byte) (int, error) { return len(frame), nil } n, err := p.owner.buffer.Write(frame) + // If we have an rtp sender bypass and give straight to sender + if p.owner.rtpSndr != nil { + err = p.owner.rtpSndr.send(frame) + if err != nil { + p.owner.config.Logger.Log(smartlogger.Error, pkg+"rtp send failed with error", "error", err.Error()) + } + } if err != nil { if err == ring.ErrDropped { p.owner.config.Logger.Log(smartlogger.Warning, pkg+"dropped frame", "frame size", len(frame)) @@ -213,7 +223,7 @@ func (r *Revid) reset(config Config) error { } n := 1 - if r.config.Output2 != 0 { + if r.config.Output2 != 0 && r.config.Output2 != Rtp { n = 2 } r.destination = make([]loadSender, n) @@ -247,11 +257,10 @@ func (r *Revid) reset(config Config) error { } r.destination[outNo] = s case Rtp: - s, err := newRtpSender(r.config.RtpAddress, r.config.Logger.Log, r.config.FrameRate) + r.rtpSndr, err = newRtpSender(r.config.RtpAddress, r.config.Logger.Log, r.config.FrameRate) if err != nil { return err } - r.destination[outNo] = s } } diff --git a/revid/senders.go b/revid/senders.go index 6606350e..eab8af7c 100644 --- a/revid/senders.go +++ b/revid/senders.go @@ -388,9 +388,17 @@ func (s *rtpSender) load(c *ring.Chunk) error { return nil } -func (s *rtpSender) send() error { - _, err := s.chunk.WriteTo(s.encoder) - return err +func (s *rtpSender) send(d []byte) error { + var err error + if d != nil { + _, err = s.encoder.Write(d) + } else { + _, err = s.chunk.WriteTo(s.encoder) + } + if err != nil { + return err + } + return nil } func (s *rtpSender) release() {