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)
281 if (d->captureSession)
282 d->captureSession->setCamera(
nullptr);
284 if (oldCamera->captureSession() && oldCamera->captureSession() !=
this)
285 oldCamera->captureSession()->setCamera(
nullptr);
286 oldCamera->setCaptureSession(
nullptr);
289 if (camera->captureSession())
290 camera->captureSession()->setCamera(
nullptr);
291 if (d->captureSession)
292 d->captureSession->setCamera(camera->platformCamera());
293 camera->setCaptureSession(
this);
295 emit cameraChanged();
324void QMediaCaptureSession::setScreenCapture(QScreenCapture *screenCapture)
326 Q_D(QMediaCaptureSession);
329 QScreenCapture *oldScreenCapture = d->screenCapture;
330 if (oldScreenCapture == screenCapture)
332 d->screenCapture = screenCapture;
333 if (d->captureSession)
334 d->captureSession->setScreenCapture(
nullptr);
335 if (oldScreenCapture) {
336 if (oldScreenCapture->captureSession() && oldScreenCapture->captureSession() !=
this)
337 oldScreenCapture->captureSession()->setScreenCapture(
nullptr);
338 oldScreenCapture->setCaptureSession(
nullptr);
341 if (screenCapture->captureSession())
342 screenCapture->captureSession()->setScreenCapture(
nullptr);
343 if (d->captureSession)
344 d->captureSession->setScreenCapture(screenCapture->platformScreenCapture());
345 screenCapture->setCaptureSession(
this);
347 emit screenCaptureChanged();
375void QMediaCaptureSession::setWindowCapture(QWindowCapture *windowCapture)
377 Q_D(QMediaCaptureSession);
380 QWindowCapture *oldCapture = d->windowCapture;
381 if (oldCapture == windowCapture)
383 d->windowCapture = windowCapture;
384 if (d->captureSession)
385 d->captureSession->setWindowCapture(
nullptr);
387 if (oldCapture->captureSession() && oldCapture->captureSession() !=
this)
388 oldCapture->captureSession()->setWindowCapture(
nullptr);
389 oldCapture->setCaptureSession(
nullptr);
392 if (windowCapture->captureSession())
393 windowCapture->captureSession()->setWindowCapture(
nullptr);
394 if (d->captureSession)
395 d->captureSession->setWindowCapture(windowCapture->platformWindowCapture());
396 windowCapture->setCaptureSession(
this);
398 emit windowCaptureChanged();
414void QMediaCaptureSession::setVideoFrameInput(QVideoFrameInput *input)
416 Q_D(QMediaCaptureSession);
418 QVideoFrameInput *oldInput = d->videoFrameInput;
419 if (oldInput == input)
421 d->videoFrameInput = input;
422 if (d->captureSession)
423 d->captureSession->setVideoFrameInput(
nullptr);
425 if (oldInput->captureSession() && oldInput->captureSession() !=
this)
426 oldInput->captureSession()->setVideoFrameInput(
nullptr);
427 oldInput->setCaptureSession(
nullptr);
430 if (input->captureSession())
431 input->captureSession()->setVideoFrameInput(
nullptr);
432 if (d->captureSession)
433 d->captureSession->setVideoFrameInput(input->platformVideoFrameInput());
434 input->setCaptureSession(
this);
436 emit videoFrameInputChanged();
462void QMediaCaptureSession::setImageCapture(QImageCapture *imageCapture)
464 Q_D(QMediaCaptureSession);
467 QImageCapture *oldImageCapture = d->imageCapture;
468 if (oldImageCapture == imageCapture)
470 d->imageCapture = imageCapture;
471 if (d->captureSession)
472 d->captureSession->setImageCapture(
nullptr);
473 if (oldImageCapture) {
474 if (oldImageCapture->captureSession() && oldImageCapture->captureSession() !=
this)
475 oldImageCapture->captureSession()->setImageCapture(
nullptr);
476 oldImageCapture->setCaptureSession(
nullptr);
479 if (imageCapture->captureSession())
480 imageCapture->captureSession()->setImageCapture(
nullptr);
481 if (d->captureSession)
482 d->captureSession->setImageCapture(imageCapture->platformImageCapture());
483 imageCapture->setCaptureSession(
this);
485 emit imageCaptureChanged();
510void QMediaCaptureSession::setRecorder(QMediaRecorder *recorder)
512 Q_D(QMediaCaptureSession);
513 QMediaRecorder *oldRecorder = d->recorder;
514 if (oldRecorder == recorder)
516 d->recorder = recorder;
517 if (d->captureSession)
518 d->captureSession->setMediaRecorder(
nullptr);
520 if (oldRecorder->captureSession() && oldRecorder->captureSession() !=
this)
521 oldRecorder->captureSession()->setRecorder(
nullptr);
522 oldRecorder->setCaptureSession(
nullptr);
525 if (recorder->captureSession())
526 recorder->captureSession()->setRecorder(
nullptr);
527 if (d->captureSession)
528 d->captureSession->setMediaRecorder(recorder->platformRecoder());
529 recorder->setCaptureSession(
this);
531 emit recorderChanged();
562void QMediaCaptureSession::setVideoOutput(QObject *output)
564 Q_D(QMediaCaptureSession);
565 if (d->videoOutput == output)
567 QVideoSink *sink = qobject_cast<QVideoSink *>(output);
568 if (!sink && output) {
569 auto *mo = output->metaObject();
570 mo->invokeMethod(output,
"videoSink", Q_RETURN_ARG(QVideoSink *, sink));
572 d->videoOutput = output;
573 d->setVideoSink(sink);
604void QMediaCaptureSession::setAudioOutput(QAudioOutput *output)
606 Q_D(QMediaCaptureSession);
608 QAudioOutput *oldOutput = d->audioOutput;
609 if (oldOutput == output)
615 d->audioOutput =
nullptr;
617 if (d->captureSession)
618 d->captureSession->setAudioOutput(
nullptr);
620 oldOutput->setDisconnectFunction({});
622 output->setDisconnectFunction([
this](){ setAudioOutput(
nullptr); });
623 if (d->captureSession)
624 d->captureSession->setAudioOutput(output->handle());
626 d->audioOutput = output;
627 emit audioOutputChanged();