Skip to content

Commit

Permalink
Patch: Add 'guid' selection for AudioDeviceMac.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jul 16, 2024
1 parent 223865c commit 185ad76
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
32 changes: 29 additions & 3 deletions src/modules/audio_device/mac/audio_device_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -831,12 +831,16 @@ int32_t AudioDeviceMac::PlayoutDeviceName(uint16_t index,

memset(name, 0, kAdmMaxDeviceNameSize);

char noguid[kAdmMaxGuidSize];
if (guid != NULL) {
memset(guid, 0, kAdmMaxGuidSize);
} else {
memset(noguid, 0, kAdmMaxGuidSize);
}

return GetDeviceName(kAudioDevicePropertyScopeOutput, index,
rtc::ArrayView<char>(name, kAdmMaxDeviceNameSize));
rtc::ArrayView<char>(name, kAdmMaxDeviceNameSize),
rtc::ArrayView<char>(guid ? guid : noguid, kAdmMaxGuidSize));
}

int32_t AudioDeviceMac::RecordingDeviceName(uint16_t index,
Expand All @@ -850,12 +854,16 @@ int32_t AudioDeviceMac::RecordingDeviceName(uint16_t index,

memset(name, 0, kAdmMaxDeviceNameSize);

char noguid[kAdmMaxGuidSize];
if (guid != NULL) {
memset(guid, 0, kAdmMaxGuidSize);
} else {
memset(noguid, 0, kAdmMaxGuidSize);
}

return GetDeviceName(kAudioDevicePropertyScopeInput, index,
rtc::ArrayView<char>(name, kAdmMaxDeviceNameSize));
rtc::ArrayView<char>(name, kAdmMaxDeviceNameSize),
rtc::ArrayView<char>(guid ? guid : noguid, kAdmMaxGuidSize));
}

int16_t AudioDeviceMac::RecordingDevices() {
Expand Down Expand Up @@ -1648,7 +1656,8 @@ int32_t AudioDeviceMac::GetNumberDevices(const AudioObjectPropertyScope scope,

int32_t AudioDeviceMac::GetDeviceName(const AudioObjectPropertyScope scope,
const uint16_t index,
rtc::ArrayView<char> name) {
rtc::ArrayView<char> name,
rtc::ArrayView<char> guid) {
OSStatus err = noErr;
AudioDeviceID deviceIds[MaxNumberDevices];

Expand Down Expand Up @@ -1710,6 +1719,23 @@ int32_t AudioDeviceMac::GetDeviceName(const AudioObjectPropertyScope scope,
usedID, &propertyAddress, 0, NULL, &len, name.data()));
}

// Get UID
{
AudioObjectPropertyAddress propertyAddress = {kAudioDevicePropertyDeviceUID,
kAudioObjectPropertyScopeGlobal, 0};
CFStringRef uid = NULL;
UInt32 size = sizeof(uid);
WEBRTC_CA_RETURN_ON_ERR(AudioObjectGetPropertyData(usedID, &propertyAddress,
0, NULL, &size, &uid));

const CFIndex kCStringSize = kAdmMaxGuidSize;
CFStringGetCString(uid, guid.data(), kCStringSize, kCFStringEncodingUTF8);

if (uid) {
CFRelease(uid);
}
}

return 0;
}

Expand Down
3 changes: 2 additions & 1 deletion src/modules/audio_device/mac/audio_device_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ class AudioDeviceMac : public AudioDeviceGeneric {

int32_t GetDeviceName(AudioObjectPropertyScope scope,
uint16_t index,
rtc::ArrayView<char> name);
rtc::ArrayView<char> name,
rtc::ArrayView<char> guid);

int32_t InitDevice(uint16_t userDeviceIndex,
AudioDeviceID& deviceId,
Expand Down

0 comments on commit 185ad76

Please sign in to comment.