0
|
1 |
/* This file is part of the KDE project.
|
|
2 |
|
|
3 |
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
|
|
5 |
This library is free software: you can redistribute it and/or modify
|
|
6 |
it under the terms of the GNU Lesser General Public License as published by
|
|
7 |
the Free Software Foundation, either version 2.1 or 3 of the License.
|
|
8 |
|
|
9 |
This library is distributed in the hope that it will be useful,
|
|
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
GNU Lesser General Public License for more details.
|
|
13 |
|
|
14 |
You should have received a copy of the GNU Lesser General Public License
|
|
15 |
along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "audiodevice.h"
|
|
19 |
#include "audiograph.h"
|
|
20 |
#include <QtCore/QVector>
|
|
21 |
#include "backendheader.h"
|
|
22 |
|
|
23 |
QT_BEGIN_NAMESPACE
|
|
24 |
|
|
25 |
namespace Phonon
|
|
26 |
{
|
|
27 |
namespace QT7
|
|
28 |
{
|
|
29 |
|
|
30 |
QList<AudioDeviceID> AudioDevice::devices(Scope scope)
|
|
31 |
{
|
|
32 |
QList<AudioDeviceID> devices;
|
|
33 |
|
|
34 |
// Insert the default device explicit
|
|
35 |
if (AudioDeviceID defdev = defaultDevice(scope))
|
|
36 |
devices << defdev;
|
|
37 |
|
|
38 |
// How many input/output devices are awailable:
|
|
39 |
UInt32 deviceCount = 0;
|
|
40 |
OSStatus err = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &deviceCount, 0);
|
|
41 |
BACKEND_ASSERT3(err == noErr, "Could not get number of audio devices awailable.", FATAL_ERROR, devices)
|
|
42 |
|
|
43 |
// Get list of all devices:
|
|
44 |
AudioDeviceID deviceArray[deviceCount];
|
|
45 |
err = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &deviceCount, &deviceArray);
|
|
46 |
BACKEND_ASSERT3(err == noErr, "Could not get audio devices list.", FATAL_ERROR, devices)
|
|
47 |
|
|
48 |
for (uint i=0; i<deviceCount; i++){
|
|
49 |
if (!devices.contains(deviceArray[i])){
|
|
50 |
// Check if the current device is input or output:
|
|
51 |
UInt32 size;
|
|
52 |
err = AudioDeviceGetPropertyInfo(deviceArray[i], 0, scope == In, kAudioDevicePropertyStreams, &size, 0);
|
|
53 |
if (err == noErr && size > 0)
|
|
54 |
devices << deviceArray[i];
|
|
55 |
}
|
|
56 |
}
|
|
57 |
return devices;
|
|
58 |
}
|
|
59 |
|
|
60 |
AudioDeviceID AudioDevice::defaultSystemDevice(Scope scope)
|
|
61 |
{
|
|
62 |
ARGUMENT_UNSUPPORTED(scope, In, NORMAL_ERROR, 0)
|
|
63 |
AudioDeviceID deviceID = 0;
|
|
64 |
UInt32 size = sizeof(deviceID);
|
|
65 |
OSStatus err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultSystemOutputDevice, &size, &deviceID);
|
|
66 |
BACKEND_ASSERT3(err == noErr, "Could not get default system audio device.", FATAL_ERROR, 0)
|
|
67 |
return deviceID;
|
|
68 |
}
|
|
69 |
|
|
70 |
AudioDeviceID AudioDevice::defaultDevice(Scope scope)
|
|
71 |
{
|
|
72 |
ARGUMENT_UNSUPPORTED(scope, In, NORMAL_ERROR, 0)
|
|
73 |
AudioDeviceID deviceID = 0;
|
|
74 |
UInt32 size = sizeof(deviceID);
|
|
75 |
OSStatus err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, &size, &deviceID);
|
|
76 |
BACKEND_ASSERT3(err == noErr, "Could not get default output audio device.", FATAL_ERROR, 0)
|
|
77 |
return deviceID;
|
|
78 |
}
|
|
79 |
|
|
80 |
AudioDeviceID AudioDevice::currentDevice(AudioUnit /*unit*/, Scope /*scope*/)
|
|
81 |
{
|
|
82 |
return 0;
|
|
83 |
#if 0
|
|
84 |
|
|
85 |
kAudioDevicePropertyDeviceUID
|
|
86 |
|
|
87 |
if (!m_audioUnit)
|
|
88 |
return 0;
|
|
89 |
AudioDeviceID deviceID = 0;
|
|
90 |
UInt32 size = sizeof(deviceID);
|
|
91 |
OSStatus err = AudioUnitGetProperty(m_audioUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &size, &deviceID);
|
|
92 |
BACKEND_ASSERT3(err == noErr, "Could not get current audio device.", FATAL_ERROR, 0)
|
|
93 |
return deviceID;
|
|
94 |
#endif
|
|
95 |
}
|
|
96 |
|
|
97 |
bool AudioDevice::setDevice(AudioUnit unit, AudioDeviceID deviceID, Scope scope)
|
|
98 |
{
|
|
99 |
ARGUMENT_UNSUPPORTED(scope, In, NORMAL_ERROR, false)
|
|
100 |
UInt32 size = sizeof(deviceID);
|
|
101 |
OSStatus err = AudioUnitSetProperty(unit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &deviceID, size);
|
|
102 |
if (err != noErr)
|
|
103 |
return false;
|
|
104 |
return true;
|
|
105 |
}
|
|
106 |
|
|
107 |
QString AudioDevice::deviceSourceNameElseDeviceName(AudioDeviceID deviceID)
|
|
108 |
{
|
|
109 |
QString name = deviceSourceName(deviceID);
|
|
110 |
if (name.isEmpty())
|
|
111 |
name = deviceName(deviceID);
|
|
112 |
return name;
|
|
113 |
}
|
|
114 |
|
|
115 |
QString AudioDevice::deviceNameElseDeviceSourceName(AudioDeviceID deviceID)
|
|
116 |
{
|
|
117 |
QString name = deviceName(deviceID);
|
|
118 |
if (name.isEmpty())
|
|
119 |
name = deviceSourceName(deviceID);
|
|
120 |
return name;
|
|
121 |
}
|
|
122 |
|
|
123 |
QString AudioDevice::deviceName(AudioDeviceID deviceID)
|
|
124 |
{
|
|
125 |
if (!deviceID)
|
|
126 |
return QString();
|
|
127 |
CFStringRef cfString = 0;
|
|
128 |
UInt32 size = sizeof(cfString);
|
|
129 |
OSStatus err = AudioDeviceGetProperty(deviceID, 0, 0, kAudioDevicePropertyDeviceNameCFString, &size, &cfString);
|
|
130 |
if (err != noErr)
|
|
131 |
return QString();
|
|
132 |
QString name = PhononCFString::toQString(cfString);
|
|
133 |
CFRelease(cfString);
|
|
134 |
return name;
|
|
135 |
}
|
|
136 |
|
|
137 |
QString AudioDevice::deviceSourceName(AudioDeviceID deviceID)
|
|
138 |
{
|
|
139 |
if (!deviceID)
|
|
140 |
return QString();
|
|
141 |
UInt32 dataSource = 0;
|
|
142 |
UInt32 size = sizeof(dataSource);
|
|
143 |
OSStatus err = AudioDeviceGetProperty(deviceID, 0, 0, kAudioDevicePropertyDataSource, &size, &dataSource);
|
|
144 |
if (err != noErr)
|
|
145 |
return QString();
|
|
146 |
|
|
147 |
CFStringRef cfName = 0;
|
|
148 |
AudioValueTranslation translation = {&dataSource, sizeof(dataSource), &cfName, sizeof(cfName)};
|
|
149 |
size = sizeof(translation);
|
|
150 |
err = AudioDeviceGetProperty(deviceID, 0, 0, kAudioDevicePropertyDataSourceNameForIDCFString, &size, &translation);
|
|
151 |
if (err != noErr){
|
|
152 |
return QString();
|
|
153 |
}
|
|
154 |
QString name = PhononCFString::toQString(cfName);
|
|
155 |
CFRelease(cfName);
|
|
156 |
return name;
|
|
157 |
}
|
|
158 |
|
|
159 |
QString AudioDevice::deviceUID(AudioDeviceID deviceID)
|
|
160 |
{
|
|
161 |
if (!deviceID)
|
|
162 |
return QString();
|
|
163 |
|
|
164 |
CFStringRef cfString = 0;
|
|
165 |
UInt32 size = sizeof(cfString);
|
|
166 |
OSStatus err = AudioDeviceGetProperty(deviceID, 0, 0, kAudioDevicePropertyDeviceUID, &size, &cfString);
|
|
167 |
if (err != noErr)
|
|
168 |
return QString();
|
|
169 |
QString uid = PhononCFString::toQString(cfString);
|
|
170 |
CFRelease(cfString);
|
|
171 |
return uid;
|
|
172 |
}
|
|
173 |
|
|
174 |
}} //namespace Phonon::QT7
|
|
175 |
|
|
176 |
QT_END_NAMESPACE
|