mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
unify capture shutdown.
This commit is contained in:
parent
7902d7b1f1
commit
58ea3665b0
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -21,8 +21,8 @@ type ScreencastManagerCtx struct {
|
||||
pipeline *gst.Pipeline
|
||||
enabled bool
|
||||
started bool
|
||||
shutdown chan bool
|
||||
refresh chan bool
|
||||
emitStop chan bool
|
||||
emitUpdate chan bool
|
||||
expired int32
|
||||
sample chan types.Sample
|
||||
image types.Sample
|
||||
@ -34,8 +34,8 @@ func screencastNew(config *config.Capture) *ScreencastManagerCtx {
|
||||
config: config,
|
||||
enabled: config.Screencast,
|
||||
started: false,
|
||||
shutdown: make(chan bool),
|
||||
refresh: make(chan bool),
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -22,8 +22,6 @@ type ScreencastManager interface {
|
||||
}
|
||||
|
||||
type StreamManager interface {
|
||||
Shutdown()
|
||||
|
||||
Codec() codec.RTPCodec
|
||||
OnSample(listener func(sample Sample))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user