VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
Recorder.h
1// -----------------------------------------------------------------------------
2// This file is part of VirtualC64
3//
4// Copyright (C) Dirk W. Hoffmann. www.dirkwhoffmann.de
5// This FILE is dual-licensed. You are free to choose between:
6//
7// - The GNU General Public License v3 (or any later version)
8// - The Mozilla Public License v2
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR MPL-2.0
11// -----------------------------------------------------------------------------
12
13#pragma once
14
15#include "RecorderTypes.h"
16#include "SubComponent.h"
17#include "Chrono.h"
18#include "FFmpeg.h"
19#include "NamedPipe.h"
20
21namespace vc64 {
22
23class Recorder final : public SubComponent, public Inspectable<RecorderInfo> {
24
25 Descriptions descriptions = {{
26
27 .name = "Recorder",
28 .description = "Screen Recorder"
29 }};
30
31 ConfigOptions options = {
32
38 };
39
40 // Current configuration
41 RecorderConfig config = { };
42
43
44 //
45 // Handles
46 //
47
48 // FFmpeg instances
49 FFmpeg videoFFmpeg;
50 FFmpeg audioFFmpeg;
51
52 // Video and audio pipes
53 NamedPipe videoPipe;
54 NamedPipe audioPipe;
55
56
57 //
58 // Recording status
59 //
60
61 // The current recorder state
62 RecState state = REC_STATE_WAIT;
63
64
65 //
66 // Recording parameters
67 //
68
69 // Sound samples per frame (882 for PAL, 735 for NTSC)
70 isize samplesPerFrame = 0;
71
72 // The texture cutout that is going to be recorded
73 struct { isize x1; isize y1; isize x2; isize y2; } cutout;
74
75 // Time stamps
76 util::Time recStart;
77 util::Time recStop;
78
79
80 //
81 // Methods
82 //
83
84public:
85
86 Recorder(C64& ref);
87 Recorder& operator= (const Recorder& other) { return *this; }
88
89
90 //
91 // Methods from Serializable
92 //
93
94public:
95
96 template <class T> void serialize(T& worker) { } SERIALIZERS(serialize);
97
98
99 //
100 // Methods from CoreComponent
101 //
102
103public:
104
105 const Descriptions &getDescriptions() const override { return descriptions; }
106
107private:
108
109 void _dump(Category category, std::ostream& os) const override;
110 void _initialize() override;
111
112
113 //
114 // Configuring
115 //
116
117public:
118
119 const RecorderConfig &getConfig() const { return config; }
120 const ConfigOptions &getOptions() const override { return options; }
121 i64 getOption(Option opt) const override;
122 void checkOption(Option opt, i64 value) override;
123 void setOption(Option opt, i64 value) override;
124
125
126 //
127 // Inspecting
128 //
129
130public:
131
132 void cacheInfo(RecorderInfo &result) const override;
133
134
135 //
136 // Querying locations and flags
137 //
138
139 // Returns the paths to the two named input pipes
140 string videoPipePath();
141 string audioPipePath();
142
143 // Return the paths to the two temporary output files
144 string videoStreamPath();
145 string audioStreamPath();
146
147 // Returns the log level passed to FFmpef
148 const string loglevel() { return REC_DEBUG ? "verbose" : "warning"; }
149
150private:
151
152 // Returns the length of the recorded video
153 util::Time getDuration() const;
154
155
156 //
157 // Starting and stopping a video capture
158 //
159
160public:
161
162 // Checks whether the screen is currently recorded
163 bool isRecording() const { return state != REC_STATE_WAIT; }
164
165 // Starts the screen recorder
166 void startRecording(isize x1, isize y1, isize x2, isize y2);
167
168 // Stops the screen recorder
169 void stopRecording();
170
171 // Exports the recorded video
172 bool exportAs(const fs::path &path);
173
174
175 //
176 // Recording a video stream
177 //
178
179public:
180
181 // Records a single frame
182 void vsyncHandler();
183
184private:
185
186 void prepare();
187 void recordVideo();
188 void recordAudio();
189 void finalize();
190 void abort();
191};
192
193}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16
@ REC_STATE_WAIT
The recorder is ready.
Definition RecorderTypes.h:26
@ OPT_REC_ASPECT_X
Numerator of the video's aspect ratio.
Definition OptionTypes.h:173
@ OPT_REC_BIT_RATE
Bit rate of the recorded video.
Definition OptionTypes.h:171
@ OPT_REC_SAMPLE_RATE
Audio sample rate of the recorded video.
Definition OptionTypes.h:172
@ OPT_REC_ASPECT_Y
Denumerator of the video's aspect ratio.
Definition OptionTypes.h:174
@ OPT_REC_FRAME_RATE
Frame rate of the recorded video.
Definition OptionTypes.h:170