refactor broadcast pipeline.

This commit is contained in:
Miroslav Šedivý 2021-09-30 20:06:43 +02:00
parent 4debddf27d
commit c9c8cc67ca

View File

@ -14,18 +14,26 @@ import (
type BroacastManagerCtx struct { type BroacastManagerCtx struct {
logger zerolog.Logger logger zerolog.Logger
mu sync.Mutex mu sync.Mutex
pipelineStr string
pipeline *gst.Pipeline pipeline *gst.Pipeline
started bool pipelineStr string
pipelineMu sync.Mutex
url string url string
started bool
} }
func broadcastNew(pipelineStr string) *BroacastManagerCtx { func broadcastNew(pipelineStr string) *BroacastManagerCtx {
logger := log.With().
Str("module", "capture").
Str("submodule", "broadcast").
Logger()
return &BroacastManagerCtx{ return &BroacastManagerCtx{
logger: log.With().Str("module", "capture").Str("submodule", "broadcast").Logger(), logger: logger,
pipelineStr: pipelineStr, pipelineStr: pipelineStr,
started: false,
url: "", url: "",
started: false,
} }
} }
@ -58,14 +66,23 @@ func (manager *BroacastManagerCtx) Stop() {
} }
func (manager *BroacastManagerCtx) Started() bool { func (manager *BroacastManagerCtx) Started() bool {
manager.mu.Lock()
defer manager.mu.Unlock()
return manager.started return manager.started
} }
func (manager *BroacastManagerCtx) Url() string { func (manager *BroacastManagerCtx) Url() string {
manager.mu.Lock()
defer manager.mu.Unlock()
return manager.url return manager.url
} }
func (manager *BroacastManagerCtx) createPipeline() error { func (manager *BroacastManagerCtx) createPipeline() error {
manager.pipelineMu.Lock()
defer manager.pipelineMu.Unlock()
if manager.pipeline != nil { if manager.pipeline != nil {
return types.ErrCapturePipelineAlreadyExists return types.ErrCapturePipelineAlreadyExists
} }
@ -89,6 +106,9 @@ func (manager *BroacastManagerCtx) createPipeline() error {
} }
func (manager *BroacastManagerCtx) destroyPipeline() { func (manager *BroacastManagerCtx) destroyPipeline() {
manager.pipelineMu.Lock()
defer manager.pipelineMu.Unlock()
if manager.pipeline == nil { if manager.pipeline == nil {
return return
} }