From de04cac28e687ba59659a134745818d561213ca0 Mon Sep 17 00:00:00 2001 From: m1k1o Date: Sun, 27 Sep 2020 12:06:13 +0200 Subject: [PATCH 1/3] Revert "remove broadcast Config" This reverts commit 88c0337a164345d269364fb2819fe0916b3c2873. --- server/cmd/serve.go | 1 + server/internal/broadcast/manager.go | 4 ++- server/internal/types/config/broadcast.go | 37 +++++++++++++++++++++++ server/neko.go | 4 ++- 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 server/internal/types/config/broadcast.go diff --git a/server/cmd/serve.go b/server/cmd/serve.go index 2c7dfde..b6a7807 100644 --- a/server/cmd/serve.go +++ b/server/cmd/serve.go @@ -20,6 +20,7 @@ func init() { neko.Service.Server, neko.Service.WebRTC, neko.Service.Remote, + neko.Service.Broadcast, neko.Service.WebSocket, } diff --git a/server/internal/broadcast/manager.go b/server/internal/broadcast/manager.go index 8937ffa..bca83cf 100644 --- a/server/internal/broadcast/manager.go +++ b/server/internal/broadcast/manager.go @@ -12,14 +12,16 @@ type BroadcastManager struct { logger zerolog.Logger pipeline *gst.Pipeline remote *config.Remote + config *config.Broadcast enabled bool url string } -func New(remote *config.Remote) *BroadcastManager { +func New(remote *config.Remote, config *config.Broadcast) *BroadcastManager { return &BroadcastManager{ logger: log.With().Str("module", "remote").Logger(), remote: remote, + config: config, enabled: false, url: "", } diff --git a/server/internal/types/config/broadcast.go b/server/internal/types/config/broadcast.go new file mode 100644 index 0000000..f928448 --- /dev/null +++ b/server/internal/types/config/broadcast.go @@ -0,0 +1,37 @@ +package config + +import ( + "github.com/spf13/cobra" + "github.com/spf13/viper" +) + +type Broadcast struct { + // Enabled bool + // AudioParams string + // VideoParams string +} + +func (Broadcast) Init(cmd *cobra.Command) error { + // cmd.PersistentFlags().Bool("broadcast", false, "enable boradcasting") + // if err := viper.BindPFlag("broadcast", cmd.PersistentFlags().Lookup("broadcast")); err != nil { + // return err + // } + + // cmd.PersistentFlags().String("cast_audio", "", "audio codec parameters to use for broadcasting") + // if err := viper.BindPFlag("cast_audio", cmd.PersistentFlags().Lookup("cast_audio")); err != nil { + // return err + // } + + // cmd.PersistentFlags().String("cast_video", "", "video codec parameters to use for broadcasting") + // if err := viper.BindPFlag("cast_video", cmd.PersistentFlags().Lookup("cast_video")); err != nil { + // return err + // } + + return nil +} + +func (s *Broadcast) Set() { + // s.Enabled = viper.GetBool("broadcast") + // s.AudioParams = viper.GetString("cast_audio") + // s.VideoParams = viper.GetString("cast_video") +} diff --git a/server/neko.go b/server/neko.go index 7d4dabb..6c3d616 100644 --- a/server/neko.go +++ b/server/neko.go @@ -62,6 +62,7 @@ func init() { Root: &config.Root{}, Server: &config.Server{}, Remote: &config.Remote{}, + Broadcast: &config.Broadcast{}, WebRTC: &config.WebRTC{}, WebSocket: &config.WebSocket{}, } @@ -100,6 +101,7 @@ type Neko struct { Version *Version Root *config.Root Remote *config.Remote + Broadcast *config.Broadcast Server *config.Server WebRTC *config.WebRTC WebSocket *config.WebSocket @@ -118,7 +120,7 @@ func (neko *Neko) Preflight() { } func (neko *Neko) Start() { - broadcastManager := broadcast.New(neko.Remote) + broadcastManager := broadcast.New(neko.Remote, neko.Broadcast) remoteManager := remote.New(neko.Remote, broadcastManager) remoteManager.Start() From d02617329bdf4384f6fbebba517302229568c47a Mon Sep 17 00:00:00 2001 From: m1k1o Date: Sun, 27 Sep 2020 12:09:45 +0200 Subject: [PATCH 2/3] custom RTMP pipeline --- server/internal/broadcast/manager.go | 1 + server/internal/gst/gst.go | 11 ++++++++-- server/internal/types/config/broadcast.go | 26 ++++++----------------- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/server/internal/broadcast/manager.go b/server/internal/broadcast/manager.go index bca83cf..d6ebbe0 100644 --- a/server/internal/broadcast/manager.go +++ b/server/internal/broadcast/manager.go @@ -36,6 +36,7 @@ func (manager *BroadcastManager) Start() { manager.pipeline, err = gst.CreateRTMPPipeline( manager.remote.Device, manager.remote.Display, + manager.config.Pipeline, manager.url, ) diff --git a/server/internal/gst/gst.go b/server/internal/gst/gst.go index e2679de..5844609 100644 --- a/server/internal/gst/gst.go +++ b/server/internal/gst/gst.go @@ -65,11 +65,18 @@ func init() { } // CreateRTMPPipeline creates a GStreamer Pipeline -func CreateRTMPPipeline(pipelineDevice string, pipelineDisplay string, pipelineRTMP string) (*Pipeline, error) { +func CreateRTMPPipeline(pipelineDevice string, pipelineDisplay string, pipelineSrc string, pipelineRTMP string) (*Pipeline, error) { video := fmt.Sprintf(videoSrc, pipelineDisplay) audio := fmt.Sprintf(audioSrc, pipelineDevice) - return CreatePipeline(fmt.Sprintf("flvmux name=mux ! rtmpsink location='%s live=1' %s voaacenc ! mux. %s x264enc bframes=0 key-int-max=60 byte-stream=true tune=zerolatency speed-preset=veryfast ! mux.", pipelineRTMP, audio, video), "", 0) + var pipelineStr string + if pipelineSrc != "" { + pipelineStr = fmt.Sprintf(pipelineSrc, pipelineRTMP, pipelineDevice, pipelineDisplay) + } else { + pipelineStr = fmt.Sprintf("flvmux name=mux ! rtmpsink location='%s live=1' %s ! voaacenc ! mux. %s x264enc bframes=0 key-int-max=60 byte-stream=true tune=zerolatency speed-preset=veryfast ! mux.", pipelineRTMP, audio, video) + } + + return CreatePipeline(pipelineStr, "", 0) } // CreateAppPipeline creates a GStreamer Pipeline diff --git a/server/internal/types/config/broadcast.go b/server/internal/types/config/broadcast.go index f928448..22ef94a 100644 --- a/server/internal/types/config/broadcast.go +++ b/server/internal/types/config/broadcast.go @@ -6,32 +6,18 @@ import ( ) type Broadcast struct { - // Enabled bool - // AudioParams string - // VideoParams string + Pipeline string } func (Broadcast) Init(cmd *cobra.Command) error { - // cmd.PersistentFlags().Bool("broadcast", false, "enable boradcasting") - // if err := viper.BindPFlag("broadcast", cmd.PersistentFlags().Lookup("broadcast")); err != nil { - // return err - // } - - // cmd.PersistentFlags().String("cast_audio", "", "audio codec parameters to use for broadcasting") - // if err := viper.BindPFlag("cast_audio", cmd.PersistentFlags().Lookup("cast_audio")); err != nil { - // return err - // } - - // cmd.PersistentFlags().String("cast_video", "", "video codec parameters to use for broadcasting") - // if err := viper.BindPFlag("cast_video", cmd.PersistentFlags().Lookup("cast_video")); err != nil { - // return err - // } + cmd.PersistentFlags().String("broadcast_pipeline", "", "audio codec parameters to use for broadcasting") + if err := viper.BindPFlag("broadcast_pipeline", cmd.PersistentFlags().Lookup("broadcast_pipeline")); err != nil { + return err + } return nil } func (s *Broadcast) Set() { - // s.Enabled = viper.GetBool("broadcast") - // s.AudioParams = viper.GetString("cast_audio") - // s.VideoParams = viper.GetString("cast_video") + s.Pipeline = viper.GetString("broadcast_pipeline") } From e81756d5cd7f4bb5ab829c65fd67a42a1049bcbd Mon Sep 17 00:00:00 2001 From: m1k1o Date: Sun, 27 Sep 2020 12:10:54 +0200 Subject: [PATCH 3/3] stereo sound --- server/internal/gst/gst.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/internal/gst/gst.go b/server/internal/gst/gst.go index 5844609..c3fcc56 100644 --- a/server/internal/gst/gst.go +++ b/server/internal/gst/gst.go @@ -56,7 +56,7 @@ const ( audioClockRate = 48000 pcmClockRate = 8000 videoSrc = "ximagesrc xid=%s show-pointer=true use-damage=false ! video/x-raw ! videoconvert ! queue ! " - audioSrc = "pulsesrc device=%s ! audioconvert ! " + audioSrc = "pulsesrc device=%s ! audio/x-raw,channels=2 ! audioconvert ! " ) func init() { @@ -73,7 +73,7 @@ func CreateRTMPPipeline(pipelineDevice string, pipelineDisplay string, pipelineS if pipelineSrc != "" { pipelineStr = fmt.Sprintf(pipelineSrc, pipelineRTMP, pipelineDevice, pipelineDisplay) } else { - pipelineStr = fmt.Sprintf("flvmux name=mux ! rtmpsink location='%s live=1' %s ! voaacenc ! mux. %s x264enc bframes=0 key-int-max=60 byte-stream=true tune=zerolatency speed-preset=veryfast ! mux.", pipelineRTMP, audio, video) + pipelineStr = fmt.Sprintf("flvmux name=mux ! rtmpsink location='%s live=1' %s audio/x-raw,channels=2 ! audioconvert ! voaacenc ! mux. %s x264enc bframes=0 key-int-max=60 byte-stream=true tune=zerolatency speed-preset=veryfast ! mux.", pipelineRTMP, audio, video) } return CreatePipeline(pipelineStr, "", 0)