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,12 +55,15 @@ 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 before {
// before screen size change, we need to destroy all pipelines
if manager.video.Started() { if manager.video.Started() {
manager.video.destroyPipeline() manager.video.destroyPipeline()
} }
@ -68,16 +71,8 @@ func (manager *CaptureManagerCtx) Start() {
if manager.broadcast.Started() { if manager.broadcast.Started() {
manager.broadcast.destroyPipeline() manager.broadcast.destroyPipeline()
} }
} } else {
}() // after screen size change, we need to recreate all pipelines
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() { if manager.video.Started() {
err := manager.video.createPipeline() err := manager.video.createPipeline()
@ -93,6 +88,7 @@ func (manager *CaptureManagerCtx) Start() {
} }
} }
} }
}
}() }()
} }

View File

@ -19,18 +19,18 @@ type DesktopManagerCtx struct {
logger zerolog.Logger logger zerolog.Logger
wg sync.WaitGroup wg sync.WaitGroup
shutdown chan struct{} shutdown chan struct{}
beforeScreenSizeChangeChannel chan bool
afterScreenSizeChangeChannel chan int16
config *config.Desktop 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),
afterScreenSizeChangeChannel: make(chan int16),
config: config, 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
} }