diff options
author | Artem Dyomin <artem.dyomin@qt.io> | 2023-04-27 12:31:11 +0200 |
---|---|---|
committer | Artem Dyomin <artem.dyomin@qt.io> | 2023-05-16 12:23:06 +0200 |
commit | 44067974d2ba15c323f8146d619f67390d3042b8 (patch) | |
tree | badf3b52e7d45e4be82900e51995d3ae075d9fb6 | |
parent | df46a50615136adeac39223953ab7aed393ebd08 (diff) | |
download | qtmultimedia-44067974d2ba15c323f8146d619f67390d3042b8.tar.gz |
Fix QAudioSink on Windows and make the auto tests pass
Windows tests became working, but on CI they are still
not available since there're no audio devices on Win CI.
- use QPointer for IO device
(a corner case for close() in the destructor)
- fix the method reset(), it should close the sink and
change the state
- There's a bunch of futher improvements to be done,
namely, stop() should be improved for having more
accurate behavior.
Pick-to: 6.5
Change-Id: I575a1d97d6d07564164c8b2de91166315d8f28d7
Reviewed-by: Lars Knoll <lars@knoll.priv.no>
-rw-r--r-- | src/multimedia/windows/qwindowsaudiosink.cpp | 17 | ||||
-rw-r--r-- | src/multimedia/windows/qwindowsaudiosink_p.h | 5 |
2 files changed, 16 insertions, 6 deletions
diff --git a/src/multimedia/windows/qwindowsaudiosink.cpp b/src/multimedia/windows/qwindowsaudiosink.cpp index 30bf054f1..f585b83e2 100644 --- a/src/multimedia/windows/qwindowsaudiosink.cpp +++ b/src/multimedia/windows/qwindowsaudiosink.cpp @@ -203,6 +203,9 @@ QIODevice* QWindowsAudioSink::start() bool QWindowsAudioSink::open() { + if (m_audioClient) + return true; + HRESULT hr = m_device->Activate(__uuidof(IAudioClient), CLSCTX_INPROC_SERVER, nullptr, (void**)m_audioClient.address()); if (FAILED(hr)) { @@ -210,6 +213,8 @@ bool QWindowsAudioSink::open() return false; } + auto resetClient = qScopeGuard([this](){ m_audioClient.reset(); }); + WAVEFORMATEX *pwfx = nullptr; hr = m_audioClient->GetMixFormat(&pwfx); if (FAILED(hr)) { @@ -259,6 +264,8 @@ bool QWindowsAudioSink::open() return false; } + resetClient.dismiss(); + return true; } @@ -373,12 +380,14 @@ void QWindowsAudioSink::setVolume(qreal v) m_volume = qBound(qreal(0), v, qreal(1)); } +void QWindowsAudioSink::stop() { + // TODO: investigate and find a way to drain and stop instead of closing + close(); +} + void QWindowsAudioSink::reset() { - if (m_audioClient) { - m_audioClient->Stop(); - m_audioClient->Reset(); - } + close(); } QT_END_NAMESPACE diff --git a/src/multimedia/windows/qwindowsaudiosink_p.h b/src/multimedia/windows/qwindowsaudiosink_p.h index 95bc05e11..1178d8ad0 100644 --- a/src/multimedia/windows/qwindowsaudiosink_p.h +++ b/src/multimedia/windows/qwindowsaudiosink_p.h @@ -23,6 +23,7 @@ #include <QtCore/qdatetime.h> #include <QtCore/qmutex.h> #include <QtCore/qtimer.h> +#include <QtCore/qpointer.h> #include <QtMultimedia/qaudio.h> #include <QtMultimedia/qaudiodevice.h> @@ -48,7 +49,7 @@ public: QAudioFormat format() const override; QIODevice* start() override; void start(QIODevice* device) override; - void stop() override { close(); } + void stop() override; void reset() override; void suspend() override; void resume() override; @@ -83,7 +84,7 @@ private: qreal m_volume = 1.0; QTimer *m_timer = nullptr; QScopedPointer<QIODevice> m_pushSource; - QIODevice *m_pullSource = nullptr; + QPointer<QIODevice> m_pullSource; QComPtr<IMMDevice> m_device; QComPtr<IAudioClient> m_audioClient; QComPtr<IAudioRenderClient> m_renderClient; |