CVB++ 15.0
recording_settings.hpp
1#pragma once
2
3#include "../global.hpp"
4#include "../string.hpp"
5#include "../exception.hpp"
6
7#include "movie2.hpp"
8
9namespace Cvb
10{
11
12 CVB_BEGIN_INLINE_NS
13
14 namespace Movie2
15 {
16
18
20 class RecordingSettings
21 {
22 friend class RecordingEngine;
23
24 protected:
25 RecordingSettings() noexcept = default;
26
27 public:
28 virtual ~RecordingSettings() = default;
29
31
38 double FrameRate() const noexcept
39 {
40 return frameRate_;
41 }
42
44
51 void SetFrameRate(double frameRate)
52 {
53 if (frameRate < 0)
54 throw std::invalid_argument("frame rate must be grater than zero");
55
56 frameRate_ = frameRate;
57 }
58
60
65 {
66 return engineType_;
67 }
68
69 protected:
71 : engineType_(type)
72 {
73 }
74
75 int codecIndex_ = 0;
76 bool useMetaData_ = false;
77
78 private:
79 double frameRate_ = 25.0;
81 };
82
84
86 class DirectShowSettings : public RecordingSettings
87 {
88
89 friend class DirectShowEngine;
90
91 public:
92 DirectShowSettings() noexcept
93 : RecordingSettings(RecordingEngineType::DirectShow)
94 {
95 }
96
97 ~DirectShowSettings() = default;
98
100
105 {
106 auto handle = CreateMovie2();
107
108 CExports::cvbval_t numComperessors = 0;
109 auto resultNumCompressors = CExports::Movie2GetNumCompressors(handle.get(), numComperessors);
110 if (resultNumCompressors < 0)
112 CvbException::FromCvbResult(resultNumCompressors, "failed to get the number of compressors"));
113
114 std::vector<String> codecs(static_cast<std::size_t>(numComperessors));
115 for (CExports::cvbres_t i = 0; i < numComperessors; ++i)
116 {
117 std::vector<Char> buffer(1024);
118 auto resultCompressorName = CExports::Movie2GetCompressorNameTyped(
119 handle.get(), i, &buffer[0], static_cast<CExports::cvbres_t>(buffer.size()));
120 if (resultCompressorName < 0)
121 std::rethrow_exception(CvbException::FromCvbResult(resultCompressorName, "failed to get compressor name"));
122
123 codecs[static_cast<size_t>(i)] = String(&buffer[0]);
124 }
125 return codecs;
126 }
127
129
133 String Codec() const
134 {
135 auto handle = CreateMovie2();
136
137 std::vector<Char> buffer(1024);
138 auto resultCompressorName =
139 CExports::Movie2GetCompressorNameTyped(handle.get(), static_cast<CExports::cvbval_t>(codecIndex_),
140 &buffer[0], static_cast<CExports::cvbres_t>(buffer.size()));
141 if (resultCompressorName < 0)
142 std::rethrow_exception(CvbException::FromCvbResult(resultCompressorName, "failed to get compressor name"));
143
144 return String(&buffer[0]);
145 }
146
148
152 void SetCodec(const String &name)
153 {
154 auto codecs = AvailableCodecs();
155 auto codecIndex = std::find(codecs.begin(), codecs.end(), name) - codecs.begin();
156 if (codecIndex >= static_cast<std::ptrdiff_t>(codecs.size()))
157 throw std::invalid_argument("requested codec not available");
158
159 codecIndex_ = static_cast<int>(codecIndex);
160 }
161
163
169 bool UseMetaData() const noexcept
170 {
171 return useMetaData_;
172 }
173
175
181 void SetUseMetaData(bool useMetaData) noexcept
182 {
183 useMetaData_ = useMetaData;
184 }
185
186 // protected: // TODO
187
188 int CodecIndex() const noexcept
189 {
190 return codecIndex_;
191 }
192
193 private:
194 static std::unique_ptr<void, void (*)(void *)> CreateMovie2()
195 {
196 std::unique_ptr<void, void (*)(void *)> handle(
197 CExports::CreateMovie2Recorder(CExports::Movie2_EngineDirectShow),
198 [](void *handle) { CVB_CALL_CAPI(ReleaseObject(handle)); });
199
200 if (!handle)
201 throw std::runtime_error("failed to create movie recorder");
202
203 return handle;
204 }
205 };
206
208
210 class RawVideoSettings : public RecordingSettings
211 {
212
213 friend class RawVideoEngine;
214
215 public:
217
221 : RecordingSettings(RecordingEngineType::RawVideo)
222 {
223 }
224
225 ~RawVideoSettings() = default;
226 };
227
228 } // namespace Movie2
229
230 CVB_END_INLINE_NS
231
232} // namespace Cvb
std::vector< String > AvailableCodecs()
Gets the available codecs currently installed in the system.
Definition recording_settings.hpp:104
bool UseMetaData() const noexcept
Gets whether text metadata is to be written into the stream.
Definition recording_settings.hpp:169
void SetUseMetaData(bool useMetaData) noexcept
Sets whether text metadata is to be written into the stream.
Definition recording_settings.hpp:181
String Codec() const
Gets the name of the codec to use.
Definition recording_settings.hpp:133
void SetCodec(const String &name)
Sets the name of the codec to use.
Definition recording_settings.hpp:152
Settings for initializing a raw video engine recorder.
Definition recording_settings.hpp:211
RawVideoSettings() noexcept
Created default settings.
Definition recording_settings.hpp:220
Settings for initializing a recorder.
Definition recording_settings.hpp:21
double FrameRate() const noexcept
Gets the frame rate the video uses for playback.
Definition recording_settings.hpp:38
void SetFrameRate(double frameRate)
Sets the frame rate the video uses for playback.
Definition recording_settings.hpp:51
RecordingEngineType EngineType() const noexcept
Returns the engine type.
Definition recording_settings.hpp:64
T find(T... args)
cvbbool_t ReleaseObject(OBJ &Object)
Record movies with classes from this tool.
Definition detail_recording_engine.hpp:15
RecordingEngineType
Defines the recording engine that the recorder should use.
Definition movie2.hpp:32
@ DirectShow
Use DirectShow framework for recording AVI files.
Definition movie2.hpp:36
@ RawVideo
Use RawVideo for recording raw video.
Definition movie2.hpp:38
@ Undefined
Place holder for situations where the engine is undefined.
Definition movie2.hpp:34
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49
T rethrow_exception(T... args)