-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add initial draft for background operation (loading the state and activate the plugin from a background thread) #343
base: next
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand this design and it seems fit for purpose to me.
One potential downside of this design: plug-ins may have timers, etc., running on the main-thread, which means correctly implementing this design may be difficult. For example, they would have to stop any calls to the host from timers, and make sure there are no data races between the main thread and the bgop thread. I don't see anything here that would be impossible to implement, it just seems quite challenging with a lot of room for error to me.
|
||
4. Perform the background operations | ||
|
||
plugin_state->load(...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must these calls be made on the [bgop-thread]? My reading is yes, the thread must be the same, but I think this should be made explicit as the concept of "symbolic" threads exists elsewhere in the CLAP spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when the plug-in needs to call the host on the main thread as part of an operation here? It's not allowed to main main-thread calls so some things may be difficult for the plug-in author to write
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good question, I'm not sure what's the best answer is:
- allow callbacks on
bgop-thread
- delay the callbacks until
finished()
My gut feeling is that 1. would be the right answer. I don't think it is realistic to have the plugin asking what interfaces it can call from the host on the background thread, so it'd have to be ALL OF THEM.
Co-authored-by: Russell McClellan <[email protected]>
Co-authored-by: Russell McClellan <[email protected]>
Co-authored-by: Russell McClellan <[email protected]>
I wonder whether the following use case is supposed to be covered by some kind of CLAP "background thread" extension or not: The liquidsfz CLAP plugin implementation (planned) may be busy playing one sample (sample bank, soundfont) at a particular point in time, while the user selects a new sample from the file system the plugin is supposed to switch to. AFAICS, the current proposed background-ops spec conflicts with this use case, i.e. main thread calls are suspended in the current proposal and there is no easy way for the plugin to pass a time consuming low-priority callback to the host that is supposed to be executed asynchronously. Is the above use case something that should be accommodated for by a future version of this proposal? |
For reference, for the LV2 plugin, liquidsfz is using the LV2 worker extension to do the necessary expensive operations in background (like parsing and disk I/O) when the user selects a new sfz file:
I haven't seen anything like this for CLAP, so I wonder what the correct way to do it would be. Should the plugin could use So maybe in combination with implementing this extension everything would work similar to the LV2 worker thread? |
The plugin can deal with this without requiring host support.
|
@abique wrote:
@abique wrote:
I fail to see how host and plugins can reliably implement this "thread switching", given the requirements of all the other APIs. A few examples:
I could probably go on with other (callback related) APIs that raise similar questions, but i hope you get where I am confused now. I guess my main problems with this proposal can be summed up as follows:
|
Yeah I get your point. Maybe 2. would be easier: the host performs just one call on the |
bfe862b
to
961be0b
Compare
069d784
to
fc4a9c3
Compare
533e849
to
50f004f
Compare
The idea behind this design is to let the host run some expensive operation on a background thread to reduce the load on the main thread.
I've chosen an approach with a clear transition between the main thread to the background thread
bgop-thread
, because I think it is easier to work that way rather than having to be extra defensive everywhere and expect a call to happen at anytime from a random thread.