Skip to content

Commit

Permalink
Bug 1601859 - Update cubeb-coreaudio to 5fcbd99e1b7356be1efcdc41654d4…
Browse files Browse the repository at this point in the history
…95bd4c71c8c. r=padenot

Differential Revision: https://phabricator.services.mozilla.com/D56163

--HG--
extra : moz-landing-system : lando
  • Loading branch information
glandium committed Dec 11, 2019
1 parent 7f4fff1 commit 154efe3
Show file tree
Hide file tree
Showing 13 changed files with 393 additions and 156 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 @@ replace-with = "vendored-sources"
[source."https://github.com/ChunMinChang/cubeb-coreaudio-rs"]
git = "https://github.com/ChunMinChang/cubeb-coreaudio-rs"
replace-with = "vendored-sources"
rev = "0920240e4166d2b562840c8062e149d63f7c3a02"
rev = "5fcbd99e1b7356be1efcdc41654d495bd4c71c8c"

[source.crates-io]
replace-with = "vendored-sources"
Expand Down
12 changes: 6 additions & 6 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/coreaudio-sys-utils/.cargo-checksum.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"files":{"Cargo.toml":"077906135ef930990c17a944953291db52f5e2e178cad992872228f6dc35d263","src/aggregate_device.rs":"7d2bd5f5fd7f3d008ebb69ad81f522ca0cb73db6d7b3e50ed1a63ea26ff721f4","src/audio_object.rs":"df10160d9fd83a2c23a49e69b78d39db3a9d6389607df6acfc05821293b6af5f","src/audio_unit.rs":"bc743a1b8033ab5459520c75d7f5230d24cda5ea1198a5b4e1594256af308f47","src/cf_mutable_dict.rs":"fc42edd270c6dfb02f123214d2d8e487bbd62b5bd923b71eec13190fd0104d2a","src/dispatch.rs":"c3d43571f610cb8524ef49b5928da8363651507bb2ccec443be58c8688e111cb","src/lib.rs":"bcc559d69ef6ed0cbea5b2a36fec89d8c011eb9da70e2f26c00f881ad97a2546","src/string.rs":"ddce19b0f0e6aceb64fa96d2f15f6b191051255f58b340737028fb464087d4e1"},"package":null}
{"files":{"Cargo.toml":"35acbd2f8633a6109f3d3e554bef8d847c049ce6ef7a5f570468819e41344d7f","src/aggregate_device.rs":"7d2bd5f5fd7f3d008ebb69ad81f522ca0cb73db6d7b3e50ed1a63ea26ff721f4","src/audio_object.rs":"df10160d9fd83a2c23a49e69b78d39db3a9d6389607df6acfc05821293b6af5f","src/audio_unit.rs":"bc743a1b8033ab5459520c75d7f5230d24cda5ea1198a5b4e1594256af308f47","src/cf_mutable_dict.rs":"fc42edd270c6dfb02f123214d2d8e487bbd62b5bd923b71eec13190fd0104d2a","src/dispatch.rs":"195ca94cbc61948637bfdcbe22070a1e6d41e97cec22301df4e45dcef7b1c208","src/lib.rs":"bcc559d69ef6ed0cbea5b2a36fec89d8c011eb9da70e2f26c00f881ad97a2546","src/string.rs":"ddce19b0f0e6aceb64fa96d2f15f6b191051255f58b340737028fb464087d4e1"},"package":null}
1 change: 1 addition & 0 deletions third_party/rust/coreaudio-sys-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "coreaudio-sys-utils"
version = "0.1.0"
authors = ["Chun-Min Chang <[email protected]>"]
edition = "2018"
license = "ISC"

[dependencies]
core-foundation-sys = { version = "0.6" }
Expand Down
6 changes: 3 additions & 3 deletions third_party/rust/coreaudio-sys-utils/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ where
F: FnOnce(),
{
// Retake the leaked closure.
let closure: Box<F> = unsafe { Box::from_raw(unboxed_closure as *mut F) };
let closure = unsafe { Box::from_raw(unboxed_closure as *mut F) };
// Execute the closure.
(*closure)();
// closure is released after finishiing this function call.
// closure is released after finishing this function call.
}

let closure: Box<F> = Box::new(closure); // Allocate closure on heap.
let closure = Box::new(closure); // Allocate closure on heap.
let executor: dispatch_function_t = Some(closure_executer::<F>);

(
Expand Down
2 changes: 1 addition & 1 deletion third_party/rust/cubeb-coreaudio/.cargo-checksum.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"files":{".editorconfig":"4e53b182bcc78b83d7e1b5c03efa14d22d4955c4ed2514d1ba4e99c1eb1a50ba",".travis.yml":"bea421508af5f4d00b941866dae0ae7d94a51b9276688a7f626686e8ed8fbbf3","Cargo.toml":"208c7d2c2240a1e38070313a981f61c72f81a017faf93d5ca350e0fae3a35df4","LICENSE":"6e6f56aff5bbf3cbc60747e152fb1a719bd0716aaf6d711c554f57d92e96297c","README.md":"72d8a890d6bda3cdba393432e5ae2018a385980785ebb2b96e9c3f82a48a1b59","run_tests.sh":"871864068903c37b04857f3509361f93fbbcf2b81d74eae5715ac2b451458813","src/backend/aggregate_device.rs":"7cd732f3e1e71876753515b26ee69a315414e58869216e99ff95c6828408c4db","src/backend/auto_array.rs":"5f35545baba2b005e13a2225bd1cbdd94ffc2097554d61479929bfc5442a6dd6","src/backend/auto_release.rs":"050fdcee74cf46b9a8a85a877e166d72a853d33220f59cf734cbb6ea09daa441","src/backend/device_property.rs":"1b066b48ed09026a9286b1b8f40e2720854c3410b0f02c795a580792fda34ea9","src/backend/mixer.rs":"74dcac459493e2f919b61ed3bebe500027e422eb06b1ecd30b73a47079c61f7c","src/backend/mod.rs":"7b57ec50f24cffbacd323162b6b9357c276c151e2844c8e32fbe779b18ef3179","src/backend/resampler.rs":"fd1281d28a4db1659d2f75e43b8457651745e1b6eb5a53a77f04d752135f6dc7","src/backend/tests/aggregate_device.rs":"107f5c637844cd5ae43d2b42cec4ef3369bb702751586078c0a9d50f039161cd","src/backend/tests/api.rs":"d76c1574179085e0c1342614cd674e5aa211dd456f3725aeb294def6b32750fd","src/backend/tests/backlog.rs":"3b189a7e036543c467cc242af0ed3332721179ee2b1c8847a6db563546f1ac52","src/backend/tests/device_change.rs":"e098dafaeedd7fbbf58378c2e74e7a245dba1cf8832695c1b08932a669131e44","src/backend/tests/device_property.rs":"b1a9ae79aa5b9a3f180040d0ef0954b134680d586882d2062c5e017b555bff57","src/backend/tests/interfaces.rs":"01fc2d54ddb50f014a44f9c137f078645738bcc81e48140a3e7ae68e18a61b6b","src/backend/tests/manual.rs":"066a7d981dc02d7a3fd83486b51e27ea1c9223496167ccb23a6478fde073e882","src/backend/tests/mod.rs":"8dba770023d7f9c4228f0e11915347f0e07da5fd818e3ee4478c4b197af9aa2a","src/backend/tests/parallel.rs":"f9e1883660d6146b6e5075806561f5f689810e25c5e7764dfd28c9b939821a49","src/backend/tests/tone.rs":"16150438317ce501986734167b5fb97bfec567228acbcd8f3b4c4484c22f29e0","src/backend/tests/utils.rs":"eb552657e68e67b8a60d04ad1bbb46cd1401bcafa27d383dccf4db141c8089c5","src/backend/utils.rs":"ee77bc266d672d3d9e23eb3290c1f897687394c6e459338804a17433380a6fd2","src/capi.rs":"61f8f0c4373adaefba1eb6e7084687e83a10136db96438bc35884327668e411f","src/lib.rs":"1ff4b738ed194061fca4ff745f847dea4de4e7a4fa1f898e7b4ad5e70c62386d","todo.md":"a66296c220cad24d08ee780308007a702f7e421edf0bb60464c3ce8feeda1882"},"package":null}
{"files":{".editorconfig":"4e53b182bcc78b83d7e1b5c03efa14d22d4955c4ed2514d1ba4e99c1eb1a50ba",".travis.yml":"bea421508af5f4d00b941866dae0ae7d94a51b9276688a7f626686e8ed8fbbf3","Cargo.toml":"d1b1a03695cf8c92daa58cccb391a03b1d0b82a70505424c25fa40aba19411af","LICENSE":"6e6f56aff5bbf3cbc60747e152fb1a719bd0716aaf6d711c554f57d92e96297c","README.md":"72d8a890d6bda3cdba393432e5ae2018a385980785ebb2b96e9c3f82a48a1b59","run_tests.sh":"c764a89fe2a6b7ccdeb01895d29b2017c5b76f468aff456050babd66c1472687","src/backend/aggregate_device.rs":"7cd732f3e1e71876753515b26ee69a315414e58869216e99ff95c6828408c4db","src/backend/auto_array.rs":"5f35545baba2b005e13a2225bd1cbdd94ffc2097554d61479929bfc5442a6dd6","src/backend/auto_release.rs":"050fdcee74cf46b9a8a85a877e166d72a853d33220f59cf734cbb6ea09daa441","src/backend/device_property.rs":"1b066b48ed09026a9286b1b8f40e2720854c3410b0f02c795a580792fda34ea9","src/backend/mixer.rs":"74dcac459493e2f919b61ed3bebe500027e422eb06b1ecd30b73a47079c61f7c","src/backend/mod.rs":"567c32965797212d33464981b847dc934fdc73c8f5ea226ea3243a585f8630d2","src/backend/resampler.rs":"fd1281d28a4db1659d2f75e43b8457651745e1b6eb5a53a77f04d752135f6dc7","src/backend/tests/aggregate_device.rs":"107f5c637844cd5ae43d2b42cec4ef3369bb702751586078c0a9d50f039161cd","src/backend/tests/api.rs":"d76c1574179085e0c1342614cd674e5aa211dd456f3725aeb294def6b32750fd","src/backend/tests/backlog.rs":"3b189a7e036543c467cc242af0ed3332721179ee2b1c8847a6db563546f1ac52","src/backend/tests/device_change.rs":"bebda3dbbcd432d7c545dbe27c388773f61f68a1c8b947f61deb358682dbe53b","src/backend/tests/device_property.rs":"b1a9ae79aa5b9a3f180040d0ef0954b134680d586882d2062c5e017b555bff57","src/backend/tests/interfaces.rs":"01fc2d54ddb50f014a44f9c137f078645738bcc81e48140a3e7ae68e18a61b6b","src/backend/tests/manual.rs":"c0b8888e1f7fc09913862300023452753384e038b7433e3975b772988925f52c","src/backend/tests/mod.rs":"8dba770023d7f9c4228f0e11915347f0e07da5fd818e3ee4478c4b197af9aa2a","src/backend/tests/parallel.rs":"f9e1883660d6146b6e5075806561f5f689810e25c5e7764dfd28c9b939821a49","src/backend/tests/tone.rs":"16150438317ce501986734167b5fb97bfec567228acbcd8f3b4c4484c22f29e0","src/backend/tests/utils.rs":"981e4669902231d10f8c3d5c39d82358acc8159f026b8be27f4ab76ef19fcda3","src/backend/utils.rs":"ee77bc266d672d3d9e23eb3290c1f897687394c6e459338804a17433380a6fd2","src/capi.rs":"61f8f0c4373adaefba1eb6e7084687e83a10136db96438bc35884327668e411f","src/lib.rs":"1ff4b738ed194061fca4ff745f847dea4de4e7a4fa1f898e7b4ad5e70c62386d","todo.md":"a66296c220cad24d08ee780308007a702f7e421edf0bb60464c3ce8feeda1882"},"package":null}
1 change: 1 addition & 0 deletions third_party/rust/cubeb-coreaudio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name = "cubeb-coreaudio"
version = "0.1.0"
authors = ["Chun-Min Chang <[email protected]>", "Paul Adenot <[email protected]>"]
license = "ISC"

[lib]
crate-type = ["staticlib", "rlib"]
Expand Down
4 changes: 4 additions & 0 deletions third_party/rust/cubeb-coreaudio/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# display backtrace for debugging
export RUST_BACKTRACE=1

# Regular Tests
cargo test --verbose
cargo test test_configure_output -- --ignored
Expand Down Expand Up @@ -42,3 +45,4 @@ cargo test test_reinit_duplex_stream_by_unplugging_a_default_output_device -- --
# cargo test test_switch_output_device -- --ignored --nocapture
# cargo test test_add_then_remove_listeners -- --ignored --nocapture
# cargo test test_device_collection_change -- --ignored --nocapture
# cargo test test_stream_tester -- --ignored --nocapture
53 changes: 35 additions & 18 deletions third_party/rust/cubeb-coreaudio/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2439,6 +2439,10 @@ impl<'ctx> CoreStreamData<'ctx> {
}

fn start_audiounits(&self) -> Result<()> {
// Only allowed to be called after the stream is initialized
// and before the stream is destroyed.
assert!(!self.input_unit.is_null() || !self.output_unit.is_null());

if !self.input_unit.is_null() {
start_audiounit(self.input_unit)?;
}
Expand Down Expand Up @@ -3379,30 +3383,27 @@ impl<'ctx> AudioUnitStream<'ctx> {
}

fn destroy(&mut self) {
// Call stop_audiounits to avoid potential data race. If there is a running data callback,
// which locks a mutex inside CoreAudio framework, then this call will block the current
// thread until the callback is finished since this call asks to lock a mutex inside
// CoreAudio framework that is used by the data callback.
if !self.shutdown.load(Ordering::SeqCst) {
self.core_stream_data.stop_audiounits();
*self.shutdown.get_mut() = true;
}

*self.destroy_pending.get_mut() = true;

let queue = self.context.serial_queue;
let mutexed_stm = Arc::new(Mutex::new(self));
let also_mutexed_stm = Arc::clone(&mutexed_stm);

let stream_ptr = self as *const AudioUnitStream;
// Execute close in serial queue to avoid collision
// with reinit when un/plug devices
sync_dispatch(queue, move || {
let mut stm_guard = also_mutexed_stm.lock().unwrap();
stm_guard.destroy_internal();
// Call stop_audiounits to avoid potential data race. If there is a running data callback,
// which locks a mutex inside CoreAudio framework, then this call will block the current
// thread until the callback is finished since this call asks to lock a mutex inside
// CoreAudio framework that is used by the data callback.
if !self.shutdown.load(Ordering::SeqCst) {
self.core_stream_data.stop_audiounits();
*self.shutdown.get_mut() = true;
}

self.destroy_internal();
});

let stm_guard = mutexed_stm.lock().unwrap();
let stm_ptr = *stm_guard as *const AudioUnitStream;
cubeb_log!("Cubeb stream ({:p}) destroyed successful.", stm_ptr);
cubeb_log!("Cubeb stream ({:p}) destroyed successful.", stream_ptr);
}
}

Expand All @@ -3417,7 +3418,18 @@ impl<'ctx> StreamOps for AudioUnitStream<'ctx> {
*self.shutdown.get_mut() = false;
*self.draining.get_mut() = false;

self.core_stream_data.start_audiounits()?;
// Execute start in serial queue to avoid racing with destroy or reinit.
let queue = self.context.serial_queue;
let mut result = Err(Error::error());
let started = &mut result;
let stream = &self;
sync_dispatch(queue, move || {
*started = stream.core_stream_data.start_audiounits();
});

if result.is_err() {
return result;
}

self.notify_state_changed(State::Started);

Expand All @@ -3430,7 +3442,12 @@ impl<'ctx> StreamOps for AudioUnitStream<'ctx> {
fn stop(&mut self) -> Result<()> {
*self.shutdown.get_mut() = true;

self.core_stream_data.stop_audiounits();
// Execute stop in serial queue to avoid racing with destroy or reinit.
let queue = self.context.serial_queue;
let stream = &self;
sync_dispatch(queue, move || {
stream.core_stream_data.stop_audiounits();
});

self.notify_state_changed(State::Stopped);

Expand Down
Loading

0 comments on commit 154efe3

Please sign in to comment.