improve discord buffer packet drop message
kill the bridge if unable to send to discord for 5 seconds
This commit is contained in:
parent
649fe9f33e
commit
0f57c5d33a
|
@ -183,7 +183,7 @@ func (b *BridgeState) StartBridge() {
|
||||||
// Start Passing Between
|
// Start Passing Between
|
||||||
|
|
||||||
// From Mumble
|
// From Mumble
|
||||||
go b.MumbleStream.fromMumbleMixer(ctx, &wg, toDiscord)
|
go b.MumbleStream.fromMumbleMixer(ctx, &wg, cancel, toDiscord)
|
||||||
|
|
||||||
// From Discord
|
// From Discord
|
||||||
b.DiscordStream = &DiscordDuplex{
|
b.DiscordStream = &DiscordDuplex{
|
||||||
|
|
|
@ -3,6 +3,7 @@ package bridge
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -50,12 +51,15 @@ func (m MumbleDuplex) OnAudioStream(e *gumble.AudioStreamEvent) {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m MumbleDuplex) fromMumbleMixer(ctx context.Context, wg *sync.WaitGroup, toDiscord chan []int16) {
|
func (m MumbleDuplex) fromMumbleMixer(ctx context.Context, wg *sync.WaitGroup, cancel context.CancelFunc, toDiscord chan []int16) {
|
||||||
mumbleSleepTick.Start(10 * time.Millisecond)
|
mumbleSleepTick.Start(10 * time.Millisecond)
|
||||||
|
|
||||||
sendAudio := false
|
sendAudio := false
|
||||||
bufferWarning := false
|
bufferWarning := false
|
||||||
|
|
||||||
|
droppingPackets := false
|
||||||
|
droppingPacketCount := 0
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -124,9 +128,24 @@ func (m MumbleDuplex) fromMumbleMixer(ctx context.Context, wg *sync.WaitGroup, t
|
||||||
promToDiscordBufferSize.Set(float64(len(toDiscord)))
|
promToDiscordBufferSize.Set(float64(len(toDiscord)))
|
||||||
select {
|
select {
|
||||||
case toDiscord <- outBuf:
|
case toDiscord <- outBuf:
|
||||||
|
{
|
||||||
|
if droppingPackets {
|
||||||
|
log.Println("Discord buffer ok, total packets dropped " + strconv.Itoa(droppingPacketCount))
|
||||||
|
droppingPackets = false
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
log.Println("Error: toDiscord buffer full. Dropping packet")
|
if !droppingPackets {
|
||||||
|
log.Println("Error: toDiscord buffer full. Dropping packets")
|
||||||
|
droppingPackets = true
|
||||||
|
droppingPacketCount = 0
|
||||||
|
}
|
||||||
|
droppingPacketCount++
|
||||||
promToDiscordDropped.Inc()
|
promToDiscordDropped.Inc()
|
||||||
|
if droppingPacketCount > 250 {
|
||||||
|
log.Println("Discord Timeout")
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
discrodSendSleepTick.Notify()
|
discrodSendSleepTick.Notify()
|
||||||
|
|
Loading…
Reference in New Issue