Merged in fix-loop-mode-pause (pull request #402)

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

Approved-by: Trek Hopton <trek.hopton@gmail.com>
This commit is contained in:
Saxon Milton 2020-05-02 08:47:51 +00:00
commit f359d9ce79
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 is used for bitrate calculations.
bitrate bitrate.Calculator 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 // 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() r.mu.Lock()
defer r.mu.Unlock() defer r.mu.Unlock()
r.stop = make(chan struct{})
r.cfg.Logger.Log(logger.Debug, "resetting revid") r.cfg.Logger.Log(logger.Debug, "resetting revid")
err := r.reset(r.cfg) err := r.reset(r.cfg)
if err != nil { if err != nil {
@ -475,6 +480,8 @@ func (r *Revid) Stop() {
r.mu.Lock() r.mu.Lock()
defer r.mu.Unlock() defer r.mu.Unlock()
close(r.stop)
r.cfg.Logger.Log(logger.Debug, "stopping input") r.cfg.Logger.Log(logger.Debug, "stopping input")
err := r.input.Stop() err := r.input.Stop()
if err != nil { if err != nil {
@ -904,5 +911,12 @@ func (r *Revid) processFrom(in device.AVDevice, delay time.Duration) {
} else { } else {
r.cfg.Logger.Log(logger.Info, "input stopped") 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:
}
} }
} }