audio/internal/readerdriver: Bug fix: AudioQueue{Pause,Reset,Flush} cannot be called before AudioQueueStart

This commit is contained in:
Hajime Hoshi 2021-05-09 05:28:42 +09:00
parent bc22ab53b2
commit 9df1092507

View File

@ -96,6 +96,7 @@ type playerImpl struct {
err error
eof bool
cond *sync.Cond
started bool
}
type players struct {
@ -297,6 +298,7 @@ func (p *playerImpl) Play() {
p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueueStart failed: %d", osstatus))
return
}
p.started = true
p.state = playerPlay
p.cond.Signal()
@ -335,21 +337,24 @@ func (p *playerImpl) Reset() {
if p.state == playerClosed {
return
}
// TODO: Pausing and resetting seems not immediately?
if osstatus := C.AudioQueuePause(p.audioQueue); osstatus != C.noErr && p.err == nil {
p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueuePause failed: %d", osstatus))
return
}
// AudioQueueReset invokes the callback directry.
p.cond.L.Unlock()
if osstatus := C.AudioQueueReset(p.audioQueue); osstatus != C.noErr && p.err == nil {
p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueueReset failed: %d", osstatus))
return
}
p.cond.L.Lock()
if osstatus := C.AudioQueueFlush(p.audioQueue); osstatus != C.noErr && p.err == nil {
p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueueFlush failed: %d", osstatus))
return
if p.started {
if osstatus := C.AudioQueuePause(p.audioQueue); osstatus != C.noErr && p.err == nil {
p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueuePause failed: %d", osstatus))
return
}
// AudioQueueReset invokes the callback directry.
p.cond.L.Unlock()
if osstatus := C.AudioQueueReset(p.audioQueue); osstatus != C.noErr && p.err == nil {
p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueueReset failed: %d", osstatus))
p.cond.L.Lock()
return
}
p.cond.L.Lock()
if osstatus := C.AudioQueueFlush(p.audioQueue); osstatus != C.noErr && p.err == nil {
p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueueFlush failed: %d", osstatus))
return
}
}
p.state = playerPaused