1 | /* $Id: Recording.h 105006 2024-06-24 17:43:00Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Recording code header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.alldomusa.eu.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef MAIN_INCLUDED_Recording_h
|
---|
29 | #define MAIN_INCLUDED_Recording_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include <VBox/err.h>
|
---|
35 | #include <VBox/settings.h>
|
---|
36 |
|
---|
37 | #include "RecordingStream.h"
|
---|
38 |
|
---|
39 | class Console;
|
---|
40 |
|
---|
41 | /** No flags specified. */
|
---|
42 | #define VBOX_RECORDING_CURSOR_F_NONE 0
|
---|
43 | /** Cursor is visible. */
|
---|
44 | #define VBOX_RECORDING_CURSOR_F_VISIBLE RT_BIT(0)
|
---|
45 | /** Cursor shape contains an alpha mask. */
|
---|
46 | #define VBOX_RECORDING_CURSOR_F_ALPHA RT_BIT(1)
|
---|
47 | /** Cursor state flags valid mask. */
|
---|
48 | #define VBOX_RECORDING_CURSOR_F_VALID_MASK 0x3
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Class for keeping a recording cursor state.
|
---|
52 | */
|
---|
53 | class RecordingCursorState
|
---|
54 | {
|
---|
55 | public:
|
---|
56 |
|
---|
57 | RecordingCursorState();
|
---|
58 | virtual ~RecordingCursorState();
|
---|
59 |
|
---|
60 | void Destroy();
|
---|
61 |
|
---|
62 | int CreateOrUpdate(bool fAlpha, uint32_t uWidth, uint32_t uHeight, const uint8_t *pu8Shape, size_t cbShape);
|
---|
63 |
|
---|
64 | int Move(int32_t iX, int32_t iY);
|
---|
65 |
|
---|
66 | /** Cursor state flags. */
|
---|
67 | uint32_t m_fFlags;
|
---|
68 | /** The current cursor shape. */
|
---|
69 | RECORDINGVIDEOFRAME m_Shape;
|
---|
70 | };
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Class for managing a recording context.
|
---|
74 | */
|
---|
75 | class RecordingContext
|
---|
76 | {
|
---|
77 | public:
|
---|
78 |
|
---|
79 | RecordingContext();
|
---|
80 |
|
---|
81 | RecordingContext(Console *ptrConsole, const settings::RecordingSettings &Settings);
|
---|
82 |
|
---|
83 | virtual ~RecordingContext(void);
|
---|
84 |
|
---|
85 | public:
|
---|
86 |
|
---|
87 | const settings::RecordingSettings &GetConfig(void) const;
|
---|
88 | RecordingStream *GetStream(unsigned uScreen) const;
|
---|
89 | size_t GetStreamCount(void) const;
|
---|
90 | #ifdef VBOX_WITH_AUDIO_RECORDING
|
---|
91 | PRECORDINGCODEC GetCodecAudio(void) { return &this->m_CodecAudio; }
|
---|
92 | #endif
|
---|
93 |
|
---|
94 | int Create(Console *pConsole, const settings::RecordingSettings &Settings);
|
---|
95 | void Destroy(void);
|
---|
96 |
|
---|
97 | int Start(void);
|
---|
98 | int Stop(void);
|
---|
99 |
|
---|
100 | int SendAudioFrame(const void *pvData, size_t cbData, uint64_t uTimestampMs);
|
---|
101 | int SendVideoFrame(uint32_t uScreen, PRECORDINGVIDEOFRAME pFrame, uint64_t msTimestamp);
|
---|
102 | int SendCursorPositionChange(uint32_t uScreen, int32_t x, int32_t y, uint64_t msTimestamp);
|
---|
103 | int SendCursorShapeChange(bool fVisible, bool fAlpha, uint32_t xHot, uint32_t yHot, uint32_t uWidth, uint32_t uHeight, const uint8_t *pu8Shape, size_t cbShape, uint64_t msTimestamp);
|
---|
104 | int SendScreenChange(uint32_t uScreen, PRECORDINGSURFACEINFO pInfo, uint64_t uTimestampMs);
|
---|
105 |
|
---|
106 | public:
|
---|
107 |
|
---|
108 | uint64_t GetCurrentPTS(void) const;
|
---|
109 | bool IsFeatureEnabled(RecordingFeature_T enmFeature);
|
---|
110 | bool IsReady(void);
|
---|
111 | bool IsReady(uint32_t uScreen, uint64_t msTimestamp);
|
---|
112 | bool IsStarted(void);
|
---|
113 | bool IsLimitReached(void);
|
---|
114 | bool IsLimitReached(uint32_t uScreen, uint64_t msTimestamp);
|
---|
115 | bool NeedsUpdate(uint32_t uScreen, uint64_t msTimestamp);
|
---|
116 |
|
---|
117 | DECLCALLBACK(int) OnLimitReached(uint32_t uScreen, int vrc);
|
---|
118 |
|
---|
119 | /** The state mouse cursor state.
|
---|
120 | * We currently only support one mouse cursor at a time. */
|
---|
121 | RecordingCursorState m_Cursor;
|
---|
122 |
|
---|
123 |
|
---|
124 | protected:
|
---|
125 |
|
---|
126 | int createInternal(Console *ptrConsole, const settings::RecordingSettings &Settings);
|
---|
127 | int startInternal(void);
|
---|
128 | int stopInternal(void);
|
---|
129 |
|
---|
130 | void destroyInternal(void);
|
---|
131 |
|
---|
132 | RecordingStream *getStreamInternal(unsigned uScreen) const;
|
---|
133 |
|
---|
134 | int processCommonData(RecordingBlockMap &mapCommon, RTMSINTERVAL msTimeout);
|
---|
135 | int writeCommonData(RecordingBlockMap &mapCommon, PRECORDINGCODEC pCodec, const void *pvData, size_t cbData, uint64_t msAbsPTS, uint32_t uFlags);
|
---|
136 |
|
---|
137 | int lock(void);
|
---|
138 | int unlock(void);
|
---|
139 |
|
---|
140 | static DECLCALLBACK(int) threadMain(RTTHREAD hThreadSelf, void *pvUser);
|
---|
141 |
|
---|
142 | int threadNotify(void);
|
---|
143 |
|
---|
144 | protected:
|
---|
145 |
|
---|
146 | int audioInit(const settings::RecordingScreenSettings &screenSettings);
|
---|
147 |
|
---|
148 | static DECLCALLBACK(int) audioCodecWriteDataCallback(PRECORDINGCODEC pCodec, const void *pvData, size_t cbData, uint64_t msAbsPTS, uint32_t uFlags, void *pvUser);
|
---|
149 |
|
---|
150 | protected:
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Enumeration for a recording context state.
|
---|
154 | */
|
---|
155 | enum RECORDINGSTS
|
---|
156 | {
|
---|
157 | /** Context not initialized. */
|
---|
158 | RECORDINGSTS_UNINITIALIZED = 0,
|
---|
159 | /** Context was created. */
|
---|
160 | RECORDINGSTS_CREATED = 1,
|
---|
161 | /** Context was started. */
|
---|
162 | RECORDINGSTS_STARTED = 2,
|
---|
163 | /** The usual 32-bit hack. */
|
---|
164 | RECORDINGSTS_32BIT_HACK = 0x7fffffff
|
---|
165 | };
|
---|
166 |
|
---|
167 | /** Pointer to the console object. */
|
---|
168 | Console *m_pConsole;
|
---|
169 | /** Used recording configuration. */
|
---|
170 | settings::RecordingSettings m_Settings;
|
---|
171 | /** The current state. */
|
---|
172 | RECORDINGSTS m_enmState;
|
---|
173 | /** Critical section to serialize access. */
|
---|
174 | RTCRITSECT m_CritSect;
|
---|
175 | /** Semaphore to signal the encoding worker thread. */
|
---|
176 | RTSEMEVENT m_WaitEvent;
|
---|
177 | /** Shutdown indicator. */
|
---|
178 | bool m_fShutdown;
|
---|
179 | /** Encoding worker thread. */
|
---|
180 | RTTHREAD m_Thread;
|
---|
181 | /** Vector of current recording streams.
|
---|
182 | * Per VM screen (display) one recording stream is being used. */
|
---|
183 | RecordingStreams m_vecStreams;
|
---|
184 | /** Number of streams in vecStreams which currently are enabled for recording. */
|
---|
185 | uint16_t m_cStreamsEnabled;
|
---|
186 | /** Timestamp (in ms) of when recording has been started.
|
---|
187 | * Set to 0 if not started (yet). */
|
---|
188 | uint64_t m_tsStartMs;
|
---|
189 | #ifdef VBOX_WITH_AUDIO_RECORDING
|
---|
190 | /** Audio codec to use.
|
---|
191 | *
|
---|
192 | * We multiplex audio data from this recording context to all streams,
|
---|
193 | * to avoid encoding the same audio data for each stream. We ASSUME that
|
---|
194 | * all audio data of a VM will be the same for each stream at a given
|
---|
195 | * point in time. */
|
---|
196 | RECORDINGCODEC m_CodecAudio;
|
---|
197 | #endif /* VBOX_WITH_AUDIO_RECORDING */
|
---|
198 | /** Block map of raw common data blocks which need to get encoded first. */
|
---|
199 | RecordingBlockMap m_mapBlocksRaw;
|
---|
200 | /** Block map of encoded common blocks.
|
---|
201 | *
|
---|
202 | * Only do the encoding of common data blocks only once and then multiplex
|
---|
203 | * the encoded data to all affected recording streams.
|
---|
204 | *
|
---|
205 | * This avoids doing the (expensive) encoding + multiplexing work in other
|
---|
206 | * threads like EMT / audio async I/O..
|
---|
207 | *
|
---|
208 | * For now this only affects audio, e.g. all recording streams
|
---|
209 | * need to have the same audio data at a specific point in time. */
|
---|
210 | RecordingBlockMap m_mapBlocksEncoded;
|
---|
211 | };
|
---|
212 | #endif /* !MAIN_INCLUDED_Recording_h */
|
---|
213 |
|
---|