Skip to content

Commit

Permalink
Bug 1792743 - Update AudioIPC macOS branch to 42eb59ab. r=cubeb-revie…
Browse files Browse the repository at this point in the history
…wers,padenot

Differential Revision: https://phabricator.services.mozilla.com/D158285
  • Loading branch information
kinetiknz committed Sep 29, 2022
1 parent 83e2f27 commit bd8f657
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ rev = "21c26326f5f45f415c49eac4ba5bc41a2f961321"
[source."https://github.com/kinetiknz/audioipc-2"]
git = "https://github.com/kinetiknz/audioipc-2"
replace-with = "vendored-sources"
rev = "ea7cabf8c9dc051a52ffb6cd7d2564b29b7428eb"
rev = "42eb59ab3b86cd43d3dbe37d159ce102a8eaf2a5"

[source."https://github.com/jfkthame/mapped_hyph.git"]
git = "https://github.com/jfkthame/mapped_hyph.git"
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion third_party/rust/audioipc2-client/.cargo-checksum.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"files":{"Cargo.toml":"31dc34fae9951183eaed3511cffe3d830d52ba3c046257454f09a06156d0716b","cbindgen.toml":"fb6abe1671497f432a06e40b1db7ed7cd2cceecbd9a2382193ad7534e8855e34","src/context.rs":"4593aa41ee97b72622b572ad80f0e4c939d8be2ea45fed1f5587f5a109a67735","src/lib.rs":"c4a6797734489280f6b97dd72c9e51a7bd7be4104592eece3929e29d45cbca4a","src/send_recv.rs":"859abe75b521eb4297c84b30423814b5b87f3c7741ad16fe72189212e123e1ac","src/stream.rs":"a6c07796e6fe704cfa6baf8b904e7ffe874d3c884d44d4ed307e668dec25452b"},"package":null}
{"files":{"Cargo.toml":"31dc34fae9951183eaed3511cffe3d830d52ba3c046257454f09a06156d0716b","cbindgen.toml":"fb6abe1671497f432a06e40b1db7ed7cd2cceecbd9a2382193ad7534e8855e34","src/context.rs":"45d640800e8b287ca0242d867618bf33396fb3a9c270b7fb58adca76e37c72cc","src/lib.rs":"c4a6797734489280f6b97dd72c9e51a7bd7be4104592eece3929e29d45cbca4a","src/send_recv.rs":"859abe75b521eb4297c84b30423814b5b87f3c7741ad16fe72189212e123e1ac","src/stream.rs":"46068bb0da752c9dee489f3620d4588967921000e234110ee066397595700ae0"},"package":null}
22 changes: 12 additions & 10 deletions third_party/rust/audioipc2-client/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ impl ClientContext {
}

#[doc(hidden)]
pub fn rpc(&self) -> rpccore::Proxy<ServerMessage, ClientMessage> {
self.rpc.clone()
pub fn rpc(&self) -> Result<rpccore::Proxy<ServerMessage, ClientMessage>> {
self.rpc.try_clone().map_err(|_| Error::default())
}

#[doc(hidden)]
Expand Down Expand Up @@ -186,7 +186,7 @@ impl ContextOps for ClientContext {
.handle()
.bind_client::<CubebClient>(server_connection)
.map_err(|_| Error::default())?;
let rpc2 = rpc.clone();
let rpc2 = rpc.try_clone().map_err(|_| Error::default())?;

// Don't let errors bubble from here. Later calls against this context
// will return errors the caller expects to handle.
Expand Down Expand Up @@ -225,18 +225,18 @@ impl ContextOps for ClientContext {

fn max_channel_count(&mut self) -> Result<u32> {
assert_not_in_callback();
send_recv!(self.rpc(), ContextGetMaxChannelCount => ContextMaxChannelCount())
send_recv!(self.rpc()?, ContextGetMaxChannelCount => ContextMaxChannelCount())
}

fn min_latency(&mut self, params: StreamParams) -> Result<u32> {
assert_not_in_callback();
let params = messages::StreamParams::from(params.as_ref());
send_recv!(self.rpc(), ContextGetMinLatency(params) => ContextMinLatency())
send_recv!(self.rpc()?, ContextGetMinLatency(params) => ContextMinLatency())
}

fn preferred_sample_rate(&mut self) -> Result<u32> {
assert_not_in_callback();
send_recv!(self.rpc(), ContextGetPreferredSampleRate => ContextPreferredSampleRate())
send_recv!(self.rpc()?, ContextGetPreferredSampleRate => ContextPreferredSampleRate())
}

fn enumerate_devices(
Expand All @@ -246,7 +246,7 @@ impl ContextOps for ClientContext {
) -> Result<()> {
assert_not_in_callback();
let v: Vec<ffi::cubeb_device_info> = send_recv!(
self.rpc(), ContextGetDeviceEnumeration(devtype.bits()) => ContextEnumeratedDevices())?
self.rpc()?, ContextGetDeviceEnumeration(devtype.bits()) => ContextEnumeratedDevices())?
.into_iter()
.map(|i| i.into())
.collect();
Expand Down Expand Up @@ -329,7 +329,7 @@ impl ContextOps for ClientContext {
assert_not_in_callback();

if !self.device_collection_rpc {
let mut fd = send_recv!(self.rpc(),
let mut fd = send_recv!(self.rpc()?,
ContextSetupDeviceCollectionCallback =>
ContextSetupDeviceCollectionCallback())?;

Expand Down Expand Up @@ -358,7 +358,7 @@ impl ContextOps for ClientContext {
}

let enable = collection_changed_callback.is_some();
send_recv!(self.rpc(),
send_recv!(self.rpc()?,
ContextRegisterDeviceCollectionChanged(devtype.bits(), enable) =>
ContextRegisteredDeviceCollectionChanged)
}
Expand All @@ -367,7 +367,9 @@ impl ContextOps for ClientContext {
impl Drop for ClientContext {
fn drop(&mut self) {
debug!("ClientContext dropped...");
let _ = send_recv!(self.rpc(), ClientDisconnect => ClientDisconnected);
let _ = self
.rpc()
.and_then(|rpc| send_recv!(rpc, ClientDisconnect => ClientDisconnected));
}
}

Expand Down
49 changes: 31 additions & 18 deletions third_party/rust/audioipc2-client/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,26 @@ impl rpccore::Server for CallbackServer {

run_in_callback(|| {
let nframes = unsafe {
self.data_cb.unwrap()(
ptr::null_mut(), // https://github.com/kinetiknz/cubeb/issues/518
self.user_ptr as *mut c_void,
let input_ptr = if input_frame_size > 0 {
if let Some(buf) = &mut self.duplex_input {
buf.as_mut_ptr()
buf.as_ptr()
} else {
self.shm.get_slice(input_nbytes).unwrap().as_ptr()
} as *const _,
self.shm.get_mut_slice(output_nbytes).unwrap().as_mut_ptr() as *mut _,
}
} else {
ptr::null()
};
let output_ptr = if output_frame_size > 0 {
self.shm.get_mut_slice(output_nbytes).unwrap().as_mut_ptr()
} else {
ptr::null_mut()
};

self.data_cb.unwrap()(
ptr::null_mut(), // https://github.com/kinetiknz/cubeb/issues/518
self.user_ptr as *mut c_void,
input_ptr as *const _,
output_ptr as *mut _,
nframes as _,
)
};
Expand Down Expand Up @@ -145,7 +156,7 @@ impl<'ctx> ClientStream<'ctx> {
) -> Result<Stream> {
assert_not_in_callback();

let rpc = ctx.rpc();
let rpc = ctx.rpc()?;
let create_params = StreamCreateParams {
input_stream_params: init_params.input_stream_params,
output_stream_params: init_params.output_stream_params,
Expand Down Expand Up @@ -227,8 +238,10 @@ impl<'ctx> ClientStream<'ctx> {
impl Drop for ClientStream<'_> {
fn drop(&mut self) {
debug!("ClientStream drop");
let rpc = self.context.rpc();
let _ = send_recv!(rpc, StreamDestroy(self.token) => StreamDestroyed);
let _ = self
.context
.rpc()
.and_then(|rpc| send_recv!(rpc, StreamDestroy(self.token) => StreamDestroyed));
debug!("ClientStream drop - stream destroyed");
// Wait for CallbackServer to shutdown. The remote server drops the RPC
// connection during StreamDestroy, which will cause CallbackServer to drop
Expand All @@ -243,49 +256,49 @@ impl Drop for ClientStream<'_> {
impl StreamOps for ClientStream<'_> {
fn start(&mut self) -> Result<()> {
assert_not_in_callback();
let rpc = self.context.rpc();
let rpc = self.context.rpc()?;
send_recv!(rpc, StreamStart(self.token) => StreamStarted)
}

fn stop(&mut self) -> Result<()> {
assert_not_in_callback();
let rpc = self.context.rpc();
let rpc = self.context.rpc()?;
send_recv!(rpc, StreamStop(self.token) => StreamStopped)
}

fn position(&mut self) -> Result<u64> {
assert_not_in_callback();
let rpc = self.context.rpc();
let rpc = self.context.rpc()?;
send_recv!(rpc, StreamGetPosition(self.token) => StreamPosition())
}

fn latency(&mut self) -> Result<u32> {
assert_not_in_callback();
let rpc = self.context.rpc();
let rpc = self.context.rpc()?;
send_recv!(rpc, StreamGetLatency(self.token) => StreamLatency())
}

fn input_latency(&mut self) -> Result<u32> {
assert_not_in_callback();
let rpc = self.context.rpc();
let rpc = self.context.rpc()?;
send_recv!(rpc, StreamGetInputLatency(self.token) => StreamInputLatency())
}

fn set_volume(&mut self, volume: f32) -> Result<()> {
assert_not_in_callback();
let rpc = self.context.rpc();
let rpc = self.context.rpc()?;
send_recv!(rpc, StreamSetVolume(self.token, volume) => StreamVolumeSet)
}

fn set_name(&mut self, name: &CStr) -> Result<()> {
assert_not_in_callback();
let rpc = self.context.rpc();
let rpc = self.context.rpc()?;
send_recv!(rpc, StreamSetName(self.token, name.to_owned()) => StreamNameSet)
}

fn current_device(&mut self) -> Result<&DeviceRef> {
assert_not_in_callback();
let rpc = self.context.rpc();
let rpc = self.context.rpc()?;
match send_recv!(rpc, StreamGetCurrentDevice(self.token) => StreamCurrentDevice()) {
Ok(d) => Ok(unsafe { DeviceRef::from_ptr(Box::into_raw(Box::new(d.into()))) }),
Err(e) => Err(e),
Expand All @@ -309,7 +322,7 @@ impl StreamOps for ClientStream<'_> {
device_changed_callback: ffi::cubeb_device_changed_callback,
) -> Result<()> {
assert_not_in_callback();
let rpc = self.context.rpc();
let rpc = self.context.rpc()?;
let enable = device_changed_callback.is_some();
*self.device_change_cb.lock().unwrap() = device_changed_callback;
send_recv!(rpc, StreamRegisterDeviceChangeCallback(self.token, enable) => StreamRegisterDeviceChangeCallback)
Expand Down
2 changes: 1 addition & 1 deletion third_party/rust/audioipc2-server/.cargo-checksum.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"files":{"Cargo.toml":"7feb495b23148ecc83ec7f480aefe19c9804a8900cdb4ceb005c049cdce82428","cbindgen.toml":"fb6abe1671497f432a06e40b1db7ed7cd2cceecbd9a2382193ad7534e8855e34","src/lib.rs":"d9cc7ca311cceb70acbc63b2190d6205094152e582faaad1b4a6061019f5803f","src/server.rs":"362ec34c541e43befb95204795622b5a2da036f8e417d524c64eb6c6550d094b"},"package":null}
{"files":{"Cargo.toml":"7feb495b23148ecc83ec7f480aefe19c9804a8900cdb4ceb005c049cdce82428","cbindgen.toml":"fb6abe1671497f432a06e40b1db7ed7cd2cceecbd9a2382193ad7534e8855e34","src/lib.rs":"d9cc7ca311cceb70acbc63b2190d6205094152e582faaad1b4a6061019f5803f","src/server.rs":"744f655486469daa4973d9101bd76a124ab6169b46b540f1c955932f6139e89f"},"package":null}
20 changes: 11 additions & 9 deletions third_party/rust/audioipc2-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,15 @@ impl Drop for CubebServer {
context: Ok(context),
}) = state.as_mut()
{
let r = manager.unregister(
context,
device_collection_change_callbacks,
cubeb::DeviceType::all(),
);
if r.is_err() {
debug!("CubebServer: unregister failed: {:?}", r);
for devtype in [cubeb::DeviceType::INPUT, cubeb::DeviceType::OUTPUT] {
let r = manager.unregister(
context,
device_collection_change_callbacks,
devtype,
);
if r.is_err() {
debug!("CubebServer: unregister failed: {:?}", r);
}
}
}
})
Expand Down Expand Up @@ -722,8 +724,8 @@ impl CubebServer {
input_frame_size,
output_frame_size,
shm,
state_callback_rpc: rpc.clone(),
device_change_callback_rpc: rpc.clone(),
state_callback_rpc: rpc.try_clone()?,
device_change_callback_rpc: rpc.try_clone()?,
data_callback_rpc: rpc,
});

Expand Down
2 changes: 1 addition & 1 deletion third_party/rust/audioipc2/.cargo-checksum.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"files":{"Cargo.toml":"8b2d3abbe023360a24d37b306dbec9e8bd0162025d38ca106ebcc8d7abab4039","benches/serialization.rs":"d56855d868dab6aa22c8b03a61084535351b76c94b68d8b1d20764e352fe473f","build.rs":"65df9a97c6cdaa3faf72581f04ac289197b0b1797d69d22c1796e957ff1089e2","src/codec.rs":"4e029396765db803201249e90bcf724eb56deed3b2e455822d6673f40550a3e1","src/errors.rs":"67a4a994d0724397657581cde153bdfc05ce86e7efc467f23fafc8f64df80fa4","src/ipccore.rs":"eda3629e363124c84d5b826dea03f5551a8adad6c8efbc61b98f7d6572fdfa18","src/lib.rs":"9b107cb52081eeea3fa742d30361db70f7138baa423dfe21d37dcf5087afc338","src/messages.rs":"452362da2cace9a0f2e3134c190ecb6a9997f8be4036cde06643e17c6c238240","src/rpccore.rs":"21568946ca59e0cf1cb0dc6254ebda577a014343438a4fde2556a22e44eea2bf","src/shm.rs":"1d88f19606899e3e477865d6b84bbe3e272f51618a1c2d57b6dab03a4787cde3","src/sys/mod.rs":"e6fa1d260abf093e1f7b50185195e2d3aee0eb8c9774c6f253953b5896d838f3","src/sys/unix/cmsg.rs":"8a27a20383c333c5d033e58a546a530e26b964942a4615793d1ca078c65efb75","src/sys/unix/cmsghdr.c":"d7344b3dc15cdce410c68669b848bb81f7fe36362cd3699668cb613fa05180f8","src/sys/unix/mod.rs":"59835f0d5509940078b1820a54f49fc5514adeb3e45e7d21e3ab917431da2e74","src/sys/unix/msg.rs":"c0103cc058aeb890ab7aa023fcd6d3b9a0135d6b28fdecdec446650957210508","src/sys/windows/mod.rs":"7b1288e42b3ce34c7004b9fe3eeb6d9822c55e2688d3c2a40e55db46a2ca5d76"},"package":null}
{"files":{"Cargo.toml":"8b2d3abbe023360a24d37b306dbec9e8bd0162025d38ca106ebcc8d7abab4039","benches/serialization.rs":"d56855d868dab6aa22c8b03a61084535351b76c94b68d8b1d20764e352fe473f","build.rs":"65df9a97c6cdaa3faf72581f04ac289197b0b1797d69d22c1796e957ff1089e2","src/codec.rs":"4e029396765db803201249e90bcf724eb56deed3b2e455822d6673f40550a3e1","src/errors.rs":"67a4a994d0724397657581cde153bdfc05ce86e7efc467f23fafc8f64df80fa4","src/ipccore.rs":"be36c9d927a4ea35869163f2a30be77366acfffadb7f67f550b3b9c53b23a201","src/lib.rs":"9b107cb52081eeea3fa742d30361db70f7138baa423dfe21d37dcf5087afc338","src/messages.rs":"452362da2cace9a0f2e3134c190ecb6a9997f8be4036cde06643e17c6c238240","src/rpccore.rs":"9b7199c0e31941c399934c4442e2169fb85c6067810c37879d1c9614ce00bdf5","src/shm.rs":"1d88f19606899e3e477865d6b84bbe3e272f51618a1c2d57b6dab03a4787cde3","src/sys/mod.rs":"e6fa1d260abf093e1f7b50185195e2d3aee0eb8c9774c6f253953b5896d838f3","src/sys/unix/cmsg.rs":"8a27a20383c333c5d033e58a546a530e26b964942a4615793d1ca078c65efb75","src/sys/unix/cmsghdr.c":"d7344b3dc15cdce410c68669b848bb81f7fe36362cd3699668cb613fa05180f8","src/sys/unix/mod.rs":"59835f0d5509940078b1820a54f49fc5514adeb3e45e7d21e3ab917431da2e74","src/sys/unix/msg.rs":"c0103cc058aeb890ab7aa023fcd6d3b9a0135d6b28fdecdec446650957210508","src/sys/windows/mod.rs":"7b1288e42b3ce34c7004b9fe3eeb6d9822c55e2688d3c2a40e55db46a2ca5d76"},"package":null}
20 changes: 16 additions & 4 deletions third_party/rust/audioipc2/src/ipccore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl EventLoopHandle {
<C as Client>::ServerMessage: Serialize + Debug + AssociateHandleForMessage + Send,
<C as Client>::ClientMessage: DeserializeOwned + Debug + AssociateHandleForMessage + Send,
{
let (handler, mut proxy) = make_client::<C>();
let (handler, mut proxy) = make_client::<C>()?;
let driver = Box::new(FramedDriver::new(handler));
let r = self.add_connection(connection, driver);
trace!("EventLoop::bind_client {:?}", r);
Expand Down Expand Up @@ -236,7 +236,7 @@ impl EventLoop {
debug!("{}: {:?}: done, removing", self.name, token);
let mut connection = self.connections.remove(token.0);
if let Err(e) = connection.shutdown(self.poll.registry()) {
warn!(
debug!(
"{}: EventLoop drop - closing connection for {:?} failed: {:?}",
self.name, token, e
);
Expand Down Expand Up @@ -286,7 +286,7 @@ impl EventLoop {
debug!("{}: {:?}: done (wake), removing", self.name, token);
let mut connection = self.connections.remove(token.0);
if let Err(e) = connection.shutdown(self.poll.registry()) {
warn!(
debug!(
"{}: EventLoop drop - closing connection for {:?} failed: {:?}",
self.name, token, e
);
Expand All @@ -309,7 +309,7 @@ impl Drop for EventLoop {
self.name, token
);
if let Err(e) = connection.shutdown(self.poll.registry()) {
warn!(
debug!(
"{}: EventLoop drop - closing connection for {:?} failed: {:?}",
self.name, token, e
);
Expand Down Expand Up @@ -882,6 +882,18 @@ mod test {
.expect_err("sending on closed channel");
}

#[test]
fn clone_after_drop() {
init();
let (server, client, client_proxy) = setup();
drop(server);
drop(client);

client_proxy
.try_clone()
.expect_err("cloning a closed proxy");
}

#[test]
fn basic_event_loop_thread_callbacks() {
init();
Expand Down
Loading

0 comments on commit bd8f657

Please sign in to comment.