Updating ma_resource_manager_data source while it's playing #656
-
I have written an audio player-type implementation, which lets you play a file, then seek, pause, stop, resume etc. It's using the low-level API and the resource manager for streaming, i.e. When testing, I noticed some odd intermittent hangs and asserts in the flac code being triggered. Which led me to this issue explaining that we can't read PCM frames in the audio callback and seek from the main thread. That made me wonder which data source operations are safe to do from the main thread, while an audio callback is up and running reading data from the same source? Currently, my audio callback is only calling
Are they all unsafe without synchronisation? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
I just tried GPT-4 as well, and it gives a seemingly very reasonable answer. Is it correct? GPT:
|
Beta Was this translation helpful? Give feedback.
-
It's not very well documented, and is something I need to improve in time. Certainly you cannot seek - that's the biggest one and also the most common one I see in the wild. There are other functions that are not thread safe, but they're the kind of things you would set up once at start up and then leave so they're not as important. These include anything that modifies the internal state of the data source, such as ChatGPT is wrong about a few of these. I have added a note to my todo list to make this clearer in the documentation. I also have future plans to auto-generate some API reference documentation which will hopefully make it clearer - it'd be good to have an explicit mention in the reference docs as to whether or not it's safe to call some function while in the middle of reading. |
Beta Was this translation helpful? Give feedback.
It's not very well documented, and is something I need to improve in time. Certainly you cannot seek - that's the biggest one and also the most common one I see in the wild.
There are other functions that are not thread safe, but they're the kind of things you would set up once at start up and then leave so they're not as important. These include anything that modifies the internal state of the data source, such as
set_range()
andset_loop_point()
.ChatGPT is wrong about a few of these.
set_looping()
should be safe - that's using an explicit atomic operation for setting the internal flag. Also,get_length()
is not safe to call from another thread while in the middle of reading in the gene…