1 | /* $Id: VideoRecStream.h 75307 2018-11-07 13:56:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Video recording stream code header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2018 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 ____H_VIDEOREC_STREAM
|
---|
19 | #define ____H_VIDEOREC_STREAM
|
---|
20 |
|
---|
21 | #include <map>
|
---|
22 | #include <vector>
|
---|
23 |
|
---|
24 | #include <iprt/critsect.h>
|
---|
25 |
|
---|
26 | #include <VBox/com/array.h>
|
---|
27 | #include <VBox/com/VirtualBox.h>
|
---|
28 | #include <VBox/err.h>
|
---|
29 | #include <VBox/settings.h>
|
---|
30 |
|
---|
31 | #include "VideoRecInternals.h"
|
---|
32 |
|
---|
33 | class WebMWriter;
|
---|
34 | class CaptureContext;
|
---|
35 |
|
---|
36 | /** Structure for queuing all blocks bound to a single timecode.
|
---|
37 | * This can happen if multiple tracks are being involved. */
|
---|
38 | struct CaptureBlocks
|
---|
39 | {
|
---|
40 | virtual ~CaptureBlocks()
|
---|
41 | {
|
---|
42 | Clear();
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Resets a video recording block list by removing (destroying)
|
---|
47 | * all current elements.
|
---|
48 | */
|
---|
49 | void Clear()
|
---|
50 | {
|
---|
51 | while (!List.empty())
|
---|
52 | {
|
---|
53 | PVIDEORECBLOCK pBlock = List.front();
|
---|
54 | VideoRecBlockFree(pBlock);
|
---|
55 | List.pop_front();
|
---|
56 | }
|
---|
57 |
|
---|
58 | Assert(List.size() == 0);
|
---|
59 | }
|
---|
60 |
|
---|
61 | /** The actual block list for this timecode. */
|
---|
62 | VideoRecBlockList List;
|
---|
63 | };
|
---|
64 |
|
---|
65 | /** A block map containing all currently queued blocks.
|
---|
66 | * The key specifies a unique timecode, whereas the value
|
---|
67 | * is a list of blocks which all correlate to the same key (timecode). */
|
---|
68 | typedef std::map<uint64_t, CaptureBlocks *> VideoRecBlockMap;
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Structure for holding a set of recording (data) blocks.
|
---|
72 | */
|
---|
73 | struct CaptureBlockSet
|
---|
74 | {
|
---|
75 | virtual ~CaptureBlockSet()
|
---|
76 | {
|
---|
77 | Clear();
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Resets a recording block set by removing (destroying)
|
---|
82 | * all current elements.
|
---|
83 | */
|
---|
84 | void Clear(void)
|
---|
85 | {
|
---|
86 | VideoRecBlockMap::iterator it = Map.begin();
|
---|
87 | while (it != Map.end())
|
---|
88 | {
|
---|
89 | it->second->Clear();
|
---|
90 | delete it->second;
|
---|
91 | Map.erase(it);
|
---|
92 | it = Map.begin();
|
---|
93 | }
|
---|
94 |
|
---|
95 | Assert(Map.size() == 0);
|
---|
96 | }
|
---|
97 |
|
---|
98 | /** Timestamp (in ms) when this set was last processed. */
|
---|
99 | uint64_t tsLastProcessedMs;
|
---|
100 | /** All blocks related to this block set. */
|
---|
101 | VideoRecBlockMap Map;
|
---|
102 | };
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Class for managing a recording stream.
|
---|
106 | */
|
---|
107 | class CaptureStream
|
---|
108 | {
|
---|
109 | public:
|
---|
110 |
|
---|
111 | CaptureStream(void);
|
---|
112 |
|
---|
113 | CaptureStream(uint32_t uScreen, const settings::CaptureScreenSettings &Settings);
|
---|
114 |
|
---|
115 | virtual ~CaptureStream(void);
|
---|
116 |
|
---|
117 | public:
|
---|
118 |
|
---|
119 | int Init(uint32_t uScreen, const settings::CaptureScreenSettings &Settings);
|
---|
120 | int Uninit(void);
|
---|
121 |
|
---|
122 | int Process(VideoRecBlockMap &mapBlocksCommon);
|
---|
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 uTimeStampMs);
|
---|
125 |
|
---|
126 | const settings::CaptureScreenSettings &GetConfig(void) const;
|
---|
127 | bool IsLimitReached(uint64_t tsNowMs) const;
|
---|
128 | bool IsReady(void) const;
|
---|
129 |
|
---|
130 | protected:
|
---|
131 |
|
---|
132 | int open(const settings::CaptureScreenSettings &Settings);
|
---|
133 | int close(void);
|
---|
134 |
|
---|
135 | int initInternal(uint32_t uScreen, const settings::CaptureScreenSettings &Settings);
|
---|
136 | int uninitInternal(void);
|
---|
137 |
|
---|
138 | int initVideo(void);
|
---|
139 | int unitVideo(void);
|
---|
140 |
|
---|
141 | int initAudio(void);
|
---|
142 |
|
---|
143 | #ifdef VBOX_WITH_LIBVPX
|
---|
144 | int initVideoVPX(void);
|
---|
145 | int uninitVideoVPX(void);
|
---|
146 | int writeVideoVPX(uint64_t uTimeStampMs, PVIDEORECVIDEOFRAME pFrame);
|
---|
147 | #endif
|
---|
148 | void lock(void);
|
---|
149 | void unlock(void);
|
---|
150 |
|
---|
151 | int parseOptionsString(const com::Utf8Str &strOptions);
|
---|
152 |
|
---|
153 | protected:
|
---|
154 |
|
---|
155 | /** Recording context this stream is associated to. */
|
---|
156 | CaptureContext *pCtx;
|
---|
157 | struct
|
---|
158 | {
|
---|
159 | /** File handle to use for writing. */
|
---|
160 | RTFILE hFile;
|
---|
161 | /** File name being used for this stream. */
|
---|
162 | Utf8Str strName;
|
---|
163 | /** Pointer to WebM writer instance being used. */
|
---|
164 | WebMWriter *pWEBM;
|
---|
165 | } File;
|
---|
166 | bool fEnabled;
|
---|
167 | #ifdef VBOX_WITH_AUDIO_VIDEOREC
|
---|
168 | /** Track number of audio stream. */
|
---|
169 | uint8_t uTrackAudio;
|
---|
170 | #endif
|
---|
171 | /** Track number of video stream. */
|
---|
172 | uint8_t uTrackVideo;
|
---|
173 | /** Screen ID. */
|
---|
174 | uint16_t uScreenID;
|
---|
175 | /** Critical section to serialize access. */
|
---|
176 | RTCRITSECT CritSect;
|
---|
177 | /** Timestamp (in ms) of when recording has been start. */
|
---|
178 | uint64_t tsStartMs;
|
---|
179 |
|
---|
180 | struct
|
---|
181 | {
|
---|
182 | /** Minimal delay (in ms) between two video frames.
|
---|
183 | * This value is based on the configured FPS rate. */
|
---|
184 | uint32_t uDelayMs;
|
---|
185 | /** Time stamp (in ms) of the last video frame we encoded. */
|
---|
186 | uint64_t uLastTimeStampMs;
|
---|
187 | /** Number of failed attempts to encode the current video frame in a row. */
|
---|
188 | uint16_t cFailedEncodingFrames;
|
---|
189 | VIDEORECVIDEOCODEC Codec;
|
---|
190 | } Video;
|
---|
191 |
|
---|
192 | settings::CaptureScreenSettings ScreenSettings;
|
---|
193 | /** Common set of video recording (data) blocks, needed for
|
---|
194 | * multiplexing to all recording streams. */
|
---|
195 | CaptureBlockSet Blocks;
|
---|
196 | };
|
---|
197 |
|
---|
198 | /** Vector of video recording streams. */
|
---|
199 | typedef std::vector <CaptureStream *> VideoRecStreams;
|
---|
200 |
|
---|
201 | #endif /* ____H_VIDEOREC_STREAM */
|
---|
202 |
|
---|