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