50 lines
1,019 B
Go
50 lines
1,019 B
Go
package gstreamer
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"github.com/tinyzimmer/go-glib/glib"
|
|
"github.com/tinyzimmer/go-gst/gst"
|
|
)
|
|
|
|
var gstreamer *Gstreamer
|
|
|
|
func Init() *Gstreamer {
|
|
gst.Init(nil)
|
|
mainLoop := glib.NewMainLoop(glib.MainContextDefault(), false)
|
|
go mainLoop.Run()
|
|
decklink := &Decklink{
|
|
Slots: map[string]string{"one": ""},
|
|
}
|
|
gstreamer = &Gstreamer{
|
|
ctx: context.Background(),
|
|
Pipelines: map[string]*Pipeline{},
|
|
Decklink: decklink,
|
|
}
|
|
return gstreamer
|
|
}
|
|
|
|
func (g *Gstreamer) DeletePipeline(id string) {
|
|
g.Lock()
|
|
defer g.Unlock()
|
|
if pipeline, err := g.getPipeline(id); err == nil {
|
|
delete(g.Pipelines, id)
|
|
pipeline.ctxCancel()
|
|
}
|
|
return
|
|
}
|
|
|
|
func (g *Gstreamer) GetPipeline(id string) (*Pipeline, error) {
|
|
g.RLock()
|
|
defer g.RUnlock()
|
|
return g.getPipeline(id)
|
|
}
|
|
|
|
//only use this if ressource is locked
|
|
func (g *Gstreamer) getPipeline(id string) (*Pipeline, error) {
|
|
if pipeline, ok := g.Pipelines[id]; ok {
|
|
return pipeline, nil
|
|
}
|
|
return nil, errors.New("Pipeline not found")
|
|
}
|