18 #include <peak/dll_interface/peak_dll_interface_util.hpp> 20 #include <unordered_map> 183 ,
public std::enable_shared_from_this<DataStream>
199 std::string Key()
const;
204 std::string
ID()
const;
206 std::string
TLType()
const;
216 size_t NumBuffersAnnouncedMinRequired()
const;
226 size_t NumBuffersAnnounced()
const;
236 size_t NumBuffersQueued()
const;
246 size_t NumBuffersAwaitDelivery()
const;
256 uint64_t NumBuffersDelivered()
const;
266 uint64_t NumBuffersStarted()
const;
276 uint64_t NumUnderruns()
const;
286 size_t NumChunksPerBufferMax()
const;
296 size_t BufferAlignment()
const;
306 size_t PayloadSize()
const;
321 bool DefinesPayloadSize()
const;
332 bool IsGrabbing()
const;
365 std::shared_ptr<Buffer> AnnounceBuffer(
381 std::shared_ptr<Buffer> AllocAndAnnounceBuffer(
size_t size,
void* userPtr);
392 void QueueBuffer(
const std::shared_ptr<Buffer>& buffer);
406 void RevokeBuffer(
const std::shared_ptr<Buffer>& buffer);
427 std::vector<std::shared_ptr<Buffer>> AnnouncedBuffers()
const;
445 void StartAcquisition(
477 std::shared_ptr<Buffer> WaitForFinishedBuffer(
Timeout timeout_ms);
489 std::shared_ptr<Device> ParentDevice()
const;
492 static void PEAK_CALL_CONV BufferRevocationCallbackCWrapper(
void* buffer,
void* userPtr,
void* context);
498 void AddAnnouncedBuffer(
const std::shared_ptr<Buffer>& buffer);
499 void RemoveAnnouncedBuffer(
const std::shared_ptr<Buffer>& buffer);
500 void RevokeAnnouncedBuffers();
504 friend ClassCreator<DataStream>;
508 std::weak_ptr<Device> m_parentDevice;
510 std::vector<std::shared_ptr<Buffer>> m_announcedBuffers;
511 std::unordered_map<PEAK_BUFFER_HANDLE, std::shared_ptr<Buffer>> m_announcedBuffersByHandle;
512 std::unordered_map<PEAK_BUFFER_HANDLE, std::unique_ptr<BufferRevocationCallback>>
513 m_bufferRevocationCallbacksByBufferHandle;
515 mutable std::mutex m_announcedBuffersMutex;
516 mutable std::mutex m_bufferRevocationCallbacksByBufferHandleMutex;
532 std::string entryString;
536 entryString =
"InputPoolToOutputQueue";
540 entryString =
"DiscardOutputQueue";
544 entryString =
"AllToInputPool";
548 entryString =
"UnqueuedToInputPool";
552 entryString =
"DiscardAll";
556 entryString =
"Custom";
564 std::string entryString;
568 entryString =
"Default";
572 entryString =
"Custom";
580 std::string entryString;
584 entryString =
"Default";
588 entryString =
"Kill";
592 entryString =
"Custom";
599 : m_backendHandle(dataStreamHandle)
600 , m_parentDevice(parentDevice)
601 , m_announcedBuffers()
602 , m_announcedBuffersByHandle()
603 , m_announcedBuffersMutex()
604 , m_key(QueryStringFromCInterfaceFunction([&](
char* key,
size_t* keySize) {
628 return QueryRawInformationFromCInterfaceFunction([&](int32_t* dataType, uint8_t* buffer,
size_t* bufferSize) {
630 m_backendHandle, infoCommand, dataType, buffer, bufferSize);
636 return QueryStringFromCInterfaceFunction([&](
char*
id,
size_t* idSize) {
643 return QueryStringFromCInterfaceFunction([&](
char* tlType,
size_t* tlTypeSize) {
650 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* numBuffersAnnouncedMinRequired) {
652 m_backendHandle, numBuffersAnnouncedMinRequired);
658 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* numBuffersAnnounced) {
665 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* numBuffersQueued) {
672 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* numBuffersAwaitDelivery) {
674 m_backendHandle, numBuffersAwaitDelivery);
680 return QueryNumericFromCInterfaceFunction<uint64_t>([&](uint64_t* numBuffersDelivered) {
687 return QueryNumericFromCInterfaceFunction<uint64_t>([&](uint64_t* numBuffersStarted) {
694 return QueryNumericFromCInterfaceFunction<uint64_t>([&](uint64_t* numUnderruns) {
701 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* numChunksPerBufferMax) {
708 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* bufferAlignment) {
715 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* payloadSize) {
722 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* definesPayloadSize) {
729 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* isGrabbing) {
737 auto _callback = std::make_unique<BufferRevocationCallback>(revocationCallback);
739 auto callbackContext = _callback.get();
741 auto bufferHandle = QueryNumericFromCInterfaceFunction<PEAK_BUFFER_HANDLE>(
744 BufferRevocationCallbackCWrapper, callbackContext, _bufferHandle);
747 auto _buffer = std::make_shared<ClassCreator<Buffer>>(bufferHandle, shared_from_this());
748 AddAnnouncedBuffer(_buffer);
751 std::lock_guard<std::mutex> lock(m_bufferRevocationCallbacksByBufferHandleMutex);
753 m_bufferRevocationCallbacksByBufferHandle.emplace(bufferHandle, std::move(_callback));
761 auto bufferHandle = QueryNumericFromCInterfaceFunction<PEAK_BUFFER_HANDLE>(
764 m_backendHandle, size, userPtr, _bufferHandle);
767 auto buffer = std::make_shared<ClassCreator<Buffer>>(bufferHandle, shared_from_this());
768 AddAnnouncedBuffer(buffer);
775 auto bufferHandle = buffer->m_backendHandle;
777 CallAndCheckCInterfaceFunction(
783 auto bufferHandle = buffer->m_backendHandle;
785 CallAndCheckCInterfaceFunction(
788 RemoveAnnouncedBuffer(buffer);
791 std::lock_guard<std::mutex> lock(m_bufferRevocationCallbacksByBufferHandleMutex);
793 m_bufferRevocationCallbacksByBufferHandle.erase(bufferHandle);
801 auto bufferHandle = QueryNumericFromCInterfaceFunction<PEAK_BUFFER_HANDLE>(
804 m_backendHandle, timeout_ms, _bufferHandle);
807 return GetAnnouncedBuffer(bufferHandle);
817 CallAndCheckCInterfaceFunction([&] {
819 m_backendHandle, static_cast<PEAK_DATA_STREAM_FLUSH_MODE>(mode));
825 std::lock_guard<std::mutex> lock(m_announcedBuffersMutex);
827 return m_announcedBuffers;
832 CallAndCheckCInterfaceFunction([&] {
834 m_backendHandle, static_cast<PEAK_ACQUISITION_START_MODE>(mode), numToAcquire);
840 CallAndCheckCInterfaceFunction([&] {
842 m_backendHandle, static_cast<PEAK_ACQUISITION_STOP_MODE>(mode));
848 return LockOrThrow(m_parentDevice);
851 inline void PEAK_CALL_CONV DataStream::BufferRevocationCallbackCWrapper(
void* buffer,
void* userPtr,
void* context)
856 callback->operator()(buffer, userPtr);
862 auto moduleHandle = QueryNumericFromCInterfaceFunction<PEAK_MODULE_HANDLE>(
872 auto eventSupportingModuleHandle = QueryNumericFromCInterfaceFunction<PEAK_EVENT_SUPPORTING_MODULE_HANDLE>(
875 m_backendHandle, _eventSupportingModuleHandle);
878 return eventSupportingModuleHandle;
881 inline std::shared_ptr<Buffer> DataStream::GetAnnouncedBuffer(
PEAK_BUFFER_HANDLE bufferHandle)
const 883 std::lock_guard<std::mutex> lock(m_announcedBuffersMutex);
885 return m_announcedBuffersByHandle.at(bufferHandle);
888 inline void DataStream::AddAnnouncedBuffer(
const std::shared_ptr<Buffer>& buffer)
890 std::lock_guard<std::mutex> lock(m_announcedBuffersMutex);
892 m_announcedBuffers.emplace_back(buffer);
893 m_announcedBuffersByHandle.emplace(buffer->m_backendHandle, buffer);
896 inline void DataStream::RemoveAnnouncedBuffer(
const std::shared_ptr<Buffer>& buffer)
898 std::lock_guard<std::mutex> lock(m_announcedBuffersMutex);
900 m_announcedBuffers.erase(std::remove(std::begin(m_announcedBuffers), std::end(m_announcedBuffers), buffer));
901 m_announcedBuffersByHandle.erase(buffer->m_backendHandle);
904 inline void DataStream::RevokeAnnouncedBuffers()
906 for (
const auto& buffer : AnnouncedBuffers())
908 RevokeBuffer(buffer);
912 inline void DataStream::Shutdown()
919 RevokeAnnouncedBuffers();
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.
std::vector< std::shared_ptr< Buffer > > AnnouncedBuffers() const
Returns the currently announced buffers.
Definition: peak_data_stream.hpp:823
uint64_t NumUnderruns() const
Returns the number of underruns.
Definition: peak_data_stream.hpp:692
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.
const uint64_t PEAK_INFINITE_NUMBER
The constant defining an infinite number of buffers.
Definition: peak_backend.h:338
PEAK_C_API PEAK_DataStream_Destruct(PEAK_DATA_STREAM_HANDLE dataStreamHandle)
Destroys the given data stream.
bool DefinesPayloadSize() const
Checks whether the data stream defines the payload size.
Definition: peak_data_stream.hpp:720
void RevokeBuffer(const std::shared_ptr< Buffer > &buffer)
Revokes a given buffer.
Definition: peak_data_stream.hpp:781
int8_t PEAK_BOOL8
Definition: peak_backend.h:26
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_ToModule(PEAK_DATA_STREAM_HANDLE dataStreamHandle, PEAK_MODULE_HANDLE *moduleHandle)
Casts the given data stream to a module.
size_t NumChunksPerBufferMax() const
Returns the maximum number of chunks per buffer.
Definition: peak_data_stream.hpp:699
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.
void StopAcquisition(AcquisitionStopMode mode=AcquisitionStopMode::Default)
Stops the acquisition.
Definition: peak_data_stream.hpp:838
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.
std::function< void(void *buffer, void *userPtr)> BufferRevocationCallback
Definition: peak_data_stream.hpp:187
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition: peak_dynamic_loader.h:32
struct PEAK_EVENT_SUPPORTING_MODULE * PEAK_EVENT_SUPPORTING_MODULE_HANDLE
Definition: peak_backend.h:457
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:759
size_t PayloadSize() const
Returns the payload size in bytes, i.e. the size of the buffers.
Definition: peak_data_stream.hpp:713
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.
DataStreamFlushMode
Operation modes for DataStream::Flush() method.
Definition: peak_data_stream.hpp:42
std::string ToString(BufferPayloadType entry)
Definition: peak_buffer.hpp:472
PEAK_C_API PEAK_DataStream_KillWait(PEAK_DATA_STREAM_HANDLE dataStreamHandle)
Tells the given data stream to kill a wait for a finished buffer.
uint64_t NumBuffersDelivered() const
Returns the number of delivered buffers.
Definition: peak_data_stream.hpp:678
void Flush(DataStreamFlushMode mode)
Move buffers between the Input Buffer Pool, the Output Buffer Queue and the Announced Buffer Pool...
Definition: peak_data_stream.hpp:815
size_t NumBuffersAwaitDelivery() const
Returns the number of buffers awaiting delivery.
Definition: peak_data_stream.hpp:670
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.
void KillWait()
Kills one wait for a finished buffer or stores the kill request if there is no waiting thread...
Definition: peak_data_stream.hpp:810
PEAK_C_API PEAK_DataStream_GetIsGrabbing(PEAK_DATA_STREAM_HANDLE dataStreamHandle, PEAK_BOOL8 *isGrabbing)
Asks the given data stream whether it is grabbing.
std::shared_ptr< Buffer > AnnounceBuffer(void *buffer, size_t size, void *userPtr, const BufferRevocationCallback &revocationCallback)
Announces a given client allocated buffer on the data stream.
Definition: peak_data_stream.hpp:734
uint64_t NumBuffersStarted() const
Returns the number of started buffers.
Definition: peak_data_stream.hpp:685
~DataStream() override
Definition: peak_data_stream.hpp:609
size_t NumBuffersQueued() const
Returns the number of queued buffers.
Definition: peak_data_stream.hpp:663
AcquisitionStartMode
The enum holding the possible acquisition start modes, for DataStream::StartAcquisition().
Definition: peak_data_stream.hpp:91
PEAK_C_API PEAK_DataStream_WaitForFinishedBuffer(PEAK_DATA_STREAM_HANDLE dataStreamHandle, uint64_t timeout_ms, PEAK_BUFFER_HANDLE *bufferHandle)
Tells the given data stream to wait for a finished buffer with the given timeout. ...
Represents a GenTL Device module, i.e. a local virtual Device proxy for the actual hardware RemoteDev...
Definition: peak_device.hpp:52
std::string Key() const
Returns the unique key.
Definition: peak_data_stream.hpp:621
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_GetNumBuffersDelivered(PEAK_DATA_STREAM_HANDLE dataStreamHandle, uint64_t *numBuffersDelivered)
Asks the given data stream for its number of delivered buffers.
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.
size_t NumBuffersAnnouncedMinRequired() const
Returns the minimum number of announced buffers required to start the acquisition.
Definition: peak_data_stream.hpp:648
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...
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_GetKey(PEAK_DATA_STREAM_HANDLE dataStreamHandle, char *key, size_t *keySize)
Asks the given data stream for its key.
struct PEAK_BUFFER * PEAK_BUFFER_HANDLE
Definition: peak_backend.h:385
size_t BufferAlignment() const
Returns the buffer alignment.
Definition: peak_data_stream.hpp:706
AcquisitionStopMode
The enum holding the possible acquisition stop modes, for DataStream::StopAcquisition().
Definition: peak_data_stream.hpp:109
std::string ID() const
Returns the ID.
Definition: peak_data_stream.hpp:634
std::string TLType() const
Returns the TL (transport layer) type.
Definition: peak_data_stream.hpp:641
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_GetNumBuffersAnnouncedMinRequired(PEAK_DATA_STREAM_HANDLE dataStreamHandle, size_t *numBuffersAnnouncedMinRequired)
Asks the given data stream for its minimum required number of announced buffers.
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.
Represents a timeout value in milliseconds.
Definition: peak_timeout.hpp:30
Represents a GenTL DataStream module.
Definition: peak_data_stream.hpp:181
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.
The base class for all exceptions thrown by the library.
Definition: peak_exception.hpp:25
std::shared_ptr< Device > ParentDevice() const
Returns the parent device.
Definition: peak_data_stream.hpp:846
struct PEAK_DATA_STREAM * PEAK_DATA_STREAM_HANDLE
Definition: peak_backend.h:381
PEAK_C_API PEAK_DataStream_GetBufferAlignment(PEAK_DATA_STREAM_HANDLE dataStreamHandle, size_t *bufferAlignment)
Asks the given data stream for its buffer alignment.
void QueueBuffer(const std::shared_ptr< Buffer > &buffer)
Queues a given buffer.
Definition: peak_data_stream.hpp:773
#define PEAK_CALL_CONV
Definition: peak_dynamic_loader.h:29
#define PEAK_C_ABI_PREFIX
Definition: peak_dll_defines.h:16
PEAK_C_API PEAK_DataStream_GetPayloadSize(PEAK_DATA_STREAM_HANDLE dataStreamHandle, size_t *payloadSize)
Asks the given data stream for its payload size.
std::shared_ptr< Buffer > WaitForFinishedBuffer(Timeout timeout_ms)
Blocking wait for a finished Buffer.
Definition: peak_data_stream.hpp:799
bool IsGrabbing() const
Checks whether the data stream is grabbing.
Definition: peak_data_stream.hpp:727
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.
void StartAcquisition(AcquisitionStartMode mode=AcquisitionStartMode::Default, uint64_t numToAcquire=INFINITE_NUMBER)
Starts the acquisition.
Definition: peak_data_stream.hpp:830
PEAK_C_API PEAK_DataStream_GetNumUnderruns(PEAK_DATA_STREAM_HANDLE dataStreamHandle, uint64_t *numUnderruns)
Asks the given data stream for its number of underruns.
size_t NumBuffersAnnounced() const
Returns the number of announced buffers.
Definition: peak_data_stream.hpp:656
struct PEAK_MODULE * PEAK_MODULE_HANDLE
Definition: peak_backend.h:401
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.
RawInformation Info(int32_t infoCommand) const
Delivers information based on the given GenTL info command.
Definition: peak_data_stream.hpp:626
The base class for all modules being able to raise events.
Definition: peak_event_supporting_module.hpp:33
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.