Synchronize connection-owned stream access

This commit is contained in:
Brandon McGinty (chatgpt)
2026-08-10 11:25:08 -04:00
committed by Brandon McGinty
parent f0aa5ff35a
commit e9ba7f580a
6 changed files with 133 additions and 84 deletions
+17 -9
View File
@@ -97,6 +97,14 @@ type Barnard struct {
// reconnect replaces them. It is intentionally idempotent for repeated
// disconnect notifications.
func (b *Barnard) cleanupConnectionAudio() {
// Connection audio operations that use both resources take FileStreamMutex
// before connectionMutex, so cleanup follows that order as well.
b.FileStreamMutex.Lock()
if b.FileStream != nil {
_ = b.FileStream.Stop()
b.FileStream = nil
}
b.FileStreamMutex.Unlock()
b.connectionMutex.Lock()
if b.Stream != nil {
stream := b.Stream
@@ -104,12 +112,6 @@ func (b *Barnard) cleanupConnectionAudio() {
stream.Destroy()
}
b.connectionMutex.Unlock()
b.FileStreamMutex.Lock()
if b.FileStream != nil {
_ = b.FileStream.Stop()
b.FileStream = nil
}
b.FileStreamMutex.Unlock()
}
func (b *Barnard) cleanupToneTestAudio() {
@@ -266,9 +268,13 @@ func (b *Barnard) TreeItemKeyPress(ui *uiterm.Ui, tree *uiterm.Tree, item uiterm
for _, u := range users {
// Explicitly set user mute state to match channel state
if channelWillBeMuted && !u.LocallyMuted() {
b.UserConfig.ToggleMute(u)
if err := b.UserConfig.ToggleMute(u); err != nil {
b.AddOutputLine("Mute: could not save setting: " + err.Error())
}
} else if !channelWillBeMuted && u.LocallyMuted() {
b.UserConfig.ToggleMute(u)
if err := b.UserConfig.ToggleMute(u); err != nil {
b.AddOutputLine("Mute: could not save setting: " + err.Error())
}
}
b.updateUserGain(u)
@@ -297,7 +303,9 @@ func (b *Barnard) TreeItemKeyPress(ui *uiterm.Ui, tree *uiterm.Tree, item uiterm
if treeItem.User != nil {
if key == *b.Hotkeys.MuteToggle {
// Toggle mute for single user
b.UserConfig.ToggleMute(treeItem.User)
if err := b.UserConfig.ToggleMute(treeItem.User); err != nil {
b.AddOutputLine("Mute: could not save setting: " + err.Error())
}
b.updateUserGain(treeItem.User)
b.RebuildUserChannelTreePreservingSelection()
b.Ui.Refresh()