IDS peak genericC++  v1.5.0
peak::core::DataStream Class Reference

Represents a GenTL DataStream module. More...

#include <peak/data_stream/peak_data_stream.hpp>

Inheritance diagram for peak::core::DataStream:
peak::core::EventSupportingModule peak::core::Module

Public Types

using BufferRevocationCallback = std::function< void(void *buffer, void *userPtr)>
 

Public Member Functions

 DataStream ()=delete
 
 ~DataStream () override
 
 DataStream (const DataStream &other)=delete
 
DataStream & operator= (const DataStream &other)=delete
 
 DataStream (DataStream &&other)=delete
 
DataStream & operator= (DataStream &&other)=delete
 
std::string Key () const
 Returns the unique key. More...
 
RawInformation Info (int32_t infoCommand) const
 Delivers information based on the given GenTL info command. More...
 
std::string ID () const
 Returns the ID. More...
 
std::string TLType () const
 Returns the TL (transport layer) type. More...
 
size_t NumBuffersAnnouncedMinRequired () const
 Returns the minimum number of announced buffers required to start the acquisition. More...
 
size_t NumBuffersAnnounced () const
 Returns the number of announced buffers. More...
 
size_t NumBuffersQueued () const
 Returns the number of queued buffers. More...
 
size_t NumBuffersAwaitDelivery () const
 Returns the number of buffers awaiting delivery. More...
 
uint64_t NumBuffersDelivered () const
 Returns the number of delivered buffers. More...
 
uint64_t NumBuffersStarted () const
 Returns the number of started buffers. More...
 
uint64_t NumUnderruns () const
 Returns the number of underruns. More...
 
size_t NumChunksPerBufferMax () const
 Returns the maximum number of chunks per buffer. More...
 
size_t BufferAlignment () const
 Returns the buffer alignment. More...
 
size_t PayloadSize () const
 Returns the payload size in bytes, i.e. the size of the buffers. More...
 
bool DefinesPayloadSize () const
 Checks whether the data stream defines the payload size. More...
 
bool IsGrabbing () const
 Checks whether the data stream is grabbing. More...
 
std::shared_ptr< Device > ParentDevice () const
 Returns the parent device. More...
 
Buffer Management

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. More...
 
std::shared_ptr< Buffer > AllocAndAnnounceBuffer (size_t size, void *userPtr)
 Allocates and announces a producer allocated buffer on the data stream. More...
 
void QueueBuffer (const std::shared_ptr< Buffer > &buffer)
 Queues a given buffer. More...
 
void RevokeBuffer (const std::shared_ptr< Buffer > &buffer)
 Revokes a given buffer. More...
 
void Flush (DataStreamFlushMode mode)
 Move buffers between the Input Buffer Pool, the Output Buffer Queue and the Announced Buffer Pool, depending on the mode parameter. More...
 
std::vector< std::shared_ptr< Buffer > > AnnouncedBuffers () const
 Returns the currently announced buffers. More...
 
Start/Stop Acquisition

void StartAcquisition (AcquisitionStartMode mode=AcquisitionStartMode::Default, uint64_t numToAcquire=INFINITE_NUMBER)
 Starts the acquisition. More...
 
void StopAcquisition (AcquisitionStopMode mode=AcquisitionStopMode::Default)
 Stops the acquisition. More...
 
Wait for new buffer

std::shared_ptr< Buffer > WaitForFinishedBuffer (Timeout timeout_ms)
 Blocking wait for a finished Buffer. More...
 
void KillWait ()
 Kills one wait for a finished buffer or stores the kill request if there is no waiting thread. More...
 
- Public Member Functions inherited from peak::core::EventSupportingModule
 EventSupportingModule ()=default
 
 ~EventSupportingModule () override=default
 
 EventSupportingModule (const EventSupportingModule &other)=delete
 
EventSupportingModule & operator= (const EventSupportingModule &other)=delete
 
 EventSupportingModule (EventSupportingModule &&other)=delete
 
EventSupportingModule & operator= (EventSupportingModule &&other)=delete
 
std::unique_ptr< EventController > EnableEvents (EventType type)
 Enables events of the given event type. More...
 
- Public Member Functions inherited from peak::core::Module
 Module ()=default
 
virtual ~Module ()=default
 
 Module (const Module &other)=delete
 
Module & operator= (const Module &other)=delete
 
 Module (Module &&other)=delete
 
Module & operator= (Module &&other)=delete
 
std::vector< std::shared_ptr< NodeMap > > NodeMaps () const
 Returns the module's node maps. More...
 
std::shared_ptr< class Port > Port () const
 Returns the module's port. More...
 

Static Public Attributes

static const uint64_t INFINITE_NUMBER = PEAK_INFINITE_NUMBER
 

Additional Inherited Members

Detailed Description

Represents a GenTL DataStream module.

This class allows to query information about a GenTL DataStream module and to manage and receive Buffers from the physical device.

The workflow for the buffers follows the GenTL model: First, memory needs to be allocated and announced to the API, so they are in the GenTL "Announced Buffer Pool". Then, the buffers are queued, so they are available in the GenTL "Input Buffer Pool". From this pool, buffers are chosen and filled by the device. Once a buffer is filled, i.e. a new frame is available, it is added to the GenTL "Output Buffer Queue" and a "NewBufferEvent" is sent. At this point, the newly filled buffer is available to the API.

Buffer management

There are two options for managing memory for the buffers:

  • Allocate the memory for the buffer yourself and announce it to the API yourself, using AnnounceBuffer(). Then you'll also need to free the memory for the buffer yourself, once you are done. To help with that, AnnounceBuffer() allows to add a callback, which is called when the buffer is revoked. At that point the memory won't be used anymore, and therefore can be deleted. If you don't add this callback, you'll have to manage the time of deletion yourself.
  • Let the API allocate and free the memory for the buffer, using AllocAndAnnounceBuffer(). Then, the memory will be freed automatically when the buffer is revoked.

After announcing the buffer, use QueueBuffer() to move it to the "Input Buffer Pool".

Once a Buffer is not needed anymore, revoke it using RevokeBuffer().

Use Flush() to move buffers between the Input Buffer Pool, the Output Buffer Queue and the Announced Buffer Pool.

Receiving new buffers

Once enough buffers are announced and queued, use StartAcquisition() to start generating new frames.

Note
Typically, the RemoteDevice also needs to be started using its NodeMap, e.g.:
remoteDevice->NodeMaps()[0]->FindNode<peak::core::nodes::CommandNode>("AcquisitionStart")->Execute();
remoteDevice->NodeMaps()[0]->FindNode<peak::core::nodes::CommandNode>("AcquisitionStart")->WaitUntilDone();

Once the acquisition is started, wait for the NewBufferEvent using WaitForFinishedBuffer(), which blocks until a newly filled buffer is available.

See GenTL Data Stream Module.

Member Typedef Documentation

◆ BufferRevocationCallback

using peak::core::DataStream::BufferRevocationCallback = std::function<void(void* buffer, void* userPtr)>

The type of buffer revocation callbacks.

Constructor & Destructor Documentation

◆ DataStream() [1/3]

peak::core::DataStream::DataStream ( )
delete

◆ ~DataStream()

peak::core::DataStream::~DataStream ( )
inlineoverride

◆ DataStream() [2/3]

peak::core::DataStream::DataStream ( const DataStream &  other)
delete

◆ DataStream() [3/3]

peak::core::DataStream::DataStream ( DataStream &&  other)
delete

Member Function Documentation

◆ AllocAndAnnounceBuffer()

std::shared_ptr< Buffer > peak::core::DataStream::AllocAndAnnounceBuffer ( size_t  size,
void *  userPtr 
)
inline

Allocates and announces a producer allocated buffer on the data stream.

Parameters
[in]sizeThe size of the buffer in bytes to allocate and announce.
[in]userPtrA pointer to user defined data, for identifying the buffer or attaching custom data to the buffer. It is optional (i.e. can be nullptr). See Buffer::UserPtr().
Returns
Buffer proxy
Since
1.0
Exceptions
BadAllocExceptionBad memory allocation
InternalErrorExceptionAn internal error has occurred.

◆ AnnounceBuffer()

std::shared_ptr< Buffer > peak::core::DataStream::AnnounceBuffer ( void *  buffer,
size_t  size,
void *  userPtr,
const BufferRevocationCallback &  revocationCallback 
)
inline

Announces a given client allocated buffer on the data stream.

Parameters
[in]bufferThe raw buffer to announce.
[in]sizeThe size in bytes of the raw buffer to announce.
[in]userPtrA pointer to user defined data, for identifying the buffer or attaching custom data to the buffer. Optional (i.e. can be nullptr). See Buffer::UserPtr().
[in]revocationCallbackCallback that is called when this buffer is revoked (via RevokeBuffer()). Use it to handle cleanup of the raw buffer, e.g.:
uint8_t* image_data = new uint8_t[payload_size];
(void)datastream->AnnounceBuffer(image_data, payload_size, nullptr,
[](void* buffer, void* userPtr)
{
delete[] static_cast<uint8_t*>(buffer);
});
Optional (i.e. can be nullptr), if you handle the memory management differently.
Returns
Buffer proxy
Since
1.0
Exceptions
InvalidArgumentExceptionOne of the submitted arguments is outside the valid range or is not supported.
InternalErrorExceptionAn internal error has occurred.

◆ AnnouncedBuffers()

std::vector< std::shared_ptr< Buffer > > peak::core::DataStream::AnnouncedBuffers ( ) const
inline

Returns the currently announced buffers.

Returns
List of currently announced buffers
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ BufferAlignment()

size_t peak::core::DataStream::BufferAlignment ( ) const
inline

Returns the buffer alignment.

Returns
Buffer alignment in bytes
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ DefinesPayloadSize()

bool peak::core::DataStream::DefinesPayloadSize ( ) const
inline

Checks whether the data stream defines the payload size.

Returns
True, if the DataStream defines the payload size.
False otherwise. In this case, ask the RemoteDevice for the payload size instead of the DataStream, e.g.:
payload_size =
device->RemoteDevice()->NodeMaps()[0]->FindNode<peak::core::nodes::IntegerNode>("PayloadSize")->Value();
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ Flush()

void peak::core::DataStream::Flush ( DataStreamFlushMode  mode)
inline

Move buffers between the Input Buffer Pool, the Output Buffer Queue and the Announced Buffer Pool, depending on the mode parameter.

Parameters
[in]modeOperation modes being used to flush the buffers of the data stream.
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ ID()

std::string peak::core::DataStream::ID ( ) const
inline

Returns the ID.

Returns
ID
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ Info()

RawInformation peak::core::DataStream::Info ( int32_t  infoCommand) const
inline

Delivers information based on the given GenTL info command.

Parameters
[in]infoCommandThe GenTL info command.

This function can be used to query information going beyond the predefined info functions, based on the GenTL info commands of the corresponding module.

Example (error handling is omitted):

auto info = object->Info(GenTL::XX_INFO_XX);
// Cast depending on the delivered data type
if (info.dataType == GenTL::INFO_DATATYPE_UINT64)
{
uint64_t uint64Var = *reinterpret_cast<const uint64_t*>(info.data.data());
// Do something with the information
}
else if (infoDataTypeVar == GenTL::INFO_DATATYPE_INT64)
{
...
}
...
Returns
Raw information according to the passed info command
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ IsGrabbing()

bool peak::core::DataStream::IsGrabbing ( ) const
inline

Checks whether the data stream is grabbing.

Returns
True, while the acquisition is running.
False, if the acquisition isn't started yet or was stopped.
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ Key()

std::string peak::core::DataStream::Key ( ) const
inline

Returns the unique key.

The returned key is unique even across different producer libraries.

Returns
Unique key
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ KillWait()

void peak::core::DataStream::KillWait ( )
inline

Kills one wait for a finished buffer or stores the kill request if there is no waiting thread.

Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ NumBuffersAnnounced()

size_t peak::core::DataStream::NumBuffersAnnounced ( ) const
inline

Returns the number of announced buffers.

Returns
Number of announced buffers
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ NumBuffersAnnouncedMinRequired()

size_t peak::core::DataStream::NumBuffersAnnouncedMinRequired ( ) const
inline

Returns the minimum number of announced buffers required to start the acquisition.

Returns
Minimum number of announced buffers required
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ NumBuffersAwaitDelivery()

size_t peak::core::DataStream::NumBuffersAwaitDelivery ( ) const
inline

Returns the number of buffers awaiting delivery.

Returns
Number of buffers awaiting delivery
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ NumBuffersDelivered()

uint64_t peak::core::DataStream::NumBuffersDelivered ( ) const
inline

Returns the number of delivered buffers.

Returns
Number of delivered buffers
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ NumBuffersQueued()

size_t peak::core::DataStream::NumBuffersQueued ( ) const
inline

Returns the number of queued buffers.

Returns
Number of queued buffers
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ NumBuffersStarted()

uint64_t peak::core::DataStream::NumBuffersStarted ( ) const
inline

Returns the number of started buffers.

Returns
Number of started buffers
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ NumChunksPerBufferMax()

size_t peak::core::DataStream::NumChunksPerBufferMax ( ) const
inline

Returns the maximum number of chunks per buffer.

Returns
Maximum number of chunks per buffer
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ NumUnderruns()

uint64_t peak::core::DataStream::NumUnderruns ( ) const
inline

Returns the number of underruns.

Returns
Number of underruns
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ operator=() [1/2]

DataStream& peak::core::DataStream::operator= ( const DataStream &  other)
delete

◆ operator=() [2/2]

DataStream& peak::core::DataStream::operator= ( DataStream &&  other)
delete

◆ ParentDevice()

std::shared_ptr< Device > peak::core::DataStream::ParentDevice ( ) const
inline

Returns the parent device.

Returns
Parent device
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ PayloadSize()

size_t peak::core::DataStream::PayloadSize ( ) const
inline

Returns the payload size in bytes, i.e. the size of the buffers.

Returns
Payload size in bytes
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ QueueBuffer()

void peak::core::DataStream::QueueBuffer ( const std::shared_ptr< Buffer > &  buffer)
inline

Queues a given buffer.

Parameters
[in]bufferThe buffer to queue.
Since
1.0
Exceptions
InvalidArgumentExceptionOne of the submitted arguments is outside the valid range or is not supported.
InternalErrorExceptionAn internal error has occurred.

◆ RevokeBuffer()

void peak::core::DataStream::RevokeBuffer ( const std::shared_ptr< Buffer > &  buffer)
inline

Revokes a given buffer.

This function revokes a given buffer. If the given buffer was allocated by the client side, the callback given during buffer announcement (AnnounceBuffer()) gets triggered.

Parameters
[in]bufferThe buffer to revoke.
Since
1.0
Exceptions
InvalidArgumentExceptionOne of the submitted arguments is outside the valid range or is not supported.
InternalErrorExceptionAn internal error has occurred.

◆ StartAcquisition()

void peak::core::DataStream::StartAcquisition ( AcquisitionStartMode  mode = AcquisitionStartMode::Default,
uint64_t  numToAcquire = INFINITE_NUMBER 
)
inline

Starts the acquisition.

Parameters
[in]modeThe mode being used to start the acquisition.
[in]numToAcquireThe number of buffers to acquire.
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ StopAcquisition()

void peak::core::DataStream::StopAcquisition ( AcquisitionStopMode  mode = AcquisitionStopMode::Default)
inline

Stops the acquisition.

Parameters
[in]modeThe mode being used to stop the acquisition.
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ TLType()

std::string peak::core::DataStream::TLType ( ) const
inline

Returns the TL (transport layer) type.

Returns
TL type
Since
1.0
Exceptions
InternalErrorExceptionAn internal error has occurred.

◆ WaitForFinishedBuffer()

std::shared_ptr< Buffer > peak::core::DataStream::WaitForFinishedBuffer ( Timeout  timeout_ms)
inline

Blocking wait for a finished Buffer.

Parameters
[in]timeout_msThe time to wait for a finished buffer in milliseconds.
Returns
Newly filled Buffer.
Since
1.0
Exceptions
AbortedExceptionThe wait was aborted
TimeoutExceptionThe function call timed out
InternalErrorExceptionAn internal error has occurred.

Member Data Documentation

◆ INFINITE_NUMBER

const uint64_t peak::core::DataStream::INFINITE_NUMBER = PEAK_INFINITE_NUMBER
static

The constant defining an infinite number, used in StartAcquisition().


The documentation for this class was generated from the following file: