audio/internal/readerdriver: Bug fix: AudioQueuePause/Reset might take long time

This issue has existed since ae14caee93.
This change fixes the issue by skipping the C function calls when
possible.

Updates #1650
This commit is contained in:
Hajime Hoshi 2021-05-28 02:45:31 +09:00
parent a4d28198f4
commit 72d8d77173

View File

@ -449,18 +449,20 @@ func (p *playerImpl) resetImpl() {
return
}
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.
q := p.audioQueue
p.cond.L.Unlock()
osstatus := C.AudioQueueReset(q)
p.cond.L.Lock()
if osstatus != C.noErr && p.err == nil {
p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueueReset failed: %d", osstatus))
return
if len(p.unqueuedBufs) < 2 {
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.
q := p.audioQueue
p.cond.L.Unlock()
osstatus := C.AudioQueueReset(q)
p.cond.L.Lock()
if osstatus != C.noErr && p.err == nil {
p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueueReset failed: %d", osstatus))
return
}
}
p.state = playerPaused