diff --git a/revid/revid.go b/revid/revid.go index 8ce0c940..08035e3e 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -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: + } } }