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