diff --git a/revid/revid.go b/revid/revid.go index 38c4d7a3..0a82670d 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -180,44 +180,54 @@ func (r *Revid) reset(config Config) error { r.buffer = (*buffer)(ring.NewBuffer(ringBufferSize, ringBufferElementSize, writeTimeout)) - r.encoder = make([]stream.Encoder, 0, 2) - - // Find mpegts outputs and add them to a senders list - var mpegtsOutputs []loadSender - var flvOutputs []loadSender + // mtsSenders will hold the senders the require MPEGTS encoding, and flvSenders + // will hold senders that require FLV encoding. + var mtsSenders, flvSenders []loadSender + // We will go through our outputs and create the corresponding senders to add + // to mtsSenders if the output requires MPEGTS encoding, or flvSenders if the + // output requires FLV encoding. for _, out := range r.config.Outputs { switch out { case Http: - mpegtsOutputs = append(mpegtsOutputs, newMtsSender(newMinimalHttpSender(r.ns, r.config.Logger.Log), nil)) + s := newMtsSender(newMinimalHttpSender(r.ns, r.config.Logger.Log), nil) + mtsSenders = append(mtsSenders, s) case Rtp: s, err := newRtpSender(r.config.RtpAddress, r.config.Logger.Log, r.config.FrameRate) if err != nil { return err } - - mpegtsOutputs = append(mpegtsOutputs, s) + mtsSenders = append(mtsSenders, s) case File: s, err := newFileSender(r.config.OutputPath) if err != nil { return err } - mpegtsOutputs = append(mpegtsOutputs, s) + mtsSenders = append(mtsSenders, s) case Rtmp: s, err := newRtmpSender(r.config.RtmpUrl, rtmpConnectionTimeout, rtmpConnectionMaxTries, r.config.Logger.Log) if err != nil { return err } - flvOutputs = append(flvOutputs, s) + flvSenders = append(flvSenders, s) } } - if len(mpegtsOutputs) != 0 { - r.encoder = append(r.encoder, mts.NewEncoder(newMultiSender(r, mpegtsOutputs), float64(r.config.FrameRate))) + // If we have some senders that require MPEGTS encoding then add an MPEGTS + // encoder to revid's encoder slice, and give this encoder the mtsSenders + // as a destination. + if len(mtsSenders) != 0 { + ms := newMultiSender(r, mtsSenders) + e := mts.NewEncoder(ms, float64(r.config.FrameRate)) + r.encoder = append(r.encoder, e) } - if len(flvOutputs) != 0 { - enc, err := flv.NewEncoder(newMultiSender(r, flvOutputs), true, true, int(r.config.FrameRate)) + // If we have some senders that require FLV encoding then add an FLV + // encoder to revid's encoder slice, and give this encoder the flvSenders + // as a destination. + if len(flvSenders) != 0 { + ms := newMultiSender(r, flvSenders) + enc, err := flv.NewEncoder(ms, true, true, int(r.config.FrameRate)) if err != nil { return err }