Convert device name from CFStringRef to char*
This commit is contained in:
parent
bdc257b40e
commit
4dd2c5cdd5
@ -110,6 +110,7 @@ osx_output_set_device(OSXOutput *oo, Error &error)
|
|||||||
UInt32 size, numdevices;
|
UInt32 size, numdevices;
|
||||||
AudioDeviceID *deviceids = nullptr;
|
AudioDeviceID *deviceids = nullptr;
|
||||||
AudioObjectPropertyAddress propaddr;
|
AudioObjectPropertyAddress propaddr;
|
||||||
|
CFStringRef cfname = nullptr;
|
||||||
char name[256];
|
char name[256];
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
@ -144,8 +145,8 @@ osx_output_set_device(OSXOutput *oo, Error &error)
|
|||||||
/* which audio device matches oo->device_name? */
|
/* which audio device matches oo->device_name? */
|
||||||
propaddr = { kAudioObjectPropertyName, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
|
propaddr = { kAudioObjectPropertyName, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
|
||||||
for (i = 0; i < numdevices; i++) {
|
for (i = 0; i < numdevices; i++) {
|
||||||
size = sizeof(name);
|
size = sizeof(CFStringRef);
|
||||||
status = AudioObjectGetPropertyData(deviceids[i], &propaddr, 0, nullptr, &size, name);
|
status = AudioObjectGetPropertyData(deviceids[i], &propaddr, 0, nullptr, &size, &cfname);
|
||||||
if (status != noErr) {
|
if (status != noErr) {
|
||||||
error.Format(osx_output_domain, status,
|
error.Format(osx_output_domain, status,
|
||||||
"Unable to determine OS X device name "
|
"Unable to determine OS X device name "
|
||||||
@ -155,6 +156,12 @@ osx_output_set_device(OSXOutput *oo, Error &error)
|
|||||||
ret = false;
|
ret = false;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
if (!CFStringGetCString(cfname, name, sizeof(name), kCFStringEncodingUTF8)) {
|
||||||
|
error.Format(osx_output_domain, "Unable to convert device name CFString to char*");
|
||||||
|
ret = false;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
FormatDebug(osx_output_domain, "found OS X audio output device: %s", name);
|
FormatDebug(osx_output_domain, "found OS X audio output device: %s", name);
|
||||||
if (strcmp(oo->device_name, name) == 0) {
|
if (strcmp(oo->device_name, name) == 0) {
|
||||||
FormatDebug(osx_output_domain,
|
FormatDebug(osx_output_domain,
|
||||||
@ -191,6 +198,9 @@ osx_output_set_device(OSXOutput *oo, Error &error)
|
|||||||
|
|
||||||
done:
|
done:
|
||||||
delete[] deviceids;
|
delete[] deviceids;
|
||||||
|
if (cfname) {
|
||||||
|
CFRelease(cfname);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user