summaryrefslogtreecommitdiffstats
path: root/src/multimedia
diff options
context:
space:
mode:
authorPiotr Srebrny <piotr.srebrny@qt.io>2021-09-17 16:44:04 +0200
committerPiotr Srebrny <piotr.srebrny@qt.io>2021-09-18 13:07:39 +0200
commit6b22d5f88d6a10835fb5e92f7302903918b1f508 (patch)
treecc69eeef290f982c47de74c93c40aeb43a1da6c2 /src/multimedia
parent6b4792e63e0dfe6c568f0a79b426f004386ebe96 (diff)
Reset audio device to default when setting null deviceHEADdev
Interpret a null device as an invalid audio device. When setting null device on QAudioInput/Output reset the device to default system audio input/output. Pick-to: 6.2 Change-Id: I22d75802ecfaa563b1cc55f03d68b5ca979f066a Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/multimedia')
-rw-r--r--src/multimedia/audio/qaudioinput.cpp32
-rw-r--r--src/multimedia/audio/qaudiooutput.cpp33
2 files changed, 39 insertions, 26 deletions
diff --git a/src/multimedia/audio/qaudioinput.cpp b/src/multimedia/audio/qaudioinput.cpp
index 431e2a871..882f64b44 100644
--- a/src/multimedia/audio/qaudioinput.cpp
+++ b/src/multimedia/audio/qaudioinput.cpp
@@ -82,12 +82,11 @@
\property QAudioInput::device
\brief The audio device connected to this input.
- The device property represents the audio device connected to this input. A
- default constructed QAudioInput object will be connected to the system's
- default audio input at construction time.
-
- This property can be used to select any other input device listed by
- QMediaDevices::audioInputs().
+ The device property represents the audio device connected to this input.
+ This property can be used to select an input device from the
+ QMediaDevices::audioInputs() list.
+ You can select the system default audio input by setting this property to
+ a default constructed QAudioDevice object.
*/
QAudioInput::QAudioInput(QObject *parent)
@@ -98,9 +97,7 @@ QAudioInput::QAudioInput(const QAudioDevice &device, QObject *parent)
: QObject(parent),
d(QPlatformMediaIntegration::instance()->createAudioInput(this))
{
- d->device = device;
- if (!d->device.isNull() && d->device.mode() != QAudioDevice::Input)
- d->device = QMediaDevices::defaultAudioInput();
+ d->device = device.mode() == QAudioDevice::Input ? device : QMediaDevices::defaultAudioInput();
d->setAudioDevice(d->device);
}
@@ -114,12 +111,23 @@ QAudioDevice QAudioInput::device() const
return d->device;
}
+/*!
+ Connects the audio input to the physical audio device described by
+ \a device. Using a default constructed QAudioDevice object as \a device
+ will connect the audio input to the system default audio input device.
+*/
+
void QAudioInput::setDevice(const QAudioDevice &device)
{
- if (device.mode() == QAudioDevice::Output)
+ auto dev = device;
+ if (dev.isNull())
+ dev = QMediaDevices::defaultAudioInput();
+ if (dev.mode() != QAudioDevice::Input)
+ return;
+ if (d->device == dev)
return;
- d->device = device;
- d->setAudioDevice(device);
+ d->device = dev;
+ d->setAudioDevice(dev);
emit deviceChanged();
}
diff --git a/src/multimedia/audio/qaudiooutput.cpp b/src/multimedia/audio/qaudiooutput.cpp
index 5f49e8f26..69cb7056f 100644
--- a/src/multimedia/audio/qaudiooutput.cpp
+++ b/src/multimedia/audio/qaudiooutput.cpp
@@ -85,13 +85,11 @@
\property QAudioOutput::device
\brief The audio device connected to this output.
- The device property represents the audio device connected to this output.
- A default constructed
- QAudioOutput object will be connected to the systems default audio output at
- construction time.
-
- This property can be used to select any other output device listed by
- QMediaDevices::audioOutputs().
+ The device property represents the audio device this output is connected to.
+ This property can be used to select an output device from the
+ QMediaDevices::audioOutputs() list.
+ You can select the system default audio output by setting this property to
+ a default constructed QAudioDevice object.
*/
QAudioOutput::QAudioOutput(QObject *parent)
@@ -102,9 +100,7 @@ QAudioOutput::QAudioOutput(const QAudioDevice &device, QObject *parent)
: QObject(parent),
d(QPlatformMediaIntegration::instance()->createAudioOutput(this))
{
- d->device = device;
- if (!d->device.isNull() && d->device.mode() != QAudioDevice::Output)
- d->device = QMediaDevices::defaultAudioOutput();
+ d->device = device.mode() == QAudioDevice::Output ? device : QMediaDevices::defaultAudioOutput();
d->setAudioDevice(d->device);
}
@@ -118,14 +114,23 @@ QAudioDevice QAudioOutput::device() const
return d->device;
}
+/*!
+ Connects the audio output to the physical audio device described by
+ \a device. Using a default constructed QAudioDevice object as \a device
+ will connect the audio output to the system default audio output device.
+*/
+
void QAudioOutput::setDevice(const QAudioDevice &device)
{
- if (!device.isNull() && device.mode() != QAudioDevice::Output)
+ auto dev = device;
+ if (dev.isNull())
+ dev = QMediaDevices::defaultAudioOutput();
+ if (dev.mode() != QAudioDevice::Output)
return;
- if (d->device == device)
+ if (d->device == dev)
return;
- d->device = device;
- d->setAudioDevice(device);
+ d->device = dev;
+ d->setAudioDevice(dev);
emit deviceChanged();
}