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
qaudiosystem.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 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
5
6#include <private/qplatformaudiodevices_p.h>
7
8#include <QtCore/qdebug.h>
9
11
12QAudioStateChangeNotifier::QAudioStateChangeNotifier(QObject *parent) : QObject(parent) { }
13
14QPlatformAudioEndpointBase::QPlatformAudioEndpointBase(QObject *parent)
15 : QAudioStateChangeNotifier(parent)
16{
17}
18
19void QPlatformAudioEndpointBase::setError(QAudio::Error err)
20{
21 if (err == m_error)
22 return;
23 m_error = err;
24 emit errorChanged(err);
25}
26
27void QPlatformAudioEndpointBase::updateStreamState(QAudio::State state)
28{
29 if (m_streamState == state)
30 return;
31
32 m_streamState = state;
33 inferState();
34}
35
36void QPlatformAudioEndpointBase::updateStreamIdle(bool idle, EmitStateSignal emitStateSignal)
37{
38 if (idle == m_streamIsIdle)
39 return;
40 m_streamIsIdle = idle;
41
42 if (emitStateSignal == EmitStateSignal::True)
43 inferState();
44}
45
46void QPlatformAudioEndpointBase::inferState()
47{
48 // The "state" is derived from two sources:
49 // * the m_streamState, as changed by start/stop/suspend/resume
50 // * the "idle" state of the stream, as detected by the ringbuffer level
51 //
52 // we combine these two sources to infer a user-visible "state"
53 using State = QtAudio::State;
54
55 State oldState = m_inferredState;
56
57 switch (m_streamState) {
58 case State::StoppedState:
59 m_inferredState = State::StoppedState;
60 break;
61 case State::SuspendedState:
62 m_inferredState = State::SuspendedState;
63 break;
64 case State::ActiveState:
65 m_inferredState = m_streamIsIdle ? State::IdleState : State::ActiveState;
66 break;
67
68 case State::IdleState:
69 qCritical() << "Users should not be able to set the state to Idle!";
70 Q_UNREACHABLE_RETURN();
71 }
72
73 if (oldState != m_inferredState)
74 emit stateChanged(m_inferredState);
75}
76
77QPlatformAudioSink::QPlatformAudioSink(QObject *parent) : QPlatformAudioEndpointBase(parent) { }
78
79qreal QPlatformAudioSink::volume() const
80{
81 return 1.0;
82}
83
84QPlatformAudioSource::QPlatformAudioSource(QObject *parent) : QPlatformAudioEndpointBase(parent) { }
85
86QT_END_NAMESPACE
87
88#include "moc_qaudiosystem_p.cpp"
Combined button and popup list for selecting options.