source: trunk/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 11.3 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
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** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at qt-info@nokia.com.
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
58QT_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
77QAudioDeviceInfoInternal::QAudioDeviceInfoInternal(QByteArray dev, QAudio::Mode mode)
78{
79 device = QLatin1String(dev);
80 this->mode = mode;
81
82 updateLists();
83}
84
85QAudioDeviceInfoInternal::~QAudioDeviceInfoInternal()
86{
87 close();
88}
89
90bool QAudioDeviceInfoInternal::isFormatSupported(const QAudioFormat& format) const
91{
92 return testSettings(format);
93}
94
95QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const
96{
97 QAudioFormat nearest;
98 if(mode == QAudio::AudioOutput) {
99 nearest.setFrequency(44100);
100 nearest.setChannelCount(2);
101 nearest.setByteOrder(QAudioFormat::LittleEndian);
102 nearest.setSampleType(QAudioFormat::SignedInt);
103 nearest.setSampleSize(16);
104 nearest.setCodec(QLatin1String("audio/pcm"));
105 } else {
106 nearest.setFrequency(11025);
107 nearest.setChannelCount(1);
108 nearest.setByteOrder(QAudioFormat::LittleEndian);
109 nearest.setSampleType(QAudioFormat::SignedInt);
110 nearest.setSampleSize(8);
111 nearest.setCodec(QLatin1String("audio/pcm"));
112 }
113 return nearest;
114}
115
116QAudioFormat QAudioDeviceInfoInternal::nearestFormat(const QAudioFormat& format) const
117{
118 if(testSettings(format))
119 return format;
120 else
121 return preferredFormat();
122}
123
124QString QAudioDeviceInfoInternal::deviceName() const
125{
126 return device;
127}
128
129QStringList QAudioDeviceInfoInternal::codecList()
130{
131 updateLists();
132 return codecz;
133}
134
135QList<int> QAudioDeviceInfoInternal::frequencyList()
136{
137 updateLists();
138 return freqz;
139}
140
141QList<int> QAudioDeviceInfoInternal::channelsList()
142{
143 updateLists();
144 return channelz;
145}
146
147QList<int> QAudioDeviceInfoInternal::sampleSizeList()
148{
149 updateLists();
150 return sizez;
151}
152
153QList<QAudioFormat::Endian> QAudioDeviceInfoInternal::byteOrderList()
154{
155 updateLists();
156 return byteOrderz;
157}
158
159QList<QAudioFormat::SampleType> QAudioDeviceInfoInternal::sampleTypeList()
160{
161 updateLists();
162 return typez;
163}
164
165
166bool QAudioDeviceInfoInternal::open()
167{
168 return true;
169}
170
171void QAudioDeviceInfoInternal::close()
172{
173}
174
175bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const
176{
177 // Set nearest to closest settings that do work.
178 // See if what is in settings will work (return value).
179
180 bool failed = false;
181 bool match = false;
182
183 // check codec
184 for( int i = 0; i < codecz.count(); i++) {
185 if (format.codec() == codecz.at(i))
186 match = true;
187 }
188 if (!match) failed = true;
189
190 // check channel
191 match = false;
192 if (!failed) {
193 for( int i = 0; i < channelz.count(); i++) {
194 if (format.channels() == channelz.at(i)) {
195 match = true;
196 break;
197 }
198 }
199 if (!match)
200 failed = true;
201 }
202
203 // check frequency
204 match = false;
205 if (!failed) {
206 for( int i = 0; i < freqz.count(); i++) {
207 if (format.frequency() == freqz.at(i)) {
208 match = true;
209 break;
210 }
211 }
212 if (!match)
213 failed = true;
214 }
215
216 // check sample size
217 match = false;
218 if (!failed) {
219 for( int i = 0; i < sizez.count(); i++) {
220 if (format.sampleSize() == sizez.at(i)) {
221 match = true;
222 break;
223 }
224 }
225 if (!match)
226 failed = true;
227 }
228
229 // check byte order
230 match = false;
231 if (!failed) {
232 for( int i = 0; i < byteOrderz.count(); i++) {
233 if (format.byteOrder() == byteOrderz.at(i)) {
234 match = true;
235 break;
236 }
237 }
238 if (!match)
239 failed = true;
240 }
241
242 // check sample type
243 match = false;
244 if (!failed) {
245 for( int i = 0; i < typez.count(); i++) {
246 if (format.sampleType() == typez.at(i)) {
247 match = true;
248 break;
249 }
250 }
251 if (!match)
252 failed = true;
253 }
254
255 if(!failed) {
256 // settings work
257 return true;
258 }
259 return false;
260}
261
262void QAudioDeviceInfoInternal::updateLists()
263{
264 // redo all lists based on current settings
265 bool base = false;
266 bool match = false;
267 DWORD fmt = NULL;
268 QString tmp;
269
270 if(device.compare(QLatin1String("default")) == 0)
271 base = true;
272
273 if(mode == QAudio::AudioOutput) {
274 WAVEOUTCAPS woc;
275 unsigned long iNumDevs,i;
276 iNumDevs = waveOutGetNumDevs();
277 for(i=0;i<iNumDevs;i++) {
278 if(waveOutGetDevCaps(i, &woc, sizeof(WAVEOUTCAPS))
279 == MMSYSERR_NOERROR) {
280 tmp = QString((const QChar *)woc.szPname);
281 if(tmp.compare(device) == 0) {
282 match = true;
283 fmt = woc.dwFormats;
284 break;
285 }
286 if(base) {
287 match = true;
288 fmt = woc.dwFormats;
289 break;
290 }
291 }
292 }
293 } else {
294 WAVEINCAPS woc;
295 unsigned long iNumDevs,i;
296 iNumDevs = waveInGetNumDevs();
297 for(i=0;i<iNumDevs;i++) {
298 if(waveInGetDevCaps(i, &woc, sizeof(WAVEINCAPS))
299 == MMSYSERR_NOERROR) {
300 tmp = QString((const QChar *)woc.szPname);
301 if(tmp.compare(device) == 0) {
302 match = true;
303 fmt = woc.dwFormats;
304 break;
305 }
306 if(base) {
307 match = true;
308 fmt = woc.dwFormats;
309 break;
310 }
311 }
312 }
313 }
314 sizez.clear();
315 freqz.clear();
316 channelz.clear();
317 byteOrderz.clear();
318 typez.clear();
319 codecz.clear();
320
321 if(match) {
322 if((fmt && WAVE_FORMAT_1M08)
323 || (fmt && WAVE_FORMAT_1S08)
324 || (fmt && WAVE_FORMAT_2M08)
325 || (fmt && WAVE_FORMAT_2S08)
326 || (fmt && WAVE_FORMAT_4M08)
327 || (fmt && WAVE_FORMAT_4S08)
328#ifndef Q_OS_WINCE
329 || (fmt && WAVE_FORMAT_48M08)
330 || (fmt && WAVE_FORMAT_48S08)
331 || (fmt && WAVE_FORMAT_96M08)
332 || (fmt && WAVE_FORMAT_96S08)
333#endif
334 ) {
335 sizez.append(8);
336 }
337 if((fmt && WAVE_FORMAT_1M16)
338 || (fmt && WAVE_FORMAT_1S16)
339 || (fmt && WAVE_FORMAT_2M16)
340 || (fmt && WAVE_FORMAT_2S16)
341 || (fmt && WAVE_FORMAT_4M16)
342 || (fmt && WAVE_FORMAT_4S16)
343#ifndef Q_OS_WINCE
344 || (fmt && WAVE_FORMAT_48M16)
345 || (fmt && WAVE_FORMAT_48S16)
346 || (fmt && WAVE_FORMAT_96M16)
347 || (fmt && WAVE_FORMAT_96S16)
348#endif
349 ) {
350 sizez.append(16);
351 }
352 if((fmt && WAVE_FORMAT_1M08)
353 || (fmt && WAVE_FORMAT_1S08)
354 || (fmt && WAVE_FORMAT_1M16)
355 || (fmt && WAVE_FORMAT_1S16)) {
356 freqz.append(11025);
357 }
358 if((fmt && WAVE_FORMAT_2M08)
359 || (fmt && WAVE_FORMAT_2S08)
360 || (fmt && WAVE_FORMAT_2M16)
361 || (fmt && WAVE_FORMAT_2S16)) {
362 freqz.append(22050);
363 }
364 if((fmt && WAVE_FORMAT_4M08)
365 || (fmt && WAVE_FORMAT_4S08)
366 || (fmt && WAVE_FORMAT_4M16)
367 || (fmt && WAVE_FORMAT_4S16)) {
368 freqz.append(44100);
369 }
370#ifndef Q_OS_WINCE
371 if((fmt && WAVE_FORMAT_48M08)
372 || (fmt && WAVE_FORMAT_48S08)
373 || (fmt && WAVE_FORMAT_48M16)
374 || (fmt && WAVE_FORMAT_48S16)) {
375 freqz.append(48000);
376 }
377 if((fmt && WAVE_FORMAT_96M08)
378 || (fmt && WAVE_FORMAT_96S08)
379 || (fmt && WAVE_FORMAT_96M16)
380 || (fmt && WAVE_FORMAT_96S16)) {
381 freqz.append(96000);
382 }
383#endif
384 channelz.append(1);
385 channelz.append(2);
386 if (mode == QAudio::AudioOutput) {
387 channelz.append(4);
388 channelz.append(6);
389 channelz.append(8);
390 }
391
392 byteOrderz.append(QAudioFormat::LittleEndian);
393
394 typez.append(QAudioFormat::SignedInt);
395 typez.append(QAudioFormat::UnSignedInt);
396
397 codecz.append(QLatin1String("audio/pcm"));
398 }
399 if (freqz.count() > 0)
400 freqz.prepend(8000);
401}
402
403QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
404{
405 Q_UNUSED(mode)
406
407 QList<QByteArray> devices;
408
409 if(mode == QAudio::AudioOutput) {
410 WAVEOUTCAPS woc;
411 unsigned long iNumDevs,i;
412 iNumDevs = waveOutGetNumDevs();
413 for(i=0;i<iNumDevs;i++) {
414 if(waveOutGetDevCaps(i, &woc, sizeof(WAVEOUTCAPS))
415 == MMSYSERR_NOERROR) {
416 devices.append(QString((const QChar *)woc.szPname).toLocal8Bit().constData());
417 }
418 }
419 } else {
420 WAVEINCAPS woc;
421 unsigned long iNumDevs,i;
422 iNumDevs = waveInGetNumDevs();
423 for(i=0;i<iNumDevs;i++) {
424 if(waveInGetDevCaps(i, &woc, sizeof(WAVEINCAPS))
425 == MMSYSERR_NOERROR) {
426 devices.append(QString((const QChar *)woc.szPname).toLocal8Bit().constData());
427 }
428 }
429
430 }
431 if(devices.count() > 0)
432 devices.append("default");
433
434 return devices;
435}
436
437QByteArray QAudioDeviceInfoInternal::defaultOutputDevice()
438{
439 return QByteArray("default");
440}
441
442QByteArray QAudioDeviceInfoInternal::defaultInputDevice()
443{
444 return QByteArray("default");
445}
446
447QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.