Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB audio device unplugged and replug, make program block at speaker.Init #115

Open
microidea opened this issue Mar 12, 2021 · 0 comments
Open

Comments

@microidea
Copy link

microidea commented Mar 12, 2021

I have an USB audio device which has poor contact, when replugged I have to call speaker.Init() again to make the speaker work again.

But it's stuck at here:

player.Write(buf)

Since it's in a for loop, the whole loop is blocked:

beep/speaker/speaker.go

Lines 48 to 57 in 98afada

go func() {
for {
select {
default:
update()
case <-done:
return
}
}
}()

the done channel cannot be consumed, when I call speaker.Init again, it calls speaker.Close first, then it's stuck at here:
done <- struct{}{}

As a result when my USB audio device replugged I cannot call speaker.Init() again, it's always stuck.
So right now I change the done channel into a buffered chan, it looks good so far, but I'm not sure whether it will cause other problem.

Is it necessary to make the done channel an unbuffered chan? How to handle the replug situation properly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant