VirtualBox

source: vbox/trunk/src/VBox/Main/include/Recording.h@ 105124

Last change on this file since 105124 was 105095, checked in by vboxsync, 10 months ago

Video Recording/Main: More optimizations for recording older guests which have a slightly different screen update logic. bugref:10650

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
  • Property svn:mergeinfo set to (toggle deleted branches)
    /branches/VBox-3.0/src/VBox/Frontends/VBoxHeadless/VideoCapture/EncodeAndWrite.h58652,​70973
    /branches/VBox-3.2/src/VBox/Frontends/VBoxHeadless/VideoCapture/EncodeAndWrite.h66309,​66318
    /branches/VBox-4.0/src/VBox/Frontends/VBoxHeadless/VideoCapture/EncodeAndWrite.h70873
    /branches/VBox-4.1/src/VBox/Frontends/VBoxHeadless/VideoCapture/EncodeAndWrite.h74233
    /branches/VBox-4.2/src/VBox/Main/src-client/VideoRec.h91503-91504,​91506-91508,​91510,​91514-91515,​91521
    /branches/VBox-4.3/src/VBox/Main/src-client/VideoRec.h91223
    /branches/VBox-4.3/trunk/src/VBox/Main/src-client/VideoRec.h91223
    /branches/dsen/gui/src/VBox/Frontends/VBoxHeadless/VideoCapture/EncodeAndWrite.h79076-79078,​79089,​79109-79110,​79112-79113,​79127-79130,​79134,​79141,​79151,​79155,​79157-79159,​79193,​79197
    /branches/dsen/gui2/src/VBox/Frontends/VBoxHeadless/VideoCapture/EncodeAndWrite.h79224,​79228,​79233,​79235,​79258,​79262-79263,​79273,​79341,​79345,​79354,​79357,​79387-79388,​79559-79569,​79572-79573,​79578,​79581-79582,​79590-79591,​79598-79599,​79602-79603,​79605-79606,​79632,​79635,​79637,​79644
    /branches/dsen/gui3/src/VBox/Frontends/VBoxHeadless/VideoCapture/EncodeAndWrite.h79645-79692
File size: 8.1 KB
Line 
1/* $Id: Recording.h 105095 2024-07-02 10:06:48Z 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.215389.xyz.
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
39class 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 */
53class RecordingCursorState
54{
55public:
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 * Enumeration for a recording context state.
74 */
75enum RECORDINGSTS
76{
77 /** Recording not initialized. */
78 RECORDINGSTS_UNINITIALIZED = 0,
79 /** Recording was created. */
80 RECORDINGSTS_CREATED = 1,
81 /** Recording was started. */
82 RECORDINGSTS_STARTED = 2,
83 /** Recording was stopped. */
84 RECORDINGSTS_STOPPED = 3,
85 /** Limit has been reached. */
86 RECORDINGSTS_LIMIT_REACHED = 4,
87 /** Recording experienced an error. */
88 RECORDINGSTS_FAILURE = 5,
89 /** The usual 32-bit hack. */
90 RECORDINGSTS_32BIT_HACK = 0x7fffffff
91};
92
93/**
94 * Class for managing a recording context.
95 */
96class RecordingContext
97{
98 friend RecordingStream;
99
100public:
101
102 /** Recording context callback table. */
103 struct CALLBACKS
104 {
105 /**
106 * Recording state got changed. Optional.
107 *
108 * @param pCtx Recording context.
109 * @param enmSts New status.
110 * @param uScreen Screen ID.
111 * Set to UINT32_MAX if the limit of all streams was reached.
112 * @param vrc Result code of state change.
113 * @param pvUser User-supplied pointer. Might be NULL.
114 */
115 DECLCALLBACKMEMBER(void, pfnStateChanged, (RecordingContext *pCtx, RECORDINGSTS enmSts, uint32_t uScreen, int vrc, void *pvUser));
116
117 /** User-supplied pointer. Might be NULL. */
118 void *pvUser;
119 };
120
121public:
122
123 RecordingContext();
124
125 RecordingContext(Console *ptrConsole, const settings::RecordingSettings &Settings);
126
127 virtual ~RecordingContext(void);
128
129public:
130
131 const settings::RecordingSettings &GetConfig(void) const;
132 RecordingStream *GetStream(unsigned uScreen) const;
133 size_t GetStreamCount(void) const;
134#ifdef VBOX_WITH_AUDIO_RECORDING
135 PRECORDINGCODEC GetCodecAudio(void) { return &this->m_CodecAudio; }
136#endif
137
138 int Create(Console *pConsole, const settings::RecordingSettings &Settings);
139 void Destroy(void);
140
141 int Start(void);
142 int Stop(void);
143
144 int SendAudioFrame(const void *pvData, size_t cbData, uint64_t uTimestampMs);
145 int SendVideoFrame(uint32_t uScreen, PRECORDINGVIDEOFRAME pFrame, uint64_t msTimestamp);
146 int SendCursorPositionChange(uint32_t uScreen, int32_t x, int32_t y, uint64_t msTimestamp);
147 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);
148 int SendScreenChange(uint32_t uScreen, PRECORDINGSURFACEINFO pInfo, uint64_t uTimestampMs);
149
150public:
151
152 uint64_t GetCurrentPTS(void) const;
153 bool IsFeatureEnabled(RecordingFeature_T enmFeature);
154 bool IsFeatureEnabled(uint32_t uScreen, RecordingFeature_T enmFeature);
155 bool IsReady(void);
156 bool IsStarted(void);
157 bool IsLimitReached(void);
158 bool IsLimitReached(uint32_t uScreen, uint64_t msTimestamp);
159 bool NeedsUpdate(uint32_t uScreen, uint64_t msTimestamp);
160 void SetCallbacks(RecordingContext::CALLBACKS *pCallbacks, void *pvUser);
161
162 /** The state mouse cursor state.
163 * We currently only support one mouse cursor at a time. */
164 RecordingCursorState m_Cursor;
165
166
167protected:
168
169 int createInternal(Console *ptrConsole, const settings::RecordingSettings &Settings);
170 int startInternal(void);
171 int stopInternal(void);
172
173 void destroyInternal(void);
174
175 RecordingStream *getStreamInternal(unsigned uScreen) const;
176
177 int processCommonData(RecordingBlockMap &mapCommon, RTMSINTERVAL msTimeout);
178 int writeCommonData(RecordingBlockMap &mapCommon, PRECORDINGCODEC pCodec, const void *pvData, size_t cbData, uint64_t msAbsPTS, uint32_t uFlags);
179
180 int lock(void);
181 int unlock(void);
182
183 int onLimitReached(uint32_t uScreen, int vrc);
184
185 static DECLCALLBACK(int) threadMain(RTTHREAD hThreadSelf, void *pvUser);
186
187 int threadNotify(void);
188
189protected:
190
191 int audioInit(const settings::RecordingScreenSettings &screenSettings);
192
193 static DECLCALLBACK(int) audioCodecWriteDataCallback(PRECORDINGCODEC pCodec, const void *pvData, size_t cbData, uint64_t msAbsPTS, uint32_t uFlags, void *pvUser);
194
195protected:
196
197 /** Pointer to the console object. */
198 Console *m_pConsole;
199 /** Used recording configuration. */
200 settings::RecordingSettings m_Settings;
201 /** The current state. */
202 RECORDINGSTS m_enmState;
203 /** Callback table. */
204 CALLBACKS m_Callbacks;
205 /** Critical section to serialize access. */
206 RTCRITSECT m_CritSect;
207 /** Semaphore to signal the encoding worker thread. */
208 RTSEMEVENT m_WaitEvent;
209 /** Shutdown indicator. */
210 bool m_fShutdown;
211 /** Encoding worker thread. */
212 RTTHREAD m_Thread;
213 /** Vector of current recording streams.
214 * Per VM screen (display) one recording stream is being used. */
215 RecordingStreams m_vecStreams;
216 /** Number of streams in vecStreams which currently are enabled for recording. */
217 uint16_t m_cStreamsEnabled;
218 /** Timestamp (in ms) of when recording has been started.
219 * Set to 0 if not started (yet). */
220 uint64_t m_tsStartMs;
221#ifdef VBOX_WITH_AUDIO_RECORDING
222 /** Audio codec to use.
223 *
224 * We multiplex audio data from this recording context to all streams,
225 * to avoid encoding the same audio data for each stream. We ASSUME that
226 * all audio data of a VM will be the same for each stream at a given
227 * point in time. */
228 RECORDINGCODEC m_CodecAudio;
229#endif /* VBOX_WITH_AUDIO_RECORDING */
230 /** Block map of raw common data blocks which need to get encoded first. */
231 RecordingBlockMap m_mapBlocksRaw;
232 /** Block map of encoded common blocks.
233 *
234 * Only do the encoding of common data blocks only once and then multiplex
235 * the encoded data to all affected recording streams.
236 *
237 * This avoids doing the (expensive) encoding + multiplexing work in other
238 * threads like EMT / audio async I/O..
239 *
240 * For now this only affects audio, e.g. all recording streams
241 * need to have the same audio data at a specific point in time. */
242 RecordingBlockMap m_mapBlocksEncoded;
243};
244#endif /* !MAIN_INCLUDED_Recording_h */
245
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette