neko/internal/capture/broadcast.go

87 lines
1.8 KiB
Go
Raw Normal View History

2020-11-02 04:09:48 +13:00
package capture
import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"demodesk/neko/internal/config"
2020-11-02 04:09:48 +13:00
"demodesk/neko/internal/capture/gst"
)
type BroacastManagerCtx struct {
logger zerolog.Logger
config *config.Capture
pipeline *gst.Pipeline
enabled bool
url string
}
func broadcastNew(config *config.Capture) *BroacastManagerCtx {
return &BroacastManagerCtx{
logger: log.With().Str("module", "capture").Str("submodule", "broadcast").Logger(),
config: config,
enabled: false,
url: "",
}
}
2021-02-06 00:18:46 +13:00
func (manager *BroacastManagerCtx) shutdown() {
manager.logger.Info().Msgf("shutting down")
manager.destroyPipeline()
}
func (manager *BroacastManagerCtx) Start(url string) error {
manager.url = url
manager.enabled = true
return manager.createPipeline()
}
func (manager *BroacastManagerCtx) Stop() {
manager.enabled = false
manager.destroyPipeline()
}
func (manager *BroacastManagerCtx) Enabled() bool {
return manager.enabled
}
func (manager *BroacastManagerCtx) Url() string {
return manager.url
}
func (manager *BroacastManagerCtx) createPipeline() 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).
Msgf("creating pipeline")
2021-02-03 06:28:32 +13:00
manager.pipeline, err = gst.CreateRTMPPipeline(
2020-11-02 04:09:48 +13:00
manager.config.Device,
manager.config.Display,
manager.config.BroadcastPipeline,
manager.url,
2020-11-02 04:09:48 +13:00
)
if err != nil {
return err
2020-11-02 04:09:48 +13:00
}
manager.pipeline.Play()
manager.logger.Info().Msgf("starting pipeline")
return nil
2020-11-02 04:09:48 +13:00
}
func (manager *BroacastManagerCtx) destroyPipeline() {
if manager.pipeline == nil {
2020-11-02 04:09:48 +13:00
return
}
manager.pipeline.Stop()
manager.logger.Info().Msgf("stopping pipeline")
manager.pipeline = nil
2020-11-02 04:09:48 +13:00
}