summaryrefslogtreecommitdiffstats
path: root/src/multimedia/audio
diff options
context:
space:
mode:
authorArtem Dyomin <artem.dyomin@qt.io>2023-09-12 11:12:38 +0200
committerArtem Dyomin <artem.dyomin@qt.io>2023-09-12 22:55:35 +0000
commit775497cbe8caf8c1da16000d7198bd81533129ae (patch)
tree87bb0dd9bce332b6d05653d93be8300bfa75c9a4 /src/multimedia/audio
parentde0afbef80749e4f0e0c1c5ed52d9655b2e77f5f (diff)
Rename StateChangeGuard -> Notifier
The patch is a part of QAudioStateMachine prettification. QAudioStateMachine::Notifier is going to do only signal notifications. Pick-to: 6.6 6.5 Change-Id: Ic76d1af6ec5be704a3c10597c2ac4240841ce4a4 Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
Diffstat (limited to 'src/multimedia/audio')
-rw-r--r--src/multimedia/audio/qaudiostatemachine.cpp20
-rw-r--r--src/multimedia/audio/qaudiostatemachine_p.h43
2 files changed, 30 insertions, 33 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);