revid: does not panic when not outputs are defined in a config.

This commit is contained in:
Saxon 2019-05-05 22:50:59 +09:30
parent 7e4cc82e35
commit 8f74cd4ced
2 changed files with 30 additions and 30 deletions

View File

@ -211,6 +211,12 @@ func (c *Config) Validate(r *Revid) error {
return errors.New("bad input codec defined in config") return errors.New("bad input codec defined in config")
} }
if c.Outputs == nil {
c.Logger.Log(logger.Info, pkg+"no output defined, defaulting", "output",
defaultOutput)
c.Outputs = append(c.Outputs, defaultOutput)
c.Packetization = defaultPacketization
} else {
for i, o := range c.Outputs { for i, o := range c.Outputs {
switch o { switch o {
case File: case File:
@ -228,12 +234,6 @@ func (c *Config) Validate(r *Revid) error {
c.FramesPerClip = defaultFramesPerClip c.FramesPerClip = defaultFramesPerClip
c.Packetization = Flv c.Packetization = Flv
c.SendRetry = true c.SendRetry = true
case NothingDefined:
c.Logger.Log(logger.Info, pkg+"no output defined, defaulting", "output",
defaultOutput)
c.Outputs[i] = defaultOutput
c.Packetization = defaultPacketization
fallthrough
case Http, Rtp: case Http, Rtp:
c.Logger.Log(logger.Info, pkg+"defaulting frames per clip for http out", c.Logger.Log(logger.Info, pkg+"defaulting frames per clip for http out",
"framesPerClip", httpFramesPerClip) "framesPerClip", httpFramesPerClip)
@ -243,6 +243,7 @@ func (c *Config) Validate(r *Revid) error {
return errors.New("bad output type defined in config") return errors.New("bad output type defined in config")
} }
} }
}
if c.BurstPeriod == 0 { if c.BurstPeriod == 0 {
c.Logger.Log(logger.Info, pkg+"no burst period defined, defaulting", "burstPeriod", defaultBurstPeriod) c.Logger.Log(logger.Info, pkg+"no burst period defined, defaulting", "burstPeriod", defaultBurstPeriod)

View File

@ -59,7 +59,6 @@ func TestRaspivid(t *testing.T) {
var c Config var c Config
c.Logger = &logger c.Logger = &logger
c.Input = Raspivid c.Input = Raspivid
c.Outputs = make([]uint8, 1)
rv, err := New(c, ns) rv, err := New(c, ns)
if err != nil { if err != nil {