audio/internal/readerdriver: Refactoring (darwin)

This commit is contained in:
Hajime Hoshi 2021-05-17 23:18:55 +09:00
parent 58f6eb0dea
commit ae14caee93

View File

@ -435,7 +435,10 @@ func (p *player) Reset() {
func (p *playerImpl) Reset() { func (p *playerImpl) Reset() {
p.cond.L.Lock() p.cond.L.Lock()
defer p.cond.L.Unlock() defer p.cond.L.Unlock()
p.resetImpl()
}
func (p *playerImpl) resetImpl() {
if p.err != nil { if p.err != nil {
return return
} }
@ -520,14 +523,10 @@ func (p *player) Close() error {
func (p *playerImpl) Close() error { func (p *playerImpl) Close() error {
p.cond.L.Lock() p.cond.L.Lock()
defer p.cond.L.Unlock() defer p.cond.L.Unlock()
return p.closeImpl(false) return p.closeImpl()
} }
func (p *playerImpl) closeForReuseImpl() error { func (p *playerImpl) closeImpl() error {
return p.closeImpl(true)
}
func (p *playerImpl) closeImpl(reuseLater bool) error {
if p.audioQueue != nil { if p.audioQueue != nil {
// Even if reuseLater is true, AudioQueuePause is not efficient for reusing. // Even if reuseLater is true, AudioQueuePause is not efficient for reusing.
// AudioQueueStart takes long if the AudioQueueStop is not called. // AudioQueueStart takes long if the AudioQueueStop is not called.
@ -551,15 +550,7 @@ func (p *playerImpl) closeImpl(reuseLater bool) error {
p.audioQueue = nil p.audioQueue = nil
} }
// When reuseLater is true, this playerImpl can be reused later even though the AudioQueue is removed. p.state = playerClosed
if reuseLater {
p.state = playerPaused
p.buf = p.buf[:0]
p.eof = false
p.unqueuedBufs = nil
} else {
p.state = playerClosed
}
p.cond.Signal() p.cond.Signal()
return p.err return p.err
} }
@ -580,7 +571,7 @@ func ebiten_readerdriver_render(inUserData unsafe.Pointer, inAQ C.AudioQueueRef,
defer p.cond.L.Unlock() defer p.cond.L.Unlock()
p.unqueuedBufs = append(p.unqueuedBufs, inBuffer) p.unqueuedBufs = append(p.unqueuedBufs, inBuffer)
if len(p.unqueuedBufs) == 2 && p.eof { if len(p.unqueuedBufs) == 2 && p.eof {
p.closeForReuseImpl() p.resetImpl()
} }
} }
@ -656,7 +647,7 @@ func (p *playerImpl) setError(err error) {
func (p *playerImpl) setErrorImpl(err error) { func (p *playerImpl) setErrorImpl(err error) {
p.err = err p.err = err
p.closeImpl(false) p.closeImpl()
} }
func (p *playerImpl) loop() { func (p *playerImpl) loop() {