mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
Revert "audio: Consider the state of the player's starting and seeking"
This reverts commit 2fee7a6fe5
.
Reason: This causes freezing on browsers
This commit is contained in:
parent
b62e07b9bd
commit
facf184548
@ -74,17 +74,6 @@ func (p *players) Read(b []byte) (int, error) {
|
|||||||
l := len(b)
|
l := len(b)
|
||||||
l &= mask
|
l &= mask
|
||||||
|
|
||||||
for player := range p.players {
|
|
||||||
if player.isJustAfterStartedOrSeeked() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
s := player.bufferSizeInBytes()
|
|
||||||
if l > s {
|
|
||||||
l = s
|
|
||||||
l &= mask
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
b16s := [][]int16{}
|
b16s := [][]int16{}
|
||||||
for player := range p.players {
|
for player := range p.players {
|
||||||
buf, err := player.bufferToInt16(l)
|
buf, err := player.bufferToInt16(l)
|
||||||
@ -93,7 +82,6 @@ func (p *players) Read(b []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
b16s = append(b16s, buf)
|
b16s = append(b16s, buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < l/2; i++ {
|
for i := 0; i < l/2; i++ {
|
||||||
x := 0
|
x := 0
|
||||||
for _, b16 := range b16s {
|
for _, b16 := range b16s {
|
||||||
@ -361,7 +349,7 @@ func NewPlayer(context *Context, src io.ReadCloser) (*Player, error) {
|
|||||||
players: context.players,
|
players: context.players,
|
||||||
src: src,
|
src: src,
|
||||||
sampleRate: context.sampleRate,
|
sampleRate: context.sampleRate,
|
||||||
buf: nil,
|
buf: []byte{},
|
||||||
volume: 1,
|
volume: 1,
|
||||||
closeCh: make(chan struct{}),
|
closeCh: make(chan struct{}),
|
||||||
closedCh: make(chan struct{}),
|
closedCh: make(chan struct{}),
|
||||||
@ -538,15 +526,13 @@ func (p *Player) readLoop() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.isJustAfterStartedOrSeekedImpl() {
|
|
||||||
// Return zero values.
|
|
||||||
p.proceededCh <- proceededValues{buf, nil}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
lengthInBytes := len(buf) * 2
|
lengthInBytes := len(buf) * 2
|
||||||
l := lengthInBytes
|
l := lengthInBytes
|
||||||
|
|
||||||
|
if len(p.buf) < lengthInBytes && !p.srcEOF {
|
||||||
|
p.proceededCh <- proceededValues{buf, nil}
|
||||||
|
break
|
||||||
|
}
|
||||||
if l > len(p.buf) {
|
if l > len(p.buf) {
|
||||||
l = len(p.buf)
|
l = len(p.buf)
|
||||||
}
|
}
|
||||||
@ -557,7 +543,7 @@ func (p *Player) readLoop() {
|
|||||||
p.pos += int64(l)
|
p.pos += int64(l)
|
||||||
p.buf = p.buf[l:]
|
p.buf = p.buf[l:]
|
||||||
|
|
||||||
p.proceededCh <- proceededValues{buf[:l/2], nil}
|
p.proceededCh <- proceededValues{buf, nil}
|
||||||
|
|
||||||
case f := <-p.syncCh:
|
case f := <-p.syncCh:
|
||||||
f()
|
f()
|
||||||
@ -580,28 +566,6 @@ func (p *Player) sync(f func()) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) isJustAfterStartedOrSeeked() bool {
|
|
||||||
r := false
|
|
||||||
p.sync(func() {
|
|
||||||
r = p.isJustAfterStartedOrSeekedImpl()
|
|
||||||
})
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Player) isJustAfterStartedOrSeekedImpl() bool {
|
|
||||||
// When p.buf is nil, the player just starts playing or seeking.
|
|
||||||
// Note that this is different from len(p.buf) == 0 && p.buf != nil.
|
|
||||||
return p.buf == nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Player) bufferSizeInBytes() int {
|
|
||||||
s := 0
|
|
||||||
p.sync(func() {
|
|
||||||
s = len(p.buf)
|
|
||||||
})
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Player) eof() bool {
|
func (p *Player) eof() bool {
|
||||||
r := false
|
r := false
|
||||||
p.sync(func() {
|
p.sync(func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user