mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
change screen size only on desktop.
This commit is contained in:
parent
b0ae758d7b
commit
a8173ce02f
@ -17,6 +17,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configs := []config.Config{
|
configs := []config.Config{
|
||||||
|
neko.Service.Configs.Desktop,
|
||||||
neko.Service.Configs.Capture,
|
neko.Service.Configs.Capture,
|
||||||
neko.Service.Configs.WebRTC,
|
neko.Service.Configs.WebRTC,
|
||||||
neko.Service.Configs.Session,
|
neko.Service.Configs.Session,
|
||||||
|
@ -48,7 +48,7 @@ func (h *RoomHandler) ScreenConfigurationChange(w http.ResponseWriter, r *http.R
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := h.capture.ChangeResolution(data.Width, data.Height, data.Rate); err != nil {
|
if err := h.desktop.ChangeScreenSize(data.Width, data.Height, data.Rate); err != nil {
|
||||||
_ = render.Render(w, r, utils.ErrUnprocessableEntity(err))
|
_ = render.Render(w, r, utils.ErrUnprocessableEntity(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package capture
|
package capture
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/kataras/go-events"
|
"github.com/kataras/go-events"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
@ -42,15 +40,15 @@ func New(desktop types.DesktopManager, config *config.Capture) *CaptureManagerCt
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (manager *CaptureManagerCtx) Start() {
|
func (manager *CaptureManagerCtx) Start() {
|
||||||
manager.logger.Info().
|
|
||||||
Str("screen_resolution", fmt.Sprintf("%dx%d@%d", manager.config.ScreenWidth, manager.config.ScreenHeight, manager.config.ScreenRate)).
|
|
||||||
Msgf("Setting screen resolution...")
|
|
||||||
|
|
||||||
if err := manager.desktop.ChangeScreenSize(manager.config.ScreenWidth, manager.config.ScreenHeight, manager.config.ScreenRate); err != nil {
|
|
||||||
manager.logger.Warn().Err(err).Msg("unable to change screen size")
|
|
||||||
}
|
|
||||||
|
|
||||||
manager.StartBroadcastPipeline()
|
manager.StartBroadcastPipeline()
|
||||||
|
|
||||||
|
manager.desktop.OnScreenSizeChange(func(width int, height int, rate int) {
|
||||||
|
manager.video_stop <- true
|
||||||
|
manager.StopBroadcastPipeline()
|
||||||
|
|
||||||
|
manager.createVideoPipeline()
|
||||||
|
manager.StartBroadcastPipeline()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *CaptureManagerCtx) Shutdown() error {
|
func (manager *CaptureManagerCtx) Shutdown() error {
|
||||||
@ -102,18 +100,6 @@ func (manager *CaptureManagerCtx) Streaming() bool {
|
|||||||
return manager.streaming
|
return manager.streaming
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *CaptureManagerCtx) ChangeResolution(width int, height int, rate int) error {
|
|
||||||
manager.video_stop <- true
|
|
||||||
manager.StopBroadcastPipeline()
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
manager.createVideoPipeline()
|
|
||||||
manager.StartBroadcastPipeline()
|
|
||||||
}()
|
|
||||||
|
|
||||||
return manager.desktop.ChangeScreenSize(width, height, rate)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (manager *CaptureManagerCtx) createVideoPipeline() {
|
func (manager *CaptureManagerCtx) createVideoPipeline() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/pion/webrtc/v2"
|
"github.com/pion/webrtc/v2"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
@ -16,9 +13,6 @@ type Capture struct {
|
|||||||
AudioParams string
|
AudioParams string
|
||||||
VideoCodec string
|
VideoCodec string
|
||||||
VideoParams string
|
VideoParams string
|
||||||
ScreenWidth int
|
|
||||||
ScreenHeight int
|
|
||||||
ScreenRate int
|
|
||||||
BroadcastPipeline string
|
BroadcastPipeline string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,11 +37,6 @@ func (Capture) Init(cmd *cobra.Command) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.PersistentFlags().String("screen", "1280x720@30", "default screen resolution and framerate")
|
|
||||||
if err := viper.BindPFlag("screen", cmd.PersistentFlags().Lookup("screen")); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// video codecs
|
// video codecs
|
||||||
cmd.PersistentFlags().Bool("vp8", false, "use VP8 video codec")
|
cmd.PersistentFlags().Bool("vp8", false, "use VP8 video codec")
|
||||||
if err := viper.BindPFlag("vp8", cmd.PersistentFlags().Lookup("vp8")); err != nil {
|
if err := viper.BindPFlag("vp8", cmd.PersistentFlags().Lookup("vp8")); err != nil {
|
||||||
@ -121,25 +110,5 @@ func (s *Capture) Set() {
|
|||||||
s.Display = viper.GetString("display")
|
s.Display = viper.GetString("display")
|
||||||
s.VideoCodec = videoCodec
|
s.VideoCodec = videoCodec
|
||||||
s.VideoParams = viper.GetString("video")
|
s.VideoParams = viper.GetString("video")
|
||||||
|
|
||||||
s.ScreenWidth = 1280
|
|
||||||
s.ScreenHeight = 720
|
|
||||||
s.ScreenRate = 30
|
|
||||||
|
|
||||||
r := regexp.MustCompile(`([0-9]{1,4})x([0-9]{1,4})@([0-9]{1,3})`)
|
|
||||||
res := r.FindStringSubmatch(viper.GetString("screen"))
|
|
||||||
|
|
||||||
if len(res) > 0 {
|
|
||||||
width, err1 := strconv.ParseInt(res[1], 10, 64)
|
|
||||||
height, err2 := strconv.ParseInt(res[2], 10, 64)
|
|
||||||
rate, err3 := strconv.ParseInt(res[3], 10, 64)
|
|
||||||
|
|
||||||
if err1 == nil && err2 == nil && err3 == nil {
|
|
||||||
s.ScreenWidth = int(width)
|
|
||||||
s.ScreenHeight = int(height)
|
|
||||||
s.ScreenRate = int(rate)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
s.BroadcastPipeline = viper.GetString("broadcast_pipeline")
|
s.BroadcastPipeline = viper.GetString("broadcast_pipeline")
|
||||||
}
|
}
|
||||||
|
45
internal/config/desktop.go
Normal file
45
internal/config/desktop.go
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Desktop struct {
|
||||||
|
ScreenWidth int
|
||||||
|
ScreenHeight int
|
||||||
|
ScreenRate int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Desktop) Init(cmd *cobra.Command) error {
|
||||||
|
cmd.PersistentFlags().String("screen", "1280x720@30", "default screen size and framerate")
|
||||||
|
if err := viper.BindPFlag("screen", cmd.PersistentFlags().Lookup("screen")); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Desktop) Set() {
|
||||||
|
s.ScreenWidth = 1280
|
||||||
|
s.ScreenHeight = 720
|
||||||
|
s.ScreenRate = 30
|
||||||
|
|
||||||
|
r := regexp.MustCompile(`([0-9]{1,4})x([0-9]{1,4})@([0-9]{1,3})`)
|
||||||
|
res := r.FindStringSubmatch(viper.GetString("screen"))
|
||||||
|
|
||||||
|
if len(res) > 0 {
|
||||||
|
width, err1 := strconv.ParseInt(res[1], 10, 64)
|
||||||
|
height, err2 := strconv.ParseInt(res[2], 10, 64)
|
||||||
|
rate, err3 := strconv.ParseInt(res[3], 10, 64)
|
||||||
|
|
||||||
|
if err1 == nil && err2 == nil && err3 == nil {
|
||||||
|
s.ScreenWidth = int(width)
|
||||||
|
s.ScreenHeight = int(height)
|
||||||
|
s.ScreenRate = int(rate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,14 @@
|
|||||||
package desktop
|
package desktop
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/kataras/go-events"
|
"github.com/kataras/go-events"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
|
"demodesk/neko/internal/config"
|
||||||
"demodesk/neko/internal/desktop/xorg"
|
"demodesk/neko/internal/desktop/xorg"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,15 +16,19 @@ type DesktopManagerCtx struct {
|
|||||||
logger zerolog.Logger
|
logger zerolog.Logger
|
||||||
cleanup *time.Ticker
|
cleanup *time.Ticker
|
||||||
shutdown chan bool
|
shutdown chan bool
|
||||||
|
emmiter events.EventEmmiter
|
||||||
display string
|
display string
|
||||||
|
config *config.Desktop
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(display string) *DesktopManagerCtx {
|
func New(display string, config *config.Desktop) *DesktopManagerCtx {
|
||||||
return &DesktopManagerCtx{
|
return &DesktopManagerCtx{
|
||||||
logger: log.With().Str("module", "desktop").Logger(),
|
logger: log.With().Str("module", "desktop").Logger(),
|
||||||
cleanup: time.NewTicker(1 * time.Second),
|
cleanup: time.NewTicker(1 * time.Second),
|
||||||
shutdown: make(chan bool),
|
shutdown: make(chan bool),
|
||||||
|
emmiter: events.New(),
|
||||||
display: display,
|
display: display,
|
||||||
|
config: config,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,6 +39,14 @@ func (manager *DesktopManagerCtx) Start() {
|
|||||||
|
|
||||||
xorg.GetScreenConfigurations()
|
xorg.GetScreenConfigurations()
|
||||||
|
|
||||||
|
manager.logger.Info().
|
||||||
|
Str("screen_size", fmt.Sprintf("%dx%d@%d", manager.config.ScreenWidth, manager.config.ScreenHeight, manager.config.ScreenRate)).
|
||||||
|
Msgf("Setting initial screen size...")
|
||||||
|
|
||||||
|
if err := xorg.ChangeScreenSize(manager.config.ScreenWidth, manager.config.ScreenHeight, manager.config.ScreenRate); err != nil {
|
||||||
|
manager.logger.Warn().Err(err).Msg("unable to set initial screen size")
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
xorg.DisplayClose()
|
xorg.DisplayClose()
|
||||||
@ -50,6 +64,12 @@ func (manager *DesktopManagerCtx) Start() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (manager *DesktopManagerCtx) OnScreenSizeChange(listener func(width int, height int, rate int)) {
|
||||||
|
manager.emmiter.On("screen_size_change", func(payload ...interface{}) {
|
||||||
|
listener(payload[0].(int), payload[1].(int), payload[2].(int))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) Shutdown() error {
|
func (manager *DesktopManagerCtx) Shutdown() error {
|
||||||
manager.logger.Info().Msgf("remote shutting down")
|
manager.logger.Info().Msgf("remote shutting down")
|
||||||
|
|
||||||
|
@ -5,10 +5,6 @@ import (
|
|||||||
"demodesk/neko/internal/desktop/xorg"
|
"demodesk/neko/internal/desktop/xorg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) ChangeScreenSize(width int, height int, rate int) error {
|
|
||||||
return xorg.ChangeScreenSize(width, height, rate)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) Move(x, y int) {
|
func (manager *DesktopManagerCtx) Move(x, y int) {
|
||||||
xorg.Move(x, y)
|
xorg.Move(x, y)
|
||||||
}
|
}
|
||||||
@ -45,6 +41,15 @@ func (manager *DesktopManagerCtx) GetScreenSize() *types.ScreenSize {
|
|||||||
return xorg.GetScreenSize()
|
return xorg.GetScreenSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (manager *DesktopManagerCtx) ChangeScreenSize(width int, height int, rate int) error {
|
||||||
|
if err := xorg.ChangeScreenSize(width, height, rate); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
manager.emmiter.Emit("screen_size_change", width, height, rate)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (manager *DesktopManagerCtx) SetKeyboardLayout(layout string) {
|
func (manager *DesktopManagerCtx) SetKeyboardLayout(layout string) {
|
||||||
xorg.SetKeyboardLayout(layout)
|
xorg.SetKeyboardLayout(layout)
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,6 @@ type CaptureManager interface {
|
|||||||
StopStream()
|
StopStream()
|
||||||
Streaming() bool
|
Streaming() bool
|
||||||
|
|
||||||
ChangeResolution(width int, height int, rate int) error
|
|
||||||
|
|
||||||
// broacast
|
// broacast
|
||||||
StartBroadcast(url string)
|
StartBroadcast(url string)
|
||||||
StopBroadcast()
|
StopBroadcast()
|
||||||
|
@ -15,6 +15,7 @@ type ScreenConfiguration struct {
|
|||||||
type DesktopManager interface {
|
type DesktopManager interface {
|
||||||
Start()
|
Start()
|
||||||
Shutdown() error
|
Shutdown() error
|
||||||
|
OnScreenSizeChange(listener func(width int, height int, rate int))
|
||||||
|
|
||||||
// xorg
|
// xorg
|
||||||
ChangeScreenSize(width int, height int, rate int) error
|
ChangeScreenSize(width int, height int, rate int) error
|
||||||
|
@ -12,7 +12,7 @@ func (h *MessageHandlerCtx) screenSet(session types.Session, payload *message.Sc
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := h.capture.ChangeResolution(payload.Width, payload.Height, payload.Rate); err != nil {
|
if err := h.desktop.ChangeScreenSize(payload.Width, payload.Height, payload.Rate); err != nil {
|
||||||
h.logger.Warn().Err(err).Msgf("unable to change screen size")
|
h.logger.Warn().Err(err).Msgf("unable to change screen size")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
3
neko.go
3
neko.go
@ -62,6 +62,7 @@ func init() {
|
|||||||
},
|
},
|
||||||
Configs: &Configs{
|
Configs: &Configs{
|
||||||
Root: &config.Root{},
|
Root: &config.Root{},
|
||||||
|
Desktop: &config.Desktop{},
|
||||||
Capture: &config.Capture{},
|
Capture: &config.Capture{},
|
||||||
WebRTC: &config.WebRTC{},
|
WebRTC: &config.WebRTC{},
|
||||||
Session: &config.Session{},
|
Session: &config.Session{},
|
||||||
@ -101,6 +102,7 @@ func (i *Version) Details() string {
|
|||||||
|
|
||||||
type Configs struct {
|
type Configs struct {
|
||||||
Root *config.Root
|
Root *config.Root
|
||||||
|
Desktop *config.Desktop
|
||||||
Capture *config.Capture
|
Capture *config.Capture
|
||||||
WebRTC *config.WebRTC
|
WebRTC *config.WebRTC
|
||||||
Session *config.Session
|
Session *config.Session
|
||||||
@ -128,6 +130,7 @@ func (neko *Neko) Preflight() {
|
|||||||
func (neko *Neko) Start() {
|
func (neko *Neko) Start() {
|
||||||
neko.desktopManager = desktop.New(
|
neko.desktopManager = desktop.New(
|
||||||
neko.Configs.Capture.Display,
|
neko.Configs.Capture.Display,
|
||||||
|
neko.Configs.Desktop,
|
||||||
)
|
)
|
||||||
neko.desktopManager.Start()
|
neko.desktopManager.Start()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user