revid: add stop signal channel to allow pause in loop mode

This commit is contained in:
Saxon 2020-05-02 14:44:05 +09:30
parent 4cf155bbc2
commit d4e93e701b
1 changed files with 14 additions and 0 deletions

View File

@ -116,6 +116,9 @@ type Revid struct {
// bitrate is used for bitrate calculations.
bitrate bitrate.Calculator
// stop used used to signal stopping when looping an input.
stop chan struct{}
}
// New returns a pointer to a new Revid with the desired configuration, and/or
@ -440,6 +443,8 @@ func (r *Revid) Start() error {
r.mu.Lock()
defer r.mu.Unlock()
r.stop = make(chan struct{})
r.cfg.Logger.Log(logger.Debug, "resetting revid")
err := r.reset(r.cfg)
if err != nil {
@ -475,6 +480,8 @@ func (r *Revid) Stop() {
r.mu.Lock()
defer r.mu.Unlock()
close(r.stop)
r.cfg.Logger.Log(logger.Debug, "stopping input")
err := r.input.Stop()
if err != nil {
@ -904,5 +911,12 @@ func (r *Revid) processFrom(in device.AVDevice, delay time.Duration) {
} else {
r.cfg.Logger.Log(logger.Info, "input stopped")
}
// If we're looping and we get a stop signal we return.
select {
case <-r.stop:
return
default:
}
}
}