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 { 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 // ==================== //==================== // DECODEBIN e, err = gst.NewElementWithName("decodebin", fmt.Sprintf("%s-decodebin", i.Name)) if err != nil { log.Error().Msgf("could not create decodebin for %s: %v\n", i.Name, err) return fmt.Errorf("could not create decodebin for %s", i.Name) } err = pipeline.Add(e) if err != nil { log.Error().Msgf("could not add decodebin for %s to pipeline: %v\n", i.Name, err) return fmt.Errorf("could not add decodebin for %s to pipeline", i.Name) } decodebin := element{element: e, name: fmt.Sprintf("%s-decodebin", i.Name), prev: i.Name, next: fmt.Sprintf("%s-videoconvert", i.Name)} elements[fmt.Sprintf("%s-decodebin", i.Name)] = decodebin err = input.linkElementWrapper(&decodebin, log) if err != nil { log.Error().Msgf("could not link %s to %s: %v\n", i.Name, fmt.Sprintf("%s-decodebin", i.Name), err) return fmt.Errorf("could not link %s to %s", i.Name, fmt.Sprintf("%s-decodebin", i.Name)) } //==================== // ==================== // 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) } videoconvert := element{element: e, name: fmt.Sprintf("%s-videoconvert", i.Name), prev: fmt.Sprintf("%s-decodebin", i.Name), next: fmt.Sprintf("%s-videoscale", i.Name)} elements[fmt.Sprintf("%s-videoconvert", i.Name)] = videoconvert err = input.linkElementWrapper(&videoconvert, log) if err != nil { log.Error().Msgf("could not link %s to %s: %v\n", i.Name, fmt.Sprintf("%s-videoconvert", i.Name), err) return fmt.Errorf("could not link %s to %s", i.Name, fmt.Sprintf("%s-videoconvert", i.Name)) } //===================== //===================== // 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 }