diff --git a/revid/senders.go b/revid/senders.go index ce7eaec6..831ebf17 100644 --- a/revid/senders.go +++ b/revid/senders.go @@ -290,27 +290,16 @@ func newRtmpSender(url string, timeout uint, retries int, log func(lvl int8, msg // Write implements io.Writer. func (s *rtmpSender) Write(d []byte) (int, error) { - return write(s, d) -} - -func (s *rtmpSender) load(d []byte) error { - s.data = d - return nil -} - -func (s *rtmpSender) send() error { if s.conn == nil { - return errors.New("no rtmp connection, cannot write") + return 0, errors.New("no rtmp connection, cannot write") } - _, err := s.conn.Write(s.data) + _, err := s.conn.Write(d) if err != nil { err = s.restart() } - return err + return len(d), err } -func (s *rtmpSender) release() {} - func (s *rtmpSender) restart() error { s.close() var err error @@ -342,11 +331,6 @@ type rtpSender struct { data []byte } -// Write implements io.Writer. -func (s *rtpSender) Write(d []byte) (int, error) { - return write(s, d) -} - func newRtpSender(addr string, log func(lvl int8, msg string, args ...interface{}), fps uint) (*rtpSender, error) { conn, err := net.Dial("udp", addr) if err != nil { @@ -359,30 +343,9 @@ func newRtpSender(addr string, log func(lvl int8, msg string, args ...interface{ return s, nil } -func (s *rtpSender) load(d []byte) error { - s.data = make([]byte, len(d)) - copy(s.data, d) - return nil +// Write implements io.Writer. +func (s *rtpSender) Write(d []byte) (int, error) { + return s.encoder.Write(s.data) } func (s *rtpSender) close() error { return nil } - -func (s *rtpSender) release() {} - -func (s *rtpSender) send() error { - _, err := s.encoder.Write(s.data) - return err -} - -// write wraps the load and send method for loadSenders. -func write(s loadSender, d []byte) (int, error) { - err := s.load(d) - if err != nil { - return 0, err - } - err = s.send() - if err != nil { - return len(d), err - } - return len(d), nil -} diff --git a/revid/senders_test.go b/revid/senders_test.go index f1eb7a4c..b990c336 100644 --- a/revid/senders_test.go +++ b/revid/senders_test.go @@ -265,25 +265,12 @@ func newDummyLoadSender(fail bool, retry bool) *dummyLoadSender { } func (s *dummyLoadSender) Write(d []byte) (int, error) { - return write(s, d) -} - -// load takes a byte slice and assigns it to the dummyLoadSenders data slice. -func (s *dummyLoadSender) load(d []byte) error { - s.data = d - return nil -} - -// send will append to dummyLoadSender's buf slice, only if failOnSend is false. -// If failOnSend is set to true, we expect that data sent won't be written to -// the buf simulating a failed send. -func (s *dummyLoadSender) send() error { if !s.getFailOnSend() { s.buf = append(s.buf, s.data) - return nil + return len(d), nil } s.failHandled = false - return errSendFailed + return 0, errSendFailed } func (s *dummyLoadSender) getFailOnSend() bool {