Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Update coreaudio-rs #943

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,13 @@ libc = "0.2"
jack = { version = "0.13.0", optional = true }

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
core-foundation-sys = "0.8.2" # For linking to CoreFoundation.framework and handling device name `CFString`s.
mach2 = "0.4" # For access to mach_timebase type.

[target.'cfg(target_os = "macos")'.dependencies]
coreaudio-rs = { version = "0.11", default-features = false, features = ["audio_unit", "core_audio"] }
coreaudio-rs = { version = "0.12", default-features = false, features = ["core_audio", "audio_toolbox"] }

[target.'cfg(target_os = "ios")'.dependencies]
coreaudio-rs = { version = "0.11", default-features = false, features = ["audio_unit", "core_audio", "audio_toolbox"] }
coreaudio-rs = { version = "0.12", default-features = false, features = ["core_audio", "audio_toolbox"] }

[target.'cfg(target_os = "emscripten")'.dependencies]
wasm-bindgen = { version = "0.2.89" }
Expand Down Expand Up @@ -93,3 +92,6 @@ name = "record_wav"

[[example]]
name = "synth_tones"

[patch.crates-io]
coreaudio-rs = { path = "../coreaudio" }
1 change: 0 additions & 1 deletion src/host/coreaudio/ios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//! buffer size.
//!

extern crate core_foundation_sys;
extern crate coreaudio;

use std::cell::RefCell;
Expand Down
43 changes: 22 additions & 21 deletions src/host/coreaudio/macos/enumerate.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#![allow(deprecated)]
extern crate coreaudio;

use self::coreaudio::sys::{
kAudioHardwareNoError, kAudioHardwarePropertyDefaultInputDevice,
kAudioHardwarePropertyDefaultOutputDevice, kAudioHardwarePropertyDevices,
kAudioObjectPropertyElementMaster, kAudioObjectPropertyScopeGlobal, kAudioObjectSystemObject,
AudioDeviceID, AudioObjectGetPropertyData, AudioObjectGetPropertyDataSize,
AudioDeviceID, AudioObjectGetPropertyData, AudioObjectGetPropertyDataSize, AudioObjectID,
AudioObjectPropertyAddress, OSStatus,
};
use super::Device;
use crate::{BackendSpecificError, DevicesError, SupportedStreamConfigRange};
use std::mem;
use std::ptr::null;
use std::ptr::{null, NonNull};
use std::vec::IntoIter as VecIntoIter;

unsafe fn audio_devices() -> Result<Vec<AudioDeviceID>, OSStatus> {
Expand All @@ -30,11 +31,11 @@ unsafe fn audio_devices() -> Result<Vec<AudioDeviceID>, OSStatus> {

let data_size = 0u32;
let status = AudioObjectGetPropertyDataSize(
kAudioObjectSystemObject,
&property_address as *const _,
kAudioObjectSystemObject as AudioObjectID,
NonNull::from(&property_address),
0,
null(),
&data_size as *const _ as *mut _,
NonNull::from(&data_size),
);
try_status_or_return!(status);

Expand All @@ -43,12 +44,12 @@ unsafe fn audio_devices() -> Result<Vec<AudioDeviceID>, OSStatus> {
audio_devices.reserve_exact(device_count as usize);

let status = AudioObjectGetPropertyData(
kAudioObjectSystemObject,
&property_address as *const _,
kAudioObjectSystemObject as AudioObjectID,
NonNull::from(&property_address),
0,
null(),
&data_size as *const _ as *mut _,
audio_devices.as_mut_ptr() as *mut _,
NonNull::from(&data_size),
NonNull::new(audio_devices.as_mut_ptr()).unwrap().cast(),
);
try_status_or_return!(status);

Expand Down Expand Up @@ -95,16 +96,16 @@ pub fn default_input_device() -> Option<Device> {
mElement: kAudioObjectPropertyElementMaster,
};

let audio_device_id: AudioDeviceID = 0;
let data_size = mem::size_of::<AudioDeviceID>();
let mut audio_device_id: AudioDeviceID = 0;
let data_size = mem::size_of::<AudioDeviceID>() as u32;
let status = unsafe {
AudioObjectGetPropertyData(
kAudioObjectSystemObject,
&property_address as *const _,
kAudioObjectSystemObject as AudioObjectID,
NonNull::from(&property_address),
0,
null(),
&data_size as *const _ as *mut _,
&audio_device_id as *const _ as *mut _,
NonNull::from(&data_size),
NonNull::from(&mut audio_device_id).cast(),
)
};
if status != kAudioHardwareNoError as i32 {
Expand All @@ -125,16 +126,16 @@ pub fn default_output_device() -> Option<Device> {
mElement: kAudioObjectPropertyElementMaster,
};

let audio_device_id: AudioDeviceID = 0;
let data_size = mem::size_of::<AudioDeviceID>();
let mut audio_device_id: AudioDeviceID = 0;
let data_size = mem::size_of::<AudioDeviceID>() as u32;
let status = unsafe {
AudioObjectGetPropertyData(
kAudioObjectSystemObject,
&property_address as *const _,
kAudioObjectSystemObject as AudioObjectID,
NonNull::from(&property_address),
0,
null(),
&data_size as *const _ as *mut _,
&audio_device_id as *const _ as *mut _,
NonNull::from(&data_size),
NonNull::from(&mut audio_device_id).cast(),
)
};
if status != kAudioHardwareNoError as i32 {
Expand Down
Loading
Loading