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;
205 std::string
ID()
const;
208 std::string
TLType()
const;
219 size_t NumBuffersAnnouncedMinRequired()
const;
230 size_t NumBuffersAnnounced()
const;
241 size_t NumBuffersQueued()
const;
252 size_t NumBuffersAwaitDelivery()
const;
263 uint64_t NumBuffersDelivered()
const;
274 uint64_t NumBuffersStarted()
const;
285 uint64_t NumUnderruns()
const;
296 size_t NumChunksPerBufferMax()
const;
307 size_t BufferAlignment()
const;
318 size_t PayloadSize()
const;
334 bool DefinesPayloadSize()
const;
346 bool IsGrabbing()
const;
387 std::shared_ptr<Buffer> AnnounceBuffer(
412 std::shared_ptr<Buffer> AllocAndAnnounceBuffer(
size_t size,
void* userPtr);
427 void QueueBuffer(
const std::shared_ptr<Buffer>& buffer);
442 void RevokeBuffer(
const std::shared_ptr<Buffer>& buffer);
465 std::vector<std::shared_ptr<Buffer>> AnnouncedBuffers()
const;
493 void StartAcquisition(
539 std::shared_ptr<Buffer> WaitForFinishedBuffer(
Timeout timeout_ms);
556 std::shared_ptr<Device> ParentDevice()
const;
559 static void PEAK_CALL_CONV BufferRevocationCallbackCWrapper(
void* buffer,
void* userPtr,
void* context);
565 void AddAnnouncedBuffer(
const std::shared_ptr<Buffer>& buffer);
566 void RemoveAnnouncedBuffer(
const std::shared_ptr<Buffer>& buffer);
567 void RevokeAnnouncedBuffers();
571 friend ClassCreator<DataStream>;
575 std::weak_ptr<Device> m_parentDevice;
577 std::vector<std::shared_ptr<Buffer>> m_announcedBuffers;
578 std::unordered_map<PEAK_BUFFER_HANDLE, std::shared_ptr<Buffer>> m_announcedBuffersByHandle;
579 std::unordered_map<PEAK_BUFFER_HANDLE, std::unique_ptr<BufferRevocationCallback>>
580 m_bufferRevocationCallbacksByBufferHandle;
582 mutable std::mutex m_announcedBuffersMutex;
583 mutable std::mutex m_bufferRevocationCallbacksByBufferHandleMutex;
599 std::string entryString;
603 entryString =
"InputPoolToOutputQueue";
607 entryString =
"DiscardOutputQueue";
611 entryString =
"AllToInputPool";
615 entryString =
"UnqueuedToInputPool";
619 entryString =
"DiscardAll";
623 entryString =
"Custom";
631 std::string entryString;
635 entryString =
"Default";
639 entryString =
"Custom";
647 std::string entryString;
651 entryString =
"Default";
655 entryString =
"Kill";
659 entryString =
"Custom";
666 : m_backendHandle(dataStreamHandle)
667 , m_parentDevice(parentDevice)
668 , m_announcedBuffers()
669 , m_announcedBuffersByHandle()
670 , m_announcedBuffersMutex()
671 , m_key(QueryStringFromCInterfaceFunction([&](
char* key,
size_t* keySize) {
695 return QueryRawInformationFromCInterfaceFunction([&](int32_t* dataType, uint8_t* buffer,
size_t* bufferSize) {
697 m_backendHandle, infoCommand, dataType, buffer, bufferSize);
703 return QueryStringFromCInterfaceFunction([&](
char*
id,
size_t* idSize) {
710 return QueryStringFromCInterfaceFunction([&](
char* tlType,
size_t* tlTypeSize) {
717 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* numBuffersAnnouncedMinRequired) {
719 m_backendHandle, numBuffersAnnouncedMinRequired);
725 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* numBuffersAnnounced) {
732 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* numBuffersQueued) {
739 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* numBuffersAwaitDelivery) {
741 m_backendHandle, numBuffersAwaitDelivery);
747 return QueryNumericFromCInterfaceFunction<uint64_t>([&](uint64_t* numBuffersDelivered) {
754 return QueryNumericFromCInterfaceFunction<uint64_t>([&](uint64_t* numBuffersStarted) {
761 return QueryNumericFromCInterfaceFunction<uint64_t>([&](uint64_t* numUnderruns) {
768 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* numChunksPerBufferMax) {
775 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* bufferAlignment) {
782 return QueryNumericFromCInterfaceFunction<size_t>([&](
size_t* payloadSize) {
789 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* definesPayloadSize) {
796 return QueryNumericFromCInterfaceFunction<PEAK_BOOL8>([&](
PEAK_BOOL8* isGrabbing) {
804 auto _callback = std::make_unique<BufferRevocationCallback>(revocationCallback);
806 auto callbackContext = _callback.get();
808 auto bufferHandle = QueryNumericFromCInterfaceFunction<PEAK_BUFFER_HANDLE>(
811 BufferRevocationCallbackCWrapper, callbackContext, _bufferHandle);
814 auto _buffer = std::make_shared<ClassCreator<Buffer>>(bufferHandle, shared_from_this());
815 AddAnnouncedBuffer(_buffer);
818 std::lock_guard<std::mutex> lock(m_bufferRevocationCallbacksByBufferHandleMutex);
820 m_bufferRevocationCallbacksByBufferHandle.emplace(bufferHandle, std::move(_callback));
828 auto bufferHandle = QueryNumericFromCInterfaceFunction<PEAK_BUFFER_HANDLE>(
831 m_backendHandle, size, userPtr, _bufferHandle);
834 auto buffer = std::make_shared<ClassCreator<Buffer>>(bufferHandle, shared_from_this());
835 AddAnnouncedBuffer(buffer);
842 if (buffer ==
nullptr)
847 auto bufferHandle = buffer->m_backendHandle;
849 CallAndCheckCInterfaceFunction(
855 if (buffer ==
nullptr)
860 auto bufferHandle = buffer->m_backendHandle;
862 CallAndCheckCInterfaceFunction(
865 RemoveAnnouncedBuffer(buffer);
868 std::lock_guard<std::mutex> lock(m_bufferRevocationCallbacksByBufferHandleMutex);
870 m_bufferRevocationCallbacksByBufferHandle.erase(bufferHandle);
878 auto bufferHandle = QueryNumericFromCInterfaceFunction<PEAK_BUFFER_HANDLE>(
881 m_backendHandle, timeout_ms, _bufferHandle);
884 return GetAnnouncedBuffer(bufferHandle);
894 CallAndCheckCInterfaceFunction([&] {
896 m_backendHandle, static_cast<PEAK_DATA_STREAM_FLUSH_MODE>(mode));
902 std::lock_guard<std::mutex> lock(m_announcedBuffersMutex);
904 return m_announcedBuffers;
909 CallAndCheckCInterfaceFunction([&] {
911 m_backendHandle, static_cast<PEAK_ACQUISITION_START_MODE>(mode), numToAcquire);
917 CallAndCheckCInterfaceFunction([&] {
919 m_backendHandle, static_cast<PEAK_ACQUISITION_STOP_MODE>(mode));
925 return LockOrThrow(m_parentDevice);
928 inline void PEAK_CALL_CONV DataStream::BufferRevocationCallbackCWrapper(
void* buffer,
void* userPtr,
void* context)
933 callback->operator()(buffer, userPtr);
939 auto moduleHandle = QueryNumericFromCInterfaceFunction<PEAK_MODULE_HANDLE>(
949 auto eventSupportingModuleHandle = QueryNumericFromCInterfaceFunction<PEAK_EVENT_SUPPORTING_MODULE_HANDLE>(
952 m_backendHandle, _eventSupportingModuleHandle);
955 return eventSupportingModuleHandle;
958 inline std::shared_ptr<Buffer> DataStream::GetAnnouncedBuffer(
PEAK_BUFFER_HANDLE bufferHandle)
const 960 std::lock_guard<std::mutex> lock(m_announcedBuffersMutex);
962 return m_announcedBuffersByHandle.at(bufferHandle);
965 inline void DataStream::AddAnnouncedBuffer(
const std::shared_ptr<Buffer>& buffer)
967 std::lock_guard<std::mutex> lock(m_announcedBuffersMutex);
969 m_announcedBuffers.emplace_back(buffer);
970 m_announcedBuffersByHandle.emplace(buffer->m_backendHandle, buffer);
973 inline void DataStream::RemoveAnnouncedBuffer(
const std::shared_ptr<Buffer>& buffer)
975 std::lock_guard<std::mutex> lock(m_announcedBuffersMutex);
977 m_announcedBuffers.erase(std::remove(std::begin(m_announcedBuffers), std::end(m_announcedBuffers), buffer));
978 m_announcedBuffersByHandle.erase(buffer->m_backendHandle);
981 inline void DataStream::RevokeAnnouncedBuffers()
983 for (
const auto& buffer : AnnouncedBuffers())
985 RevokeBuffer(buffer);
989 inline void DataStream::Shutdown()
996 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:900
uint64_t NumUnderruns() const
Returns the number of underruns.
Definition: peak_data_stream.hpp:759
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:340
The exception thrown for pass an invalid argument to a function.
Definition: peak_exception.hpp:73
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:787
void RevokeBuffer(const std::shared_ptr< Buffer > &buffer)
Revokes a given buffer.
Definition: peak_data_stream.hpp:853
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:766
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:915
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:459
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:826
size_t PayloadSize() const
Returns the payload size in bytes, i.e. the size of the buffers.
Definition: peak_data_stream.hpp:780
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:505
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:745
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:892
size_t NumBuffersAwaitDelivery() const
Returns the number of buffers awaiting delivery.
Definition: peak_data_stream.hpp:737
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()
Tells the data stream to kill a wait for a finished buffer.
Definition: peak_data_stream.hpp:887
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 to the data stream.
Definition: peak_data_stream.hpp:801
uint64_t NumBuffersStarted() const
Returns the number of started buffers.
Definition: peak_data_stream.hpp:752
~DataStream() override
Definition: peak_data_stream.hpp:676
size_t NumBuffersQueued() const
Returns the number of queued buffers.
Definition: peak_data_stream.hpp:730
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:688
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:715
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:387
size_t BufferAlignment() const
Returns the buffer alignment.
Definition: peak_data_stream.hpp:773
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:701
std::string TLType() const
Returns the TL (transport layer) type.
Definition: peak_data_stream.hpp:708
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:923
struct PEAK_DATA_STREAM * PEAK_DATA_STREAM_HANDLE
Definition: peak_backend.h:383
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:840
#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:876
bool IsGrabbing() const
Checks whether the data stream is grabbing.
Definition: peak_data_stream.hpp:794
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:907
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:723
struct PEAK_MODULE * PEAK_MODULE_HANDLE
Definition: peak_backend.h:403
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:693
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.