join GetScreenSizeChangeChannel.

This commit is contained in:
Miroslav Šedivý 2023-01-29 18:00:56 +01:00
parent 6e62b796fc
commit f3080713ce
4 changed files with 42 additions and 52 deletions

View File

@ -55,41 +55,37 @@ func (manager *CaptureManagerCtx) Start() {
go func() { go func() {
for { for {
_, ok := <-manager.desktop.GetBeforeScreenSizeChangeChannel() before, ok := <-manager.desktop.GetScreenSizeChangeChannel()
if !ok { if !ok {
manager.logger.Info().Msg("before screen size change channel was closed") manager.logger.Info().Msg("screen size change channel was closed")
return return
} }
if manager.video.Started() { if before {
manager.video.destroyPipeline() // before screen size change, we need to destroy all pipelines
}
if manager.broadcast.Started() { if manager.video.Started() {
manager.broadcast.destroyPipeline() manager.video.destroyPipeline()
}
}
}()
go func() {
for {
_, ok := <-manager.desktop.GetAfterScreenSizeChangeChannel()
if !ok {
manager.logger.Info().Msg("after screen size change channel was closed")
return
}
if manager.video.Started() {
err := manager.video.createPipeline()
if err != nil && !errors.Is(err, types.ErrCapturePipelineAlreadyExists) {
manager.logger.Panic().Err(err).Msg("unable to recreate video pipeline")
} }
}
if manager.broadcast.Started() { if manager.broadcast.Started() {
err := manager.broadcast.createPipeline() manager.broadcast.destroyPipeline()
if err != nil && !errors.Is(err, types.ErrCapturePipelineAlreadyExists) { }
manager.logger.Panic().Err(err).Msg("unable to recreate broadcast pipeline") } else {
// after screen size change, we need to recreate all pipelines
if manager.video.Started() {
err := manager.video.createPipeline()
if err != nil && !errors.Is(err, types.ErrCapturePipelineAlreadyExists) {
manager.logger.Panic().Err(err).Msg("unable to recreate video pipeline")
}
}
if manager.broadcast.Started() {
err := manager.broadcast.createPipeline()
if err != nil && !errors.Is(err, types.ErrCapturePipelineAlreadyExists) {
manager.logger.Panic().Err(err).Msg("unable to recreate broadcast pipeline")
}
} }
} }
} }

View File

@ -16,21 +16,21 @@ import (
var mu = sync.Mutex{} var mu = sync.Mutex{}
type DesktopManagerCtx struct { type DesktopManagerCtx struct {
logger zerolog.Logger logger zerolog.Logger
wg sync.WaitGroup wg sync.WaitGroup
shutdown chan struct{} shutdown chan struct{}
beforeScreenSizeChangeChannel chan bool config *config.Desktop
afterScreenSizeChangeChannel chan int16
config *config.Desktop screenSizeChangeChannel chan bool
} }
func New(config *config.Desktop) *DesktopManagerCtx { func New(config *config.Desktop) *DesktopManagerCtx {
return &DesktopManagerCtx{ return &DesktopManagerCtx{
logger: log.With().Str("module", "desktop").Logger(), logger: log.With().Str("module", "desktop").Logger(),
shutdown: make(chan struct{}), shutdown: make(chan struct{}),
beforeScreenSizeChangeChannel: make(chan bool), config: config,
afterScreenSizeChangeChannel: make(chan int16),
config: config, screenSizeChangeChannel: make(chan bool),
} }
} }
@ -84,18 +84,15 @@ func (manager *DesktopManagerCtx) Start() {
}() }()
} }
func (manager *DesktopManagerCtx) GetBeforeScreenSizeChangeChannel() chan bool { func (manager *DesktopManagerCtx) GetScreenSizeChangeChannel() chan bool {
return manager.beforeScreenSizeChangeChannel return manager.screenSizeChangeChannel
}
func (manager *DesktopManagerCtx) GetAfterScreenSizeChangeChannel() chan int16 {
return manager.afterScreenSizeChangeChannel
} }
func (manager *DesktopManagerCtx) Shutdown() error { func (manager *DesktopManagerCtx) Shutdown() error {
manager.logger.Info().Msgf("desktop shutting down") manager.logger.Info().Msgf("desktop shutting down")
close(manager.shutdown) close(manager.shutdown)
close(manager.screenSizeChangeChannel)
manager.wg.Wait() manager.wg.Wait()
xorg.DisplayClose() xorg.DisplayClose()

View File

@ -72,10 +72,10 @@ func (manager *DesktopManagerCtx) ScreenConfigurations() map[int]types.ScreenCon
func (manager *DesktopManagerCtx) SetScreenSize(size types.ScreenSize) error { func (manager *DesktopManagerCtx) SetScreenSize(size types.ScreenSize) error {
mu.Lock() mu.Lock()
manager.GetBeforeScreenSizeChangeChannel() <- true manager.GetScreenSizeChangeChannel() <- true
defer func() { defer func() {
manager.GetAfterScreenSizeChangeChannel() <- size.Rate manager.GetScreenSizeChangeChannel() <- false
mu.Unlock() mu.Unlock()
}() }()

View File

@ -43,8 +43,7 @@ type DesktopErrorMessage struct {
type DesktopManager interface { type DesktopManager interface {
Start() Start()
Shutdown() error Shutdown() error
GetBeforeScreenSizeChangeChannel() chan bool GetScreenSizeChangeChannel() (before chan bool) // true - before, false - after
GetAfterScreenSizeChangeChannel() chan int16
// clipboard // clipboard
ReadClipboard() string ReadClipboard() string
@ -73,8 +72,6 @@ type DesktopManager interface {
// xevent // xevent
GetCursorChangedChannel() chan uint64 GetCursorChangedChannel() chan uint64
GetClipboardUpdatedChannel() chan bool GetClipboardUpdatedChannel() chan struct{}
GetFileChooserDialogOpenedChannel() chan bool
GetFileChooserDialogClosedChannel() chan bool
GetEventErrorChannel() chan DesktopErrorMessage GetEventErrorChannel() chan DesktopErrorMessage
} }