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
qohosvideodevices.cpp
Go to the documentation of this file.
1
// Copyright (C) 2026 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
"qohosvideodevices_p.h"
5
6
#
include
"qohosglobal_p.h"
7
8
#
include
<
private
/
qcameradevice_p
.
h
>
9
10
#
include
<
QtMultimedia
/
qcameradevice
.
h
>
11
#
include
<
QtMultimedia
/
qvideoframeformat
.
h
>
12
13
#
include
<
QtCore
/
qbytearray
.
h
>
14
#
include
<
QtCore
/
qloggingcategory
.
h
>
15
#
include
<
QtCore
/
qstring
.
h
>
16
17
#
include
<
ohcamera
/
camera
.
h
>
18
#
include
<
ohcamera
/
camera_manager
.
h
>
19
20
#
include
<
info
/
application_target_sdk_version
.
h
>
21
22
QT_BEGIN_NAMESPACE
23
24
namespace
{
25
26
QCameraDevice
::
Position
positionFor
(Camera_Position position)
27
{
28
switch
(position) {
29
case
CAMERA_POSITION_FRONT:
30
return
QCameraDevice::FrontFace;
31
case
CAMERA_POSITION_BACK:
32
return
QCameraDevice::BackFace;
33
case
CAMERA_POSITION_UNSPECIFIED:
34
break
;
35
}
36
return
QCameraDevice::UnspecifiedPosition;
37
}
38
39
QString
descriptionFor
(
const
Camera_Device &device)
40
{
41
QString position;
42
switch
(device.cameraPosition) {
43
case
CAMERA_POSITION_FRONT:
44
position = QStringLiteral(
"Front"
);
45
break
;
46
case
CAMERA_POSITION_BACK:
47
position = QStringLiteral(
"Back"
);
48
break
;
49
default
:
50
position = QStringLiteral(
"Camera"
);
51
break
;
52
}
53
QString type;
54
switch
(device.cameraType) {
55
case
CAMERA_TYPE_WIDE_ANGLE:
56
type = QStringLiteral(
"Wide"
);
57
break
;
58
case
CAMERA_TYPE_ULTRA_WIDE:
59
type = QStringLiteral(
"UltraWide"
);
60
break
;
61
case
CAMERA_TYPE_TELEPHOTO:
62
type = QStringLiteral(
"Telephoto"
);
63
break
;
64
case
CAMERA_TYPE_TRUE_DEPTH:
65
type = QStringLiteral(
"TrueDepth"
);
66
break
;
67
case
CAMERA_TYPE_DEFAULT:
68
break
;
69
}
70
return
type.isEmpty() ? position : QStringLiteral(
"%1 (%2)"
).arg(position, type);
71
}
72
73
QVideoFrameFormat::PixelFormat pixelFormatFor(Camera_Format format)
74
{
75
switch
(format) {
76
case
CAMERA_FORMAT_RGBA_8888:
77
return
QVideoFrameFormat::Format_RGBA8888;
78
case
CAMERA_FORMAT_YUV_420_SP:
79
return
QVideoFrameFormat::Format_NV12;
80
case
CAMERA_FORMAT_JPEG:
81
return
QVideoFrameFormat::Format_Jpeg;
82
case
CAMERA_FORMAT_YCBCR_P010:
83
case
CAMERA_FORMAT_YCRCB_P010:
84
#
if
OH_CURRENT_API_VERSION
>=
23
85
case
CAMERA_FORMAT_HEIC:
86
#
endif
87
#
if
OH_CURRENT_API_VERSION
>=
24
88
case
CAMERA_FORMAT_DNG:
89
#
endif
90
#
if
OH_CURRENT_API_VERSION
>=
26
91
case
CAMERA_FORMAT_DNG_XDRAW:
92
#
endif
93
break
;
94
}
95
return
QVideoFrameFormat::Format_Invalid;
96
}
97
98
QList
<
QCameraFormat
>
collectVideoFormats
(Camera_Manager *manager,
const
Camera_Device &device)
99
{
100
QList<QCameraFormat> formats;
101
Camera_OutputCapability *caps =
nullptr
;
102
if
(OH_CameraManager_GetSupportedCameraOutputCapability(manager,
103
const_cast
<Camera_Device *>(&device),
104
&caps)
105
!= CAMERA_OK
106
|| !caps) {
107
return
formats;
108
}
109
110
for
(uint32_t i = 0; i < caps->videoProfilesSize; ++i) {
111
Camera_VideoProfile *profile = caps->videoProfiles[i];
112
if
(!profile)
113
continue
;
114
const
auto
pixelFormat = pixelFormatFor(profile->format);
115
if
(pixelFormat == QVideoFrameFormat::Format_Invalid)
116
continue
;
117
auto
*priv =
new
QCameraFormatPrivate;
118
priv->pixelFormat = pixelFormat;
119
priv->resolution = QSize{
int
(profile->size.width),
int
(profile->size.height) };
120
priv->minFrameRate =
float
(profile->range.min);
121
priv->maxFrameRate =
float
(profile->range.max);
122
formats.append(priv->create());
123
}
124
125
OH_CameraManager_DeleteSupportedCameraOutputCapability(manager, caps);
126
return
formats;
127
}
128
129
}
// namespace
130
131
QOhosVideoDevices::QOhosVideoDevices(QPlatformMediaIntegration *integration)
132
: QPlatformVideoDevices(integration)
133
{
134
}
135
136
QList<QCameraDevice> QOhosVideoDevices::findVideoInputs()
const
137
{
138
Camera_Manager *manager =
nullptr
;
139
if
(OH_Camera_GetCameraManager(&manager) != CAMERA_OK || !manager)
140
return
{};
141
142
Camera_Device *devices =
nullptr
;
143
uint32_t count = 0;
144
if
(OH_CameraManager_GetSupportedCameras(manager, &devices, &count) != CAMERA_OK || !devices) {
145
OH_Camera_DeleteCameraManager(manager);
146
return
{};
147
}
148
149
QList<QCameraDevice> result;
150
result.reserve(count);
151
for
(uint32_t i = 0; i < count; ++i) {
152
const
Camera_Device &dev = devices[i];
153
auto
*priv =
new
QCameraDevicePrivate;
154
priv->id = QByteArray{ dev.cameraId };
155
priv->description = descriptionFor(dev);
156
priv->isDefault = (i == 0);
157
priv->position = positionFor(dev.cameraPosition);
158
priv->videoFormats = collectVideoFormats(manager, dev);
159
result.append(priv->create());
160
}
161
162
OH_CameraManager_DeleteSupportedCameras(manager, devices, count);
163
OH_Camera_DeleteCameraManager(manager);
164
return
result;
165
}
166
167
QT_END_NAMESPACE
168
169
#
include
"moc_qohosvideodevices_p.cpp"
QT_BEGIN_NAMESPACE::collectVideoFormats
QList< QCameraFormat > collectVideoFormats(Camera_Manager *manager, const Camera_Device &device)
Definition
qohosvideodevices.cpp:98
QT_BEGIN_NAMESPACE::positionFor
QCameraDevice::Position positionFor(Camera_Position position)
Definition
qohosvideodevices.cpp:26
QT_BEGIN_NAMESPACE::descriptionFor
QString descriptionFor(const Camera_Device &device)
Definition
qohosvideodevices.cpp:39
qtmultimedia
src
plugins
multimedia
ohos
mediacapture
qohosvideodevices.cpp
Generated on
for Qt by
1.18.0