6#include "../stream_base.hpp"
7#include "../driver.hpp"
8#include "../../exception.hpp"
9#include "../../cancellation_token.hpp"
10#include "../../genapi/node_map_enumerator.hpp"
11#include "../flow_set_pool.hpp"
12#include "../gendc_descriptor.hpp"
20 inline HandleGuard<CompositeStreamBase>::HandleGuard(
void *handle) noexcept
21 : HandleGuard<CompositeStreamBase>(handle, [](
void *handle) { CVB_CALL_CAPI(
ReleaseObject(handle)); })
30 class CompositeStreamBase :
public StreamBase
33 using GuardType = HandleGuard<CompositeStreamBase>;
35 template <
class T,
class... ARGS>
36 static std::shared_ptr<T> FromHandle(HandleGuard<CompositeStreamBase> &&guard, ARGS &&...args);
47 return handle_.Handle();
71 Internal::DoResCall([
this, bufferCountToAcquire]() {
72 return CExports::CVDStreamAcquisitionEngineStart(
Handle(), bufferCountToAcquire);
74 acquisitionState_ = Cvb::AcquisitionState::Started;
86 template <
class Rep,
class Period>
111 template <
class Rep,
class Period>
139 if (acquisitionState_ == Cvb::AcquisitionState::Started)
140 acquisitionState_ = Cvb::AcquisitionState::Stopping;
143 acquisitionState_ = Cvb::AcquisitionState::Stopped;
161 if (acquisitionState_ == Cvb::AcquisitionState::Started)
162 acquisitionState_ = Cvb::AcquisitionState::Stopping;
163 else if (acquisitionState_ == Cvb::AcquisitionState::Stopping)
164 acquisitionState_ = Cvb::AcquisitionState::AbortingStop;
165 Internal::DoResCall([
this]() {
return CExports::CVDStreamAcquisitionEngineAbort(
Handle()); });
166 acquisitionState_ = Cvb::AcquisitionState::Stopped;
178 if (acquisitionState_ == Cvb::AcquisitionState::Started)
179 acquisitionState_ = Cvb::AcquisitionState::Stopping;
180 else if (acquisitionState_ == Cvb::AcquisitionState::Stopping)
181 acquisitionState_ = Cvb::AcquisitionState::AbortingStop;
184 acquisitionState_ = Cvb::AcquisitionState::Stopped;
208 [
this, bufferCountToAcquire]() {
return CExports::CVDStreamControlStart(
Handle(), bufferCountToAcquire); });
220 Internal::DoResCall([
this]() {
return CExports::CVDStreamControlStop(
Handle()); });
244 Internal::DoResCall([
this]() {
return CExports::CVDStreamControlAbort(
Handle()); });
268 CVB_CALL_CAPI_CHECKED(CVDStreamUnregisterFlowSetPool(
Handle()));
282 CVB_CALL_CAPI_CHECKED(CVDStreamRegisterManagedFlowSetPool(
Handle(),
static_cast<std::size_t>(flowSetCount)));
301 flowSetPoolPtr->SetUserCallback(releaseCallback);
302 CVB_CALL_CAPI_CHECKED(CVDStreamRegisterExternalFlowSetPool(
303 Handle(),
reinterpret_cast<CExports::CVDFlowSet *
>(flowSetPoolPtr->ToNativeStruct().data()),
304 flowSetPoolPtr->PoolSize(), flowSetPoolPtr->OnReleaseCallback, &*flowSetPoolPtr));
305 flowSetPoolPtr->SetReleaseThis(flowSetPoolPtr);
317 CVB_CALL_CAPI(CVDStreamGetFlowSetCount(
Handle(), count));
318 return static_cast<int>(count);
331 CVB_CALL_CAPI(CVDStreamFlowSetInfoGetFlowSetMinCount(
Handle(), count));
332 return static_cast<int>(count);
344 combinedStreaming_ =
true;
351 combinedStreaming_ =
false;
358 combinedStreaming_ =
false;
359 return deviceResult && engineResult;
366 combinedStreaming_ =
false;
373 combinedStreaming_ =
false;
374 return deviceResult && engineResult;
389 return acquisitionState_;
399 if (!CExports::CVDCanGenDCDescriptorProvider(
Handle()))
402 return Internal::DoResCallObjectOut<Driver::GenDcDescriptor>([
this](CExports::CVDGNDCDESCRIPTOR &handle) {
403 return CVB_CALL_CAPI(CVDGNDCPGetDescriptor(
Handle(), handle));
414 if (!CExports::CVDCanFlowSetInfo(
Handle()))
419 CVB_CALL_CAPI_CHECKED(CVDStreamFlowSetInfoGetFlowCount(
Handle(), flowCount));
424 CVB_CALL_CAPI_CHECKED(CVDStreamFlowSetInfoGetFlowSize(
Handle(), i, flowInfos[i].Size));
425 CVB_CALL_CAPI_CHECKED(CVDStreamFlowSetInfoGetFlowAlignment(
Handle(), i, flowInfos[i].Alignment));
461 if (combinedStreaming_)
464 CExports::CVDStreamControlAbort(
Handle());
465 CExports::CVDStreamAcquisitionEngineAbort(
Handle());
475 , handle_(std::move(guard))
477 , combinedStreaming_(false)
479 if (CExports::CanNodeMapHandle2(
Handle()))
480 TryFillNodeMapKeys2();
483 template <
class T,
class Rep,
class Period>
484 WaitResultBase<T> InternalWaitFor(
const std::chrono::duration<Rep, Period> &timeSpan)
489 template <
class T,
class Rep,
class Period>
490 WaitResultBase<T> InternalWaitFor(
const std::chrono::duration<Rep, Period> &timeSpan,
491 const CancellationToken &token)
498 WaitResultBase<T> InternalWait()
500 return InternalWaitFor<T>(-1);
504 WaitResultBase<T> InternalWait(
const CancellationToken &token)
506 return InternalWaitFor<T>(-1, token.Handle());
511 WaitResultBase<T> InternalWaitFor(std::int64_t timeout, CExports::CVCANCELLATIONTOKEN token =
nullptr)
513 CExports::CVDWaitStatus waitStatus = CExports::CVDWaitStatus::CVDWS_Ok;
514 CExports::CVCOMPOSITE handle =
nullptr;
515 CVB_CALL_CAPI_CHECKED(
516 CVDStreamAcquisitionEngineWaitForNextComposite(
Handle(), timeout, token, waitStatus, handle));
517 return std::make_tuple(HandleGuard<T>(handle),
static_cast<WaitStatus>(waitStatus));
520 virtual void InternalEngineStop(
const std::chrono::milliseconds &timeout)
522 if (acquisitionState_ == Cvb::AcquisitionState::Started)
523 acquisitionState_ = Cvb::AcquisitionState::Stopping;
525 [
this, timeout]() {
return CExports::CVDStreamAcquisitionEngineStop(
Handle(), timeout.count()); });
526 acquisitionState_ = Cvb::AcquisitionState::Stopped;
529 bool TryFillNodeMapKeys2()
531 size_t numNodeMaps = 0;
532 auto resultNum = CExports::NMH2GetNum(
Handle(), numNodeMaps);
535 for (
size_t i = 0; i < numNodeMaps; ++i)
537 size_t bufferSize = 0;
538 auto resultBufferLength = CExports::NMH2GetID(
Handle(), i,
nullptr, bufferSize);
539 if (resultBufferLength < 0)
541 std::vector<char> buffer(bufferSize);
542 auto resultBuffer = CExports::NMH2GetID(
Handle(), i, &buffer[0], bufferSize);
543 if (resultBuffer < 0)
545 String keyString(buffer.begin(), buffer.end() - 1);
546 nodeMaps_[keyString].Reset();
551 HandleGuard<CompositeStreamBase> handle_;
552 std::atomic<Cvb::AcquisitionState> acquisitionState_;
553 mutable std::map<String, Internal::AsyncRef<GenApi::NodeMap>> nodeMaps_;
554 bool combinedStreaming_;
30 class CompositeStreamBase :
public StreamBase {
…};
Base class of all composite based streams.
Definition decl_composite_stream_base.hpp:31
Base class of all composite based streams.
Definition decl_composite_stream_base.hpp:31
void Abort() override
Stops the acquisition of images immediately.
Definition decl_composite_stream_base.hpp:362
void Start() override
Starts the acquisition.
Definition decl_composite_stream_base.hpp:340
virtual void EngineStart(std::int64_t bufferCountToAcquire)
Starts the acquisition engine on the host.
Definition decl_composite_stream_base.hpp:69
Cvb::Driver::AcquisitionInterface AcquisitionInterface() const noexcept override
Gets the interface of this implementation.
Definition decl_composite_stream_base.hpp:335
virtual bool TryEngineAbort() noexcept
Stops the acquisition engine immediately.
Definition decl_composite_stream_base.hpp:176
void DeregisterFlowSetPool()
Removes an existing flow set pool from the acquisition engine.
Definition decl_composite_stream_base.hpp:266
virtual bool TryEngineStop() noexcept
Stops the acquisition engine.
Definition decl_composite_stream_base.hpp:124
void RegisterManagedFlowSetPool(int flowSetCount)
Registers an internal flows set pool.
Definition decl_composite_stream_base.hpp:280
virtual bool TryDeviceStop() noexcept
Stops the stream in the device.
Definition decl_composite_stream_base.hpp:230
void Stop() override
Stops the acquisition.
Definition decl_composite_stream_base.hpp:347
virtual void DeviceStart(std::int64_t bufferCountToAcquire)
Starts the stream on the device.
Definition decl_composite_stream_base.hpp:205
virtual void DeviceStop()
Stops the stream in the device.
Definition decl_composite_stream_base.hpp:218
void EngineStop(const std::chrono::duration< Rep, Period > &timeout)
Stops the acquisition engine.
Definition decl_composite_stream_base.hpp:87
bool IsIndexed() const noexcept override
Gets whether this stream is an indexed stream.
Definition decl_composite_stream_base.hpp:377
Cvb::AcquisitionState AcquisitionState() const noexcept
Gets the current acquisition state.
Definition decl_composite_stream_base.hpp:387
int MinRequiredFlowSetCount() const
Gets minimum number of flow sets required for the acquisition.
Definition decl_composite_stream_base.hpp:328
bool TryAbort() noexcept override
Stops the acquisition of images immediately.
Definition decl_composite_stream_base.hpp:369
virtual void EngineStop()
Stops the acquisition engine.
Definition decl_composite_stream_base.hpp:98
NodeMapPtr NodeMap(const String &name) const
Gets the NodeMap with the given name.
Definition detail_composite_stream_base.hpp:24
virtual void DeviceAbort()
Stops the stream in the device immediately.
Definition decl_composite_stream_base.hpp:242
virtual void DeviceStart()
Starts the stream on the device.
Definition decl_composite_stream_base.hpp:193
void RegisterExternalFlowSetPool(FlowSetPoolPtr flowSetPoolPtr)
Registers external memory.
Definition decl_composite_stream_base.hpp:289
bool TryEngineStop(const std::chrono::duration< Rep, Period > &timeout) noexcept
Stops the acquisition engine.
Definition decl_composite_stream_base.hpp:112
virtual void EngineStart()
Starts the acquisition engine on the host.
Definition decl_composite_stream_base.hpp:56
int FlowSetCount() const noexcept
Gets the number of registered flow sets.
Definition decl_composite_stream_base.hpp:314
virtual void EngineAbort()
Stops the acquisition engine immediately.
Definition decl_composite_stream_base.hpp:159
std::unique_ptr< Driver::GenDcDescriptor > GenDCPrefetchDescriptor() const
If this Stream represents a GenDC stream, returns the GenDC prefetch descriptor.
Definition decl_composite_stream_base.hpp:397
virtual bool TryDeviceAbort() noexcept
Stops the stream in the device immediately.
Definition decl_composite_stream_base.hpp:254
std::vector< FlowInfo > FlowSetInfo() const
Gets the flow set info of this stream.
Definition decl_composite_stream_base.hpp:412
void * Handle() const noexcept
Classic API stream handle.
Definition decl_composite_stream_base.hpp:45
bool TryStop() noexcept override
Stops the acquisition.
Definition decl_composite_stream_base.hpp:354
void RegisterExternalFlowSetPool(FlowSetPoolPtr flowSetPoolPtr, std::function< void()> releaseCallback)
Registers external memory.
Definition decl_composite_stream_base.hpp:299
virtual bool TryEngineStop(const std::chrono::milliseconds &timeout) noexcept
Stops the acquisition engine.
Definition decl_composite_stream_base.hpp:137
std::map< String, NodeMapPtr > NodeMaps() const
Gets the dictionary holding all available stream NodeMaps.
Definition detail_composite_stream_base.hpp:40
T duration_cast(T... args)
cvbbool_t ReleaseObject(OBJ &Object)
Namespace for driver or device related operations.
Definition decl_composite.hpp:28
std::shared_ptr< FlowSetPool > FlowSetPoolPtr
Convenience shared pointer for FlowSetPool.
Definition driver.hpp:33
@ String
String value.
Definition driver.hpp:366
AcquisitionState
Specifies current state of the acquisition engine.
Definition driver.hpp:542
@ Stopped
The engine is stopped.
Definition driver.hpp:550
AcquisitionInterface
Known acquisition CVB interfaces.
Definition driver.hpp:435
@ GenTL
Flow set pool / queue based acquition for TL based techologies.
Definition driver.hpp:441
const int CVB_OK
No error occurred.
Definition exception.hpp:21
std::shared_ptr< NodeMap > NodeMapPtr
Convenience shared pointer for NodeMap.
Definition genapi.hpp:27
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
std::shared_ptr< Device > DevicePtr
Convenience shared pointer for Device.
Definition global.hpp:98