summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Dyomin <artem.dyomin@qt.io>2023-09-12 11:12:38 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-09-13 07:32:27 +0000
commitf0cb91bf09bf8de45e342157453101ddb2a07148 (patch)
tree47363a392a8e189e0c4b279cf8f1b4b560421c31
parent78e84f647a2852c9b51a7c7944f2c6ac4ab63602 (diff)
Rename StateChangeGuard -> Notifier
The patch is a part of QAudioStateMachine prettification. QAudioStateMachine::Notifier is going to do only signal notifications. Change-Id: Ic76d1af6ec5be704a3c10597c2ac4240841ce4a4 Reviewed-by: Artem Dyomin <artem.dyomin@qt.io> (cherry picked from commit 775497cbe8caf8c1da16000d7198bd81533129ae) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 55517575ec573a87d91254fba1de54c7cb69e0b9)
-rw-r--r--src/multimedia/audio/qaudiostatemachine.cpp20
-rw-r--r--src/multimedia/audio/qaudiostatemachine_p.h43
-rw-r--r--src/multimedia/darwin/qdarwinaudiosink.mm4
-rw-r--r--src/multimedia/pulseaudio/qpulseaudiosink.cpp22
-rw-r--r--tests/auto/unit/multimedia/qaudiostatemachine/tst_qaudiostatemachine.cpp28
5 files changed, 57 insertions, 60 deletions
diff --git a/src/multimedia/audio/qaudiostatemachine.cpp b/src/multimedia/audio/qaudiostatemachine.cpp
index 5a6de2673..8f501fc11 100644
--- a/src/multimedia/audio/qaudiostatemachine.cpp
+++ b/src/multimedia/audio/qaudiostatemachine.cpp
@@ -8,7 +8,7 @@
QT_BEGIN_NAMESPACE
-using Guard = QAudioStateMachine::StateChangeGuard;
+using Notifier = QAudioStateMachine::Notifier;
using RawState = QAudioStateMachine::RawState;
namespace {
@@ -104,8 +104,8 @@ QAudio::Error QAudioStateMachine::error() const
return m_error;
}
-Guard QAudioStateMachine::changeState(std::pair<RawState, uint32_t> prevStatesSet,
- RawState newState, QAudio::Error error, bool shouldDrain)
+Notifier QAudioStateMachine::changeState(std::pair<RawState, uint32_t> prevStatesSet,
+ RawState newState, QAudio::Error error, bool shouldDrain)
{
auto checkState = [flags = prevStatesSet.second](RawState state) {
return (flags >> state) & 1;
@@ -145,7 +145,7 @@ Guard QAudioStateMachine::changeState(std::pair<RawState, uint32_t> prevStatesSe
}
}
-Guard QAudioStateMachine::stop(QAudio::Error error, bool shouldDrain, bool forceUpdateError)
+Notifier QAudioStateMachine::stop(QAudio::Error error, bool shouldDrain, bool forceUpdateError)
{
auto result = changeState(
makeStatesSet(QAudio::ActiveState, QAudio::IdleState, QAudio::SuspendedState),
@@ -157,7 +157,7 @@ Guard QAudioStateMachine::stop(QAudio::Error error, bool shouldDrain, bool force
return result;
}
-Guard QAudioStateMachine::start(bool active)
+Notifier QAudioStateMachine::start(bool active)
{
return changeState(makeStatesSet(QAudio::StoppedState),
active ? QAudio::ActiveState : QAudio::IdleState);
@@ -191,7 +191,7 @@ std::pair<bool, bool> QAudioStateMachine::getDrainedAndStopped() const
return { !isDrainingState(state), toAudioState(state) == QAudio::StoppedState };
}
-Guard QAudioStateMachine::suspend()
+Notifier QAudioStateMachine::suspend()
{
// Due to the current documentation, we set QAudio::NoError.
// TBD: leave the previous error should be more reasonable (IgnoreError)
@@ -205,7 +205,7 @@ Guard QAudioStateMachine::suspend()
return result;
}
-Guard QAudioStateMachine::resume()
+Notifier QAudioStateMachine::resume()
{
// Due to the current documentation, we set QAudio::NoError.
// TBD: leave the previous error should be more reasonable (IgnoreError)
@@ -213,12 +213,12 @@ Guard QAudioStateMachine::resume()
return changeState(makeStatesSet(QAudio::SuspendedState), m_suspendedInState, error);
}
-Guard QAudioStateMachine::activateFromIdle()
+Notifier QAudioStateMachine::activateFromIdle()
{
return changeState(makeStatesSet(QAudio::IdleState), QAudio::ActiveState);
}
-Guard QAudioStateMachine::updateActiveOrIdle(bool isActive, QAudio::Error error)
+Notifier QAudioStateMachine::updateActiveOrIdle(bool isActive, QAudio::Error error)
{
const auto state = isActive ? QAudio::ActiveState : QAudio::IdleState;
return changeState(makeStatesSet(QAudio::ActiveState, QAudio::IdleState), state, error);
@@ -230,7 +230,7 @@ void QAudioStateMachine::setError(QAudio::Error error)
emit m_notifier->errorChanged(error);
}
-Guard QAudioStateMachine::forceSetState(QAudio::State state, QAudio::Error error)
+Notifier QAudioStateMachine::forceSetState(QAudio::State state, QAudio::Error error)
{
return changeState(makeStatesSet(QAudio::ActiveState, QAudio::IdleState, QAudio::SuspendedState,
QAudio::StoppedState),
diff --git a/src/multimedia/audio/qaudiostatemachine_p.h b/src/multimedia/audio/qaudiostatemachine_p.h
index 44ea051a2..1baee3ef4 100644
--- a/src/multimedia/audio/qaudiostatemachine_p.h
+++ b/src/multimedia/audio/qaudiostatemachine_p.h
@@ -30,9 +30,8 @@ class QAudioStateChangeNotifier;
/* QAudioStateMachine provides an opportunity to
* toggle QAudio::State with QAudio::Error in
* a thread-safe manner.
- * The toggling functions return a guard,
- * which scope guaranties thread safety (if synchronization enabled)
- * and notifies about the change via
+ * The toggling functions return a notifier,
+ * which notifies about the change via
* QAudioStateChangeNotifier::stateChanged and errorChanged.
*
* The state machine is supposed to be used mostly in
@@ -42,7 +41,7 @@ class Q_MULTIMEDIA_EXPORT QAudioStateMachine
{
public:
using RawState = int;
- class StateChangeGuard
+ class Notifier
{
public:
void reset()
@@ -51,10 +50,10 @@ public:
stateMachine->reset(m_state, m_prevState, m_error);
}
- ~StateChangeGuard() { reset(); }
+ ~Notifier() { reset(); }
- StateChangeGuard(const StateChangeGuard &) = delete;
- StateChangeGuard(StateChangeGuard &&other) noexcept
+ Notifier(const Notifier &) = delete;
+ Notifier(Notifier &&other) noexcept
: m_stateMachine(std::exchange(other.m_stateMachine, nullptr)),
m_state(other.m_state),
m_prevState(other.m_prevState),
@@ -69,7 +68,7 @@ public:
// Can be added make state changing more flexible
// but needs some investigation to ensure state change consistency
// The method is supposed to be used for sync read/write
- // under "guard = updateActiveOrIdle(isActive)"
+ // under "notifier = updateActiveOrIdle(isActive)"
// void setState(QAudio::State state) { ... }
bool isStateChanged() const { return m_state != m_prevState; }
@@ -77,10 +76,8 @@ public:
QAudio::State prevState() const { return QAudio::State(m_prevState); }
private:
- StateChangeGuard(QAudioStateMachine *stateMachine = nullptr,
- RawState state = QAudio::StoppedState,
- RawState prevState = QAudio::StoppedState,
- QAudio::Error error = QAudio::NoError)
+ Notifier(QAudioStateMachine *stateMachine = nullptr, RawState state = QAudio::StoppedState,
+ RawState prevState = QAudio::StoppedState, QAudio::Error error = QAudio::NoError)
: m_stateMachine(stateMachine), m_state(state), m_prevState(prevState), m_error(error)
{
}
@@ -116,39 +113,39 @@ public:
void onDrained();
// Active/Idle/Suspended -> Stopped
- StateChangeGuard stop(QAudio::Error error = QAudio::NoError, bool shouldDrain = false,
- bool forceUpdateError = false);
+ Notifier stop(QAudio::Error error = QAudio::NoError, bool shouldDrain = false,
+ bool forceUpdateError = false);
// Active/Idle/Suspended -> Stopped
- StateChangeGuard stopOrUpdateError(QAudio::Error error = QAudio::NoError)
+ Notifier stopOrUpdateError(QAudio::Error error = QAudio::NoError)
{
return stop(error, false, true);
}
// Stopped -> Active/Idle
- StateChangeGuard start(bool isActive = true);
+ Notifier start(bool isActive = true);
// Active/Idle -> Suspended + saves the exchanged state
- StateChangeGuard suspend();
+ Notifier suspend();
// Suspended -> saved state (Active/Idle)
- StateChangeGuard resume();
+ Notifier resume();
// Idle -> Active
- StateChangeGuard activateFromIdle();
+ Notifier activateFromIdle();
// Active/Idle -> Active/Idle + updateError
- StateChangeGuard updateActiveOrIdle(bool isActive, QAudio::Error error = QAudio::NoError);
+ Notifier updateActiveOrIdle(bool isActive, QAudio::Error error = QAudio::NoError);
// Any -> Any; better use more strict methods
- StateChangeGuard forceSetState(QAudio::State state, QAudio::Error error = QAudio::NoError);
+ Notifier forceSetState(QAudio::State state, QAudio::Error error = QAudio::NoError);
// force set the error
void setError(QAudio::Error error);
private:
- StateChangeGuard changeState(std::pair<RawState, uint32_t> prevStatesSet, RawState state,
- QAudio::Error error = QAudio::NoError, bool shouldDrain = false);
+ Notifier changeState(std::pair<RawState, uint32_t> prevStatesSet, RawState state,
+ QAudio::Error error = QAudio::NoError, bool shouldDrain = false);
void reset(RawState state, RawState prevState, QAudio::Error error);
diff --git a/src/multimedia/darwin/qdarwinaudiosink.mm b/src/multimedia/darwin/qdarwinaudiosink.mm
index 134d779c3..e2d128483 100644
--- a/src/multimedia/darwin/qdarwinaudiosink.mm
+++ b/src/multimedia/darwin/qdarwinaudiosink.mm
@@ -271,8 +271,8 @@ void QDarwinAudioSink::stop()
if (m_audioBuffer)
m_audioBuffer->setFillingEnabled(false);
- if (auto guard = m_stateMachine.stop(QAudio::NoError, true)) {
- if (guard.prevState() == QAudio::ActiveState) {
+ if (auto notifier = m_stateMachine.stop(QAudio::NoError, true)) {
+ if (notifier.prevState() == QAudio::ActiveState) {
m_stateMachine.waitForDrained(std::chrono::milliseconds(500));
if (m_stateMachine.isDraining())
diff --git a/src/multimedia/pulseaudio/qpulseaudiosink.cpp b/src/multimedia/pulseaudio/qpulseaudiosink.cpp
index 5ac27d9df..612f65de6 100644
--- a/src/multimedia/pulseaudio/qpulseaudiosink.cpp
+++ b/src/multimedia/pulseaudio/qpulseaudiosink.cpp
@@ -118,10 +118,10 @@ QPulseAudioSink::QPulseAudioSink(const QByteArray &device, QObject *parent)
QPulseAudioSink::~QPulseAudioSink()
{
- if (auto guard = m_stateMachine.stop()) {
+ if (auto notifier = m_stateMachine.stop()) {
close();
QSignalBlocker blocker(this);
- guard.reset();
+ notifier.reset();
}
}
@@ -166,8 +166,8 @@ void QPulseAudioSink::start(QIODevice *device)
return;
}
- auto guard = m_stateMachine.start();
- Q_ASSERT(guard);
+ auto notifier = m_stateMachine.start();
+ Q_ASSERT(notifier);
// ensure we only process timing infos that are up to date
gettimeofday(&lastTimingInfo, nullptr);
@@ -191,8 +191,8 @@ QIODevice *QPulseAudioSink::start()
if (!open())
return nullptr;
- auto guard = m_stateMachine.start(false);
- Q_ASSERT(guard);
+ auto notifier = m_stateMachine.start(false);
+ Q_ASSERT(notifier);
m_audioSource = new PulseOutputPrivate(this);
m_audioSource->open(QIODevice::WriteOnly|QIODevice::Unbuffered);
@@ -487,7 +487,7 @@ qint64 QPulseAudioSink::write(const char *data, qint64 len)
void QPulseAudioSink::stop()
{
- if (auto guard = m_stateMachine.stop())
+ if (auto notifier = m_stateMachine.stop())
close();
}
@@ -579,7 +579,7 @@ qint64 QPulseAudioSink::processedUSecs() const
void QPulseAudioSink::resume()
{
- if (auto guard = m_stateMachine.resume()) {
+ if (auto notifier = m_stateMachine.resume()) {
m_resuming = true;
{
@@ -611,7 +611,7 @@ QAudioFormat QPulseAudioSink::format() const
void QPulseAudioSink::suspend()
{
- if (auto guard = m_stateMachine.suspend()) {
+ if (auto notifier = m_stateMachine.suspend()) {
m_tickTimer.stop();
QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
@@ -626,7 +626,7 @@ void QPulseAudioSink::suspend()
void QPulseAudioSink::reset()
{
- if (auto guard = m_stateMachine.stopOrUpdateError())
+ if (auto notifier = m_stateMachine.stopOrUpdateError())
close();
}
@@ -675,7 +675,7 @@ qreal QPulseAudioSink::volume() const
void QPulseAudioSink::onPulseContextFailed()
{
- if (auto guard = m_stateMachine.stop(QAudio::FatalError))
+ if (auto notifier = m_stateMachine.stop(QAudio::FatalError))
close();
}
diff --git a/tests/auto/unit/multimedia/qaudiostatemachine/tst_qaudiostatemachine.cpp b/tests/auto/unit/multimedia/qaudiostatemachine/tst_qaudiostatemachine.cpp
index 22039f2e4..0b4375227 100644
--- a/tests/auto/unit/multimedia/qaudiostatemachine/tst_qaudiostatemachine.cpp
+++ b/tests/auto/unit/multimedia/qaudiostatemachine/tst_qaudiostatemachine.cpp
@@ -177,8 +177,8 @@ void tst_QAudioStateMachine::stop_changesState_whenStateIsNotStopped()
QSignalSpy stateSpy(&changeNotifier, &QAudioStateChangeNotifier::stateChanged);
QSignalSpy errorSpy(&changeNotifier, &QAudioStateChangeNotifier::errorChanged);
- auto guard = stateMachine.stop();
- QVERIFY(guard);
+ auto notifier = stateMachine.stop();
+ QVERIFY(notifier);
QVERIFY(!stateMachine.isDraining());
@@ -188,7 +188,7 @@ void tst_QAudioStateMachine::stop_changesState_whenStateIsNotStopped()
QCOMPARE(stateSpy.size(), 0);
QCOMPARE(errorSpy.size(), 0);
- guard.reset();
+ notifier.reset();
QVERIFY(!stateMachine.isDraining());
@@ -286,8 +286,8 @@ void tst_QAudioStateMachine::updateActiveOrIdle_changesState_whenStateIsActiveOr
const auto expectedState = active ? QAudio::ActiveState : QAudio::IdleState;
- auto guard = stateMachine.updateActiveOrIdle(active, error);
- QVERIFY(guard);
+ auto notifier = stateMachine.updateActiveOrIdle(active, error);
+ QVERIFY(notifier);
QCOMPARE(stateSpy.size(), 0);
QCOMPARE(errorSpy.size(), 0);
@@ -295,7 +295,7 @@ void tst_QAudioStateMachine::updateActiveOrIdle_changesState_whenStateIsActiveOr
QCOMPARE(stateMachine.state(), expectedState);
QCOMPARE(stateMachine.error(), prevError);
- guard.reset();
+ notifier.reset();
QCOMPARE(stateSpy.size(), expectedState == prevState ? 0 : 1);
if (!stateSpy.empty())
@@ -316,13 +316,13 @@ void tst_QAudioStateMachine::stopWithDraining_setDrainingFlagUnderTheGuard()
stateMachine.start();
- auto guard = stateMachine.stop(QAudio::IOError, true);
- QVERIFY(guard);
+ auto notifier = stateMachine.stop(QAudio::IOError, true);
+ QVERIFY(notifier);
QVERIFY(stateMachine.isDraining());
QCOMPARE(stateMachine.getDrainedAndStopped(), std::make_pair(false, true));
QCOMPARE(stateMachine.state(), QAudio::StoppedState);
- guard.reset();
+ notifier.reset();
QVERIFY(!stateMachine.isDraining());
QCOMPARE(stateMachine.getDrainedAndStopped(), std::make_pair(true, true));
@@ -338,8 +338,8 @@ void tst_QAudioStateMachine::onDrained_interruptsWaitingForDrained_whenCalledFro
QSignalSpy stateSpy(&changeNotifier, &QAudioStateChangeNotifier::stateChanged);
QSignalSpy errorSpy(&changeNotifier, &QAudioStateChangeNotifier::errorChanged);
- auto guard = stateMachine.stop(QAudio::IOError, true);
- QVERIFY(guard);
+ auto notifier = stateMachine.stop(QAudio::IOError, true);
+ QVERIFY(notifier);
QVERIFY(stateMachine.isDraining());
QCOMPARE(stateMachine.state(), QAudio::StoppedState);
@@ -366,7 +366,7 @@ void tst_QAudioStateMachine::onDrained_interruptsWaitingForDrained_whenCalledFro
QCOMPARE(stateSpy.size(), 0);
QCOMPARE(errorSpy.size(), 0);
- guard.reset();
+ notifier.reset();
QCOMPARE(stateSpy.size(), 1);
QCOMPARE(errorSpy.size(), 1);
@@ -379,8 +379,8 @@ void tst_QAudioStateMachine::waitForDrained_waitsLimitedTime()
stateMachine.start();
- auto guard = stateMachine.stop(QAudio::IOError, true);
- QVERIFY(guard);
+ auto notifier = stateMachine.stop(QAudio::IOError, true);
+ QVERIFY(notifier);
QElapsedTimer elapsedTimer;
elapsedTimer.start();