From d6e257084d301bbd447645a4b728a5c745618dc8 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 27 Jun 2022 22:50:16 +0900 Subject: [PATCH] audio: bug fix: potential busy reading after the source reaches EOF Closes #2167 Updates hajimehoshi/oto#171 --- audio/internal/cbackend/player.go | 14 +++++++++----- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/audio/internal/cbackend/player.go b/audio/internal/cbackend/player.go index 11f068a5d..d633402af 100644 --- a/audio/internal/cbackend/player.go +++ b/audio/internal/cbackend/player.go @@ -221,9 +221,7 @@ func (p *playerImpl) playImpl() { } p.buf = append(p.buf, buf[:n]...) if err == io.EOF { - if len(p.buf) == 0 { - p.eof = true - } + p.eof = true break } } @@ -367,6 +365,10 @@ func (p *playerImpl) readBufferAndAdd(buf []float32) int { copy(p.buf, p.buf[n*bitDepthInBytes:]) p.buf = p.buf[:len(p.buf)-n*bitDepthInBytes] + if p.eof && len(p.buf) == 0 { + p.state = playerPaused + } + return n } @@ -404,9 +406,11 @@ func (p *playerImpl) readSourceToBuffer() { } p.buf = append(p.buf, buf[:n]...) - if err == io.EOF && len(p.buf) == 0 { - p.state = playerPaused + if err == io.EOF { p.eof = true + if len(p.buf) == 0 { + p.state = playerPaused + } } } diff --git a/go.mod b/go.mod index 33d438924..99f24710b 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/hajimehoshi/bitmapfont/v2 v2.2.0 github.com/hajimehoshi/file2byteslice v0.0.0-20210813153925-5340248a8f41 github.com/hajimehoshi/go-mp3 v0.3.3 - github.com/hajimehoshi/oto/v2 v2.2.0-alpha.3 + github.com/hajimehoshi/oto/v2 v2.2.0-alpha.3.0.20220627134823-65dbd988610c github.com/jakecoffman/cp v1.2.0 github.com/jezek/xgb v1.0.1 github.com/jfreymuth/oggvorbis v1.0.3 diff --git a/go.sum b/go.sum index 4935f1d7b..89b4cba15 100644 --- a/go.sum +++ b/go.sum @@ -11,8 +11,8 @@ github.com/hajimehoshi/go-mp3 v0.3.3 h1:cWnfRdpye2m9ElSoVqneYRcpt/l3ijttgjMeQh+r github.com/hajimehoshi/go-mp3 v0.3.3/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM= github.com/hajimehoshi/oto v0.6.1 h1:7cJz/zRQV4aJvMSSRqzN2TImoVVMpE0BCY4nrNJaDOM= github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI= -github.com/hajimehoshi/oto/v2 v2.2.0-alpha.3 h1:hBxyR67t2ErMcF/aTxB8FOzMaBj+62T5RTgjfth6fXE= -github.com/hajimehoshi/oto/v2 v2.2.0-alpha.3/go.mod h1:9i0oYbpJ8BhVGkXDKdXKfFthX1JUNfXjeTp944W8TGM= +github.com/hajimehoshi/oto/v2 v2.2.0-alpha.3.0.20220627134823-65dbd988610c h1:hHMvizeDtTgaLcvh78CvzVi82yrYkUJsr81vfRBeeg0= +github.com/hajimehoshi/oto/v2 v2.2.0-alpha.3.0.20220627134823-65dbd988610c/go.mod h1:9i0oYbpJ8BhVGkXDKdXKfFthX1JUNfXjeTp944W8TGM= github.com/jakecoffman/cp v1.2.0 h1:ZdCFqHglNYJibiIeRvpAktJ7ZuWUnh0cnBsZNKVbY3A= github.com/jakecoffman/cp v1.2.0/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg= github.com/jezek/xgb v1.0.1 h1:YUGhxps0aR7J2Xplbs23OHnV1mWaxFVcOl9b+1RQkt8=