Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwindowscamera.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <mediacapture/qwindowsmediacapture_p.h>
7#include <mediacapture/qwindowsmediadevicesession_p.h>
8
9#include <QtMultimedia/qcameradevice.h>
10
12
17
18QWindowsCamera::~QWindowsCamera() = default;
19
21{
22 return m_active;
23}
24
25void QWindowsCamera::setActive(bool active)
26{
27 if (m_active == active)
28 return;
29 if (m_cameraDevice.isNull() && active)
30 return;
31 m_active = active;
32 if (m_mediaDeviceSession)
33 m_mediaDeviceSession->setActive(active);
34
35 emit activeChanged(m_active);
36}
37
38void QWindowsCamera::setCamera(const QCameraDevice &camera)
39{
40 if (m_cameraDevice == camera)
41 return;
42 m_cameraDevice = camera;
43 if (m_mediaDeviceSession)
44 m_mediaDeviceSession->setActiveCamera(camera);
45}
46
47void QWindowsCamera::setCaptureSession(QPlatformMediaCaptureSession *session)
48{
49 QWindowsMediaCaptureService *captureService = static_cast<QWindowsMediaCaptureService *>(session);
50 if (m_captureService == captureService)
51 return;
52
53 if (m_mediaDeviceSession) {
54 m_mediaDeviceSession->disconnect(this);
55 m_mediaDeviceSession->setActive(false);
56 m_mediaDeviceSession->setCameraFormat({});
57 m_mediaDeviceSession->setActiveCamera({});
58 }
59
60 m_captureService = captureService;
61 if (!m_captureService) {
62 m_mediaDeviceSession = nullptr;
63 return;
64 }
65
66 m_mediaDeviceSession = m_captureService->session();
67 Q_ASSERT(m_mediaDeviceSession);
68
69 m_mediaDeviceSession->setActive(false);
70 m_mediaDeviceSession->setActiveCamera(m_cameraDevice);
71 m_mediaDeviceSession->setCameraFormat(m_cameraFormat);
72 m_mediaDeviceSession->setActive(m_active);
73
74 connect(m_mediaDeviceSession, &QWindowsMediaDeviceSession::activeChanged,
75 this, &QWindowsCamera::onActiveChanged);
76}
77
78bool QWindowsCamera::setCameraFormat(const QCameraFormat &format)
79{
80 if (!format.isNull() && !m_cameraDevice.videoFormats().contains(format))
81 return false;
82
83 m_cameraFormat = format.isNull() ? findBestCameraFormat(m_cameraDevice) : format;
84
85 if (m_mediaDeviceSession)
86 m_mediaDeviceSession->setCameraFormat(m_cameraFormat);
87 return true;
88}
89
90void QWindowsCamera::onActiveChanged(bool active)
91{
92 if (m_active == active)
93 return;
94 if (m_cameraDevice.isNull() && active)
95 return;
96 m_active = active;
97 emit activeChanged(m_active);
98}
99
100QT_END_NAMESPACE
101
102#include "moc_qwindowscamera_p.cpp"
QCamera * camera
The QCamera class provides interface for system camera devices.
Definition qcamera.h:25
bool isActive() const override
void setCamera(const QCameraDevice &camera) override
void setCaptureSession(QPlatformMediaCaptureSession *) override
bool setCameraFormat(const QCameraFormat &format) override
void setActive(bool active) override
QWindowsMediaDeviceSession * session() const
Combined button and popup list for selecting options.