Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/drm/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 | #ifndef SCREEN_CAST_STREAM_H | ||||
22 | #define SCREEN_CAST_STREAM_H | ||||
23 | | ||||
24 | #include <QObject> | ||||
25 | #include <QSize> | ||||
26 | | ||||
27 | #include <pipewire/pipewire.h> | ||||
28 | #include <spa/param/format-utils.h> | ||||
29 | #include <spa/param/video/format-utils.h> | ||||
30 | #include <spa/param/props.h> | ||||
31 | #include "config-kwin.h" | ||||
32 | | ||||
33 | #include <spa/utils/result.h> | ||||
34 | | ||||
35 | namespace KWin | ||||
36 | { | ||||
37 | class AbstractEglBackend; | ||||
38 | class DrmOutput; | ||||
39 | class DrmSurfaceBuffer; | ||||
40 | } | ||||
41 | | ||||
42 | class ScreenCastStream : public QObject | ||||
43 | { | ||||
44 | Q_OBJECT | ||||
45 | public: | ||||
46 | explicit ScreenCastStream(const QSize &resolution, KWin::AbstractEglBackend* backend, QObject *parent = nullptr); | ||||
47 | ~ScreenCastStream(); | ||||
48 | | ||||
49 | static void onCoreError(void *data, uint32_t id, int seq, int res, const char *message); | ||||
50 | static void onStreamParamChanged(void *data, uint32_t id, const struct spa_pod *format); | ||||
51 | static void onStreamStateChanged(void *data, pw_stream_state old, pw_stream_state state, const char *error_message); | ||||
52 | static void onStreamProcess(void *data); | ||||
53 | | ||||
54 | // Public | ||||
55 | bool init(); | ||||
56 | uint framerate(); | ||||
57 | uint nodeId(); | ||||
58 | QString error() const { | ||||
59 | return m_error; | ||||
60 | } | ||||
61 | | ||||
62 | void removeStream(); | ||||
63 | | ||||
64 | #if HAVE_GBM | ||||
65 | bool recordFrame(struct gbm_bo *bo, quint32 width, quint32 height, quint32 stride); | ||||
66 | #endif | ||||
67 | | ||||
68 | void stop(); | ||||
69 | | ||||
70 | Q_SIGNALS: | ||||
71 | void streamReady(uint nodeId); | ||||
72 | void startStreaming(); | ||||
73 | void stopStreaming(uint nodeId); | ||||
74 | | ||||
75 | private: | ||||
76 | pw_stream *createStream(); | ||||
77 | public: | ||||
78 | struct pw_context *pwContext = nullptr; | ||||
79 | struct pw_core *pwCore = nullptr; | ||||
80 | struct pw_stream *pwStream = nullptr; | ||||
81 | struct pw_thread_loop *pwMainLoop = nullptr; | ||||
82 | | ||||
83 | spa_hook coreListener; | ||||
84 | spa_hook streamListener; | ||||
85 | | ||||
86 | // event handlers | ||||
87 | pw_core_events pwCoreEvents = {}; | ||||
88 | pw_stream_events pwStreamEvents = {}; | ||||
89 | | ||||
90 | uint32_t pwNodeId = 0; | ||||
91 | | ||||
92 | QSize resolution; | ||||
93 | bool m_stopped = false; | ||||
94 | | ||||
95 | spa_video_info_raw videoFormat; | ||||
96 | KWin::AbstractEglBackend* const m_backend; | ||||
97 | QString m_error; | ||||
98 | | ||||
99 | }; | ||||
100 | | ||||
101 | #endif // SCREEN_CAST_STREAM_H |