diff --git a/.cargo/config.toml.in b/.cargo/config.toml.in index 64ba1278f803..00ad675c8dc4 100644 --- a/.cargo/config.toml.in +++ b/.cargo/config.toml.in @@ -70,9 +70,9 @@ git = "https://github.com/mozilla/audioipc" rev = "3495905752a4263827f5d43737f9ca3ed0243ce0" replace-with = "vendored-sources" -[source."git+https://github.com/mozilla/cubeb-coreaudio-rs?rev=6d84f4638551dfa01b25a3a074729d64cdadd985"] +[source."git+https://github.com/mozilla/cubeb-coreaudio-rs?rev=8bce3b333a920999055397a397e59c2b81a93b9a"] git = "https://github.com/mozilla/cubeb-coreaudio-rs" -rev = "6d84f4638551dfa01b25a3a074729d64cdadd985" +rev = "8bce3b333a920999055397a397e59c2b81a93b9a" replace-with = "vendored-sources" [source."git+https://github.com/mozilla/cubeb-pulse-rs?rev=8678dcab1c287de79c4c184ccc2e065bc62b70e2"] diff --git a/Cargo.lock b/Cargo.lock index 82cfe75b0210..8cb706a43f48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -934,7 +934,7 @@ dependencies = [ [[package]] name = "coreaudio-sys-utils" version = "0.1.0" -source = "git+https://github.com/mozilla/cubeb-coreaudio-rs?rev=6d84f4638551dfa01b25a3a074729d64cdadd985#6d84f4638551dfa01b25a3a074729d64cdadd985" +source = "git+https://github.com/mozilla/cubeb-coreaudio-rs?rev=8bce3b333a920999055397a397e59c2b81a93b9a#8bce3b333a920999055397a397e59c2b81a93b9a" dependencies = [ "core-foundation-sys", "coreaudio-sys", @@ -1182,7 +1182,7 @@ dependencies = [ [[package]] name = "cubeb-coreaudio" version = "0.1.0" -source = "git+https://github.com/mozilla/cubeb-coreaudio-rs?rev=6d84f4638551dfa01b25a3a074729d64cdadd985#6d84f4638551dfa01b25a3a074729d64cdadd985" +source = "git+https://github.com/mozilla/cubeb-coreaudio-rs?rev=8bce3b333a920999055397a397e59c2b81a93b9a#8bce3b333a920999055397a397e59c2b81a93b9a" dependencies = [ "atomic", "audio-mixer", @@ -1190,7 +1190,6 @@ dependencies = [ "coreaudio-sys-utils", "cubeb-backend", "float-cmp", - "lazy_static", "libc", "mach", "ringbuf", diff --git a/third_party/rust/cubeb-coreaudio/.cargo-checksum.json b/third_party/rust/cubeb-coreaudio/.cargo-checksum.json index 543b9af7769b..530b0c1fd410 100644 --- a/third_party/rust/cubeb-coreaudio/.cargo-checksum.json +++ b/third_party/rust/cubeb-coreaudio/.cargo-checksum.json @@ -1 +1 @@ -{"files":{".circleci/config.yml":"7f3dc865105ca8f33965a7958b1fe2e627ae2d5a703f3b2a4ab6e2e796018597",".editorconfig":"4e53b182bcc78b83d7e1b5c03efa14d22d4955c4ed2514d1ba4e99c1eb1a50ba",".githooks/pre-push":"8b8b26544cd56f54c0c33812551f786bb25cb08c86dbfeb6bf3daad881c826a1",".github/workflows/test.yml":"cf6ebe6d41b022897360866b526d19ba8843aa82ae99a1d28393985576b6a782",".travis.yml":"dc07bac53f70f16c9bdf52264bdc58500ae6018c1b4c567bc7642f6b4ca3cc35","Cargo.toml":"2698cf87581d8d551ed3ac5875564720ed23d7b788e8d145d4281c8026203cd2","LICENSE":"6e6f56aff5bbf3cbc60747e152fb1a719bd0716aaf6d711c554f57d92e96297c","README.md":"0007782a05a5330f739ad789c19c82562c82e32386b0447000fc72c0d48405bc","build-audiounit-rust-in-cubeb.sh":"d228a05985dcd02ec1ecac66a2b64dae5a530804a25a7054ccc95905aedfb7ef","install_git_hook.sh":"d38c8e51e636f6b90b489621ac34ccd1d1b1f40dccce3d178ed1da1c5068f16d","install_rustfmt_clippy.sh":"4ae90d8dcb9757cb3ae4ae142ef80e5377c0dde61c63f4a3c32418646e80ca7b","run_device_tests.sh":"1403232694fabeae004179be8399d1fe2a1b100d60cd90db37d8860eddbaf2ae","run_sanitizers.sh":"84e93a0da137803018f37403511e8c92760be730426bf6cea34419d93d1a7ff8","run_tests.sh":"bae82f66dd47a060b6fdcc238520084aec1079d5b1b1d66d103baa1ffaa8773d","src/backend/aggregate_device.rs":"a910b9d596b1971cb4fee34f5030809ade584f41eb5cbad73a09abe7352ebd15","src/backend/auto_release.rs":"050fdcee74cf46b9a8a85a877e166d72a853d33220f59cf734cbb6ea09daa441","src/backend/buffer_manager.rs":"e9bcf964347daa8952f98caa2746e34a31ea8908375204896593f56e4b6147ca","src/backend/device_property.rs":"30ceeceee4fc1f6f872c6c61765e41d582ccd91d2d1ac3ca9b1e5ac18dd11a71","src/backend/mixer.rs":"c4d09291598cbffb2217b551770ec590f34b6dd6b461dd99b019d5bb70f0eef3","src/backend/mod.rs":"d46f66d64fc07fb8dfbb1ab9be8bdc37f0bfd3ed13ea131c0dfd18b7f4679946","src/backend/resampler.rs":"48bf8f56ae8d60dbabca6417b768000619abee8731ac3902164b45651ac08a4d","src/backend/tests/aggregate_device.rs":"afbdf1da1fcaddcad2986bd3146bf93ca75c24b3362f5f23a09517a926290ca2","src/backend/tests/api.rs":"3b0936810b3afa84cb80428c471e1097701fd790460d00c0a5715fd8026d0a4d","src/backend/tests/backlog.rs":"3b189a7e036543c467cc242af0ed3332721179ee2b1c8847a6db563546f1ac52","src/backend/tests/device_change.rs":"babf50326fb38db24fe80f24f546e1b6ad04319ae8835bb372d893fc9b3038a2","src/backend/tests/device_property.rs":"4ef3ab625809fe95e944c19cc5dc1cc79f473520a4314d123b1f80c6b7e11411","src/backend/tests/interfaces.rs":"a96d1432afd381bf74dcbe73e892dfc4ddc68721a956606c94fd4128c6589adc","src/backend/tests/manual.rs":"f72625c05110534775c4608ccc45472ea108286657ffc1f029844a13d0b883bf","src/backend/tests/mod.rs":"8dba770023d7f9c4228f0e11915347f0e07da5fd818e3ee4478c4b197af9aa2a","src/backend/tests/parallel.rs":"a7ebd579339c40ca64c0757cc9da6baec641e670f226e1b2ec5049894700bd7a","src/backend/tests/tone.rs":"b028c67777b6453a26190b6a49785dfe28556adcbe179cb10862ce0d47ee8509","src/backend/tests/utils.rs":"3e435569798b883db8342137098832b88837a387008852005363f74e5e6ff18e","src/backend/utils.rs":"6c3ffbcd602e6cc9f56deb9ecb07b2eef2e6f074ef924178e466f380aae5c595","src/capi.rs":"21b66b70545bf04ec719928004d1d9adb45b24ced51288f5b2993d79aaf78f5f","src/lib.rs":"5e586d45cd6b3722f0a6736d9252593299269817a153eef1930a5fb9bfbb56f5","todo.md":"efc1f012eb9a331a040cad4ac03aa79307f25885f71b6fb38f3ad7af8d7d515c"},"package":null} \ No newline at end of file +{"files":{".circleci/config.yml":"7f3dc865105ca8f33965a7958b1fe2e627ae2d5a703f3b2a4ab6e2e796018597",".editorconfig":"4e53b182bcc78b83d7e1b5c03efa14d22d4955c4ed2514d1ba4e99c1eb1a50ba",".githooks/pre-push":"8b8b26544cd56f54c0c33812551f786bb25cb08c86dbfeb6bf3daad881c826a1",".github/workflows/test.yml":"cf6ebe6d41b022897360866b526d19ba8843aa82ae99a1d28393985576b6a782",".travis.yml":"dc07bac53f70f16c9bdf52264bdc58500ae6018c1b4c567bc7642f6b4ca3cc35","Cargo.toml":"bd7f9d71d7b83bb7b5516058b4af37c81eede73f11975b56cc6885b721c407a7","LICENSE":"6e6f56aff5bbf3cbc60747e152fb1a719bd0716aaf6d711c554f57d92e96297c","README.md":"0007782a05a5330f739ad789c19c82562c82e32386b0447000fc72c0d48405bc","build-audiounit-rust-in-cubeb.sh":"d228a05985dcd02ec1ecac66a2b64dae5a530804a25a7054ccc95905aedfb7ef","install_git_hook.sh":"d38c8e51e636f6b90b489621ac34ccd1d1b1f40dccce3d178ed1da1c5068f16d","install_rustfmt_clippy.sh":"4ae90d8dcb9757cb3ae4ae142ef80e5377c0dde61c63f4a3c32418646e80ca7b","run_device_tests.sh":"1403232694fabeae004179be8399d1fe2a1b100d60cd90db37d8860eddbaf2ae","run_sanitizers.sh":"84e93a0da137803018f37403511e8c92760be730426bf6cea34419d93d1a7ff8","run_tests.sh":"bae82f66dd47a060b6fdcc238520084aec1079d5b1b1d66d103baa1ffaa8773d","src/backend/aggregate_device.rs":"a910b9d596b1971cb4fee34f5030809ade584f41eb5cbad73a09abe7352ebd15","src/backend/auto_release.rs":"050fdcee74cf46b9a8a85a877e166d72a853d33220f59cf734cbb6ea09daa441","src/backend/buffer_manager.rs":"e9bcf964347daa8952f98caa2746e34a31ea8908375204896593f56e4b6147ca","src/backend/device_property.rs":"30ceeceee4fc1f6f872c6c61765e41d582ccd91d2d1ac3ca9b1e5ac18dd11a71","src/backend/mixer.rs":"c4d09291598cbffb2217b551770ec590f34b6dd6b461dd99b019d5bb70f0eef3","src/backend/mod.rs":"3625c021440b011cfbc2e506ed35d0be216189346937df9d228d3199d858556e","src/backend/resampler.rs":"48bf8f56ae8d60dbabca6417b768000619abee8731ac3902164b45651ac08a4d","src/backend/tests/aggregate_device.rs":"afbdf1da1fcaddcad2986bd3146bf93ca75c24b3362f5f23a09517a926290ca2","src/backend/tests/api.rs":"3b0936810b3afa84cb80428c471e1097701fd790460d00c0a5715fd8026d0a4d","src/backend/tests/backlog.rs":"3b189a7e036543c467cc242af0ed3332721179ee2b1c8847a6db563546f1ac52","src/backend/tests/device_change.rs":"babf50326fb38db24fe80f24f546e1b6ad04319ae8835bb372d893fc9b3038a2","src/backend/tests/device_property.rs":"4ef3ab625809fe95e944c19cc5dc1cc79f473520a4314d123b1f80c6b7e11411","src/backend/tests/interfaces.rs":"a96d1432afd381bf74dcbe73e892dfc4ddc68721a956606c94fd4128c6589adc","src/backend/tests/manual.rs":"f72625c05110534775c4608ccc45472ea108286657ffc1f029844a13d0b883bf","src/backend/tests/mod.rs":"8dba770023d7f9c4228f0e11915347f0e07da5fd818e3ee4478c4b197af9aa2a","src/backend/tests/parallel.rs":"a7ebd579339c40ca64c0757cc9da6baec641e670f226e1b2ec5049894700bd7a","src/backend/tests/tone.rs":"b028c67777b6453a26190b6a49785dfe28556adcbe179cb10862ce0d47ee8509","src/backend/tests/utils.rs":"3e435569798b883db8342137098832b88837a387008852005363f74e5e6ff18e","src/backend/utils.rs":"6c3ffbcd602e6cc9f56deb9ecb07b2eef2e6f074ef924178e466f380aae5c595","src/capi.rs":"21b66b70545bf04ec719928004d1d9adb45b24ced51288f5b2993d79aaf78f5f","src/lib.rs":"be88c967e470bf6c120f3e42f7155fe89a4718f56a35524ea4c17181856757d5","todo.md":"efc1f012eb9a331a040cad4ac03aa79307f25885f71b6fb38f3ad7af8d7d515c"},"package":null} \ No newline at end of file diff --git a/third_party/rust/cubeb-coreaudio/Cargo.toml b/third_party/rust/cubeb-coreaudio/Cargo.toml index 23276a307056..e55840520b30 100644 --- a/third_party/rust/cubeb-coreaudio/Cargo.toml +++ b/third_party/rust/cubeb-coreaudio/Cargo.toml @@ -31,7 +31,6 @@ audio-mixer = "0.2" bitflags = "2" cubeb-backend = "0.13" float-cmp = "0.6" -lazy_static = "1.2" libc = "0.2" mach = "0.3" ringbuf = "0.2.6" diff --git a/third_party/rust/cubeb-coreaudio/src/backend/mod.rs b/third_party/rust/cubeb-coreaudio/src/backend/mod.rs index 3917171bc64e..82e4bdb66388 100644 --- a/third_party/rust/cubeb-coreaudio/src/backend/mod.rs +++ b/third_party/rust/cubeb-coreaudio/src/backend/mod.rs @@ -4,7 +4,6 @@ // accompanying file LICENSE for details. #![allow(unused_assignments)] #![allow(unused_must_use)] - extern crate coreaudio_sys_utils; extern crate libc; extern crate ringbuf; @@ -106,16 +105,6 @@ bitflags! { } } -lazy_static! { - static ref HOST_TIME_TO_NS_RATIO: (u32, u32) = { - let mut timebase_info = mach_timebase_info { numer: 0, denom: 0 }; - unsafe { - mach_timebase_info(&mut timebase_info); - } - (timebase_info.numer, timebase_info.denom) - }; -} - #[cfg(feature = "audio-dump")] fn dump_audio(stream: cubeb_audio_dump_stream_t, audio_samples: *mut c_void, count: u32) { unsafe { @@ -682,10 +671,10 @@ extern "C" fn audiounit_input_callback( } } -fn host_time_to_ns(host_time: u64) -> u64 { +fn host_time_to_ns(ctx: &AudioUnitContext, host_time: u64) -> u64 { let mut rv: f64 = host_time as f64; - rv *= HOST_TIME_TO_NS_RATIO.0 as f64; - rv /= HOST_TIME_TO_NS_RATIO.1 as f64; + rv *= ctx.host_time_to_ns_ratio.0 as f64; + rv /= ctx.host_time_to_ns_ratio.1 as f64; rv as u64 } @@ -697,7 +686,7 @@ fn compute_output_latency(stm: &AudioUnitStream, audio_output_time: u64, now: u6 // The total output latency is the timestamp difference + the stream latency + the hardware // latency. let total_output_latency_ns = - fixed_latency_ns + host_time_to_ns(audio_output_time.saturating_sub(now)); + fixed_latency_ns + host_time_to_ns(stm.context, audio_output_time.saturating_sub(now)); (total_output_latency_ns * output_hw_rate / NS2S) as u32 } @@ -710,7 +699,7 @@ fn compute_input_latency(stm: &AudioUnitStream, audio_input_time: u64, now: u64) // The total input latency is the timestamp difference + the stream latency + // the hardware latency. let total_input_latency_ns = - host_time_to_ns(now.saturating_sub(audio_input_time)) + fixed_latency_ns; + host_time_to_ns(stm.context, now.saturating_sub(audio_input_time)) + fixed_latency_ns; (total_input_latency_ns * input_hw_rate / NS2S) as u32 } @@ -729,6 +718,14 @@ extern "C" fn audiounit_output_callback( assert!(!user_ptr.is_null()); let stm = unsafe { &mut *(user_ptr as *mut AudioUnitStream) }; + if output_frames == 0 { + cubeb_alog!( + "({:p}) output callback empty.", + stm as *const AudioUnitStream + ); + return NO_ERR; + } + let out_buffer_list_ref = unsafe { &mut (*out_buffer_list) }; assert_eq!(out_buffer_list_ref.mNumberBuffers, 1); let buffers = unsafe { @@ -879,6 +876,7 @@ extern "C" fn audiounit_output_callback( output_frames ); + assert_ne!(output_frames, 0); let outframes = stm.core_stream_data.resampler.fill( input_buffer, if input_buffer.is_null() { @@ -2474,6 +2472,7 @@ pub struct AudioUnitContext { serial_queue: Queue, latency_controller: Mutex, devices: Mutex, + host_time_to_ns_ratio: (u32, u32), // Storage for a context-global vpio unit. Duplex streams that need one will take this // and return it when done. shared_voice_processing_unit: SharedVoiceProcessingUnitManager, @@ -2488,11 +2487,19 @@ impl AudioUnitContext { format!("{}.context.shared_vpio", DISPATCH_QUEUE_LABEL).as_str(), &serial_queue, ); + let host_time_to_ns_ratio = { + let mut timebase_info = mach_timebase_info { numer: 0, denom: 0 }; + unsafe { + mach_timebase_info(&mut timebase_info); + } + (timebase_info.numer, timebase_info.denom) + }; Self { _ops: &OPS as *const _, serial_queue, latency_controller: Mutex::new(LatencyController::default()), devices: Mutex::new(SharedDevices::default()), + host_time_to_ns_ratio, shared_voice_processing_unit: SharedVoiceProcessingUnitManager::new(shared_vp_queue), } } @@ -4922,7 +4929,7 @@ impl<'ctx> StreamOps for AudioUnitStream<'ctx> { let now = unsafe { mach_absolute_time() }; let diff = now - timestamp; let interpolated_frames = cmp::min( - host_time_to_ns(diff) + host_time_to_ns(self.context, diff) * self.core_stream_data.output_stream_params.rate() as u64 / NS2S, buffer_size, diff --git a/third_party/rust/cubeb-coreaudio/src/lib.rs b/third_party/rust/cubeb-coreaudio/src/lib.rs index 87efbf54d6e3..bf1ae96f0ca6 100644 --- a/third_party/rust/cubeb-coreaudio/src/lib.rs +++ b/third_party/rust/cubeb-coreaudio/src/lib.rs @@ -10,8 +10,6 @@ extern crate bitflags; extern crate cubeb_backend; #[macro_use] extern crate float_cmp; -#[macro_use] -extern crate lazy_static; extern crate mach; mod backend; diff --git a/toolkit/library/rust/shared/Cargo.toml b/toolkit/library/rust/shared/Cargo.toml index 5023a4e34d93..dcad9ee731eb 100644 --- a/toolkit/library/rust/shared/Cargo.toml +++ b/toolkit/library/rust/shared/Cargo.toml @@ -22,7 +22,7 @@ static_prefs = { path = "../../../../modules/libpref/init/static_prefs" } profiler_helper = { path = "../../../../tools/profiler/rust-helper", optional = true } mozurl = { path = "../../../../netwerk/base/mozurl" } webrender_bindings = { path = "../../../../gfx/webrender_bindings" } -cubeb-coreaudio = { git = "https://github.com/mozilla/cubeb-coreaudio-rs", rev = "6d84f4638551dfa01b25a3a074729d64cdadd985", optional = true } +cubeb-coreaudio = { git = "https://github.com/mozilla/cubeb-coreaudio-rs", rev = "8bce3b333a920999055397a397e59c2b81a93b9a", optional = true } cubeb-pulse = { git = "https://github.com/mozilla/cubeb-pulse-rs", rev="8678dcab1c287de79c4c184ccc2e065bc62b70e2", optional = true, features=["pulse-dlopen"] } cubeb-sys = { version = "0.13", optional = true, features=["gecko-in-tree"] } audioipc2-client = { git = "https://github.com/mozilla/audioipc", rev = "3495905752a4263827f5d43737f9ca3ed0243ce0", optional = true }