WIP: legacy config integration.

This commit is contained in:
Miroslav Šedivý 2024-07-18 18:58:40 +02:00
parent 51fb1e7bbe
commit f2eab73847
3 changed files with 10 additions and 3 deletions

View File

@ -28,7 +28,7 @@ type BroacastManagerCtx struct {
pipelinesActive prometheus.Gauge pipelinesActive prometheus.Gauge
} }
func broadcastNew(pipelineFn func(url string) (string, error), defaultUrl string) *BroacastManagerCtx { func broadcastNew(pipelineFn func(url string) (string, error), defaultUrl string, autostart bool) *BroacastManagerCtx {
logger := log.With(). logger := log.With().
Str("module", "capture"). Str("module", "capture").
Str("submodule", "broadcast"). Str("submodule", "broadcast").
@ -38,7 +38,7 @@ func broadcastNew(pipelineFn func(url string) (string, error), defaultUrl string
logger: logger, logger: logger,
pipelineFn: pipelineFn, pipelineFn: pipelineFn,
url: defaultUrl, url: defaultUrl,
started: defaultUrl != "", started: defaultUrl != "" && autostart,
// metrics // metrics
pipelinesCounter: promauto.NewCounter(prometheus.CounterOpts{ pipelinesCounter: promauto.NewCounter(prometheus.CounterOpts{

View File

@ -103,7 +103,7 @@ func New(desktop types.DesktopManager, config *config.Capture) *CaptureManagerCt
"! x264enc threads=4 bitrate=%d key-int-max=15 byte-stream=true tune=zerolatency speed-preset=%s "+ "! x264enc threads=4 bitrate=%d key-int-max=15 byte-stream=true tune=zerolatency speed-preset=%s "+
"! mux.", url, config.AudioDevice, config.BroadcastAudioBitrate*1000, config.Display, config.BroadcastVideoBitrate, config.BroadcastPreset, "! mux.", url, config.AudioDevice, config.BroadcastAudioBitrate*1000, config.Display, config.BroadcastVideoBitrate, config.BroadcastPreset,
), nil ), nil
}, config.BroadcastUrl), }, config.BroadcastUrl, config.BroadcastAutostart),
screencast: screencastNew(config.ScreencastEnabled, func() string { screencast: screencastNew(config.ScreencastEnabled, func() string {
if config.ScreencastPipeline != "" { if config.ScreencastPipeline != "" {
// replace {display} with valid display // replace {display} with valid display

View File

@ -28,6 +28,7 @@ type Capture struct {
BroadcastPreset string BroadcastPreset string
BroadcastPipeline string BroadcastPipeline string
BroadcastUrl string BroadcastUrl string
BroadcastAutostart bool
ScreencastEnabled bool ScreencastEnabled bool
ScreencastRate string ScreencastRate string
@ -102,6 +103,11 @@ func (Capture) Init(cmd *cobra.Command) error {
return err return err
} }
cmd.PersistentFlags().Bool("capture.broadcast.autostart", true, "automatically start broadcasting when neko starts and broadcast_url is set")
if err := viper.BindPFlag("capture.broadcast.autostart", cmd.PersistentFlags().Lookup("capture.broadcast.autostart")); err != nil {
return err
}
// screencast // screencast
cmd.PersistentFlags().Bool("capture.screencast.enabled", false, "enable screencast") cmd.PersistentFlags().Bool("capture.screencast.enabled", false, "enable screencast")
if err := viper.BindPFlag("capture.screencast.enabled", cmd.PersistentFlags().Lookup("capture.screencast.enabled")); err != nil { if err := viper.BindPFlag("capture.screencast.enabled", cmd.PersistentFlags().Lookup("capture.screencast.enabled")); err != nil {
@ -227,6 +233,7 @@ func (s *Capture) Set() {
s.BroadcastPreset = viper.GetString("capture.broadcast.preset") s.BroadcastPreset = viper.GetString("capture.broadcast.preset")
s.BroadcastPipeline = viper.GetString("capture.broadcast.pipeline") s.BroadcastPipeline = viper.GetString("capture.broadcast.pipeline")
s.BroadcastUrl = viper.GetString("capture.broadcast.url") s.BroadcastUrl = viper.GetString("capture.broadcast.url")
s.BroadcastAutostart = viper.GetBool("capture.broadcast.autostart")
// screencast // screencast
s.ScreencastEnabled = viper.GetBool("capture.screencast.enabled") s.ScreencastEnabled = viper.GetBool("capture.screencast.enabled")