Skip to content

Commit

Permalink
Use Fifo sink
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 16, 2021
1 parent e95a150 commit 06962bd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions flush.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exec 5<>stream.fifo
cat <&5 >/dev/null & cat_pid=$!
sleep 1
kill "$cat_pid"
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func openStream(dev *gousb.Device) {
if useGstreamer != nil && *useGstreamer {
sink = GstSink{}
} else {
sink = FFPlaySink{}

//sink = FFPlaySink{}
sink = FifoSink{Path: fmt.Sprintf("stream%d-%d.fifo", dev.Desc.Bus, dev.Desc.Address)}
}
ffmpegIn, stopPlayer := sink.StartInstance()
// claim interface
Expand Down
22 changes: 21 additions & 1 deletion sinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"io"
"os"
"os/exec"
"syscall"

Expand Down Expand Up @@ -34,7 +35,7 @@ type GstSink struct {
}

func (sink GstSink) StartInstance() (io.WriteCloser, func()) {
args := []string{"fdsrc", "fd=0", "!", "decodebin", "!", "videoconvert", "!", "autovideosink"}
args := []string{"fdsrc", "fd=0", "!", "decodebin3", "!", "videoconvert", "n-threads=8", "!", "autovideosink", "sync=false"}
cmd := exec.Command("gst-launch-1.0", args...)
stdin, err := cmd.StdinPipe()
if err != nil {
Expand Down Expand Up @@ -63,3 +64,22 @@ func (sink UdpSink) StartInstance() (io.WriteCloser, func()) {
cmd.Process.Signal(syscall.SIGKILL) // Not ellegant... could try sigterm and wait before...
}
}

type FifoSink struct {
Path string
}

func (sink FifoSink) StartInstance() (io.WriteCloser, func()) {
os.Remove(sink.Path)
err := syscall.Mkfifo(sink.Path, 0666)
if err != nil {
log.Fatal("Make named pipe file error:", err)
}
f, err := os.OpenFile(sink.Path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0777)
log.MustFatal(err)

return f, func() {
f.Close()
os.Remove(sink.Path)
}
}

0 comments on commit 06962bd

Please sign in to comment.