sbooth / SFBAudioEngine

A powerhouse of audio functionality for macOS and iOS
https://sbooth.github.io/SFBAudioEngine/
MIT License
552 stars 87 forks source link

Decoder queue not cleared correctly #178

Closed gttmnn closed 3 years ago

gttmnn commented 3 years ago

Not sure what I am doing wrong but it seems like the decoder queue is not cleared correctly when playing tracks. This shows up in the log when the problem is about to happen:

No open slots in _decoderStateArray

The result is that the playback is stopped and the requested track might or might not play.

The problem can be reproduced in the SimplePlayer-macOS example project by loading a file and then double-clicking the playlist item multiple times to play it again and again. It does not seem to happen when tracks are played sequentially, so it seems to be tied to how "fast" tracks are queued and played.

Full log output: output.txt

macOS 10.15.7 Xcode 12.3

sbooth commented 3 years ago

This bug is related to how often the garbage collector dispatch source runs, which by default is once every 10 seconds. To fix it the collector needs to run more often or have the ability to be signaled on demand (perhaps via a semaphore). I will look into a fix.

sbooth commented 3 years ago

I've created an experimental fix at https://github.com/sbooth/SFBAudioEngine/tree/collector-thread

gttmnn commented 3 years ago

That was blazing fast, thank you very much. I did some quick testing and it all seems to work with the fix, amazing.

sbooth commented 3 years ago

I'm glad it's working for you now.

I reworked the code to use a dispatch source instead of a a dedicated thread. In theory this should decrease the overhead.