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_videostream_p.h
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
#
ifndef
QPIPEWIRE_VIDEOSTREAM_P_H
5
#
define
QPIPEWIRE_VIDEOSTREAM_P_H
6
7
//
8
// W A R N I N G
9
// -------------
10
//
11
// This file is not part of the Qt API. It exists purely as an
12
// implementation detail. This header file may change from version to
13
// version without notice, or even be removed.
14
//
15
// We mean it.
16
//
17
18
#
include
<
QtMultimedia
/
private
/
qpipewire_cameracontextmanager_p
.
h
>
19
#
include
<
QtMultimedia
/
private
/
qpipewire_cameranode_p
.
h
>
20
#
include
<
QtMultimedia
/
private
/
qtmultimediaglobal_p
.
h
>
21
#
include
<
QtMultimedia
/
qvideoframe
.
h
>
22
#
include
<
QtMultimedia
/
qvideoframeformat
.
h
>
23
#
include
<
QtCore
/
qbytearray
.
h
>
24
#
include
<
QtCore
/
qmutex
.
h
>
25
#
include
<
QtCore
/
qobject
.
h
>
26
#
include
<
QtCore
/
qsize
.
h
>
27
28
#
include
<
bitset
>
29
#
include
<
chrono
>
30
#
include
<
memory
>
31
#
include
<
optional
>
32
#
include
<
vector
>
33
34
#
include
<
spa
/
buffer
/
buffer
.
h
>
35
#
include
<
spa
/
param
/
video
/
format
.
h
>
36
37
#
include
<
pipewire
/
version
.
h
>
38
39
// DMABUF negotiation needs SPA_FORMAT_VIDEO_modifier/SPA_VIDEO_FLAG_MODIFIER(_FIXATION_REQUIRED)
40
// and SPA_PARAM_BUFFERS_dataType, none of which older libspa headers declare.
41
#
if
QT_CONFIG
(
linux_dmabuf
)
&&
PW_CHECK_VERSION
(
0
,
3
,
76
)
42
#
define
QT_PIPEWIRE_HAS_DMABUF_CAMERA
1
43
#
else
44
#
define
QT_PIPEWIRE_HAS_DMABUF_CAMERA
0
45
#
endif
46
47
#
if
QT_PIPEWIRE_HAS_DMABUF_CAMERA
48
#
include
<
QtMultimedia
/
private
/
qdmabufallocator_p
.
h
>
49
#
endif
50
51
QT_BEGIN_NAMESPACE
52
53
namespace
QtPipeWire
{
54
55
using
BufferDataTypes
=
std
::
bitset
<
SPA_DATA_DmaBuf
+ 1>;
56
57
#
if
QT_PIPEWIRE_HAS_DMABUF_CAMERA
58
class
DmaBufBufferRegistry
;
59
class
NodeDmaBufRegistry
;
60
61
// A DMA-BUF the camera node allocated, with a duplicate of its fd that outlives the buffer.
62
struct
NodeDmaBuf
63
{
64
pw_buffer
*
pwBuffer
=
nullptr
;
65
std
::
shared_ptr
<
QtMultimediaPrivate
::
QDmaBuf
>
dmaBuf
;
66
};
67
#
endif
68
69
class
Q_MULTIMEDIA_EXPORT
QPipeWireVideoStream
:
public
QObject
70
{
71
Q_OBJECT
72
73
public
:
74
QPipeWireVideoStream
(
QCameraContextManager
&
context
,
QByteArray
targetObject
,
75
QVideoFrameFormat
::
PixelFormat
requestedPixelFormat
,
QSize
requestedSize
,
76
qreal
requestedFrameRate
,
DmaBufStrategy
dmaBufStrategy
);
77
~
QPipeWireVideoStream
()
override
;
78
79
Q_DISABLE_COPY_MOVE
(
QPipeWireVideoStream
)
80
81
bool
start
();
82
83
QVideoFrameFormat
frameFormat
()
const
;
84
85
Q_SIGNALS
:
86
void
newVideoFrame
(
const
QVideoFrame
&
frame
);
87
void
errorOccurred
(
const
QString
&
errorString
);
88
89
private
:
90
void
onStateChanged
(
pw_stream_state
old
,
pw_stream_state
state
,
const
char
*
error
);
91
void
onParamChanged
(
uint32_t
id
,
const
spa_pod
*
param
);
92
void
onProcess
();
93
94
#
if
QT_PIPEWIRE_HAS_DMABUF_CAMERA
95
// Answers a SPA_VIDEO_FLAG_MODIFIER_FIXATION_REQUIRED request with the one
96
// modifier we can read, which makes the server send a fixated format.
97
void
confirmDmaBufModifier
(
spa_video_format
,
spa_rectangle
);
98
99
void
onAddBuffer
(
pw_buffer
*
buffer
);
100
void
allocateDmaBufBuffers
(
QSize
size
,
QVideoFrameFormat
::
PixelFormat
pixelFormat
);
101
bool
emitDmaBufFrame
(
pw_buffer
*
buffer
,
const
QVideoFrameFormat
&
frameFormat
);
102
void
addNodeDmaBuf
(
pw_buffer
*
buffer
);
103
void
removeNodeDmaBuf
(
pw_buffer
*
buffer
);
104
bool
emitNodeDmaBufFrame
(
pw_buffer
*
buffer
,
const
QVideoFrameFormat
&
frameFormat
);
105
#
endif
106
107
static
const
pw_stream_events
&
streamEvents
();
108
109
QCameraContextManager
&
m_context
;
110
const
QByteArray
m_targetObject
;
111
const
QVideoFrameFormat
::
PixelFormat
m_requestedPixelFormat
;
112
const
QSize
m_requestedSize
;
113
const
qreal
m_requestedFrameRate
;
114
const
DmaBufStrategy
m_dmaBufStrategy
;
115
116
PwStreamHandle
m_stream
;
117
spa_hook
m_streamListener
{};
118
119
mutable
QMutex
m_formatMutex
;
120
QVideoFrameFormat
m_frameFormat
;
121
122
// Only meaningful on the event loop thread. A DMABUF buffer is only read when
123
// its layout is known: a compressed byte stream, or raw with a linear modifier.
124
bool
m_dmaBufReadable
=
false
;
125
BufferDataTypes
m_bufferDataTypes
;
126
127
// The first frame's timestamp in microseconds; frame start times are relative to it.
128
std
::
optional
<
std
::
chrono
::
microseconds
>
m_firstFrameTime
;
129
130
#
if
QT_PIPEWIRE_HAS_DMABUF_CAMERA
131
// Set when the stream allocates its DMA-BUF buffers itself, so they outlive the stream.
132
std
::
optional
<
QtMultimediaPrivate
::
QDmaBufAllocator
>
m_dmaBufAllocator
;
133
std
::
shared_ptr
<
DmaBufBufferRegistry
>
m_bufferRegistry
;
134
135
// DMA-BUFs that the camera node allocated, bound by PipeWire while the stream is connected.
136
std
::
vector
<
NodeDmaBuf
>
m_nodeDmaBufs
;
137
std
::
shared_ptr
<
NodeDmaBufRegistry
>
m_nodeRegistry
;
138
#
endif
139
};
140
141
}
// namespace QtPipeWire
142
143
QT_END_NAMESPACE
144
145
#
endif
// QPIPEWIRE_VIDEOSTREAM_P_H
QtPipeWire::QPipeWireVideoStream
Definition
qpipewire_videostream_p.h:70
QtPipeWire
Definition
qpipewire_async_support.cpp:10
QtPipeWire::Q_STATIC_LOGGING_CATEGORY
Q_STATIC_LOGGING_CATEGORY(lcPipewireAudioSink, "qt.multimedia.pipewire.audiosink")
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
__has_include
#define __has_include(x)
Definition
qcompilerdetection.h:459
QT_PIPEWIRE_HAS_DMABUF_CAMERA
#define QT_PIPEWIRE_HAS_DMABUF_CAMERA
Definition
qpipewire_videostream_p.h:44
qtmultimedia
src
multimedia
pipewire
qpipewire_videostream_p.h
Generated on
for Qt by
1.18.0