Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
23
QT_BEGIN_NAMESPACE
24
25
namespace
QtMultimediaPrivate
{
26
27
template
<
typename
EndpointType>
28
class
QAVAudioSessionRecovery
29
{
30
public
:
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
60
Q_DISABLE_COPY_MOVE
(
QAVAudioSessionRecovery
)
61
62
void
userResumeRequested
()
63
{
64
if
(m_interrupted)
65
activateSession();
66
m_interrupted =
false
;
67
}
68
void
streamStopped
() { m_interrupted =
false
; }
69
70
private
:
71
bool
isStreamActive()
const
72
{
73
if
(!m_endpoint.currentStream())
74
return
false
;
75
76
const
QAudio::State state = m_endpoint.state();
77
return
state == QAudio::ActiveState || state == QAudio::IdleState;
78
}
79
80
void
onInterruptionBegan()
81
{
82
if
(!isStreamActive())
83
return
;
84
85
m_interrupted =
true
;
86
m_endpoint.updateStreamState(QAudio::SuspendedState);
87
}
88
89
void
onInterruptionEnded(
bool
shouldResume)
90
{
91
if
(!m_interrupted)
92
return
;
93
94
if
(!shouldResume)
95
return
;
96
97
recover();
98
}
99
100
void
onMediaServicesInvalidated()
101
{
102
auto
*stream = m_endpoint.currentStream();
103
if
(!stream)
104
return
;
105
106
m_interrupted =
false
;
107
stream->invalidateAudioUnit();
108
stream->reportIOError();
109
}
110
111
void
onApplicationActivated()
112
{
113
if
(m_interrupted)
114
recover();
115
else
116
m_endpoint.resumeStreamIfNecessary();
117
}
118
119
void
recover()
120
{
121
m_interrupted =
false
;
122
auto
*stream = m_endpoint.currentStream();
123
if
(!stream) {
124
return
;
125
}
126
127
const
bool
resumed = activateSession() && stream->resume();
128
if
(resumed)
129
m_endpoint.updateStreamState(QAudio::ActiveState);
130
else
131
stream->reportIOError();
132
}
133
134
static
bool
activateSession()
135
{
136
QAVAudioSessionManager *monitor = QAVAudioSessionManager::instance();
137
return
monitor && monitor->reassertActivation();
138
}
139
140
EndpointType& m_endpoint;
141
bool
m_interrupted =
false
;
142
};
143
144
}
// namespace QtMultimediaPrivate
145
146
QT_END_NAMESPACE
147
148
#
endif
// QAVAUDIOSESSIONRECOVERY_P_H
QtMultimediaPrivate::QAVAudioSessionRecovery
Definition
qavaudiosessionrecovery_p.h:29
QtMultimediaPrivate::QAVAudioSessionRecovery::QAVAudioSessionRecovery
QAVAudioSessionRecovery(EndpointType &endpoint)
Definition
qavaudiosessionrecovery_p.h:31
QtMultimediaPrivate::QAVAudioSessionRecovery::streamStopped
void streamStopped()
Definition
qavaudiosessionrecovery_p.h:68
QtMultimediaPrivate::QAVAudioSessionRecovery::userResumeRequested
void userResumeRequested()
Definition
qavaudiosessionrecovery_p.h:62
QtMultimediaPrivate::impl
Definition
qaudiosystem_p.h:257
qtmultimedia
src
multimedia
coreaudio
qavaudiosessionrecovery_p.h
Generated on
for Qt by
1.18.0