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. |
simlay
left a comment
There was a problem hiding this comment.
I'm not sure how to do it correctly but I think this can be done without using libc.
| mSelector: selector, | ||
| mScope: kAudioObjectPropertyScopeGlobal, | ||
| mElement: kAudioObjectPropertyElementMaster, | ||
| mElement: kAudioObjectPropertyElementMain, |
There was a problem hiding this comment.
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.
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.
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 { |
| mSelector: selector, | ||
| mScope: kAudioObjectPropertyScopeGlobal, | ||
| mElement: kAudioObjectPropertyElementMaster, | ||
| mElement: kAudioObjectPropertyElementMain, |
There was a problem hiding this comment.
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.
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.
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.
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