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() {
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")
}
}
}
}

View File

@ -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()

View File

@ -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()
}()

View File

@ -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
}