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 {
manager.url = url
manager.enabled = true

View File

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

View File

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

View File

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

View File

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