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
qaudiosink.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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
5#include "qaudio.h"
6#include "qaudiodevice.h"
7#include "qaudiosystem_p.h"
8#include "qaudiosink.h"
9
10#include <private/qplatformmediadevices_p.h>
11#include <private/qplatformmediaintegration_p.h>
12
14
78 : QAudioSink({}, format, parent)
79{
80}
81
87QAudioSink::QAudioSink(const QAudioDevice &audioDevice, const QAudioFormat &format, QObject *parent):
88 QObject(parent)
89{
90 d = QPlatformMediaIntegration::instance()->mediaDevices()->audioOutputDevice(format, audioDevice, parent);
91 if (d)
93 // if the signal has been emitted from another thread,
94 // the state may be already changed by main one
95 if (state == d->state())
97 });
98 else
99 qWarning() << ("No audio device detected");
100}
101
115{
116 delete d;
117}
118
124{
125 return d ? d->format() : QAudioFormat();
126}
127
143{
144 if (!d)
145 return;
146 d->elapsedTime.restart();
147 d->start(device);
148}
149
168{
169 if (!d)
170 return nullptr;
171 d->elapsedTime.restart();
172 return d->start();
173}
174
182{
183 if (d)
184 d->stop();
185}
186
192{
193 if (d)
194 d->reset();
195}
196
204{
205 if (d)
206 d->suspend();
207}
208
217{
218 if (d)
219 d->resume();
220}
221
229{
230 return d ? d->bytesFree() : 0;
231}
232
242{
243 if (d)
245}
246
257{
258 return d ? d->bufferSize() : 0;
259}
260
266{
267 return d ? d->processedUSecs() : 0;
268}
269
275{
276 return state() == QAudio::StoppedState ? 0 : d->elapsedTime.nsecsElapsed()/1000;
277}
278
283{
284 return d ? d->error() : QAudio::OpenError;
285}
286
291{
292 return d ? d->state() : QAudio::StoppedState;
293}
294
312{
313 if (!d)
314 return;
315 qreal v = qBound(qreal(0.0), volume, qreal(1.0));
316 d->setVolume(v);
317}
318
323{
324 return d ? d->volume() : 1.0;
325}
326
338
339#include "moc_qaudiosink.cpp"
IOBluetoothDevice * device
The QAudioDevice class provides an information about audio devices and their functionality.
The QAudioFormat class stores audio stream parameter information.
The QAudioSink class provides an interface for sending audio data to an audio output device.
Definition qaudiosink.h:24
QAudioSink(const QAudioFormat &format=QAudioFormat(), QObject *parent=nullptr)
Construct a new audio output and attach it to parent.
qint64 processedUSecs() const
Returns the amount of audio data processed since start() was called (in microseconds).
void stop()
Stops the audio output, detaching from the system resource.
void resume()
Resumes processing audio data after a suspend().
void stateChanged(QAudio::State state)
This signal is emitted when the device state has changed.
void setVolume(qreal)
Sets the output volume to volume.
void setBufferSize(qsizetype bytes)
Sets the audio buffer size to value in bytes.
qint64 elapsedUSecs() const
Returns the microseconds since start() was called, including time in Idle and Suspend states.
qreal volume() const
Returns the volume between 0.0 and 1.0 inclusive.
qsizetype bufferSize() const
Returns the audio buffer size in bytes.
QAudioFormat format() const
Returns the QAudioFormat being used.
QtAudio::Error error() const
Returns the error state.
QtAudio::State state() const
Returns the state of audio processing.
void reset()
Drops all audio data in the buffers, resets buffers to zero.
qsizetype bytesFree() const
Returns the number of free bytes available in the audio buffer.
void suspend()
Stops processing audio data, preserving buffered audio data.
QIODevice * start()
Returns a pointer to the internal QIODevice being used to transfer data to the system's audio output.
~QAudioSink()
Destroys this audio output.
void stateChanged(QAudio::State state)
qint64 restart() noexcept
Restarts the timer and returns the number of milliseconds elapsed since the previous start.
qint64 nsecsElapsed() const noexcept
\inmodule QtCore \reentrant
Definition qiodevice.h:34
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
virtual qsizetype bytesFree() const =0
QElapsedTimer elapsedTime
virtual void resume()=0
virtual void start(QIODevice *device)=0
virtual void reset()=0
virtual QAudio::Error error() const =0
virtual void stop()=0
virtual qint64 processedUSecs() const =0
virtual qreal volume() const
virtual QAudioFormat format() const =0
virtual QAudio::State state() const =0
virtual void setVolume(qreal)
virtual void setBufferSize(qsizetype value)=0
virtual qsizetype bufferSize() const =0
virtual void suspend()=0
static QPlatformMediaIntegration * instance()
State
Definition qaudio.h:29
@ StoppedState
Definition qaudio.h:29
Error
Definition qaudio.h:28
@ OpenError
Definition qaudio.h:28
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qWarning
Definition qlogging.h:166
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
GLsizei const GLfloat * v
[13]
GLint GLsizei GLsizei GLenum format
#define emit
ptrdiff_t qsizetype
Definition qtypes.h:165
long long qint64
Definition qtypes.h:60
double qreal
Definition qtypes.h:187