2020-11-02 04:09:48 +13:00
|
|
|
package capture
|
|
|
|
|
|
|
|
import (
|
|
|
|
"demodesk/neko/internal/capture/gst"
|
|
|
|
)
|
|
|
|
|
2020-11-19 09:34:39 +13:00
|
|
|
func (manager *CaptureManagerCtx) StartBroadcast(url string) error {
|
2020-11-15 01:46:12 +13:00
|
|
|
manager.broadcast_url = url
|
|
|
|
manager.broadcasting = true
|
2020-11-19 09:34:39 +13:00
|
|
|
return manager.createBroadcastPipeline()
|
2020-11-15 01:46:12 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-11-19 09:34:39 +13:00
|
|
|
func (manager *CaptureManagerCtx) createBroadcastPipeline() error {
|
2020-11-02 04:09:48 +13:00
|
|
|
var err error
|
|
|
|
|
|
|
|
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 {
|
2020-11-19 09:34:39 +13:00
|
|
|
return err
|
2020-11-02 04:09:48 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
manager.broadcast.Play()
|
2020-11-14 05:42:04 +13:00
|
|
|
manager.logger.Info().Msgf("starting broadcast pipeline")
|
2020-11-19 09:34:39 +13:00
|
|
|
return nil
|
2020-11-02 04:09:48 +13:00
|
|
|
}
|
|
|
|
|
2020-11-15 01:46:12 +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
|
|
|
|
}
|