From f2eab73847fd4eaaafd31140b2a16fb57e2165e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Thu, 18 Jul 2024 18:58:40 +0200 Subject: [PATCH] WIP: legacy config integration. --- server/internal/capture/broadcast.go | 4 ++-- server/internal/capture/manager.go | 2 +- server/internal/config/capture.go | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/server/internal/capture/broadcast.go b/server/internal/capture/broadcast.go index 2ded2cd0..0b056c02 100644 --- a/server/internal/capture/broadcast.go +++ b/server/internal/capture/broadcast.go @@ -28,7 +28,7 @@ type BroacastManagerCtx struct { 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(). Str("module", "capture"). Str("submodule", "broadcast"). @@ -38,7 +38,7 @@ func broadcastNew(pipelineFn func(url string) (string, error), defaultUrl string logger: logger, pipelineFn: pipelineFn, url: defaultUrl, - started: defaultUrl != "", + started: defaultUrl != "" && autostart, // metrics pipelinesCounter: promauto.NewCounter(prometheus.CounterOpts{ diff --git a/server/internal/capture/manager.go b/server/internal/capture/manager.go index 2a71485e..f4d004c0 100644 --- a/server/internal/capture/manager.go +++ b/server/internal/capture/manager.go @@ -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 "+ "! mux.", url, config.AudioDevice, config.BroadcastAudioBitrate*1000, config.Display, config.BroadcastVideoBitrate, config.BroadcastPreset, ), nil - }, config.BroadcastUrl), + }, config.BroadcastUrl, config.BroadcastAutostart), screencast: screencastNew(config.ScreencastEnabled, func() string { if config.ScreencastPipeline != "" { // replace {display} with valid display diff --git a/server/internal/config/capture.go b/server/internal/config/capture.go index 6e23b4a8..9f870dc5 100644 --- a/server/internal/config/capture.go +++ b/server/internal/config/capture.go @@ -28,6 +28,7 @@ type Capture struct { BroadcastPreset string BroadcastPipeline string BroadcastUrl string + BroadcastAutostart bool ScreencastEnabled bool ScreencastRate string @@ -102,6 +103,11 @@ func (Capture) Init(cmd *cobra.Command) error { 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 cmd.PersistentFlags().Bool("capture.screencast.enabled", false, "enable screencast") 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.BroadcastPipeline = viper.GetString("capture.broadcast.pipeline") s.BroadcastUrl = viper.GetString("capture.broadcast.url") + s.BroadcastAutostart = viper.GetBool("capture.broadcast.autostart") // screencast s.ScreencastEnabled = viper.GetBool("capture.screencast.enabled")