Skip to content

Commit

Permalink
Move buffer_size callback to ProcessHandler
Browse files Browse the repository at this point in the history
Resolves RustAudio#137
  • Loading branch information
ollpu committed Mar 26, 2021
1 parent a2fcb2a commit 73d14c8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
5 changes: 0 additions & 5 deletions examples/playback_capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions src/client/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<N, P>(data: *mut libc::c_void)
Expand Down Expand Up @@ -210,7 +214,7 @@ where
P: 'static + Send + ProcessHandler,
{
let ctx = CallbackContext::<N, P>::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, P>(n_frames: Frames, data: *mut libc::c_void) -> libc::c_int
Expand Down
10 changes: 5 additions & 5 deletions src/client/test_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 73d14c8

Please sign in to comment.