86 lines
3.7 KiB
Go
86 lines
3.7 KiB
Go
|
package gstreamer
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"github.com/rs/zerolog"
|
||
|
"github.com/tinyzimmer/go-gst/gst"
|
||
|
)
|
||
|
|
||
|
func (o *OutputElement) create(pipeline *gst.Pipeline, lastElement *element, log zerolog.Logger) error {
|
||
|
elements := map[string]element{}
|
||
|
|
||
|
e, err := gst.NewElementWithName("videoconvert", fmt.Sprintf("%s-videoconvert", o.Name))
|
||
|
if err != nil {
|
||
|
log.Error().Msgf("could not create videoconvert for %s: %v\n", o.Name, err)
|
||
|
return fmt.Errorf("could not create videoconvert for %s", o.Name)
|
||
|
}
|
||
|
err = pipeline.Add(e)
|
||
|
if err != nil {
|
||
|
log.Error().Msgf("could not add videoconvert for %s to pipeline: %v\n", o.Name, err)
|
||
|
return fmt.Errorf("could not add videoconvert for %s to pipeline", o.Name)
|
||
|
}
|
||
|
videoconvert := element{element: e, name: fmt.Sprintf("%s-videoconvert", o.Name), prev: lastElement.name, next: fmt.Sprintf("%s-videoscale", o.Name), inputCaps: o.Caps}
|
||
|
elements[fmt.Sprintf("%s-videoconvert", o.Name)] = videoconvert
|
||
|
err = lastElement.linkElementWrapper(&videoconvert, log)
|
||
|
if err != nil {
|
||
|
log.Error().Msgf("could not link %s to %s: %v\n", o.Name, fmt.Sprintf("%s-videoconvert", o.Name), err)
|
||
|
return fmt.Errorf("could not link %s to %s", o.Name, fmt.Sprintf("%s-videoconvert", o.Name))
|
||
|
}
|
||
|
|
||
|
e, err = gst.NewElementWithName("videoscale", fmt.Sprintf("%s-videoscale", o.Name))
|
||
|
if err != nil {
|
||
|
log.Error().Msgf("could not create videoscale for %s: %v\n", o.Name, err)
|
||
|
return fmt.Errorf("could not create videoscale for %s", o.Name)
|
||
|
}
|
||
|
err = pipeline.Add(e)
|
||
|
if err != nil {
|
||
|
log.Error().Msgf("could not add videoscale for %s to pipeline: %v\n", o.Name, err)
|
||
|
return fmt.Errorf("could not add videoscale for %s to pipeline", o.Name)
|
||
|
}
|
||
|
videoscale := element{element: e, name: fmt.Sprintf("%s-videoscale", o.Name), prev: fmt.Sprintf("%s-videoconvert", o.Name), next: fmt.Sprintf("%s-videorate", o.Name)}
|
||
|
elements[fmt.Sprintf("%s-videoscale", o.Name)] = videoscale
|
||
|
err = videoconvert.linkElementWrapper(&videoscale, log)
|
||
|
if err != nil {
|
||
|
log.Error().Msgf("could not link %s to %s: %v\n", fmt.Sprintf("%s-videoconvert", o.Name), fmt.Sprintf("%s-videoscale", o.Name), err)
|
||
|
return fmt.Errorf("could not link %s to %s", fmt.Sprintf("%s-videoconvert", o.Name), fmt.Sprintf("%s-videoscale", o.Name))
|
||
|
}
|
||
|
|
||
|
e, err = gst.NewElementWithName("videorate", fmt.Sprintf("%s-videorate", o.Name))
|
||
|
if err != nil {
|
||
|
log.Error().Msgf("could not create videorate for %s: %v\n", o.Name, err)
|
||
|
return fmt.Errorf("could not create videorate for %s", o.Name)
|
||
|
}
|
||
|
err = pipeline.Add(e)
|
||
|
if err != nil {
|
||
|
log.Error().Msgf("could not add videorate for %s to pipeline: %v\n", o.Name, err)
|
||
|
return fmt.Errorf("could not add videorate for %s to pipeline", o.Name)
|
||
|
}
|
||
|
videorate := element{element: e, name: fmt.Sprintf("%s-videorate", o.Name), prev: fmt.Sprintf("%s-videoscale", o.Name), next: o.Name}
|
||
|
elements[fmt.Sprintf("%s-videorate", o.Name)] = videorate
|
||
|
err = videoscale.linkElementWrapper(&videorate, log)
|
||
|
if err != nil {
|
||
|
log.Error().Msgf("could not link %s to %s: %v\n", fmt.Sprintf("%s-videoscale", o.Name), fmt.Sprintf("%s-videorate", o.Name), err)
|
||
|
return fmt.Errorf("could not link %s to %s", fmt.Sprintf("%s-videoscale", o.Name), fmt.Sprintf("%s-videorate", o.Name))
|
||
|
}
|
||
|
|
||
|
e, err = gst.NewElementWithName(o.Type, o.Name)
|
||
|
if err != nil {
|
||
|
log.Error().Msgf("could not create element %s: %v\n", o.Name, err)
|
||
|
return fmt.Errorf("could not create element %s", o.Name)
|
||
|
}
|
||
|
for prop, value := range o.Properties {
|
||
|
setPropertyWrapper(e, prop, value)
|
||
|
}
|
||
|
err = pipeline.Add(e)
|
||
|
if err != nil {
|
||
|
log.Error().Msgf("could not add element %s to pipeline: %v\n", o.Name, err)
|
||
|
return fmt.Errorf("could not add element %s to pipeline", o.Name)
|
||
|
}
|
||
|
output := element{element: e, name: o.Name, prev: fmt.Sprintf("%s-videoscale", o.Name)}
|
||
|
elements[o.Name] = output
|
||
|
|
||
|
o.elements = elements
|
||
|
|
||
|
return nil
|
||
|
}
|