Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
4
#
include
"qwindowscamera_p.h"
5
6
#
include
<
mediacapture
/
qwindowsmediacapture_p
.
h
>
7
#
include
<
mediacapture
/
qwindowsmediadevicesession_p
.
h
>
8
9
#
include
<
QtMultimedia
/
qcameradevice
.
h
>
10
11
QT_BEGIN_NAMESPACE
12
13
QWindowsCamera
::
QWindowsCamera
(
QCamera
*
camera
)
14
:
QPlatformCamera
(
camera
)
15
{
16
}
17
18
QWindowsCamera::~QWindowsCamera() =
default
;
19
20
bool
QWindowsCamera
::
isActive
()
const
21
{
22
return
m_active;
23
}
24
25
void
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
Q_EMIT activeChanged(m_active);
36
}
37
38
void
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
47
void
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
78
bool
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
90
void
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
Q_EMIT activeChanged(m_active);
98
}
99
100
QT_END_NAMESPACE
101
102
#
include
"moc_qwindowscamera_p.cpp"
camera
QCamera * camera
Definition
camerasnippets.cpp:19
QCamera
The QCamera class provides interface for system camera devices.
Definition
qcamera.h:25
QWindowsCamera
Definition
qwindowscamera_p.h:26
QWindowsCamera::isActive
bool isActive() const override
Definition
qwindowscamera.cpp:20
QWindowsCamera::setCamera
void setCamera(const QCameraDevice &camera) override
Definition
qwindowscamera.cpp:38
QWindowsCamera::setCaptureSession
void setCaptureSession(QPlatformMediaCaptureSession *) override
Definition
qwindowscamera.cpp:47
QWindowsCamera::setCameraFormat
bool setCameraFormat(const QCameraFormat &format) override
Definition
qwindowscamera.cpp:78
QWindowsCamera::setActive
void setActive(bool active) override
Definition
qwindowscamera.cpp:25
QWindowsMediaCaptureService
Definition
qwindowsmediacapture_p.h:29
QWindowsMediaCaptureService::session
QWindowsMediaDeviceSession * session() const
Definition
qwindowsmediacapture.cpp:104
QWindowsMediaDeviceSession::setActive
void setActive(bool active)
Definition
qwindowsmediadevicesession.cpp:56
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtmultimedia
src
plugins
multimedia
windows
mediacapture
qwindowscamera.cpp
Generated on
for Qt by
1.18.0