make per-user audio state thread-safe

Move volume, boost, mute, and OpenAL source behind accessors guarded
by a per-user mutex.
The audio goroutine reads these fields on every decoded packet while
the UI writes them from key handlers, which is a data race on the
gain a stream is currently rendering with.

Also add the per-user sequence fields the decoder needs to notice
gaps in a user's audio stream.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Brandon McGinty
2026-08-20 14:22:33 -04:00
co-authored by Claude Opus 5
parent b67940ddbc
commit 60470ad091
6 changed files with 117 additions and 50 deletions
+10 -10
View File
@@ -115,17 +115,17 @@ func (b *Barnard) TreeItemKeyPress(ui *uiterm.Ui, tree *uiterm.Tree, item uiterm
users := makeUsersArray(treeItem.Channel.Users)
for _, u := range users {
// Explicitly set user mute state to match channel state
if channelWillBeMuted && !u.LocallyMuted {
if channelWillBeMuted && !u.LocallyMuted() {
b.UserConfig.ToggleMute(u)
} else if !channelWillBeMuted && u.LocallyMuted {
} else if !channelWillBeMuted && u.LocallyMuted() {
b.UserConfig.ToggleMute(u)
}
if u.AudioSource != nil {
if u.LocallyMuted {
u.AudioSource.SetGain(0)
if source := u.AudioSource(); source != nil {
if u.LocallyMuted() {
source.SetGain(0)
} else {
u.AudioSource.SetGain(u.Volume)
source.SetGain(u.Volume())
}
}
}
@@ -159,11 +159,11 @@ func (b *Barnard) TreeItemKeyPress(ui *uiterm.Ui, tree *uiterm.Tree, item uiterm
if key == *b.Hotkeys.MuteToggle {
// Toggle mute for single user
b.UserConfig.ToggleMute(treeItem.User)
if treeItem.User.AudioSource != nil {
if treeItem.User.LocallyMuted {
treeItem.User.AudioSource.SetGain(0)
if source := treeItem.User.AudioSource(); source != nil {
if treeItem.User.LocallyMuted() {
source.SetGain(0)
} else {
treeItem.User.AudioSource.SetGain(treeItem.User.Volume)
source.SetGain(treeItem.User.Volume())
}
}
b.RebuildUserChannelTreePreservingSelection()