6#include "private/qplatformaudioinput_p.h"
7#include "private/qplatformaudiooutput_p.h"
8#include "private/qplatformsurfacecapture_p.h"
11#include "private/qplatformcamera_p.h"
22static Q_LOGGING_CATEGORY(qLcFFmpegMediaCaptureSession,
"qt.multimedia.ffmpeg.mediacapturesession")
28 constexpr int BufferSizeFactor = 2;
29 constexpr int BufferSizeExceeding = 4096;
31 return input.bufferSize() * BufferSizeFactor + BufferSizeExceeding;
37 &QFFmpegMediaCaptureSession::updateVideoFrameConnection);
49 if (setVideoSource(m_camera,
camera))
55 return m_screenCapture;
66 return m_windowCapture;
77 return m_imageCapture;
99 if (m_mediaRecorder ==
r)
113 return m_mediaRecorder;
118 qCDebug(qLcFFmpegMediaCaptureSession)
119 <<
"set audio input:" << (
input ?
input->device.description() :
"null");
124 if (m_audioInput == ffmpegAudioInput)
130 m_audioInput = ffmpegAudioInput;
134 &QFFmpegMediaCaptureSession::updateAudioSink);
139void QFFmpegMediaCaptureSession::updateAudioSink()
142 m_audioSink->reset();
146 if (!m_audioInput || !m_audioOutput)
152 qWarning() <<
"Audio source format" <<
format <<
"is not compatible with the audio output";
154 m_audioSink = std::make_unique<QAudioSink>(m_audioOutput->
device,
format);
156 m_audioBufferSize = preferredAudioSinkBufferSize(*m_audioInput);
157 m_audioSink->setBufferSize(m_audioBufferSize);
159 qCDebug(qLcFFmpegMediaCaptureSession)
160 <<
"Create audiosink, format:" <<
format <<
"bufferSize:" << m_audioSink->bufferSize()
163 m_audioIODevice = m_audioSink->start();
164 if (m_audioIODevice) {
167 if (m_audioBufferSize < preferredAudioSinkBufferSize(*m_audioInput)) {
168 qCDebug(qLcFFmpegMediaCaptureSession)
169 <<
"Recreate audiosink due to small buffer size:"
170 << m_audioBufferSize;
178 if (written <
buffer.byteCount())
180 <<
"Not all bytes written:" << written <<
"vs"
184 qWarning() <<
"Failed to start audiosink push mode";
190void QFFmpegMediaCaptureSession::updateVolume()
193 m_audioSink->setVolume(m_audioOutput->
muted ? 0.f : m_audioOutput->volume);
203 if (std::exchange(m_videoSink,
sink) ==
sink)
206 updateVideoFrameConnection();
211 qCDebug(qLcFFmpegMediaCaptureSession)
212 <<
"set audio output:" << (
output ?
output->device.description() :
"null");
214 if (m_audioOutput ==
output)
224 &QFFmpegMediaCaptureSession::updateAudioSink);
226 &QFFmpegMediaCaptureSession::updateVolume);
228 &QFFmpegMediaCaptureSession::updateVolume);
234void QFFmpegMediaCaptureSession::updateVideoFrameConnection()
238 if (m_primaryActiveVideoSource && m_videoSink) {
242 m_videoFrameConnection =
248void QFFmpegMediaCaptureSession::updatePrimaryActiveVideoSource()
252 if (std::exchange(m_primaryActiveVideoSource,
source) !=
source)
256template<
typename V
ideoSource>
258 VideoSource *newSource)
263 if (
auto prevSource = std::exchange(
source, newSource)) {
264 prevSource->setCaptureSession(
nullptr);
265 prevSource->disconnect(
this);
269 source->setCaptureSession(
this);
271 &QFFmpegMediaCaptureSession::updatePrimaryActiveVideoSource);
276 updatePrimaryActiveVideoSource();
283 return m_primaryActiveVideoSource;
288#include "moc_qffmpegmediacapturesession_p.cpp"
bool isFormatSupported(const QAudioFormat &format) const
Returns true if the supplied settings are supported by the audio device described by this QAudioDevic...
QString description
\qmlproperty string QtMultimedia::audioDevice::description
QAudioFormat preferredFormat() const
Returns the default audio format settings for this device.
void mutedChanged(bool muted)
void volumeChanged(float volume)
void setCaptureSession(QPlatformMediaCaptureSession *session)
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
The QVideoSink class represents a generic sink for video data.
void setVideoFrame(const QVideoFrame &frame)
Sets the current video frame.
Combined button and popup list for selecting options.
#define Q_LOGGING_CATEGORY(name,...)
#define qCWarning(category,...)
#define qCDebug(category,...)
GLint GLsizei GLsizei GLenum format
GLsizei GLsizei GLchar * source
GLsizei GLenum GLboolean sink
GLenum GLenum GLenum input
QT_BEGIN_NAMESPACE typedef uchar * output
myObject disconnect()
[26]