aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go80
1 files changed, 76 insertions, 4 deletions
diff --git a/main.go b/main.go
index c072bea..0ed7d2f 100644
--- a/main.go
+++ b/main.go
@@ -6,6 +6,8 @@ import (
"io/ioutil"
"log"
"os"
+ "regexp"
+ "strconv"
"strings"
"time"
@@ -123,12 +125,10 @@ func getSources(client *pulseaudio.Client) []device {
outputs := make([]device, 0)
for i := range sources {
- if strings.Contains(sources[i].Name, "nui_") {
+ if strings.Contains(sources[i].Name, "nui_") || strings.Contains(sources[i].Name, "NoiseTorch") {
continue
}
- log.Printf("Input %s, %+v\n", sources[i].Name, sources[i])
-
var inp device
inp.ID = sources[i].Name
@@ -153,7 +153,7 @@ func getSinks(client *pulseaudio.Client) []device {
inputs := make([]device, 0)
for i := range sources {
- if strings.Contains(sources[i].Name, "nui_") {
+ if strings.Contains(sources[i].Name, "nui_") || strings.Contains(sources[i].Name, "NoiseTorch") {
continue
}
@@ -190,6 +190,14 @@ func paConnectionWatchdog(ctx *ntcontext) {
fmt.Fprintf(os.Stderr, "Couldn't create pulseaudio client: %v\n", err)
}
+ info, err := serverInfo(paClient)
+ if err != nil {
+ log.Printf("Couldn't fetch audio server info: %s\n", err)
+ }
+ ctx.serverInfo = info
+
+ log.Printf("Connected to audio server. Server name '%s'\n", info.name)
+
ctx.paClient = paClient
go updateNoiseSupressorLoaded(ctx)
@@ -203,6 +211,70 @@ func paConnectionWatchdog(ctx *ntcontext) {
}
}
+func serverInfo(paClient *pulseaudio.Client) (audioserverinfo, error) {
+ info, err := paClient.ServerInfo()
+ if err != nil {
+ log.Printf("Couldn't fetch pulse server info: %v\n", err)
+ fmt.Fprintf(os.Stderr, "Couldn't fetch pulse server info: %v\n", err)
+ }
+
+ pkgname := info.PackageName
+ log.Printf("Audioserver package name: %s\n", pkgname)
+ log.Printf("Audioserver package version: %s\n", info.PackageVersion)
+ isPipewire := strings.Contains(pkgname, "PipeWire")
+
+ var servername string
+ var servertype uint
+ var major, minor, patch int
+ var versionRegex *regexp.Regexp
+ var versionString string
+
+ var outdatedPipeWire bool
+
+ if isPipewire {
+ servername = "PipeWire"
+ servertype = servertype_pipewire
+ versionRegex = regexp.MustCompile(`.*?on PipeWire (\d+)\.(\d+)\.(\d+).*?`)
+ versionString = pkgname
+ log.Printf("Detected PipeWire\n")
+ } else {
+ servername = "PulseAudio"
+ servertype = servertype_pulse
+ versionRegex = regexp.MustCompile(`.*?(\d+)\.(\d+)\.(\d+).*?`)
+ versionString = info.PackageVersion
+ log.Printf("Detected PulseAudio\n")
+ }
+
+ res := versionRegex.FindStringSubmatch(versionString)
+ if len(res) != 4 {
+ return audioserverinfo{}, fmt.Errorf("couldn't parse server version, regexp didn't match.")
+ }
+ major, err = strconv.Atoi(res[1])
+ if err != nil {
+ return audioserverinfo{}, err
+ }
+ minor, err = strconv.Atoi(res[2])
+ if err != nil {
+ return audioserverinfo{}, err
+ }
+ patch, err = strconv.Atoi(res[3])
+ if err != nil {
+ return audioserverinfo{}, err
+ }
+ if isPipewire && major <= 0 && minor <= 3 && patch < 28 {
+ log.Printf("pipewire version %d.%d.%d too old.\n", major, minor, patch)
+ outdatedPipeWire = true
+ }
+
+ return audioserverinfo{
+ servertype: servertype,
+ name: servername,
+ major: major,
+ minor: minor,
+ patch: patch,
+ outdatedPipeWire: outdatedPipeWire}, nil
+}
+
func preselectDevice(ctx *ntcontext, devices []device, preselectID string,
fallbackFunc func(client *pulseaudio.Client) (string, error)) []device {