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
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
5
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
22QT_BEGIN_NAMESPACE
23
24namespace {
25
26QCameraDevice::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
39QString 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
73QVideoFrameFormat::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 break;
88 }
89 return QVideoFrameFormat::Format_Invalid;
90}
91
92QList<QCameraFormat> collectVideoFormats(Camera_Manager *manager, const Camera_Device &device)
93{
94 QList<QCameraFormat> formats;
95 Camera_OutputCapability *caps = nullptr;
96 if (OH_CameraManager_GetSupportedCameraOutputCapability(manager,
97 const_cast<Camera_Device *>(&device),
98 &caps)
99 != CAMERA_OK
100 || !caps) {
101 return formats;
102 }
103
104 for (uint32_t i = 0; i < caps->videoProfilesSize; ++i) {
105 Camera_VideoProfile *profile = caps->videoProfiles[i];
106 if (!profile)
107 continue;
108 const auto pixelFormat = pixelFormatFor(profile->format);
109 if (pixelFormat == QVideoFrameFormat::Format_Invalid)
110 continue;
111 auto *priv = new QCameraFormatPrivate;
112 priv->pixelFormat = pixelFormat;
113 priv->resolution = QSize{ int(profile->size.width), int(profile->size.height) };
114 priv->minFrameRate = float(profile->range.min);
115 priv->maxFrameRate = float(profile->range.max);
116 formats.append(priv->create());
117 }
118
119 OH_CameraManager_DeleteSupportedCameraOutputCapability(manager, caps);
120 return formats;
121}
122
123} // namespace
124
125QOhosVideoDevices::QOhosVideoDevices(QPlatformMediaIntegration *integration)
126 : QPlatformVideoDevices(integration)
127{
128}
129
130QList<QCameraDevice> QOhosVideoDevices::findVideoInputs() const
131{
132 Camera_Manager *manager = nullptr;
133 if (OH_Camera_GetCameraManager(&manager) != CAMERA_OK || !manager)
134 return {};
135
136 Camera_Device *devices = nullptr;
137 uint32_t count = 0;
138 if (OH_CameraManager_GetSupportedCameras(manager, &devices, &count) != CAMERA_OK || !devices) {
139 OH_Camera_DeleteCameraManager(manager);
140 return {};
141 }
142
143 QList<QCameraDevice> result;
144 result.reserve(count);
145 for (uint32_t i = 0; i < count; ++i) {
146 const Camera_Device &dev = devices[i];
147 auto *priv = new QCameraDevicePrivate;
148 priv->id = QByteArray{ dev.cameraId };
149 priv->description = descriptionFor(dev);
150 priv->isDefault = (i == 0);
151 priv->position = positionFor(dev.cameraPosition);
152 priv->videoFormats = collectVideoFormats(manager, dev);
153 result.append(priv->create());
154 }
155
156 OH_CameraManager_DeleteSupportedCameras(manager, devices, count);
157 OH_Camera_DeleteCameraManager(manager);
158 return result;
159}
160
161QT_END_NAMESPACE
162
163#include "moc_qohosvideodevices_p.cpp"
QList< QCameraFormat > collectVideoFormats(Camera_Manager *manager, const Camera_Device &device)
QCameraDevice::Position positionFor(Camera_Position position)
QString descriptionFor(const Camera_Device &device)