Fix deadlock on exit by making mic level updates async
This commit is contained in:
@@ -22,6 +22,7 @@ type Capturer struct {
|
||||
running bool
|
||||
mu sync.Mutex
|
||||
stopChan chan struct{}
|
||||
wg sync.WaitGroup
|
||||
|
||||
// Callback for captured audio (called with 960-sample frames)
|
||||
onAudio func(samples []int16)
|
||||
@@ -136,6 +137,7 @@ func (c *Capturer) Start() error {
|
||||
return fmt.Errorf("failed to start audio client: %w", err)
|
||||
}
|
||||
|
||||
c.wg.Add(1)
|
||||
go c.captureLoop()
|
||||
return nil
|
||||
}
|
||||
@@ -151,6 +153,7 @@ func (c *Capturer) Stop() {
|
||||
c.mu.Unlock()
|
||||
|
||||
close(c.stopChan)
|
||||
c.wg.Wait() // Wait for capture loop to finish before proceeding
|
||||
c.client.Stop()
|
||||
}
|
||||
|
||||
@@ -180,6 +183,7 @@ func (c *Capturer) IsRunning() bool {
|
||||
}
|
||||
|
||||
func (c *Capturer) captureLoop() {
|
||||
defer c.wg.Done()
|
||||
ticker := time.NewTicker(10 * time.Millisecond) // Check more often than 20ms
|
||||
defer ticker.Stop()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user