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"
19 inline HandleGuard<CompositeStreamBase>::HandleGuard(
void *handle) noexcept
20 : HandleGuard<CompositeStreamBase>(handle, [](
void *handle) { CVB_CALL_CAPI(
ReleaseObject(handle)); })
29 class CompositeStreamBase :
public StreamBase
32 using GuardType = HandleGuard<CompositeStreamBase>;
34 template <
class T,
class... ARGS>
35 static std::shared_ptr<T> FromHandle(HandleGuard<CompositeStreamBase> &&guard, ARGS &&...args);
46 return handle_.Handle();
70 Internal::DoResCall([
this, bufferCountToAcquire]() {
71 return CExports::CVDStreamAcquisitionEngineStart(
Handle(), bufferCountToAcquire);
73 acquisitionState_ = Cvb::AcquisitionState::Started;
85 template <
class Rep,
class Period>
110 template <
class Rep,
class Period>
138 if (acquisitionState_ == Cvb::AcquisitionState::Started)
139 acquisitionState_ = Cvb::AcquisitionState::Stopping;
142 acquisitionState_ = Cvb::AcquisitionState::Stopped;
160 if (acquisitionState_ == Cvb::AcquisitionState::Started)
161 acquisitionState_ = Cvb::AcquisitionState::Stopping;
162 else if (acquisitionState_ == Cvb::AcquisitionState::Stopping)
163 acquisitionState_ = Cvb::AcquisitionState::AbortingStop;
164 Internal::DoResCall([
this]() {
return CExports::CVDStreamAcquisitionEngineAbort(
Handle()); });
165 acquisitionState_ = Cvb::AcquisitionState::Stopped;
177 if (acquisitionState_ == Cvb::AcquisitionState::Started)
178 acquisitionState_ = Cvb::AcquisitionState::Stopping;
179 else if (acquisitionState_ == Cvb::AcquisitionState::Stopping)
180 acquisitionState_ = Cvb::AcquisitionState::AbortingStop;
183 acquisitionState_ = Cvb::AcquisitionState::Stopped;
207 [
this, bufferCountToAcquire]() {
return CExports::CVDStreamControlStart(
Handle(), bufferCountToAcquire); });
219 Internal::DoResCall([
this]() {
return CExports::CVDStreamControlStop(
Handle()); });
243 Internal::DoResCall([
this]() {
return CExports::CVDStreamControlAbort(
Handle()); });
267 CVB_CALL_CAPI_CHECKED(CVDStreamUnregisterFlowSetPool(
Handle()));
281 CVB_CALL_CAPI_CHECKED(CVDStreamRegisterManagedFlowSetPool(
Handle(),
static_cast<std::size_t>(flowSetCount)));
300 flowSetPoolPtr->SetUserCallback(releaseCallback);
301 CVB_CALL_CAPI_CHECKED(CVDStreamRegisterExternalFlowSetPool(
302 Handle(),
reinterpret_cast<CExports::CVDFlowSet *
>(flowSetPoolPtr->ToNativeStruct().data()),
303 flowSetPoolPtr->PoolSize(), flowSetPoolPtr->OnReleaseCallback, &*flowSetPoolPtr));
304 flowSetPoolPtr->SetReleaseThis(flowSetPoolPtr);
316 CVB_CALL_CAPI(CVDStreamGetFlowSetCount(
Handle(), count));
317 return static_cast<int>(count);
330 CVB_CALL_CAPI(CVDStreamFlowSetInfoGetFlowSetMinCount(
Handle(), count));
331 return static_cast<int>(count);
343 combinedStreaming_ =
true;
350 combinedStreaming_ =
false;
357 combinedStreaming_ =
false;
358 return deviceResult && engineResult;
365 combinedStreaming_ =
false;
372 combinedStreaming_ =
false;
373 return deviceResult && engineResult;
388 return acquisitionState_;
398 if (!CExports::CVDCanFlowSetInfo(
Handle()))
403 CVB_CALL_CAPI_CHECKED(CVDStreamFlowSetInfoGetFlowCount(
Handle(), flowCount));
408 CVB_CALL_CAPI_CHECKED(CVDStreamFlowSetInfoGetFlowSize(
Handle(), i, flowInfos[i].Size));
409 CVB_CALL_CAPI_CHECKED(CVDStreamFlowSetInfoGetFlowAlignment(
Handle(), i, flowInfos[i].Alignment));
445 if (combinedStreaming_)
448 CExports::CVDStreamControlAbort(
Handle());
449 CExports::CVDStreamAcquisitionEngineAbort(
Handle());
459 , handle_(std::move(guard))
461 , combinedStreaming_(false)
463 if (CExports::CanNodeMapHandle2(
Handle()))
464 TryFillNodeMapKeys2();
467 template <
class T,
class Rep,
class Period>
468 WaitResultBase<T> InternalWaitFor(
const std::chrono::duration<Rep, Period> &timeSpan)
473 template <
class T,
class Rep,
class Period>
474 WaitResultBase<T> InternalWaitFor(
const std::chrono::duration<Rep, Period> &timeSpan,
475 const CancellationToken &token)
482 WaitResultBase<T> InternalWait()
484 return InternalWaitFor<T>(-1);
488 WaitResultBase<T> InternalWait(
const CancellationToken &token)
490 return InternalWaitFor<T>(-1, token.Handle());
495 WaitResultBase<T> InternalWaitFor(std::int64_t timeout, CExports::CVCANCELLATIONTOKEN token =
nullptr)
497 CExports::CVDWaitStatus waitStatus = CExports::CVDWaitStatus::CVDWS_Ok;
498 CExports::CVCOMPOSITE handle =
nullptr;
499 CVB_CALL_CAPI_CHECKED(
500 CVDStreamAcquisitionEngineWaitForNextComposite(
Handle(), timeout, token, waitStatus, handle));
501 return std::make_tuple(HandleGuard<T>(handle),
static_cast<WaitStatus>(waitStatus));
504 virtual void InternalEngineStop(
const std::chrono::milliseconds &timeout)
506 if (acquisitionState_ == Cvb::AcquisitionState::Started)
507 acquisitionState_ = Cvb::AcquisitionState::Stopping;
509 [
this, timeout]() {
return CExports::CVDStreamAcquisitionEngineStop(
Handle(), timeout.count()); });
510 acquisitionState_ = Cvb::AcquisitionState::Stopped;
513 bool TryFillNodeMapKeys2()
515 size_t numNodeMaps = 0;
516 auto resultNum = CExports::NMH2GetNum(
Handle(), numNodeMaps);
519 for (
size_t i = 0; i < numNodeMaps; ++i)
521 size_t bufferSize = 0;
522 auto resultBufferLength = CExports::NMH2GetID(
Handle(), i,
nullptr, bufferSize);
523 if (resultBufferLength < 0)
525 std::vector<char> buffer(bufferSize);
526 auto resultBuffer = CExports::NMH2GetID(
Handle(), i, &buffer[0], bufferSize);
527 if (resultBuffer < 0)
529 String keyString(buffer.begin(), buffer.end() - 1);
530 nodeMaps_[keyString].Reset();
535 HandleGuard<CompositeStreamBase> handle_;
536 std::atomic<Cvb::AcquisitionState> acquisitionState_;
537 mutable std::map<String, Internal::AsyncRef<GenApi::NodeMap>> nodeMaps_;
538 bool combinedStreaming_;
Base class of all composite based streams.
Definition decl_composite_stream_base.hpp:30
Base class of all composite based streams.
Definition decl_composite_stream_base.hpp:30
void Abort() override
Stops the acquisition of images immediately.
Definition decl_composite_stream_base.hpp:361
void Start() override
Starts the acquisition.
Definition decl_composite_stream_base.hpp:339
virtual void EngineStart(std::int64_t bufferCountToAcquire)
Starts the acquisition engine on the host.
Definition decl_composite_stream_base.hpp:68
Cvb::Driver::AcquisitionInterface AcquisitionInterface() const noexcept override
Gets the interface of this implementation.
Definition decl_composite_stream_base.hpp:334
virtual bool TryEngineAbort() noexcept
Stops the acquisition engine immediately.
Definition decl_composite_stream_base.hpp:175
void DeregisterFlowSetPool()
Removes an existing flow set pool from the acquisition engine.
Definition decl_composite_stream_base.hpp:265
virtual bool TryEngineStop() noexcept
Stops the acquisition engine.
Definition decl_composite_stream_base.hpp:123
void RegisterManagedFlowSetPool(int flowSetCount)
Registers an internal flows set pool.
Definition decl_composite_stream_base.hpp:279
virtual bool TryDeviceStop() noexcept
Stops the stream in the device.
Definition decl_composite_stream_base.hpp:229
void Stop() override
Stops the acquisition.
Definition decl_composite_stream_base.hpp:346
virtual void DeviceStart(std::int64_t bufferCountToAcquire)
Starts the stream on the device.
Definition decl_composite_stream_base.hpp:204
virtual void DeviceStop()
Stops the stream in the device.
Definition decl_composite_stream_base.hpp:217
void EngineStop(const std::chrono::duration< Rep, Period > &timeout)
Stops the acquisition engine.
Definition decl_composite_stream_base.hpp:86
bool IsIndexed() const noexcept override
Gets whether this stream is an indexed stream.
Definition decl_composite_stream_base.hpp:376
Cvb::AcquisitionState AcquisitionState() const noexcept
Gets the current acquisition state.
Definition decl_composite_stream_base.hpp:386
int MinRequiredFlowSetCount() const
Gets minimum number of flow sets required for the acquisition.
Definition decl_composite_stream_base.hpp:327
bool TryAbort() noexcept override
Stops the acquisition of images immediately.
Definition decl_composite_stream_base.hpp:368
virtual void EngineStop()
Stops the acquisition engine.
Definition decl_composite_stream_base.hpp:97
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:241
virtual void DeviceStart()
Starts the stream on the device.
Definition decl_composite_stream_base.hpp:192
void RegisterExternalFlowSetPool(FlowSetPoolPtr flowSetPoolPtr)
Registers external memory.
Definition decl_composite_stream_base.hpp:288
bool TryEngineStop(const std::chrono::duration< Rep, Period > &timeout) noexcept
Stops the acquisition engine.
Definition decl_composite_stream_base.hpp:111
virtual void EngineStart()
Starts the acquisition engine on the host.
Definition decl_composite_stream_base.hpp:55
int FlowSetCount() const noexcept
Gets the number of registered flow sets.
Definition decl_composite_stream_base.hpp:313
virtual void EngineAbort()
Stops the acquisition engine immediately.
Definition decl_composite_stream_base.hpp:158
virtual bool TryDeviceAbort() noexcept
Stops the stream in the device immediately.
Definition decl_composite_stream_base.hpp:253
std::vector< FlowInfo > FlowSetInfo() const
Gets the flow set info of this stream.
Definition decl_composite_stream_base.hpp:396
void * Handle() const noexcept
Classic API stream handle.
Definition decl_composite_stream_base.hpp:44
bool TryStop() noexcept override
Stops the acquisition.
Definition decl_composite_stream_base.hpp:353
void RegisterExternalFlowSetPool(FlowSetPoolPtr flowSetPoolPtr, std::function< void()> releaseCallback)
Registers external memory.
Definition decl_composite_stream_base.hpp:298
virtual bool TryEngineStop(const std::chrono::milliseconds &timeout) noexcept
Stops the acquisition engine.
Definition decl_composite_stream_base.hpp:136
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:27
std::shared_ptr< FlowSetPool > FlowSetPoolPtr
Convenience shared pointer for FlowSetPool.
Definition driver.hpp:28
@ String
String value.
Definition driver.hpp:368
AcquisitionState
Specifies current state of the acquisition engine.
Definition driver.hpp:544
@ Stopped
The engine is stopped.
Definition driver.hpp:552
AcquisitionInterface
Known acquisition CVB interfaces.
Definition driver.hpp:437
@ GenTL
Flow set pool / queue based acquition for TL based techologies.
Definition driver.hpp:443
const int CVB_OK
No error occurred.
Definition exception.hpp:21
std::shared_ptr< NodeMap > NodeMapPtr
Convenience shared pointer for NodeMap.
Definition genapi.hpp:22
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