summaryrefslogtreecommitdiffstats
path: root/src/plugins/coreaudio/coreaudiodeviceinfo.mm
diff options
context:
space:
mode:
authorChristian Stromme <christian.stromme@theqtcompany.com>2016-04-19 14:53:24 +0200
committerChristian Stromme <christian.stromme@qt.io>2016-05-20 10:54:32 +0000
commit3c5bbb0dac7bed3199ddddc88c0175d5a2ac1036 (patch)
tree51b9987225bf224637b87c3dd20558a3cca95811 /src/plugins/coreaudio/coreaudiodeviceinfo.mm
parent49461f9cffa5439e536a844ec3a0134c252141e6 (diff)
Improve QAudioDeviceInfo::defaultDevice().
The previous implementation of QAudioDeviceInfo::defaultXDevice() would always report the first available device as the "default" one, making the order, in which devices were listed, a hidden requirement when implementing audio plugins. To make it easier and more reliable to retrieve the default device, all new plugins should implement the new QAudioSystemPluginExtension interface as well as the QAudioSystemPlugin. Devices will be chosen in the following order (first match wins): default plugin -> default device -> first available device plugins -> default device -> first available device Task-number: QTBUG-51292 Change-Id: I8ace78858976fe7c60a2c4a117ef15c4e1bb177f Reviewed-by: Yoann Lopes <yoann.lopes@qt.io>
Diffstat (limited to 'src/plugins/coreaudio/coreaudiodeviceinfo.mm')
-rw-r--r--src/plugins/coreaudio/coreaudiodeviceinfo.mm53
1 files changed, 15 insertions, 38 deletions
diff --git a/src/plugins/coreaudio/coreaudiodeviceinfo.mm b/src/plugins/coreaudio/coreaudiodeviceinfo.mm
index 66e8ed4d7..1a79438cb 100644
--- a/src/plugins/coreaudio/coreaudiodeviceinfo.mm
+++ b/src/plugins/coreaudio/coreaudiodeviceinfo.mm
@@ -280,47 +280,29 @@ static QByteArray get_device_info(AudioDeviceID audioDevice, QAudio::Mode mode)
}
#endif
-QByteArray CoreAudioDeviceInfo::defaultInputDevice()
+QByteArray CoreAudioDeviceInfo::defaultDevice(QAudio::Mode mode)
{
#if defined(Q_OS_OSX)
AudioDeviceID audioDevice;
UInt32 size = sizeof(audioDevice);
- AudioObjectPropertyAddress defaultInputDevicePropertyAddress = { kAudioHardwarePropertyDefaultInputDevice,
- kAudioObjectPropertyScopeGlobal,
- kAudioObjectPropertyElementMaster };
-
- if (AudioObjectGetPropertyData(kAudioObjectSystemObject,
- &defaultInputDevicePropertyAddress,
- 0, NULL, &size, &audioDevice) != noErr) {
- qWarning() << "QAudioDeviceInfo: Unable to find default input device";
- return QByteArray();
- }
-
- return get_device_info(audioDevice, QAudio::AudioInput);
-#else //iOS
- return CoreAudioSessionManager::instance().inputDevices().first();
-#endif
-}
-
-QByteArray CoreAudioDeviceInfo::defaultOutputDevice()
-{
-#if defined(Q_OS_OSX)
- AudioDeviceID audioDevice;
- UInt32 size = sizeof(audioDevice);
- AudioObjectPropertyAddress defaultOutputDevicePropertyAddress = { kAudioHardwarePropertyDefaultOutputDevice,
- kAudioObjectPropertyScopeGlobal,
- kAudioObjectPropertyElementMaster };
+ const AudioObjectPropertySelector selector = (mode == QAudio::AudioOutput) ? kAudioHardwarePropertyDefaultOutputDevice
+ : kAudioHardwarePropertyDefaultInputDevice;
+ AudioObjectPropertyAddress defaultDevicePropertyAddress = { selector,
+ kAudioObjectPropertyScopeGlobal,
+ kAudioObjectPropertyElementMaster };
if (AudioObjectGetPropertyData(kAudioObjectSystemObject,
- &defaultOutputDevicePropertyAddress,
+ &defaultDevicePropertyAddress,
0, NULL, &size, &audioDevice) != noErr) {
- qWarning() << "QAudioDeviceInfo: Unable to find default output device";
+ qWarning("QAudioDeviceInfo: Unable to find default %s device", (mode == QAudio::AudioOutput) ? "output" : "input");
return QByteArray();
}
- return get_device_info(audioDevice, QAudio::AudioOutput);
+ return get_device_info(audioDevice, mode);
#else //iOS
- return CoreAudioSessionManager::instance().outputDevices().first();
+ const auto &devices = (mode == QAudio::AudioOutput) ? CoreAudioSessionManager::instance().outputDevices()
+ : CoreAudioSessionManager::instance().inputDevices();
+ return !devices.isEmpty() ? devices.first() : QByteArray();
#endif
}
@@ -343,15 +325,10 @@ QList<QByteArray> CoreAudioDeviceInfo::availableDevices(QAudio::Mode mode)
AudioDeviceID* audioDevices = new AudioDeviceID[dc];
if (AudioObjectGetPropertyData(kAudioObjectSystemObject, &audioDevicesPropertyAddress, 0, NULL, &propSize, audioDevices) == noErr) {
- QByteArray defaultDevice = (mode == QAudio::AudioOutput) ? defaultOutputDevice() : defaultInputDevice();
for (int i = 0; i < dc; ++i) {
- QByteArray info = get_device_info(audioDevices[i], mode);
- if (!info.isNull()) {
- if (info == defaultDevice)
- devices.prepend(info);
- else
- devices << info;
- }
+ const QByteArray &info = get_device_info(audioDevices[i], mode);
+ if (!info.isNull())
+ devices << info;
}
}