Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qaudiostatemachine_p.h
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QAUDIOSTATEMACHINE_P_H
5#define QAUDIOSTATEMACHINE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
19
20#include <qpointer.h>
21#include <atomic>
22
24
26
27/* QAudioStateMachine provides an opportunity to
28 * toggle QAudio::State with QAudio::Error in
29 * a thread-safe manner.
30 * The toggling functions return a notifier,
31 * which notifies about the change via
32 * QAudioStateChangeNotifier::stateChanged and errorChanged.
33 *
34 * The state machine is supposed to be used mostly in
35 * QAudioSink and QAudioSource implementations.
36 */
37class Q_MULTIMEDIA_EXPORT QAudioStateMachine
38{
39public:
42 {
43 public:
44 void reset()
45 {
46 if (auto stateMachine = std::exchange(m_stateMachine, nullptr))
47 stateMachine->reset(m_state, m_prevState);
48 }
49
51
52 Notifier(const Notifier &) = delete;
54 : m_stateMachine(std::exchange(other.m_stateMachine, nullptr)),
55 m_state(other.m_state),
56 m_prevState(other.m_prevState)
57 {
58 }
59
60 operator bool() const { return m_stateMachine != nullptr; }
61
63
65
66 bool isDraining() const { return AudioStateMachineUtils::isDrainingState(m_state); }
67
68 bool isStateChanged() const { return prevAudioState() != audioState(); }
69
70 private:
73 : m_stateMachine(stateMachine), m_state(state), m_prevState(prevState)
74 {
75 }
76
77 private:
78 QAudioStateMachine *m_stateMachine;
79 RawState m_state;
80 const RawState m_prevState;
81
82 friend class QAudioStateMachine;
83 };
84
86
88
89 QAudio::State state() const;
90
91 QAudio::Error error() const;
92
93 bool isActiveOrIdle() const;
94
95 bool isDraining() const;
96
97 // atomicaly checks if the state is stopped and marked as drained
98 std::pair<bool, bool> getDrainedAndStopped() const;
99
100 // Stopped[draining] -> Stopped
101 bool onDrained();
102
103 // Active/Idle/Suspended -> Stopped
104 // or Active -> Stopped[draining] for shouldDrain = true
105 Notifier stop(QAudio::Error error = QAudio::NoError, bool shouldDrain = false,
106 bool forceUpdateError = false);
107
108 // Active/Idle/Suspended -> Stopped
110 {
111 return stop(error, false, true);
112 }
113
114 // Stopped -> Active/Idle
115 Notifier start(bool isActive = true);
116
117 // Active/Idle -> Suspended + saves the exchanged state
119
120 // Suspended -> saved state (Active/Idle)
122
123 // Idle -> Active
124 Notifier activateFromIdle();
125
126 // Active/Idle -> Active/Idle + updateError
127 Notifier updateActiveOrIdle(bool isActive, QAudio::Error error = QAudio::NoError);
128
129 // Any -> Any; better use more strict methods
131
132 // force set the error
134
135private:
136 template <typename StatesChecker, typename NewState>
137 Notifier changeState(const StatesChecker &statesChecker, const NewState &newState);
138
139 void reset(RawState state, RawState prevState);
140
141private:
142 QPointer<QAudioStateChangeNotifier> m_notifier;
143 std::atomic<RawState> m_state = QAudio::StoppedState;
144 QAudio::State m_suspendedInState = QAudio::SuspendedState;
145};
146
148
149#endif // QAUDIOSTATEMACHINE_P_H
DarwinBluetooth::LECBManagerNotifier * notifier
bool isActive
Notifier(Notifier &&other) noexcept
Notifier(const Notifier &)=delete
QAudio::State prevAudioState() const
Notifier stopOrUpdateError(QAudio::Error error=QAudio::NoError)
AudioStateMachineUtils::RawState RawState
else opt state
[0]
void newState(QList< State > &states, const char *token, const char *lexem, bool pre)
constexpr bool isDrainingState(RawState state)
constexpr QAudio::State toAudioState(RawState state)
State
Definition qaudio.h:29
@ StoppedState
Definition qaudio.h:29
@ SuspendedState
Definition qaudio.h:29
Error
Definition qaudio.h:28
@ NoError
Definition qaudio.h:28
Combined button and popup list for selecting options.
QAudioStateMachine::Notifier Notifier
DBusConnection const char DBusError * error
GLuint start
GLboolean reset
static void setError(QJsonObject *response, const QString &msg)
future resume()
future suspend()
QSharedPointer< T > other(t)
[5]