author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 03 May 2010 13:17:34 +0300 | |
changeset 19 | fcece45ef507 |
parent 18 | 2f34d5167611 |
child 30 | 5dc02b23752f |
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" |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
61 |
#elif defined(Q_OS_SYMBIAN) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
62 |
#include "qaudiodeviceinfo_symbian_p.h" |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
63 |
#include "qaudiooutput_symbian_p.h" |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
64 |
#include "qaudioinput_symbian_p.h" |
0 | 65 |
#endif |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
66 |
#endif |
0 | 67 |
|
68 |
QT_BEGIN_NAMESPACE |
|
69 |
||
70 |
Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, |
|
71 |
(QAudioEngineFactoryInterface_iid, QLatin1String("/audio"), Qt::CaseInsensitive)) |
|
72 |
||
73 |
||
74 |
class QNullDeviceInfo : public QAbstractAudioDeviceInfo |
|
75 |
{ |
|
76 |
public: |
|
77 |
QAudioFormat preferredFormat() const { qWarning()<<"using null deviceinfo, none available"; return QAudioFormat(); } |
|
78 |
bool isFormatSupported(const QAudioFormat& ) const { return false; } |
|
79 |
QAudioFormat nearestFormat(const QAudioFormat& ) const { return QAudioFormat(); } |
|
80 |
QString deviceName() const { return QString(); } |
|
81 |
QStringList codecList() { return QStringList(); } |
|
82 |
QList<int> frequencyList() { return QList<int>(); } |
|
83 |
QList<int> channelsList() { return QList<int>(); } |
|
84 |
QList<int> sampleSizeList() { return QList<int>(); } |
|
85 |
QList<QAudioFormat::Endian> byteOrderList() { return QList<QAudioFormat::Endian>(); } |
|
86 |
QList<QAudioFormat::SampleType> sampleTypeList() { return QList<QAudioFormat::SampleType>(); } |
|
87 |
}; |
|
88 |
||
89 |
class QNullInputDevice : public QAbstractAudioInput |
|
90 |
{ |
|
91 |
public: |
|
92 |
QIODevice* start(QIODevice* ) { qWarning()<<"using null input device, none available"; return 0; } |
|
93 |
void stop() {} |
|
94 |
void reset() {} |
|
95 |
void suspend() {} |
|
96 |
void resume() {} |
|
97 |
int bytesReady() const { return 0; } |
|
98 |
int periodSize() const { return 0; } |
|
99 |
void setBufferSize(int ) {} |
|
100 |
int bufferSize() const { return 0; } |
|
101 |
void setNotifyInterval(int ) {} |
|
102 |
int notifyInterval() const { return 0; } |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
103 |
qint64 processedUSecs() const { return 0; } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
104 |
qint64 elapsedUSecs() const { return 0; } |
0 | 105 |
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
|
106 |
QAudio::State state() const { return QAudio::StoppedState; } |
0 | 107 |
QAudioFormat format() const { return QAudioFormat(); } |
108 |
}; |
|
109 |
||
110 |
class QNullOutputDevice : public QAbstractAudioOutput |
|
111 |
{ |
|
112 |
public: |
|
113 |
QIODevice* start(QIODevice* ) { qWarning()<<"using null output device, none available"; return 0; } |
|
114 |
void stop() {} |
|
115 |
void reset() {} |
|
116 |
void suspend() {} |
|
117 |
void resume() {} |
|
118 |
int bytesFree() const { return 0; } |
|
119 |
int periodSize() const { return 0; } |
|
120 |
void setBufferSize(int ) {} |
|
121 |
int bufferSize() const { return 0; } |
|
122 |
void setNotifyInterval(int ) {} |
|
123 |
int notifyInterval() const { return 0; } |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
124 |
qint64 processedUSecs() const { return 0; } |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
125 |
qint64 elapsedUSecs() const { return 0; } |
0 | 126 |
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
|
127 |
QAudio::State state() const { return QAudio::StoppedState; } |
0 | 128 |
QAudioFormat format() const { return QAudioFormat(); } |
129 |
}; |
|
130 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
131 |
QList<QAudioDeviceInfo> QAudioDeviceFactory::availableDevices(QAudio::Mode mode) |
0 | 132 |
{ |
133 |
QList<QAudioDeviceInfo> devices; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
134 |
#ifndef QT_NO_AUDIO_BACKEND |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
135 |
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN)) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
136 |
foreach (const QByteArray &handle, QAudioDeviceInfoInternal::availableDevices(mode)) |
0 | 137 |
devices << QAudioDeviceInfo(QLatin1String("builtin"), handle, mode); |
138 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
139 |
#endif |
0 | 140 |
QFactoryLoader* l = loader(); |
141 |
||
142 |
foreach (QString const& key, l->keys()) { |
|
143 |
QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(l->instance(key)); |
|
144 |
if (plugin) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
145 |
foreach (QByteArray const& handle, plugin->availableDevices(mode)) |
0 | 146 |
devices << QAudioDeviceInfo(key, handle, mode); |
147 |
} |
|
148 |
||
149 |
delete plugin; |
|
150 |
} |
|
151 |
||
152 |
return devices; |
|
153 |
} |
|
154 |
||
155 |
QAudioDeviceInfo QAudioDeviceFactory::defaultInputDevice() |
|
156 |
{ |
|
157 |
QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(QLatin1String("default"))); |
|
158 |
||
159 |
if (plugin) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
QList<QByteArray> list = plugin->availableDevices(QAudio::AudioInput); |
0 | 161 |
if (list.size() > 0) |
162 |
return QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioInput); |
|
163 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
164 |
#ifndef QT_NO_AUDIO_BACKEND |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
165 |
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN)) |
0 | 166 |
return QAudioDeviceInfo(QLatin1String("builtin"), QAudioDeviceInfoInternal::defaultInputDevice(), QAudio::AudioInput); |
167 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
168 |
#endif |
0 | 169 |
return QAudioDeviceInfo(); |
170 |
} |
|
171 |
||
172 |
QAudioDeviceInfo QAudioDeviceFactory::defaultOutputDevice() |
|
173 |
{ |
|
174 |
QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(QLatin1String("default"))); |
|
175 |
||
176 |
if (plugin) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
177 |
QList<QByteArray> list = plugin->availableDevices(QAudio::AudioOutput); |
0 | 178 |
if (list.size() > 0) |
179 |
return QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioOutput); |
|
180 |
} |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
#ifndef QT_NO_AUDIO_BACKEND |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
182 |
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN)) |
0 | 183 |
return QAudioDeviceInfo(QLatin1String("builtin"), QAudioDeviceInfoInternal::defaultOutputDevice(), QAudio::AudioOutput); |
184 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
185 |
#endif |
0 | 186 |
return QAudioDeviceInfo(); |
187 |
} |
|
188 |
||
189 |
QAbstractAudioDeviceInfo* QAudioDeviceFactory::audioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode) |
|
190 |
{ |
|
191 |
QAbstractAudioDeviceInfo *rc = 0; |
|
192 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
193 |
#ifndef QT_NO_AUDIO_BACKEND |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
194 |
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN)) |
0 | 195 |
if (realm == QLatin1String("builtin")) |
196 |
return new QAudioDeviceInfoInternal(handle, mode); |
|
197 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
198 |
#endif |
0 | 199 |
QAudioEngineFactoryInterface* plugin = |
200 |
qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(realm)); |
|
201 |
||
202 |
if (plugin) |
|
203 |
rc = plugin->createDeviceInfo(handle, mode); |
|
204 |
||
205 |
return rc == 0 ? new QNullDeviceInfo() : rc; |
|
206 |
} |
|
207 |
||
208 |
QAbstractAudioInput* QAudioDeviceFactory::createDefaultInputDevice(QAudioFormat const &format) |
|
209 |
{ |
|
210 |
return createInputDevice(defaultInputDevice(), format); |
|
211 |
} |
|
212 |
||
213 |
QAbstractAudioOutput* QAudioDeviceFactory::createDefaultOutputDevice(QAudioFormat const &format) |
|
214 |
{ |
|
215 |
return createOutputDevice(defaultOutputDevice(), format); |
|
216 |
} |
|
217 |
||
218 |
QAbstractAudioInput* QAudioDeviceFactory::createInputDevice(QAudioDeviceInfo const& deviceInfo, QAudioFormat const &format) |
|
219 |
{ |
|
220 |
if (deviceInfo.isNull()) |
|
221 |
return new QNullInputDevice(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
222 |
#ifndef QT_NO_AUDIO_BACKEND |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
223 |
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN)) |
0 | 224 |
if (deviceInfo.realm() == QLatin1String("builtin")) |
225 |
return new QAudioInputPrivate(deviceInfo.handle(), format); |
|
226 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
227 |
#endif |
0 | 228 |
QAudioEngineFactoryInterface* plugin = |
229 |
qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(deviceInfo.realm())); |
|
230 |
||
231 |
if (plugin) |
|
232 |
return plugin->createInput(deviceInfo.handle(), format); |
|
233 |
||
234 |
return new QNullInputDevice(); |
|
235 |
} |
|
236 |
||
237 |
QAbstractAudioOutput* QAudioDeviceFactory::createOutputDevice(QAudioDeviceInfo const& deviceInfo, QAudioFormat const &format) |
|
238 |
{ |
|
239 |
if (deviceInfo.isNull()) |
|
240 |
return new QNullOutputDevice(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
241 |
#ifndef QT_NO_AUDIO_BACKEND |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
242 |
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA) || defined(Q_OS_SYMBIAN)) |
0 | 243 |
if (deviceInfo.realm() == QLatin1String("builtin")) |
244 |
return new QAudioOutputPrivate(deviceInfo.handle(), format); |
|
245 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
246 |
#endif |
0 | 247 |
QAudioEngineFactoryInterface* plugin = |
248 |
qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(deviceInfo.realm())); |
|
249 |
||
250 |
if (plugin) |
|
251 |
return plugin->createOutput(deviceInfo.handle(), format); |
|
252 |
||
253 |
return new QNullOutputDevice(); |
|
254 |
} |
|
255 |
||
256 |
QT_END_NAMESPACE |
|
257 |