2020-10-23 03:54:50 +13:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2021-03-12 05:55:13 +13:00
|
|
|
"os"
|
|
|
|
|
2020-10-23 03:54:50 +13:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
2021-02-02 11:50:18 +13:00
|
|
|
|
|
|
|
"demodesk/neko/internal/types/codec"
|
2020-10-23 03:54:50 +13:00
|
|
|
)
|
|
|
|
|
2020-11-02 04:09:48 +13:00
|
|
|
type Capture struct {
|
2021-03-12 05:55:13 +13:00
|
|
|
Display string
|
|
|
|
|
|
|
|
AudioDevice string
|
2021-02-15 02:40:17 +13:00
|
|
|
AudioCodec codec.RTPCodec
|
|
|
|
AudioPipeline string
|
2021-02-06 03:10:41 +13:00
|
|
|
|
2021-02-15 02:40:17 +13:00
|
|
|
BroadcastPipeline string
|
2021-02-06 03:10:41 +13:00
|
|
|
|
|
|
|
Screencast bool
|
|
|
|
ScreencastRate string
|
|
|
|
ScreencastQuality string
|
2021-01-23 06:13:32 +13:00
|
|
|
ScreencastPipeline string
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|
|
|
|
|
2020-11-02 04:09:48 +13:00
|
|
|
func (Capture) Init(cmd *cobra.Command) error {
|
2021-03-12 05:55:13 +13:00
|
|
|
// audio
|
|
|
|
cmd.PersistentFlags().String("audio_device", "auto_null.monitor", "audio device to capture")
|
|
|
|
if err := viper.BindPFlag("audio_device", cmd.PersistentFlags().Lookup("audio_device")); err != nil {
|
2020-10-23 03:54:50 +13:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-03-12 05:55:13 +13:00
|
|
|
cmd.PersistentFlags().String("audio_pipeline", "", "gstreamer pipeline used for audio streaming")
|
|
|
|
if err := viper.BindPFlag("audio_pipeline", cmd.PersistentFlags().Lookup("audio_pipeline")); err != nil {
|
2020-10-23 03:54:50 +13:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2021-03-12 05:55:13 +13:00
|
|
|
cmd.PersistentFlags().String("broadcast_pipeline", "", "gstreamer pipeline used for broadcasting")
|
2020-11-02 04:09:48 +13:00
|
|
|
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-03-12 05:55:13 +13:00
|
|
|
cmd.PersistentFlags().String("screencast_rate", "10/1", "screencast frame rate")
|
2021-01-23 06:44:27 +13:00
|
|
|
if err := viper.BindPFlag("screencast_rate", cmd.PersistentFlags().Lookup("screencast_rate")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-03-12 05:55:13 +13:00
|
|
|
cmd.PersistentFlags().String("screencast_quality", "60", "screencast JPEG quality")
|
2021-01-23 06:44:27 +13:00
|
|
|
if err := viper.BindPFlag("screencast_quality", cmd.PersistentFlags().Lookup("screencast_quality")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-03-12 05:55:13 +13:00
|
|
|
cmd.PersistentFlags().String("screencast_pipeline", "", "gstreamer pipeline used for screencasting")
|
2021-01-23 06:13:32 +13:00
|
|
|
if err := viper.BindPFlag("screencast_pipeline", cmd.PersistentFlags().Lookup("screencast_pipeline")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-10-23 03:54:50 +13:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-11-02 04:09:48 +13:00
|
|
|
func (s *Capture) Set() {
|
2021-03-12 05:55:13 +13:00
|
|
|
// Display is provided by env variable
|
|
|
|
s.Display = os.Getenv("DISPLAY")
|
|
|
|
|
|
|
|
s.AudioDevice = viper.GetString("audio_device")
|
|
|
|
s.AudioPipeline = viper.GetString("audio_pipeline")
|
|
|
|
|
2020-10-23 03:54:50 +13:00
|
|
|
if viper.GetBool("opus") {
|
2021-03-12 05:55:13 +13:00
|
|
|
s.AudioCodec = codec.Opus()
|
2020-10-23 03:54:50 +13:00
|
|
|
} else if viper.GetBool("g722") {
|
2021-03-12 05:55:13 +13:00
|
|
|
s.AudioCodec = codec.G722()
|
2020-10-23 03:54:50 +13:00
|
|
|
} else if viper.GetBool("pcmu") {
|
2021-03-12 05:55:13 +13:00
|
|
|
s.AudioCodec = codec.PCMU()
|
2020-10-23 03:54:50 +13:00
|
|
|
} else if viper.GetBool("pcma") {
|
2021-03-12 05:55:13 +13:00
|
|
|
s.AudioCodec = codec.PCMA()
|
2021-02-02 11:50:18 +13:00
|
|
|
} else {
|
|
|
|
// default
|
2021-03-12 05:55:13 +13:00
|
|
|
s.AudioCodec = codec.Opus()
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|
|
|
|
|
2020-11-02 04:09:48 +13:00
|
|
|
s.BroadcastPipeline = viper.GetString("broadcast_pipeline")
|
2021-02-06 03:10:41 +13:00
|
|
|
|
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")
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|