8#include "../../_cexports/c_driver.h"
10#include "../../global.hpp"
11#include "../../exception.hpp"
13#include "../driver.hpp"
14#include "../stream_base.hpp"
16#include "../../utilities/system_info.hpp"
32 class Stream :
public StreamBase
37 return acquisitionEngine_->AcquisitionInterface();
47 if (acquisitionEngine_ && acquisitionInterface == acquisitionEngine_->AcquisitionInterface())
50 switch (acquisitionInterface)
53 acquisitionEngine_ = std::make_unique<Grab2>(*
Parent());
57 acquisitionEngine_ = std::make_unique<Grab>(*
Parent());
68 acquisitionEngine_->Start();
73 if (!acquisitionEngine_->TryStop())
79 return acquisitionEngine_->TryStop();
84 if (!acquisitionEngine_->TryAbort())
90 return acquisitionEngine_->TryAbort();
104 return acquisitionEngine_->IsRunning();
120 return statistics_->Query(query);
152 template <
class T,
class Rep,
class Period>
156 auto baseImage =
WaitFor(timeSpan, waitStatus);
174 template <
class Rep,
class Period>
183 template <
class T,
class Rep,
class Period>
196 waitResult.
Image = image;
206 template <
class Rep,
class Period>
222 auto baseImage =
Wait(waitStatus);
269 waitResult.
Image = image;
299 template <
class T,
class Rep,
class Period>
320 template <
class Rep,
class Period>
329 template <
class T,
class Rep,
class Period>
341 waitResult.
Image = image;
351 template <
class Rep,
class Period>
405 class AcquisitionEngine
410 explicit AcquisitionEngine(
const Device &device)
412 , lastTimeout_(static_cast<uint32_t>(
Utilities::SystemInfo::DefaultTimeout().count()))
416 AcquisitionEngine(
const AcquisitionEngine &other) =
delete;
417 AcquisitionEngine &operator=(
const AcquisitionEngine &other) =
delete;
418 AcquisitionEngine(AcquisitionEngine &&other) =
delete;
419 AcquisitionEngine &operator=(AcquisitionEngine &&other) =
delete;
421 virtual ~AcquisitionEngine() =
default;
423 template <
class Rep,
class Period>
432 auto result = TryWaitFor(
static_cast<uint32_t
>(msTimeSpan));
452 template <
class Rep,
class Period>
453 void GetTimedSnapshot(
const std::chrono::duration<Rep, Period> &timeSpan,
WaitStatus &waitResult)
460 throw std::overflow_error(
"wait timeout must fit to unsigned 32 bit integer in ms");
461 auto result = TryGetTimedSnapshot(
static_cast<uint32_t
>(msTimeSpan));
475 std::rethrow_exception(CvbException::FromCvbResult(result,
"WaitFor failed"));
481 void SetTimeout(uint32_t msTimeSpan);
483 virtual void Start() = 0;
485 virtual bool TryStop() noexcept = 0;
487 virtual
bool TryAbort() noexcept = 0;
489 virtual
bool IsRunning() const noexcept = 0;
491 virtual Cvb::Driver::AcquisitionInterface AcquisitionInterface() const noexcept = 0;
493 virtual
int TryWaitFor(uint32_t msTineSpan) = 0;
495 virtual
int TryGetTimedSnapshot(uint32_t msTineSpan) = 0;
498 void *Handle() const noexcept;
501 const Device &device_;
503 uint32_t lastTimeout_;
506 class Grab : public AcquisitionEngine
509 explicit Grab(
const Device &device);
511 void Start()
override
514 std::rethrow_exception(CvbException::FromCvbResult(
ErrorCodes::CVB_BUSY,
"acquisition already running"));
518 bool TryStop() noexcept
override
524 bool TryAbort() noexcept
override
529 bool IsRunning() const noexcept
override
539 int TryWaitFor(uint32_t msTineSpan)
override;
541 int TryGetTimedSnapshot(uint32_t msTineSpan)
override;
547 class Grab2 :
public AcquisitionEngine
550 explicit Grab2(
const Device &device);
552 void Start()
override;
554 bool TryStop() noexcept override;
556 bool TryAbort() noexcept override;
558 bool IsRunning() const noexcept override;
560 Cvb::Driver::AcquisitionInterface AcquisitionInterface() const noexcept
override
565 int TryWaitFor(uint32_t msTineSpan)
override;
567 int TryGetTimedSnapshot(uint32_t msTineSpan)
override;
573 static std::unique_ptr<StreamStats> CreateGrab2(
const Device &device)
575 return std::make_unique<Grab2Stats>(device);
578 static std::unique_ptr<StreamStats> CreateNo(
const Device &device)
580 return std::make_unique<NoStats>(device);
583 explicit StreamStats(
const Device &device)
588 StreamStats(
const StreamStats &other) =
delete;
589 StreamStats &operator=(
const StreamStats &other) =
delete;
590 StreamStats(StreamStats &&other) =
delete;
591 StreamStats &operator=(StreamStats &&other) =
delete;
592 virtual ~StreamStats() =
default;
594 double Query(StreamInfo query)
const
597 if (!TryGetValue(query, value))
598 throw std::runtime_error(
"statistics query not supported");
603 virtual bool TryGetValue(StreamInfo query,
double &value)
const noexcept = 0;
605 void *Handle() const noexcept;
608 const Device &device_;
611 class Grab2Stats : public StreamStats
614 explicit Grab2Stats(
const Device &device)
615 : StreamStats(device)
620 bool TryGetValue(StreamInfo query,
double &value)
const noexcept override;
623 class NoStats :
public StreamStats
626 explicit NoStats(
const Device &device)
627 : StreamStats(device)
632 bool TryGetValue(StreamInfo,
double &)
const noexcept override
638 std::unique_ptr<AcquisitionEngine> acquisitionEngine_;
640 std::unique_ptr<StreamStats> statistics_;
32 class Stream :
public StreamBase {
…};
Generic CVB physical device.
Definition decl_device.hpp:39
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
void Abort() override
Stops the acquisition of images immediately.
Definition decl_stream.hpp:82
double Statistics(StreamInfo query) const
Gets statistics value if supported.
Definition decl_stream.hpp:118
StreamImagePtr GetSnapshot(WaitStatus &waitStatus)
Acquires a single image and returns it.
Definition decl_stream.hpp:363
WaitResult< T > Wait()
Waits for ever for the next acquired image and returns it.
Definition decl_stream.hpp:258
void Start() override
Starts the acquisition.
Definition decl_stream.hpp:66
Cvb::Driver::AcquisitionInterface AcquisitionInterface() const noexcept override
Gets the interface of this implementation.
Definition decl_stream.hpp:35
bool IsRunning() const noexcept
Gets whether the acquisition is currently active.
Definition decl_stream.hpp:102
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
T Statistics(StreamInfo query) const
Gets statistics value if supported.
Definition decl_stream.hpp:130
WaitResult< StreamImage > Wait()
Waits for ever for the next acquired image and returns it.
Definition decl_stream.hpp:278
void Stop() override
Stops the acquisition.
Definition decl_stream.hpp:71
bool IsIndexed() const noexcept override
Gets whether this stream is an indexed stream.
Definition decl_stream.hpp:107
bool TryAbort() noexcept override
Stops the acquisition of images immediately.
Definition decl_stream.hpp:88
WaitResult< StreamImage > WaitFor(const std::chrono::duration< Rep, Period > &timeSpan)
Waits for the given time span for the next acquired image.
Definition decl_stream.hpp:207
WaitResult< StreamImage > GetSnapshot()
Acquires a single image and returns it.
Definition decl_stream.hpp:383
std::shared_ptr< T > Wait(WaitStatus &waitStatus)
Waits forever for the next acquired image and returns it.
Definition decl_stream.hpp:219
WaitResult< T > WaitFor(const std::chrono::duration< Rep, Period > &timeSpan)
Waits for the given time span for the next acquired image.
Definition decl_stream.hpp:184
void SetAcquisitionInterface(Cvb::Driver::AcquisitionInterface acquisitionInterface)
Sets the interface of this implementation.
Definition decl_stream.hpp:45
virtual RingBufferPtr RingBuffer() const noexcept
Gets the ring buffer interface object if present.
Definition decl_stream.hpp:140
WaitResult< StreamImage > GetTimedSnapshot(const std::chrono::duration< Rep, Period > &timeSpan)
Acquires a single image for a given time span and returns it.
Definition decl_stream.hpp:352
bool TryStop() noexcept override
Stops the acquisition.
Definition decl_stream.hpp:77
StreamImagePtr Wait(WaitStatus &waitStatus)
Waits for ever for the next acquired image and returns it.
Definition decl_stream.hpp:238
WaitResult< T > GetTimedSnapshot(const std::chrono::duration< Rep, Period > &timeSpan)
Acquires a single image for a given time span and returns it.
Definition decl_stream.hpp:330
T duration_cast(T... args)
Namespace for driver or device related operations.
Definition decl_composite.hpp:27
@ Stream
Definition driver.hpp:432
std::shared_ptr< StreamImage > StreamImagePtr
Convenience shared pointer for StreamImage.
Definition driver.hpp:84
StreamInfo
Queryable stream information.
Definition driver.hpp:453
std::shared_ptr< RingBuffer > RingBufferPtr
Convenience shared pointer for RingBuffer.
Definition driver.hpp:36
AcquisitionInterface
Known acquisition CVB interfaces.
Definition driver.hpp:437
@ Grab2
Ring buffer / queue based acquisition.
Definition driver.hpp:441
@ Grabber
Basic grabber interface for single image acquisition.
Definition driver.hpp:439
const int CVB_BUSY
Hardware busy.
Definition exception.hpp:57
const int CVB_GRABABORTED
Failure because grab was aborted.
Definition exception.hpp:61
const int CVB_TIMEOUT
Timeout in function.
Definition exception.hpp:29
Namespace for helpers and utilities, which are not directly related to image processing.
Definition version.hpp:16
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
@ Abort
The acquisition has been stopped asynchronously, there is no image buffer.
Definition global.hpp:402
@ Ok
Everything is fine, a new image arrived.
Definition global.hpp:398
@ Timeout
A timeout occurred, no image buffer has been returned.
Definition global.hpp:400
std::shared_ptr< Device > DevicePtr
Convenience shared pointer for Device.
Definition global.hpp:98
T dynamic_pointer_cast(T... args)
T rethrow_exception(T... args)
A combined result returned after waiting for a image.
Definition driver.hpp:393
WaitStatus Status
The status.
Definition driver.hpp:395
std::shared_ptr< T > Image
The returned image by wait if applicable cast to the provided type.
Definition driver.hpp:397