unify capture shutdown.

This commit is contained in:
Miroslav Šedivý 2021-02-05 12:18:46 +01:00
parent 7902d7b1f1
commit 58ea3665b0
5 changed files with 42 additions and 31 deletions

View File

@ -25,6 +25,12 @@ func broadcastNew(config *config.Capture) *BroacastManagerCtx {
} }
} }
func (manager *BroacastManagerCtx) shutdown() {
manager.logger.Info().Msgf("shutting down")
manager.destroyPipeline()
}
func (manager *BroacastManagerCtx) Start(url string) error { func (manager *BroacastManagerCtx) Start(url string) error {
manager.url = url manager.url = url
manager.enabled = true manager.enabled = true

View File

@ -81,11 +81,11 @@ func (manager *CaptureManagerCtx) Start() {
func (manager *CaptureManagerCtx) Shutdown() error { func (manager *CaptureManagerCtx) Shutdown() error {
manager.logger.Info().Msgf("capture shutting down") manager.logger.Info().Msgf("capture shutting down")
manager.broadcast.destroyPipeline() manager.broadcast.shutdown()
manager.screencast.destroyPipeline() manager.screencast.shutdown()
manager.screencast.shutdown <- true
manager.audio.Shutdown() manager.audio.shutdown()
manager.video.Shutdown() manager.video.shutdown()
return nil return nil
} }

View File

@ -21,8 +21,8 @@ type ScreencastManagerCtx struct {
pipeline *gst.Pipeline pipeline *gst.Pipeline
enabled bool enabled bool
started bool started bool
shutdown chan bool emitStop chan bool
refresh chan bool emitUpdate chan bool
expired int32 expired int32
sample chan types.Sample sample chan types.Sample
image types.Sample image types.Sample
@ -34,8 +34,8 @@ func screencastNew(config *config.Capture) *ScreencastManagerCtx {
config: config, config: config,
enabled: config.Screencast, enabled: config.Screencast,
started: false, started: false,
shutdown: make(chan bool), emitStop: make(chan bool),
refresh: make(chan bool), emitUpdate: make(chan bool),
} }
if !manager.enabled { if !manager.enabled {
@ -44,16 +44,16 @@ func screencastNew(config *config.Capture) *ScreencastManagerCtx {
go func() { go func() {
ticker := time.NewTicker(5 * time.Second) ticker := time.NewTicker(5 * time.Second)
manager.logger.Debug().Msg("subroutine started") manager.logger.Debug().Msg("started emitting samples")
for { for {
select { select {
case <-manager.shutdown: case <-manager.emitStop:
manager.logger.Debug().Msg("shutting down") manager.logger.Debug().Msg("stopped emitting samples")
ticker.Stop() ticker.Stop()
return return
case <-manager.refresh: case <-manager.emitUpdate:
manager.logger.Debug().Msg("subroutine updated") manager.logger.Debug().Msg("update emitting samples")
case sample := <-manager.sample: case sample := <-manager.sample:
manager.image = sample manager.image = sample
case <-ticker.C: case <-ticker.C:
@ -67,6 +67,13 @@ func screencastNew(config *config.Capture) *ScreencastManagerCtx {
return manager return manager
} }
func (manager *ScreencastManagerCtx) shutdown() {
manager.logger.Info().Msgf("shutting down")
manager.destroyPipeline()
manager.emitStop <- true
}
func (manager *ScreencastManagerCtx) Enabled() bool { func (manager *ScreencastManagerCtx) Enabled() bool {
return manager.enabled return manager.enabled
} }
@ -144,7 +151,7 @@ func (manager *ScreencastManagerCtx) createPipeline() error {
manager.logger.Info().Msgf("starting pipeline") manager.logger.Info().Msgf("starting pipeline")
manager.sample = manager.pipeline.Sample manager.sample = manager.pipeline.Sample
manager.refresh <-true manager.emitUpdate <-true
return nil return nil
} }

View File

@ -58,7 +58,7 @@ func streamNew(codec codec.RTPCodec, pipelineDevice string, pipelineSrc string)
return manager return manager
} }
func (manager *StreamManagerCtx) Shutdown() { func (manager *StreamManagerCtx) shutdown() {
manager.logger.Info().Msgf("shutting down") manager.logger.Info().Msgf("shutting down")
manager.destroyPipeline() manager.destroyPipeline()

View File

@ -22,8 +22,6 @@ type ScreencastManager interface {
} }
type StreamManager interface { type StreamManager interface {
Shutdown()
Codec() codec.RTPCodec Codec() codec.RTPCodec
OnSample(listener func(sample Sample)) OnSample(listener func(sample Sample))