Trait sqa_jack::handler::JackHandler
source · pub trait JackHandler: Send {
fn process(&mut self, _ctx: &JackCallbackContext) -> JackControl { ... }
fn buffer_size(&mut self, _new_size: JackNFrames) -> JackControl { ... }
fn sample_rate(&mut self, _new_rate: JackNFrames) -> JackControl { ... }
fn thread_init(&mut self) { ... }
fn shutdown(&mut self, _status: JackStatus, _reason: &str) { ... }
fn client_registered(&mut self, _name: &str, _registered: bool) { ... }
fn xrun(&mut self) -> JackControl { ... }
}
Expand description
Trait for an object that implements JACK callbacks.
Most of the default implementations return JackControl::Continue
- however, process() does not - you
must explicitly override this behaviour if you want to specify nothing for process()
.
Provided Methods
sourcefn process(&mut self, _ctx: &JackCallbackContext) -> JackControl
fn process(&mut self, _ctx: &JackCallbackContext) -> JackControl
This function is called by the engine any time there is work to be done.
Return JackControl::Stop
to stop processing, otherwise return
JackControl::Continue
to continue.
Realtime safety
The code in the supplied function MUST be suitable for real-time execution. That means that it cannot call functions that might block for a long time. This includes all I/O functions (disk, TTY, network), malloc, free, printf, pthread_mutex_lock, sleep, wait, poll, select, pthread_join, pthread_cond_wait, etc.
Rust-specific things to avoid using: std
MPSC channels (use
bounded_spsc_queue instead, or
similar ringbuffer solution), mutexes, RWLock
s, Barrier
s, String
s, Vec
s (use
a pre-allocated ArrayVec instead), and
anything under std::collections
.
sourcefn buffer_size(&mut self, _new_size: JackNFrames) -> JackControl
fn buffer_size(&mut self, _new_size: JackNFrames) -> JackControl
This is called whenever the size of the the buffer that will be passed to the
process()
function is about to change.
Clients that depend on knowing the buffer size must implement this callback.
sourcefn sample_rate(&mut self, _new_rate: JackNFrames) -> JackControl
fn sample_rate(&mut self, _new_rate: JackNFrames) -> JackControl
Called whenever the system sample rate changes.
Given that the JACK API exposes no way to change the sample rate, the library author would like you to know that this is a decidedly rare occurence. Still, it’s worth being prepared ;)
sourcefn thread_init(&mut self)
fn thread_init(&mut self)
Called just once after the creation of the thread in which all other callbacks are handled.
sourcefn shutdown(&mut self, _status: JackStatus, _reason: &str)
fn shutdown(&mut self, _status: JackStatus, _reason: &str)
To be called if and when the JACK server shuts down the client thread.
sourcefn client_registered(&mut self, _name: &str, _registered: bool)
fn client_registered(&mut self, _name: &str, _registered: bool)
Called whenever a client is registered or unregistered.
Use the registered
argument to determine which it is.
sourcefn xrun(&mut self) -> JackControl
fn xrun(&mut self) -> JackControl
Called when an XRUN (over- or under- run) occurs.