Archived
2
0

Merge pull request #9 from m1k1o/broadcast

Custom Broadcast Pipeline + stereo
This commit is contained in:
Miroslav Šedivý 2020-09-27 12:20:28 +02:00 committed by GitHub
commit 030e695e4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 5 deletions

View File

@ -20,6 +20,7 @@ func init() {
neko.Service.Server, neko.Service.Server,
neko.Service.WebRTC, neko.Service.WebRTC,
neko.Service.Remote, neko.Service.Remote,
neko.Service.Broadcast,
neko.Service.WebSocket, neko.Service.WebSocket,
} }

View File

@ -12,14 +12,16 @@ type BroadcastManager struct {
logger zerolog.Logger logger zerolog.Logger
pipeline *gst.Pipeline pipeline *gst.Pipeline
remote *config.Remote remote *config.Remote
config *config.Broadcast
enabled bool enabled bool
url string url string
} }
func New(remote *config.Remote) *BroadcastManager { func New(remote *config.Remote, config *config.Broadcast) *BroadcastManager {
return &BroadcastManager{ return &BroadcastManager{
logger: log.With().Str("module", "remote").Logger(), logger: log.With().Str("module", "remote").Logger(),
remote: remote, remote: remote,
config: config,
enabled: false, enabled: false,
url: "", url: "",
} }
@ -34,6 +36,7 @@ func (manager *BroadcastManager) Start() {
manager.pipeline, err = gst.CreateRTMPPipeline( manager.pipeline, err = gst.CreateRTMPPipeline(
manager.remote.Device, manager.remote.Device,
manager.remote.Display, manager.remote.Display,
manager.config.Pipeline,
manager.url, manager.url,
) )

View File

@ -56,7 +56,7 @@ const (
audioClockRate = 48000 audioClockRate = 48000
pcmClockRate = 8000 pcmClockRate = 8000
videoSrc = "ximagesrc xid=%s show-pointer=true use-damage=false ! video/x-raw ! videoconvert ! queue ! " 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() { func init() {
@ -65,11 +65,18 @@ func init() {
} }
// CreateRTMPPipeline creates a GStreamer Pipeline // 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) video := fmt.Sprintf(videoSrc, pipelineDisplay)
audio := fmt.Sprintf(audioSrc, pipelineDevice) 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 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)
} }
// CreateAppPipeline creates a GStreamer Pipeline // CreateAppPipeline creates a GStreamer Pipeline

View File

@ -0,0 +1,23 @@
package config
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
type Broadcast struct {
Pipeline string
}
func (Broadcast) Init(cmd *cobra.Command) error {
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.Pipeline = viper.GetString("broadcast_pipeline")
}

View File

@ -62,6 +62,7 @@ func init() {
Root: &config.Root{}, Root: &config.Root{},
Server: &config.Server{}, Server: &config.Server{},
Remote: &config.Remote{}, Remote: &config.Remote{},
Broadcast: &config.Broadcast{},
WebRTC: &config.WebRTC{}, WebRTC: &config.WebRTC{},
WebSocket: &config.WebSocket{}, WebSocket: &config.WebSocket{},
} }
@ -100,6 +101,7 @@ type Neko struct {
Version *Version Version *Version
Root *config.Root Root *config.Root
Remote *config.Remote Remote *config.Remote
Broadcast *config.Broadcast
Server *config.Server Server *config.Server
WebRTC *config.WebRTC WebRTC *config.WebRTC
WebSocket *config.WebSocket WebSocket *config.WebSocket
@ -118,7 +120,7 @@ func (neko *Neko) Preflight() {
} }
func (neko *Neko) Start() { func (neko *Neko) Start() {
broadcastManager := broadcast.New(neko.Remote) broadcastManager := broadcast.New(neko.Remote, neko.Broadcast)
remoteManager := remote.New(neko.Remote, broadcastManager) remoteManager := remote.New(neko.Remote, broadcastManager)
remoteManager.Start() remoteManager.Start()