diff options
-rw-r--r-- | soundbox/pipewire.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/soundbox/pipewire.go b/soundbox/pipewire.go index bb672f8..0443766 100644 --- a/soundbox/pipewire.go +++ b/soundbox/pipewire.go @@ -8,10 +8,12 @@ import "C" import ( "context" + "fmt" "io" "log" "net" "os/exec" + "sync" "unsafe" ) @@ -21,6 +23,10 @@ type pwCapture struct { var pwAudio chan []byte +// lock makes sure there is always just one PipeWire capture device since +// multiple are not yet implemented. +var lock sync.Mutex + func newPWCapture(ctx context.Context) pwCapture { pwc := pwCapture{} @@ -74,6 +80,12 @@ func s16leDropSilence(input []byte) []byte { } func StreamPipewireContext(ctx context.Context, targets []net.HardwareAddr) error { + success := lock.TryLock() + if !success { + return fmt.Errorf("Could not acquire lock") + } + defer lock.Unlock() + cmd := exec.CommandContext( ctx, "ffmpeg", |