Fix: coredump issue

This commit is contained in:
Alex P 2025-11-11 22:41:46 +02:00
parent 98d20d4ffa
commit 22a16c7f17
1 changed files with 25 additions and 9 deletions

View File

@ -136,21 +136,37 @@ func setAudioTrack(audioTrack *webrtc.TrackLocalStaticSample) {
audioMutex.Lock() audioMutex.Lock()
currentAudioTrack = audioTrack currentAudioTrack = audioTrack
oldRelay := outputRelay oldRelay := outputRelay
oldSource := outputSource
outputRelay = nil outputRelay = nil
outputSource = nil
audioMutex.Unlock()
var newRelay *audio.OutputRelay // Stop relay and disconnect source outside mutex to avoid blocking during CGO calls
if outputSource != nil { if oldRelay != nil {
newRelay = audio.NewOutputRelay(outputSource, audioTrack) oldRelay.Stop()
}
if oldSource != nil {
oldSource.Disconnect()
}
// Create new source and relay for the new track
audioMutex.Lock()
if currentAudioTrack != nil && audioOutputEnabled.Load() {
alsaDevice := "hw:1,0"
newSource := audio.NewCgoOutputSource(alsaDevice)
newRelay := audio.NewOutputRelay(newSource, currentAudioTrack)
outputSource = newSource
outputRelay = newRelay outputRelay = newRelay
} }
audioMutex.Unlock() audioMutex.Unlock()
// Stop/start outside mutex to avoid blocking during CGO calls // Start new relay outside mutex
if oldRelay != nil { audioMutex.Lock()
oldRelay.Stop() relayToStart := outputRelay
} audioMutex.Unlock()
if newRelay != nil {
if err := newRelay.Start(); err != nil { if relayToStart != nil {
if err := relayToStart.Start(); err != nil {
audioLogger.Error().Err(err).Msg("Failed to start output relay") audioLogger.Error().Err(err).Msg("Failed to start output relay")
} }
} }