revid: write timeouts for ringbuffer are just int to avoid overflow when converting duration to int on pi for the purpose of logging

This commit is contained in:
Saxon 2019-10-15 11:02:28 +10:30
parent ee1bea3f77
commit 8837dce389
2 changed files with 10 additions and 10 deletions

View File

@ -125,12 +125,12 @@ const (
// MTS ring buffer defaults. // MTS ring buffer defaults.
defaultMTSRBSize = 1000 defaultMTSRBSize = 1000
defaultMTSRBElementSize = 100000 defaultMTSRBElementSize = 100000
defaultMTSRBWriteTimeout = 5 * time.Second defaultMTSRBWriteTimeout = 5
// RTMP ring buffer defaults. // RTMP ring buffer defaults.
defaultRTMPRBSize = 1000 defaultRTMPRBSize = 1000
defaultRTMPRBElementSize = 300000 defaultRTMPRBElementSize = 300000
defaultRTMPRBWriteTimeout = 5 * time.Second defaultRTMPRBWriteTimeout = 5
) )
// Config provides parameters relevant to a revid instance. A new config must // Config provides parameters relevant to a revid instance. A new config must
@ -258,12 +258,12 @@ type Config struct {
// RTMP ring buffer parameters. // RTMP ring buffer parameters.
RTMPRBSize int // The number of elements in the RTMP sender ringbuffer. RTMPRBSize int // The number of elements in the RTMP sender ringbuffer.
RTMPRBElementSize int // The element size in bytes of the RTMP sender RingBuffer. RTMPRBElementSize int // The element size in bytes of the RTMP sender RingBuffer.
RTMPRBWriteTimeout time.Duration RTMPRBWriteTimeout int // The ringbuffer write timeout in seconds.
// MTS ring buffer parameters. // MTS ring buffer parameters.
MTSRBSize int // The number of elements in the MTS sender ringbuffer. MTSRBSize int // The number of elements in the MTS sender ringbuffer.
MTSRBElementSize int // The element size in bytes of the MTS sender RingBuffer. MTSRBElementSize int // The element size in bytes of the MTS sender RingBuffer.
MTSRBWriteTimeout time.Duration MTSRBWriteTimeout int // The ringbuffer write timeout in seconds.
} }
// Validation errors. // Validation errors.
@ -462,7 +462,7 @@ func (c *Config) Validate() error {
} }
if c.RTMPRBWriteTimeout <= 0 { if c.RTMPRBWriteTimeout <= 0 {
c.Logger.Log(logger.Info, pkg+"RTMPRBWriteTimeout bad or unset, defaulting", "RTMPRBWriteTimeout", int(defaultRTMPRBWriteTimeout)) c.Logger.Log(logger.Info, pkg+"RTMPRBWriteTimeout bad or unset, defaulting", "RTMPRBWriteTimeout", defaultRTMPRBWriteTimeout)
c.RTMPRBWriteTimeout = defaultRTMPRBWriteTimeout c.RTMPRBWriteTimeout = defaultRTMPRBWriteTimeout
} }
@ -477,7 +477,7 @@ func (c *Config) Validate() error {
} }
if c.MTSRBWriteTimeout <= 0 { if c.MTSRBWriteTimeout <= 0 {
c.Logger.Log(logger.Info, pkg+"MTSRBWriteTimeout bad or unset, defaulting", "MTSRBWriteTimeout", int(defaultMTSRBWriteTimeout)) c.Logger.Log(logger.Info, pkg+"MTSRBWriteTimeout bad or unset, defaulting", "MTSRBWriteTimeout", defaultMTSRBWriteTimeout)
c.MTSRBWriteTimeout = defaultMTSRBWriteTimeout c.MTSRBWriteTimeout = defaultMTSRBWriteTimeout
} }

View File

@ -255,7 +255,7 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io.
w = newMtsSender( w = newMtsSender(
newHttpSender(r.ns, r.config.Logger.Log), newHttpSender(r.ns, r.config.Logger.Log),
r.config.Logger.Log, r.config.Logger.Log,
ring.NewBuffer(r.config.MTSRBSize, r.config.MTSRBElementSize, r.config.MTSRBWriteTimeout), ring.NewBuffer(r.config.MTSRBSize, r.config.MTSRBElementSize, time.Duration(r.config.MTSRBWriteTimeout)*time.Second),
r.config.ClipDuration, r.config.ClipDuration,
) )
mtsSenders = append(mtsSenders, w) mtsSenders = append(mtsSenders, w)
@ -276,7 +276,7 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io.
r.config.RTMPURL, r.config.RTMPURL,
rtmpConnectionTimeout, rtmpConnectionTimeout,
rtmpConnectionMaxTries, rtmpConnectionMaxTries,
ring.NewBuffer(r.config.RTMPRBSize, r.config.RTMPRBElementSize, r.config.RTMPRBWriteTimeout), ring.NewBuffer(r.config.RTMPRBSize, r.config.RTMPRBElementSize, time.Duration(r.config.RTMPRBWriteTimeout)*time.Second),
r.config.Logger.Log, r.config.Logger.Log,
) )
if err != nil { if err != nil {
@ -596,7 +596,7 @@ func (r *Revid) Update(vars map[string]string) error {
r.config.Logger.Log(logger.Warning, pkg+"invalid RTMPRBWriteTimeout var", "value", value) r.config.Logger.Log(logger.Warning, pkg+"invalid RTMPRBWriteTimeout var", "value", value)
break break
} }
r.config.RTMPRBWriteTimeout = time.Duration(v) * time.Second r.config.RTMPRBWriteTimeout = v
case "MTSRBSize": case "MTSRBSize":
v, err := strconv.Atoi(value) v, err := strconv.Atoi(value)
if err != nil || v < 0 { if err != nil || v < 0 {
@ -617,7 +617,7 @@ func (r *Revid) Update(vars map[string]string) error {
r.config.Logger.Log(logger.Warning, pkg+"invalid MTSRBWriteTimeout var", "value", value) r.config.Logger.Log(logger.Warning, pkg+"invalid MTSRBWriteTimeout var", "value", value)
break break
} }
r.config.MTSRBWriteTimeout = time.Duration(v) * time.Second r.config.MTSRBWriteTimeout = v
} }
} }
r.config.Logger.Log(logger.Info, pkg+"revid config changed", "config", fmt.Sprintf("%+v", r.config)) r.config.Logger.Log(logger.Info, pkg+"revid config changed", "config", fmt.Sprintf("%+v", r.config))