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
36 /// Returns where the streams current state
37 Q_PROPERTY(StreamState state READ state NOTIFY stateChanged)
38
39 /// Specify the pipewire node id that we want to play
40 Q_PROPERTY(uint nodeId READ nodeId WRITE setNodeId NOTIFY nodeIdChanged)
41
42 /**
43 * Specifies the file descriptor we are connected to, if none 0 will be returned
44 *
45 * Transfers the ownership of the fd, will close it when it's done with it.
46 */
47 Q_PROPERTY(uint fd READ fd WRITE setFd NOTIFY fdChanged RESET resetFd)
48
49 /**
50 * Returns the size of the source being rendered
51 * @note: This won't be updated until the first frame is recieved
52 */
53 Q_PROPERTY(QSize streamSize READ streamSize NOTIFY streamSizeChanged)
54
55 /**
56 * Allows disabling the dmabuf streams
57 */
58 Q_PROPERTY(bool allowDmaBuf READ allowDmaBuf WRITE setAllowDmaBuf)
59
60 Q_PROPERTY(bool usingDmaBuf READ usingDmaBuf NOTIFY usingDmaBufChanged)
61
62 /**
63 * Specifies whether the first frame has been received and there's something to display.
64 */
65 Q_PROPERTY(bool ready READ isReady NOTIFY readyChanged)
66
67public:
68 enum class StreamState { Error, Unconnected, Connecting, Paused, Streaming };
69 Q_ENUM(StreamState);
70
71 PipeWireSourceItem(QQuickItem *parent = nullptr);
72 ~PipeWireSourceItem() override;
73
74 QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *data) override;
75 Q_SCRIPTABLE QString error() const;
76
77 void setNodeId(uint nodeId);
78 uint nodeId() const;
79
80 void setFd(uint fd);
81 void resetFd();
82 uint fd() const;
83
84 QSize streamSize() const;
85
86 bool usingDmaBuf() const;
87 bool allowDmaBuf() const;
88 void setAllowDmaBuf(bool allowed);
89
90 bool isReady() const;
91
92 void componentComplete() override;
93 void releaseResources() override;
94
95 StreamState state() const;
96
98 void nodeIdChanged(uint nodeId);
99 void fdChanged(uint fd);
100 void streamSizeChanged();
101 void stateChanged();
102 void usingDmaBufChanged();
103 void readyChanged();
104
105private:
106 void itemChange(ItemChange change, const ItemChangeData &data) override;
107 void processFrame(const PipeWireFrame &frame);
108 void updateTextureDmaBuf(const DmaBufAttributes &attribs, spa_video_format format);
109 void updateTextureImage(const std::shared_ptr<PipeWireFrameData> &data);
110 void refresh();
111 void setReady(bool ready);
112
114};
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
Q_ENUM(...)
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
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-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:05:20 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.