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
qaudiobufferinput.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 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#include "qaudiobufferinput.h"
8
10
12{
13public:
15
16 bool sendAudioBuffer(const QAudioBuffer &audioBuffer)
17 {
18 return sendMediaFrame(
19 [&]() { emit m_platfromAudioBufferInput->newAudioBuffer(audioBuffer); });
20 }
21
22 void initialize(const QAudioFormat &format = {})
23 {
24 m_platfromAudioBufferInput = std::make_unique<QPlatformAudioBufferInput>(format);
25 addUpdateSignal(m_platfromAudioBufferInput.get(),
27 }
28
30 {
31 m_platfromAudioBufferInput.reset();
32
33 if (captureSession())
35 }
36
37 QMediaCaptureSession *session() const { return m_captureSession; }
38
40 {
41 return m_platfromAudioBufferInput.get();
42 }
43
44private:
46 QMediaCaptureSession *newSession) override
47 {
48 if (prevSession)
50
51 if (newSession)
53 }
54
55 bool checkIfCanSendMediaFrame() const override
56 {
57 if (auto encoderInterface = m_platfromAudioBufferInput->encoderInterface())
58 return encoderInterface->canPushFrame();
59
60 // Not implemented yet
61 // return captureSession()->audioOutput() != nullptr;
62 return false;
63 }
64
65 void emitReadyToSendMediaFrame() override { emit q->readyToSendAudioBuffer(); }
66
67private:
68 QAudioBufferInput *q = nullptr;
69 QMediaCaptureSession *m_captureSession = nullptr;
70 std::unique_ptr<QPlatformAudioBufferInput> m_platfromAudioBufferInput;
71};
72
90
103 : QObject(*new QAudioBufferInputPrivate(this), parent)
104{
106 d->initialize(format);
107}
108
113{
115 d->uninitialize();
116}
117
135{
137 return d->sendAudioBuffer(audioBuffer);
138}
139
144{
145 Q_D(const QAudioBufferInput);
146 return d->platfromAudioBufferInput()->audioFormat();
147}
148
157{
158 Q_D(const QAudioBufferInput);
159 return d->captureSession();
160}
161
162void QAudioBufferInput::setCaptureSession(QMediaCaptureSession *captureSession)
163{
165 d->setCaptureSession(captureSession);
166}
167
168QPlatformAudioBufferInput *QAudioBufferInput::platformAudioBufferInput() const
169{
170 Q_D(const QAudioBufferInput);
171 return d->platfromAudioBufferInput();
172}
173
void updateCaptureSessionConnections(QMediaCaptureSession *prevSession, QMediaCaptureSession *newSession) override
QMediaCaptureSession * session() const
bool sendAudioBuffer(const QAudioBuffer &audioBuffer)
bool checkIfCanSendMediaFrame() const override
QPlatformAudioBufferInput * platfromAudioBufferInput() const
QAudioBufferInputPrivate(QAudioBufferInput *q)
void initialize(const QAudioFormat &format={})
void emitReadyToSendMediaFrame() override
\inmodule QtMultimedia
QAudioBufferInput(QObject *parent=nullptr)
Constructs a new QAudioBufferInput object with parent.
bool sendAudioBuffer(const QAudioBuffer &audioBuffer)
Sends \l QAudioBuffer to \l QMediaRecorder through \l QMediaCaptureSession.
QMediaCaptureSession * captureSession() const
Returns the capture session this audio buffer input is connected to, or a nullptr if the audio buffer...
~QAudioBufferInput() override
Destroys the object.
QAudioFormat format() const
Returns the audio format that was specified upon construction of the audio buffer input.
\inmodule QtMultimedia
The QAudioFormat class stores audio stream parameter information.
The QMediaCaptureSession class allows capturing of audio and video content.
void setAudioBufferInput(QAudioBufferInput *input)
void addUpdateSignal(Sender sender, Signal signal)
void removeUpdateSignal(Sender sender, Signal signal)
bool sendMediaFrame(Sender &&sender)
QMediaCaptureSession * captureSession() const
\inmodule QtCore
Definition qobject.h:103
#define this
Definition dialogs.cpp:9
Combined button and popup list for selecting options.
GLint GLsizei GLsizei GLenum format
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
#define emit