diff --git a/examples/playback_capture.rs b/examples/playback_capture.rs index 6a1e8ee9..9f2f4cef 100644 --- a/examples/playback_capture.rs +++ b/examples/playback_capture.rs @@ -64,11 +64,6 @@ impl jack::NotificationHandler for Notifications { ); } - fn buffer_size(&mut self, _: &jack::Client, sz: jack::Frames) -> jack::Control { - println!("JACK: buffer size changed to {}", sz); - jack::Control::Continue - } - fn sample_rate(&mut self, _: &jack::Client, srate: jack::Frames) -> jack::Control { println!("JACK: sample rate changed to {}", srate); jack::Control::Continue diff --git a/src/client/callbacks.rs b/src/client/callbacks.rs index d5cb276d..baf72666 100644 --- a/src/client/callbacks.rs +++ b/src/client/callbacks.rs @@ -25,12 +25,6 @@ pub trait NotificationHandler: Send { /// Called whenever "freewheel" mode is entered or leaving. fn freewheel(&mut self, _: &Client, _is_freewheel_enabled: bool) {} - /// Called whenever the size of the buffer that will be passed to `process` - /// is about to change. - fn buffer_size(&mut self, _: &Client, _size: Frames) -> Control { - Control::Continue - } - /// Called whenever the system sample rate changes. fn sample_rate(&mut self, _: &Client, _srate: Frames) -> Control { Control::Continue @@ -150,6 +144,16 @@ pub trait ProcessHandler: Send { /// Should return `Control::Continue` on success, and /// `Control::Quit` on error. fn process(&mut self, _: &Client, _process_scope: &ProcessScope) -> Control; + + /// Called whenever the size of the buffer that will be passed to `process` + /// is about to change, and once before the first call to `process`. + /// + /// It is called on the same thread as `process`, but as an exception, does + /// not need to be suitable for real-time execution, so it is allowed to + /// allocate new buffers to accomodate the buffer size for example. + fn buffer_size(&mut self, _: &Client, _size: Frames) -> Control { + Control::Continue + } } unsafe extern "C" fn thread_init_callback(data: *mut libc::c_void) @@ -210,7 +214,7 @@ where P: 'static + Send + ProcessHandler, { let ctx = CallbackContext::::from_raw(data); - ctx.notification.buffer_size(&ctx.client, n_frames).to_ffi() + ctx.process.buffer_size(&ctx.client, n_frames).to_ffi() } unsafe extern "C" fn sample_rate(n_frames: Frames, data: *mut libc::c_void) -> libc::c_int diff --git a/src/client/test_callback.rs b/src/client/test_callback.rs index a42040c5..b619cee2 100644 --- a/src/client/test_callback.rs +++ b/src/client/test_callback.rs @@ -27,11 +27,6 @@ impl NotificationHandler for Counter { self.thread_init_count.fetch_add(1, Ordering::Relaxed); } - fn buffer_size(&mut self, _: &Client, size: Frames) -> Control { - self.buffer_size_change_history.push(size); - Control::Continue - } - fn client_registration(&mut self, _: &Client, name: &str, is_registered: bool) { if is_registered { self.registered_client_history.push(name.to_string()) @@ -65,6 +60,11 @@ impl ProcessHandler for Counter { } Control::Continue } + + fn buffer_size(&mut self, _: &Client, size: Frames) -> Control { + self.buffer_size_change_history.push(size); + Control::Continue + } } fn open_test_client(name: &str) -> Client {