author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 16 Apr 2010 15:50:13 +0300 | |
changeset 18 | 2f34d5167611 |
parent 3 | 41300fa6a67c |
child 8 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtMultimedia module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include <QtCore/qdebug.h> |
|
43 |
#include <QtMultimedia/qaudioengine.h> |
|
44 |
#include <QtMultimedia/qaudioengineplugin.h> |
|
45 |
#include <private/qfactoryloader_p.h> |
|
46 |
#include "qaudiodevicefactory_p.h" |
|
47 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
48 |
#ifndef QT_NO_AUDIO_BACKEND |
0 | 49 |
#if defined(Q_OS_WIN) |
50 |
#include "qaudiodeviceinfo_win32_p.h" |
|
51 |
#include "qaudiooutput_win32_p.h" |
|
52 |
#include "qaudioinput_win32_p.h" |
|
53 |
#elif defined(Q_OS_MAC) |
|
54 |
#include "qaudiodeviceinfo_mac_p.h" |
|
55 |
#include "qaudiooutput_mac_p.h" |
|
56 |
#include "qaudioinput_mac_p.h" |
|
57 |
#elif defined(HAS_ALSA) |
|
58 |
#include "qaudiodeviceinfo_alsa_p.h" |
|
59 |
#include "qaudiooutput_alsa_p.h" |
|
60 |
#include "qaudioinput_alsa_p.h" |
|
61 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
62 |
#endif |
0 | 63 |
|
64 |
QT_BEGIN_NAMESPACE |
|
65 |
||
66 |
Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, |
|
67 |
(QAudioEngineFactoryInterface_iid, QLatin1String("/audio"), Qt::CaseInsensitive)) |
|
68 |
||
69 |
||
70 |
class QNullDeviceInfo : public QAbstractAudioDeviceInfo |
|
71 |
{ |
|
72 |
public: |
|
73 |
QAudioFormat preferredFormat() const { qWarning()<<"using null deviceinfo, none available"; return QAudioFormat(); } |
|
74 |
bool isFormatSupported(const QAudioFormat& ) const { return false; } |
|
75 |
QAudioFormat nearestFormat(const QAudioFormat& ) const { return QAudioFormat(); } |
|
76 |
QString deviceName() const { return QString(); } |
|
77 |
QStringList codecList() { return QStringList(); } |
|
78 |
QList<int> frequencyList() { return QList<int>(); } |
|
79 |
QList<int> channelsList() { return QList<int>(); } |
|
80 |
QList<int> sampleSizeList() { return QList<int>(); } |
|
81 |
QList<QAudioFormat::Endian> byteOrderList() { return QList<QAudioFormat::Endian>(); } |
|
82 |
QList<QAudioFormat::SampleType> sampleTypeList() { return QList<QAudioFormat::SampleType>(); } |
|
83 |
}; |
|
84 |
||
85 |
class QNullInputDevice : public QAbstractAudioInput |
|
86 |
{ |
|
87 |
public: |
|
88 |
QIODevice* start(QIODevice* ) { qWarning()<<"using null input device, none available"; return 0; } |
|
89 |
void stop() {} |
|
90 |
void reset() {} |
|
91 |
void suspend() {} |
|
92 |
void resume() {} |
|
93 |
int bytesReady() const { return 0; } |
|
94 |
int periodSize() const { return 0; } |
|
95 |
void setBufferSize(int ) {} |
|
96 |
int bufferSize() const { return 0; } |
|
97 |
void setNotifyInterval(int ) {} |
|
98 |
int notifyInterval() const { return 0; } |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
99 |
qint64 processedUSecs() const { return 0; } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
100 |
qint64 elapsedUSecs() const { return 0; } |
0 | 101 |
QAudio::Error error() const { return QAudio::OpenError; } |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
102 |
QAudio::State state() const { return QAudio::StoppedState; } |
0 | 103 |
QAudioFormat format() const { return QAudioFormat(); } |
104 |
}; |
|
105 |
||
106 |
class QNullOutputDevice : public QAbstractAudioOutput |
|
107 |
{ |
|
108 |
public: |
|
109 |
QIODevice* start(QIODevice* ) { qWarning()<<"using null output device, none available"; return 0; } |
|
110 |
void stop() {} |
|
111 |
void reset() {} |
|
112 |
void suspend() {} |
|
113 |
void resume() {} |
|
114 |
int bytesFree() const { return 0; } |
|
115 |
int periodSize() const { return 0; } |
|
116 |
void setBufferSize(int ) {} |
|
117 |
int bufferSize() const { return 0; } |
|
118 |
void setNotifyInterval(int ) {} |
|
119 |
int notifyInterval() const { return 0; } |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
120 |
qint64 processedUSecs() const { return 0; } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
121 |
qint64 elapsedUSecs() const { return 0; } |
0 | 122 |
QAudio::Error error() const { return QAudio::OpenError; } |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
123 |
QAudio::State state() const { return QAudio::StoppedState; } |
0 | 124 |
QAudioFormat format() const { return QAudioFormat(); } |
125 |
}; |
|
126 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
127 |
QList<QAudioDeviceInfo> QAudioDeviceFactory::availableDevices(QAudio::Mode mode) |
0 | 128 |
{ |
129 |
QList<QAudioDeviceInfo> devices; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
130 |
#ifndef QT_NO_AUDIO_BACKEND |
0 | 131 |
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
132 |
foreach (const QByteArray &handle, QAudioDeviceInfoInternal::availableDevices(mode)) |
0 | 133 |
devices << QAudioDeviceInfo(QLatin1String("builtin"), handle, mode); |
134 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
135 |
#endif |
0 | 136 |
QFactoryLoader* l = loader(); |
137 |
||
138 |
foreach (QString const& key, l->keys()) { |
|
139 |
QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(l->instance(key)); |
|
140 |
if (plugin) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
141 |
foreach (QByteArray const& handle, plugin->availableDevices(mode)) |
0 | 142 |
devices << QAudioDeviceInfo(key, handle, mode); |
143 |
} |
|
144 |
||
145 |
delete plugin; |
|
146 |
} |
|
147 |
||
148 |
return devices; |
|
149 |
} |
|
150 |
||
151 |
QAudioDeviceInfo QAudioDeviceFactory::defaultInputDevice() |
|
152 |
{ |
|
153 |
QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(QLatin1String("default"))); |
|
154 |
||
155 |
if (plugin) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
156 |
QList<QByteArray> list = plugin->availableDevices(QAudio::AudioInput); |
0 | 157 |
if (list.size() > 0) |
158 |
return QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioInput); |
|
159 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
#ifndef QT_NO_AUDIO_BACKEND |
0 | 161 |
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) |
162 |
return QAudioDeviceInfo(QLatin1String("builtin"), QAudioDeviceInfoInternal::defaultInputDevice(), QAudio::AudioInput); |
|
163 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
164 |
#endif |
0 | 165 |
return QAudioDeviceInfo(); |
166 |
} |
|
167 |
||
168 |
QAudioDeviceInfo QAudioDeviceFactory::defaultOutputDevice() |
|
169 |
{ |
|
170 |
QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(QLatin1String("default"))); |
|
171 |
||
172 |
if (plugin) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
173 |
QList<QByteArray> list = plugin->availableDevices(QAudio::AudioOutput); |
0 | 174 |
if (list.size() > 0) |
175 |
return QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioOutput); |
|
176 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
177 |
#ifndef QT_NO_AUDIO_BACKEND |
0 | 178 |
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) |
179 |
return QAudioDeviceInfo(QLatin1String("builtin"), QAudioDeviceInfoInternal::defaultOutputDevice(), QAudio::AudioOutput); |
|
180 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
#endif |
0 | 182 |
return QAudioDeviceInfo(); |
183 |
} |
|
184 |
||
185 |
QAbstractAudioDeviceInfo* QAudioDeviceFactory::audioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode) |
|
186 |
{ |
|
187 |
QAbstractAudioDeviceInfo *rc = 0; |
|
188 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
#ifndef QT_NO_AUDIO_BACKEND |
0 | 190 |
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) |
191 |
if (realm == QLatin1String("builtin")) |
|
192 |
return new QAudioDeviceInfoInternal(handle, mode); |
|
193 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
194 |
#endif |
0 | 195 |
QAudioEngineFactoryInterface* plugin = |
196 |
qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(realm)); |
|
197 |
||
198 |
if (plugin) |
|
199 |
rc = plugin->createDeviceInfo(handle, mode); |
|
200 |
||
201 |
return rc == 0 ? new QNullDeviceInfo() : rc; |
|
202 |
} |
|
203 |
||
204 |
QAbstractAudioInput* QAudioDeviceFactory::createDefaultInputDevice(QAudioFormat const &format) |
|
205 |
{ |
|
206 |
return createInputDevice(defaultInputDevice(), format); |
|
207 |
} |
|
208 |
||
209 |
QAbstractAudioOutput* QAudioDeviceFactory::createDefaultOutputDevice(QAudioFormat const &format) |
|
210 |
{ |
|
211 |
return createOutputDevice(defaultOutputDevice(), format); |
|
212 |
} |
|
213 |
||
214 |
QAbstractAudioInput* QAudioDeviceFactory::createInputDevice(QAudioDeviceInfo const& deviceInfo, QAudioFormat const &format) |
|
215 |
{ |
|
216 |
if (deviceInfo.isNull()) |
|
217 |
return new QNullInputDevice(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
218 |
#ifndef QT_NO_AUDIO_BACKEND |
0 | 219 |
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) |
220 |
if (deviceInfo.realm() == QLatin1String("builtin")) |
|
221 |
return new QAudioInputPrivate(deviceInfo.handle(), format); |
|
222 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
223 |
#endif |
0 | 224 |
QAudioEngineFactoryInterface* plugin = |
225 |
qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(deviceInfo.realm())); |
|
226 |
||
227 |
if (plugin) |
|
228 |
return plugin->createInput(deviceInfo.handle(), format); |
|
229 |
||
230 |
return new QNullInputDevice(); |
|
231 |
} |
|
232 |
||
233 |
QAbstractAudioOutput* QAudioDeviceFactory::createOutputDevice(QAudioDeviceInfo const& deviceInfo, QAudioFormat const &format) |
|
234 |
{ |
|
235 |
if (deviceInfo.isNull()) |
|
236 |
return new QNullOutputDevice(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
237 |
#ifndef QT_NO_AUDIO_BACKEND |
0 | 238 |
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) |
239 |
if (deviceInfo.realm() == QLatin1String("builtin")) |
|
240 |
return new QAudioOutputPrivate(deviceInfo.handle(), format); |
|
241 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
242 |
#endif |
0 | 243 |
QAudioEngineFactoryInterface* plugin = |
244 |
qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(deviceInfo.realm())); |
|
245 |
||
246 |
if (plugin) |
|
247 |
return plugin->createOutput(deviceInfo.handle(), format); |
|
248 |
||
249 |
return new QNullOutputDevice(); |
|
250 |
} |
|
251 |
||
252 |
QT_END_NAMESPACE |
|
253 |