neko/internal/capture/broadcast.go
2020-11-14 13:46:12 +01:00

63 lines
1.4 KiB
Go

package capture
import (
"demodesk/neko/internal/capture/gst"
)
func (manager *CaptureManagerCtx) StartBroadcast(url string) {
manager.broadcast_url = url
manager.broadcasting = true
manager.createBroadcastPipeline()
}
func (manager *CaptureManagerCtx) StopBroadcast() {
manager.broadcasting = false
manager.destroyBroadcastPipeline()
}
func (manager *CaptureManagerCtx) BroadcastEnabled() bool {
return manager.broadcasting
}
func (manager *CaptureManagerCtx) BroadcastUrl() string {
return manager.broadcast_url
}
func (manager *CaptureManagerCtx) createBroadcastPipeline() {
var err error
if manager.broadcast != nil || !manager.BroadcastEnabled() {
return
}
manager.logger.Info().
Str("audio_device", manager.config.Device).
Str("video_display", manager.config.Display).
Str("broadcast_pipeline", manager.config.BroadcastPipeline).
Msgf("creating broadcast pipeline")
manager.broadcast, err = gst.CreateRTMPPipeline(
manager.config.Device,
manager.config.Display,
manager.config.BroadcastPipeline,
manager.broadcast_url,
)
if err != nil {
manager.logger.Panic().Err(err).Msg("unable to create broadcast pipeline")
}
manager.broadcast.Play()
manager.logger.Info().Msgf("starting broadcast pipeline")
}
func (manager *CaptureManagerCtx) destroyBroadcastPipeline() {
if manager.broadcast == nil {
return
}
manager.broadcast.Stop()
manager.logger.Info().Msgf("stopping broadcast pipeline")
manager.broadcast = nil
}