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 
9 
10 namespace Cvb
11 {
12 
13 CVB_BEGIN_INLINE_NS
14 
15 namespace Movie2
16 {
17 
19 
22 {
23  friend class RecordingEngine;
24 
25  protected:
26 
27 
28  RecordingSettings() noexcept = default;
29 
30 
31  public:
32 
33  virtual ~RecordingSettings() = default;
34 
36 
43  double FrameRate() const noexcept
44  {
45  return frameRate_;
46  }
47 
49 
56  void SetFrameRate(double frameRate)
57  {
58  if (frameRate < 0)
59  throw std::invalid_argument("frame rate must be grater than zero");
60 
61  frameRate_ = frameRate;
62  }
63 
65 
70  {
71  return engineType_;
72  }
73 
74  protected:
76  : engineType_(type)
77  {}
78 
79  int codecIndex_ = 0;
80  bool useMetaData_ = false;
81 
82  private:
83 
84  double frameRate_ = 25.0;
86 
87 
88 };
89 
91 
94 {
95 
96 friend class DirectShowEngine;
97 
98 public:
99 
100  DirectShowSettings() noexcept
102  {}
103 
104  ~DirectShowSettings() = default;
105 
107 
112  {
113  auto handle = CreateMovie2();
114 
115  CExports::cvbval_t numComperessors = 0;
116  auto resultNumCompressors = CExports::Movie2GetNumCompressors(handle.get(), numComperessors);
117  if (resultNumCompressors < 0)
118  std::rethrow_exception(CvbException::FromCvbResult(resultNumCompressors, "failed to get the number of compressors"));
119 
120 
121  std::vector<String> codecs(static_cast<std::size_t>(numComperessors));
122  for (CExports::cvbres_t i = 0; i < numComperessors; ++i)
123  {
124  std::vector<Char> buffer(1024);
125  auto resultCompressorName = CExports::Movie2GetCompressorNameTyped(handle.get(), i, &buffer[0], static_cast<CExports::cvbres_t>(buffer.size()));
126  if (resultCompressorName < 0)
127  std::rethrow_exception(CvbException::FromCvbResult(resultCompressorName, "failed to get compressor name"));
128 
129  codecs[static_cast<size_t>(i)] = String(&buffer[0]);
130  }
131  return codecs;
132  }
133 
135 
139  String Codec() const
140  {
141  auto handle = CreateMovie2();
142 
143  std::vector<Char> buffer(1024);
144  auto resultCompressorName = CExports::Movie2GetCompressorNameTyped(handle.get(),
145  static_cast<CExports::cvbval_t>(codecIndex_),
146  &buffer[0],
147  static_cast<CExports::cvbres_t>(buffer.size()));
148  if (resultCompressorName < 0)
149  std::rethrow_exception(CvbException::FromCvbResult(resultCompressorName, "failed to get compressor name"));
150 
151  return String(&buffer[0]);
152  }
153 
155 
159  void SetCodec(const String& name)
160  {
161  auto codecs = AvailableCodecs();
162  auto codecIndex = std::find(codecs.begin(), codecs.end(), name) - codecs.begin();
163  if (codecIndex >= static_cast<std::ptrdiff_t>(codecs.size()))
164  throw std::invalid_argument("requested codec not available");
165 
166  codecIndex_ = static_cast<int>(codecIndex);
167  }
168 
170 
176  bool UseMetaData() const noexcept
177  {
178  return useMetaData_;
179  }
180 
182 
188  void SetUseMetaData(bool useMetaData) noexcept
189  {
190  useMetaData_ = useMetaData;
191  }
192 
193 //protected: // TODO
194 
195  int CodecIndex() const noexcept
196  {
197  return codecIndex_;
198  }
199 
200 private:
201 
202  static std::unique_ptr<void, void(*)(void *)> CreateMovie2()
203  {
204  std::unique_ptr<void, void(*)(void *)> handle(CExports::CreateMovie2Recorder(CExports::Movie2_EngineDirectShow),
205  [](void * handle) { CVB_CALL_CAPI(ReleaseObject(handle)); });
206 
207  if (!handle)
208  throw std::runtime_error("failed to create movie recorder");
209 
210  return handle;
211  }
212 
213 
214 
215 };
216 
218 
221 {
222 
223 friend class RawVideoEngine;
224 
225 public:
226 
228 
231  RawVideoSettings() noexcept
233  {}
234 
235  ~RawVideoSettings() = default;
236 
237 };
238 
239 }
240 
241 CVB_END_INLINE_NS
242 
243 }
void SetUseMetaData(bool useMetaData) noexcept
Sets whether text metadata is to be written into the stream.
Definition: recording_settings.hpp:188
void SetCodec(const String &name)
Sets the name of the codec to use.
Definition: recording_settings.hpp:159
Settings for initializing a direct show engine recorder.
Definition: recording_settings.hpp:93
RecordingEngineType
Defines the recording engine that the recorder should use.
Definition: movie2.hpp:42
double FrameRate() const noexcept
Gets the frame rate the video uses for playback.
Definition: recording_settings.hpp:43
STL class.
Root namespace for the Image Manager interface.
Definition: version.hpp:11
Settings for initializing a raw video engine recorder.
Definition: recording_settings.hpp:220
std::vector< String > AvailableCodecs()
Gets the available codecs currently installed in the system.
Definition: recording_settings.hpp:111
void SetFrameRate(double frameRate)
Sets the frame rate the video uses for playback.
Definition: recording_settings.hpp:56
RawVideoSettings() noexcept
Created default settings.
Definition: recording_settings.hpp:231
Settings for initializing a recorder.
Definition: recording_settings.hpp:21
bool UseMetaData() const noexcept
Gets whether text metadata is to be written into the stream.
Definition: recording_settings.hpp:176
Use DirectShow framework for recording AVI files.
STL class.
STL class.
Place holder for situations where the engine is undefined.
Use RawVideo for recording raw video.
RecordingEngineType EngineType() const noexcept
Returns the engine type.
Definition: recording_settings.hpp:69
String Codec() const
Gets the name of the codec to use.
Definition: recording_settings.hpp:139