25 Q_Q(QMediaCaptureSession);
27 if (sink == videoSink)
30 videoSink->setSource(
nullptr);
35 captureSession->setVideoPreview(sink);
36 emit q->videoOutputChanged();
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
127struct QMediaCaptureSession::ObjectTraits<QCamera>
129 static constexpr auto Member = &QMediaCaptureSessionPrivate::camera;
130 static constexpr auto Setter = &QMediaCaptureSession::setCamera;
131 static constexpr auto PlatformSetter = &QPlatformMediaCaptureSession::setCamera;
132 static constexpr auto PlatformObjectProvider = &QCamera::platformCamera;
133 static constexpr auto ChangeNotifier = &QMediaCaptureSession::cameraChanged;
137struct QMediaCaptureSession::ObjectTraits<QScreenCapture>
139 static constexpr auto Member = &QMediaCaptureSessionPrivate::screenCapture;
140 static constexpr auto Setter = &QMediaCaptureSession::setScreenCapture;
141 static constexpr auto PlatformSetter = &QPlatformMediaCaptureSession::setScreenCapture;
142 static constexpr auto PlatformObjectProvider = &QScreenCapture::platformScreenCapture;
143 static constexpr auto ChangeNotifier = &QMediaCaptureSession::screenCaptureChanged;
147struct QMediaCaptureSession::ObjectTraits<QWindowCapture>
149 static constexpr auto Member = &QMediaCaptureSessionPrivate::windowCapture;
150 static constexpr auto Setter = &QMediaCaptureSession::setWindowCapture;
151 static constexpr auto PlatformSetter = &QPlatformMediaCaptureSession::setWindowCapture;
152 static constexpr auto PlatformObjectProvider = &QWindowCapture::platformWindowCapture;
153 static constexpr auto ChangeNotifier = &QMediaCaptureSession::windowCaptureChanged;
157struct QMediaCaptureSession::ObjectTraits<QVideoFrameInput>
159 static constexpr auto Member = &QMediaCaptureSessionPrivate::videoFrameInput;
160 static constexpr auto Setter = &QMediaCaptureSession::setVideoFrameInput;
161 static constexpr auto PlatformSetter = &QPlatformMediaCaptureSession::setVideoFrameInput;
162 static constexpr auto PlatformObjectProvider = &QVideoFrameInput::platformVideoFrameInput;
163 static constexpr auto ChangeNotifier = &QMediaCaptureSession::videoFrameInputChanged;
167struct QMediaCaptureSession::ObjectTraits<QAudioBufferInput>
169 static constexpr auto Member = &QMediaCaptureSessionPrivate::audioBufferInput;
170 static constexpr auto Setter = &QMediaCaptureSession::setAudioBufferInput;
171 static constexpr auto PlatformSetter = &QPlatformMediaCaptureSession::setAudioBufferInput;
172 static constexpr auto PlatformObjectProvider = &QAudioBufferInput::platformAudioBufferInput;
173 static constexpr auto ChangeNotifier = &QMediaCaptureSession::audioBufferInputChanged;
177struct QMediaCaptureSession::ObjectTraits<QImageCapture>
179 static constexpr auto Member = &QMediaCaptureSessionPrivate::imageCapture;
180 static constexpr auto Setter = &QMediaCaptureSession::setImageCapture;
181 static constexpr auto PlatformSetter = &QPlatformMediaCaptureSession::setImageCapture;
182 static constexpr auto PlatformObjectProvider = &QImageCapture::platformImageCapture;
183 static constexpr auto ChangeNotifier = &QMediaCaptureSession::imageCaptureChanged;
187struct QMediaCaptureSession::ObjectTraits<QMediaRecorder>
189 static constexpr auto Member = &QMediaCaptureSessionPrivate::recorder;
190 static constexpr auto Setter = &QMediaCaptureSession::setRecorder;
191 static constexpr auto PlatformSetter = &QPlatformMediaCaptureSession::setMediaRecorder;
192 static constexpr auto PlatformObjectProvider = &QMediaRecorder::platformRecoder;
193 static constexpr auto ChangeNotifier = &QMediaCaptureSession::recorderChanged;
196template <
typename Object>
197void QMediaCaptureSession::setObject(Object *object) {
198 Q_D(QMediaCaptureSession);
200 using Traits = QMediaCaptureSession::ObjectTraits<Object>;
202 Object *oldObject = d->*Traits::Member;
203 if (oldObject == object)
206 d->*Traits::Member = object;
208 if (d->captureSession)
209 std::invoke(Traits::PlatformSetter, d->captureSession,
nullptr);
212 if (oldObject->captureSession() && oldObject->captureSession() !=
this)
213 std::invoke(Traits::Setter, oldObject->captureSession(),
nullptr);
214 oldObject->setCaptureSession(
nullptr);
218 if (
auto *otherSession = object->captureSession())
219 std::invoke(Traits::Setter, otherSession,
nullptr);
220 if (d->captureSession)
221 std::invoke(Traits::PlatformSetter, d->captureSession,
222 std::invoke(Traits::PlatformObjectProvider, object));
223 object->setCaptureSession(
this);
226 emit (
this->*Traits::ChangeNotifier)();
230
231
232QMediaCaptureSession::QMediaCaptureSession(QObject *parent)
233 : QObject{ *
new QMediaCaptureSessionPrivate, parent }
235 Q_D(QMediaCaptureSession);
237 auto maybeCaptureSession = QPlatformMediaIntegration::instance()->createCaptureSession();
238 if (maybeCaptureSession) {
239 d->captureSession.reset(maybeCaptureSession.value());
240 d->captureSession->setCaptureSession(
this);
242 qWarning() <<
"Failed to initialize QMediaCaptureSession" << maybeCaptureSession.error();
247
248
249QMediaCaptureSession::~QMediaCaptureSession()
251 Q_D(QMediaCaptureSession);
254 setRecorder(
nullptr);
255 setImageCapture(
nullptr);
256 setScreenCapture(
nullptr);
257 setWindowCapture(
nullptr);
258 setVideoFrameInput(
nullptr);
259 setAudioBufferInput(
nullptr);
260 setAudioInput(
nullptr);
261 setAudioOutput(
nullptr);
262 d->setVideoSink(
nullptr);
263 d->captureSession.reset();
266
267
268
269
272
273
274
275
276QAudioInput *QMediaCaptureSession::audioInput()
const
278 Q_D(
const QMediaCaptureSession);
279 return d->audioInput;
283
284
285
286
287void QMediaCaptureSession::setAudioInput(QAudioInput *input)
289 Q_D(QMediaCaptureSession);
291 QAudioInput *oldInput = d->audioInput;
292 if (oldInput == input)
297 d->audioInput =
nullptr;
300 if (d->captureSession)
301 d->captureSession->setAudioInput(
nullptr);
303 oldInput->setDisconnectFunction({});
305 input->setDisconnectFunction([
this](){ setAudioInput(
nullptr); });
306 if (d->captureSession)
307 d->captureSession->setAudioInput(input->handle());
309 d->audioInput = input;
310 emit audioInputChanged();
314
315
316
317
318
319QAudioBufferInput *QMediaCaptureSession::audioBufferInput()
const
321 Q_D(
const QMediaCaptureSession);
323 return d->audioBufferInput;
326void QMediaCaptureSession::setAudioBufferInput(QAudioBufferInput *input)
332
333
334
335
336
337
338
341
342
343
344
345
346
347
348QCamera *QMediaCaptureSession::camera()
const
350 Q_D(
const QMediaCaptureSession);
354void QMediaCaptureSession::setCamera(QCamera *camera)
356 Q_D(QMediaCaptureSession);
359 && d->camera != camera
360 && !QPlatformMediaIntegration::instance()->isCameraSwitchingDuringRecordingSupported()
361 && recorder() && recorder()->recorderState() == QMediaRecorder::RecordingState) {
362 qWarning(
"This media backend does not support camera switching during recording");
370
371
372
373
374
375
376
377
380
381
382
383
384
385
386
387
388QScreenCapture *QMediaCaptureSession::screenCapture()
390 Q_D(QMediaCaptureSession);
391 return d->screenCapture;
394void QMediaCaptureSession::setScreenCapture(QScreenCapture *screenCapture)
396 setObject(screenCapture);
400
401
402
403
404
405
406
407
410
411
412
413
414
415
416
417
418QWindowCapture *QMediaCaptureSession::windowCapture()
420 Q_D(QMediaCaptureSession);
421 return d->windowCapture;
424void QMediaCaptureSession::setWindowCapture(QWindowCapture *windowCapture)
426 setObject(windowCapture);
430
431
432
433
434
435
436QVideoFrameInput *QMediaCaptureSession::videoFrameInput()
const
438 Q_D(
const QMediaCaptureSession);
439 return d->videoFrameInput;
442void QMediaCaptureSession::setVideoFrameInput(QVideoFrameInput *input)
448
449
450
451
452
453
454
456
457
458
459
460
461
462
463QImageCapture *QMediaCaptureSession::imageCapture()
465 Q_D(QMediaCaptureSession);
466 return d->imageCapture;
469void QMediaCaptureSession::setImageCapture(QImageCapture *imageCapture)
471 setObject(imageCapture);
474
475
476
477
478
479
480
482
483
484
485
486
487
488
490QMediaRecorder *QMediaCaptureSession::recorder()
492 Q_D(QMediaCaptureSession);
496void QMediaCaptureSession::setRecorder(QMediaRecorder *recorder)
501
502
503
504
505
506
507
508
509
510
512
513
514
515
516QObject *QMediaCaptureSession::videoOutput()
const
518 Q_D(
const QMediaCaptureSession);
519 return d->videoOutput;
522
523
524
525
526
527
528
529void QMediaCaptureSession::setVideoOutput(QObject *output)
531 Q_D(QMediaCaptureSession);
532 if (d->videoOutput == output)
534 QVideoSink *sink = qobject_cast<QVideoSink *>(output);
535 if (!sink && output) {
536 auto *mo = output->metaObject();
537 mo->invokeMethod(output,
"videoSink", Q_RETURN_ARG(QVideoSink *, sink));
539 d->videoOutput = output;
540 d->setVideoSink(sink);
544
545
546
547
548
549
550
551void QMediaCaptureSession::setVideoSink(QVideoSink *sink)
553 Q_D(QMediaCaptureSession);
554 d->videoOutput =
nullptr;
555 d->setVideoSink(sink);
559
560
561QVideoSink *QMediaCaptureSession::videoSink()
const
563 Q_D(
const QMediaCaptureSession);
567
568
569
570
571void QMediaCaptureSession::setAudioOutput(QAudioOutput *output)
573 Q_D(QMediaCaptureSession);
575 QAudioOutput *oldOutput = d->audioOutput;
576 if (oldOutput == output)
582 d->audioOutput =
nullptr;
584 if (d->captureSession)
585 d->captureSession->setAudioOutput(
nullptr);
587 oldOutput->setDisconnectFunction({});
589 output->setDisconnectFunction([
this](){ setAudioOutput(
nullptr); });
590 if (d->captureSession)
591 d->captureSession->setAudioOutput(output->handle());
593 d->audioOutput = output;
594 emit audioOutputChanged();
597
598
599
600
601
602
604
605
606
607
608QAudioOutput *QMediaCaptureSession::audioOutput()
const
610 Q_D(
const QMediaCaptureSession);
611 return d->audioOutput;
615
616
617QPlatformMediaCaptureSession *QMediaCaptureSession::platformSession()
const
619 Q_D(
const QMediaCaptureSession);
620 return d->captureSession.get();
623
624
625
626
629
630
631
632
635
636
637
638
641
642
643
644
647
648
649
650
653
654
655
656
659#include "moc_qmediacapturesession.cpp"
Combined button and popup list for selecting options.