neko/internal/config/capture.go

153 lines
4.6 KiB
Go
Raw Normal View History

package config
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
2021-02-02 11:50:18 +13:00
"demodesk/neko/internal/types/codec"
)
2020-11-02 04:09:48 +13:00
type Capture struct {
Display string
Device string
2021-02-02 11:50:18 +13:00
AudioCodec codec.RTP
AudioParams string
2021-02-02 11:50:18 +13:00
VideoCodec codec.RTP
VideoParams string
2021-01-23 06:13:32 +13:00
2020-11-02 04:09:48 +13:00
BroadcastPipeline string
2021-01-23 06:13:32 +13:00
Screencast bool
2021-01-23 06:44:27 +13:00
ScreencastRate string
ScreencastQuality string
2021-01-23 06:13:32 +13:00
ScreencastPipeline string
}
2020-11-02 04:09:48 +13:00
func (Capture) Init(cmd *cobra.Command) error {
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
}
cmd.PersistentFlags().String("audio", "", "audio codec parameters to use for streaming")
if err := viper.BindPFlag("audio", cmd.PersistentFlags().Lookup("audio")); err != nil {
return err
}
cmd.PersistentFlags().String("video", "", "video codec parameters to use for streaming")
if err := viper.BindPFlag("video", cmd.PersistentFlags().Lookup("video")); err != nil {
return err
}
// 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
}
2020-11-02 04:09:48 +13:00
// broadcast
cmd.PersistentFlags().String("broadcast_pipeline", "", "audio video codec parameters to use for broadcasting")
if err := viper.BindPFlag("broadcast_pipeline", cmd.PersistentFlags().Lookup("broadcast_pipeline")); err != nil {
return err
}
2021-01-23 06:13:32 +13:00
// screencast
cmd.PersistentFlags().Bool("screencast", false, "enable screencast")
if err := viper.BindPFlag("screencast", cmd.PersistentFlags().Lookup("screencast")); err != nil {
return err
}
2021-01-23 06:44:27 +13:00
cmd.PersistentFlags().String("screencast_rate", "10/1", "set screencast frame rate")
if err := viper.BindPFlag("screencast_rate", cmd.PersistentFlags().Lookup("screencast_rate")); err != nil {
return err
}
cmd.PersistentFlags().String("screencast_quality", "60", "set screencast JPEG quality")
if err := viper.BindPFlag("screencast_quality", cmd.PersistentFlags().Lookup("screencast_quality")); err != nil {
return err
}
2021-01-23 06:13:32 +13:00
cmd.PersistentFlags().String("screencast_pipeline", "", "custom screencast pipeline")
if err := viper.BindPFlag("screencast_pipeline", cmd.PersistentFlags().Lookup("screencast_pipeline")); err != nil {
return err
}
return nil
}
2020-11-02 04:09:48 +13:00
func (s *Capture) Set() {
2021-02-02 11:50:18 +13:00
var videoCodec codec.RTP
if viper.GetBool("vp8") {
2021-02-02 11:50:18 +13:00
videoCodec = codec.New(codec.VP8)
} else if viper.GetBool("vp9") {
2021-02-02 11:50:18 +13:00
videoCodec = codec.New(codec.VP9)
} else if viper.GetBool("h264") {
2021-02-02 11:50:18 +13:00
videoCodec = codec.New(codec.H264)
} else {
// default
videoCodec = codec.New(codec.VP8)
}
2021-02-02 11:50:18 +13:00
var audioCodec codec.RTP
if viper.GetBool("opus") {
2021-02-02 11:50:18 +13:00
audioCodec = codec.New(codec.Opus)
} else if viper.GetBool("g722") {
2021-02-02 11:50:18 +13:00
audioCodec = codec.New(codec.G722)
} else if viper.GetBool("pcmu") {
2021-02-02 11:50:18 +13:00
audioCodec = codec.New(codec.PCMU)
} else if viper.GetBool("pcma") {
2021-02-02 11:50:18 +13:00
audioCodec = codec.New(codec.PCMA)
} else {
// default
audioCodec = codec.New(codec.Opus)
}
s.Device = viper.GetString("device")
s.AudioCodec = audioCodec
s.AudioParams = viper.GetString("audio")
s.Display = viper.GetString("display")
s.VideoCodec = videoCodec
s.VideoParams = viper.GetString("video")
2021-01-23 06:13:32 +13:00
2020-11-02 04:09:48 +13:00
s.BroadcastPipeline = viper.GetString("broadcast_pipeline")
2021-01-23 06:13:32 +13:00
s.Screencast = viper.GetBool("screencast")
2021-01-23 06:44:27 +13:00
s.ScreencastRate = viper.GetString("screencast_rate")
s.ScreencastQuality = viper.GetString("screencast_quality")
2021-01-23 06:13:32 +13:00
s.ScreencastPipeline = viper.GetString("screencast_pipeline")
}