Archived
2
0

default screen size

This commit is contained in:
Craig 2020-02-11 06:10:54 +00:00
parent e9cf941870
commit 4fe1d481a0
2 changed files with 44 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package config
import (
"regexp"
"strconv"
"strings"
@ -20,6 +21,9 @@ type WebRTC struct {
EphemeralMin uint16
EphemeralMax uint16
NAT1To1IPs []string
ScreenWidth int
ScreenHeight int
ScreenRate int
}
func (WebRTC) Init(cmd *cobra.Command) error {
@ -43,6 +47,11 @@ func (WebRTC) Init(cmd *cobra.Command) error {
return err
}
cmd.PersistentFlags().String("screen", "1280x720@30", "default screen resolution and framerate")
if err := viper.BindPFlag("vparams", cmd.PersistentFlags().Lookup("video")); err != nil {
return err
}
cmd.PersistentFlags().String("epr", "59000-59100", "limits the pool of ephemeral ports that ICE UDP connections can allocate from")
if err := viper.BindPFlag("epr", cmd.PersistentFlags().Lookup("epr")); err != nil {
return err
@ -150,4 +159,23 @@ func (s *WebRTC) Set() {
s.EphemeralMin = min
s.EphemeralMax = max
}
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[1], 10, 64)
rate, err3 := strconv.ParseInt(res[1], 10, 64)
if err1 == nil && err2 == nil && err3 == nil {
s.ScreenWidth = int(width)
s.ScreenHeight = int(height)
s.ScreenRate = int(rate)
}
}
}

View File

@ -56,6 +56,14 @@ type WebRTCManager struct {
func (m *WebRTCManager) Start() {
xorg.Display(m.config.Display)
if !xorg.ValidScreenSize(m.config.ScreenWidth, m.config.ScreenHeight, m.config.ScreenRate) {
m.logger.Warn().Msgf("invalid screen option %dx%d@%d", m.config.ScreenWidth, m.config.ScreenHeight, m.config.ScreenRate)
} else {
if err := xorg.ChangeScreenSize(m.config.ScreenWidth, m.config.ScreenHeight, m.config.ScreenRate); err != nil {
m.logger.Warn().Err(err).Msg("unable to change screen size")
}
}
videoPipeline, err := gst.CreatePipeline(
m.config.VideoCodec,
m.config.Display,
@ -231,7 +239,15 @@ func (m *WebRTCManager) CreatePeer(id string, sdp string) (string, types.Peer, e
}
func (m *WebRTCManager) ChangeScreenSize(width int, height int, rate int) error {
if !xorg.ValidScreenSize(width, height, rate) {
return fmt.Errorf("unknown configuration")
}
m.videoPipeline.Stop()
defer func() {
m.videoPipeline.Start()
m.logger.Info().Msg("starting pipeline")
}()
if err := xorg.ChangeScreenSize(width, height, rate); err != nil {
return err
@ -248,7 +264,6 @@ func (m *WebRTCManager) ChangeScreenSize(width int, height int, rate int) error
}
m.videoPipeline = videoPipeline
m.videoPipeline.Start()
return nil
}