From 53382c5774705981030537b1d622e57fb11cd568 Mon Sep 17 00:00:00 2001 From: Saxon Date: Tue, 12 Mar 2019 15:39:51 +1030 Subject: [PATCH] revid: newMultiSender returns error if the passed active function is nil --- revid/revid.go | 7 +++++-- revid/senders.go | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/revid/revid.go b/revid/revid.go index 063a2aeb..43782a71 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -219,7 +219,10 @@ func (r *Revid) reset(config Config) error { if len(mtsSenders) != 1 && len(flvSenders) != 0 { retry = false } - ms := newMultiSender(mtsSenders, retry, r.IsRunning) + ms, _ := newMultiSender(mtsSenders, retry, r.IsRunning) + if err != nil { + return err + } e := mts.NewEncoder(ms, float64(r.config.FrameRate)) r.encoder = append(r.encoder, e) } @@ -228,7 +231,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(flvSenders, false, r.IsRunning) + 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 ee7e5b18..0dc40e9c 100644 --- a/revid/senders.go +++ b/revid/senders.go @@ -63,12 +63,16 @@ type multiSender struct { // 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{ +func newMultiSender(senders []loadSender, retry bool, active func() bool) (*multiSender, error) { + if active == nil { + return nil, errors.New("multi sender requires that active func is provided") + } + s := &multiSender{ senders: senders, retry: retry, active: active, } + return s, nil } // Write implements io.Writer. The written slice will be sent to each loadSender