summaryrefslogtreecommitdiffstats
path: root/src/multimedia/audio
diff options
context:
space:
mode:
authorArtem Dyomin <artem.dyomin@qt.io>2023-09-12 11:28:30 +0200
committerArtem Dyomin <artem.dyomin@qt.io>2023-09-13 08:07:21 +0000
commit8423c36ac7f5908f1404ad0b4c6d746857c3a2c9 (patch)
treeeb45d6b9aa0f59dd9185f87089f5c80ef0b66260 /src/multimedia/audio
parent775497cbe8caf8c1da16000d7198bd81533129ae (diff)
Move some logic of QAudioStateMachine to AudioStateMachineUtils
The patch is a part of QAudioStateMachine prettification. Pick-to: 6.5 6.6 Change-Id: I08092be2d497c5d3fba7f569e443e5139ce30ba8 Reviewed-by: Jøger Hansegård <joger.hansegard@qt.io> Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
Diffstat (limited to 'src/multimedia/audio')
-rw-r--r--src/multimedia/audio/qaudiostatemachine.cpp49
-rw-r--r--src/multimedia/audio/qaudiostatemachine_p.h6
-rw-r--r--src/multimedia/audio/qaudiostatemachineutils_p.h71
3 files changed, 74 insertions, 52 deletions
diff --git a/src/multimedia/audio/qaudiostatemachine.cpp b/src/multimedia/audio/qaudiostatemachine.cpp
index 8f501fc11..83716efd2 100644
--- a/src/multimedia/audio/qaudiostatemachine.cpp
+++ b/src/multimedia/audio/qaudiostatemachine.cpp
@@ -9,54 +9,7 @@
QT_BEGIN_NAMESPACE
using Notifier = QAudioStateMachine::Notifier;
-using RawState = QAudioStateMachine::RawState;
-
-namespace {
-constexpr RawState DrainingFlag = 1 << 16;
-constexpr RawState InProgressFlag = 1 << 17;
-constexpr RawState WaitingFlags = DrainingFlag | InProgressFlag;
-
-inline bool isWaitingState(RawState state)
-{
- return (state & WaitingFlags) != 0;
-}
-
-inline bool isDrainingState(RawState state)
-{
- return (state & DrainingFlag) != 0;
-}
-
-inline RawState fromWaitingState(RawState state)
-{
- return state & ~WaitingFlags;
-}
-
-inline QAudio::State toAudioState(RawState state)
-{
- return QAudio::State(fromWaitingState(state));
-}
-
-template<typename... States>
-constexpr std::pair<RawState, uint32_t> makeStatesSet(QAudio::State first, States... others)
-{
- return { first, ((1 << first) | ... | (1 << others)) };
-}
-
-// ensures compareExchange (testAndSet) operation with opportunity
-// to check several states, can be considered as atomic
-template<typename T, typename Predicate>
-bool multipleCompareExchange(std::atomic<T> &target, T &prevValue, T newValue, Predicate predicate)
-{
- Q_ASSERT(predicate(prevValue));
- do {
- if (target.compare_exchange_strong(prevValue, newValue))
- return true;
- } while (predicate(prevValue));
-
- return false;
-}
-
-} // namespace
+using namespace AudioStateMachineUtils;
struct QAudioStateMachine::Synchronizer {
QMutex m_mutex;
diff --git a/src/multimedia/audio/qaudiostatemachine_p.h b/src/multimedia/audio/qaudiostatemachine_p.h
index 1baee3ef4..b3207230b 100644
--- a/src/multimedia/audio/qaudiostatemachine_p.h
+++ b/src/multimedia/audio/qaudiostatemachine_p.h
@@ -14,9 +14,7 @@
//
// We mean it.
//
-
-#include <QtMultimedia/qaudio.h>
-
+#include "qaudiostatemachineutils_p.h"
#include <qmutex.h>
#include <qwaitcondition.h>
#include <qpointer.h>
@@ -40,7 +38,7 @@ class QAudioStateChangeNotifier;
class Q_MULTIMEDIA_EXPORT QAudioStateMachine
{
public:
- using RawState = int;
+ using RawState = AudioStateMachineUtils::RawState;
class Notifier
{
public:
diff --git a/src/multimedia/audio/qaudiostatemachineutils_p.h b/src/multimedia/audio/qaudiostatemachineutils_p.h
new file mode 100644
index 000000000..a1c5ef579
--- /dev/null
+++ b/src/multimedia/audio/qaudiostatemachineutils_p.h
@@ -0,0 +1,71 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QAUDIOSTATEMACHINEUTILS_P_H
+#define QAUDIOSTATEMACHINEUTILS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qaudio.h"
+
+QT_BEGIN_NAMESPACE
+
+namespace AudioStateMachineUtils {
+using RawState = int;
+constexpr RawState DrainingFlag = 1 << 16;
+constexpr RawState InProgressFlag = 1 << 17;
+constexpr RawState WaitingFlags = DrainingFlag | InProgressFlag;
+
+constexpr bool isWaitingState(RawState state)
+{
+ return (state & WaitingFlags) != 0;
+}
+
+constexpr bool isDrainingState(RawState state)
+{
+ return (state & DrainingFlag) != 0;
+}
+
+constexpr RawState fromWaitingState(RawState state)
+{
+ return state & ~WaitingFlags;
+}
+
+constexpr QAudio::State toAudioState(RawState state)
+{
+ return QAudio::State(fromWaitingState(state));
+}
+
+template <typename... States>
+constexpr std::pair<RawState, uint32_t> makeStatesSet(QAudio::State first, States... others)
+{
+ return { first, ((1 << first) | ... | (1 << others)) };
+}
+
+// ensures compareExchange (testAndSet) operation with opportunity
+// to check several states, can be considered as atomic
+template <typename T, typename Predicate>
+bool multipleCompareExchange(std::atomic<T> &target, T &prevValue, T newValue, Predicate predicate)
+{
+ Q_ASSERT(predicate(prevValue));
+ do {
+ if (target.compare_exchange_strong(prevValue, newValue))
+ return true;
+ } while (predicate(prevValue));
+
+ return false;
+}
+} // namespace AudioStateMachineUtils
+
+QT_END_NAMESPACE
+
+#endif // QAUDIOSTATEMACHINEUTILS_P_H