VirtualBox

source: vbox/trunk/src/VBox/Main/include/Recording.h@ 96260

Last change on this file since 96260 was 96260, checked in by vboxsync, 3 years ago

Recording/Main: Greatly reduced workload spent in the recording driver's async I/O thread by also encoding the audio data in the dedicated recording thread (using two different block maps, see comments for details). bugref:10275

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
  • Property svn:mergeinfo set to (toggle deleted branches)
    /branches/VBox-3.0/src/VBox/Frontends/VBoxHeadless/VideoCapture/EncodeAndWrite.h58652,​70973
    /branches/VBox-3.2/src/VBox/Frontends/VBoxHeadless/VideoCapture/EncodeAndWrite.h66309,​66318
    /branches/VBox-4.0/src/VBox/Frontends/VBoxHeadless/VideoCapture/EncodeAndWrite.h70873
    /branches/VBox-4.1/src/VBox/Frontends/VBoxHeadless/VideoCapture/EncodeAndWrite.h74233
    /branches/VBox-4.2/src/VBox/Main/src-client/VideoRec.h91503-91504,​91506-91508,​91510,​91514-91515,​91521
    /branches/VBox-4.3/src/VBox/Main/src-client/VideoRec.h91223
    /branches/VBox-4.3/trunk/src/VBox/Main/src-client/VideoRec.h91223
    /branches/dsen/gui/src/VBox/Frontends/VBoxHeadless/VideoCapture/EncodeAndWrite.h79076-79078,​79089,​79109-79110,​79112-79113,​79127-79130,​79134,​79141,​79151,​79155,​79157-79159,​79193,​79197
    /branches/dsen/gui2/src/VBox/Frontends/VBoxHeadless/VideoCapture/EncodeAndWrite.h79224,​79228,​79233,​79235,​79258,​79262-79263,​79273,​79341,​79345,​79354,​79357,​79387-79388,​79559-79569,​79572-79573,​79578,​79581-79582,​79590-79591,​79598-79599,​79602-79603,​79605-79606,​79632,​79635,​79637,​79644
    /branches/dsen/gui3/src/VBox/Frontends/VBoxHeadless/VideoCapture/EncodeAndWrite.h79645-79692
File size: 5.5 KB
Line 
1/* $Id: Recording.h 96260 2022-08-17 12:02:46Z vboxsync $ */
2/** @file
3 * Recording code header.
4 */
5
6/*
7 * Copyright (C) 2012-2022 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. 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
29class Console;
30
31/**
32 * Class for managing a recording context.
33 */
34class RecordingContext
35{
36public:
37
38 RecordingContext();
39
40 RecordingContext(Console *ptrConsole, const settings::RecordingSettings &Settings);
41
42 virtual ~RecordingContext(void);
43
44public:
45
46 const settings::RecordingSettings &GetConfig(void) const;
47 RecordingStream *GetStream(unsigned uScreen) const;
48 size_t GetStreamCount(void) const;
49#ifdef VBOX_WITH_AUDIO_RECORDING
50 PRECORDINGCODEC GetCodecAudio(void) { return &this->CodecAudio; }
51#endif
52
53 int Create(Console *pConsole, const settings::RecordingSettings &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);
64public:
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
75protected:
76
77 int createInternal(Console *ptrConsole, const settings::RecordingSettings &Settings);
78 int startInternal(void);
79 int stopInternal(void);
80
81 void destroyInternal(void);
82
83 RecordingStream *getStreamInternal(unsigned uScreen) const;
84
85 int processCommonData(RecordingBlockMap &mapCommon, RTMSINTERVAL msTimeout);
86 int writeCommonData(RecordingBlockMap &mapCommon, PRECORDINGCODEC pCodec, const void *pvData, size_t cbData, uint64_t msAbsPTS, uint32_t uFlags);
87
88 int lock(void);
89 int unlock(void);
90
91 static DECLCALLBACK(int) threadMain(RTTHREAD hThreadSelf, void *pvUser);
92
93 int threadNotify(void);
94
95protected:
96
97 int audioInit(const settings::RecordingScreenSettings &screenSettings);
98
99 static DECLCALLBACK(int) audioCodecWriteDataCallback(PRECORDINGCODEC pCodec, const void *pvData, size_t cbData, uint64_t msAbsPTS, uint32_t uFlags, void *pvUser);
100
101protected:
102
103 /**
104 * Enumeration for a recording context state.
105 */
106 enum RECORDINGSTS
107 {
108 /** Context not initialized. */
109 RECORDINGSTS_UNINITIALIZED = 0,
110 /** Context was created. */
111 RECORDINGSTS_CREATED = 1,
112 /** Context was started. */
113 RECORDINGSTS_STARTED = 2,
114 /** The usual 32-bit hack. */
115 RECORDINGSTS_32BIT_HACK = 0x7fffffff
116 };
117
118 /** Pointer to the console object. */
119 Console *pConsole;
120 /** Used recording configuration. */
121 settings::RecordingSettings m_Settings;
122 /** The current state. */
123 RECORDINGSTS enmState;
124 /** Critical section to serialize access. */
125 RTCRITSECT CritSect;
126 /** Semaphore to signal the encoding worker thread. */
127 RTSEMEVENT WaitEvent;
128 /** Shutdown indicator. */
129 bool fShutdown;
130 /** Encoding worker thread. */
131 RTTHREAD Thread;
132 /** Vector of current recording streams.
133 * Per VM screen (display) one recording stream is being used. */
134 RecordingStreams vecStreams;
135 /** Number of streams in vecStreams which currently are enabled for recording. */
136 uint16_t cStreamsEnabled;
137 /** Timestamp (in ms) of when recording has been started. */
138 uint64_t tsStartMs;
139#ifdef VBOX_WITH_AUDIO_RECORDING
140 /** Audio codec to use.
141 *
142 * We multiplex audio data from this recording context to all streams,
143 * to avoid encoding the same audio data for each stream. We ASSUME that
144 * all audio data of a VM will be the same for each stream at a given
145 * point in time. */
146 RECORDINGCODEC CodecAudio;
147#endif /* VBOX_WITH_AUDIO_RECORDING */
148 /** Block map of raw common data blocks which need to get encoded first. */
149 RecordingBlockMap mapBlocksRaw;
150 /** Block map of encoded common blocks.
151 *
152 * Only do the encoding of common data blocks only once and then multiplex
153 * the encoded data to all affected recording streams.
154 *
155 * This avoids doing the (expensive) encoding + multiplexing work in other
156 * threads like EMT / audio async I/O..
157 *
158 * For now this only affects audio, e.g. all recording streams
159 * need to have the same audio data at a specific point in time. */
160 RecordingBlockMap mapBlocksEncoded;
161};
162#endif /* !MAIN_INCLUDED_Recording_h */
163
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