VirtualBox

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

最後變更 在這個檔案從96175是 96175,由 vboxsync 提交於 3 年 前

Recording: Implemented support for Vorbis codec (provided by libvorbis, not enabled by default yet). This also makes all the codec handling more abstract by using a simple codec wrapper, to keep other places free from codec-specific as much as possible. Initial implementation works and output files are being recognized by media players, but there still are some timing bugs to resolve, as well as optimizing the performance. bugref:10275

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 6.1 KB
 
1/* $Id: RecordingStream.h 96175 2022-08-12 14:01:17Z 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.alldomusa.eu.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 SendVideoFrame(uint32_t x, uint32_t y, uint32_t uPixelFormat, uint32_t uBPP, uint32_t uBytesPerLine,
123 uint32_t uSrcWidth, uint32_t uSrcHeight, uint8_t *puSrcData, uint64_t msTimestamp);
124
125 const settings::RecordingScreenSettings &GetConfig(void) const;
126 uint16_t GetID(void) const { return this->uScreenID; };
127#ifdef VBOX_WITH_AUDIO_RECORDING
128 const PRECORDINGCODEC GetAudioCodec(void) { return &this->CodecAudio; };
129#endif
130 const PRECORDINGCODEC GetVideoCodec(void) { return &this->CodecVideo; };
131 bool IsLimitReached(uint64_t msTimestamp) const;
132 bool IsReady(void) const;
133
134protected:
135
136 static int codecWriteDataCallback(PRECORDINGCODEC pCodec, const void *pvData, size_t cbData, void *pvUser);
137
138protected:
139
140 int open(const settings::RecordingScreenSettings &Settings);
141 int close(void);
142
143 int initInternal(RecordingContext *pCtx, uint32_t uScreen, const settings::RecordingScreenSettings &Settings);
144 int uninitInternal(void);
145
146 int initVideo(const settings::RecordingScreenSettings &Settings);
147 int unitVideo(void);
148
149 int initAudio(const settings::RecordingScreenSettings &Settings);
150
151 bool isLimitReachedInternal(uint64_t msTimestamp) const;
152 int iterateInternal(uint64_t msTimestamp);
153
154 void lock(void);
155 void unlock(void);
156
157protected:
158
159 /**
160 * Enumeration for a recording stream state.
161 */
162 enum RECORDINGSTREAMSTATE
163 {
164 /** Stream not initialized. */
165 RECORDINGSTREAMSTATE_UNINITIALIZED = 0,
166 /** Stream was initialized. */
167 RECORDINGSTREAMSTATE_INITIALIZED = 1,
168 /** The usual 32-bit hack. */
169 RECORDINGSTREAMSTATE_32BIT_HACK = 0x7fffffff
170 };
171
172 /** Recording context this stream is associated to. */
173 RecordingContext *pCtx;
174 /** The current state. */
175 RECORDINGSTREAMSTATE enmState;
176 struct
177 {
178 /** File handle to use for writing. */
179 RTFILE hFile;
180 /** Pointer to WebM writer instance being used. */
181 WebMWriter *pWEBM;
182 } File;
183 bool fEnabled;
184 /** Track number of audio stream.
185 * Set to UINT8_MAX if not being used. */
186 uint8_t uTrackAudio;
187 /** Track number of video stream.
188 * Set to UINT8_MAX if not being used. */
189 uint8_t uTrackVideo;
190 /** Screen ID. */
191 uint16_t uScreenID;
192 /** Critical section to serialize access. */
193 RTCRITSECT CritSect;
194 /** Timestamp (in ms) of when recording has been start. */
195 uint64_t tsStartMs;
196
197#ifdef VBOX_WITH_AUDIO_RECORDING
198 /** Audio codec instance data to use. */
199 RECORDINGCODEC CodecAudio;
200#endif
201 /** Video codec instance data to use. */
202 RECORDINGCODEC CodecVideo;
203 /** Screen settings to use. */
204 settings::RecordingScreenSettings ScreenSettings;
205 /** Common set of recording (data) blocks, needed for
206 * multiplexing to all recording streams. */
207 RecordingBlockSet Blocks;
208};
209
210/** Vector of recording streams. */
211typedef std::vector <RecordingStream *> RecordingStreams;
212
213#endif /* !MAIN_INCLUDED_RecordingStream_h */
214
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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