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
qpipewire_cameranode.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
6#include <QtCore/qloggingcategory.h>
7
9
10namespace QtPipeWire {
11
12using namespace Qt::StringLiterals;
13using namespace std::string_view_literals;
14
15namespace {
16
17QByteArray toByteArray(std::string_view sv)
18{
19 return QByteArray(sv.data(), qsizetype(sv.size()));
20}
21
22QString toString(std::string_view sv)
23{
24 return QString::fromUtf8(sv.data(), qsizetype(sv.size()));
25}
26
27} // namespace
28
29bool isCameraNode(const PwPropertyDict &nodeProperties)
30{
31 // An escape hatch for triaging a camera that we filter out but should not.
32 static const bool acceptAll =
33 qEnvironmentVariableIntValue("QT_PIPEWIRE_CAMERA_ACCEPT_ALL") != 0;
34
35 const std::optional<std::string_view> mediaClass = getMediaClass(nodeProperties);
36 if (!mediaClass)
37 return false;
38
39 if (mediaClass != "Video/Source"sv)
40 return false;
41
42 if (acceptAll)
43 return true;
44
45 if (getMediaRole(nodeProperties) == "Camera"sv)
46 return true;
47
48 const std::optional<std::string_view> deviceApi = getDeviceApi(nodeProperties);
49 return deviceApi == "v4l2"sv || deviceApi == "libcamera"sv;
50}
51
52DmaBufStrategy dmaBufStrategy(const PwPropertyDict &deviceProperties)
53{
54 const std::optional<std::string_view> deviceApi = getDeviceApi(deviceProperties);
55 if (deviceApi == "v4l2"sv)
57 if (deviceApi == "libcamera"sv)
60}
61
62QByteArray cameraDeviceId(const PwPropertyDict &nodeProperties)
63{
64 // node.name is derived from the device's sysfs path: stable and unique
65 if (auto nodeName = getNodeName(nodeProperties))
66 return "pw:" + toByteArray(*nodeName);
67
68 // object.path less stable, based on the devfs name, e.g. v4l2:/dev/video0
69 if (auto objectPath = getObjectPath(nodeProperties))
70 return "pw:" + toByteArray(*objectPath);
71
72 // Last resort: not stable across runs, but better than an empty id, which
73 // would make the device unusable.
74 if (auto serial = getObjectSerial(nodeProperties))
75 return "pw:serial:" + QByteArray::number(qulonglong(serial->value));
76
77 return {};
78}
79
80QString cameraDescription(const PwPropertyDict &nodeProperties,
81 const PwPropertyDict &deviceProperties)
82{
83 if (auto description = getNodeDescription(nodeProperties))
84 return toString(*description);
85 if (auto nick = getNodeNick(nodeProperties))
86 return toString(*nick);
87 if (auto description = getDeviceDescription(deviceProperties))
88 return toString(*description);
89 if (auto nodeName = getNodeName(nodeProperties))
90 return toString(*nodeName);
91 return {};
92}
93
94QCameraDevice::Position cameraPosition(const PwPropertyDict &nodeProperties)
95{
96 // Only libcamera reports where a camera faces; v4l2 has no notion of it.
97 if (getDeviceApi(nodeProperties) != "libcamera"sv)
98 return QCameraDevice::UnspecifiedPosition;
99
100 const auto location = nodeProperties.find("api.libcamera.location"sv);
101 if (location == nodeProperties.end())
102 return QCameraDevice::UnspecifiedPosition;
103
104 if (location->second == "front"sv)
105 return QCameraDevice::FrontFace;
106 if (location->second == "back"sv)
107 return QCameraDevice::BackFace;
108
109 // "external" and anything unrecognised.
110 return QCameraDevice::UnspecifiedPosition;
111}
112
113} // namespace QtPipeWire
114
115QT_END_NAMESPACE
Combined button and popup list for selecting options.
QCameraDevice::Position cameraPosition(const PwPropertyDict &nodeProperties)
QByteArray cameraDeviceId(const PwPropertyDict &nodeProperties)
bool isCameraNode(const PwPropertyDict &nodeProperties)
DmaBufStrategy dmaBufStrategy(const PwPropertyDict &deviceProperties)
QString cameraDescription(const PwPropertyDict &nodeProperties, const PwPropertyDict &deviceProperties)