-
Notifications
You must be signed in to change notification settings - Fork 442
feat: stable Device::id() #1014
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
Open
xephyris
wants to merge
25
commits into
RustAudio:master
Choose a base branch
from
xephyris:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+279
−43
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
8cc6f25
feat: add device_id support for macOS to DeviceTrait
xephyris 9161bbb
fix: fix import statements for other APIs
xephyris 845baac
wip: use DeviceId enum instead to work around conflicting device_id i…
xephyris bd9b071
feat: transition to using DeviceId for enum for better cross compatib…
xephyris 60c3c26
docs: add description for DeviceId
xephyris 2a93a70
feat: implemented device id for windows wasapi
xephyris fb1efd0
docs: update description
xephyris 626b823
fix: reformat existing code and fix android build error
xephyris c9d6b05
feat: add ALSA support to device id() function
xephyris 6f8587f
fix: resolve merge conflicts
xephyris 24ef5ac
feat: add support for jack and aaudio (untested). fix naming structur…
xephyris 8b5b8d0
docs: update changelog
xephyris 068e171
fix: fix function names causing compile errors
xephyris f9301b8
fix: fix aaudio DeviceId type
xephyris 2972b52
feat: implement macos DeviceId to use kAudioDevicePropertyDeviceUID …
xephyris 99fc8b7
fmt: reformat with rustfmt
xephyris 43bc3e0
docs: update changelog
xephyris 6e93a1b
feat: add asio support and reformat macos id function
xephyris 59f4a9f
fmt: reformat code
xephyris b811266
feat: return default for ios, emscripten, and webaudio
xephyris eefc6ef
fix: Merge branch 'master' into master
xephyris f40bb9d
feat: add in rest of audio APIs to from_str()
xephyris 492a98e
fix: Merge branch 'master' into master
xephyris 30645a5
fix: change catch-all to todo!
xephyris 44ec96b
fix: resolve parse error on null and deviceid implementations
xephyris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,10 +32,11 @@ use super::{asbd_from_config, frames_to_duration, host_time_to_stream_instant}; | |
use crate::traits::{DeviceTrait, HostTrait, StreamTrait}; | ||
|
||
use crate::{ | ||
BackendSpecificError, BufferSize, BuildStreamError, Data, DefaultStreamConfigError, | ||
DeviceNameError, DevicesError, InputCallbackInfo, OutputCallbackInfo, PauseStreamError, | ||
PlayStreamError, SampleFormat, SampleRate, StreamConfig, StreamError, SupportedBufferSize, | ||
SupportedStreamConfig, SupportedStreamConfigRange, SupportedStreamConfigsError, | ||
BackendSpecificError, BufferSize, BuildStreamError, Data, DefaultStreamConfigError, DeviceId, | ||
DeviceIdError, DeviceNameError, DevicesError, InputCallbackInfo, OutputCallbackInfo, | ||
PauseStreamError, PlayStreamError, SampleFormat, SampleRate, StreamConfig, StreamError, | ||
SupportedBufferSize, SupportedStreamConfig, SupportedStreamConfigRange, | ||
SupportedStreamConfigsError, | ||
}; | ||
|
||
use self::enumerate::{ | ||
|
@@ -88,6 +89,10 @@ impl Device { | |
Ok("Default Device".to_owned()) | ||
} | ||
|
||
fn id(&self) -> Result<DeviceId, DeviceIdError> { | ||
Ok(DeviceId::IOS("default".to_string())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "default" differs from "Default Device" in |
||
} | ||
|
||
#[inline] | ||
fn supported_input_configs( | ||
&self, | ||
|
@@ -154,6 +159,11 @@ impl DeviceTrait for Device { | |
Device::name(self) | ||
} | ||
|
||
#[inline] | ||
fn id(&self) -> Result<DeviceId, DeviceIdError> { | ||
Device::id(self) | ||
} | ||
|
||
#[inline] | ||
fn supported_input_configs( | ||
&self, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,16 +6,18 @@ use crate::host::coreaudio::macos::StreamInner; | |
use crate::traits::DeviceTrait; | ||
use crate::{ | ||
BackendSpecificError, BufferSize, BuildStreamError, ChannelCount, Data, | ||
DefaultStreamConfigError, DeviceNameError, InputCallbackInfo, OutputCallbackInfo, SampleFormat, | ||
SampleRate, StreamConfig, StreamError, SupportedBufferSize, SupportedStreamConfig, | ||
SupportedStreamConfigRange, SupportedStreamConfigsError, | ||
DefaultStreamConfigError, DeviceId, DeviceIdError, DeviceNameError, InputCallbackInfo, | ||
OutputCallbackInfo, SampleFormat, SampleRate, StreamConfig, StreamError, SupportedBufferSize, | ||
SupportedStreamConfig, SupportedStreamConfigRange, SupportedStreamConfigsError, | ||
}; | ||
use coreaudio::audio_unit::render_callback::{self, data}; | ||
use coreaudio::audio_unit::{AudioUnit, Element, Scope}; | ||
use objc2_audio_toolbox::{ | ||
kAudioOutputUnitProperty_CurrentDevice, kAudioOutputUnitProperty_EnableIO, | ||
kAudioUnitProperty_StreamFormat, | ||
}; | ||
use objc2_core_audio::kAudioDevicePropertyDeviceUID; | ||
use objc2_core_audio::kAudioObjectPropertyElementMain; | ||
use objc2_core_audio::{ | ||
kAudioDevicePropertyAvailableNominalSampleRates, kAudioDevicePropertyBufferFrameSize, | ||
kAudioDevicePropertyBufferFrameSizeRange, kAudioDevicePropertyDeviceIsAlive, | ||
|
@@ -29,6 +31,8 @@ use objc2_core_audio::{ | |
use objc2_core_audio_types::{ | ||
AudioBuffer, AudioBufferList, AudioStreamBasicDescription, AudioValueRange, | ||
}; | ||
use objc2_core_foundation::CFString; | ||
use objc2_core_foundation::Type; | ||
|
||
pub use super::enumerate::{ | ||
default_input_device, default_output_device, SupportedInputConfigs, SupportedOutputConfigs, | ||
|
@@ -44,6 +48,9 @@ use std::time::{Duration, Instant}; | |
|
||
use super::property_listener::AudioObjectPropertyListener; | ||
use coreaudio::audio_unit::macos_helpers::get_device_name; | ||
|
||
type CFStringRef = *mut std::os::raw::c_void; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we remove this in favor of plain fn id(&self) -> Result<DeviceId, DeviceIdError> {
let property_address = AudioObjectPropertyAddress {
mSelector: kAudioDevicePropertyDeviceUID,
mScope: kAudioObjectPropertyScopeGlobal,
mElement: kAudioObjectPropertyElementMain,
};
// CFString is retained by the audio object, use wrap_under_get_rule
let mut uid: *const CFString = std::ptr::null();
let data_size = size_of::<*const CFString>() as u32;
// SAFETY: AudioObjectGetPropertyData is documented to write a CFString pointer
// for kAudioDevicePropertyDeviceUID. We check the status code before use.
let status = unsafe {
AudioObjectGetPropertyData(
self.audio_device_id,
NonNull::from(&property_address),
0,
null(),
NonNull::from(&data_size),
NonNull::from(&mut uid).cast(),
)
};
check_os_status(status)?;
if uid.is_null() {
return Err(DeviceIdError::BackendSpecific {
err: BackendSpecificError {
description: "Device UID is null".to_string(),
},
});
}
// SAFETY: We verified uid is non-null and the status was successful
let uid_string = unsafe { CFString::wrap_under_get_rule(uid).to_string() };
Ok(DeviceId::CoreAudio(uid_string))
} |
||
|
||
/// Attempt to set the device sample rate to the provided rate. | ||
/// Return an error if the requested sample rate is not supported by the device. | ||
fn set_sample_rate( | ||
|
@@ -301,6 +308,10 @@ impl DeviceTrait for Device { | |
Device::name(self) | ||
} | ||
|
||
fn id(&self) -> Result<DeviceId, DeviceIdError> { | ||
Device::id(self) | ||
} | ||
|
||
fn supported_input_configs( | ||
&self, | ||
) -> Result<Self::SupportedInputConfigs, SupportedStreamConfigsError> { | ||
|
@@ -395,6 +406,38 @@ impl Device { | |
}) | ||
} | ||
|
||
fn id(&self) -> Result<DeviceId, DeviceIdError> { | ||
let property_address = AudioObjectPropertyAddress { | ||
mSelector: kAudioDevicePropertyDeviceUID, | ||
mScope: kAudioObjectPropertyScopeGlobal, | ||
mElement: kAudioObjectPropertyElementMain, | ||
}; | ||
let mut uid: CFStringRef = std::ptr::null_mut(); | ||
let data_size = size_of::<CFStringRef>() as u32; | ||
let status = unsafe { | ||
AudioObjectGetPropertyData( | ||
self.audio_device_id, | ||
NonNull::from(&property_address), | ||
0, | ||
null(), | ||
NonNull::from(&data_size), | ||
NonNull::from(&mut uid).cast(), | ||
) | ||
}; | ||
check_os_status(status)?; | ||
if !uid.is_null() { | ||
let uid_string = | ||
unsafe { CFString::wrap_under_get_rule(uid as *mut CFString).to_string() }; | ||
Ok(DeviceId::CoreAudio(uid_string)) | ||
} else { | ||
Err(DeviceIdError::BackendSpecific { | ||
err: BackendSpecificError { | ||
description: "Device UID not found".to_string(), | ||
}, | ||
}) | ||
} | ||
} | ||
|
||
// Logic re-used between `supported_input_configs` and `supported_output_configs`. | ||
#[allow(clippy::cast_ptr_alignment)] | ||
fn supported_configs( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should be
DeviceTrait
.