revid: newMultiSender returns error if the passed active function is nil

This commit is contained in:
Saxon 2019-03-12 15:39:51 +10:30
parent e2a6d9f4bd
commit 53382c5774
2 changed files with 11 additions and 4 deletions

View File

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

View File

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