![]() |
Qt 6.x
The Qt SDK
|
The QAudioDevice class provides an information about audio devices and their functionality. More...
#include <qaudiodevice.h>
Public Types | |
enum | Mode { Null , Input , Output } |
Describes the mode of this device. More... | |
Public Member Functions | |
QAudioDevice () | |
Describes an audio device. | |
QAudioDevice (const QAudioDevice &other) | |
Constructs a copy of other. | |
~QAudioDevice () | |
Destroy this audio device info. | |
QAudioDevice (QAudioDevice &&other) noexcept=default | |
Move constructs from other. | |
void | swap (QAudioDevice &other) noexcept |
Swaps the audio device with the other. | |
QAudioDevice & | operator= (const QAudioDevice &other) |
Sets the QAudioDevice object to be equal to other. | |
bool | operator== (const QAudioDevice &other) const |
Returns true if this QAudioDevice class represents the same audio device as other. | |
bool | operator!= (const QAudioDevice &other) const |
Returns true if this QAudioDevice class represents a different audio device than other. | |
bool | isNull () const |
Returns whether this QAudioDevice object holds a valid device definition. | |
QByteArray | id () const |
QString | description () const |
bool | isDefault () const |
QAudioDevice::Mode | mode () const |
bool | isFormatSupported (const QAudioFormat &format) const |
Returns true if the supplied settings are supported by the audio device described by this QAudioDevice. | |
QAudioFormat | preferredFormat () const |
Returns the default audio format settings for this device. | |
int | minimumSampleRate () const |
Returns the minimum supported sample rate (in Hertz). | |
int | maximumSampleRate () const |
Returns the maximum supported sample rate (in Hertz). | |
int | minimumChannelCount () const |
Returns the minimum number of supported channel counts. | |
int | maximumChannelCount () const |
Returns the maximum number of supported channel counts. | |
QList< QAudioFormat::SampleFormat > | supportedSampleFormats () const |
Returns a list of supported sample types. | |
QAudioFormat::ChannelConfig | channelConfiguration () const |
Returns the channel configuration of the device. | |
const QAudioDevicePrivate * | handle () const |
Properties | |
QByteArray | id |
\qmlproperty string QtMultimedia::audioDevice::id | |
QString | description |
\qmlproperty string QtMultimedia::audioDevice::description | |
bool | isDefault |
\qmlproperty bool QtMultimedia::audioDevice::isDefault | |
Mode | mode |
\qmlproperty enumeration QtMultimedia::audioDevice::mode | |
Friends | |
class | QAudioDevicePrivate |
The QAudioDevice class provides an information about audio devices and their functionality.
\inmodule QtMultimedia
QAudioDevice describes an audio device available in the system, either for input or for playback.
A QAudioDevice is used by Qt to construct classes that communicate with the device – such as QAudioSource, and QAudioSink. It is also used to determine the input or output device to use in a capture session or during media playback.
You can also query each device for the formats it supports. A format in this context is a set consisting of a channel count, sample rate, and sample type. A format is represented by the QAudioFormat class.
The values supported by the device for each of these parameters can be fetched with minimumChannelCount(), maximumChannelCount(), minimumSampleRate(), maximumSampleRate() and supportedSampleFormats(). The combinations supported are dependent on the audio device capabilities. If you need a specific format, you can check if the device supports it with isFormatSupported(). For instance:
The set of available devices can be retrieved from the QMediaDevices class.
For instance:
In this code sample, we loop through all devices that are able to output sound, i.e., play an audio stream in a supported format. For each device we find, we simply print the deviceName().
Definition at line 24 of file qaudiodevice.h.
enum QAudioDevice::Mode |
Describes the mode of this device.
\value Null A null device. \value Input An input device. \value Output An output device.
Enumerator | |
---|---|
Null | |
Input | |
Output |
Definition at line 32 of file qaudiodevice.h.
|
default |
Describes an audio device.
\qmlvaluetype audioDevice \inqmlmodule QtMultimedia \since 6.2
! \instantiates QAudioDevice
The audioDevice value type describes the properties of an audio device that is connected to the system.
The list of audio input or output devices can be queried from the \l{MediaDevices} type. To select a certain audio device for input or output set it as the device on \l{AudioInput} or \l{AudioOutput}.
\qml MediaPlayer { audioOutput: AudioOutput { device: mediaDevices.defaultAudioOutput } } MediaDevices { id: mediaDevices } \endqml
Constructs a null QAudioDevice object.
|
default |
Constructs a copy of other.
|
default |
Destroy this audio device info.
|
defaultnoexcept |
Move constructs from other.
QAudioFormat::ChannelConfig QAudioDevice::channelConfiguration | ( | ) | const |
Returns the channel configuration of the device.
Definition at line 300 of file qaudiodevice.cpp.
References QAudioFormat::ChannelConfigUnknown, QAudioDevicePrivate::channelConfiguration, and isNull().
Referenced by QAudioOutputStream::startOutput(), and QFFmpeg::AudioRenderer::updateOutput().
QString QAudioDevice::description | ( | ) | const |
Definition at line 195 of file qaudiodevice.cpp.
References QAudioDevicePrivate::description, and isNull().
|
inline |
Definition at line 71 of file qaudiodevice.h.
References d.
Referenced by QDarwinAudioSink::QDarwinAudioSink(), QDarwinAudioSource::QDarwinAudioSource(), QWindowsMediaDevices::createAudioSink(), QWindowsMediaDevices::createAudioSource(), QGstreamerAudioInput::setAudioDevice(), and QGstreamerAudioOutput::setAudioDevice().
QByteArray QAudioDevice::id | ( | ) | const |
Definition at line 175 of file qaudiodevice.cpp.
References QAudioDevicePrivate::id, and isNull().
bool QAudioDevice::isDefault | ( | ) | const |
Definition at line 211 of file qaudiodevice.cpp.
References QAudioDevicePrivate::isDefault.
bool QAudioDevice::isFormatSupported | ( | const QAudioFormat & | format | ) | const |
Returns true if the supplied settings are supported by the audio device described by this QAudioDevice.
Definition at line 220 of file qaudiodevice.cpp.
References QListSpecialMethodsBase< T >::contains(), isNull(), QAudioDevicePrivate::maximumChannelCount, QAudioDevicePrivate::maximumSampleRate, QAudioDevicePrivate::minimumChannelCount, QAudioDevicePrivate::minimumSampleRate, settings, and QAudioDevicePrivate::supportedSampleFormats.
Referenced by QDarwinAudioSink::start(), QDarwinAudioSource::start(), QDarwinAudioSink::start(), and QDarwinAudioSource::start().
bool QAudioDevice::isNull | ( | ) | const |
Returns whether this QAudioDevice object holds a valid device definition.
Definition at line 151 of file qaudiodevice.cpp.
Referenced by QDarwinAudioSink::QDarwinAudioSink(), QDarwinAudioSource::QDarwinAudioSource(), channelConfiguration(), description(), id(), isFormatSupported(), maximumChannelCount(), maximumSampleRate(), minimumChannelCount(), minimumSampleRate(), preferredFormat(), QGstreamerAudioInput::setAudioDevice(), and supportedSampleFormats().
int QAudioDevice::maximumChannelCount | ( | ) | const |
Returns the maximum number of supported channel counts.
This is typically 1 for mono sound, or 2 for stereo sound.
Definition at line 284 of file qaudiodevice.cpp.
References isNull(), and QAudioDevicePrivate::maximumChannelCount.
int QAudioDevice::maximumSampleRate | ( | ) | const |
Returns the maximum supported sample rate (in Hertz).
Definition at line 264 of file qaudiodevice.cpp.
References isNull(), and QAudioDevicePrivate::maximumSampleRate.
int QAudioDevice::minimumChannelCount | ( | ) | const |
Returns the minimum number of supported channel counts.
This is typically 1 for mono sound, or 2 for stereo sound.
Definition at line 274 of file qaudiodevice.cpp.
References isNull(), and QAudioDevicePrivate::minimumChannelCount.
int QAudioDevice::minimumSampleRate | ( | ) | const |
Returns the minimum supported sample rate (in Hertz).
Definition at line 256 of file qaudiodevice.cpp.
References isNull(), and QAudioDevicePrivate::minimumSampleRate.
QAudioDevice::Mode QAudioDevice::mode | ( | ) | const |
Definition at line 346 of file qaudiodevice.cpp.
References QAudioDevicePrivate::mode, and Null.
bool QAudioDevice::operator!= | ( | const QAudioDevice & | other | ) | const |
Returns true if this QAudioDevice class represents a different audio device than other.
Definition at line 143 of file qaudiodevice.cpp.
References operator==(), and other().
|
default |
Sets the QAudioDevice object to be equal to other.
Moves other into this QAudioDevice object.
bool QAudioDevice::operator== | ( | const QAudioDevice & | other | ) | const |
Returns true if this QAudioDevice class represents the same audio device as other.
Definition at line 128 of file qaudiodevice.cpp.
References QAudioDevicePrivate::id, QAudioDevicePrivate::isDefault, QAudioDevicePrivate::mode, and other().
Referenced by operator!=().
QAudioFormat QAudioDevice::preferredFormat | ( | ) | const |
Returns the default audio format settings for this device.
These settings are provided by the platform/audio plugin being used.
They are also dependent on the \l {QAudio}Mode being used.
A typical audio system would provide something like: \list
Definition at line 248 of file qaudiodevice.cpp.
References isNull(), and QAudioDevicePrivate::preferredFormat.
Referenced by openSlDebugInfo().
QList< QAudioFormat::SampleFormat > QAudioDevice::supportedSampleFormats | ( | ) | const |
Returns a list of supported sample types.
Definition at line 292 of file qaudiodevice.cpp.
References isNull(), and QAudioDevicePrivate::supportedSampleFormats.
|
inlinenoexcept |
Swaps the audio device with the other.
Definition at line 45 of file qaudiodevice.h.
|
friend |
Definition at line 73 of file qaudiodevice.h.
|
read |
\qmlproperty string QtMultimedia::audioDevice::description
Holds a human readable name of the audio device.
Use this string to present the device to the user.
Returns a human readable name of the audio device.
Use this string to present the device to the user.
Definition at line 82 of file qaudiodevice.h.
Referenced by QGstreamerAudioInput::setAudioDevice().
|
read |
\qmlproperty string QtMultimedia::audioDevice::id
Holds an identifier for the audio device.
Device names vary depending on the platform/audio plugin being used.
They are a unique identifier for the audio device.
Returns an identifier for the audio device.
Device names vary depending on the platform/audio plugin being used.
They are a unique identifier for the audio device.
Definition at line 82 of file qaudiodevice.h.
Referenced by QDarwinAudioSink::QDarwinAudioSink(), QDarwinAudioSource::QDarwinAudioSource(), QQnxAudioSink::QQnxAudioSink(), AVFMediaPlayer::audioOutputChanged(), QWindowsMediaDeviceSession::audioOutputDeviceChanged(), QAlsaMediaDevices::createAudioSink(), QAndroidMediaDevices::createAudioSink(), QPulseAudioMediaDevices::createAudioSink(), QWasmMediaDevices::createAudioSink(), QAlsaMediaDevices::createAudioSource(), QAndroidMediaDevices::createAudioSource(), QPulseAudioMediaDevices::createAudioSource(), QWasmMediaDevices::createAudioSource(), QWindowsMediaDeviceSession::setActive(), QGstreamerAudioInput::setAudioDevice(), QGstreamerAudioOutput::setAudioDevice(), QWasmAudioInput::setAudioDevice(), QWasmAudioOutput::setAudioDevice(), QWindowsMediaDeviceSession::setAudioOutput(), QAndroidCaptureSession::setAudioOutput(), QWasmAudioOutput::setSource(), QAndroidCaptureSession::start(), QAndroidMediaPlayer::updateAudioDevice(), and AVFCameraSession::updateAudioOutput().
|
read |
\qmlproperty bool QtMultimedia::audioDevice::isDefault
Is true if this is the default audio device.
Returns true if this is the default audio device.
Definition at line 82 of file qaudiodevice.h.
|
read |
\qmlproperty enumeration QtMultimedia::audioDevice::mode
Holds whether this device is an input or output device.
The returned value can be one of the following:
\value audioDevice.Null A null device. \value audioDevice.Input input device. \value audioDevice.Output An output device.
Returns whether this device is an input or output device.
Definition at line 82 of file qaudiodevice.h.
Referenced by QAudioInput::QAudioInput(), and QAudioOutput::QAudioOutput().