43 #include <QtMultimedia/qaudioengine.h> |
43 #include <QtMultimedia/qaudioengine.h> |
44 #include <QtMultimedia/qaudioengineplugin.h> |
44 #include <QtMultimedia/qaudioengineplugin.h> |
45 #include <private/qfactoryloader_p.h> |
45 #include <private/qfactoryloader_p.h> |
46 #include "qaudiodevicefactory_p.h" |
46 #include "qaudiodevicefactory_p.h" |
47 |
47 |
|
48 #ifndef QT_NO_AUDIO_BACKEND |
48 #if defined(Q_OS_WIN) |
49 #if defined(Q_OS_WIN) |
49 #include "qaudiodeviceinfo_win32_p.h" |
50 #include "qaudiodeviceinfo_win32_p.h" |
50 #include "qaudiooutput_win32_p.h" |
51 #include "qaudiooutput_win32_p.h" |
51 #include "qaudioinput_win32_p.h" |
52 #include "qaudioinput_win32_p.h" |
52 #elif defined(Q_OS_MAC) |
53 #elif defined(Q_OS_MAC) |
56 #elif defined(HAS_ALSA) |
57 #elif defined(HAS_ALSA) |
57 #include "qaudiodeviceinfo_alsa_p.h" |
58 #include "qaudiodeviceinfo_alsa_p.h" |
58 #include "qaudiooutput_alsa_p.h" |
59 #include "qaudiooutput_alsa_p.h" |
59 #include "qaudioinput_alsa_p.h" |
60 #include "qaudioinput_alsa_p.h" |
60 #endif |
61 #endif |
|
62 #endif |
61 |
63 |
62 QT_BEGIN_NAMESPACE |
64 QT_BEGIN_NAMESPACE |
63 |
65 |
64 Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, |
66 Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, |
65 (QAudioEngineFactoryInterface_iid, QLatin1String("/audio"), Qt::CaseInsensitive)) |
67 (QAudioEngineFactoryInterface_iid, QLatin1String("/audio"), Qt::CaseInsensitive)) |
92 int periodSize() const { return 0; } |
94 int periodSize() const { return 0; } |
93 void setBufferSize(int ) {} |
95 void setBufferSize(int ) {} |
94 int bufferSize() const { return 0; } |
96 int bufferSize() const { return 0; } |
95 void setNotifyInterval(int ) {} |
97 void setNotifyInterval(int ) {} |
96 int notifyInterval() const { return 0; } |
98 int notifyInterval() const { return 0; } |
97 qint64 totalTime() const { return 0; } |
99 qint64 processedUSecs() const { return 0; } |
98 qint64 clock() const { return 0; } |
100 qint64 elapsedUSecs() const { return 0; } |
99 QAudio::Error error() const { return QAudio::OpenError; } |
101 QAudio::Error error() const { return QAudio::OpenError; } |
100 QAudio::State state() const { return QAudio::StopState; } |
102 QAudio::State state() const { return QAudio::StoppedState; } |
101 QAudioFormat format() const { return QAudioFormat(); } |
103 QAudioFormat format() const { return QAudioFormat(); } |
102 }; |
104 }; |
103 |
105 |
104 class QNullOutputDevice : public QAbstractAudioOutput |
106 class QNullOutputDevice : public QAbstractAudioOutput |
105 { |
107 { |
113 int periodSize() const { return 0; } |
115 int periodSize() const { return 0; } |
114 void setBufferSize(int ) {} |
116 void setBufferSize(int ) {} |
115 int bufferSize() const { return 0; } |
117 int bufferSize() const { return 0; } |
116 void setNotifyInterval(int ) {} |
118 void setNotifyInterval(int ) {} |
117 int notifyInterval() const { return 0; } |
119 int notifyInterval() const { return 0; } |
118 qint64 totalTime() const { return 0; } |
120 qint64 processedUSecs() const { return 0; } |
119 qint64 clock() const { return 0; } |
121 qint64 elapsedUSecs() const { return 0; } |
120 QAudio::Error error() const { return QAudio::OpenError; } |
122 QAudio::Error error() const { return QAudio::OpenError; } |
121 QAudio::State state() const { return QAudio::StopState; } |
123 QAudio::State state() const { return QAudio::StoppedState; } |
122 QAudioFormat format() const { return QAudioFormat(); } |
124 QAudioFormat format() const { return QAudioFormat(); } |
123 }; |
125 }; |
124 |
126 |
125 QList<QAudioDeviceInfo> QAudioDeviceFactory::deviceList(QAudio::Mode mode) |
127 QList<QAudioDeviceInfo> QAudioDeviceFactory::availableDevices(QAudio::Mode mode) |
126 { |
128 { |
127 QList<QAudioDeviceInfo> devices; |
129 QList<QAudioDeviceInfo> devices; |
128 #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) |
130 #ifndef QT_NO_AUDIO_BACKEND |
129 foreach (const QByteArray &handle, QAudioDeviceInfoInternal::deviceList(mode)) |
131 #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) |
|
132 foreach (const QByteArray &handle, QAudioDeviceInfoInternal::availableDevices(mode)) |
130 devices << QAudioDeviceInfo(QLatin1String("builtin"), handle, mode); |
133 devices << QAudioDeviceInfo(QLatin1String("builtin"), handle, mode); |
|
134 #endif |
131 #endif |
135 #endif |
132 QFactoryLoader* l = loader(); |
136 QFactoryLoader* l = loader(); |
133 |
137 |
134 foreach (QString const& key, l->keys()) { |
138 foreach (QString const& key, l->keys()) { |
135 QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(l->instance(key)); |
139 QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(l->instance(key)); |
136 if (plugin) { |
140 if (plugin) { |
137 foreach (QByteArray const& handle, plugin->deviceList(mode)) |
141 foreach (QByteArray const& handle, plugin->availableDevices(mode)) |
138 devices << QAudioDeviceInfo(key, handle, mode); |
142 devices << QAudioDeviceInfo(key, handle, mode); |
139 } |
143 } |
140 |
144 |
141 delete plugin; |
145 delete plugin; |
142 } |
146 } |
147 QAudioDeviceInfo QAudioDeviceFactory::defaultInputDevice() |
151 QAudioDeviceInfo QAudioDeviceFactory::defaultInputDevice() |
148 { |
152 { |
149 QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(QLatin1String("default"))); |
153 QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(QLatin1String("default"))); |
150 |
154 |
151 if (plugin) { |
155 if (plugin) { |
152 QList<QByteArray> list = plugin->deviceList(QAudio::AudioInput); |
156 QList<QByteArray> list = plugin->availableDevices(QAudio::AudioInput); |
153 if (list.size() > 0) |
157 if (list.size() > 0) |
154 return QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioInput); |
158 return QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioInput); |
155 } |
159 } |
|
160 #ifndef QT_NO_AUDIO_BACKEND |
156 #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) |
161 #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) |
157 return QAudioDeviceInfo(QLatin1String("builtin"), QAudioDeviceInfoInternal::defaultInputDevice(), QAudio::AudioInput); |
162 return QAudioDeviceInfo(QLatin1String("builtin"), QAudioDeviceInfoInternal::defaultInputDevice(), QAudio::AudioInput); |
158 #endif |
163 #endif |
|
164 #endif |
159 return QAudioDeviceInfo(); |
165 return QAudioDeviceInfo(); |
160 } |
166 } |
161 |
167 |
162 QAudioDeviceInfo QAudioDeviceFactory::defaultOutputDevice() |
168 QAudioDeviceInfo QAudioDeviceFactory::defaultOutputDevice() |
163 { |
169 { |
164 QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(QLatin1String("default"))); |
170 QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(QLatin1String("default"))); |
165 |
171 |
166 if (plugin) { |
172 if (plugin) { |
167 QList<QByteArray> list = plugin->deviceList(QAudio::AudioOutput); |
173 QList<QByteArray> list = plugin->availableDevices(QAudio::AudioOutput); |
168 if (list.size() > 0) |
174 if (list.size() > 0) |
169 return QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioOutput); |
175 return QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioOutput); |
170 } |
176 } |
|
177 #ifndef QT_NO_AUDIO_BACKEND |
171 #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) |
178 #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) |
172 return QAudioDeviceInfo(QLatin1String("builtin"), QAudioDeviceInfoInternal::defaultOutputDevice(), QAudio::AudioOutput); |
179 return QAudioDeviceInfo(QLatin1String("builtin"), QAudioDeviceInfoInternal::defaultOutputDevice(), QAudio::AudioOutput); |
173 #endif |
180 #endif |
|
181 #endif |
174 return QAudioDeviceInfo(); |
182 return QAudioDeviceInfo(); |
175 } |
183 } |
176 |
184 |
177 QAbstractAudioDeviceInfo* QAudioDeviceFactory::audioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode) |
185 QAbstractAudioDeviceInfo* QAudioDeviceFactory::audioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode) |
178 { |
186 { |
179 QAbstractAudioDeviceInfo *rc = 0; |
187 QAbstractAudioDeviceInfo *rc = 0; |
180 |
188 |
|
189 #ifndef QT_NO_AUDIO_BACKEND |
181 #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) |
190 #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) |
182 if (realm == QLatin1String("builtin")) |
191 if (realm == QLatin1String("builtin")) |
183 return new QAudioDeviceInfoInternal(handle, mode); |
192 return new QAudioDeviceInfoInternal(handle, mode); |
184 #endif |
193 #endif |
|
194 #endif |
185 QAudioEngineFactoryInterface* plugin = |
195 QAudioEngineFactoryInterface* plugin = |
186 qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(realm)); |
196 qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(realm)); |
187 |
197 |
188 if (plugin) |
198 if (plugin) |
189 rc = plugin->createDeviceInfo(handle, mode); |
199 rc = plugin->createDeviceInfo(handle, mode); |
203 |
213 |
204 QAbstractAudioInput* QAudioDeviceFactory::createInputDevice(QAudioDeviceInfo const& deviceInfo, QAudioFormat const &format) |
214 QAbstractAudioInput* QAudioDeviceFactory::createInputDevice(QAudioDeviceInfo const& deviceInfo, QAudioFormat const &format) |
205 { |
215 { |
206 if (deviceInfo.isNull()) |
216 if (deviceInfo.isNull()) |
207 return new QNullInputDevice(); |
217 return new QNullInputDevice(); |
|
218 #ifndef QT_NO_AUDIO_BACKEND |
208 #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) |
219 #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) |
209 if (deviceInfo.realm() == QLatin1String("builtin")) |
220 if (deviceInfo.realm() == QLatin1String("builtin")) |
210 return new QAudioInputPrivate(deviceInfo.handle(), format); |
221 return new QAudioInputPrivate(deviceInfo.handle(), format); |
211 #endif |
222 #endif |
|
223 #endif |
212 QAudioEngineFactoryInterface* plugin = |
224 QAudioEngineFactoryInterface* plugin = |
213 qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(deviceInfo.realm())); |
225 qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(deviceInfo.realm())); |
214 |
226 |
215 if (plugin) |
227 if (plugin) |
216 return plugin->createInput(deviceInfo.handle(), format); |
228 return plugin->createInput(deviceInfo.handle(), format); |
220 |
232 |
221 QAbstractAudioOutput* QAudioDeviceFactory::createOutputDevice(QAudioDeviceInfo const& deviceInfo, QAudioFormat const &format) |
233 QAbstractAudioOutput* QAudioDeviceFactory::createOutputDevice(QAudioDeviceInfo const& deviceInfo, QAudioFormat const &format) |
222 { |
234 { |
223 if (deviceInfo.isNull()) |
235 if (deviceInfo.isNull()) |
224 return new QNullOutputDevice(); |
236 return new QNullOutputDevice(); |
|
237 #ifndef QT_NO_AUDIO_BACKEND |
225 #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) |
238 #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) |
226 if (deviceInfo.realm() == QLatin1String("builtin")) |
239 if (deviceInfo.realm() == QLatin1String("builtin")) |
227 return new QAudioOutputPrivate(deviceInfo.handle(), format); |
240 return new QAudioOutputPrivate(deviceInfo.handle(), format); |
228 #endif |
241 #endif |
|
242 #endif |
229 QAudioEngineFactoryInterface* plugin = |
243 QAudioEngineFactoryInterface* plugin = |
230 qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(deviceInfo.realm())); |
244 qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(deviceInfo.realm())); |
231 |
245 |
232 if (plugin) |
246 if (plugin) |
233 return plugin->createOutput(deviceInfo.handle(), format); |
247 return plugin->createOutput(deviceInfo.handle(), format); |