Qt 4.8
qaudiodeviceinfo.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 #include "qaudiodevicefactory_p.h"
43 #include <QtMultimedia/qaudioengine.h>
44 #include <QtMultimedia/qaudiodeviceinfo.h>
45 
46 #include <QtCore/qmap.h>
47 
49 
51 {
52 public:
55  realm(r), handle(h), mode(m)
56  {
58  }
59 
61  QSharedData(other),
62  realm(other.realm), handle(other.handle), mode(other.mode)
63  {
65  }
66 
68  {
69  delete info;
70 
71  realm = other.realm;
72  handle = other.handle;
73  mode = other.mode;
75  return *this;
76  }
77 
79  {
80  delete info;
81  }
82 
87 };
88 
89 
153 {
154 }
155 
161  d(other.d)
162 {
163 }
164 
170 {
171 }
172 
178 {
179  d = other.d;
180  return *this;
181 }
182 
188 {
189  return d->info == 0;
190 }
191 
203 {
204  return isNull() ? QString() : d->info->deviceName();
205 }
206 
212 {
213  return isNull() ? false : d->info->isFormatSupported(settings);
214 }
215 
231 {
232  return isNull() ? QAudioFormat() : d->info->preferredFormat();
233 }
234 
244 {
245  if (isFormatSupported(settings))
246  return settings;
247 
248  QAudioFormat nearest = settings;
249 
250  nearest.setCodec(QLatin1String("audio/pcm"));
251 
252  if (nearest.sampleType() == QAudioFormat::Unknown) {
253  QAudioFormat preferred = preferredFormat();
254  nearest.setSampleType(preferred.sampleType());
255  }
256 
257  QMap<int,int> testFrequencies;
258  QList<int> frequenciesAvailable = supportedFrequencies();
259  QMap<int,int> testSampleSizes;
260  QList<int> sampleSizesAvailable = supportedSampleSizes();
261 
262  // Get sorted sampleSizes (equal to and ascending values only)
263  if (sampleSizesAvailable.contains(settings.sampleSize()))
264  testSampleSizes.insert(0,settings.sampleSize());
265  sampleSizesAvailable.removeAll(settings.sampleSize());
266  foreach (int size, sampleSizesAvailable) {
267  int larger = (size > settings.sampleSize()) ? size : settings.sampleSize();
268  int smaller = (size > settings.sampleSize()) ? settings.sampleSize() : size;
269  if (size >= settings.sampleSize()) {
270  int diff = larger - smaller;
271  testSampleSizes.insert(diff, size);
272  }
273  }
274 
275  // Get sorted frequencies (equal to and ascending values only)
276  if (frequenciesAvailable.contains(settings.frequency()))
277  testFrequencies.insert(0,settings.frequency());
278  frequenciesAvailable.removeAll(settings.frequency());
279  foreach (int frequency, frequenciesAvailable) {
280  int larger = (frequency > settings.frequency()) ? frequency : settings.frequency();
281  int smaller = (frequency > settings.frequency()) ? settings.frequency() : frequency;
282  if (frequency >= settings.frequency()) {
283  int diff = larger - smaller;
284  testFrequencies.insert(diff, frequency);
285  }
286  }
287 
288  // Try to find nearest
289  // Check ascending frequencies, ascending sampleSizes
290  QMapIterator<int, int> sz(testSampleSizes);
291  while (sz.hasNext()) {
292  sz.next();
293  nearest.setSampleSize(sz.value());
294  QMapIterator<int, int> i(testFrequencies);
295  while (i.hasNext()) {
296  i.next();
297  nearest.setFrequency(i.value());
298  if (isFormatSupported(nearest))
299  return nearest;
300  }
301  }
302 
303  //Fallback
304  return preferredFormat();
305 }
306 
320 {
321  return isNull() ? QStringList() : d->info->codecList();
322 }
323 
331 {
332  return supportedFrequencies();
333 }
334 
345 {
346  return isNull() ? QList<int>() : d->info->frequencyList();
347 }
348 
356 {
357  return supportedChannels();
358 }
359 
370 {
371  return isNull() ? QList<int>() : d->info->channelsList();
372 }
373 
379 {
380  return isNull() ? QList<int>() : d->info->sampleSizeList();
381 }
382 
388 {
390 }
391 
397 {
399 }
400 
407 {
409 }
410 
417 {
419 }
420 
426 {
428 }
429 
430 
436  d(new QAudioDeviceInfoPrivate(realm, handle, mode))
437 {
438 }
439 
445 {
446  return d->realm;
447 }
448 
454 {
455  return d->handle;
456 }
457 
458 
464 {
465  return d->mode;
466 }
467 
469 
double d
Definition: qnumeric_p.h:62
static QList< QAudioDeviceInfo > availableDevices(QAudio::Mode mode)
Returns a list of audio devices that support mode.
QByteArray handle() const
int frequency() const
Use sampleRate() instead.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QList< QAudioFormat::SampleType > supportedSampleTypes() const
Returns a list of supported sample types.
QList< int > supportedSampleSizes() const
Returns a list of supported sample sizes.
static QList< QAudioDeviceInfo > availableDevices(QAudio::Mode mode)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QAudioDeviceInfo()
Constructs an empty QAudioDeviceInfo object.
QAbstractAudioDeviceInfo * info
QString realm() const
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
virtual QList< int > sampleSizeList()=0
Returns the list of currently available sample sizes.
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.
QList< int > supportedChannelCounts() const
Returns a list of supported channel counts.
virtual bool isFormatSupported(const QAudioFormat &format) const =0
Returns true if format is available from audio device.
QList< int > supportedSampleRates() const
Returns a list of supported sample rates.
QSharedDataPointer< QAudioDeviceInfoPrivate > d
QList< int > supportedChannels() const
Use supportedChannelCount() instead.
QAudioFormat::SampleType sampleType() const
Returns the current SampleType value.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
static QAudioDeviceInfo defaultOutputDevice()
Returns the name of the default output audio device.
bool isFormatSupported(const QAudioFormat &format) const
Returns true if settings are supported by the audio device of this QAudioDeviceInfo.
~QAudioDeviceInfo()
Destroy this audio device info.
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static Bigint * diff(Bigint *a, Bigint *b)
QList< QAudioFormat::Endian > supportedByteOrders() const
Returns a list of supported byte orders.
The QAudioDeviceInfo class provides an interface to query audio devices and their functionality...
virtual QString deviceName() const =0
Returns the audio device name.
virtual QStringList codecList()=0
Returns the list of currently available codecs.
QAudio::Mode mode() const
Mode
Definition: qaudio.h:60
virtual QAudioFormat preferredFormat() const =0
Returns the nearest settings.
QList< int > supportedFrequencies() const
Use supportedSampleRates() instead.
QAudioFormat nearestFormat(const QAudioFormat &format) const
Returns closest QAudioFormat to settings that system audio supports.
The QSharedData class is a base class for shared data objects.
Definition: qshareddata.h:56
QString deviceName() const
Returns human readable name of audio device.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:559
QAudioDeviceInfo & operator=(const QAudioDeviceInfo &other)
Sets the QAudioDeviceInfo object to be equal to other.
static QAudioDeviceInfo defaultInputDevice()
virtual QList< int > channelsList()=0
Returns the list of currently available channels.
QAudioDeviceInfoPrivate & operator=(const QAudioDeviceInfoPrivate &other)
void setFrequency(int frequency)
Use setSampleRate() instead.
The QAbstractAudioDeviceInfo class provides access for QAudioDeviceInfo to access the audio device pr...
Definition: qaudioengine.h:56
static QAudioDeviceInfo defaultOutputDevice()
bool isNull() const
Returns whether this QAudioDeviceInfo object holds a device definition.
The QAudioFormat class stores audio parameter information.
Definition: qaudioformat.h:60
QAudioDeviceInfoPrivate(const QAudioDeviceInfoPrivate &other)
QAudioFormat preferredFormat() const
Returns QAudioFormat of default settings.
static QAbstractAudioDeviceInfo * audioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode)
void setSampleSize(int sampleSize)
Sets the sample size to the sampleSize specified.
virtual QList< QAudioFormat::SampleType > sampleTypeList()=0
Returns the list of currently available sample types.
void setCodec(const QString &codec)
Sets the codec to codec.
QAudioDeviceInfoPrivate(const QString &r, const QByteArray &h, QAudio::Mode m)
QStringList supportedCodecs() const
Returns a list of supported codecs.
virtual QList< int > frequencyList()=0
Returns the list of currently available frequencies.
static QAudioDeviceInfo defaultInputDevice()
Returns the name of the default input audio device.
virtual QList< QAudioFormat::Endian > byteOrderList()=0
Returns the list of currently available byte orders.
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770