KPipewire

pipewiresourceitem.h
1/*
2 Render a PipeWire stream into a QtQuick scene as a standard Item
3 SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#pragma once
9
10#include <QImage>
11#include <QQuickItem>
12#include <functional>
13#include <optional>
14
15#include <pipewire/pipewire.h>
16#include <spa/param/format-utils.h>
17#include <spa/param/props.h>
18#include <spa/param/video/format-utils.h>
19
20#include <kpipewire_export.h>
21
22struct DmaBufAttributes;
23class PipeWireSourceStream;
24struct PipeWireFrame;
25class PipeWireFrameData;
26class QSGTexture;
27class QOpenGLTexture;
28typedef void *EGLImage;
29
30class PipeWireSourceItemPrivate;
31
32class KPIPEWIRE_EXPORT PipeWireSourceItem : public QQuickItem
33{
34 Q_OBJECT
35 QML_ELEMENT
36
37 /// Returns where the streams current state
38 Q_PROPERTY(StreamState state READ state NOTIFY stateChanged)
39
40 /// Specify the pipewire node id that we want to play
41 Q_PROPERTY(uint nodeId READ nodeId WRITE setNodeId NOTIFY nodeIdChanged)
42
43 /**
44 * Specifies the file descriptor we are connected to, if none 0 will be returned
45 *
46 * Transfers the ownership of the fd, will close it when it's done with it.
47 */
48 Q_PROPERTY(uint fd READ fd WRITE setFd NOTIFY fdChanged RESET resetFd)
49
50 /**
51 * Returns the size of the source being rendered
52 * @note: This won't be updated until the first frame is recieved
53 */
54 Q_PROPERTY(QSize streamSize READ streamSize NOTIFY streamSizeChanged)
55
56 /**
57 * Allows disabling the dmabuf streams
58 */
59 Q_PROPERTY(bool allowDmaBuf READ allowDmaBuf WRITE setAllowDmaBuf)
60
61 Q_PROPERTY(bool usingDmaBuf READ usingDmaBuf NOTIFY usingDmaBufChanged)
62
63 /**
64 * Specifies whether the first frame has been received and there's something to display.
65 */
66 Q_PROPERTY(bool ready READ isReady NOTIFY readyChanged)
67
68public:
69 enum class StreamState { Error, Unconnected, Connecting, Paused, Streaming };
70 Q_ENUM(StreamState);
71
72 PipeWireSourceItem(QQuickItem *parent = nullptr);
73 ~PipeWireSourceItem() override;
74
75 QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *data) override;
76 Q_SCRIPTABLE QString error() const;
77
78 void setNodeId(uint nodeId);
79 uint nodeId() const;
80
81 void setFd(uint fd);
82 void resetFd();
83 uint fd() const;
84
85 QSize streamSize() const;
86
87 bool usingDmaBuf() const;
88 bool allowDmaBuf() const;
89 void setAllowDmaBuf(bool allowed);
90
91 bool isReady() const;
92
93 void componentComplete() override;
94 void releaseResources() override;
95
96 StreamState state() const;
97
98Q_SIGNALS:
99 void nodeIdChanged(uint nodeId);
100 void fdChanged(uint fd);
101 void streamSizeChanged();
102 void stateChanged();
103 void usingDmaBufChanged();
104 void readyChanged();
105
106private:
107 void itemChange(ItemChange change, const ItemChangeData &data) override;
108 void processFrame(const PipeWireFrame &frame);
109 void updateTextureDmaBuf(const DmaBufAttributes &attribs, spa_video_format format);
110 void updateTextureImage(const std::shared_ptr<PipeWireFrameData> &data);
111 void refresh();
112 void setReady(bool ready);
113
114 QScopedPointer<PipeWireSourceItemPrivate> d;
115};
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
Q_ENUM(...)
Q_PROPERTY(...)
virtual void componentComplete() override
virtual void itemChange(ItemChange change, const ItemChangeData &value)
virtual void releaseResources()
virtual QSGNode * updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri May 2 2025 12:00:27 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.