-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rkilgore features #94
base: master
Are you sure you want to change the base?
Conversation
…bjectPropertyElementMain
…oreaudio-rs into rkilgore-features
sorry for the confusion, I'm not very good with git bc I haven't used it much in the last 5 years. There are 3 changes here. I accidentally named the 3rd one the same as the second when it should have actually had the message "add query function get_audio_device_supports_scope(devid)". I tried to run "git commit --amend" so that I could edit the message, and it wanted me to git pull first, and when I did that it got all messed up. So the last 4th and 5th changes are noops and the 3rd one should have the description of the 4th. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to do it correctly but I think this can be done without using libc.
@@ -44,7 +46,7 @@ pub fn get_default_device_id(input: bool) -> Option<AudioDeviceID> { | |||
let property_address = AudioObjectPropertyAddress { | |||
mSelector: selector, | |||
mScope: kAudioObjectPropertyScopeGlobal, | |||
mElement: kAudioObjectPropertyElementMaster, | |||
mElement: kAudioObjectPropertyElementMain, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh. Interesting. I figured the name change was due to a bindgen change. Looks like kAudioObjectPropertyElementMaster
is deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am on macOS 10, and kAudioObjectPropertyElementMain only exists on macOS 12+ (I haven't upgraded because of reports that moving off Catalina for old macbooks can brick them.)
Does this mean that the current code on master won't work on macOS 13? If we wanted to support all macOS versions would we need OS version selectors or something?
// audio_buffers.reserve_exact(count as usize); | ||
// unsafe { audio_buffers.set_len(count as usize) }; | ||
|
||
let status = unsafe { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have clippy checks on in this repo but I think it'd complain about an unsafe
block in an unsafe
block.
mElement: kAudioObjectPropertyElementWildcard, | ||
}; | ||
|
||
macro_rules! try_status_or_return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see. This is what #93 was about.
@@ -44,7 +46,7 @@ pub fn get_default_device_id(input: bool) -> Option<AudioDeviceID> { | |||
let property_address = AudioObjectPropertyAddress { | |||
mSelector: selector, | |||
mScope: kAudioObjectPropertyScopeGlobal, | |||
mElement: kAudioObjectPropertyElementMaster, | |||
mElement: kAudioObjectPropertyElementMain, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am on macOS 10, and kAudioObjectPropertyElementMain only exists on macOS 12+ (I haven't upgraded because of reports that moving off Catalina for old macbooks can brick them.)
Does this mean that the current code on master won't work on macOS 13? If we wanted to support all macOS versions would we need OS version selectors or something?
&data_size as *const _ as *mut _, | ||
) | ||
}; | ||
try_status_or_return!(status); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this macro invoked only once in this function? inline it?
// let count = data_size / mem::size_of::<sys::AudioBuffer>() as u32; | ||
// let mut audio_buffers: Vec<sys::AudioBuffer> = vec![]; | ||
// audio_buffers.reserve_exact(count as usize); | ||
// unsafe { audio_buffers.set_len(count as usize) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove if not needed?
try_status_or_return!(status); | ||
|
||
unsafe { | ||
let buffers: *mut sys::AudioBufferList = libc::malloc(data_size as usize) as *mut sys::AudioBufferList; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other parts of this repo use vec u8 as a way to allocate some bytes (see render_callback.rs let mut data = vec![0u8; data_byte_size as usize]; but there is also a TODO there saying that it is leaking len and capacity fields of the vec.
A few answers here, https://stackoverflow.com/questions/45306575/how-can-you-allocate-a-raw-mutable-pointer-in-stable-rust the first answer suggests std::alloc.
On closer inspection, is it possible to remove libc and malloc/free by using a vec u8 .as_mut_ptr()
and then you don't need to free because the vec will drop itself?
add a couple of functions I needed for my project and I replaced a deprecated constant