2020-04-06 10:34:51 +12:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
2022-09-13 08:12:47 +12:00
|
|
|
type Capture struct {
|
2020-04-06 10:34:51 +12:00
|
|
|
Display string
|
|
|
|
Device string
|
|
|
|
AudioCodec string
|
|
|
|
AudioParams string
|
2021-02-15 09:07:56 +13:00
|
|
|
AudioBitrate uint
|
2022-03-18 08:25:17 +13:00
|
|
|
VideoHWEnc string
|
2020-04-06 10:34:51 +12:00
|
|
|
VideoCodec string
|
|
|
|
VideoParams string
|
2021-02-15 09:07:56 +13:00
|
|
|
VideoBitrate uint
|
2021-02-16 02:59:20 +13:00
|
|
|
MaxFPS int
|
2020-04-06 10:34:51 +12:00
|
|
|
}
|
|
|
|
|
2022-09-13 08:12:47 +12:00
|
|
|
func (Capture) Init(cmd *cobra.Command) error {
|
2020-04-06 10:34:51 +12:00
|
|
|
cmd.PersistentFlags().String("display", ":99.0", "XDisplay to capture")
|
|
|
|
if err := viper.BindPFlag("display", cmd.PersistentFlags().Lookup("display")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.PersistentFlags().String("device", "auto_null.monitor", "audio device to capture")
|
|
|
|
if err := viper.BindPFlag("device", cmd.PersistentFlags().Lookup("device")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-06 14:29:38 +12:00
|
|
|
cmd.PersistentFlags().String("audio", "", "audio codec parameters to use for streaming")
|
|
|
|
if err := viper.BindPFlag("audio", cmd.PersistentFlags().Lookup("audio")); err != nil {
|
2020-04-06 10:34:51 +12:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-02-15 09:07:56 +13:00
|
|
|
cmd.PersistentFlags().Int("audio_bitrate", 128, "audio bitrate in kbit/s")
|
|
|
|
if err := viper.BindPFlag("audio_bitrate", cmd.PersistentFlags().Lookup("audio_bitrate")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-06 14:29:38 +12:00
|
|
|
cmd.PersistentFlags().String("video", "", "video codec parameters to use for streaming")
|
|
|
|
if err := viper.BindPFlag("video", cmd.PersistentFlags().Lookup("video")); err != nil {
|
2020-04-06 10:34:51 +12:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-02-15 09:07:56 +13:00
|
|
|
cmd.PersistentFlags().Int("video_bitrate", 3072, "video bitrate in kbit/s")
|
|
|
|
if err := viper.BindPFlag("video_bitrate", cmd.PersistentFlags().Lookup("video_bitrate")); err != nil {
|
2020-04-06 10:34:51 +12:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-02-16 02:59:20 +13:00
|
|
|
cmd.PersistentFlags().Int("max_fps", 25, "maximum fps delivered via WebRTC, 0 is for no maximum")
|
|
|
|
if err := viper.BindPFlag("max_fps", cmd.PersistentFlags().Lookup("max_fps")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-03-18 08:25:17 +13:00
|
|
|
// hw encoding
|
|
|
|
cmd.PersistentFlags().String("hwenc", "", "use hardware accelerated encoding")
|
|
|
|
if err := viper.BindPFlag("hwenc", cmd.PersistentFlags().Lookup("hwenc")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-06 10:34:51 +12:00
|
|
|
// video codecs
|
|
|
|
cmd.PersistentFlags().Bool("vp8", false, "use VP8 video codec")
|
|
|
|
if err := viper.BindPFlag("vp8", cmd.PersistentFlags().Lookup("vp8")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.PersistentFlags().Bool("vp9", false, "use VP9 video codec")
|
|
|
|
if err := viper.BindPFlag("vp9", cmd.PersistentFlags().Lookup("vp9")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.PersistentFlags().Bool("h264", false, "use H264 video codec")
|
|
|
|
if err := viper.BindPFlag("h264", cmd.PersistentFlags().Lookup("h264")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// audio codecs
|
|
|
|
cmd.PersistentFlags().Bool("opus", false, "use Opus audio codec")
|
|
|
|
if err := viper.BindPFlag("opus", cmd.PersistentFlags().Lookup("opus")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.PersistentFlags().Bool("g722", false, "use G722 audio codec")
|
|
|
|
if err := viper.BindPFlag("g722", cmd.PersistentFlags().Lookup("g722")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.PersistentFlags().Bool("pcmu", false, "use PCMU audio codec")
|
|
|
|
if err := viper.BindPFlag("pcmu", cmd.PersistentFlags().Lookup("pcmu")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.PersistentFlags().Bool("pcma", false, "use PCMA audio codec")
|
|
|
|
if err := viper.BindPFlag("pcma", cmd.PersistentFlags().Lookup("pcma")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-13 08:12:47 +12:00
|
|
|
func (s *Capture) Set() {
|
2021-02-15 05:30:24 +13:00
|
|
|
audioCodec := "Opus"
|
2020-04-06 10:34:51 +12:00
|
|
|
if viper.GetBool("opus") {
|
2021-02-15 05:30:24 +13:00
|
|
|
audioCodec = "Opus"
|
2020-04-06 10:34:51 +12:00
|
|
|
} else if viper.GetBool("g722") {
|
2021-02-15 05:30:24 +13:00
|
|
|
audioCodec = "G722"
|
2020-04-06 10:34:51 +12:00
|
|
|
} else if viper.GetBool("pcmu") {
|
2021-02-15 05:30:24 +13:00
|
|
|
audioCodec = "PCMU"
|
2020-04-06 10:34:51 +12:00
|
|
|
} else if viper.GetBool("pcma") {
|
2021-02-15 05:30:24 +13:00
|
|
|
audioCodec = "PCMA"
|
2020-04-06 10:34:51 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
s.Device = viper.GetString("device")
|
|
|
|
s.AudioCodec = audioCodec
|
2020-04-06 14:29:38 +12:00
|
|
|
s.AudioParams = viper.GetString("audio")
|
2021-02-15 09:07:56 +13:00
|
|
|
s.AudioBitrate = viper.GetUint("audio_bitrate")
|
2022-03-18 08:25:17 +13:00
|
|
|
|
|
|
|
videoCodec := "VP8"
|
|
|
|
if viper.GetBool("vp8") {
|
|
|
|
videoCodec = "VP8"
|
|
|
|
} else if viper.GetBool("vp9") {
|
|
|
|
videoCodec = "VP9"
|
|
|
|
} else if viper.GetBool("h264") {
|
|
|
|
videoCodec = "H264"
|
|
|
|
}
|
|
|
|
videoHWEnc := ""
|
|
|
|
if viper.GetString("hwenc") == "VAAPI" {
|
|
|
|
videoHWEnc = "VAAPI"
|
|
|
|
}
|
2020-04-06 10:34:51 +12:00
|
|
|
s.Display = viper.GetString("display")
|
2022-03-18 08:25:17 +13:00
|
|
|
s.VideoHWEnc = videoHWEnc
|
2020-04-06 10:34:51 +12:00
|
|
|
s.VideoCodec = videoCodec
|
2020-04-06 14:29:38 +12:00
|
|
|
s.VideoParams = viper.GetString("video")
|
2021-02-15 09:07:56 +13:00
|
|
|
s.VideoBitrate = viper.GetUint("video_bitrate")
|
2020-04-06 10:34:51 +12:00
|
|
|
|
2021-02-16 02:59:20 +13:00
|
|
|
s.MaxFPS = viper.GetInt("max_fps")
|
2020-04-06 10:34:51 +12:00
|
|
|
}
|