neko/internal/capture/broadcast.go

63 lines
1.4 KiB
Go
Raw Normal View History

2020-11-02 04:09:48 +13:00
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() {
2020-11-02 04:09:48 +13:00
var err error
2020-11-02 05:34:47 +13:00
if manager.broadcast != nil || !manager.BroadcastEnabled() {
2020-11-02 04:09:48 +13:00
return
}
manager.logger.Info().
Str("audio_device", manager.config.Device).
Str("video_display", manager.config.Display).
2020-11-02 05:34:47 +13:00
Str("broadcast_pipeline", manager.config.BroadcastPipeline).
2020-11-14 05:42:04 +13:00
Msgf("creating broadcast pipeline")
2020-11-02 04:09:48 +13:00
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()
2020-11-14 05:42:04 +13:00
manager.logger.Info().Msgf("starting broadcast pipeline")
2020-11-02 04:09:48 +13:00
}
func (manager *CaptureManagerCtx) destroyBroadcastPipeline() {
2020-11-02 05:34:47 +13:00
if manager.broadcast == nil {
2020-11-02 04:09:48 +13:00
return
}
2020-11-02 08:18:19 +13:00
manager.broadcast.Stop()
2020-11-14 05:42:04 +13:00
manager.logger.Info().Msgf("stopping broadcast pipeline")
2020-11-02 04:09:48 +13:00
manager.broadcast = nil
}