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