1 | /* $Id: VideoRec.h 75313 2018-11-07 17:13:56Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Video recording 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
|
---|
19 | #define ____H_VIDEOREC
|
---|
20 |
|
---|
21 | #include <VBox/com/array.h>
|
---|
22 | #include <VBox/com/string.h>
|
---|
23 | #include <VBox/com/VirtualBox.h>
|
---|
24 | #include <VBox/err.h>
|
---|
25 | #include <VBox/settings.h>
|
---|
26 |
|
---|
27 | using namespace com;
|
---|
28 |
|
---|
29 | #include "VideoRecInternals.h"
|
---|
30 | #include "VideoRecStream.h"
|
---|
31 |
|
---|
32 | class Console;
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Class for managing a capturing context.
|
---|
36 | */
|
---|
37 | class CaptureContext
|
---|
38 | {
|
---|
39 | public:
|
---|
40 |
|
---|
41 | CaptureContext(Console *pConsole);
|
---|
42 |
|
---|
43 | CaptureContext(Console *pConsole, const settings::CaptureSettings &a_Settings);
|
---|
44 |
|
---|
45 | virtual ~CaptureContext(void);
|
---|
46 |
|
---|
47 | public:
|
---|
48 |
|
---|
49 | const settings::CaptureSettings &GetConfig(void) const;
|
---|
50 | CaptureStream *GetStream(unsigned uScreen) const;
|
---|
51 | size_t GetStreamCount(void) const;
|
---|
52 |
|
---|
53 | int Create(const settings::CaptureSettings &a_Settings);
|
---|
54 | int 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 uTimeStampMs);
|
---|
64 | public:
|
---|
65 |
|
---|
66 | bool IsFeatureEnabled(CaptureFeature_T enmFeature) const;
|
---|
67 | bool IsReady(void) const;
|
---|
68 | bool IsReady(uint32_t uScreen, uint64_t uTimeStampMs) const;
|
---|
69 | bool IsStarted(void) const;
|
---|
70 | bool IsLimitReached(uint32_t uScreen, uint64_t tsNowMs) const;
|
---|
71 |
|
---|
72 | protected:
|
---|
73 |
|
---|
74 | int createInternal(const settings::CaptureSettings &a_Settings);
|
---|
75 | int startInternal(void);
|
---|
76 | int stopInternal(void);
|
---|
77 |
|
---|
78 | int destroyInternal(void);
|
---|
79 |
|
---|
80 | CaptureStream *getStreamInternal(unsigned uScreen) const;
|
---|
81 |
|
---|
82 | static DECLCALLBACK(int) threadMain(RTTHREAD hThreadSelf, void *pvUser);
|
---|
83 |
|
---|
84 | int threadNotify(void);
|
---|
85 |
|
---|
86 | protected:
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Enumeration for a recording context state.
|
---|
90 | */
|
---|
91 | enum VIDEORECSTS
|
---|
92 | {
|
---|
93 | /** Context not initialized. */
|
---|
94 | VIDEORECSTS_UNINITIALIZED = 0,
|
---|
95 | /** Context was created. */
|
---|
96 | VIDEORECSTS_CREATED = 1,
|
---|
97 | /** Context was started. */
|
---|
98 | VIDEORECSTS_STARTED = 2,
|
---|
99 | /** The usual 32-bit hack. */
|
---|
100 | VIDEORECSTS_32BIT_HACK = 0x7fffffff
|
---|
101 | };
|
---|
102 |
|
---|
103 | /** Pointer to the console object. */
|
---|
104 | Console *pConsole;
|
---|
105 | /** Used recording configuration. */
|
---|
106 | settings::CaptureSettings Settings;
|
---|
107 | /** The current state. */
|
---|
108 | VIDEORECSTS enmState;
|
---|
109 | /** Critical section to serialize access. */
|
---|
110 | RTCRITSECT CritSect;
|
---|
111 | /** Semaphore to signal the encoding worker thread. */
|
---|
112 | RTSEMEVENT WaitEvent;
|
---|
113 | /** Shutdown indicator. */
|
---|
114 | bool fShutdown;
|
---|
115 | /** Worker thread. */
|
---|
116 | RTTHREAD Thread;
|
---|
117 | /** Vector of current recording streams.
|
---|
118 | * Per VM screen (display) one recording stream is being used. */
|
---|
119 | VideoRecStreams vecStreams;
|
---|
120 | /** Timestamp (in ms) of when recording has been started. */
|
---|
121 | uint64_t tsStartMs;
|
---|
122 | /** Block map of common blocks which need to get multiplexed
|
---|
123 | * to all recording streams. This common block maps should help
|
---|
124 | * reducing the time spent in EMT and avoid doing the (expensive)
|
---|
125 | * multiplexing work in there.
|
---|
126 | *
|
---|
127 | * For now this only affects audio, e.g. all recording streams
|
---|
128 | * need to have the same audio data at a specific point in time. */
|
---|
129 | VideoRecBlockMap mapBlocksCommon;
|
---|
130 | };
|
---|
131 | #endif /* !____H_VIDEOREC */
|
---|
132 |
|
---|