mirror of https://github.com/jetkvm/kvm.git
[Milestone] Fix: in-flight audio input quality updates
This commit is contained in:
parent
3c6184d0e8
commit
bda92b4a62
|
@ -196,7 +196,7 @@ func (p *GoroutinePool) supervisor() {
|
||||||
tasks := atomic.LoadInt64(&p.taskCount)
|
tasks := atomic.LoadInt64(&p.taskCount)
|
||||||
queueLen := len(p.taskQueue)
|
queueLen := len(p.taskQueue)
|
||||||
|
|
||||||
p.logger.Info().
|
p.logger.Debug().
|
||||||
Int64("workers", workers).
|
Int64("workers", workers).
|
||||||
Int64("tasks_processed", tasks).
|
Int64("tasks_processed", tasks).
|
||||||
Int("queue_length", queueLen).
|
Int("queue_length", queueLen).
|
||||||
|
@ -215,7 +215,7 @@ func (p *GoroutinePool) Shutdown(wait bool) {
|
||||||
if wait {
|
if wait {
|
||||||
// Wait for all tasks to be processed
|
// Wait for all tasks to be processed
|
||||||
if len(p.taskQueue) > 0 {
|
if len(p.taskQueue) > 0 {
|
||||||
p.logger.Info().Int("remaining_tasks", len(p.taskQueue)).Msg("Waiting for tasks to complete")
|
p.logger.Debug().Int("remaining_tasks", len(p.taskQueue)).Msg("Waiting for tasks to complete")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the task queue to signal no more tasks
|
// Close the task queue to signal no more tasks
|
||||||
|
|
|
@ -136,8 +136,8 @@ func (ais *AudioInputSupervisor) startProcess() error {
|
||||||
|
|
||||||
// Add process to monitoring
|
// Add process to monitoring
|
||||||
|
|
||||||
// Connect client to the server
|
// Connect client to the server synchronously to avoid race condition
|
||||||
go ais.connectClient()
|
ais.connectClient()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -311,14 +311,26 @@ func SetMicrophoneQuality(quality AudioQuality) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update audio input subprocess configuration dynamically without restart
|
// Update audio input subprocess configuration dynamically without restart
|
||||||
if supervisor := GetAudioInputSupervisor(); supervisor != nil {
|
logger := logging.GetDefaultLogger().With().Str("component", "audio").Logger()
|
||||||
logger := logging.GetDefaultLogger().With().Str("component", "audio").Logger()
|
logger.Info().Int("quality", int(quality)).Msg("updating audio input quality settings dynamically")
|
||||||
logger.Info().Int("quality", int(quality)).Msg("updating audio input subprocess quality settings dynamically")
|
|
||||||
|
|
||||||
// Set new OPUS configuration for future restarts
|
// Set new OPUS configuration for future restarts
|
||||||
|
if supervisor := GetAudioInputSupervisor(); supervisor != nil {
|
||||||
supervisor.SetOpusConfig(config.Bitrate*1000, complexity, vbr, signalType, bandwidth, dtx)
|
supervisor.SetOpusConfig(config.Bitrate*1000, complexity, vbr, signalType, bandwidth, dtx)
|
||||||
|
|
||||||
// Send dynamic configuration update to running subprocess
|
// Check if microphone is active but IPC control is broken
|
||||||
|
inputManager := getAudioInputManager()
|
||||||
|
if inputManager.IsRunning() && !supervisor.IsConnected() {
|
||||||
|
logger.Info().Msg("microphone active but IPC disconnected, attempting to reconnect control channel")
|
||||||
|
// Reconnect the IPC control channel
|
||||||
|
supervisor.Stop()
|
||||||
|
time.Sleep(50 * time.Millisecond)
|
||||||
|
if err := supervisor.Start(); err != nil {
|
||||||
|
logger.Warn().Err(err).Msg("failed to reconnect IPC control channel")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send dynamic configuration update to running subprocess via IPC
|
||||||
if supervisor.IsConnected() {
|
if supervisor.IsConnected() {
|
||||||
// Convert AudioConfig to InputIPCOpusConfig with complete Opus parameters
|
// Convert AudioConfig to InputIPCOpusConfig with complete Opus parameters
|
||||||
opusConfig := InputIPCOpusConfig{
|
opusConfig := InputIPCOpusConfig{
|
||||||
|
@ -335,17 +347,16 @@ func SetMicrophoneQuality(quality AudioQuality) {
|
||||||
|
|
||||||
logger.Info().Interface("opusConfig", opusConfig).Msg("sending Opus configuration to audio input subprocess")
|
logger.Info().Interface("opusConfig", opusConfig).Msg("sending Opus configuration to audio input subprocess")
|
||||||
if err := supervisor.SendOpusConfig(opusConfig); err != nil {
|
if err := supervisor.SendOpusConfig(opusConfig); err != nil {
|
||||||
logger.Warn().Err(err).Msg("failed to send dynamic Opus config update, subprocess may need restart")
|
logger.Warn().Err(err).Msg("failed to send dynamic Opus config update via IPC, falling back to subprocess restart")
|
||||||
// Fallback to restart if dynamic update fails
|
// Fallback to subprocess restart if IPC update fails
|
||||||
supervisor.Stop()
|
supervisor.Stop()
|
||||||
if err := supervisor.Start(); err != nil {
|
if err := supervisor.Start(); err != nil {
|
||||||
logger.Error().Err(err).Msg("failed to restart audio input subprocess after config update failure")
|
logger.Error().Err(err).Msg("failed to restart audio input subprocess after IPC update failure")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.Info().Msg("audio input quality updated dynamically with complete Opus configuration")
|
logger.Info().Msg("audio input quality updated dynamically via IPC")
|
||||||
|
|
||||||
// Reset audio input server stats after config update
|
// Reset audio input stats after config update
|
||||||
// Allow adaptive buffer manager to naturally adjust buffer sizes
|
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(Config.QualityChangeSettleDelay) // Wait for quality change to settle
|
time.Sleep(Config.QualityChangeSettleDelay) // Wait for quality change to settle
|
||||||
// Reset audio input server stats to clear persistent warnings
|
// Reset audio input server stats to clear persistent warnings
|
||||||
|
|
Loading…
Reference in New Issue