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_camera.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 <QtMultimedia/private/qpipewire_cameracontextmanager_p.h>
7#include <QtMultimedia/private/qpipewire_videostream_p.h>
8#include <QtCore/qloggingcategory.h>
9
11
12namespace QtPipeWire {
13
14using namespace Qt::StringLiterals;
15
16Q_STATIC_LOGGING_CATEGORY(lcPipewireCamera, "qt.multimedia.pipewire.camera")
17
22
30
32{
33 return m_active;
34}
35
37{
38 if (m_active == active)
39 return;
40
42 return;
43
46
47 if (active) {
49 if (!startStream())
50 return;
51 m_active = true;
52 } else {
53 m_active = false;
54 stopStream();
56 }
57
59}
60
62{
64 return;
65
66 const bool wasActive = m_active;
67 stopStream();
68
71
72 if (wasActive)
74}
75
77{
79 return false;
80
82 return true;
83
84 if (m_active) {
85 stopStream();
87 }
88
89 return true;
90}
91
93{
95 if (resolved.isNull())
97
99 return false;
100
102 return true;
103}
104
106{
107 // Until the stream has negotiated a format, report what was requested, so
108 // that a sink has something to work with.
109 if (m_stream) {
111 if (negotiated.isValid())
112 return negotiated;
113 }
114
116}
117
119{
121
123
124 const std::optional<QByteArray> target =
126 if (!target) {
127 const QByteArray id = m_cameraDevice.id();
128 if (!id.startsWith("pw:")) {
130 u"The camera id \"%1\" does not name a PipeWire camera. Camera ids are "
131 "not interchangeable between backends."_s.arg(QString::fromUtf8(id)));
132 } else {
134 u"No PipeWire camera with the id \"%1\" is present."_s.arg(
135 QString::fromUtf8(id)));
136 }
137 return false;
138 }
139
144
146 [this](const QVideoFrame &frame) {
149 }, Qt::DirectConnection);
151 [this](const QString &errorString) {
153 }, Qt::QueuedConnection);
154
155 if (!m_stream->start()) {
156 m_stream.reset();
157 updateError(QCamera::CameraError, u"Could not start the PipeWire camera stream."_s);
158 return false;
159 }
160
161 qCDebug(lcPipewireCamera) << "streaming from" << *target << "as" << m_cameraFormat.pixelFormat()
163 return true;
164}
165
167{
168 m_stream.reset();
169}
170
171} // namespace QtPipeWire
172
173QT_END_NAMESPACE
Combined button and popup list for selecting options.
Q_STATIC_LOGGING_CATEGORY(lcPipewireAudioSink, "qt.multimedia.pipewire.audiosink")