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,36 +211,37 @@ 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")
} }
for i, o := range c.Outputs { if c.Outputs == nil {
switch o { c.Logger.Log(logger.Info, pkg+"no output defined, defaulting", "output",
case File: defaultOutput)
case Udp: c.Outputs = append(c.Outputs, defaultOutput)
case Rtmp, FfmpegRtmp: c.Packetization = defaultPacketization
if c.RtmpUrl == "" { } else {
c.Logger.Log(logger.Info, pkg+"no RTMP URL: falling back to HTTP") for i, o := range c.Outputs {
c.Outputs[i] = Http switch o {
// FIXME(kortschak): Does this want the same line as below? case File:
// c.FramesPerClip = httpFramesPerClip case Udp:
break case Rtmp, FfmpegRtmp:
if c.RtmpUrl == "" {
c.Logger.Log(logger.Info, pkg+"no RTMP URL: falling back to HTTP")
c.Outputs[i] = Http
// FIXME(kortschak): Does this want the same line as below?
// c.FramesPerClip = httpFramesPerClip
break
}
c.Logger.Log(logger.Info, pkg+"defaulting frames per clip for rtmp out",
"framesPerClip", defaultFramesPerClip)
c.FramesPerClip = defaultFramesPerClip
c.Packetization = Flv
c.SendRetry = true
case Http, Rtp:
c.Logger.Log(logger.Info, pkg+"defaulting frames per clip for http out",
"framesPerClip", httpFramesPerClip)
c.FramesPerClip = httpFramesPerClip
c.Packetization = Mpegts
default:
return errors.New("bad output type defined in config")
} }
c.Logger.Log(logger.Info, pkg+"defaulting frames per clip for rtmp out",
"framesPerClip", defaultFramesPerClip)
c.FramesPerClip = defaultFramesPerClip
c.Packetization = Flv
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:
c.Logger.Log(logger.Info, pkg+"defaulting frames per clip for http out",
"framesPerClip", httpFramesPerClip)
c.FramesPerClip = httpFramesPerClip
c.Packetization = Mpegts
default:
return errors.New("bad output type defined in config")
} }
} }

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 {