Changeset View
Changeset View
Standalone View
Standalone View
src/client/videostreaming.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org> | ||||
3 | | ||||
4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL | ||||
5 | */ | ||||
6 | | ||||
7 | #include "videostreaming.h" | ||||
8 | #include "qwayland-video-streaming.h" | ||||
9 | #include <QRect> | ||||
10 | | ||||
11 | using namespace KWayland::Client; | ||||
12 | | ||||
13 | class KWayland::Client::VideoStreamSourcePrivate | ||||
14 | { | ||||
15 | public: | ||||
16 | VideoStreamSourcePrivate(quint32 sourceId, const QString &description, const QString &iconName, bool isOutput, const QRect &geometry) | ||||
17 | : sourceId(sourceId) | ||||
18 | , description(description) | ||||
19 | , iconName(iconName) | ||||
20 | , isOutput(isOutput) | ||||
21 | , geometry(geometry) | ||||
22 | {} | ||||
23 | | ||||
24 | const quint32 sourceId; | ||||
25 | const QString description; | ||||
26 | const QString iconName; | ||||
27 | const bool isOutput; | ||||
28 | const QRect geometry; | ||||
29 | }; | ||||
30 | | ||||
31 | VideoStreamSource::VideoStreamSource() | ||||
32 | : d(new VideoStreamSourcePrivate(0, {}, {}, false, {})) | ||||
33 | {} | ||||
34 | | ||||
35 | VideoStreamSource::VideoStreamSource(quint32 sourceId, const QString &description, const QString &iconName, bool isOutput, const QRect &geometry) | ||||
36 | : d(new VideoStreamSourcePrivate(sourceId, description, iconName, isOutput, geometry)) | ||||
37 | {} | ||||
38 | | ||||
39 | VideoStreamSource::VideoStreamSource(const VideoStreamSource& other) | ||||
40 | : d(other.d) | ||||
41 | {} | ||||
42 | | ||||
43 | VideoStreamSource::~VideoStreamSource() = default; | ||||
44 | | ||||
45 | quint32 VideoStreamSource::sourceId() const | ||||
46 | { | ||||
47 | return d->sourceId; | ||||
48 | } | ||||
49 | | ||||
50 | QString VideoStreamSource::description() const | ||||
51 | { | ||||
52 | return d->description; | ||||
53 | } | ||||
54 | | ||||
55 | QString VideoStreamSource::iconName() const | ||||
56 | { | ||||
57 | return d->iconName; | ||||
58 | } | ||||
59 | | ||||
60 | bool VideoStreamSource::isOutput() const | ||||
61 | { | ||||
62 | return d->isOutput; | ||||
63 | } | ||||
64 | | ||||
65 | QRect VideoStreamSource::geometry() const | ||||
66 | { | ||||
67 | return d->geometry; | ||||
68 | } | ||||
69 | | ||||
70 | bool VideoStreamSource::operator!=(const VideoStreamSource& other) const | ||||
71 | { | ||||
72 | return d != other.d; | ||||
73 | } | ||||
74 | | ||||
75 | class KWayland::Client::VideoStreamingPrivate : public QtWayland::org_kde_kwin_video_streaming | ||||
76 | { | ||||
77 | public: | ||||
78 | VideoStreamingPrivate(VideoStreaming *q) | ||||
79 | : q(q) | ||||
80 | {} | ||||
81 | | ||||
82 | void org_kde_kwin_video_streaming_addSource(uint32_t sourceId, const QString & description, const QString & iconName, quint32 type, | ||||
83 | int32_t geometryX, int32_t geometryY, int32_t geometryWidth, int32_t geometryHeight) override { | ||||
84 | m_sources << VideoStreamSource {sourceId, description, iconName, type==SourceType_output, QRect{geometryX, geometryY, geometryWidth, geometryHeight}}; | ||||
85 | if (m_done) | ||||
86 | Q_EMIT q->sourcesChanged(); | ||||
87 | } | ||||
88 | void org_kde_kwin_video_streaming_removeSource(uint32_t sourceId) override { | ||||
89 | auto it = std::find_if(m_sources.begin(), m_sources.end(), [sourceId] (const VideoStreamSource &source) { | ||||
90 | return source.sourceId() == sourceId; | ||||
91 | }); | ||||
92 | Q_ASSERT(it != m_sources.end()); | ||||
93 | m_sources.erase(it); | ||||
94 | Q_EMIT q->sourcesChanged(); | ||||
95 | } | ||||
96 | | ||||
97 | void org_kde_kwin_video_streaming_done() override { | ||||
98 | m_done = true; | ||||
99 | Q_EMIT q->initialized(); | ||||
100 | Q_EMIT q->sourcesChanged(); | ||||
101 | } | ||||
102 | | ||||
103 | void org_kde_kwin_video_streaming_created(int32_t nodeid, uint32_t sourceId) override { | ||||
104 | Q_EMIT q->created(sourceById(sourceId), nodeid); | ||||
105 | } | ||||
106 | | ||||
107 | VideoStreamSource sourceById(quint32 sourceId) { | ||||
108 | auto it = std::find_if(m_sources.begin(), m_sources.end(), [sourceId] (const VideoStreamSource &source) { | ||||
109 | return source.sourceId() == sourceId; | ||||
110 | }); | ||||
111 | if (it == m_sources.constEnd()) | ||||
112 | return {}; | ||||
113 | return *it; | ||||
114 | } | ||||
115 | | ||||
116 | bool m_done = false; | ||||
117 | QVector<VideoStreamSource> m_sources; | ||||
118 | VideoStreaming *const q; | ||||
119 | }; | ||||
120 | | ||||
121 | VideoStreaming::VideoStreaming(QObject* parent) | ||||
122 | : QObject(parent) | ||||
123 | , d(new VideoStreamingPrivate(this)) | ||||
124 | {} | ||||
125 | | ||||
126 | VideoStreaming::~VideoStreaming() = default; | ||||
127 | | ||||
128 | void VideoStreaming::close(quint32 nodeid) | ||||
129 | { | ||||
130 | d->close(nodeid); | ||||
131 | } | ||||
132 | | ||||
133 | void VideoStreaming::create(const VideoStreamSource& source) | ||||
134 | { | ||||
135 | d->create(source.sourceId()); | ||||
136 | } | ||||
137 | | ||||
138 | QVector<VideoStreamSource> VideoStreaming::sources() const | ||||
139 | { | ||||
140 | return d->m_sources; | ||||
141 | } |