audio/internal/readerdriver: Refactoring

This commit is contained in:
Hajime Hoshi 2021-05-09 05:46:55 +09:00
parent 22567d20b6
commit 7eeaef7ff8

View File

@ -96,7 +96,6 @@ type playerImpl struct {
err error err error
eof bool eof bool
cond *sync.Cond cond *sync.Cond
started bool
volume float64 volume float64
} }
@ -303,7 +302,6 @@ 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()
@ -323,6 +321,10 @@ func (p *playerImpl) Pause() {
if p.state != playerPlay { if p.state != playerPlay {
return return
} }
if p.audioQueue == nil {
return
}
if osstatus := C.AudioQueuePause(p.audioQueue); osstatus != C.noErr && p.err == nil { if osstatus := C.AudioQueuePause(p.audioQueue); osstatus != C.noErr && p.err == nil {
p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueuePause failed: %d", osstatus)) p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueuePause failed: %d", osstatus))
return return
@ -342,24 +344,25 @@ func (p *playerImpl) Reset() {
if p.state == playerClosed { if p.state == playerClosed {
return return
} }
if p.audioQueue == nil {
return
}
if p.started { if osstatus := C.AudioQueuePause(p.audioQueue); osstatus != C.noErr && p.err == nil {
if osstatus := C.AudioQueuePause(p.audioQueue); osstatus != C.noErr && p.err == nil { p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueuePause failed: %d", osstatus))
p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueuePause failed: %d", osstatus)) return
return }
} // AudioQueueReset invokes the callback directry.
// AudioQueueReset invokes the callback directry. p.cond.L.Unlock()
p.cond.L.Unlock() if osstatus := C.AudioQueueReset(p.audioQueue); osstatus != C.noErr && p.err == nil {
if osstatus := C.AudioQueueReset(p.audioQueue); osstatus != C.noErr && p.err == nil { p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueueReset failed: %d", osstatus))
p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueueReset failed: %d", osstatus))
p.cond.L.Lock()
return
}
p.cond.L.Lock() p.cond.L.Lock()
if osstatus := C.AudioQueueFlush(p.audioQueue); osstatus != C.noErr && p.err == nil { return
p.setErrorImpl(fmt.Errorf("readerdriver: AudioQueueFlush 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
} }
p.state = playerPaused p.state = playerPaused