QAudioBufferInput 类

QAudioBufferInput 类用于提供自定义音频缓冲为 QMediaRecorder 透过 QMediaCaptureSession . 更多...

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

公共函数

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 )

信号

void readyToSendAudioBuffer ()

详细描述

QAudioBufferInput 仅支持采用 FFmpeg 后端。

Custom audio buffers can be recorded by connecting a QAudioBufferInput QMediaRecorder QMediaCaptureSession . For a pull mode implementation, call sendAudioBuffer () in response to the readyToSendAudioBuffer () signal. In the snippet below this is done by connecting the signal to a slot in a custom media generator class. The slot function emits another signal with a new audio buffer, which is connected to sendAudioBuffer ():

QMediaCaptureSession session;
QMediaRecorder recorder;
QAudioBufferInput audioInput;
session.setRecorder(&recorder);
session.setAudioBufferInput(&audioInput);
MediaGenerator generator; // Custom class providing audio buffers
connect(&audioInput, &QAudioBufferInput::readyToSendAudioBuffer,
        &generator, &MediaGenerator::nextAudioBuffer);
connect(&generator, &MediaGenerator::audioBufferReady,
        &audioInput, &QAudioBufferInput::sendAudioBuffer);
recorder.record();
					

Here's a minimal implementation of the slot function that provides audio buffers:

void MediaGenerator::nextAudioBuffer()
{
    QAudioBuffer buffer = nextBuffer();
    emit audioBufferReady(buffer);
}
					

更多细节见 readyToSendAudioBuffer () 和 sendAudioBuffer ().

另请参阅 QMediaRecorder and QMediaCaptureSession .

成员函数文档编制

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

构造新的 QAudioBufferInput 对象采用 parent .

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

构造新的 QAudioBufferInput 对象采用音频 format and parent .

指定 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 ()

销毁对象。

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.

使用 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 .

另请参阅 sendAudioBuffer ().

bool QAudioBufferInput:: sendAudioBuffer (const QAudioBuffer & audioBuffer )

发送 QAudioBuffer to QMediaRecorder 透过 QMediaCaptureSession .

返回 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.