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

This commit is contained in:
saxon 2019-01-01 16:03:04 +10:30
parent ebccfa1a54
commit ccd4c32ff6
2 changed files with 23 additions and 6 deletions

View File

@ -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
}
}

View File

@ -388,10 +388,18 @@ func (s *rtpSender) load(c *ring.Chunk) error {
return nil
}
func (s *rtpSender) send() error {
_, err := s.chunk.WriteTo(s.encoder)
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() {
s.chunk.Close()