-
Notifications
You must be signed in to change notification settings - Fork 78
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
Jack backend uses non "realtime safe" operations #102
Comments
Is this fixable within midir's design? If not, I suggest to remove the JACK backend. |
And if it's not, what kind of design changes would be required (just hypothetically)? |
Zero chance of heap allocation |
So looking at this again, I think there's two things here:
|
Are sysex messages actually arbitrarily sized or is there a defined upper limit?
Yikes. You're right, this is a major problem and doesn't really fit in midir's design. I think it may be best to remove the JACK backend. I also notice that it is using jack-sys directly instead of the safe Rust API for the JACK bindings, so it should probably be rewritten even if it is kept. The JACK implementation (JACK1/JACK2/Pipewire) doesn't matter. In any case the JACK process callback must not heap allocate, block, or invoke any system calls not explicitly defined as being nonblocking or you risk causing audible glitches. This is especially bad in midir's context because an application just trying to get MIDI data could cause glitching in a separate application using JACK for audio. |
My approach for similar problems is usually to have a If you want to support processing in realtime threads, you could add a separate API for that, which would provide the chunked sysex data and maybe some sort of state indicating So yeah, I guess I'm just suggesting what you're talking about in |
midir/src/backend/jack/mod.rs
Lines 176 to 194 in 85eaa46
The process callback is called in the jack process graph which should only be executing "realtime safe" operations but
midir
createsMidiMessage
, which uses a Vec for its bytes, and pushes to thatVec
, which allocates on the heap and is therefore not generally considered "realtime safe."Another thing
Option<T>
only implements https://doc.rust-lang.org/std/option/enum.Option.html#impl-Sync ifT
isSync
and in the case of MidiPort it isn't. So this isn't technically safe either:midir/src/backend/jack/mod.rs
Line 173 in 85eaa46
The text was updated successfully, but these errors were encountered: