Skip to content

Commit

Permalink
Add gstreamer flag
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Bachschwell <lukas@lbsfilm.at>
  • Loading branch information
s00500 committed May 15, 2021
1 parent 7c23975 commit e95a150
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Make sure you have go and ffmpeg installed, then run like this:

`go run .`

Crosscompilation does not work in an easy way due to the dependency on libusb
Per default this will use ffplay, if you want to use gstreamer though use it like this `go run . --gstreamer`

Crosscompilation does not work in an easy way due to the dependency on libusb
If you find any new intersting things about this let me know on the discordserver @s00500 or here in the issue section


## Test status

For now I tested this with macOS bigsur, no additional drivers installd, although I might have a few on my computer anyway
Expand Down
16 changes: 14 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"flag"
"fmt"
"io"
"sync"
Expand All @@ -13,8 +14,14 @@ import (

var magicStartBytes = []byte{0x52, 0x4d, 0x56, 0x54}

var useGstreamer *bool = flag.Bool("gstreamer", false, "use gstreamer")

func main() {
flag.Parse()
log.Info("Starting djifpvvideout")
if useGstreamer != nil && *useGstreamer {
log.Info("using gstreamer")
}

openPorts := make([]string, 0)
openPortsMu := sync.RWMutex{}
Expand Down Expand Up @@ -59,15 +66,20 @@ func main() {
openPorts = deleteElement(openPorts, fmt.Sprintf("%d.%d", dev.Desc.Bus, dev.Desc.Address))
openPortsMu.Unlock()
log.Warnf("lost device on %d.%d", dev.Desc.Bus, dev.Desc.Address)

}()
}
time.Sleep(time.Second * 3)
}
}

func openStream(dev *gousb.Device) {
sink := FFPlaySink{}
var sink StreamSink
if useGstreamer != nil && *useGstreamer {
sink = GstSink{}
} else {
sink = FFPlaySink{}

}
ffmpegIn, stopPlayer := sink.StartInstance()
// claim interface
intf, done, err := googleInterface(dev)
Expand Down
16 changes: 16 additions & 0 deletions sinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ func (sink FFPlaySink) StartInstance() (io.WriteCloser, func()) {
}
}

type GstSink struct {
}

func (sink GstSink) StartInstance() (io.WriteCloser, func()) {
args := []string{"fdsrc", "fd=0", "!", "decodebin", "!", "videoconvert", "!", "autovideosink"}
cmd := exec.Command("gst-launch-1.0", args...)
stdin, err := cmd.StdinPipe()
if err != nil {
log.Fatal("Could not get gstreamer stdin")
}
log.MustFatal(cmd.Start())
return stdin, func() {
cmd.Process.Signal(syscall.SIGKILL) // Not ellegant... could try sigterm and wait before...
}
}

type UdpSink struct {
}

Expand Down

0 comments on commit e95a150

Please sign in to comment.