129QMediaCaptureSession::QMediaCaptureSession(QObject *parent)
130 : QObject{ *
new QMediaCaptureSessionPrivate, parent }
132 Q_D(QMediaCaptureSession);
134 auto maybeCaptureSession = QPlatformMediaIntegration::instance()->createCaptureSession();
135 if (maybeCaptureSession) {
136 d->captureSession.reset(maybeCaptureSession.value());
137 d->captureSession->setCaptureSession(
this);
139 qWarning() <<
"Failed to initialize QMediaCaptureSession" << maybeCaptureSession.error();
184void QMediaCaptureSession::setAudioInput(QAudioInput *input)
186 Q_D(QMediaCaptureSession);
188 QAudioInput *oldInput = d->audioInput;
189 if (oldInput == input)
194 d->audioInput =
nullptr;
196 if (d->captureSession)
197 d->captureSession->setAudioInput(
nullptr);
199 oldInput->setDisconnectFunction({});
201 input->setDisconnectFunction([
this](){ setAudioInput(
nullptr); });
202 if (d->captureSession)
203 d->captureSession->setAudioInput(input->handle());
205 d->audioInput = input;
206 emit audioInputChanged();
222void QMediaCaptureSession::setAudioBufferInput(QAudioBufferInput *input)
224 Q_D(QMediaCaptureSession);
227 QAudioBufferInput *oldInput = d->audioBufferInput;
228 if (oldInput == input)
230 d->audioBufferInput = input;
231 if (d->captureSession)
232 d->captureSession->setAudioBufferInput(
nullptr);
234 if (oldInput->captureSession() && oldInput->captureSession() !=
this)
235 oldInput->captureSession()->setAudioBufferInput(
nullptr);
236 oldInput->setCaptureSession(
nullptr);
239 if (input->captureSession())
240 input->captureSession()->setAudioBufferInput(
nullptr);
241 if (d->captureSession)
242 d->captureSession->setAudioBufferInput(input->platformAudioBufferInput());
243 input->setCaptureSession(
this);
245 emit audioBufferInputChanged();
272void QMediaCaptureSession::setCamera(QCamera *camera)
274 Q_D(QMediaCaptureSession);
277 QCamera *oldCamera = d->camera;
278 if (oldCamera == camera)
282 && !QPlatformMediaIntegration::instance()->isCameraSwitchingDuringRecordingSupported()
283 && recorder() && recorder()->recorderState() == QMediaRecorder::RecordingState) {
284 qWarning(
"This media backend does not support camera switching during recording");
289 if (d->captureSession)
290 d->captureSession->setCamera(
nullptr);
292 if (oldCamera->captureSession() && oldCamera->captureSession() !=
this)
293 oldCamera->captureSession()->setCamera(
nullptr);
294 oldCamera->setCaptureSession(
nullptr);
297 if (camera->captureSession())
298 camera->captureSession()->setCamera(
nullptr);
299 if (d->captureSession)
300 d->captureSession->setCamera(camera->platformCamera());
301 camera->setCaptureSession(
this);
303 emit cameraChanged();
332void QMediaCaptureSession::setScreenCapture(QScreenCapture *screenCapture)
334 Q_D(QMediaCaptureSession);
337 QScreenCapture *oldScreenCapture = d->screenCapture;
338 if (oldScreenCapture == screenCapture)
340 d->screenCapture = screenCapture;
341 if (d->captureSession)
342 d->captureSession->setScreenCapture(
nullptr);
343 if (oldScreenCapture) {
344 if (oldScreenCapture->captureSession() && oldScreenCapture->captureSession() !=
this)
345 oldScreenCapture->captureSession()->setScreenCapture(
nullptr);
346 oldScreenCapture->setCaptureSession(
nullptr);
349 if (screenCapture->captureSession())
350 screenCapture->captureSession()->setScreenCapture(
nullptr);
351 if (d->captureSession)
352 d->captureSession->setScreenCapture(screenCapture->platformScreenCapture());
353 screenCapture->setCaptureSession(
this);
355 emit screenCaptureChanged();
383void QMediaCaptureSession::setWindowCapture(QWindowCapture *windowCapture)
385 Q_D(QMediaCaptureSession);
388 QWindowCapture *oldCapture = d->windowCapture;
389 if (oldCapture == windowCapture)
391 d->windowCapture = windowCapture;
392 if (d->captureSession)
393 d->captureSession->setWindowCapture(
nullptr);
395 if (oldCapture->captureSession() && oldCapture->captureSession() !=
this)
396 oldCapture->captureSession()->setWindowCapture(
nullptr);
397 oldCapture->setCaptureSession(
nullptr);
400 if (windowCapture->captureSession())
401 windowCapture->captureSession()->setWindowCapture(
nullptr);
402 if (d->captureSession)
403 d->captureSession->setWindowCapture(windowCapture->platformWindowCapture());
404 windowCapture->setCaptureSession(
this);
406 emit windowCaptureChanged();
422void QMediaCaptureSession::setVideoFrameInput(QVideoFrameInput *input)
424 Q_D(QMediaCaptureSession);
426 QVideoFrameInput *oldInput = d->videoFrameInput;
427 if (oldInput == input)
429 d->videoFrameInput = input;
430 if (d->captureSession)
431 d->captureSession->setVideoFrameInput(
nullptr);
433 if (oldInput->captureSession() && oldInput->captureSession() !=
this)
434 oldInput->captureSession()->setVideoFrameInput(
nullptr);
435 oldInput->setCaptureSession(
nullptr);
438 if (input->captureSession())
439 input->captureSession()->setVideoFrameInput(
nullptr);
440 if (d->captureSession)
441 d->captureSession->setVideoFrameInput(input->platformVideoFrameInput());
442 input->setCaptureSession(
this);
444 emit videoFrameInputChanged();
470void QMediaCaptureSession::setImageCapture(QImageCapture *imageCapture)
472 Q_D(QMediaCaptureSession);
475 QImageCapture *oldImageCapture = d->imageCapture;
476 if (oldImageCapture == imageCapture)
478 d->imageCapture = imageCapture;
479 if (d->captureSession)
480 d->captureSession->setImageCapture(
nullptr);
481 if (oldImageCapture) {
482 if (oldImageCapture->captureSession() && oldImageCapture->captureSession() !=
this)
483 oldImageCapture->captureSession()->setImageCapture(
nullptr);
484 oldImageCapture->setCaptureSession(
nullptr);
487 if (imageCapture->captureSession())
488 imageCapture->captureSession()->setImageCapture(
nullptr);
489 if (d->captureSession)
490 d->captureSession->setImageCapture(imageCapture->platformImageCapture());
491 imageCapture->setCaptureSession(
this);
493 emit imageCaptureChanged();
518void QMediaCaptureSession::setRecorder(QMediaRecorder *recorder)
520 Q_D(QMediaCaptureSession);
521 QMediaRecorder *oldRecorder = d->recorder;
522 if (oldRecorder == recorder)
524 d->recorder = recorder;
525 if (d->captureSession)
526 d->captureSession->setMediaRecorder(
nullptr);
528 if (oldRecorder->captureSession() && oldRecorder->captureSession() !=
this)
529 oldRecorder->captureSession()->setRecorder(
nullptr);
530 oldRecorder->setCaptureSession(
nullptr);
533 if (recorder->captureSession())
534 recorder->captureSession()->setRecorder(
nullptr);
535 if (d->captureSession)
536 d->captureSession->setMediaRecorder(recorder->platformRecoder());
537 recorder->setCaptureSession(
this);
539 emit recorderChanged();
570void QMediaCaptureSession::setVideoOutput(QObject *output)
572 Q_D(QMediaCaptureSession);
573 if (d->videoOutput == output)
575 QVideoSink *sink = qobject_cast<QVideoSink *>(output);
576 if (!sink && output) {
577 auto *mo = output->metaObject();
578 mo->invokeMethod(output,
"videoSink", Q_RETURN_ARG(QVideoSink *, sink));
580 d->videoOutput = output;
581 d->setVideoSink(sink);
612void QMediaCaptureSession::setAudioOutput(QAudioOutput *output)
614 Q_D(QMediaCaptureSession);
616 QAudioOutput *oldOutput = d->audioOutput;
617 if (oldOutput == output)
623 d->audioOutput =
nullptr;
625 if (d->captureSession)
626 d->captureSession->setAudioOutput(
nullptr);
628 oldOutput->setDisconnectFunction({});
630 output->setDisconnectFunction([
this](){ setAudioOutput(
nullptr); });
631 if (d->captureSession)
632 d->captureSession->setAudioOutput(output->handle());
634 d->audioOutput = output;
635 emit audioOutputChanged();