audio/internal/readerdriver: Refactoring (Windows)

This commit is contained in:
Hajime Hoshi 2021-05-29 03:43:05 +09:00
parent 98bfe5a692
commit c46981a719

View File

@ -303,20 +303,6 @@ func (p *playerImpl) playImpl() {
thePlayers.add(p, p.waveOut)
}
buf := make([]byte, p.context.maxBufferSize())
for len(p.buf) < p.context.maxBufferSize() {
n, err := p.src.Read(buf)
if err != nil && err != io.EOF {
p.setErrorImpl(err)
return
}
p.buf = append(p.buf, buf[:n]...)
if err == io.EOF {
p.eof = true
break
}
}
if p.eof && len(p.buf) == 0 {
return
}
@ -537,7 +523,7 @@ func (p *playerImpl) readAndWriteBufferImpl() {
return
}
if len(p.buf) < p.context.maxBufferSize() && !p.eof {
for len(p.buf) < p.context.maxBufferSize() && !p.eof {
buf := make([]byte, p.context.maxBufferSize())
n, err := p.src.Read(buf)
if err != nil && err != io.EOF {
@ -545,13 +531,18 @@ func (p *playerImpl) readAndWriteBufferImpl() {
return
}
p.buf = append(p.buf, buf[:n]...)
if err == io.EOF && len(p.buf) == 0 {
if err == io.EOF {
if len(p.buf) == 0 {
p.eof = true
}
break
}
}
if len(p.buf) > 0 {
for _, h := range p.headers {
if len(p.buf) == 0 {
break
}
if h.IsQueued() {
continue
}
@ -624,7 +615,6 @@ func (p *playerImpl) readAndWriteBufferImpl() {
break
}
}
}
if p.queuedHeadersNum() == 0 && p.eof {
p.pauseImpl()