Merged in default-mode-crash-fix (pull request #150)

revid-cli: initialising config.Output slice when no outputs are defined so that a default output can still be set

Approved-by: Alan Noble <anoble@gmail.com>
This commit is contained in:
Saxon Milton 2019-02-25 06:42:38 +00:00 committed by Alan Noble
commit c247e63bd0
3 changed files with 20 additions and 14 deletions

View File

@ -184,6 +184,10 @@ func handleFlags() revid.Config {
log.Log(logger.Error, pkg+"bad input codec argument")
}
if len(outputs) == 0 {
cfg.Outputs = make([]uint8, 1)
}
for _, o := range outputs {
switch o {
case "File":

View File

@ -148,11 +148,9 @@ func (c *Config) Validate(r *Revid) error {
// Configuration really needs to be rethought here.
if c.Quantize && c.Quantization == 0 {
c.Quantization = defaultQuantization
} else {
c.Bitrate = defaultBitrate
}
if (c.Bitrate > 0 && c.Quantization > 0) || (c.Bitrate == 0 && c.Quantization == 0) {
if (c.Bitrate > 0 && c.Quantize) || (c.Bitrate == 0 && !c.Quantize) {
return errors.New("bad bitrate and quantization combination for H264 input")
}

View File

@ -187,7 +187,6 @@ func (p *packer) Write(frame []byte) (int, error) {
// an error if construction of the new instance was not successful.
func New(c Config, ns *netsender.Sender) (*Revid, error) {
r := Revid{ns: ns, err: make(chan error)}
r.buffer = ring.NewBuffer(ringBufferSize, ringBufferElementSize, writeTimeout)
r.packer.owner = &r
err := r.reset(c)
if err != nil {
@ -230,14 +229,7 @@ func (r *Revid) reset(config Config) error {
}
r.config = config
for _, dest := range r.destination {
if dest != nil {
err = dest.close()
if err != nil {
return err
}
}
}
r.buffer = ring.NewBuffer(ringBufferSize, ringBufferElementSize, writeTimeout)
r.destination = r.destination[:0]
for _, typ := range r.config.Outputs {
@ -392,6 +384,7 @@ func (r *Revid) Update(vars map[string]string) error {
for key, value := range vars {
switch key {
case "Output":
r.config.Outputs = make([]uint8, 1)
// FIXME(kortschak): There can be only one!
// How do we specify outputs after the first?
//
@ -409,6 +402,17 @@ func (r *Revid) Update(vars map[string]string) error {
r.config.Logger.Log(logger.Warning, pkg+"invalid Output1 param", "value", value)
continue
}
case "Packetization":
switch value {
case "Mpegts":
r.config.Packetization = Mpegts
case "Flv":
r.config.Packetization = Flv
default:
r.config.Logger.Log(logger.Warning, pkg+"invalid packetization param", "value", value)
continue
}
case "FramesPerClip":
f, err := strconv.ParseUint(value, 10, 0)
if err != nil {
@ -493,8 +497,8 @@ func (r *Revid) Update(vars map[string]string) error {
r.config.BurstPeriod = uint(v)
}
}
return nil
r.config.Logger.Log(logger.Info, pkg+"revid config changed", "config", fmt.Sprint("%+v", r.config))
return r.reset(r.config)
}
// outputClips takes the clips produced in the packClips method and outputs them