From f8518176d53aa7e08b5049f3a5caa2813c782a2a Mon Sep 17 00:00:00 2001 From: Tyler Stiene Date: Thu, 31 Dec 2020 22:11:08 -0500 Subject: [PATCH 1/3] check if fromDiscordMap channel is full --- discord.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/discord.go b/discord.go index 8ff77b8..c3a1d6c 100644 --- a/discord.go +++ b/discord.go @@ -153,10 +153,22 @@ func discordReceivePCM(v *discordgo.VoiceConnection, die chan bool) { OnError("Error decoding opus data", err) continue } + if len(p.PCM) != 960 { + log.Println("Opus size error") + continue + } discordMutex.Lock() - fromDiscordMap[p.SSRC].pcm <- p.PCM[0:480] - fromDiscordMap[p.SSRC].pcm <- p.PCM[480:960] + select { + case fromDiscordMap[p.SSRC].pcm <- p.PCM[0:480]: + default: + log.Println("fromDiscordMap buffer full. Dropping packet") + } + select { + case fromDiscordMap[p.SSRC].pcm <- p.PCM[480:960]: + default: + log.Println("fromDiscordMap buffer full. Dropping packet") + } discordMutex.Unlock() } } From a735f3f62f37d535f0e19d334f993ab2b5fbb6d9 Mon Sep 17 00:00:00 2001 From: Tyler Stiene Date: Mon, 4 Jan 2021 21:23:52 -0500 Subject: [PATCH 2/3] attempt to set niceness --- discord.go | 1 + main.go | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/discord.go b/discord.go index c3a1d6c..2436543 100644 --- a/discord.go +++ b/discord.go @@ -163,6 +163,7 @@ func discordReceivePCM(v *discordgo.VoiceConnection, die chan bool) { case fromDiscordMap[p.SSRC].pcm <- p.PCM[0:480]: default: log.Println("fromDiscordMap buffer full. Dropping packet") + continue } select { case fromDiscordMap[p.SSRC].pcm <- p.PCM[480:960]: diff --git a/main.go b/main.go index 0c2c690..ac36b1c 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "os" "os/signal" "strconv" + "syscall" "time" "github.com/bwmarrin/discordgo" @@ -88,6 +89,12 @@ func main() { log.Fatalln("missing discord cid") } + // Attempt to set the nice value of the process + err := syscall.Setpriority(syscall.PRIO_PROCESS, os.Getpid(), -5) + if err != nil { + log.Println("Unable to set priority. ", err) + } + // DISCORD Setup discord, err := discordgo.New("Bot " + *discordToken) @@ -131,7 +138,7 @@ func main() { tlsConfig.InsecureSkipVerify = true } - mumble, err := gumble.DialWithDialer(new(net.Dialer),*mumbleAddr+":"+strconv.Itoa(*mumblePort),config, &tlsConfig) + mumble, err := gumble.DialWithDialer(new(net.Dialer), *mumbleAddr+":"+strconv.Itoa(*mumblePort), config, &tlsConfig) if err != nil { log.Println(err) From 7947e93a6df3827559e2339965d9243911ce68ef Mon Sep 17 00:00:00 2001 From: Tyler Stiene Date: Mon, 4 Jan 2021 21:27:30 -0500 Subject: [PATCH 3/3] fix mutex issue --- discord.go | 1 + 1 file changed, 1 insertion(+) diff --git a/discord.go b/discord.go index 2436543..8988850 100644 --- a/discord.go +++ b/discord.go @@ -163,6 +163,7 @@ func discordReceivePCM(v *discordgo.VoiceConnection, die chan bool) { case fromDiscordMap[p.SSRC].pcm <- p.PCM[0:480]: default: log.Println("fromDiscordMap buffer full. Dropping packet") + discordMutex.Unlock() continue } select {