1 | /* $Id: VideoRecStream.h 74999 2018-10-23 13:50:28Z 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 |
|
---|
30 | #include "VideoRecInternals.h"
|
---|
31 |
|
---|
32 | class WebMWriter;
|
---|
33 |
|
---|
34 | struct VIDEORECCFG;
|
---|
35 | typedef struct VIDEORECCFG *PVIDEORECCFG;
|
---|
36 |
|
---|
37 | struct VIDEORECCONTEXT;
|
---|
38 | typedef struct VIDEORECCONTEXT *PVIDEORECCONTEXT;
|
---|
39 |
|
---|
40 |
|
---|
41 | /** Structure for queuing all blocks bound to a single timecode.
|
---|
42 | * This can happen if multiple tracks are being involved. */
|
---|
43 | struct VideoRecBlocks
|
---|
44 | {
|
---|
45 | virtual ~VideoRecBlocks()
|
---|
46 | {
|
---|
47 | Clear();
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Resets a video recording block list by removing (destroying)
|
---|
52 | * all current elements.
|
---|
53 | */
|
---|
54 | void Clear()
|
---|
55 | {
|
---|
56 | while (!List.empty())
|
---|
57 | {
|
---|
58 | PVIDEORECBLOCK pBlock = List.front();
|
---|
59 | VideoRecBlockFree(pBlock);
|
---|
60 | List.pop_front();
|
---|
61 | }
|
---|
62 |
|
---|
63 | Assert(List.size() == 0);
|
---|
64 | }
|
---|
65 |
|
---|
66 | /** The actual block list for this timecode. */
|
---|
67 | VideoRecBlockList List;
|
---|
68 | };
|
---|
69 |
|
---|
70 | /** A block map containing all currently queued blocks.
|
---|
71 | * The key specifies a unique timecode, whereas the value
|
---|
72 | * is a list of blocks which all correlate to the same key (timecode). */
|
---|
73 | typedef std::map<uint64_t, VideoRecBlocks *> VideoRecBlockMap;
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Structure for holding a set of video recording (data) blocks.
|
---|
77 | */
|
---|
78 | struct VideoRecBlockSet
|
---|
79 | {
|
---|
80 | virtual ~VideoRecBlockSet()
|
---|
81 | {
|
---|
82 | Clear();
|
---|
83 | }
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Resets a video recording block set by removing (destroying)
|
---|
87 | * all current elements.
|
---|
88 | */
|
---|
89 | void Clear()
|
---|
90 | {
|
---|
91 | VideoRecBlockMap::iterator it = Map.begin();
|
---|
92 | while (it != Map.end())
|
---|
93 | {
|
---|
94 | it->second->Clear();
|
---|
95 | delete it->second;
|
---|
96 | Map.erase(it);
|
---|
97 | it = Map.begin();
|
---|
98 | }
|
---|
99 |
|
---|
100 | Assert(Map.size() == 0);
|
---|
101 | }
|
---|
102 |
|
---|
103 | /** Timestamp (in ms) when this set was last processed. */
|
---|
104 | uint64_t tsLastProcessedMs;
|
---|
105 | /** All blocks related to this block set. */
|
---|
106 | VideoRecBlockMap Map;
|
---|
107 | };
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * Structure for maintaining a video recording stream.
|
---|
111 | */
|
---|
112 | typedef struct VIDEORECSTREAM
|
---|
113 | {
|
---|
114 | /** Video recording context this stream is associated to. */
|
---|
115 | PVIDEORECCONTEXT pCtx;
|
---|
116 | /** Destination where to write the stream to. */
|
---|
117 | VIDEORECDEST enmDst;
|
---|
118 | union
|
---|
119 | {
|
---|
120 | struct
|
---|
121 | {
|
---|
122 | /** File handle to use for writing. */
|
---|
123 | RTFILE hFile;
|
---|
124 | /** File name being used for this stream. */
|
---|
125 | char *pszFile;
|
---|
126 | /** Pointer to WebM writer instance being used. */
|
---|
127 | WebMWriter *pWEBM;
|
---|
128 | } File;
|
---|
129 | };
|
---|
130 | #ifdef VBOX_WITH_AUDIO_VIDEOREC
|
---|
131 | /** Track number of audio stream. */
|
---|
132 | uint8_t uTrackAudio;
|
---|
133 | #endif
|
---|
134 | /** Track number of video stream. */
|
---|
135 | uint8_t uTrackVideo;
|
---|
136 | /** Screen ID. */
|
---|
137 | uint16_t uScreenID;
|
---|
138 | /** Whether video recording is enabled or not. */
|
---|
139 | bool fEnabled;
|
---|
140 | /** Critical section to serialize access. */
|
---|
141 | RTCRITSECT CritSect;
|
---|
142 |
|
---|
143 | struct
|
---|
144 | {
|
---|
145 | /** Codec-specific data. */
|
---|
146 | VIDEORECVIDEOCODEC Codec;
|
---|
147 | /** Minimal delay (in ms) between two video frames.
|
---|
148 | * This value is based on the configured FPS rate. */
|
---|
149 | uint32_t uDelayMs;
|
---|
150 | /** Target X resolution (in pixels). */
|
---|
151 | uint32_t uWidth;
|
---|
152 | /** Target Y resolution (in pixels). */
|
---|
153 | uint32_t uHeight;
|
---|
154 | /** Time stamp (in ms) of the last video frame we encoded. */
|
---|
155 | uint64_t uLastTimeStampMs;
|
---|
156 | /** Number of failed attempts to encode the current video frame in a row. */
|
---|
157 | uint16_t cFailedEncodingFrames;
|
---|
158 | } Video;
|
---|
159 |
|
---|
160 | /** Common set of video recording (data) blocks, needed for
|
---|
161 | * multiplexing to all recording streams. */
|
---|
162 | VideoRecBlockSet Blocks;
|
---|
163 | } VIDEORECSTREAM, *PVIDEORECSTREAM;
|
---|
164 |
|
---|
165 | /** Vector of video recording streams. */
|
---|
166 | typedef std::vector <PVIDEORECSTREAM> VideoRecStreams;
|
---|
167 |
|
---|
168 | int videoRecStreamClose(PVIDEORECSTREAM pStream);
|
---|
169 | PVIDEORECSTREAM videoRecStreamGet(PVIDEORECCONTEXT pCtx, uint32_t uScreen);
|
---|
170 | int videoRecStreamOpen(PVIDEORECSTREAM pStream, PVIDEORECCFG pCfg);
|
---|
171 | int videoRecStreamUninit(PVIDEORECSTREAM pStream);
|
---|
172 | int videoRecStreamUnitVideo(PVIDEORECSTREAM pStream);
|
---|
173 | int videoRecStreamInitVideo(PVIDEORECSTREAM pStream, PVIDEORECCFG pCfg);
|
---|
174 | #ifdef VBOX_WITH_LIBVPX
|
---|
175 | int videoRecStreamInitVideoVPX(PVIDEORECSTREAM pStream, PVIDEORECCFG pCfg);
|
---|
176 | int videoRecStreamUninitVideoVPX(PVIDEORECSTREAM pStream);
|
---|
177 | int videoRecStreamWriteVideoVPX(PVIDEORECSTREAM pStream, uint64_t uTimeStampMs, PVIDEORECVIDEOFRAME pFrame);
|
---|
178 | #endif
|
---|
179 | void videoRecStreamLock(PVIDEORECSTREAM pStream);
|
---|
180 | void videoRecStreamUnlock(PVIDEORECSTREAM pStream);
|
---|
181 |
|
---|
182 | #endif /* ____H_VIDEOREC_STREAM */
|
---|
183 |
|
---|