QAudioBufferInput Class

The QAudioBufferInput class is used for providing custom audio buffers to QMediaRecorder through QMediaCaptureSession. More...

Header: #include <QAudioBufferInput>
CMake: find_package(Qt6 REQUIRED COMPONENTS Multimedia)
target_link_libraries(mytarget PRIVATE Qt6::Multimedia)
qmake: QT += multimedia
Since: Qt 6.8
Inherits: QObject

Public Functions

QAudioBufferInput(QObject *parent = nullptr)
QAudioBufferInput(const QAudioFormat &format, QObject *parent = nullptr)
virtual ~QAudioBufferInput() override
QMediaCaptureSession *captureSession() const
QAudioFormat format() const
bool sendAudioBuffer(const QAudioBuffer &audioBuffer)


Detailed Description

See also QMediaRecorder and QMediaCaptureSession.

Member Function Documentation

[explicit] QAudioBufferInput::QAudioBufferInput(QObject *parent = nullptr)

Constructs a new QAudioBufferInput object with parent.

[explicit] QAudioBufferInput::QAudioBufferInput(const QAudioFormat &format, QObject *parent = nullptr)

Constructs a new QAudioBufferInput object with audio format and parent.

The specified format will work as a hint for the initialization of the matching audio encoder upon invoking QMediaRecorder::record(). If the format is not specified or not valid, the audio encoder will be initialized upon sending the first audio buffer.

We recommend specifying the format if you know in advance what kind of audio buffers you're going to send.

[override virtual noexcept] QAudioBufferInput::~QAudioBufferInput()

Destroys the object.

QMediaCaptureSession *QAudioBufferInput::captureSession() const

Returns the capture session this audio buffer input is connected to, or a nullptr if the audio buffer input is not connected to a capture session.

Use QMediaCaptureSession::setAudioBufferInput() to connect the audio buffer input to a session.

QAudioFormat QAudioBufferInput::format() const

Returns the audio format that was specified upon construction of the audio buffer input.

[signal] void QAudioBufferInput::readyToSendAudioBuffer()

Signals that a new audio buffer can be sent to the audio buffer input. After receiving the signal, if you have audio date to be sent, invoke sendAudioBuffer once or in a loop until it returns false.

See also sendAudioBuffer().

bool QAudioBufferInput::sendAudioBuffer(const QAudioBuffer &audioBuffer)

Sends QAudioBuffer to QMediaRecorder through QMediaCaptureSession.

Returns true if the specified audioBuffer has been sent successfully to the destination. Returns false, if the buffer hasn't been sent, which can happen if the instance is not assigned to QMediaCaptureSession, the session doesn't have a media recorder, the media recorder is not started or its queue is full. The readyToSendAudioBuffer() signal will be emitted as soon as the destination is able to handle a new audio buffer.

Sending of an empty audio buffer is treated by QMediaRecorder as an end of the input stream. QMediaRecorder stops the recording automatically if QMediaRecorder::autoStop is true and all the inputs have reported the end of the stream.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.