diff --git a/revid/revid.go b/revid/revid.go index 1345e191..063a2aeb 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -219,7 +219,7 @@ func (r *Revid) reset(config Config) error { if len(mtsSenders) != 1 && len(flvSenders) != 0 { retry = false } - ms := newMultiSender(r, mtsSenders, retry) + ms := newMultiSender(mtsSenders, retry, r.IsRunning) e := mts.NewEncoder(ms, float64(r.config.FrameRate)) r.encoder = append(r.encoder, e) } @@ -228,7 +228,7 @@ func (r *Revid) reset(config Config) error { // encoder to revid's encoder slice, and give this encoder the flvSenders // as a destination. if len(flvSenders) != 0 { - ms := newMultiSender(r, flvSenders, false) + ms := newMultiSender(flvSenders, false, r.IsRunning) e, err := flv.NewEncoder(ms, true, true, int(r.config.FrameRate)) if err != nil { return err diff --git a/revid/senders.go b/revid/senders.go index 7c2ed9b1..ee7e5b18 100644 --- a/revid/senders.go +++ b/revid/senders.go @@ -55,27 +55,32 @@ type Sender interface { // multiSender allows for the sending through multi loadSenders using a single // call to multiSender.Write. type multiSender struct { - owner *Revid + active func() bool senders []loadSender retry bool } -// newMultiSender returns a pointer to a new multiSender. -func newMultiSender(owner *Revid, senders []loadSender, retry bool) *multiSender { - return &multiSender{owner: owner, senders: senders, retry: retry} +// newMultiSender returns a pointer to a new multiSender. active is a function +// to indicate the state of the multiSenders owner i.e. whether it is running +// or not. +func newMultiSender(senders []loadSender, retry bool, active func() bool) *multiSender { + return &multiSender{ + senders: senders, + retry: retry, + active: active, + } } // Write implements io.Writer. The written slice will be sent to each loadSender -// in multiSender.senders. If s.owner.config.SendRetry is true then on failed -// sends we notify the current sender to take any required actions and then try -// the send again. +// in multiSender.senders as long as s.active() is true. If a send fails, and +// s.retry is true, the send will be tried again. func (s *multiSender) Write(d []byte) (int, error) { for _, sender := range s.senders { sender.load(d) - for s.owner.IsRunning() { + for s.active() { err := sender.send() if err != nil { - s.handleFail(sender, err) + sender.handleSendFail(err) } if err == nil || !s.retry { break @@ -90,15 +95,6 @@ func (s *multiSender) Write(d []byte) (int, error) { return len(d), nil } -// handleFail calls the passed sender's handleSendFail method and then logs -// error if this was not successful. -func (s *multiSender) handleFail(sender loadSender, e error) { - err := sender.handleSendFail(e) - if err != nil { - s.owner.config.Logger.Log(logger.Warning, "could not currenty handle send fail", "error", err) - } -} - // minimalHttpSender implements Sender for posting HTTP to netreceiver or vidgrind. type minimalHttpSender struct { client *netsender.Sender