mirror of https://github.com/jetkvm/kvm.git
Fix: Audio Output Enable / Disable
This commit is contained in:
parent
0f2aa9abe4
commit
02acee0c75
|
@ -156,6 +156,15 @@ func (s *AudioOutputSupervisor) Stop() {
|
|||
s.forceKillProcess("audio output server")
|
||||
}
|
||||
|
||||
// Ensure socket file cleanup even if subprocess didn't clean up properly
|
||||
// This prevents "address already in use" errors on restart
|
||||
outputSocketPath := getOutputSocketPath()
|
||||
if err := os.Remove(outputSocketPath); err != nil && !os.IsNotExist(err) {
|
||||
s.logger.Warn().Err(err).Str("socket_path", outputSocketPath).Msg("failed to remove output socket file during supervisor stop")
|
||||
} else if err == nil {
|
||||
s.logger.Debug().Str("socket_path", outputSocketPath).Msg("cleaned up output socket file")
|
||||
}
|
||||
|
||||
s.logger.Info().Str("component", AudioOutputSupervisorComponent).Msg("component stopped")
|
||||
}
|
||||
|
||||
|
|
|
@ -30,13 +30,34 @@ func StartAudioRelay(audioTrack AudioTrackWriter) error {
|
|||
// Get current audio config
|
||||
config := GetAudioConfig()
|
||||
|
||||
// Start the relay (audioTrack can be nil initially)
|
||||
if err := relay.Start(audioTrack, config); err != nil {
|
||||
return err
|
||||
// Retry starting the relay with exponential backoff
|
||||
// This handles cases where the subprocess hasn't created its socket yet
|
||||
maxAttempts := 5
|
||||
baseDelay := 200 * time.Millisecond
|
||||
maxDelay := 2 * time.Second
|
||||
|
||||
var lastErr error
|
||||
for i := 0; i < maxAttempts; i++ {
|
||||
if err := relay.Start(audioTrack, config); err != nil {
|
||||
lastErr = err
|
||||
if i < maxAttempts-1 {
|
||||
// Calculate exponential backoff delay
|
||||
delay := time.Duration(float64(baseDelay) * (1.5 * float64(i+1)))
|
||||
if delay > maxDelay {
|
||||
delay = maxDelay
|
||||
}
|
||||
time.Sleep(delay)
|
||||
continue
|
||||
}
|
||||
return fmt.Errorf("failed to start audio relay after %d attempts: %w", maxAttempts, lastErr)
|
||||
}
|
||||
|
||||
// Success
|
||||
globalRelay = relay
|
||||
return nil
|
||||
}
|
||||
|
||||
globalRelay = relay
|
||||
return nil
|
||||
return fmt.Errorf("failed to start audio relay after %d attempts: %w", maxAttempts, lastErr)
|
||||
}
|
||||
|
||||
// StopAudioRelay stops the audio relay system
|
||||
|
|
Loading…
Reference in New Issue