revid: made logic regarding sender and encoder selection more readable, and added more commenting

This commit is contained in:
Saxon 2019-03-12 03:01:43 +10:30
parent 2588a125a9
commit 652a5ab173
1 changed files with 24 additions and 14 deletions

View File

@ -180,44 +180,54 @@ func (r *Revid) reset(config Config) error {
r.buffer = (*buffer)(ring.NewBuffer(ringBufferSize, ringBufferElementSize, writeTimeout)) r.buffer = (*buffer)(ring.NewBuffer(ringBufferSize, ringBufferElementSize, writeTimeout))
r.encoder = make([]stream.Encoder, 0, 2) // mtsSenders will hold the senders the require MPEGTS encoding, and flvSenders
// will hold senders that require FLV encoding.
// Find mpegts outputs and add them to a senders list var mtsSenders, flvSenders []loadSender
var mpegtsOutputs []loadSender
var flvOutputs []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 { for _, out := range r.config.Outputs {
switch out { switch out {
case Http: 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: case Rtp:
s, err := newRtpSender(r.config.RtpAddress, r.config.Logger.Log, r.config.FrameRate) s, err := newRtpSender(r.config.RtpAddress, r.config.Logger.Log, r.config.FrameRate)
if err != nil { if err != nil {
return err return err
} }
mtsSenders = append(mtsSenders, s)
mpegtsOutputs = append(mpegtsOutputs, s)
case File: case File:
s, err := newFileSender(r.config.OutputPath) s, err := newFileSender(r.config.OutputPath)
if err != nil { if err != nil {
return err return err
} }
mpegtsOutputs = append(mpegtsOutputs, s) mtsSenders = append(mtsSenders, s)
case Rtmp: case Rtmp:
s, err := newRtmpSender(r.config.RtmpUrl, rtmpConnectionTimeout, rtmpConnectionMaxTries, r.config.Logger.Log) s, err := newRtmpSender(r.config.RtmpUrl, rtmpConnectionTimeout, rtmpConnectionMaxTries, r.config.Logger.Log)
if err != nil { if err != nil {
return err return err
} }
flvOutputs = append(flvOutputs, s) flvSenders = append(flvSenders, s)
} }
} }
if len(mpegtsOutputs) != 0 { // If we have some senders that require MPEGTS encoding then add an MPEGTS
r.encoder = append(r.encoder, mts.NewEncoder(newMultiSender(r, mpegtsOutputs), float64(r.config.FrameRate))) // 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 { // If we have some senders that require FLV encoding then add an FLV
enc, err := flv.NewEncoder(newMultiSender(r, flvOutputs), true, true, int(r.config.FrameRate)) // 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 { if err != nil {
return err return err
} }