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
8#include <qcameradevice.h>
9
11
13 : QPlatformCamera(camera)
14{
15}
16
17QWindowsCamera::~QWindowsCamera() = default;
18
19bool QWindowsCamera::isActive() const
20{
21 return m_active;
22}
23
24void QWindowsCamera::setActive(bool active)
25{
26 if (m_active == active)
27 return;
28 if (m_cameraDevice.isNull() && active)
29 return;
30 m_active = active;
31 if (m_mediaDeviceSession)
32 m_mediaDeviceSession->setActive(active);
33
34 emit activeChanged(m_active);
35}
36
37void QWindowsCamera::setCamera(const QCameraDevice &camera)
38{
39 if (m_cameraDevice == camera)
40 return;
41 m_cameraDevice = camera;
42 if (m_mediaDeviceSession)
43 m_mediaDeviceSession->setActiveCamera(camera);
44}
45
46void QWindowsCamera::setCaptureSession(QPlatformMediaCaptureSession *session)
47{
48 QWindowsMediaCaptureService *captureService = static_cast<QWindowsMediaCaptureService *>(session);
49 if (m_captureService == captureService)
50 return;
51
52 if (m_mediaDeviceSession) {
53 m_mediaDeviceSession->disconnect(this);
54 m_mediaDeviceSession->setActive(false);
55 m_mediaDeviceSession->setCameraFormat({});
56 m_mediaDeviceSession->setActiveCamera({});
57 }
58
59 m_captureService = captureService;
60 if (!m_captureService) {
61 m_mediaDeviceSession = nullptr;
62 return;
63 }
64
65 m_mediaDeviceSession = m_captureService->session();
66 Q_ASSERT(m_mediaDeviceSession);
67
68 m_mediaDeviceSession->setActive(false);
69 m_mediaDeviceSession->setActiveCamera(m_cameraDevice);
70 m_mediaDeviceSession->setCameraFormat(m_cameraFormat);
71 m_mediaDeviceSession->setActive(m_active);
72
73 connect(m_mediaDeviceSession, &QWindowsMediaDeviceSession::activeChanged,
74 this, &QWindowsCamera::onActiveChanged);
75}
76
77bool QWindowsCamera::setCameraFormat(const QCameraFormat &format)
78{
79 if (!format.isNull() && !m_cameraDevice.videoFormats().contains(format))
80 return false;
81
82 m_cameraFormat = format.isNull() ? findBestCameraFormat(m_cameraDevice) : format;
83
84 if (m_mediaDeviceSession)
85 m_mediaDeviceSession->setCameraFormat(m_cameraFormat);
86 return true;
87}
88
89void QWindowsCamera::onActiveChanged(bool active)
90{
91 if (m_active == active)
92 return;
93 if (m_cameraDevice.isNull() && active)
94 return;
95 m_active = active;
96 emit activeChanged(m_active);
97}
98
99QT_END_NAMESPACE
100
101#include "moc_qwindowscamera_p.cpp"
The QCamera class provides interface for system camera devices.
Definition qcamera.h:25
bool setCameraFormat(const QCameraFormat &) override
bool isActive() const override
void setActive(bool active) override
QWindowsMediaDeviceSession * session() const
void setActiveCamera(const QCameraDevice &camera)