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 14 | c0432d11811c |
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 |
// |
|
43 |
// W A R N I N G |
|
44 |
// ------------- |
|
45 |
// |
|
46 |
// This file is not part of the Qt API. It exists for the convenience |
|
47 |
// of other Qt classes. This header file may change from version to |
|
48 |
// version without notice, or even be removed. |
|
49 |
// |
|
50 |
// We mean it. |
|
51 |
// |
|
52 |
||
53 |
||
54 |
#include <windows.h> |
|
55 |
#include <mmsystem.h> |
|
56 |
#include "qaudiodeviceinfo_win32_p.h" |
|
57 |
||
58 |
QT_BEGIN_NAMESPACE |
|
59 |
||
60 |
// For mingw toolchain mmsystem.h only defines half the defines, so add if needed. |
|
61 |
#ifndef WAVE_FORMAT_44M08 |
|
62 |
#define WAVE_FORMAT_44M08 0x00000100 |
|
63 |
#define WAVE_FORMAT_44S08 0x00000200 |
|
64 |
#define WAVE_FORMAT_44M16 0x00000400 |
|
65 |
#define WAVE_FORMAT_44S16 0x00000800 |
|
66 |
#define WAVE_FORMAT_48M08 0x00001000 |
|
67 |
#define WAVE_FORMAT_48S08 0x00002000 |
|
68 |
#define WAVE_FORMAT_48M16 0x00004000 |
|
69 |
#define WAVE_FORMAT_48S16 0x00008000 |
|
70 |
#define WAVE_FORMAT_96M08 0x00010000 |
|
71 |
#define WAVE_FORMAT_96S08 0x00020000 |
|
72 |
#define WAVE_FORMAT_96M16 0x00040000 |
|
73 |
#define WAVE_FORMAT_96S16 0x00080000 |
|
74 |
#endif |
|
75 |
||
76 |
||
77 |
QAudioDeviceInfoInternal::QAudioDeviceInfoInternal(QByteArray dev, QAudio::Mode mode) |
|
78 |
{ |
|
79 |
device = QLatin1String(dev); |
|
80 |
this->mode = mode; |
|
81 |
} |
|
82 |
||
83 |
QAudioDeviceInfoInternal::~QAudioDeviceInfoInternal() |
|
84 |
{ |
|
85 |
close(); |
|
86 |
} |
|
87 |
||
88 |
bool QAudioDeviceInfoInternal::isFormatSupported(const QAudioFormat& format) const |
|
89 |
{ |
|
90 |
return testSettings(format); |
|
91 |
} |
|
92 |
||
93 |
QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const |
|
94 |
{ |
|
95 |
QAudioFormat nearest; |
|
96 |
if(mode == QAudio::AudioOutput) { |
|
97 |
nearest.setFrequency(44100); |
|
98 |
nearest.setChannels(2); |
|
99 |
nearest.setByteOrder(QAudioFormat::LittleEndian); |
|
100 |
nearest.setSampleType(QAudioFormat::SignedInt); |
|
101 |
nearest.setSampleSize(16); |
|
102 |
nearest.setCodec(QLatin1String("audio/pcm")); |
|
103 |
} else { |
|
104 |
nearest.setFrequency(11025); |
|
105 |
nearest.setChannels(1); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
106 |
nearest.setByteOrder(QAudioFormat::LittleEndian); |
0 | 107 |
nearest.setSampleType(QAudioFormat::SignedInt); |
108 |
nearest.setSampleSize(8); |
|
109 |
nearest.setCodec(QLatin1String("audio/pcm")); |
|
110 |
} |
|
111 |
return nearest; |
|
112 |
} |
|
113 |
||
114 |
QAudioFormat QAudioDeviceInfoInternal::nearestFormat(const QAudioFormat& format) const |
|
115 |
{ |
|
116 |
if(testSettings(format)) |
|
117 |
return format; |
|
118 |
else |
|
119 |
return preferredFormat(); |
|
120 |
} |
|
121 |
||
122 |
QString QAudioDeviceInfoInternal::deviceName() const |
|
123 |
{ |
|
124 |
return device; |
|
125 |
} |
|
126 |
||
127 |
QStringList QAudioDeviceInfoInternal::codecList() |
|
128 |
{ |
|
129 |
updateLists(); |
|
130 |
return codecz; |
|
131 |
} |
|
132 |
||
133 |
QList<int> QAudioDeviceInfoInternal::frequencyList() |
|
134 |
{ |
|
135 |
updateLists(); |
|
136 |
return freqz; |
|
137 |
} |
|
138 |
||
139 |
QList<int> QAudioDeviceInfoInternal::channelsList() |
|
140 |
{ |
|
141 |
updateLists(); |
|
142 |
return channelz; |
|
143 |
} |
|
144 |
||
145 |
QList<int> QAudioDeviceInfoInternal::sampleSizeList() |
|
146 |
{ |
|
147 |
updateLists(); |
|
148 |
return sizez; |
|
149 |
} |
|
150 |
||
151 |
QList<QAudioFormat::Endian> QAudioDeviceInfoInternal::byteOrderList() |
|
152 |
{ |
|
153 |
updateLists(); |
|
154 |
return byteOrderz; |
|
155 |
} |
|
156 |
||
157 |
QList<QAudioFormat::SampleType> QAudioDeviceInfoInternal::sampleTypeList() |
|
158 |
{ |
|
159 |
updateLists(); |
|
160 |
return typez; |
|
161 |
} |
|
162 |
||
163 |
||
164 |
bool QAudioDeviceInfoInternal::open() |
|
165 |
{ |
|
166 |
return true; |
|
167 |
} |
|
168 |
||
169 |
void QAudioDeviceInfoInternal::close() |
|
170 |
{ |
|
171 |
} |
|
172 |
||
173 |
bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const |
|
174 |
{ |
|
175 |
// Set nearest to closest settings that do work. |
|
176 |
// See if what is in settings will work (return value). |
|
177 |
||
178 |
bool failed = false; |
|
179 |
||
180 |
// For now, just accept only audio/pcm codec |
|
181 |
if(!format.codec().startsWith(QLatin1String("audio/pcm"))) |
|
182 |
failed = true; |
|
183 |
||
184 |
if(!failed && !(format.channels() == 1 || format.channels() == 2)) |
|
185 |
failed = true; |
|
186 |
||
187 |
if(!failed) { |
|
188 |
if(!(format.frequency() == 8000 || format.frequency() == 11025 || format.frequency() == 22050 || |
|
189 |
format.frequency() == 44100 || format.frequency() == 48000 || format.frequency() == 96000)) |
|
190 |
failed = true; |
|
191 |
} |
|
192 |
||
193 |
if(!failed && !(format.sampleSize() == 8 || format.sampleSize() == 16)) |
|
194 |
failed = true; |
|
195 |
||
196 |
if(!failed) { |
|
197 |
// settings work |
|
198 |
return true; |
|
199 |
} |
|
200 |
return false; |
|
201 |
} |
|
202 |
||
203 |
void QAudioDeviceInfoInternal::updateLists() |
|
204 |
{ |
|
205 |
// redo all lists based on current settings |
|
206 |
bool base = false; |
|
207 |
bool match = false; |
|
208 |
DWORD fmt = NULL; |
|
209 |
QString tmp; |
|
210 |
||
211 |
if(device.compare(QLatin1String("default")) == 0) |
|
212 |
base = true; |
|
213 |
||
214 |
if(mode == QAudio::AudioOutput) { |
|
215 |
WAVEOUTCAPS woc; |
|
216 |
unsigned long iNumDevs,i; |
|
217 |
iNumDevs = waveOutGetNumDevs(); |
|
218 |
for(i=0;i<iNumDevs;i++) { |
|
219 |
if(waveOutGetDevCaps(i, &woc, sizeof(WAVEOUTCAPS)) |
|
220 |
== MMSYSERR_NOERROR) { |
|
221 |
tmp = QString::fromUtf16((const unsigned short*)woc.szPname); |
|
222 |
if(tmp.compare(device) == 0) { |
|
223 |
match = true; |
|
224 |
fmt = woc.dwFormats; |
|
225 |
break; |
|
226 |
} |
|
227 |
if(base) { |
|
228 |
match = true; |
|
229 |
fmt = woc.dwFormats; |
|
230 |
break; |
|
231 |
} |
|
232 |
} |
|
233 |
} |
|
234 |
} else { |
|
235 |
WAVEINCAPS woc; |
|
236 |
unsigned long iNumDevs,i; |
|
237 |
iNumDevs = waveInGetNumDevs(); |
|
238 |
for(i=0;i<iNumDevs;i++) { |
|
239 |
if(waveInGetDevCaps(i, &woc, sizeof(WAVEINCAPS)) |
|
240 |
== MMSYSERR_NOERROR) { |
|
241 |
tmp = QString::fromUtf16((const unsigned short*)woc.szPname); |
|
242 |
if(tmp.compare(device) == 0) { |
|
243 |
match = true; |
|
244 |
fmt = woc.dwFormats; |
|
245 |
break; |
|
246 |
} |
|
247 |
if(base) { |
|
248 |
match = true; |
|
249 |
fmt = woc.dwFormats; |
|
250 |
break; |
|
251 |
} |
|
252 |
} |
|
253 |
} |
|
254 |
} |
|
255 |
sizez.clear(); |
|
256 |
freqz.clear(); |
|
257 |
channelz.clear(); |
|
258 |
byteOrderz.clear(); |
|
259 |
typez.clear(); |
|
260 |
codecz.clear(); |
|
261 |
||
262 |
if(match) { |
|
263 |
if((fmt && WAVE_FORMAT_1M08) |
|
264 |
|| (fmt && WAVE_FORMAT_1S08) |
|
265 |
|| (fmt && WAVE_FORMAT_2M08) |
|
266 |
|| (fmt && WAVE_FORMAT_2S08) |
|
267 |
|| (fmt && WAVE_FORMAT_4M08) |
|
268 |
|| (fmt && WAVE_FORMAT_4S08) |
|
269 |
#ifndef Q_OS_WINCE |
|
270 |
|| (fmt && WAVE_FORMAT_48M08) |
|
271 |
|| (fmt && WAVE_FORMAT_48S08) |
|
272 |
|| (fmt && WAVE_FORMAT_96M08) |
|
273 |
|| (fmt && WAVE_FORMAT_96S08) |
|
274 |
#endif |
|
275 |
) { |
|
276 |
sizez.append(8); |
|
277 |
} |
|
278 |
if((fmt && WAVE_FORMAT_1M16) |
|
279 |
|| (fmt && WAVE_FORMAT_1S16) |
|
280 |
|| (fmt && WAVE_FORMAT_2M16) |
|
281 |
|| (fmt && WAVE_FORMAT_2S16) |
|
282 |
|| (fmt && WAVE_FORMAT_4M16) |
|
283 |
|| (fmt && WAVE_FORMAT_4S16) |
|
284 |
#ifndef Q_OS_WINCE |
|
285 |
|| (fmt && WAVE_FORMAT_48M16) |
|
286 |
|| (fmt && WAVE_FORMAT_48S16) |
|
287 |
|| (fmt && WAVE_FORMAT_96M16) |
|
288 |
|| (fmt && WAVE_FORMAT_96S16) |
|
289 |
#endif |
|
290 |
) { |
|
291 |
sizez.append(16); |
|
292 |
} |
|
293 |
if((fmt && WAVE_FORMAT_1M08) |
|
294 |
|| (fmt && WAVE_FORMAT_1S08) |
|
295 |
|| (fmt && WAVE_FORMAT_1M16) |
|
296 |
|| (fmt && WAVE_FORMAT_1S16)) { |
|
297 |
freqz.append(11025); |
|
298 |
} |
|
299 |
if((fmt && WAVE_FORMAT_2M08) |
|
300 |
|| (fmt && WAVE_FORMAT_2S08) |
|
301 |
|| (fmt && WAVE_FORMAT_2M16) |
|
302 |
|| (fmt && WAVE_FORMAT_2S16)) { |
|
303 |
freqz.append(22050); |
|
304 |
} |
|
305 |
if((fmt && WAVE_FORMAT_4M08) |
|
306 |
|| (fmt && WAVE_FORMAT_4S08) |
|
307 |
|| (fmt && WAVE_FORMAT_4M16) |
|
308 |
|| (fmt && WAVE_FORMAT_4S16)) { |
|
309 |
freqz.append(44100); |
|
310 |
} |
|
311 |
#ifndef Q_OS_WINCE |
|
312 |
if((fmt && WAVE_FORMAT_48M08) |
|
313 |
|| (fmt && WAVE_FORMAT_48S08) |
|
314 |
|| (fmt && WAVE_FORMAT_48M16) |
|
315 |
|| (fmt && WAVE_FORMAT_48S16)) { |
|
316 |
freqz.append(48000); |
|
317 |
} |
|
318 |
if((fmt && WAVE_FORMAT_96M08) |
|
319 |
|| (fmt && WAVE_FORMAT_96S08) |
|
320 |
|| (fmt && WAVE_FORMAT_96M16) |
|
321 |
|| (fmt && WAVE_FORMAT_96S16)) { |
|
322 |
freqz.append(96000); |
|
323 |
} |
|
324 |
#endif |
|
325 |
channelz.append(1); |
|
326 |
channelz.append(2); |
|
327 |
||
328 |
byteOrderz.append(QAudioFormat::LittleEndian); |
|
329 |
||
330 |
typez.append(QAudioFormat::SignedInt); |
|
331 |
typez.append(QAudioFormat::UnSignedInt); |
|
332 |
||
333 |
codecz.append(QLatin1String("audio/pcm")); |
|
334 |
} |
|
335 |
} |
|
336 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
337 |
QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode) |
0 | 338 |
{ |
339 |
Q_UNUSED(mode) |
|
340 |
||
341 |
QList<QByteArray> devices; |
|
342 |
||
343 |
if(mode == QAudio::AudioOutput) { |
|
344 |
WAVEOUTCAPS woc; |
|
345 |
unsigned long iNumDevs,i; |
|
346 |
iNumDevs = waveOutGetNumDevs(); |
|
347 |
for(i=0;i<iNumDevs;i++) { |
|
348 |
if(waveOutGetDevCaps(i, &woc, sizeof(WAVEOUTCAPS)) |
|
349 |
== MMSYSERR_NOERROR) { |
|
350 |
devices.append(QString::fromUtf16((const unsigned short*)woc.szPname).toLocal8Bit().constData()); |
|
351 |
} |
|
352 |
} |
|
353 |
} else { |
|
354 |
WAVEINCAPS woc; |
|
355 |
unsigned long iNumDevs,i; |
|
356 |
iNumDevs = waveInGetNumDevs(); |
|
357 |
for(i=0;i<iNumDevs;i++) { |
|
358 |
if(waveInGetDevCaps(i, &woc, sizeof(WAVEINCAPS)) |
|
359 |
== MMSYSERR_NOERROR) { |
|
360 |
devices.append(QString::fromUtf16((const unsigned short*)woc.szPname).toLocal8Bit().constData()); |
|
361 |
} |
|
362 |
} |
|
363 |
||
364 |
} |
|
365 |
if(devices.count() > 0) |
|
366 |
devices.append("default"); |
|
367 |
||
368 |
return devices; |
|
369 |
} |
|
370 |
||
371 |
QByteArray QAudioDeviceInfoInternal::defaultOutputDevice() |
|
372 |
{ |
|
373 |
return QByteArray("default"); |
|
374 |
} |
|
375 |
||
376 |
QByteArray QAudioDeviceInfoInternal::defaultInputDevice() |
|
377 |
{ |
|
378 |
return QByteArray("default"); |
|
379 |
} |
|
380 |
||
381 |
QT_END_NAMESPACE |