5#include "../global.hpp"
6#include "../exception.hpp"
7#include "../string.hpp"
8#include "../size_2d.hpp"
10#include "../image.hpp"
13#include "recording_settings.hpp"
15#include "_detail/detail_recording_engine.hpp"
24inline HandleGuard<Movie2::Recorder>::HandleGuard(
void * handle) noexcept
25 : HandleGuard<Movie2::Recorder>(handle, [](
void* handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
98 return Create(path, size, pixelFormat, Private::RecordingEngine::Create(settings));
123 return handle_.Handle();
134 metaData_ = metaData;
136 auto res = CVB_CALL_CAPI(Movie2SetImage(
Handle(), image.Handle()));
137 if (res != CExports::CVC_E_OK)
138 Utilities::SystemInfo::ThrowLastError();
140 res = CVB_CALL_CAPI(Movie2AddFrame(
Handle()));
141 if (res != CExports::CVC_E_OK)
142 Utilities::SystemInfo::ThrowLastError();
149 CExports::Movie2StopRecording(
Handle());
153 Recorder(HandleGuard<Recorder>&& guard) noexcept
154 : handle_(std::move(guard))
160 Recorder(Recorder && other) noexcept
161 : handle_(std::move(other.handle_))
165 Recorder(
const String & path, Size2D<int> size,
RecorderPixelFormat pixelFormat, Private::RecordingEnginePtr engine)
166 : Recorder(std::
move(*CreateRecorder(size, pixelFormat, engine)))
170 ConfigureEngine(engine);
182 intptr_t dummyBuffer = 0;
187 HandleGuard<Recorder> guard(CExports::CreateMovie2RecorderEx(
static_cast<CExports::Movie2_RecordingEngine
>(engine->Settings().EngineType()), dummyImage->Handle()));
191 return std::make_unique<Recorder>(std::move(guard));
194 void ConfigureEngine(Private::RecordingEnginePtr engine)
199 ConfigureDirectShowEngine();
201 ConfigureRawVideoEngine();
204 void ConfigureDirectShowEngine()
206 auto directShowEngine = std::dynamic_pointer_cast<Private::DirectShowEngine>(engine_);
207 const auto& settings = directShowEngine->Settings();
209 CVB_CALL_CAPI(Movie2SetSyncMode(
Handle(), CExports::Movie2_SyncAfterCopy));
210 CVB_CALL_CAPI(Movie2SetAcqMode(
Handle(), CExports::Movie2_AcqAddFrame));
211 CVB_CALL_CAPI(Movie2SetCompressorIndex(
Handle(),
static_cast<CExports::cvbval_t
>(settings.CodecIndex())));
212 CVB_CALL_CAPI(Movie2SetFrameRate(
Handle(), settings.FrameRate()));
213 CVB_CALL_CAPI(Movie2SetUseMetadata(
Handle(), (settings.UseMetaData()) ? 1 : 0));
215 if (settings.UseMetaData())
217 Internal::DoResCall([&]()
219 CExports::pfMovie2ProvideMetaData metaDataCallback = [](CExports::MOVIE2RECORDER,
char* szMetaData, CExports::cvbval_t BufferSize,
void* pUserData)
221 if (szMetaData && BufferSize > 0)
224 auto metaData = recorder->metaData_;
226 std::string metaDataAscii(Internal::CastToAscii (metaData));
227 size_t charsToCopy = std::min(metaData.size(),
static_cast<std::size_t>(BufferSize) - 1);
228 std::copy_n(metaDataAscii.begin(), charsToCopy, szMetaData);
229 szMetaData[charsToCopy] = 0;
233 CExports::cvbval_t dummy = 0;
234 return CVB_CALL_CAPI(Movie2RegisterMetaDataCallback(
Handle(), metaDataCallback,
this, dummy));
239 void ConfigureRawVideoEngine()
241 const auto& settings = engine_->Settings();
242 CVB_CALL_CAPI(Movie2SetSyncMode(
Handle(), CExports::Movie2_SyncAfterCopy));
243 CVB_CALL_CAPI(Movie2SetAcqMode(
Handle(), CExports::Movie2_AcqAddFrame));
244 Internal::DoResCall([&]()
246 return CVB_CALL_CAPI(Movie2SetFrameRate(
Handle(), settings.FrameRate()));
250 void Record(
const String & path)
252 auto res = CExports::Movie2SetTargetFileNameTyped(
Handle(), path.c_str());
253 if (res != CExports::CVC_E_OK)
254 Utilities::SystemInfo::ThrowLastError();
256 Internal::DoResCall([&]()
258 return CVB_CALL_CAPI(Movie2StartRecording(
Handle()));
263 HandleGuard<Recorder> handle_;
264 Private::RecordingEnginePtr engine_;
static DataType Int8BppUnsigned() noexcept
Represents 8-bit unsigned integer pixels (bytes).
Definition: data_type.hpp:47
The Common Vision Blox image.
Definition: decl_image.hpp:45
Settings for initializing a direct show engine recorder.
Definition: recording_settings.hpp:94
Movie recorder for writing video files to disk.
Definition: recorder.hpp:67
static RecorderPtr FromHandle(HandleGuard< Recorder > &&guard)
Creates a recorder from a classic API handle.
Definition: recorder.hpp:79
static std::unique_ptr< Recorder > Create(const String &path, Size2D< int > size, RecorderPixelFormat pixelFormat)
Creates a recorder object writing video streams with the given pixel format. Uses the DirectShowEngin...
Definition: recorder.hpp:109
static std::unique_ptr< Recorder > Create(const String &path, Size2D< int > size, RecorderPixelFormat pixelFormat, const RecordingSettings &settings)
Creates a recorder object writing video streams with the given pixel format and recording engine.
Definition: recorder.hpp:96
void Write(const Image &image, const String &metaData=String())
Writes the given image into the stream.
Definition: recorder.hpp:132
void * Handle() const noexcept
Classic API classifier handle.
Definition: recorder.hpp:121
Settings for initializing a recorder.
Definition: recording_settings.hpp:22
T Height() const noexcept
Gets the vertical component of the size.
Definition: size_2d.hpp:79
T Width() const noexcept
Gets the horizontal component of the size.
Definition: size_2d.hpp:59
static std::unique_ptr< WrappedImage > FromRgbPixels(void *buffer, int bufferSize, int width, int height, DataType dataType, int pixelStride, int lineStride, int planeStride)
Wraps, without copying, the given RGB pixel buffer in a CvbImage.
Definition: decl_wrapped_image.hpp:80
static std::unique_ptr< WrappedImage > FromGreyPixels(void *buffer, int bufferSize, int width, int height, DataType dataType, int pixelStride, int lineStride)
Wraps, without copying, the given monochrome pixel buffer in an image.
Definition: decl_wrapped_image.hpp:47
std::shared_ptr< Recorder > RecorderPtr
Convenience shared pointer for Recorder.
Definition: movie2.hpp:27
RecorderPixelFormat
Defines whether the recorder object writes color or mono data.
Definition: movie2.hpp:32
@ Mono
Recorder writes single-plane monochrome data.
@ DirectShow
Use DirectShow framework for recording AVI files.
@ RawVideo
Use RawVideo for recording raw video.
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24
std::string String
String for wide characters or unicode characters.
Definition: string.hpp:45