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
52QByteArray cameraDeviceId(const PwPropertyDict &nodeProperties)
53{
54 // node.name is derived from the device's sysfs path: stable and unique
55 if (auto nodeName = getNodeName(nodeProperties))
56 return "pw:" + toByteArray(*nodeName);
57
58 // object.path less stable, based on the devfs name, e.g. v4l2:/dev/video0
59 if (auto objectPath = getObjectPath(nodeProperties))
60 return "pw:" + toByteArray(*objectPath);
61
62 // Last resort: not stable across runs, but better than an empty id, which
63 // would make the device unusable.
64 if (auto serial = getObjectSerial(nodeProperties))
65 return "pw:serial:" + QByteArray::number(qulonglong(serial->value));
66
67 return {};
68}
69
70QString cameraDescription(const PwPropertyDict &nodeProperties,
71 const PwPropertyDict &deviceProperties)
72{
73 if (auto description = getNodeDescription(nodeProperties))
74 return toString(*description);
75 if (auto nick = getNodeNick(nodeProperties))
76 return toString(*nick);
77 if (auto description = getDeviceDescription(deviceProperties))
78 return toString(*description);
79 if (auto nodeName = getNodeName(nodeProperties))
80 return toString(*nodeName);
81 return {};
82}
83
84QCameraDevice::Position cameraPosition(const PwPropertyDict &nodeProperties)
85{
86 // Only libcamera reports where a camera faces; v4l2 has no notion of it.
87 if (getDeviceApi(nodeProperties) != "libcamera"sv)
88 return QCameraDevice::UnspecifiedPosition;
89
90 const auto location = nodeProperties.find("api.libcamera.location"sv);
91 if (location == nodeProperties.end())
92 return QCameraDevice::UnspecifiedPosition;
93
94 if (location->second == "front"sv)
95 return QCameraDevice::FrontFace;
96 if (location->second == "back"sv)
97 return QCameraDevice::BackFace;
98
99 // "external" and anything unrecognised.
100 return QCameraDevice::UnspecifiedPosition;
101}
102
103} // namespace QtPipeWire
104
105QT_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)
QString cameraDescription(const PwPropertyDict &nodeProperties, const PwPropertyDict &deviceProperties)