Changeset View
Changeset View
Standalone View
Standalone View
screencaststream.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright © 2018-2020 Red Hat, Inc | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Lesser General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2 of the License, or (at your option) any later version. | ||||
8 | * | ||||
9 | * This library is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | * Lesser General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Lesser General Public | ||||
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
16 | * | ||||
17 | * Authors: | ||||
18 | * Jan Grulich <jgrulich@redhat.com> | ||||
19 | */ | ||||
20 | | ||||
21 | #pragma once | ||||
22 | | ||||
23 | #include <QObject> | ||||
24 | #include <QSize> | ||||
25 | | ||||
26 | #include "kwinglobals.h" | ||||
27 | #include "config-kwin.h" | ||||
28 | #include <pipewire/pipewire.h> | ||||
29 | #include <spa/param/format-utils.h> | ||||
30 | #include <spa/param/video/format-utils.h> | ||||
31 | #include <spa/param/props.h> | ||||
32 | #include <spa/utils/result.h> | ||||
33 | | ||||
34 | #undef Status | ||||
35 | | ||||
36 | class KWIN_EXPORT ScreenCastStream : public QObject | ||||
37 | { | ||||
38 | Q_OBJECT | ||||
39 | public: | ||||
40 | explicit ScreenCastStream(const QSize &resolution, QObject *parent); | ||||
41 | ~ScreenCastStream(); | ||||
42 | | ||||
43 | static void onCoreError(void *data, uint32_t id, int seq, int res, const char *message); | ||||
44 | static void onStreamParamChanged(void *data, uint32_t id, const struct spa_pod *format); | ||||
45 | static void onStreamStateChanged(void *data, pw_stream_state old, pw_stream_state state, const char *error_message); | ||||
46 | | ||||
47 | bool init(int bitsPerPixel); | ||||
48 | uint framerate(); | ||||
49 | uint nodeId(); | ||||
50 | QString error() const { | ||||
51 | return m_error; | ||||
52 | } | ||||
53 | | ||||
54 | void removeStream(); | ||||
55 | void stop(); | ||||
56 | | ||||
57 | uint bytesPerPixel() const { | ||||
58 | return m_bytesPerPixel; | ||||
59 | } | ||||
60 | | ||||
61 | Q_SIGNALS: | ||||
62 | void streamReady(quint32 nodeId); | ||||
63 | void startStreaming(); | ||||
64 | void stopStreaming(uint nodeId); | ||||
65 | | ||||
66 | private: | ||||
67 | pw_stream *createStream(); | ||||
68 | public: | ||||
69 | struct pw_context *pwContext = nullptr; | ||||
70 | struct pw_core *pwCore = nullptr; | ||||
71 | struct pw_stream *pwStream = nullptr; | ||||
72 | struct pw_thread_loop *pwMainLoop = nullptr; | ||||
73 | | ||||
74 | spa_hook coreListener; | ||||
75 | spa_hook streamListener; | ||||
76 | | ||||
77 | // event handlers | ||||
78 | pw_core_events pwCoreEvents = {}; | ||||
79 | pw_stream_events pwStreamEvents = {}; | ||||
80 | | ||||
81 | uint32_t pwNodeId = 0; | ||||
82 | | ||||
83 | QSize m_resolution; | ||||
84 | bool m_stopped = false; | ||||
85 | | ||||
86 | spa_video_info_raw videoFormat; | ||||
87 | QString m_error; | ||||
88 | uint m_bytesPerPixel = 0; | ||||
89 | }; |