Qt 4.8
qaudiodeviceinfo_win32_p.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtMultimedia module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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>
57 
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 
78 {
80  this->mode = mode;
81 
82  updateLists();
83 }
84 
86 {
87  close();
88 }
89 
91 {
92  return testSettings(format);
93 }
94 
96 {
98  if(mode == QAudio::AudioOutput) {
99  nearest.setFrequency(44100);
100  nearest.setChannelCount(2);
103  nearest.setSampleSize(16);
104  nearest.setCodec(QLatin1String("audio/pcm"));
105  } else {
106  nearest.setFrequency(11025);
107  nearest.setChannelCount(1);
110  nearest.setSampleSize(8);
111  nearest.setCodec(QLatin1String("audio/pcm"));
112  }
113  return nearest;
114 }
115 
117 {
118  if(testSettings(format))
119  return format;
120  else
121  return preferredFormat();
122 }
123 
125 {
126  return device;
127 }
128 
130 {
131  updateLists();
132  return codecz;
133 }
134 
136 {
137  updateLists();
138  return freqz;
139 }
140 
142 {
143  updateLists();
144  return channelz;
145 }
146 
148 {
149  updateLists();
150  return sizez;
151 }
152 
154 {
155  updateLists();
156  return byteOrderz;
157 }
158 
160 {
161  updateLists();
162  return typez;
163 }
164 
165 
167 {
168  return true;
169 }
170 
172 {
173 }
174 
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 
263 {
264  // redo all lists based on current settings
265  bool base = false;
266  bool match = false;
267  DWORD fmt = 0;
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 
393 
396 
397  codecz.append(QLatin1String("audio/pcm"));
398  }
399  if (freqz.count() > 0)
400  freqz.prepend(8000);
401 }
402 
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).toUtf8().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).toUtf8().constData());
427  }
428  }
429 
430  }
431  if(devices.count() > 0)
432  devices.append("default");
433 
434  return devices;
435 }
436 
438 {
439  return QByteArray("default");
440 }
441 
443 {
444  return QByteArray("default");
445 }
446 
static QByteArray defaultOutputDevice()
int frequency() const
Use sampleRate() instead.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define WAVE_FORMAT_48S08
#define WAVE_FORMAT_96S16
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QString deviceName() const
Returns the audio device name.
void setChannelCount(int channelCount)
Sets the channel count to channels.
static bool match(const uchar *found, const char *target, uint len)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
void setSampleType(QAudioFormat::SampleType sampleType)
Sets the sampleType to sampleType.
The QString class provides a Unicode character string.
Definition: qstring.h:83
int sampleSize() const
Returns the current sample size value.
static const uint base
Definition: qurl.cpp:268
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QList< QAudioFormat::SampleType > typez
QAudioFormat::Endian byteOrder() const
Returns the current byteOrder value.
static QByteArray defaultInputDevice()
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QAudioFormat preferredFormat() const
Returns the nearest settings.
QAudioFormat::SampleType sampleType() const
Returns the current SampleType value.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QString codec() const
Returns the current codec value.
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
QList< int > channelsList()
Returns the list of currently available channels.
#define WAVE_FORMAT_96M16
bool isFormatSupported(const QAudioFormat &format) const
Returns true if format is available from audio device.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
void clear()
Removes all items from the list.
Definition: qlist.h:764
#define WAVE_FORMAT_48S16
#define WAVE_FORMAT_48M16
QAudioDeviceInfoInternal(QByteArray dev, QAudio::Mode mode)
Mode
Definition: qaudio.h:60
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QStringList codecList()
Returns the list of currently available codecs.
QList< QAudioFormat::SampleType > sampleTypeList()
Returns the list of currently available sample types.
#define WAVE_FORMAT_96M08
int compare(const QString &s) const
Definition: qstring.cpp:5037
static bool failed
Definition: qtestresult.cpp:60
QAudioFormat nearestFormat(const QAudioFormat &format) const
Returns the nearest settings format.
QList< QAudioFormat::Endian > byteOrderz
QList< QAudioFormat::Endian > byteOrderList()
Returns the list of currently available byte orders.
QList< int > sampleSizeList()
Returns the list of currently available sample sizes.
void setFrequency(int frequency)
Use setSampleRate() instead.
QList< int > frequencyList()
Returns the list of currently available frequencies.
#define WAVE_FORMAT_48M08
The QAudioFormat class stores audio parameter information.
Definition: qaudioformat.h:60
static QList< QByteArray > availableDevices(QAudio::Mode)
bool testSettings(const QAudioFormat &format) const
void setSampleSize(int sampleSize)
Sets the sample size to the sampleSize specified.
#define WAVE_FORMAT_96S08
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
void setCodec(const QString &codec)
Sets the codec to codec.
void setByteOrder(QAudioFormat::Endian byteOrder)
Sets the byteOrder to byteOrder.
int channels() const
Use channelCount() instead.