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
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
4
#
include
"qpipewire_cameranode_p.h"
5
6
#
include
<
QtCore
/
qloggingcategory
.
h
>
7
8
QT_BEGIN_NAMESPACE
9
10
namespace
QtPipeWire
{
11
12
using
namespace
Qt
::
StringLiterals
;
13
using
namespace
std
::
string_view_literals
;
14
15
namespace
{
16
17
QByteArray toByteArray(std::string_view sv)
18
{
19
return
QByteArray(sv.data(), qsizetype(sv.size()));
20
}
21
22
QString toString(std::string_view sv)
23
{
24
return
QString::fromUtf8(sv.data(), qsizetype(sv.size()));
25
}
26
27
}
// namespace
28
29
bool
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
52
DmaBufStrategy
dmaBufStrategy
(
const
PwPropertyDict &deviceProperties)
53
{
54
const
std::optional<std::string_view> deviceApi = getDeviceApi(deviceProperties);
55
if
(deviceApi ==
"v4l2"sv
)
56
return
DmaBufStrategy
::
ClientAllocated
;
57
if
(deviceApi ==
"libcamera"sv
)
58
return
DmaBufStrategy
::
NodeAllocated
;
59
return
DmaBufStrategy
::
None
;
60
}
61
62
QByteArray
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
80
QString
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
94
QCameraDevice
::
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
115
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QtPipeWire
Definition
qpipewire_async_support.cpp:10
QtPipeWire::cameraPosition
QCameraDevice::Position cameraPosition(const PwPropertyDict &nodeProperties)
Definition
qpipewire_cameranode.cpp:94
QtPipeWire::DmaBufStrategy
DmaBufStrategy
Definition
qpipewire_cameranode_p.h:34
QtPipeWire::DmaBufStrategy::ClientAllocated
@ ClientAllocated
Definition
qpipewire_cameranode_p.h:39
QtPipeWire::DmaBufStrategy::None
@ None
Definition
qpipewire_cameranode_p.h:36
QtPipeWire::DmaBufStrategy::NodeAllocated
@ NodeAllocated
Definition
qpipewire_cameranode_p.h:42
QtPipeWire::cameraDeviceId
QByteArray cameraDeviceId(const PwPropertyDict &nodeProperties)
Definition
qpipewire_cameranode.cpp:62
QtPipeWire::isCameraNode
bool isCameraNode(const PwPropertyDict &nodeProperties)
Definition
qpipewire_cameranode.cpp:29
QtPipeWire::dmaBufStrategy
DmaBufStrategy dmaBufStrategy(const PwPropertyDict &deviceProperties)
Definition
qpipewire_cameranode.cpp:52
QtPipeWire::cameraDescription
QString cameraDescription(const PwPropertyDict &nodeProperties, const PwPropertyDict &deviceProperties)
Definition
qpipewire_cameranode.cpp:80
qtmultimedia
src
multimedia
pipewire
qpipewire_cameranode.cpp
Generated on
for Qt by
1.18.0