1 | /* $Id: Recording.h 76893 2019-01-18 13:51:30Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Recording code header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2019 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_Recording_h
|
---|
19 | #define MAIN_INCLUDED_Recording_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include <VBox/com/array.h>
|
---|
25 | #include <VBox/com/string.h>
|
---|
26 | #include <VBox/com/VirtualBox.h>
|
---|
27 | #include <VBox/settings.h>
|
---|
28 |
|
---|
29 | using namespace com;
|
---|
30 |
|
---|
31 | #include "RecordingInternals.h"
|
---|
32 | #include "RecordingStream.h"
|
---|
33 |
|
---|
34 | class Console;
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Class for managing a recording context.
|
---|
38 | */
|
---|
39 | class RecordingContext
|
---|
40 | {
|
---|
41 | public:
|
---|
42 |
|
---|
43 | RecordingContext(Console *pConsole, const settings::RecordingSettings &a_Settings);
|
---|
44 |
|
---|
45 | virtual ~RecordingContext(void);
|
---|
46 |
|
---|
47 | public:
|
---|
48 |
|
---|
49 | const settings::RecordingSettings &GetConfig(void) const;
|
---|
50 | RecordingStream *GetStream(unsigned uScreen) const;
|
---|
51 | size_t GetStreamCount(void) const;
|
---|
52 |
|
---|
53 | int Create(const settings::RecordingSettings &a_Settings);
|
---|
54 | void Destroy(void);
|
---|
55 |
|
---|
56 | int Start(void);
|
---|
57 | int Stop(void);
|
---|
58 |
|
---|
59 | int SendAudioFrame(const void *pvData, size_t cbData, uint64_t uTimestampMs);
|
---|
60 | int SendVideoFrame(uint32_t uScreen,
|
---|
61 | uint32_t x, uint32_t y, uint32_t uPixelFormat, uint32_t uBPP,
|
---|
62 | uint32_t uBytesPerLine, uint32_t uSrcWidth, uint32_t uSrcHeight,
|
---|
63 | uint8_t *puSrcData, uint64_t msTimestamp);
|
---|
64 | public:
|
---|
65 |
|
---|
66 | bool IsFeatureEnabled(RecordingFeature_T enmFeature);
|
---|
67 | bool IsReady(void);
|
---|
68 | bool IsReady(uint32_t uScreen, uint64_t msTimestamp);
|
---|
69 | bool IsStarted(void);
|
---|
70 | bool IsLimitReached(void);
|
---|
71 | bool IsLimitReached(uint32_t uScreen, uint64_t msTimestamp);
|
---|
72 |
|
---|
73 | DECLCALLBACK(int) OnLimitReached(uint32_t uScreen, int rc);
|
---|
74 |
|
---|
75 | protected:
|
---|
76 |
|
---|
77 | int createInternal(const settings::RecordingSettings &a_Settings);
|
---|
78 | int startInternal(void);
|
---|
79 | int stopInternal(void);
|
---|
80 |
|
---|
81 | void destroyInternal(void);
|
---|
82 |
|
---|
83 | RecordingStream *getStreamInternal(unsigned uScreen) const;
|
---|
84 |
|
---|
85 | int lock(void);
|
---|
86 | int unlock(void);
|
---|
87 |
|
---|
88 | static DECLCALLBACK(int) threadMain(RTTHREAD hThreadSelf, void *pvUser);
|
---|
89 |
|
---|
90 | int threadNotify(void);
|
---|
91 |
|
---|
92 | protected:
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Enumeration for a recording context state.
|
---|
96 | */
|
---|
97 | enum RECORDINGSTS
|
---|
98 | {
|
---|
99 | /** Context not initialized. */
|
---|
100 | RECORDINGSTS_UNINITIALIZED = 0,
|
---|
101 | /** Context was created. */
|
---|
102 | RECORDINGSTS_CREATED = 1,
|
---|
103 | /** Context was started. */
|
---|
104 | RECORDINGSTS_STARTED = 2,
|
---|
105 | /** The usual 32-bit hack. */
|
---|
106 | RECORDINGSTS_32BIT_HACK = 0x7fffffff
|
---|
107 | };
|
---|
108 |
|
---|
109 | /** Pointer to the console object. */
|
---|
110 | Console *pConsole;
|
---|
111 | /** Used recording configuration. */
|
---|
112 | settings::RecordingSettings Settings;
|
---|
113 | /** The current state. */
|
---|
114 | RECORDINGSTS enmState;
|
---|
115 | /** Critical section to serialize access. */
|
---|
116 | RTCRITSECT CritSect;
|
---|
117 | /** Semaphore to signal the encoding worker thread. */
|
---|
118 | RTSEMEVENT WaitEvent;
|
---|
119 | /** Shutdown indicator. */
|
---|
120 | bool fShutdown;
|
---|
121 | /** Worker thread. */
|
---|
122 | RTTHREAD Thread;
|
---|
123 | /** Vector of current recording streams.
|
---|
124 | * Per VM screen (display) one recording stream is being used. */
|
---|
125 | RecordingStreams vecStreams;
|
---|
126 | /** Number of streams in vecStreams which currently are enabled for recording. */
|
---|
127 | uint16_t cStreamsEnabled;
|
---|
128 | /** Timestamp (in ms) of when recording has been started. */
|
---|
129 | uint64_t tsStartMs;
|
---|
130 | /** Block map of common blocks which need to get multiplexed
|
---|
131 | * to all recording streams. This common block maps should help
|
---|
132 | * reducing the time spent in EMT and avoid doing the (expensive)
|
---|
133 | * multiplexing work in there.
|
---|
134 | *
|
---|
135 | * For now this only affects audio, e.g. all recording streams
|
---|
136 | * need to have the same audio data at a specific point in time. */
|
---|
137 | RecordingBlockMap mapBlocksCommon;
|
---|
138 | };
|
---|
139 | #endif /* !MAIN_INCLUDED_Recording_h */
|
---|
140 |
|
---|