mirror of https://bitbucket.org/ausocean/av.git
revid: add stop signal channel to allow pause in loop mode
This commit is contained in:
parent
4cf155bbc2
commit
d4e93e701b
|
@ -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:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue