summaryrefslogtreecommitdiffstats
path: root/third_party/rust/cubeb-coreaudio
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/cubeb-coreaudio')
-rw-r--r--third_party/rust/cubeb-coreaudio/.cargo-checksum.json2
-rw-r--r--third_party/rust/cubeb-coreaudio/Cargo.toml5
-rw-r--r--third_party/rust/cubeb-coreaudio/src/backend/mixer.rs53
-rw-r--r--third_party/rust/cubeb-coreaudio/src/backend/mod.rs172
-rw-r--r--third_party/rust/cubeb-coreaudio/src/backend/tests/api.rs3
5 files changed, 212 insertions, 23 deletions
diff --git a/third_party/rust/cubeb-coreaudio/.cargo-checksum.json b/third_party/rust/cubeb-coreaudio/.cargo-checksum.json
index fa6f229b4c..b0c27f353e 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":"ac8f4cf5b7631b5c738d50c0cf78113bd395940b9e76593904bbaf2d02d16a70",".travis.yml":"dc07bac53f70f16c9bdf52264bdc58500ae6018c1b4c567bc7642f6b4ca3cc35","Cargo.toml":"0fb7c56c04e05dacffa5176f885cb8019ee6ab7f885479be501aba0eaac2148f","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":"90c2542fa3ff8a35fed894fae3a1aa0157117b7f0e28df14b8e6f7b1f1f43797","run_sanitizers.sh":"84e93a0da137803018f37403511e8c92760be730426bf6cea34419d93d1a7ff8","run_tests.sh":"bae82f66dd47a060b6fdcc238520084aec1079d5b1b1d66d103baa1ffaa8773d","src/backend/aggregate_device.rs":"db7d644358090b1d65ff2d53ad854369790ae4ad7dfa12b79888c0002c1b4950","src/backend/auto_release.rs":"050fdcee74cf46b9a8a85a877e166d72a853d33220f59cf734cbb6ea09daa441","src/backend/buffer_manager.rs":"e9bcf964347daa8952f98caa2746e34a31ea8908375204896593f56e4b6147ca","src/backend/device_property.rs":"a7622feaa41db1cd76fd35a85a022e44f4894e396a104a59008d5b8757d2ab4e","src/backend/mixer.rs":"ed299d3954e2a823060c870a8244673a7d4bca530830cb66b964d047a80ee3af","src/backend/mod.rs":"e52b79a17dbf7faa072ec87cc3e4201b907772104c3be777498275733b9c334e","src/backend/resampler.rs":"48bf8f56ae8d60dbabca6417b768000619abee8731ac3902164b45651ac08a4d","src/backend/tests/aggregate_device.rs":"770cf90f32b5ab2203476031c1fbc8379b713baa97bec36f7fd0d77fef1efd60","src/backend/tests/api.rs":"d72d7c0de8d12e880966948be4686bcf8c789f0ef19cb435c242fd72f2d252f9","src/backend/tests/backlog.rs":"3b189a7e036543c467cc242af0ed3332721179ee2b1c8847a6db563546f1ac52","src/backend/tests/device_change.rs":"babf50326fb38db24fe80f24f546e1b6ad04319ae8835bb372d893fc9b3038a2","src/backend/tests/device_property.rs":"73c25f579a995e8a59c9b7d391813afb75f739b5e2f825480cba04499a1d46e8","src/backend/tests/interfaces.rs":"654333cd6d6023e72ba392d98872d33bc55f8f052205a9f701aec72069449e24","src/backend/tests/manual.rs":"e550cc8bb7619bb80b68e49bf7f475c029e0f1b34323d1d30edcbe322cf4efc7","src/backend/tests/mod.rs":"8dba770023d7f9c4228f0e11915347f0e07da5fd818e3ee4478c4b197af9aa2a","src/backend/tests/parallel.rs":"a7ebd579339c40ca64c0757cc9da6baec641e670f226e1b2ec5049894700bd7a","src/backend/tests/tone.rs":"b028c67777b6453a26190b6a49785dfe28556adcbe179cb10862ce0d47ee8509","src/backend/tests/utils.rs":"80d7e4ebc06b23c63a4d2867e0c80e0bfe05449fa55edd21e785ed2c089bf7d5","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":"ac8f4cf5b7631b5c738d50c0cf78113bd395940b9e76593904bbaf2d02d16a70",".travis.yml":"dc07bac53f70f16c9bdf52264bdc58500ae6018c1b4c567bc7642f6b4ca3cc35","Cargo.toml":"a16b883e4fb41bdbbe5f68158040f181aeeffb4573ab0d493e9452f7c6f00541","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":"90c2542fa3ff8a35fed894fae3a1aa0157117b7f0e28df14b8e6f7b1f1f43797","run_sanitizers.sh":"84e93a0da137803018f37403511e8c92760be730426bf6cea34419d93d1a7ff8","run_tests.sh":"bae82f66dd47a060b6fdcc238520084aec1079d5b1b1d66d103baa1ffaa8773d","src/backend/aggregate_device.rs":"db7d644358090b1d65ff2d53ad854369790ae4ad7dfa12b79888c0002c1b4950","src/backend/auto_release.rs":"050fdcee74cf46b9a8a85a877e166d72a853d33220f59cf734cbb6ea09daa441","src/backend/buffer_manager.rs":"e9bcf964347daa8952f98caa2746e34a31ea8908375204896593f56e4b6147ca","src/backend/device_property.rs":"a7622feaa41db1cd76fd35a85a022e44f4894e396a104a59008d5b8757d2ab4e","src/backend/mixer.rs":"c4d09291598cbffb2217b551770ec590f34b6dd6b461dd99b019d5bb70f0eef3","src/backend/mod.rs":"d75e116a58d63c6a7cb281d160066f48c8c449702dad58c762ad50d9512d7bd3","src/backend/resampler.rs":"48bf8f56ae8d60dbabca6417b768000619abee8731ac3902164b45651ac08a4d","src/backend/tests/aggregate_device.rs":"770cf90f32b5ab2203476031c1fbc8379b713baa97bec36f7fd0d77fef1efd60","src/backend/tests/api.rs":"773e88b506efccf0eacbf408d34dea1fb2c5a8500e7fe8a494a97f15f1ea41fc","src/backend/tests/backlog.rs":"3b189a7e036543c467cc242af0ed3332721179ee2b1c8847a6db563546f1ac52","src/backend/tests/device_change.rs":"babf50326fb38db24fe80f24f546e1b6ad04319ae8835bb372d893fc9b3038a2","src/backend/tests/device_property.rs":"73c25f579a995e8a59c9b7d391813afb75f739b5e2f825480cba04499a1d46e8","src/backend/tests/interfaces.rs":"654333cd6d6023e72ba392d98872d33bc55f8f052205a9f701aec72069449e24","src/backend/tests/manual.rs":"e550cc8bb7619bb80b68e49bf7f475c029e0f1b34323d1d30edcbe322cf4efc7","src/backend/tests/mod.rs":"8dba770023d7f9c4228f0e11915347f0e07da5fd818e3ee4478c4b197af9aa2a","src/backend/tests/parallel.rs":"a7ebd579339c40ca64c0757cc9da6baec641e670f226e1b2ec5049894700bd7a","src/backend/tests/tone.rs":"b028c67777b6453a26190b6a49785dfe28556adcbe179cb10862ce0d47ee8509","src/backend/tests/utils.rs":"80d7e4ebc06b23c63a4d2867e0c80e0bfe05449fa55edd21e785ed2c089bf7d5","src/backend/utils.rs":"6c3ffbcd602e6cc9f56deb9ecb07b2eef2e6f074ef924178e466f380aae5c595","src/capi.rs":"21b66b70545bf04ec719928004d1d9adb45b24ced51288f5b2993d79aaf78f5f","src/lib.rs":"5e586d45cd6b3722f0a6736d9252593299269817a153eef1930a5fb9bfbb56f5","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 8a73548f57..02fb9832ac 100644
--- a/third_party/rust/cubeb-coreaudio/Cargo.toml
+++ b/third_party/rust/cubeb-coreaudio/Cargo.toml
@@ -27,7 +27,7 @@ crate-type = [
[dependencies]
atomic = "0.4"
-audio-mixer = "0.1"
+audio-mixer = "0.2"
bitflags = "2"
cubeb-backend = "0.12.0"
float-cmp = "0.6"
@@ -43,3 +43,6 @@ path = "coreaudio-sys-utils"
[dev-dependencies]
itertools = "0.11"
+
+[features]
+audio-dump = []
diff --git a/third_party/rust/cubeb-coreaudio/src/backend/mixer.rs b/third_party/rust/cubeb-coreaudio/src/backend/mixer.rs
index a4f63926b1..8b80738736 100644
--- a/third_party/rust/cubeb-coreaudio/src/backend/mixer.rs
+++ b/third_party/rust/cubeb-coreaudio/src/backend/mixer.rs
@@ -5,7 +5,7 @@ use std::os::raw::{c_int, c_void};
extern crate audio_mixer;
pub use self::audio_mixer::Channel;
-const CHANNEL_OERDER: [audio_mixer::Channel; audio_mixer::Channel::count()] = [
+const CHANNEL_ORDER: [audio_mixer::Channel; audio_mixer::Channel::count()] = [
audio_mixer::Channel::FrontLeft,
audio_mixer::Channel::FrontRight,
audio_mixer::Channel::FrontCenter,
@@ -25,6 +25,7 @@ const CHANNEL_OERDER: [audio_mixer::Channel; audio_mixer::Channel::count()] = [
audio_mixer::Channel::TopBackCenter,
audio_mixer::Channel::TopBackRight,
audio_mixer::Channel::Silence,
+ audio_mixer::Channel::Discrete,
];
pub fn get_channel_order(channel_layout: ChannelLayout) -> Vec<audio_mixer::Channel> {
@@ -33,7 +34,7 @@ pub fn get_channel_order(channel_layout: ChannelLayout) -> Vec<audio_mixer::Chan
let mut channel_index: usize = 0;
while map != 0 {
if map & 1 == 1 {
- order.push(CHANNEL_OERDER[channel_index]);
+ order.push(CHANNEL_ORDER[channel_index]);
}
map >>= 1;
channel_index += 1;
@@ -44,14 +45,14 @@ pub fn get_channel_order(channel_layout: ChannelLayout) -> Vec<audio_mixer::Chan
fn get_default_channel_order(channel_count: usize) -> Vec<audio_mixer::Channel> {
assert_ne!(channel_count, 0);
let mut channels = Vec::with_capacity(channel_count);
- for channel in CHANNEL_OERDER.iter().take(channel_count) {
+ for channel in CHANNEL_ORDER.iter().take(channel_count) {
channels.push(*channel);
}
- if channel_count > CHANNEL_OERDER.len() {
+ if channel_count > CHANNEL_ORDER.len() {
channels.extend(vec![
audio_mixer::Channel::Silence;
- channel_count - CHANNEL_OERDER.len()
+ channel_count - CHANNEL_ORDER.len()
]);
}
@@ -214,7 +215,7 @@ impl Mixer {
if output_channels.is_empty()
|| out_channel_count != output_channels.len()
|| all_silence == output_channels
- || Self::non_silent_duplicate_channel_present(&output_channels)
+ || Self::duplicate_channel_present(&output_channels)
{
cubeb_log!("Use invalid layout. Apply default layout instead");
output_channels = get_default_channel_order(out_channel_count);
@@ -261,10 +262,10 @@ impl Mixer {
)
}
- fn non_silent_duplicate_channel_present(channels: &[audio_mixer::Channel]) -> bool {
+ fn duplicate_channel_present(channels: &[audio_mixer::Channel]) -> bool {
let mut bitmap: u32 = 0;
for channel in channels {
- if channel != &Channel::Silence {
+ if channel != &Channel::Silence && channel != &Channel::Discrete {
if (bitmap & channel.bitmask()) != 0 {
return true;
}
@@ -456,14 +457,14 @@ fn test_get_channel_order() {
#[test]
fn test_get_default_channel_order() {
- for len in 1..CHANNEL_OERDER.len() + 10 {
+ for len in 1..CHANNEL_ORDER.len() + 10 {
let channels = get_default_channel_order(len);
- if len <= CHANNEL_OERDER.len() {
- assert_eq!(channels, &CHANNEL_OERDER[..len]);
+ if len <= CHANNEL_ORDER.len() {
+ assert_eq!(channels, &CHANNEL_ORDER[..len]);
} else {
- let silences = vec![audio_mixer::Channel::Silence; len - CHANNEL_OERDER.len()];
- assert_eq!(channels[..CHANNEL_OERDER.len()], CHANNEL_OERDER);
- assert_eq!(&channels[CHANNEL_OERDER.len()..], silences.as_slice());
+ let silences = vec![audio_mixer::Channel::Silence; len - CHANNEL_ORDER.len()];
+ assert_eq!(channels[..CHANNEL_ORDER.len()], CHANNEL_ORDER);
+ assert_eq!(&channels[CHANNEL_ORDER.len()..], silences.as_slice());
}
}
}
@@ -478,7 +479,7 @@ fn test_non_silent_duplicate_channels() {
Channel::Silence,
Channel::FrontRight,
];
- assert!(Mixer::non_silent_duplicate_channel_present(&duplicate));
+ assert!(Mixer::duplicate_channel_present(&duplicate));
let non_duplicate = [
Channel::FrontLeft,
@@ -488,5 +489,25 @@ fn test_non_silent_duplicate_channels() {
Channel::Silence,
Channel::Silence,
];
- assert!(!Mixer::non_silent_duplicate_channel_present(&non_duplicate));
+ assert!(!Mixer::duplicate_channel_present(&non_duplicate));
+
+ let duplicate = [
+ Channel::FrontLeft,
+ Channel::Discrete,
+ Channel::FrontRight,
+ Channel::FrontCenter,
+ Channel::Discrete,
+ Channel::FrontRight,
+ ];
+ assert!(Mixer::duplicate_channel_present(&duplicate));
+
+ let non_duplicate = [
+ Channel::FrontLeft,
+ Channel::Discrete,
+ Channel::FrontRight,
+ Channel::FrontCenter,
+ Channel::Discrete,
+ Channel::Discrete,
+ ];
+ assert!(!Mixer::duplicate_channel_present(&non_duplicate));
}
diff --git a/third_party/rust/cubeb-coreaudio/src/backend/mod.rs b/third_party/rust/cubeb-coreaudio/src/backend/mod.rs
index e6be028a2e..855c119b63 100644
--- a/third_party/rust/cubeb-coreaudio/src/backend/mod.rs
+++ b/third_party/rust/cubeb-coreaudio/src/backend/mod.rs
@@ -33,6 +33,8 @@ use self::mixer::*;
use self::resampler::*;
use self::utils::*;
use backend::ringbuf::RingBuffer;
+#[cfg(feature = "audio_dump")]
+use cubeb_backend::ffi::cubeb_audio_dump_stream_t;
use cubeb_backend::{
ffi, ChannelLayout, Context, ContextOps, DeviceCollectionRef, DeviceId, DeviceRef, DeviceType,
Error, InputProcessingParams, Ops, Result, SampleFormat, State, Stream, StreamOps,
@@ -114,6 +116,16 @@ lazy_static! {
};
}
+#[cfg(feature = "audio_dump")]
+fn dump_audio(stream: cubeb_audio_dump_stream_t, audio_samples: *mut c_void, count: u32) {
+ unsafe {
+ let rv = ffi::cubeb_audio_dump_write(stream, audio_samples, count);
+ if rv != 0 {
+ cubeb_alog!("Error dumping audio data");
+ }
+ }
+}
+
fn make_sized_audio_channel_layout(sz: usize) -> AutoRelease<AudioChannelLayout> {
assert!(sz >= mem::size_of::<AudioChannelLayout>());
assert_eq!(
@@ -194,7 +206,12 @@ impl From<CAChannelLabel> for mixer::Channel {
sys::kAudioChannelLabel_TopBackLeft => mixer::Channel::TopBackLeft,
sys::kAudioChannelLabel_TopBackCenter => mixer::Channel::TopBackCenter,
sys::kAudioChannelLabel_TopBackRight => mixer::Channel::TopBackRight,
- _ => mixer::Channel::Silence,
+ sys::kAudioChannelLabel_Unknown => mixer::Channel::Discrete,
+ sys::kAudioChannelLabel_Unused => mixer::Channel::Silence,
+ v => {
+ eprintln!("Warning: channel label value {} isn't handled", v);
+ mixer::Channel::Silence
+ }
}
}
}
@@ -551,6 +568,16 @@ extern "C" fn audiounit_input_callback(
ErrorHandle::Reinit
} else {
assert_eq!(status, NO_ERR);
+
+ #[cfg(feature = "audio_dump")]
+ {
+ dump_audio(
+ stm.core_stream_data.audio_dump_input,
+ input_buffer_list.mBuffers[0].mData,
+ input_frames * stm.core_stream_data.input_dev_desc.mChannelsPerFrame,
+ );
+ }
+
input_buffer_manager
.push_data(input_buffer_list.mBuffers[0].mData, input_frames as usize);
ErrorHandle::Return(status)
@@ -708,6 +735,14 @@ extern "C" fn audiounit_output_callback(
if stm.stopped.load(Ordering::SeqCst) {
cubeb_alog!("({:p}) output stopped.", stm as *const AudioUnitStream);
audiounit_make_silent(&buffers[0]);
+ #[cfg(feature = "audio_dump")]
+ {
+ dump_audio(
+ stm.core_stream_data.audio_dump_output,
+ buffers[0].mData,
+ output_frames * stm.core_stream_data.output_dev_desc.mChannelsPerFrame,
+ );
+ }
return NO_ERR;
}
@@ -718,12 +753,20 @@ extern "C" fn audiounit_output_callback(
cubeb_alog!("({:p}) output drained.", stm as *const AudioUnitStream);
stm.notify_state_changed(State::Drained);
let queue = stm.queue.clone();
+ audiounit_make_silent(&buffers[0]);
+ #[cfg(feature = "audio_dump")]
+ {
+ dump_audio(
+ stm.core_stream_data.audio_dump_output,
+ buffers[0].mData,
+ output_frames * stm.core_stream_data.output_dev_desc.mChannelsPerFrame,
+ );
+ }
// Use a new thread, through the queue, to avoid deadlock when calling
// AudioOutputUnitStop method from inside render callback
queue.run_async(move || {
stm.core_stream_data.stop_audiounits();
});
- audiounit_make_silent(&buffers[0]);
return NO_ERR;
}
@@ -846,12 +889,21 @@ extern "C" fn audiounit_output_callback(
stm.stopped.store(true, Ordering::SeqCst);
stm.notify_state_changed(State::Error);
let queue = stm.queue.clone();
+ audiounit_make_silent(&buffers[0]);
+
+ #[cfg(feature = "audio_dump")]
+ {
+ dump_audio(
+ stm.core_stream_data.audio_dump_output,
+ buffers[0].mData,
+ output_frames * stm.core_stream_data.output_dev_desc.mChannelsPerFrame,
+ );
+ }
// Use a new thread, through the queue, to avoid deadlock when calling
// AudioOutputUnitStop method from inside render callback
queue.run_async(move || {
stm.core_stream_data.stop_audiounits();
});
- audiounit_make_silent(&buffers[0]);
return NO_ERR;
}
@@ -898,6 +950,15 @@ extern "C" fn audiounit_output_callback(
buffers[0].mDataByteSize as usize,
);
}
+
+ #[cfg(feature = "audio_dump")]
+ {
+ dump_audio(
+ stm.core_stream_data.audio_dump_output,
+ buffers[0].mData,
+ output_frames * stm.core_stream_data.output_dev_desc.mChannelsPerFrame,
+ );
+ }
NO_ERR
}
@@ -3010,6 +3071,14 @@ struct CoreStreamData<'ctx> {
output_alive_listener: Option<device_property_listener>,
output_source_listener: Option<device_property_listener>,
input_logging: Option<InputCallbackLogger>,
+ #[cfg(feature = "audio_dump")]
+ audio_dump_session: ffi::cubeb_audio_dump_session_t,
+ #[cfg(feature = "audio_dump")]
+ audio_dump_session_running: bool,
+ #[cfg(feature = "audio_dump")]
+ audio_dump_input: ffi::cubeb_audio_dump_stream_t,
+ #[cfg(feature = "audio_dump")]
+ audio_dump_output: ffi::cubeb_audio_dump_stream_t,
}
impl<'ctx> Default for CoreStreamData<'ctx> {
@@ -3050,6 +3119,14 @@ impl<'ctx> Default for CoreStreamData<'ctx> {
output_alive_listener: None,
output_source_listener: None,
input_logging: None,
+ #[cfg(feature = "audio_dump")]
+ audio_dump_session: ptr::null_mut(),
+ #[cfg(feature = "audio_dump")]
+ audio_dump_session_running: false,
+ #[cfg(feature = "audio_dump")]
+ audio_dump_input: ptr::null_mut(),
+ #[cfg(feature = "audio_dump")]
+ audio_dump_output: ptr::null_mut(),
}
}
}
@@ -3097,6 +3174,14 @@ impl<'ctx> CoreStreamData<'ctx> {
output_alive_listener: None,
output_source_listener: None,
input_logging: None,
+ #[cfg(feature = "audio_dump")]
+ audio_dump_session: ptr::null_mut(),
+ #[cfg(feature = "audio_dump")]
+ audio_dump_session_running: false,
+ #[cfg(feature = "audio_dump")]
+ audio_dump_input: ptr::null_mut(),
+ #[cfg(feature = "audio_dump")]
+ audio_dump_output: ptr::null_mut(),
}
}
@@ -3454,6 +3539,11 @@ impl<'ctx> CoreStreamData<'ctx> {
assert!(!self.stm_ptr.is_null());
let stream = unsafe { &(*self.stm_ptr) };
+ #[cfg(feature = "audio_dump")]
+ unsafe {
+ ffi::cubeb_audio_dump_init(&mut self.audio_dump_session);
+ }
+
// Configure I/O stream
if self.has_input() {
assert!(!self.input_unit.is_null());
@@ -3543,6 +3633,26 @@ impl<'ctx> CoreStreamData<'ctx> {
e
})?;
+ #[cfg(feature = "audio_dump")]
+ {
+ let name = format!("input-{:p}.wav", self.stm_ptr);
+ let cname = CString::new(name).expect("OK");
+ let rv = unsafe {
+ ffi::cubeb_audio_dump_stream_init(
+ self.audio_dump_session,
+ &mut self.audio_dump_input,
+ *params.as_ptr(),
+ cname.as_ptr(),
+ )
+ };
+ if rv == 0 {
+ assert_ne!(self.audio_dump_input, ptr::null_mut(),);
+ cubeb_log!("Successfully inited audio dump for input");
+ } else {
+ cubeb_log!("Failed to init audio dump for input");
+ }
+ }
+
assert_eq!(self.input_dev_desc.mSampleRate, input_hw_desc.mSampleRate);
// Use latency to set buffer size
@@ -3739,6 +3849,26 @@ impl<'ctx> CoreStreamData<'ctx> {
e
})?;
+ #[cfg(feature = "audio_dump")]
+ {
+ let name = format!("output-{:p}.wav", self.stm_ptr);
+ let cname = CString::new(name).expect("OK");
+ let rv = unsafe {
+ ffi::cubeb_audio_dump_stream_init(
+ self.audio_dump_session,
+ &mut self.audio_dump_output,
+ *params.as_ptr(),
+ cname.as_ptr(),
+ )
+ };
+ if rv == 0 {
+ assert_ne!(self.audio_dump_output, ptr::null_mut(),);
+ cubeb_log!("Successfully inited audio dump for output");
+ } else {
+ cubeb_log!("Failed to init audio dump for output");
+ }
+ }
+
let device_layout = self
.get_output_channel_layout()
.map_err(|e| {
@@ -3908,6 +4038,12 @@ impl<'ctx> CoreStreamData<'ctx> {
self.input_logging = Some(InputCallbackLogger::new());
}
+ #[cfg(feature = "audio_dump")]
+ {
+ unsafe { ffi::cubeb_audio_dump_start(self.audio_dump_session) };
+ self.audio_dump_session_running = true;
+ }
+
if !self.input_unit.is_null() {
let r = audio_unit_initialize(self.input_unit);
if r != NO_ERR {
@@ -4081,6 +4217,36 @@ impl<'ctx> CoreStreamData<'ctx> {
// Return the VPIO unit if present.
self.voiceprocessing_unit_handle = None;
+ #[cfg(feature = "audio_dump")]
+ {
+ if !self.audio_dump_session.is_null() {
+ unsafe {
+ ffi::cubeb_audio_dump_stop(self.audio_dump_session);
+ if !self.audio_dump_input.is_null() {
+ let rv = ffi::cubeb_audio_dump_stream_shutdown(
+ self.audio_dump_session,
+ self.audio_dump_input,
+ );
+ if rv != 0 {
+ cubeb_log!("Failed to shutdown audio dump for input");
+ }
+ }
+ if !self.audio_dump_output.is_null() {
+ let rv = ffi::cubeb_audio_dump_stream_shutdown(
+ self.audio_dump_session,
+ self.audio_dump_output,
+ );
+ if rv != 0 {
+ cubeb_log!("Failed to shutdown audio dump for output");
+ }
+ }
+ ffi::cubeb_audio_dump_shutdown(self.audio_dump_session);
+ self.audio_dump_session = ptr::null_mut();
+ self.audio_dump_session_running = false;
+ }
+ }
+ }
+
self.resampler.destroy();
self.mixer = None;
self.aggregate_device = None;
diff --git a/third_party/rust/cubeb-coreaudio/src/backend/tests/api.rs b/third_party/rust/cubeb-coreaudio/src/backend/tests/api.rs
index 5ce2374a3e..ea08a5ef45 100644
--- a/third_party/rust/cubeb-coreaudio/src/backend/tests/api.rs
+++ b/third_party/rust/cubeb-coreaudio/src/backend/tests/api.rs
@@ -376,7 +376,6 @@ fn test_get_default_device_id_with_inout_type() {
#[test]
fn test_convert_channel_layout() {
let pairs = [
- (vec![kAudioObjectUnknown], vec![mixer::Channel::Silence]),
(
vec![kAudioChannelLabel_Mono],
vec![mixer::Channel::FrontCenter],
@@ -398,7 +397,7 @@ fn test_convert_channel_layout() {
vec![
mixer::Channel::FrontLeft,
mixer::Channel::FrontRight,
- mixer::Channel::Silence,
+ mixer::Channel::Discrete,
],
),
(