audio: Bug fix: Avoid deadlock

This commit is contained in:
Hajime Hoshi 2016-05-26 03:13:56 +09:00
parent 644dfcd0fd
commit d6dee0815e

View File

@ -255,17 +255,16 @@ func NewPlayer(sampleRate, channelNum, bytesPerSample int) (*Player, error) {
} }
func (p *Player) Proceed(data []byte) error { func (p *Player) Proceed(data []byte) error {
select {
case err := <-p.chErr:
return err
default:
}
p.buffer = append(p.buffer, data...) p.buffer = append(p.buffer, data...)
if len(p.buffer) < p.bufferSize { if len(p.buffer) < p.bufferSize {
return nil return nil
} }
buf := p.buffer[:p.bufferSize] buf := p.buffer[:p.bufferSize]
p.chBuffer <- buf select {
case p.chBuffer <- buf:
case err := <-p.chErr:
return err
}
p.buffer = p.buffer[p.bufferSize:] p.buffer = p.buffer[p.bufferSize:]
return nil return nil
} }