revid: created multiSender retry field and setting based on outputs

Added a retry field for the multiSender which will be used to decide whether to retry sending or not. This is being set true if we have a http sender and no other senders.
This commit is contained in:
Saxon 2019-03-12 15:18:02 +10:30
parent 30ea5d74f6
commit 0ca75538d2
2 changed files with 9 additions and 4 deletions

View File

@ -188,9 +188,11 @@ func (r *Revid) reset(config Config) error {
// to mtsSenders if the output requires MPEGTS encoding, or flvSenders if the // to mtsSenders if the output requires MPEGTS encoding, or flvSenders if the
// output requires FLV encoding. // output requires FLV encoding.
var sender loadSender var sender loadSender
var retry bool
for _, out := range r.config.Outputs { for _, out := range r.config.Outputs {
switch out { switch out {
case Http: case Http:
retry = true
sender = newMtsSender(newMinimalHttpSender(r.ns, r.config.Logger.Log), nil) sender = newMtsSender(newMinimalHttpSender(r.ns, r.config.Logger.Log), nil)
case Rtp: case Rtp:
sender, err = newRtpSender(r.config.RtpAddress, r.config.Logger.Log, r.config.FrameRate) sender, err = newRtpSender(r.config.RtpAddress, r.config.Logger.Log, r.config.FrameRate)
@ -214,7 +216,10 @@ func (r *Revid) reset(config Config) error {
// encoder to revid's encoder slice, and give this encoder the mtsSenders // encoder to revid's encoder slice, and give this encoder the mtsSenders
// as a destination. // as a destination.
if len(mtsSenders) != 0 { if len(mtsSenders) != 0 {
ms := newMultiSender(r, mtsSenders) if len(mtsSenders) != 1 && len(flvSenders) != 0 {
retry = false
}
ms := newMultiSender(r, mtsSenders, retry)
e := mts.NewEncoder(ms, float64(r.config.FrameRate)) e := mts.NewEncoder(ms, float64(r.config.FrameRate))
r.encoder = append(r.encoder, e) r.encoder = append(r.encoder, e)
} }
@ -223,7 +228,7 @@ func (r *Revid) reset(config Config) error {
// encoder to revid's encoder slice, and give this encoder the flvSenders // encoder to revid's encoder slice, and give this encoder the flvSenders
// as a destination. // as a destination.
if len(flvSenders) != 0 { if len(flvSenders) != 0 {
ms := newMultiSender(r, flvSenders) ms := newMultiSender(r, flvSenders, false)
e, err := flv.NewEncoder(ms, true, true, int(r.config.FrameRate)) e, err := flv.NewEncoder(ms, true, true, int(r.config.FrameRate))
if err != nil { if err != nil {
return err return err

View File

@ -61,8 +61,8 @@ type multiSender struct {
} }
// newMultiSender returns a pointer to a new multiSender. // newMultiSender returns a pointer to a new multiSender.
func newMultiSender(owner *Revid, senders []loadSender) *multiSender { func newMultiSender(owner *Revid, senders []loadSender, retry bool) *multiSender {
return &multiSender{owner: owner, senders: senders} return &multiSender{owner: owner, senders: senders, retry: retry}
} }
// Write implements io.Writer. The written slice will be sent to each loadSender // Write implements io.Writer. The written slice will be sent to each loadSender