18#include <peak/dll_interface/peak_dll_interface_util.hpp>
20#include <unordered_map>
184 ,
public std::enable_shared_from_this<DataStream>
200 std::string
Key()
const;
206 std::string
ID()
const;
209 std::string
TLType()
const;
471 void QueueBuffer(
const std::shared_ptr<Buffer>& buffer);
491 void RevokeBuffer(
const std::shared_ptr<Buffer>& buffer);
653 static void PEAK_CALL_CONV BufferRevocationCallbackCWrapper(
void* buffer,
void* userPtr,
void* context);
659 void AddAnnouncedBuffer(
const std::shared_ptr<Buffer>& buffer);
660 void RemoveAnnouncedBuffer(
const std::shared_ptr<Buffer>& buffer);
661 void RevokeAnnouncedBuffers();
665 friend ClassCreator<DataStream>;
669 std::weak_ptr<Device> m_parentDevice;
671 std::vector<std::shared_ptr<Buffer>> m_announcedBuffers;
672 std::unordered_map<PEAK_BUFFER_HANDLE, std::shared_ptr<Buffer>> m_announcedBuffersByHandle;
673 std::unordered_map<PEAK_BUFFER_HANDLE, std::unique_ptr<BufferRevocationCallback>>
674 m_bufferRevocationCallbacksByBufferHandle;
676 mutable std::mutex m_announcedBuffersMutex;
677 mutable std::mutex m_bufferRevocationCallbacksByBufferHandleMutex;
693 std::string entryString;
697 entryString =
"InputPoolToOutputQueue";
701 entryString =
"DiscardOutputQueue";
705 entryString =
"AllToInputPool";
709 entryString =
"UnqueuedToInputPool";
713 entryString =
"DiscardAll";
717 entryString =
"Custom";
725 std::string entryString;
729 entryString =
"Default";
733 entryString =
"Custom";
741 std::string entryString;
745 entryString =
"Default";
749 entryString =
"Kill";
753 entryString =
"Custom";
760 : m_backendHandle(dataStreamHandle)
761 , m_parentDevice(parentDevice)
762 , m_announcedBuffers()
763 , m_announcedBuffersByHandle()
764 , m_announcedBuffersMutex()
765 , m_key(QueryStringFromCInterfaceFunction([&](char* key, size_t* keySize) {
789 return QueryRawInformationFromCInterfaceFunction([&](int32_t* dataType, uint8_t* buffer,
size_t* bufferSize) {
791 m_backendHandle, infoCommand, dataType, buffer, bufferSize);
797 return QueryStringFromCInterfaceFunction([&](
char*
id,
size_t* idSize) {
804 return QueryStringFromCInterfaceFunction([&](
char* tlType,
size_t* tlTypeSize) {
811 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* numBuffersAnnouncedMinRequired) {
813 m_backendHandle, numBuffersAnnouncedMinRequired);
819 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* numBuffersAnnounced) {
826 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* numBuffersQueued) {
833 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* numBuffersAwaitDelivery) {
835 m_backendHandle, numBuffersAwaitDelivery);
841 return QueryNumericFromCInterfaceFunction<uint64_t>([&](uint64_t* numBuffersDelivered) {
848 return QueryNumericFromCInterfaceFunction<uint64_t>([&](uint64_t* numBuffersStarted) {
855 return QueryNumericFromCInterfaceFunction<uint64_t>([&](uint64_t* numUnderruns) {
862 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* numChunksPerBufferMax) {
869 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* bufferAlignment) {
876 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* payloadSize) {
883 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* definesPayloadSize) {
890 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* isGrabbing) {
898 auto _callback = std::make_unique<BufferRevocationCallback>(revocationCallback);
900 auto callbackContext = _callback.get();
902 auto bufferHandle = QueryNumericFromCInterfaceFunction<PEAK_BUFFER_HANDLE>(
905 BufferRevocationCallbackCWrapper, callbackContext, _bufferHandle);
908 auto _buffer = std::make_shared<ClassCreator<Buffer>>(bufferHandle, shared_from_this());
909 AddAnnouncedBuffer(_buffer);
912 std::lock_guard<std::mutex> lock(m_bufferRevocationCallbacksByBufferHandleMutex);
914 m_bufferRevocationCallbacksByBufferHandle.emplace(bufferHandle, std::move(_callback));
922 auto bufferHandle = QueryNumericFromCInterfaceFunction<PEAK_BUFFER_HANDLE>(
925 m_backendHandle, size, userPtr, _bufferHandle);
928 auto buffer = std::make_shared<ClassCreator<Buffer>>(bufferHandle, shared_from_this());
929 AddAnnouncedBuffer(buffer);
936 if (buffer ==
nullptr)
941 auto bufferHandle = buffer->m_backendHandle;
943 CallAndCheckCInterfaceFunction(
949 if (buffer ==
nullptr)
954 auto bufferHandle = buffer->m_backendHandle;
956 CallAndCheckCInterfaceFunction(
959 RemoveAnnouncedBuffer(buffer);
962 std::lock_guard<std::mutex> lock(m_bufferRevocationCallbacksByBufferHandleMutex);
964 m_bufferRevocationCallbacksByBufferHandle.erase(bufferHandle);
972 auto bufferHandle = QueryNumericFromCInterfaceFunction<PEAK_BUFFER_HANDLE>(
975 m_backendHandle, timeout_ms, _bufferHandle);
978 return GetAnnouncedBuffer(bufferHandle);
993 CallAndCheckCInterfaceFunction([&] {
1001 std::lock_guard<std::mutex> lock(m_announcedBuffersMutex);
1003 return m_announcedBuffers;
1008 CallAndCheckCInterfaceFunction([&] {
1016 CallAndCheckCInterfaceFunction([&] {
1024 return LockOrThrow(m_parentDevice);
1027inline void PEAK_CALL_CONV DataStream::BufferRevocationCallbackCWrapper(
void* buffer,
void* userPtr,
void* context)
1032 callback->operator()(buffer, userPtr);
1038 auto moduleHandle = QueryNumericFromCInterfaceFunction<PEAK_MODULE_HANDLE>(
1043 return moduleHandle;
1048 auto eventSupportingModuleHandle = QueryNumericFromCInterfaceFunction<PEAK_EVENT_SUPPORTING_MODULE_HANDLE>(
1051 m_backendHandle, _eventSupportingModuleHandle);
1054 return eventSupportingModuleHandle;
1057inline std::shared_ptr<Buffer> DataStream::GetAnnouncedBuffer(
PEAK_BUFFER_HANDLE bufferHandle)
const
1059 std::lock_guard<std::mutex> lock(m_announcedBuffersMutex);
1061 return m_announcedBuffersByHandle.at(bufferHandle);
1064inline void DataStream::AddAnnouncedBuffer(
const std::shared_ptr<Buffer>& buffer)
1066 std::lock_guard<std::mutex> lock(m_announcedBuffersMutex);
1068 m_announcedBuffers.emplace_back(buffer);
1069 m_announcedBuffersByHandle.emplace(buffer->m_backendHandle, buffer);
1072inline void DataStream::RemoveAnnouncedBuffer(
const std::shared_ptr<Buffer>& buffer)
1074 std::lock_guard<std::mutex> lock(m_announcedBuffersMutex);
1076 m_announcedBuffers.erase(std::remove(std::begin(m_announcedBuffers), std::end(m_announcedBuffers), buffer));
1077 m_announcedBuffersByHandle.erase(buffer->m_backendHandle);
1080inline void DataStream::RevokeAnnouncedBuffers()
1082 for (
const auto& buffer : AnnouncedBuffers())
1084 RevokeBuffer(buffer);
1088inline void DataStream::Shutdown()
1092 StopAcquisition(AcquisitionStopMode::Default);
1094 Flush(DataStreamFlushMode::DiscardAll);
1095 RevokeAnnouncedBuffers();
static const uint64_t INFINITE_NUMBER
Definition peak_data_stream.hpp:190
std::shared_ptr< Buffer > AnnounceBuffer(void *buffer, size_t size, void *userPtr, const BufferRevocationCallback &revocationCallback)
Announces a given client allocated buffer to the data stream.
Definition peak_data_stream.hpp:895
DataStream(DataStream &&other)=delete
RawInformation Info(int32_t infoCommand) const
Delivers information based on the given GenTL info command.
Definition peak_data_stream.hpp:787
void RevokeBuffer(const std::shared_ptr< Buffer > &buffer)
Revokes a specified buffer.
Definition peak_data_stream.hpp:947
bool DefinesPayloadSize() const
Checks whether the data stream defines the payload size.
Definition peak_data_stream.hpp:881
void StartAcquisition(AcquisitionStartMode mode=AcquisitionStartMode::Default, uint64_t numToAcquire=INFINITE_NUMBER)
Starts the acquisition.
Definition peak_data_stream.hpp:1006
DataStream & operator=(DataStream &&other)=delete
size_t BufferAlignment() const
Returns the buffer alignment.
Definition peak_data_stream.hpp:867
void QueueBuffer(const std::shared_ptr< Buffer > &buffer)
Queues a given buffer.
Definition peak_data_stream.hpp:934
std::shared_ptr< Device > ParentDevice() const
Returns the parent device.
Definition peak_data_stream.hpp:1022
std::shared_ptr< Buffer > AllocAndAnnounceBuffer(size_t size, void *userPtr)
Allocates and announces a producer allocated buffer on the data stream.
Definition peak_data_stream.hpp:920
size_t NumBuffersAnnounced() const
Retrieves the count of buffers announced via AnnounceBuffer or AllocAndAnnounceBuffer.
Definition peak_data_stream.hpp:817
~DataStream() override
Definition peak_data_stream.hpp:770
uint64_t NumBuffersDelivered() const
Retrieves the count of buffers delivered since the last acquisition start.
Definition peak_data_stream.hpp:839
std::string Key() const
Returns the unique key.
Definition peak_data_stream.hpp:782
std::string TLType() const
Returns the TL (transport layer) type.
Definition peak_data_stream.hpp:802
uint64_t NumUnderruns() const
Retrieves the count of underruns.
Definition peak_data_stream.hpp:853
uint64_t NumBuffersStarted() const
Returns the count of buffers that have been initiated.
Definition peak_data_stream.hpp:846
std::shared_ptr< Buffer > WaitForFinishedBuffer(Timeout timeout_ms)
Blocking wait for a finished Buffer.
Definition peak_data_stream.hpp:970
size_t NumBuffersAnnouncedMinRequired() const
Returns the minimum number of buffers that must be announced before starting the acquisition with Sta...
Definition peak_data_stream.hpp:809
void KillWait()
Tells the data stream to kill one call to WaitForFinishedBuffer.
Definition peak_data_stream.hpp:981
void Flush(DataStreamFlushMode mode)
Move buffers between the Input Buffer Pool, the Output Buffer Pool and the Announced Buffer Pool,...
Definition peak_data_stream.hpp:991
size_t NumBuffersAwaitDelivery() const
Retrieves the count of buffers that are currently waiting to be delivered, i.e., the number of buffer...
Definition peak_data_stream.hpp:831
bool IsGrabbing() const
Checks whether the data stream is grabbing.
Definition peak_data_stream.hpp:888
size_t NumChunksPerBufferMax() const
Returns the maximum number of chunks per buffer.
Definition peak_data_stream.hpp:860
size_t PayloadSize() const
Returns the payload size in bytes, i.e. the size of the buffers.
Definition peak_data_stream.hpp:874
std::function< void(void *buffer, void *userPtr)> BufferRevocationCallback
Definition peak_data_stream.hpp:188
DataStream(const DataStream &other)=delete
std::vector< std::shared_ptr< Buffer > > AnnouncedBuffers() const
Retrieves the list of the currently announced buffers. The buffers' states are irrelevant,...
Definition peak_data_stream.hpp:999
void StopAcquisition(AcquisitionStopMode mode=AcquisitionStopMode::Default)
Stops the acquisition.
Definition peak_data_stream.hpp:1014
std::string ID() const
Returns the ID.
Definition peak_data_stream.hpp:795
DataStream & operator=(const DataStream &other)=delete
size_t NumBuffersQueued() const
Retrieves the count of buffers that are currently queued, i.e., the number of buffers present in the ...
Definition peak_data_stream.hpp:824
void FlushPendingKillWaits()
Flushes the KillWait queue.
Definition peak_data_stream.hpp:986
EventSupportingModule()=default
virtual PEAK_EVENT_SUPPORTING_MODULE_HANDLE EventSupportingModuleHandle() const =0
The base class for all exceptions thrown by the library.
Definition peak_exception.hpp:28
The exception thrown for passing an invalid argument to a function.
Definition peak_exception.hpp:116
virtual PEAK_MODULE_HANDLE ModuleHandle() const =0
Represents a timeout value in milliseconds.
Definition peak_timeout.hpp:32
@ Custom
Definition peak_buffer.hpp:56
The "core" namespace contains the direct GenAPI and GenTL wrapper.
Definition peak_buffer.hpp:34
DataStreamFlushMode
Operation modes for DataStream::Flush() method.
Definition peak_data_stream.hpp:43
@ UnqueuedToInputPool
Definition peak_data_stream.hpp:70
@ DiscardOutputQueue
Definition peak_data_stream.hpp:57
@ Custom
Definition peak_data_stream.hpp:83
@ InputPoolToOutputQueue
Definition peak_data_stream.hpp:51
@ AllToInputPool
Definition peak_data_stream.hpp:64
@ DiscardAll
Definition peak_data_stream.hpp:78
std::string ToString(BufferPayloadType entry)
Definition peak_buffer.hpp:612
AcquisitionStartMode
The enum holding the possible acquisition start modes, for DataStream::StartAcquisition().
Definition peak_data_stream.hpp:92
@ Default
Definition peak_data_stream.hpp:96
@ Custom
Definition peak_data_stream.hpp:101
AcquisitionStopMode
The enum holding the possible acquisition stop modes, for DataStream::StopAcquisition().
Definition peak_data_stream.hpp:110
@ Kill
Definition peak_data_stream.hpp:125
@ Default
Definition peak_data_stream.hpp:116
@ Custom
Definition peak_data_stream.hpp:130
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_dynamic_loader.h:35
struct PEAK_DATA_STREAM * PEAK_DATA_STREAM_HANDLE
Definition peak_backend.h:401
PEAK_C_API PEAK_DataStream_KillWait(PEAK_DATA_STREAM_HANDLE dataStreamHandle)
Tells the data stream to kill one call to PEAK_DataStream_WaitForFinishedBuffer.
PEAK_C_API PEAK_DataStream_GetNumBuffersAnnouncedMinRequired(PEAK_DATA_STREAM_HANDLE dataStreamHandle, size_t *numBuffersAnnouncedMinRequired)
Asks the given data stream for its minimum required number of announced buffers.
struct PEAK_MODULE * PEAK_MODULE_HANDLE
Definition peak_backend.h:421
PEAK_C_API PEAK_DataStream_ToModule(PEAK_DATA_STREAM_HANDLE dataStreamHandle, PEAK_MODULE_HANDLE *moduleHandle)
Casts the given data stream to a module.
PEAK_C_API PEAK_DataStream_Flush(PEAK_DATA_STREAM_HANDLE dataStreamHandle, PEAK_DATA_STREAM_FLUSH_MODE flushMode)
Tells the given data stream to flush its queues using the given mode.
PEAK_C_API PEAK_DataStream_Destruct(PEAK_DATA_STREAM_HANDLE dataStreamHandle)
Destroys the given data stream.
PEAK_C_API PEAK_DataStream_GetNumUnderruns(PEAK_DATA_STREAM_HANDLE dataStreamHandle, uint64_t *numUnderruns)
Asks the given data stream for its number of underruns.
PEAK_C_API PEAK_DataStream_GetBufferAlignment(PEAK_DATA_STREAM_HANDLE dataStreamHandle, size_t *bufferAlignment)
Asks the given data stream for its buffer alignment.
PEAK_C_API PEAK_DataStream_GetNumChunksPerBufferMax(PEAK_DATA_STREAM_HANDLE dataStreamHandle, size_t *numChunksPerBufferMax)
Asks the given data stream for its maximum number of chunks per buffer.
PEAK_C_API PEAK_DataStream_GetDefinesPayloadSize(PEAK_DATA_STREAM_HANDLE dataStreamHandle, PEAK_BOOL8 *definesPayloadSize)
Asks the given data stream whether it defines the payload size.
struct PEAK_BUFFER * PEAK_BUFFER_HANDLE
Definition peak_backend.h:405
struct PEAK_EVENT_SUPPORTING_MODULE * PEAK_EVENT_SUPPORTING_MODULE_HANDLE
Definition peak_backend.h:477
PEAK_C_API PEAK_DataStream_GetNumBuffersStarted(PEAK_DATA_STREAM_HANDLE dataStreamHandle, uint64_t *numBuffersStarted)
Asks the given data stream for its number of started buffers.
PEAK_C_API PEAK_DataStream_GetPayloadSize(PEAK_DATA_STREAM_HANDLE dataStreamHandle, size_t *payloadSize)
Asks the given data stream for its payload size.
PEAK_C_API PEAK_DataStream_GetNumBuffersAnnounced(PEAK_DATA_STREAM_HANDLE dataStreamHandle, size_t *numBuffersAnnounced)
Asks the given data stream for its number of announced buffers.
PEAK_C_API PEAK_DataStream_GetKey(PEAK_DATA_STREAM_HANDLE dataStreamHandle, char *key, size_t *keySize)
Asks the given data stream for its key.
PEAK_C_API PEAK_DataStream_AnnounceBuffer(PEAK_DATA_STREAM_HANDLE dataStreamHandle, void *buffer, size_t bufferSize, void *userPtr, PEAK_BUFFER_REVOCATION_CALLBACK revocationCallback, void *callbackContext, PEAK_BUFFER_HANDLE *bufferHandle)
Announces the given buffer at the given data stream.
PEAK_C_API PEAK_DataStream_GetNumBuffersQueued(PEAK_DATA_STREAM_HANDLE dataStreamHandle, size_t *numBuffersQueued)
Asks the given data stream for its number of queued buffers.
PEAK_C_API PEAK_DataStream_FlushPendingKillWaits(PEAK_DATA_STREAM_HANDLE dataStreamHandle)
Flushes the KillWait queue.
PEAK_C_API PEAK_DataStream_WaitForFinishedBuffer(PEAK_DATA_STREAM_HANDLE dataStreamHandle, uint64_t timeout_ms, PEAK_BUFFER_HANDLE *bufferHandle)
Blocking wait for a finished Buffer.
PEAK_C_API PEAK_DataStream_GetIsGrabbing(PEAK_DATA_STREAM_HANDLE dataStreamHandle, PEAK_BOOL8 *isGrabbing)
Asks the given data stream whether it is grabbing.
PEAK_C_API PEAK_DataStream_RevokeBuffer(PEAK_DATA_STREAM_HANDLE dataStreamHandle, PEAK_BUFFER_HANDLE bufferHandle)
Tells the given data stream to revoke the given buffer.
int32_t PEAK_ACQUISITION_START_MODE
Definition peak_backend.h:52
int8_t PEAK_BOOL8
Definition peak_backend.h:43
PEAK_C_API PEAK_DataStream_GetNumBuffersDelivered(PEAK_DATA_STREAM_HANDLE dataStreamHandle, uint64_t *numBuffersDelivered)
Asks the given data stream for its number of delivered buffers.
static const uint64_t PEAK_INFINITE_NUMBER
The constant defining an infinite number of buffers.
Definition peak_backend.h:358
int32_t PEAK_ACQUISITION_STOP_MODE
Definition peak_backend.h:62
int32_t PEAK_DATA_STREAM_FLUSH_MODE
Definition peak_backend.h:120
PEAK_C_API PEAK_DataStream_GetID(PEAK_DATA_STREAM_HANDLE dataStreamHandle, char *id, size_t *idSize)
Asks the given data stream for its ID.
PEAK_C_API PEAK_DataStream_StopAcquisition(PEAK_DATA_STREAM_HANDLE dataStreamHandle, PEAK_ACQUISITION_STOP_MODE stopMode)
Tells the given data stream to stop the acquisition using the given mode.
PEAK_C_API PEAK_DataStream_QueueBuffer(PEAK_DATA_STREAM_HANDLE dataStreamHandle, PEAK_BUFFER_HANDLE bufferHandle)
Tells the given data stream to queue the given buffer.
PEAK_C_API PEAK_DataStream_GetNumBuffersAwaitDelivery(PEAK_DATA_STREAM_HANDLE dataStreamHandle, size_t *numBuffersAwaitDelivery)
Asks the given data stream for its number of buffers awaiting delivery.
PEAK_C_API PEAK_DataStream_AllocAndAnnounceBuffer(PEAK_DATA_STREAM_HANDLE dataStreamHandle, size_t bufferSize, void *userPtr, PEAK_BUFFER_HANDLE *bufferHandle)
Tells the given data stream to allocate and announce a buffer with the given size.
PEAK_C_API PEAK_DataStream_GetTLType(PEAK_DATA_STREAM_HANDLE dataStreamHandle, char *tlType, size_t *tlTypeSize)
Asks the given data stream for its TL type.
PEAK_C_API PEAK_DataStream_GetInfo(PEAK_DATA_STREAM_HANDLE dataStreamHandle, int32_t infoCommand, int32_t *infoDataType, uint8_t *info, size_t *infoSize)
Asks the given data stream for an information based on a specific command.
PEAK_C_API PEAK_DataStream_ToEventSupportingModule(PEAK_DATA_STREAM_HANDLE dataStreamHandle, PEAK_EVENT_SUPPORTING_MODULE_HANDLE *eventSupportingModuleHandle)
Casts the given data stream to an event-supporting module.
PEAK_C_API PEAK_DataStream_StartAcquisition(PEAK_DATA_STREAM_HANDLE dataStreamHandle, PEAK_ACQUISITION_START_MODE startMode, uint64_t numToAcquire)
Tells the given data stream to start the acquisition using the given mode and to acquire the given nu...
#define PEAK_C_ABI_PREFIX
Definition peak_dll_defines.h:16
#define PEAK_CALL_CONV
Definition peak_dynamic_loader.h:30