3#include "../../global.hpp"
5#include "../../_decl/decl_device.hpp"
7#include "../_decl/decl_stream.hpp"
9#include "../_decl/decl_buffer_image.hpp"
10#include "../_decl/decl_ring_buffer.hpp"
11#include "../_decl/decl_ring_buffer_image.hpp"
21 inline Stream::Stream(
const DevicePtr &device)
24 SetAcquisitionInterface(AcquisitionEngine::GetBestAcquisitionInterface(*device));
26 if (CExports::CanGrab2(Parent()->Handle()))
27 StreamStats::CreateGrab2(*Parent()).swap(statistics_);
29 StreamStats::CreateNo(*Parent()).swap(statistics_);
32 template <
class Rep,
class Period>
35 acquisitionEngine_->WaitFor(timeSpan, waitStatus);
39 auto image = MakeStreamImage();
40 Parent()->OnImageAcquired();
44 template <
class Rep,
class Period>
48 acquisitionEngine_->GetTimedSnapshot(timeSpan, waitStatus);
52 auto image = MakeSnapshotImage();
53 Parent()->OnImageAcquired();
58 Stream::AcquisitionEngine::GetBestAcquisitionInterface(
const Device &device)
60 if (CExports::CanGrab2(device.
Handle()))
62 else if (CExports::CanGrabber(device.
Handle()))
68 inline void Stream::AcquisitionEngine::SetTimeout(uint32_t msTimeSpan)
70 if (lastTimeout_ == msTimeSpan)
73 auto result = CExports::SetTimeout(device_.Handle(), msTimeSpan);
75 CvbException::FromCvbResult(result,
"failed to set timeout");
76 lastTimeout_ = msTimeSpan;
79 inline void *Stream::AcquisitionEngine::Handle() const noexcept
81 return device_.Handle();
84 inline Stream::Grab::Grab(
const Device &device)
85 : AcquisitionEngine(device)
88 if (!CExports::CanGrabber(device.Handle()))
89 throw std::runtime_error(
"no IGrabber");
92 inline int Stream::Grab::TryWaitFor(uint32_t msTineSpan)
94 SetTimeout(msTineSpan);
95 return CExports::Snap(Handle());
98 inline int Stream::Grab::TryGetTimedSnapshot(uint32_t msTineSpan)
100 SetTimeout(msTineSpan);
101 return CExports::Snap(Handle());
104 inline Stream::Grab2::Grab2(
const Device &device)
105 : AcquisitionEngine(device)
107 if (!CExports::CanGrab2(device.Handle()))
108 throw std::runtime_error(
"no IGrab2");
111 inline void Stream::Grab2::Start()
113 auto result = CExports::G2Grab(Handle());
115 std::rethrow_exception(CvbException::FromCvbResult(result,
"failed to start acquisition with G2Grab"));
118 inline bool Stream::Grab2::TryStop() noexcept
120 auto result = CExports::G2Freeze(Handle(),
false);
121 return (result >= 0);
124 inline bool Stream::Grab2::TryAbort() noexcept
126 auto result = CExports::G2Freeze(Handle(),
true);
127 return (result >= 0);
130 inline bool Stream::Grab2::IsRunning() const noexcept
133 CExports::G2GetGrabStatus(Handle(), CExports::GRAB_INFO_GRAB_ACTIVE, active);
134 return active != 0.0;
137 inline int Stream::Grab2::TryWaitFor(uint32_t msTineSpan)
139 SetTimeout(msTineSpan);
140 return CExports::G2Wait(Handle());
143 inline int Stream::Grab2::TryGetTimedSnapshot(uint32_t msTineSpan)
145 SetTimeout(msTineSpan);
146 return CExports::Snap(Handle());
149 inline bool Stream::Grab2Stats::TryGetValue(
StreamInfo query,
double &value)
const noexcept
151 auto result = CExports::G2GetGrabStatus(Handle(),
static_cast<CExports::GRAB_INFO_CMD
>(query), value);
155 inline void *Stream::StreamStats::Handle() const noexcept
157 return device_.Handle();
Generic CVB physical device.
Definition decl_device.hpp:78
void * Handle() const noexcept
Classic API device handle.
Definition decl_device.hpp:122
Base class of all streams.
Definition stream_base.hpp:19
DevicePtr Parent() const noexcept
Gets the parent device of this stream.
Definition stream_base.hpp:42
std::shared_ptr< T > WaitFor(const std::chrono::duration< Rep, Period > &timeSpan, WaitStatus &waitStatus)
Waits for the given time span for the next acquired image.
Definition decl_stream.hpp:153
std::shared_ptr< T > GetTimedSnapshot(const std::chrono::duration< Rep, Period > &timeSpan, WaitStatus &waitStatus)
Acquires a single image for a given time span and returns it.
Definition decl_stream.hpp:300
Namespace for driver or device related operations.
Definition decl_composite.hpp:28
std::shared_ptr< StreamImage > StreamImagePtr
Convenience shared pointer for StreamImage.
Definition driver.hpp:93
StreamInfo
Queryable stream information.
Definition driver.hpp:451
AcquisitionInterface
Known acquisition CVB interfaces.
Definition driver.hpp:435
@ Grab2
Ring buffer / queue based acquisition.
Definition driver.hpp:439
@ Grabber
Basic grabber interface for single image acquisition.
Definition driver.hpp:437
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
WaitStatus
Status after waiting for an image to be returned.
Definition global.hpp:396
@ Ok
Everything is fine, a new image arrived.
Definition global.hpp:398
std::shared_ptr< Device > DevicePtr
Convenience shared pointer for Device.
Definition global.hpp:98