Synchronize connection-owned audio resources
This commit is contained in:
committed by
Brandon McGinty
parent
b407a20132
commit
57961ffc9f
+24
-9
@@ -31,11 +31,12 @@ type Barnard struct {
|
||||
Address string
|
||||
TLSConfig tls.Config
|
||||
|
||||
Stream *gumbleopenal.Stream
|
||||
Tx bool
|
||||
AutoTransmit bool // auto-start transmission on connect
|
||||
Connected bool
|
||||
stateMutex sync.RWMutex
|
||||
Stream *gumbleopenal.Stream
|
||||
connectionMutex sync.RWMutex
|
||||
Tx bool
|
||||
AutoTransmit bool // auto-start transmission on connect
|
||||
Connected bool
|
||||
stateMutex sync.RWMutex
|
||||
|
||||
Ui *uiterm.Ui
|
||||
UiOutput uiterm.Textview
|
||||
@@ -96,11 +97,13 @@ type Barnard struct {
|
||||
// reconnect replaces them. It is intentionally idempotent for repeated
|
||||
// disconnect notifications.
|
||||
func (b *Barnard) cleanupConnectionAudio() {
|
||||
b.connectionMutex.Lock()
|
||||
if b.Stream != nil {
|
||||
stream := b.Stream
|
||||
b.Stream = nil
|
||||
stream.Destroy()
|
||||
}
|
||||
b.connectionMutex.Unlock()
|
||||
b.FileStreamMutex.Lock()
|
||||
if b.FileStream != nil {
|
||||
_ = b.FileStream.Stop()
|
||||
@@ -121,9 +124,21 @@ func (b *Barnard) cleanupToneTestAudio() {
|
||||
}
|
||||
|
||||
func (b *Barnard) updateUserGain(user *gumble.User) {
|
||||
if b.Stream != nil {
|
||||
b.Stream.UpdateUserGain(user)
|
||||
b.withStream(func(stream *gumbleopenal.Stream) {
|
||||
stream.UpdateUserGain(user)
|
||||
})
|
||||
}
|
||||
|
||||
// withStream keeps a connection-owned stream alive for the complete operation.
|
||||
// Reconnect cleanup takes the write lock before destroying or replacing it.
|
||||
func (b *Barnard) withStream(action func(*gumbleopenal.Stream)) bool {
|
||||
b.connectionMutex.RLock()
|
||||
defer b.connectionMutex.RUnlock()
|
||||
if b.Stream == nil {
|
||||
return false
|
||||
}
|
||||
action(b.Stream)
|
||||
return true
|
||||
}
|
||||
|
||||
func (b *Barnard) isChannelMuted(channelID uint32) bool {
|
||||
@@ -212,8 +227,8 @@ func (b *Barnard) StopTransmission() {
|
||||
close(b.toneTestStop)
|
||||
b.toneTestStop = nil
|
||||
}
|
||||
} else if b.Stream != nil {
|
||||
b.Stream.StopSource()
|
||||
} else {
|
||||
b.withStream(func(stream *gumbleopenal.Stream) { _ = stream.StopSource() })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user