-
Notifications
You must be signed in to change notification settings - Fork 539
feat(coreaudio): report device transport as InterfaceType #1345
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
jplot
wants to merge
1
commit into
RustAudio:master
Choose a base branch
from
jplot:feat/coreaudio-transport-type
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.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,9 +30,9 @@ use objc2_core_audio::{ | |
| kAudioDevicePropertyBufferFrameSizeRange, kAudioDevicePropertyDeviceUID, | ||
| kAudioDevicePropertyLatency, kAudioDevicePropertyNominalSampleRate, | ||
| kAudioDevicePropertySafetyOffset, kAudioDevicePropertyStreamConfiguration, | ||
| kAudioDevicePropertyStreamFormat, kAudioObjectPropertyClass, kAudioObjectPropertyElementMain, | ||
| kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyScopeInput, | ||
| kAudioObjectPropertyScopeOutput, | ||
| kAudioDevicePropertyStreamFormat, kAudioDevicePropertyTransportType, kAudioObjectPropertyClass, | ||
| kAudioObjectPropertyElementMain, kAudioObjectPropertyScopeGlobal, | ||
| kAudioObjectPropertyScopeInput, kAudioObjectPropertyScopeOutput, | ||
| }; | ||
| use objc2_core_audio_types::{ | ||
| AudioBuffer, AudioBufferList, AudioStreamBasicDescription, AudioValueRange, | ||
|
|
@@ -405,6 +405,64 @@ impl Device { | |
| status == 0 && class_id == kAudioAggregateDeviceClassID | ||
| } | ||
|
|
||
| /// `None` when the property is unavailable or names a transport with no | ||
| /// `InterfaceType` counterpart, so the field is left unset rather than wrong. | ||
| fn transport_interface_type(&self) -> Option<InterfaceType> { | ||
| let property_address = AudioObjectPropertyAddress { | ||
| mSelector: kAudioDevicePropertyTransportType, | ||
| mScope: kAudioObjectPropertyScopeGlobal, | ||
| mElement: kAudioObjectPropertyElementMain, | ||
| }; | ||
|
|
||
| let mut transport: u32 = 0; | ||
| let data_size = size_of::<u32>() as u32; | ||
|
|
||
| // SAFETY: AudioObjectGetPropertyData writes a UInt32 for | ||
| // kAudioDevicePropertyTransportType. The status is checked before use. | ||
| let status = unsafe { | ||
| AudioObjectGetPropertyData( | ||
| self.audio_device_id, | ||
| NonNull::from(&property_address), | ||
| 0, | ||
| null(), | ||
| NonNull::from(&data_size), | ||
|
Comment on lines
+418
to
+428
|
||
| NonNull::from(&mut transport).cast(), | ||
| ) | ||
| }; | ||
| if status != 0 { | ||
| return None; | ||
| } | ||
|
|
||
| // Four-character codes from AudioHardwareBase.h. | ||
| const BUILT_IN: u32 = u32::from_be_bytes(*b"bltn"); | ||
|
Member
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. The following are already exported by pub const kAudioDeviceTransportTypeUnknown: u32 = 0;
pub const kAudioDeviceTransportTypeBuiltIn: u32 = 0x626c746e;
pub const kAudioDeviceTransportTypeAggregate: u32 = 0x67727570;
pub const kAudioDeviceTransportTypeVirtual: u32 = 0x76697274;
pub const kAudioDeviceTransportTypePCI: u32 = 0x70636920;
pub const kAudioDeviceTransportTypeUSB: u32 = 0x75736220;
pub const kAudioDeviceTransportTypeFireWire: u32 = 0x31333934;
pub const kAudioDeviceTransportTypeBluetooth: u32 = 0x626c7565;
pub const kAudioDeviceTransportTypeBluetoothLE: u32 = 0x626c6561;
pub const kAudioDeviceTransportTypeHDMI: u32 = 0x68646d69;
pub const kAudioDeviceTransportTypeDisplayPort: u32 = 0x64707274;
pub const kAudioDeviceTransportTypeAirPlay: u32 = 0x61697270;
pub const kAudioDeviceTransportTypeAVB: u32 = 0x65617662;
pub const kAudioDeviceTransportTypeThunderbolt: u32 = 0x7468756e;
pub const kAudioDeviceTransportTypeContinuityCaptureWired: u32 = 0x63637764;
pub const kAudioDeviceTransportTypeContinuityCaptureWireless: u32 = 0x6363776c;
pub const kAudioDeviceTransportTypeContinuityCapture: u32 = 0x63636170; |
||
| const USB: u32 = u32::from_be_bytes(*b"usb "); | ||
| const BLUETOOTH: u32 = u32::from_be_bytes(*b"blue"); | ||
| const BLUETOOTH_LE: u32 = u32::from_be_bytes(*b"blea"); | ||
| const VIRTUAL: u32 = u32::from_be_bytes(*b"virt"); | ||
| const AGGREGATE: u32 = u32::from_be_bytes(*b"grup"); | ||
| const THUNDERBOLT: u32 = u32::from_be_bytes(*b"thun"); | ||
| const HDMI: u32 = u32::from_be_bytes(*b"hdmi"); | ||
| const DISPLAY_PORT: u32 = u32::from_be_bytes(*b"dprt"); | ||
| const FIREWIRE: u32 = u32::from_be_bytes(*b"1394"); | ||
| const PCI: u32 = u32::from_be_bytes(*b"pci "); | ||
| const AIRPLAY: u32 = u32::from_be_bytes(*b"airp"); | ||
|
|
||
| match transport { | ||
| BUILT_IN => Some(InterfaceType::BuiltIn), | ||
| USB => Some(InterfaceType::Usb), | ||
| BLUETOOTH | BLUETOOTH_LE => Some(InterfaceType::Bluetooth), | ||
| VIRTUAL => Some(InterfaceType::Virtual), | ||
| AGGREGATE => Some(InterfaceType::Aggregate), | ||
| THUNDERBOLT => Some(InterfaceType::Thunderbolt), | ||
| HDMI => Some(InterfaceType::Hdmi), | ||
| DISPLAY_PORT => Some(InterfaceType::DisplayPort), | ||
| FIREWIRE => Some(InterfaceType::FireWire), | ||
| PCI => Some(InterfaceType::Pci), | ||
| AIRPLAY => Some(InterfaceType::Network), | ||
| _ => None, | ||
|
Comment on lines
+448
to
+462
|
||
| } | ||
| } | ||
|
|
||
| fn description(&self) -> Result<crate::DeviceDescription, Error> { | ||
| let name = get_device_name(self.audio_device_id).context("Failed to get device name")?; | ||
|
|
||
|
|
@@ -422,8 +480,11 @@ impl Device { | |
|
|
||
| let mut builder = DeviceDescriptionBuilder::new(name).direction(direction); | ||
|
|
||
| // Check if this is an aggregate device | ||
| if self.is_aggregate_device() { | ||
| // TransportType also reports "grup" for aggregates; the class check | ||
| // remains for devices that do not expose the property. | ||
| if let Some(interface_type) = self.transport_interface_type() { | ||
| builder = builder.interface_type(interface_type); | ||
| } else if self.is_aggregate_device() { | ||
| builder = builder.interface_type(InterfaceType::Aggregate); | ||
| } | ||
|
|
||
|
|
||
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.
This could be a bit shorter by removing the examples in the parentheses.