47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package gstreamer
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/rs/zerolog"
|
|
"github.com/tinyzimmer/go-gst/gst"
|
|
"strings"
|
|
)
|
|
|
|
func setPropertyWrapper(element *gst.Element, name string, value interface{}) {
|
|
element.SetArg(name, fmt.Sprintf("%v", value))
|
|
}
|
|
|
|
func (element1 *element) linkElementWrapper(element2 *element, log zerolog.Logger, capabilities ...string) error {
|
|
var err error
|
|
var caps string
|
|
if len(capabilities) > 0 {
|
|
caps = strings.Join(capabilities, ", ")
|
|
}
|
|
if len(element1.outputCaps) > 0 {
|
|
if caps != "" {
|
|
log.Error().Str("action", "linking").Str("element1", element1.name).Str("element2", element2.name).Msg("element1 has output caps but you specified already caps so i'm only using them")
|
|
} else {
|
|
caps = strings.Join(element1.outputCaps, ",")
|
|
}
|
|
}
|
|
if len(element2.inputCaps) > 0 {
|
|
if caps != "" {
|
|
log.Error().Str("action", "linking").Str("element1", element1.name).Str("element2", element2.name).Msg("element2 has input caps but you specified already caps so i'm only using them")
|
|
} else {
|
|
caps = strings.Join(element2.inputCaps, ",")
|
|
}
|
|
}
|
|
if len(caps) > 0 {
|
|
capabilities := gst.NewCapsFromString(caps)
|
|
err = element1.element.LinkFiltered(element2.element, capabilities)
|
|
} else {
|
|
err = element1.element.Link(element2.element)
|
|
}
|
|
if err != nil {
|
|
log.Error().Msgf("could not link %s to %s: %v\n", element2.name, element1.name, err)
|
|
return fmt.Errorf("could not link %s to %s", element2.name, element1.name)
|
|
}
|
|
element1.next, element2.prev = element2.name, element1.name
|
|
|
|
return nil
|
|
}
|