VirtualBox

source: vbox/trunk/src/VBox/Main/include/VideoRecStream.h@ 75251

Last change on this file since 75251 was 75251, checked in by vboxsync, 7 years ago

Capturing: Separated capturing settings into new interfaces ICaptureSettings and ICaptureScreenSettings to unload stuff from IMachine; a lot of internal interface / code cleanups. Also see #9286. Work in progress.

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

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