1 | /* $Id: Recording.h 96322 2022-08-19 07:45:57Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Recording code header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef MAIN_INCLUDED_Recording_h
|
---|
19 | #define MAIN_INCLUDED_Recording_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include <VBox/err.h>
|
---|
25 | #include <VBox/settings.h>
|
---|
26 |
|
---|
27 | #include "RecordingStream.h"
|
---|
28 |
|
---|
29 | class Console;
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Class for managing a recording context.
|
---|
33 | */
|
---|
34 | class RecordingContext
|
---|
35 | {
|
---|
36 | public:
|
---|
37 |
|
---|
38 | RecordingContext();
|
---|
39 |
|
---|
40 | RecordingContext(Console *ptrConsole, const settings::RecordingSettings &Settings);
|
---|
41 |
|
---|
42 | virtual ~RecordingContext(void);
|
---|
43 |
|
---|
44 | public:
|
---|
45 |
|
---|
46 | const settings::RecordingSettings &GetConfig(void) const;
|
---|
47 | RecordingStream *GetStream(unsigned uScreen) const;
|
---|
48 | size_t GetStreamCount(void) const;
|
---|
49 | #ifdef VBOX_WITH_AUDIO_RECORDING
|
---|
50 | PRECORDINGCODEC GetCodecAudio(void) { return &this->CodecAudio; }
|
---|
51 | #endif
|
---|
52 |
|
---|
53 | int Create(Console *pConsole, const settings::RecordingSettings &Settings);
|
---|
54 | void Destroy(void);
|
---|
55 |
|
---|
56 | int Start(void);
|
---|
57 | int Stop(void);
|
---|
58 |
|
---|
59 | int SendAudioFrame(const void *pvData, size_t cbData, uint64_t uTimestampMs);
|
---|
60 | int SendVideoFrame(uint32_t uScreen,
|
---|
61 | uint32_t x, uint32_t y, uint32_t uPixelFormat, uint32_t uBPP,
|
---|
62 | uint32_t uBytesPerLine, uint32_t uSrcWidth, uint32_t uSrcHeight,
|
---|
63 | uint8_t *puSrcData, uint64_t msTimestamp);
|
---|
64 | public:
|
---|
65 |
|
---|
66 | bool IsFeatureEnabled(RecordingFeature_T enmFeature);
|
---|
67 | bool IsReady(void);
|
---|
68 | bool IsReady(uint32_t uScreen, uint64_t msTimestamp);
|
---|
69 | bool IsStarted(void);
|
---|
70 | bool IsLimitReached(void);
|
---|
71 | bool IsLimitReached(uint32_t uScreen, uint64_t msTimestamp);
|
---|
72 | bool NeedsUpdate( uint32_t uScreen, uint64_t msTimestamp);
|
---|
73 |
|
---|
74 | DECLCALLBACK(int) OnLimitReached(uint32_t uScreen, int rc);
|
---|
75 |
|
---|
76 | protected:
|
---|
77 |
|
---|
78 | int createInternal(Console *ptrConsole, const settings::RecordingSettings &Settings);
|
---|
79 | int startInternal(void);
|
---|
80 | int stopInternal(void);
|
---|
81 |
|
---|
82 | void destroyInternal(void);
|
---|
83 |
|
---|
84 | RecordingStream *getStreamInternal(unsigned uScreen) const;
|
---|
85 |
|
---|
86 | int processCommonData(RecordingBlockMap &mapCommon, RTMSINTERVAL msTimeout);
|
---|
87 | int writeCommonData(RecordingBlockMap &mapCommon, PRECORDINGCODEC pCodec, const void *pvData, size_t cbData, uint64_t msAbsPTS, uint32_t uFlags);
|
---|
88 |
|
---|
89 | int lock(void);
|
---|
90 | int unlock(void);
|
---|
91 |
|
---|
92 | static DECLCALLBACK(int) threadMain(RTTHREAD hThreadSelf, void *pvUser);
|
---|
93 |
|
---|
94 | int threadNotify(void);
|
---|
95 |
|
---|
96 | protected:
|
---|
97 |
|
---|
98 | int audioInit(const settings::RecordingScreenSettings &screenSettings);
|
---|
99 |
|
---|
100 | static DECLCALLBACK(int) audioCodecWriteDataCallback(PRECORDINGCODEC pCodec, const void *pvData, size_t cbData, uint64_t msAbsPTS, uint32_t uFlags, void *pvUser);
|
---|
101 |
|
---|
102 | protected:
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Enumeration for a recording context state.
|
---|
106 | */
|
---|
107 | enum RECORDINGSTS
|
---|
108 | {
|
---|
109 | /** Context not initialized. */
|
---|
110 | RECORDINGSTS_UNINITIALIZED = 0,
|
---|
111 | /** Context was created. */
|
---|
112 | RECORDINGSTS_CREATED = 1,
|
---|
113 | /** Context was started. */
|
---|
114 | RECORDINGSTS_STARTED = 2,
|
---|
115 | /** The usual 32-bit hack. */
|
---|
116 | RECORDINGSTS_32BIT_HACK = 0x7fffffff
|
---|
117 | };
|
---|
118 |
|
---|
119 | /** Pointer to the console object. */
|
---|
120 | Console *pConsole;
|
---|
121 | /** Used recording configuration. */
|
---|
122 | settings::RecordingSettings m_Settings;
|
---|
123 | /** The current state. */
|
---|
124 | RECORDINGSTS enmState;
|
---|
125 | /** Critical section to serialize access. */
|
---|
126 | RTCRITSECT CritSect;
|
---|
127 | /** Semaphore to signal the encoding worker thread. */
|
---|
128 | RTSEMEVENT WaitEvent;
|
---|
129 | /** Shutdown indicator. */
|
---|
130 | bool fShutdown;
|
---|
131 | /** Encoding worker thread. */
|
---|
132 | RTTHREAD Thread;
|
---|
133 | /** Vector of current recording streams.
|
---|
134 | * Per VM screen (display) one recording stream is being used. */
|
---|
135 | RecordingStreams vecStreams;
|
---|
136 | /** Number of streams in vecStreams which currently are enabled for recording. */
|
---|
137 | uint16_t cStreamsEnabled;
|
---|
138 | /** Timestamp (in ms) of when recording has been started. */
|
---|
139 | uint64_t tsStartMs;
|
---|
140 | #ifdef VBOX_WITH_AUDIO_RECORDING
|
---|
141 | /** Audio codec to use.
|
---|
142 | *
|
---|
143 | * We multiplex audio data from this recording context to all streams,
|
---|
144 | * to avoid encoding the same audio data for each stream. We ASSUME that
|
---|
145 | * all audio data of a VM will be the same for each stream at a given
|
---|
146 | * point in time. */
|
---|
147 | RECORDINGCODEC CodecAudio;
|
---|
148 | #endif /* VBOX_WITH_AUDIO_RECORDING */
|
---|
149 | /** Block map of raw common data blocks which need to get encoded first. */
|
---|
150 | RecordingBlockMap mapBlocksRaw;
|
---|
151 | /** Block map of encoded common blocks.
|
---|
152 | *
|
---|
153 | * Only do the encoding of common data blocks only once and then multiplex
|
---|
154 | * the encoded data to all affected recording streams.
|
---|
155 | *
|
---|
156 | * This avoids doing the (expensive) encoding + multiplexing work in other
|
---|
157 | * threads like EMT / audio async I/O..
|
---|
158 | *
|
---|
159 | * For now this only affects audio, e.g. all recording streams
|
---|
160 | * need to have the same audio data at a specific point in time. */
|
---|
161 | RecordingBlockMap mapBlocksEncoded;
|
---|
162 | };
|
---|
163 | #endif /* !MAIN_INCLUDED_Recording_h */
|
---|
164 |
|
---|