From f3080713ce6eb1cde69022b47052fdea3ec9fe3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sun, 29 Jan 2023 18:00:56 +0100 Subject: [PATCH] join GetScreenSizeChangeChannel. --- server/internal/capture/manager.go | 52 ++++++++++++++---------------- server/internal/desktop/manager.go | 31 ++++++++---------- server/internal/desktop/xorg.go | 4 +-- server/internal/types/desktop.go | 7 ++-- 4 files changed, 42 insertions(+), 52 deletions(-) diff --git a/server/internal/capture/manager.go b/server/internal/capture/manager.go index 9bb88af..014e1a6 100644 --- a/server/internal/capture/manager.go +++ b/server/internal/capture/manager.go @@ -55,41 +55,37 @@ func (manager *CaptureManagerCtx) Start() { go func() { for { - _, ok := <-manager.desktop.GetBeforeScreenSizeChangeChannel() + before, ok := <-manager.desktop.GetScreenSizeChangeChannel() if !ok { - manager.logger.Info().Msg("before screen size change channel was closed") + manager.logger.Info().Msg("screen size change channel was closed") return } - if manager.video.Started() { - manager.video.destroyPipeline() - } + if before { + // before screen size change, we need to destroy all pipelines - if manager.broadcast.Started() { - manager.broadcast.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.video.Started() { + manager.video.destroyPipeline() } - } - 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") + if manager.broadcast.Started() { + manager.broadcast.destroyPipeline() + } + } 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") + } } } } diff --git a/server/internal/desktop/manager.go b/server/internal/desktop/manager.go index 5e5071f..918efb0 100644 --- a/server/internal/desktop/manager.go +++ b/server/internal/desktop/manager.go @@ -16,21 +16,21 @@ import ( var mu = sync.Mutex{} type DesktopManagerCtx struct { - logger zerolog.Logger - wg sync.WaitGroup - shutdown chan struct{} - beforeScreenSizeChangeChannel chan bool - afterScreenSizeChangeChannel chan int16 - config *config.Desktop + logger zerolog.Logger + wg sync.WaitGroup + shutdown chan struct{} + config *config.Desktop + + screenSizeChangeChannel chan bool } func New(config *config.Desktop) *DesktopManagerCtx { return &DesktopManagerCtx{ - logger: log.With().Str("module", "desktop").Logger(), - shutdown: make(chan struct{}), - beforeScreenSizeChangeChannel: make(chan bool), - afterScreenSizeChangeChannel: make(chan int16), - config: config, + logger: log.With().Str("module", "desktop").Logger(), + shutdown: make(chan struct{}), + config: config, + + screenSizeChangeChannel: make(chan bool), } } @@ -84,18 +84,15 @@ func (manager *DesktopManagerCtx) Start() { }() } -func (manager *DesktopManagerCtx) GetBeforeScreenSizeChangeChannel() chan bool { - return manager.beforeScreenSizeChangeChannel -} - -func (manager *DesktopManagerCtx) GetAfterScreenSizeChangeChannel() chan int16 { - return manager.afterScreenSizeChangeChannel +func (manager *DesktopManagerCtx) GetScreenSizeChangeChannel() chan bool { + return manager.screenSizeChangeChannel } func (manager *DesktopManagerCtx) Shutdown() error { manager.logger.Info().Msgf("desktop shutting down") close(manager.shutdown) + close(manager.screenSizeChangeChannel) manager.wg.Wait() xorg.DisplayClose() diff --git a/server/internal/desktop/xorg.go b/server/internal/desktop/xorg.go index df1ad97..3008eaa 100644 --- a/server/internal/desktop/xorg.go +++ b/server/internal/desktop/xorg.go @@ -72,10 +72,10 @@ func (manager *DesktopManagerCtx) ScreenConfigurations() map[int]types.ScreenCon func (manager *DesktopManagerCtx) SetScreenSize(size types.ScreenSize) error { mu.Lock() - manager.GetBeforeScreenSizeChangeChannel() <- true + manager.GetScreenSizeChangeChannel() <- true defer func() { - manager.GetAfterScreenSizeChangeChannel() <- size.Rate + manager.GetScreenSizeChangeChannel() <- false mu.Unlock() }() diff --git a/server/internal/types/desktop.go b/server/internal/types/desktop.go index e2be4d2..e70e370 100644 --- a/server/internal/types/desktop.go +++ b/server/internal/types/desktop.go @@ -43,8 +43,7 @@ type DesktopErrorMessage struct { type DesktopManager interface { Start() Shutdown() error - GetBeforeScreenSizeChangeChannel() chan bool - GetAfterScreenSizeChangeChannel() chan int16 + GetScreenSizeChangeChannel() (before chan bool) // true - before, false - after // clipboard ReadClipboard() string @@ -73,8 +72,6 @@ type DesktopManager interface { // xevent GetCursorChangedChannel() chan uint64 - GetClipboardUpdatedChannel() chan bool - GetFileChooserDialogOpenedChannel() chan bool - GetFileChooserDialogClosedChannel() chan bool + GetClipboardUpdatedChannel() chan struct{} GetEventErrorChannel() chan DesktopErrorMessage }