VirtualBox

source: vbox/trunk/src/VBox/Main/include/RecordingStream.h@ 96324

Last change on this file since 96324 was 96324, checked in by vboxsync, 2 years ago

Recording/Main: Renaming (use m_ prefixes for class variables).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/* $Id: RecordingStream.h 96324 2022-08-19 08:15:55Z vboxsync $ */
2/** @file
3 * Recording stream 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_RecordingStream_h
19#define MAIN_INCLUDED_RecordingStream_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <map>
25#include <vector>
26
27#include <iprt/critsect.h>
28
29#include "RecordingInternals.h"
30
31class WebMWriter;
32class RecordingContext;
33
34/** Structure for queuing all blocks bound to a single timecode.
35 * This can happen if multiple tracks are being involved. */
36struct RecordingBlocks
37{
38 virtual ~RecordingBlocks()
39 {
40 Clear();
41 }
42
43 /**
44 * Resets a recording block list by removing (destroying)
45 * all current elements.
46 */
47 void Clear()
48 {
49 while (!List.empty())
50 {
51 RecordingBlock *pBlock = List.front();
52 List.pop_front();
53 delete pBlock;
54 }
55
56 Assert(List.size() == 0);
57 }
58
59 /** The actual block list for this timecode. */
60 RecordingBlockList List;
61};
62
63/** A block map containing all currently queued blocks.
64 * The key specifies a unique timecode, whereas the value
65 * is a list of blocks which all correlate to the same key (timecode). */
66typedef std::map<uint64_t, RecordingBlocks *> RecordingBlockMap;
67
68/**
69 * Structure for holding a set of recording (data) blocks.
70 */
71struct RecordingBlockSet
72{
73 virtual ~RecordingBlockSet()
74 {
75 Clear();
76 }
77
78 /**
79 * Resets a recording block set by removing (destroying)
80 * all current elements.
81 */
82 void Clear(void)
83 {
84 RecordingBlockMap::iterator it = Map.begin();
85 while (it != Map.end())
86 {
87 it->second->Clear();
88 delete it->second;
89 Map.erase(it);
90 it = Map.begin();
91 }
92
93 Assert(Map.size() == 0);
94 }
95
96 /** Timestamp (in ms) when this set was last processed. */
97 uint64_t tsLastProcessedMs;
98 /** All blocks related to this block set. */
99 RecordingBlockMap Map;
100};
101
102/**
103 * Class for managing a recording stream.
104 *
105 * A recording stream represents one entity to record (e.g. on screen / monitor),
106 * so there is a 1:1 mapping (stream <-> monitors).
107 */
108class RecordingStream
109{
110public:
111
112 RecordingStream(RecordingContext *pCtx, uint32_t uScreen, const settings::RecordingScreenSettings &Settings);
113
114 virtual ~RecordingStream(void);
115
116public:
117
118 int Init(RecordingContext *pCtx, uint32_t uScreen, const settings::RecordingScreenSettings &Settings);
119 int Uninit(void);
120
121 int Process(RecordingBlockMap &mapBlocksCommon);
122 int SendAudioFrame(const void *pvData, size_t cbData, uint64_t msTimestamp);
123 int SendVideoFrame(uint32_t x, uint32_t y, uint32_t uPixelFormat, uint32_t uBPP, uint32_t uBytesPerLine,
124 uint32_t uSrcWidth, uint32_t uSrcHeight, uint8_t *puSrcData, uint64_t msTimestamp);
125
126 const settings::RecordingScreenSettings &GetConfig(void) const;
127 uint16_t GetID(void) const { return this->m_uScreenID; };
128#ifdef VBOX_WITH_AUDIO_RECORDING
129 PRECORDINGCODEC GetAudioCodec(void) { return this->m_pCodecAudio; };
130#endif
131 PRECORDINGCODEC GetVideoCodec(void) { return &this->m_CodecVideo; };
132
133 bool IsLimitReached(uint64_t msTimestamp) const;
134 bool IsReady(void) const;
135 bool NeedsUpdate(uint64_t msTimestamp) const;
136
137public:
138
139 static DECLCALLBACK(int) codecWriteDataCallback(PRECORDINGCODEC pCodec, const void *pvData, size_t cbData, uint64_t msAbsPTS, uint32_t uFlags, void *pvUser);
140
141protected:
142
143 int open(const settings::RecordingScreenSettings &screenSettings);
144 int close(void);
145
146 int initInternal(RecordingContext *pCtx, uint32_t uScreen, const settings::RecordingScreenSettings &screenSettings);
147 int uninitInternal(void);
148
149 int initVideo(const settings::RecordingScreenSettings &screenSettings);
150 int unitVideo(void);
151
152 bool isLimitReachedInternal(uint64_t msTimestamp) const;
153 int iterateInternal(uint64_t msTimestamp);
154
155 int codecWriteToWebM(PRECORDINGCODEC pCodec, const void *pvData, size_t cbData, uint64_t msAbsPTS, uint32_t uFlags);
156
157 void lock(void);
158 void unlock(void);
159
160protected:
161
162 /**
163 * Enumeration for a recording stream state.
164 */
165 enum RECORDINGSTREAMSTATE
166 {
167 /** Stream not initialized. */
168 RECORDINGSTREAMSTATE_UNINITIALIZED = 0,
169 /** Stream was initialized. */
170 RECORDINGSTREAMSTATE_INITIALIZED = 1,
171 /** The usual 32-bit hack. */
172 RECORDINGSTREAMSTATE_32BIT_HACK = 0x7fffffff
173 };
174
175 /** Recording context this stream is associated to. */
176 RecordingContext *m_pCtx;
177 /** The current state. */
178 RECORDINGSTREAMSTATE m_enmState;
179 struct
180 {
181 /** File handle to use for writing. */
182 RTFILE m_hFile;
183 /** Pointer to WebM writer instance being used. */
184 WebMWriter *m_pWEBM;
185 } File;
186 bool m_fEnabled;
187 /** Track number of audio stream.
188 * Set to UINT8_MAX if not being used. */
189 uint8_t m_uTrackAudio;
190 /** Track number of video stream.
191 * Set to UINT8_MAX if not being used. */
192 uint8_t m_uTrackVideo;
193 /** Screen ID. */
194 uint16_t m_uScreenID;
195 /** Critical section to serialize access. */
196 RTCRITSECT m_CritSect;
197 /** Timestamp (in ms) of when recording has been started. */
198 uint64_t m_tsStartMs;
199#ifdef VBOX_WITH_AUDIO_RECORDING
200 /** Pointer to audio codec instance data to use.
201 *
202 * We multiplex audio data from the recording context to all streams,
203 * to avoid encoding the same audio data for each stream. We ASSUME that
204 * all audio data of a VM will be the same for each stream at a given
205 * point in time.
206 *
207 * Might be NULL if not being used. */
208 PRECORDINGCODEC m_pCodecAudio;
209#endif /* VBOX_WITH_AUDIO_RECORDING */
210 /** Video codec instance data to use. */
211 RECORDINGCODEC m_CodecVideo;
212 /** Screen settings to use. */
213 settings::RecordingScreenSettings
214 m_ScreenSettings;
215 /** Common set of recording (data) blocks, needed for
216 * multiplexing to all recording streams. */
217 RecordingBlockSet m_Blocks;
218};
219
220/** Vector of recording streams. */
221typedef std::vector <RecordingStream *> RecordingStreams;
222
223#endif /* !MAIN_INCLUDED_RecordingStream_h */
224
Note: See TracBrowser for help on using the repository browser.

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