Qt 4.8
Public Functions | Static Public Functions | Public Variables | Private Functions | Properties | List of all members
QAudioDeviceInfoInternal Class Reference

#include <qaudiodeviceinfo_alsa_p.h>

Inheritance diagram for QAudioDeviceInfoInternal:
QAbstractAudioDeviceInfo QAbstractAudioDeviceInfo QAbstractAudioDeviceInfo QObject QObject QObject

Public Functions

QList< QAudioFormat::EndianbyteOrderList ()
 Returns the list of currently available byte orders. More...
 
QList< QAudioFormat::EndianbyteOrderList ()
 Returns the list of currently available byte orders. More...
 
QList< QAudioFormat::EndianbyteOrderList ()
 Returns the list of currently available byte orders. More...
 
QList< int > channelsList ()
 Returns the list of currently available channels. More...
 
QList< int > channelsList ()
 Returns the list of currently available channels. More...
 
QList< int > channelsList ()
 Returns the list of currently available channels. More...
 
void close ()
 
QStringList codecList ()
 Returns the list of currently available codecs. More...
 
QStringList codecList ()
 Returns the list of currently available codecs. More...
 
QStringList codecList ()
 Returns the list of currently available codecs. More...
 
QString deviceName () const
 Returns the audio device name. More...
 
QString deviceName () const
 Returns the audio device name. More...
 
QString deviceName () const
 Returns the audio device name. More...
 
QList< int > frequencyList ()
 Returns the list of currently available frequencies. More...
 
QList< int > frequencyList ()
 Returns the list of currently available frequencies. More...
 
QList< int > frequencyList ()
 Returns the list of currently available frequencies. More...
 
bool isFormatSupported (const QAudioFormat &format) const
 Returns true if format is available from audio device. More...
 
bool isFormatSupported (const QAudioFormat &format) const
 Returns true if format is available from audio device. More...
 
bool isFormatSupported (const QAudioFormat &format) const
 Returns true if format is available from audio device. More...
 
QAudioFormat nearestFormat (const QAudioFormat &format) const
 Returns the nearest settings format. More...
 
QAudioFormat nearestFormat (const QAudioFormat &format) const
 Returns the nearest settings format. More...
 
QAudioFormat nearestFormat (const QAudioFormat &format) const
 Returns the nearest settings format. More...
 
bool open ()
 
QAudioFormat preferredFormat () const
 Returns the nearest settings. More...
 
QAudioFormat preferredFormat () const
 Returns the nearest settings. More...
 
QAudioFormat preferredFormat () const
 Returns the nearest settings. More...
 
 QAudioDeviceInfoInternal (QByteArray const &handle, QAudio::Mode mode)
 
 QAudioDeviceInfoInternal (QByteArray dev, QAudio::Mode mode)
 
 QAudioDeviceInfoInternal (QByteArray dev, QAudio::Mode mode)
 
QList< int > sampleSizeList ()
 Returns the list of currently available sample sizes. More...
 
QList< int > sampleSizeList ()
 Returns the list of currently available sample sizes. More...
 
QList< int > sampleSizeList ()
 Returns the list of currently available sample sizes. More...
 
QList< QAudioFormat::SampleTypesampleTypeList ()
 Returns the list of currently available sample types. More...
 
QList< QAudioFormat::SampleTypesampleTypeList ()
 Returns the list of currently available sample types. More...
 
QList< QAudioFormat::SampleTypesampleTypeList ()
 Returns the list of currently available sample types. More...
 
bool testSettings (const QAudioFormat &format) const
 
bool testSettings (const QAudioFormat &format) const
 
void updateLists ()
 
void updateLists ()
 
 ~QAudioDeviceInfoInternal ()
 
 ~QAudioDeviceInfoInternal ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Static Public Functions

static QList< QByteArrayavailableDevices (QAudio::Mode mode)
 
static QList< QByteArrayavailableDevices (QAudio::Mode)
 
static QList< QByteArrayavailableDevices (QAudio::Mode)
 
static QByteArray defaultInputDevice ()
 
static QByteArray defaultInputDevice ()
 
static QByteArray defaultInputDevice ()
 
static QByteArray defaultOutputDevice ()
 
static QByteArray defaultOutputDevice ()
 
static QByteArray defaultOutputDevice ()
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 

Public Variables

AudioDeviceID deviceId
 
QString name
 

Private Functions

void close ()
 
bool open ()
 

Properties

QList< QAudioFormat::EndianbyteOrderz
 
QList< int > channelz
 
QStringList codecz
 
QString device
 
QList< int > freqz
 
snd_pcm_t * handle
 
QAudio::Mode mode
 
QAudioFormat nearest
 
snd_pcm_hw_params_t * params
 
QList< int > sizez
 
QList< QAudioFormat::SampleTypetypez
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 74 of file qaudiodeviceinfo_alsa_p.h.

Constructors and Destructors

◆ QAudioDeviceInfoInternal() [1/3]

QAudioDeviceInfoInternal::QAudioDeviceInfoInternal ( QByteArray  dev,
QAudio::Mode  mode 
)

Definition at line 59 of file qaudiodeviceinfo_alsa_p.cpp.

60 {
61  handle = 0;
62 
63  device = QLatin1String(dev);
64  this->mode = mode;
65 
66 #if (SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
67  checkSurround();
68 #endif
69 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

◆ ~QAudioDeviceInfoInternal() [1/2]

QAudioDeviceInfoInternal::~QAudioDeviceInfoInternal ( )

Definition at line 71 of file qaudiodeviceinfo_alsa_p.cpp.

72 {
73  close();
74 }

◆ QAudioDeviceInfoInternal() [2/3]

QAudioDeviceInfoInternal::QAudioDeviceInfoInternal ( QByteArray const &  handle,
QAudio::Mode  mode 
)

Definition at line 69 of file qaudiodeviceinfo_mac_p.cpp.

70 {
71  QDataStream ds(handle);
72  quint32 did, tm;
73 
74  ds >> did >> tm >> name;
75  deviceId = AudioDeviceID(did);
76  mode = QAudio::Mode(tm);
77 }
Mode
Definition: qaudio.h:60
unsigned int quint32
Definition: qglobal.h:938
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71

◆ QAudioDeviceInfoInternal() [3/3]

QAudioDeviceInfoInternal::QAudioDeviceInfoInternal ( QByteArray  dev,
QAudio::Mode  mode 
)

◆ ~QAudioDeviceInfoInternal() [2/2]

QAudioDeviceInfoInternal::~QAudioDeviceInfoInternal ( )

Functions

◆ availableDevices() [1/3]

static QList<QByteArray> QAudioDeviceInfoInternal::availableDevices ( QAudio::Mode  mode)
static

◆ availableDevices() [2/3]

QList< QByteArray > QAudioDeviceInfoInternal::availableDevices ( QAudio::Mode  mode)
static

Definition at line 416 of file qaudiodeviceinfo_alsa_p.cpp.

Referenced by QAudioDeviceFactory::availableDevices(), defaultInputDevice(), defaultOutputDevice(), get_device_info(), open(), QAudioInputPrivate::open(), QAudioOutputPrivate::open(), and testSettings().

417 {
418  QList<QByteArray> allDevices;
419  QList<QByteArray> devices;
421 
422 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
423  // Create a list of all current audio devices that support mode
424  void **hints, **n;
425  char *name, *descr, *io;
426 
427  if(snd_device_name_hint(-1, "pcm", &hints) < 0) {
428  qWarning() << "no alsa devices available";
429  return devices;
430  }
431  n = hints;
432 
433  if(mode == QAudio::AudioInput) {
434  filter = "Input";
435  } else {
436  filter = "Output";
437  }
438 
439  while (*n != NULL) {
440  name = snd_device_name_get_hint(*n, "NAME");
441  if (name != 0 && qstrcmp(name, "null") != 0) {
442  descr = snd_device_name_get_hint(*n, "DESC");
443  io = snd_device_name_get_hint(*n, "IOID");
444 
445  if ((descr != NULL) && ((io == NULL) || (io == filter))) {
447  QString deviceDescription = QLatin1String(descr);
448  allDevices.append(deviceName.toLocal8Bit().constData());
449  if (deviceDescription.contains(QLatin1String("Default Audio Device")))
450  devices.append(deviceName.toLocal8Bit().constData());
451  }
452 
453  free(name);
454  if (descr != NULL)
455  free(descr);
456  if (io != NULL)
457  free(io);
458  }
459  ++n;
460  }
461  snd_device_name_free_hint(hints);
462 
463  if(devices.size() > 0) {
464  devices.append("default");
465  }
466 #else
467  int idx = 0;
468  char* name;
469 
470  while(snd_card_get_name(idx,&name) == 0) {
471  devices.append(name);
472  idx++;
473  }
474  if (idx > 0)
475  devices.append("default");
476 #endif
477  if (devices.size() == 0 && allDevices.size() > 0)
478  return allDevices;
479 
480  return devices;
481 }
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QString deviceName() const
Returns the audio device name.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
Q_CORE_EXPORT void qWarning(const char *,...)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336

◆ availableDevices() [3/3]

static QList<QByteArray> QAudioDeviceInfoInternal::availableDevices ( QAudio::Mode  )
static

◆ byteOrderList() [1/3]

QList<QAudioFormat::Endian> QAudioDeviceInfoInternal::byteOrderList ( )
virtual

Returns the list of currently available byte orders.

Implements QAbstractAudioDeviceInfo.

◆ byteOrderList() [2/3]

QList< QAudioFormat::Endian > QAudioDeviceInfoInternal::byteOrderList ( )
virtual

Returns the list of currently available byte orders.

Implements QAbstractAudioDeviceInfo.

Definition at line 143 of file qaudiodeviceinfo_alsa_p.cpp.

Referenced by QAudioDeviceInfoInternal().

144 {
145  updateLists();
146  return byteOrderz;
147 }
QList< QAudioFormat::Endian > byteOrderz

◆ byteOrderList() [3/3]

QList<QAudioFormat::Endian> QAudioDeviceInfoInternal::byteOrderList ( )
virtual

Returns the list of currently available byte orders.

Implements QAbstractAudioDeviceInfo.

◆ channelsList() [1/3]

QList<int> QAudioDeviceInfoInternal::channelsList ( )
virtual

Returns the list of currently available channels.

Implements QAbstractAudioDeviceInfo.

◆ channelsList() [2/3]

QList< int > QAudioDeviceInfoInternal::channelsList ( )
virtual

Returns the list of currently available channels.

Implements QAbstractAudioDeviceInfo.

Definition at line 131 of file qaudiodeviceinfo_alsa_p.cpp.

Referenced by QAudioDeviceInfoInternal().

132 {
133  updateLists();
134  return channelz;
135 }

◆ channelsList() [3/3]

QList<int> QAudioDeviceInfoInternal::channelsList ( )
virtual

Returns the list of currently available channels.

Implements QAbstractAudioDeviceInfo.

◆ close() [1/2]

void QAudioDeviceInfoInternal::close ( )

◆ close() [2/2]

void QAudioDeviceInfoInternal::close ( )
private

Definition at line 196 of file qaudiodeviceinfo_alsa_p.cpp.

Referenced by updateLists(), and ~QAudioDeviceInfoInternal().

197 {
198  if(handle)
199  snd_pcm_close(handle);
200  handle = 0;
201 }

◆ codecList() [1/3]

QStringList QAudioDeviceInfoInternal::codecList ( )
virtual

Returns the list of currently available codecs.

Implements QAbstractAudioDeviceInfo.

◆ codecList() [2/3]

QStringList QAudioDeviceInfoInternal::codecList ( )
virtual

Returns the list of currently available codecs.

Implements QAbstractAudioDeviceInfo.

Definition at line 119 of file qaudiodeviceinfo_alsa_p.cpp.

Referenced by QAudioDeviceInfoInternal().

120 {
121  updateLists();
122  return codecz;
123 }

◆ codecList() [3/3]

QStringList QAudioDeviceInfoInternal::codecList ( )
virtual

Returns the list of currently available codecs.

Implements QAbstractAudioDeviceInfo.

◆ defaultInputDevice() [1/3]

static QByteArray QAudioDeviceInfoInternal::defaultInputDevice ( )
static

◆ defaultInputDevice() [2/3]

QByteArray QAudioDeviceInfoInternal::defaultInputDevice ( )
static

Definition at line 483 of file qaudiodeviceinfo_alsa_p.cpp.

Referenced by QAudioDeviceFactory::defaultInputDevice(), and get_device_info().

484 {
486  if(devices.size() == 0)
487  return QByteArray();
488 
489  return devices.first();
490 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QList< QByteArray > availableDevices(QAudio::Mode)

◆ defaultInputDevice() [3/3]

static QByteArray QAudioDeviceInfoInternal::defaultInputDevice ( )
static

◆ defaultOutputDevice() [1/3]

static QByteArray QAudioDeviceInfoInternal::defaultOutputDevice ( )
static

◆ defaultOutputDevice() [2/3]

QByteArray QAudioDeviceInfoInternal::defaultOutputDevice ( )
static

Definition at line 492 of file qaudiodeviceinfo_alsa_p.cpp.

Referenced by QAudioDeviceFactory::defaultOutputDevice(), and get_device_info().

493 {
495  if(devices.size() == 0)
496  return QByteArray();
497 
498  return devices.first();
499 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static QList< QByteArray > availableDevices(QAudio::Mode)

◆ defaultOutputDevice() [3/3]

static QByteArray QAudioDeviceInfoInternal::defaultOutputDevice ( )
static

◆ deviceName() [1/3]

QString QAudioDeviceInfoInternal::deviceName ( ) const
virtual

Returns the audio device name.

Implements QAbstractAudioDeviceInfo.

◆ deviceName() [2/3]

QString QAudioDeviceInfoInternal::deviceName ( ) const
virtual

Returns the audio device name.

Implements QAbstractAudioDeviceInfo.

Definition at line 114 of file qaudiodeviceinfo_alsa_p.cpp.

Referenced by availableDevices(), defaultOutputDevice(), and QAudioDeviceInfoInternal().

115 {
116  return device;
117 }

◆ deviceName() [3/3]

QString QAudioDeviceInfoInternal::deviceName ( ) const
virtual

Returns the audio device name.

Implements QAbstractAudioDeviceInfo.

◆ frequencyList() [1/3]

QList<int> QAudioDeviceInfoInternal::frequencyList ( )
virtual

Returns the list of currently available frequencies.

Implements QAbstractAudioDeviceInfo.

◆ frequencyList() [2/3]

QList< int > QAudioDeviceInfoInternal::frequencyList ( )
virtual

Returns the list of currently available frequencies.

Implements QAbstractAudioDeviceInfo.

Definition at line 125 of file qaudiodeviceinfo_alsa_p.cpp.

Referenced by QAudioDeviceInfoInternal().

126 {
127  updateLists();
128  return freqz;
129 }

◆ frequencyList() [3/3]

QList<int> QAudioDeviceInfoInternal::frequencyList ( )
virtual

Returns the list of currently available frequencies.

Implements QAbstractAudioDeviceInfo.

◆ isFormatSupported() [1/3]

bool QAudioDeviceInfoInternal::isFormatSupported ( const QAudioFormat format) const
virtual

Returns true if format is available from audio device.

Implements QAbstractAudioDeviceInfo.

◆ isFormatSupported() [2/3]

bool QAudioDeviceInfoInternal::isFormatSupported ( const QAudioFormat format) const
virtual

Returns true if format is available from audio device.

Implements QAbstractAudioDeviceInfo.

Definition at line 76 of file qaudiodeviceinfo_alsa_p.cpp.

Referenced by QAudioDeviceInfoInternal().

77 {
78  return testSettings(format);
79 }
bool testSettings(const QAudioFormat &format) const

◆ isFormatSupported() [3/3]

bool QAudioDeviceInfoInternal::isFormatSupported ( const QAudioFormat format) const
virtual

Returns true if format is available from audio device.

Implements QAbstractAudioDeviceInfo.

◆ nearestFormat() [1/3]

QAudioFormat QAudioDeviceInfoInternal::nearestFormat ( const QAudioFormat format) const
virtual

Returns the nearest settings format.

Implements QAbstractAudioDeviceInfo.

◆ nearestFormat() [2/3]

QAudioFormat QAudioDeviceInfoInternal::nearestFormat ( const QAudioFormat format) const
virtual

Returns the nearest settings format.

Implements QAbstractAudioDeviceInfo.

Definition at line 106 of file qaudiodeviceinfo_alsa_p.cpp.

Referenced by QAudioDeviceInfoInternal().

107 {
108  if(testSettings(format))
109  return format;
110  else
111  return preferredFormat();
112 }
QAudioFormat preferredFormat() const
Returns the nearest settings.
bool testSettings(const QAudioFormat &format) const

◆ nearestFormat() [3/3]

QAudioFormat QAudioDeviceInfoInternal::nearestFormat ( const QAudioFormat format) const
virtual

Returns the nearest settings format.

Implements QAbstractAudioDeviceInfo.

◆ open() [1/2]

bool QAudioDeviceInfoInternal::open ( )

◆ open() [2/2]

bool QAudioDeviceInfoInternal::open ( )
private

Definition at line 155 of file qaudiodeviceinfo_alsa_p.cpp.

Referenced by updateLists().

156 {
157  int err = 0;
158  QString dev = device;
160 
161  if(dev.compare(QLatin1String("default")) == 0) {
162 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
163  dev = QLatin1String(devices.first().constData());
164 #else
165  dev = QLatin1String("hw:0,0");
166 #endif
167  } else {
168 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
169  dev = device;
170 #else
171  int idx = 0;
172  char *name;
173 
174  QString shortName = device.mid(device.indexOf(QLatin1String("="),0)+1);
175 
176  while(snd_card_get_name(idx,&name) == 0) {
177  if(dev.contains(QLatin1String(name)))
178  break;
179  idx++;
180  }
181  dev = QString(QLatin1String("hw:%1,0")).arg(idx);
182 #endif
183  }
184  if(mode == QAudio::AudioOutput) {
185  err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0);
186  } else {
187  err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_CAPTURE,0);
188  }
189  if(err < 0) {
190  handle = 0;
191  return false;
192  }
193  return true;
194 }
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
int compare(const QString &s) const
Definition: qstring.cpp:5037
static QList< QByteArray > availableDevices(QAudio::Mode)

◆ preferredFormat() [1/3]

QAudioFormat QAudioDeviceInfoInternal::preferredFormat ( ) const
virtual

Returns the nearest settings.

Implements QAbstractAudioDeviceInfo.

◆ preferredFormat() [2/3]

QAudioFormat QAudioDeviceInfoInternal::preferredFormat ( ) const
virtual

Returns the nearest settings.

Implements QAbstractAudioDeviceInfo.

Definition at line 81 of file qaudiodeviceinfo_alsa_p.cpp.

Referenced by nearestFormat(), and QAudioDeviceInfoInternal().

82 {
84  if(mode == QAudio::AudioOutput) {
85  nearest.setFrequency(44100);
86  nearest.setChannels(2);
89  nearest.setSampleSize(16);
90  nearest.setCodec(QLatin1String("audio/pcm"));
91  } else {
92  nearest.setFrequency(8000);
93  nearest.setChannels(1);
95  nearest.setSampleSize(8);
96  nearest.setCodec(QLatin1String("audio/pcm"));
97  if(!testSettings(nearest)) {
98  nearest.setChannels(2);
99  nearest.setSampleSize(16);
101  }
102  }
103  return nearest;
104 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setSampleType(QAudioFormat::SampleType sampleType)
Sets the sampleType to sampleType.
void setChannels(int channels)
Use setChannelCount() instead.
void setFrequency(int frequency)
Use setSampleRate() instead.
The QAudioFormat class stores audio parameter information.
Definition: qaudioformat.h:60
bool testSettings(const QAudioFormat &format) const
void setSampleSize(int sampleSize)
Sets the sample size to the sampleSize specified.
void setCodec(const QString &codec)
Sets the codec to codec.
void setByteOrder(QAudioFormat::Endian byteOrder)
Sets the byteOrder to byteOrder.

◆ preferredFormat() [3/3]

QAudioFormat QAudioDeviceInfoInternal::preferredFormat ( ) const
virtual

Returns the nearest settings.

Implements QAbstractAudioDeviceInfo.

◆ sampleSizeList() [1/3]

QList<int> QAudioDeviceInfoInternal::sampleSizeList ( )
virtual

Returns the list of currently available sample sizes.

Implements QAbstractAudioDeviceInfo.

◆ sampleSizeList() [2/3]

QList< int > QAudioDeviceInfoInternal::sampleSizeList ( )
virtual

Returns the list of currently available sample sizes.

Implements QAbstractAudioDeviceInfo.

Definition at line 137 of file qaudiodeviceinfo_alsa_p.cpp.

Referenced by QAudioDeviceInfoInternal().

138 {
139  updateLists();
140  return sizez;
141 }

◆ sampleSizeList() [3/3]

QList<int> QAudioDeviceInfoInternal::sampleSizeList ( )
virtual

Returns the list of currently available sample sizes.

Implements QAbstractAudioDeviceInfo.

◆ sampleTypeList() [1/3]

QList<QAudioFormat::SampleType> QAudioDeviceInfoInternal::sampleTypeList ( )
virtual

Returns the list of currently available sample types.

Implements QAbstractAudioDeviceInfo.

◆ sampleTypeList() [2/3]

QList< QAudioFormat::SampleType > QAudioDeviceInfoInternal::sampleTypeList ( )
virtual

Returns the list of currently available sample types.

Implements QAbstractAudioDeviceInfo.

Definition at line 149 of file qaudiodeviceinfo_alsa_p.cpp.

Referenced by QAudioDeviceInfoInternal().

150 {
151  updateLists();
152  return typez;
153 }
QList< QAudioFormat::SampleType > typez

◆ sampleTypeList() [3/3]

QList<QAudioFormat::SampleType> QAudioDeviceInfoInternal::sampleTypeList ( )
virtual

Returns the list of currently available sample types.

Implements QAbstractAudioDeviceInfo.

◆ testSettings() [1/2]

bool QAudioDeviceInfoInternal::testSettings ( const QAudioFormat format) const

Definition at line 203 of file qaudiodeviceinfo_alsa_p.cpp.

Referenced by isFormatSupported(), nearestFormat(), and preferredFormat().

204 {
205  // Set nearest to closest settings that do work.
206  // See if what is in settings will work (return value).
207  int err = 0;
208  snd_pcm_t* handle;
209  snd_pcm_hw_params_t *params;
210  QString dev = device;
211 
213 
214  if(dev.compare(QLatin1String("default")) == 0) {
215 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
216  dev = QLatin1String(devices.first().constData());
217 #else
218  dev = QLatin1String("hw:0,0");
219 #endif
220  } else {
221 #if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
222  dev = device;
223 #else
224  int idx = 0;
225  char *name;
226 
227  QString shortName = device.mid(device.indexOf(QLatin1String("="),0)+1);
228 
229  while(snd_card_get_name(idx,&name) == 0) {
230  if(shortName.compare(QLatin1String(name)) == 0)
231  break;
232  idx++;
233  }
234  dev = QString(QLatin1String("hw:%1,0")).arg(idx);
235 #endif
236  }
237  if(mode == QAudio::AudioOutput) {
238  err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0);
239  } else {
240  err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_CAPTURE,0);
241  }
242  if(err < 0) {
243  handle = 0;
244  return false;
245  }
246 
247  bool testChannel = false;
248  bool testCodec = false;
249  bool testFreq = false;
250  bool testType = false;
251  bool testSize = false;
252 
253  int dir = 0;
254 
255  snd_pcm_nonblock( handle, 0 );
256  snd_pcm_hw_params_alloca( &params );
257  snd_pcm_hw_params_any( handle, params );
258 
259  // set the values!
260  snd_pcm_hw_params_set_channels(handle,params,format.channels());
261  snd_pcm_hw_params_set_rate(handle,params,format.frequency(),dir);
262 
263  err = -1;
264 
265  switch(format.sampleSize()) {
266  case 8:
267  if(format.sampleType() == QAudioFormat::SignedInt)
268  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S8);
269  else if(format.sampleType() == QAudioFormat::UnSignedInt)
270  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U8);
271  break;
272  case 16:
273  if(format.sampleType() == QAudioFormat::SignedInt) {
274  if(format.byteOrder() == QAudioFormat::LittleEndian)
275  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_LE);
276  else if(format.byteOrder() == QAudioFormat::BigEndian)
277  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_BE);
278  } else if(format.sampleType() == QAudioFormat::UnSignedInt) {
279  if(format.byteOrder() == QAudioFormat::LittleEndian)
280  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_LE);
281  else if(format.byteOrder() == QAudioFormat::BigEndian)
282  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_BE);
283  }
284  break;
285  case 32:
286  if(format.sampleType() == QAudioFormat::SignedInt) {
287  if(format.byteOrder() == QAudioFormat::LittleEndian)
288  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_LE);
289  else if(format.byteOrder() == QAudioFormat::BigEndian)
290  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_BE);
291  } else if(format.sampleType() == QAudioFormat::UnSignedInt) {
292  if(format.byteOrder() == QAudioFormat::LittleEndian)
293  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_LE);
294  else if(format.byteOrder() == QAudioFormat::BigEndian)
295  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_BE);
296  }
297  }
298 
299  // For now, just accept only audio/pcm codec
300  if(!format.codec().startsWith(QLatin1String("audio/pcm"))) {
301  err=-1;
302  } else
303  testCodec = true;
304 
305  if(err>=0 && format.channels() != -1) {
306  err = snd_pcm_hw_params_test_channels(handle,params,format.channels());
307  if(err>=0)
308  err = snd_pcm_hw_params_set_channels(handle,params,format.channels());
309  if(err>=0)
310  testChannel = true;
311  }
312 
313  if(err>=0 && format.frequency() != -1) {
314  err = snd_pcm_hw_params_test_rate(handle,params,format.frequency(),0);
315  if(err>=0)
316  err = snd_pcm_hw_params_set_rate(handle,params,format.frequency(),dir);
317  if(err>=0)
318  testFreq = true;
319  }
320 
321  if((err>=0 && format.sampleSize() != -1) &&
322  (format.sampleType() != QAudioFormat::Unknown)) {
323  switch(format.sampleSize()) {
324  case 8:
325  if(format.sampleType() == QAudioFormat::SignedInt)
326  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S8);
327  else if(format.sampleType() == QAudioFormat::UnSignedInt)
328  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U8);
329  break;
330  case 16:
331  if(format.sampleType() == QAudioFormat::SignedInt) {
332  if(format.byteOrder() == QAudioFormat::LittleEndian)
333  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_LE);
334  else if(format.byteOrder() == QAudioFormat::BigEndian)
335  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_BE);
336  } else if(format.sampleType() == QAudioFormat::UnSignedInt) {
337  if(format.byteOrder() == QAudioFormat::LittleEndian)
338  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_LE);
339  else if(format.byteOrder() == QAudioFormat::BigEndian)
340  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_BE);
341  }
342  break;
343  case 32:
344  if(format.sampleType() == QAudioFormat::SignedInt) {
345  if(format.byteOrder() == QAudioFormat::LittleEndian)
346  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_LE);
347  else if(format.byteOrder() == QAudioFormat::BigEndian)
348  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_BE);
349  } else if(format.sampleType() == QAudioFormat::UnSignedInt) {
350  if(format.byteOrder() == QAudioFormat::LittleEndian)
351  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_LE);
352  else if(format.byteOrder() == QAudioFormat::BigEndian)
353  err = snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_BE);
354  }
355  }
356  if(err>=0) {
357  testSize = true;
358  testType = true;
359  }
360  }
361  if(err>=0)
362  err = snd_pcm_hw_params(handle, params);
363 
364  if(err == 0) {
365  // settings work
366  // close()
367  if(handle)
368  snd_pcm_close(handle);
369  return true;
370  }
371  if(handle)
372  snd_pcm_close(handle);
373 
374  return false;
375 }
int frequency() const
Use sampleRate() instead.
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
int sampleSize() const
Returns the current sample size value.
QAudioFormat::Endian byteOrder() const
Returns the current byteOrder value.
QAudioFormat::SampleType sampleType() const
Returns the current SampleType value.
QString codec() const
Returns the current codec value.
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
int compare(const QString &s) const
Definition: qstring.cpp:5037
static QList< QByteArray > availableDevices(QAudio::Mode)
int channels() const
Use channelCount() instead.

◆ testSettings() [2/2]

bool QAudioDeviceInfoInternal::testSettings ( const QAudioFormat format) const

◆ updateLists() [1/2]

void QAudioDeviceInfoInternal::updateLists ( )

Definition at line 377 of file qaudiodeviceinfo_alsa_p.cpp.

Referenced by byteOrderList(), channelsList(), codecList(), frequencyList(), sampleSizeList(), and sampleTypeList().

378 {
379  // redo all lists based on current settings
380  freqz.clear();
381  channelz.clear();
382  sizez.clear();
383  byteOrderz.clear();
384  typez.clear();
385  codecz.clear();
386 
387  if(!handle)
388  open();
389 
390  if(!handle)
391  return;
392 
393  for(int i=0; i<(int)MAX_SAMPLE_RATES; i++) {
394  //if(snd_pcm_hw_params_test_rate(handle, params, SAMPLE_RATES[i], dir) == 0)
396  }
397  channelz.append(1);
398  channelz.append(2);
399 #if (SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
400  if (surround40) channelz.append(4);
401  if (surround51) channelz.append(6);
402  if (surround71) channelz.append(8);
403 #endif
404  sizez.append(8);
405  sizez.append(16);
406  sizez.append(32);
412  codecz.append(QLatin1String("audio/pcm"));
413  close();
414 }
const unsigned int MAX_SAMPLE_RATES
const unsigned int SAMPLE_RATES[]
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QList< QAudioFormat::SampleType > typez
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void clear()
Removes all items from the list.
Definition: qlist.h:764
QList< QAudioFormat::Endian > byteOrderz

◆ updateLists() [2/2]

void QAudioDeviceInfoInternal::updateLists ( )

Properties

◆ byteOrderz

QList< QAudioFormat::Endian > QAudioDeviceInfoInternal::byteOrderz
private

Definition at line 114 of file qaudiodeviceinfo_alsa_p.h.

Referenced by byteOrderList(), and updateLists().

◆ channelz

QList< int > QAudioDeviceInfoInternal::channelz
private

Definition at line 112 of file qaudiodeviceinfo_alsa_p.h.

Referenced by channelsList(), and updateLists().

◆ codecz

QStringList QAudioDeviceInfoInternal::codecz
private

Definition at line 115 of file qaudiodeviceinfo_alsa_p.h.

Referenced by codecList(), and updateLists().

◆ device

QString QAudioDeviceInfoInternal::device
private

◆ deviceId

AudioDeviceID QAudioDeviceInfoInternal::deviceId

Definition at line 68 of file qaudiodeviceinfo_mac_p.h.

Referenced by QAudioDeviceInfoInternal().

◆ freqz

QList< int > QAudioDeviceInfoInternal::freqz
private

Definition at line 111 of file qaudiodeviceinfo_alsa_p.h.

Referenced by frequencyList(), and updateLists().

◆ handle

snd_pcm_t* QAudioDeviceInfoInternal::handle
private

◆ mode

QAudio::Mode QAudioDeviceInfoInternal::mode
private

◆ name

QString QAudioDeviceInfoInternal::name

◆ nearest

QAudioFormat QAudioDeviceInfoInternal::nearest
private

Definition at line 110 of file qaudiodeviceinfo_alsa_p.h.

Referenced by preferredFormat().

◆ params

snd_pcm_hw_params_t* QAudioDeviceInfoInternal::params
private

Definition at line 118 of file qaudiodeviceinfo_alsa_p.h.

Referenced by testSettings().

◆ sizez

QList< int > QAudioDeviceInfoInternal::sizez
private

Definition at line 113 of file qaudiodeviceinfo_alsa_p.h.

Referenced by sampleSizeList(), and updateLists().

◆ typez

QList< QAudioFormat::SampleType > QAudioDeviceInfoInternal::typez
private

Definition at line 116 of file qaudiodeviceinfo_alsa_p.h.

Referenced by sampleTypeList(), and updateLists().


The documentation for this class was generated from the following files: