2022-02-06 00:34:05 +01:00
|
|
|
package gstreamer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
"github.com/tinyzimmer/go-gst/gst"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (i *InputElement) create(pipeline *gst.Pipeline, log zerolog.Logger) error {
|
2022-02-07 11:20:50 +01:00
|
|
|
|
2022-02-06 00:34:05 +01:00
|
|
|
elements := map[string]element{}
|
|
|
|
e, err := gst.NewElementWithName(i.Type, i.Name)
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Msgf("could not create element %s: %v\n", i.Name, err)
|
|
|
|
return fmt.Errorf("could not create element %s", i.Name)
|
|
|
|
}
|
|
|
|
for prop, value := range i.Properties {
|
|
|
|
setPropertyWrapper(e, prop, value)
|
|
|
|
}
|
|
|
|
err = pipeline.Add(e)
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Msgf("could not add element %s to pipeline: %v\n", i.Name, err)
|
|
|
|
return fmt.Errorf("could not add element %s to pipeline", i.Name)
|
|
|
|
}
|
|
|
|
input := element{element: e, name: i.Name, next: fmt.Sprintf("%s-decodebin", i.Name)}
|
|
|
|
elements[i.Name] = input
|
|
|
|
// ====================
|
|
|
|
|
|
|
|
//====================
|
2022-02-07 11:20:50 +01:00
|
|
|
// RAWVIDEOPARSE
|
|
|
|
e, err = gst.NewElementWithName("rawvideoparse", fmt.Sprintf("%s-rawvideoparse", i.Name))
|
2022-02-06 00:34:05 +01:00
|
|
|
if err != nil {
|
2022-02-07 11:20:50 +01:00
|
|
|
log.Error().Msgf("could not create rawvideoparse for %s: %v\n", i.Name, err)
|
|
|
|
return fmt.Errorf("could not create rawvideoparse for %s", i.Name)
|
2022-02-06 00:34:05 +01:00
|
|
|
}
|
2022-02-07 11:20:50 +01:00
|
|
|
setPropertyWrapper(e, "format", "bgra")
|
|
|
|
setPropertyWrapper(e, "width", 1280)
|
|
|
|
setPropertyWrapper(e, "height", 720)
|
|
|
|
setPropertyWrapper(e, "framerate", "50")
|
2022-02-06 00:34:05 +01:00
|
|
|
err = pipeline.Add(e)
|
|
|
|
if err != nil {
|
2022-02-07 11:20:50 +01:00
|
|
|
log.Error().Msgf("could not add rawvideoparse for %s to pipeline: %v\n", i.Name, err)
|
|
|
|
return fmt.Errorf("could not add rawvideoparse for %s to pipeline", i.Name)
|
2022-02-06 00:34:05 +01:00
|
|
|
}
|
2022-02-07 11:20:50 +01:00
|
|
|
rawvideoparse := element{element: e, name: fmt.Sprintf("%s-rawvideoparse", i.Name), prev: i.Name, next: fmt.Sprintf("%s-videoconvert", i.Name)}
|
|
|
|
elements[fmt.Sprintf("%s-rawvideoparse", i.Name)] = rawvideoparse
|
|
|
|
|
|
|
|
err = input.linkElementWrapper(&rawvideoparse, log)
|
2022-02-06 00:34:05 +01:00
|
|
|
if err != nil {
|
2022-02-07 11:20:50 +01:00
|
|
|
log.Error().Msgf("could not link %s to %s: %v", fmt.Sprintf("%s-rawvideoparse", i.Name), i.Name, err)
|
|
|
|
return fmt.Errorf("could not link %s to %s", fmt.Sprintf("%s-rawvideoparse", i.Name), i.Name)
|
2022-02-06 00:34:05 +01:00
|
|
|
}
|
|
|
|
//====================
|
|
|
|
|
|
|
|
// ====================
|
|
|
|
// VIDEOCONVERT
|
|
|
|
e, err = gst.NewElementWithName("videoconvert", fmt.Sprintf("%s-videoconvert", i.Name))
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Msgf("could not create videoconvert for %s: %v\n", i.Name, err)
|
|
|
|
return fmt.Errorf("could not create videoconvert for %s", i.Name)
|
|
|
|
}
|
|
|
|
err = pipeline.Add(e)
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Msgf("could not add videoconvert for %s to pipeline: %v\n", i.Name, err)
|
|
|
|
return fmt.Errorf("could not add videoconvert for %s to pipeline", i.Name)
|
|
|
|
}
|
2022-02-07 11:20:50 +01:00
|
|
|
videoconvert := element{element: e, name: fmt.Sprintf("%s-videoconvert", i.Name), prev: fmt.Sprintf("%s-rawvideoparse", i.Name), next: fmt.Sprintf("%s-videoscale", i.Name)}
|
2022-02-06 00:34:05 +01:00
|
|
|
elements[fmt.Sprintf("%s-videoconvert", i.Name)] = videoconvert
|
2022-02-07 11:20:50 +01:00
|
|
|
err = rawvideoparse.linkElementWrapper(&videoconvert, log)
|
2022-02-06 00:34:05 +01:00
|
|
|
if err != nil {
|
2022-02-07 11:20:50 +01:00
|
|
|
log.Error().Msgf("could not link %s to %s: %v\n", fmt.Sprintf("%s-videoconvert", i.Name), fmt.Sprintf("%s-decodebin", i.Name), err)
|
|
|
|
return fmt.Errorf("could not link %s to %s", fmt.Sprintf("%s-videoconvert", i.Name), fmt.Sprintf("%s-decodebin", i.Name))
|
2022-02-06 00:34:05 +01:00
|
|
|
}
|
|
|
|
//=====================
|
|
|
|
|
|
|
|
//=====================
|
|
|
|
// VIDEOSCALE
|
|
|
|
e, err = gst.NewElementWithName("videoscale", fmt.Sprintf("%s-videoscale", i.Name))
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Msgf("could not create videoscale for %s: %v\n", i.Name, err)
|
|
|
|
return fmt.Errorf("could not create videoscale for %s", i.Name)
|
|
|
|
}
|
|
|
|
err = pipeline.Add(e)
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Msgf("could not add videoscale for %s to pipeline: %v\n", i.Name, err)
|
|
|
|
return fmt.Errorf("could not add videoscale for %s to pipeline", i.Name)
|
|
|
|
}
|
|
|
|
videoscale := element{element: e, name: fmt.Sprintf("%s-videoscale", i.Name), prev: fmt.Sprintf("%s-videoconvert", i.Name), next: fmt.Sprintf("%s-videorate", i.Name)}
|
|
|
|
elements[fmt.Sprintf("%s-videoscale", i.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", i.Name), fmt.Sprintf("%s-videoscale", i.Name), err)
|
|
|
|
return fmt.Errorf("could not link %s to %s", fmt.Sprintf("%s-videoconvert", i.Name), fmt.Sprintf("%s-videoscale", i.Name))
|
|
|
|
}
|
|
|
|
//=====================
|
|
|
|
|
|
|
|
//=====================
|
|
|
|
// VIDEORATE
|
|
|
|
e, err = gst.NewElementWithName("videorate", fmt.Sprintf("%s-videorate", i.Name))
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Msgf("could not create videorate for %s: %v\n", i.Name, err)
|
|
|
|
return fmt.Errorf("could not create videorate for %s", i.Name)
|
|
|
|
}
|
|
|
|
err = pipeline.Add(e)
|
|
|
|
if err != nil {
|
|
|
|
log.Error().Msgf("could not add videorate for %s to pipeline: %v\n", i.Name, err)
|
|
|
|
return fmt.Errorf("could not add videorate for %s to pipeline", i.Name)
|
|
|
|
}
|
|
|
|
videorate := element{element: e, name: fmt.Sprintf("%s-videorate", i.Name), prev: fmt.Sprintf("%s-videoscale", i.Name), outputCaps: i.Caps}
|
|
|
|
elements[fmt.Sprintf("%s-videorate", i.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", i.Name), fmt.Sprintf("%s-videorate", i.Name), err)
|
|
|
|
return fmt.Errorf("could not link %s to %s", fmt.Sprintf("%s-videoscale", i.Name), fmt.Sprintf("%s-videorate", i.Name))
|
|
|
|
}
|
|
|
|
|
|
|
|
i.elements = elements
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *InputElement) getLastElement() *element {
|
|
|
|
e := i.elements[fmt.Sprintf("%s-videorate", i.Name)]
|
|
|
|
return &e
|
|
|
|
}
|