Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qavaudiosessionrecovery_p.h
Go to the documentation of this file.
1// Copyright (C) 2026 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 QAVAUDIOSESSIONRECOVERY_P_H
5#define QAVAUDIOSESSIONRECOVERY_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
18#include <QtMultimedia/private/qavaudiosessionmanager_p.h>
19#include <QtMultimedia/qaudio.h>
20
21#include <QtGui/qguiapplication.h>
22
23QT_BEGIN_NAMESPACE
24
25namespace QtMultimediaPrivate {
26
27template <typename EndpointType>
29{
30public:
31 explicit QAVAudioSessionRecovery(EndpointType &endpoint) : m_endpoint(endpoint)
32 {
33 QAVAudioSessionManager *monitor = QAVAudioSessionManager::instance();
34
35 QObject::connect(monitor, &QAVAudioSessionManager::interruptionBegan, &m_endpoint,
36 [this] {
37 onInterruptionBegan();
38 });
39 QObject::connect(monitor, &QAVAudioSessionManager::interruptionEnded, &m_endpoint,
40 [this](bool shouldResume) {
41 onInterruptionEnded(shouldResume);
42 });
43 QObject::connect(monitor, &QAVAudioSessionManager::mediaServicesWereLost, &m_endpoint,
44 [this] {
45 onMediaServicesInvalidated();
46 });
47 QObject::connect(monitor, &QAVAudioSessionManager::mediaServicesWereReset, &m_endpoint,
48 [this] {
49 onMediaServicesInvalidated();
50 });
51
52 if (qGuiApp)
53 QObject::connect(qGuiApp, &QGuiApplication::applicationStateChanged, &m_endpoint,
54 [this](Qt::ApplicationState state) {
55 if (state == Qt::ApplicationState::ApplicationActive)
56 onApplicationActivated();
57 });
58 }
59
61
63 {
64 if (m_interrupted)
66 m_interrupted = false;
67 }
68 void streamStopped() { m_interrupted = false; }
69
70private:
71 bool isStreamActive() const
72 {
74 return false;
75
77 return state == QAudio::ActiveState || state == QAudio::IdleState;
78 }
79
81 {
82 if (!isStreamActive())
83 return;
84
85 m_interrupted = true;
87 }
88
90 {
91 if (!m_interrupted)
92 return;
93
94 if (!shouldResume)
95 return;
96
97 recover();
98 }
99
101 {
103 if (!stream)
104 return;
105
106 m_interrupted = false;
109 }
110
112 {
113 if (m_interrupted)
114 recover();
115 else
117 }
118
119 void recover()
120 {
121 m_interrupted = false;
123 if (!stream) {
124 return;
125 }
126
127 const bool resumed = activateSession() && stream->resume();
128 if (resumed)
130 else
132 }
133
134 static bool activateSession()
135 {
138 }
139
141 bool m_interrupted = false;
142};
143
144} // namespace QtMultimediaPrivate
145
146QT_END_NAMESPACE
147
148#endif // QAVAUDIOSESSIONRECOVERY_P_H