Imaging Control 4 C++ Library 1.2.0
|
The snap sink is a sink implementation that allows a program to capture single images or sequences of images on demand, while still having a display showing all images. More...
Classes | |
struct | Config |
The SnapSink configuration structure. More... | |
struct | CustomAllocationStrategy |
Specifies a custom allocation strategy. More... | |
Public Types | |
enum class | AllocationStrategy { Default = ic4::c_interface::IC4_SNAPSINK_ALLOCATION_STRATEGY_DEFAULT , Custom = ic4::c_interface::IC4_SNAPSINK_ALLOCATION_STRATEGY_CUSTOM } |
The buffer allocation strategy defines how many buffers are pre-allocated, when additional buffers are created, and when excess buffers are reclaimed. More... | |
Public Types inherited from Sink | |
enum class | SinkMode { Run = c_interface::IC4_SINK_MODE_RUN , Pause = c_interface::IC4_SINK_MODE_PAUSE } |
Defines the possible sink modes. More... | |
Public Member Functions | |
ImageType | outputImageType (Error &err=Error::Default()) const |
Queries the image type of the images the sink is configured to receive. | |
std::shared_ptr< ImageBuffer > | snapSingle (std::chrono::milliseconds timeout, Error &err=Error::Default()) |
Grabs a single image out of the video stream received from the video capture device. | |
std::shared_ptr< ImageBuffer > | snapSingle (int64_t timeout_ms, Error &err=Error::Default()) |
Grabs a single image out of the video stream received from the video capture device. | |
std::vector< std::shared_ptr< ImageBuffer > > | snapSequence (size_t count, std::chrono::milliseconds timeout, Error &err=Error::Default()) |
Grabs a sequence of images out of the video stream received from the video capture device. | |
std::vector< std::shared_ptr< ImageBuffer > > | snapSequence (size_t count, int64_t timeout_ms, Error &err=Error::Default()) |
Grabs a sequence of images out of the video stream received from the video capture device. | |
SinkType | sinkType () const noexcept final |
Returns the type of this sink. | |
Public Member Functions inherited from Sink | |
bool | setSinkMode (SinkMode mode, Error &err=Error::Default()) noexcept |
Sets the sink mode for a sink. | |
SinkMode | sinkMode () const noexcept |
Gets the current sink mode of a sink. | |
bool | isAttached () const noexcept |
Checks whether a sink is currently attached to a Grabber as part of a data stream. | |
Static Public Member Functions | |
static std::shared_ptr< SnapSink > | create (Error &err=Error::Default()) |
Creates a SnapSink using the default configuration. | |
static std::shared_ptr< SnapSink > | create (const CustomAllocationStrategy &strategy, Error &err=Error::Default()) |
Creates a SnapSink using a customized buffer allocation strategy. | |
static std::shared_ptr< SnapSink > | create (const std::shared_ptr< BufferAllocator > &allocator, Error &err=Error::Default()) |
Creates a SnapSink using a custom buffer allocator. | |
static std::shared_ptr< SnapSink > | create (const std::vector< PixelFormat > &acceptedPixelFormats, Error &err=Error::Default()) |
Creates a SnapSink specifying a list of accepted image types. | |
static std::shared_ptr< SnapSink > | create (PixelFormat acceptedPixelFormat, Error &err=Error::Default()) |
Creates a SnapSink specifying an accepted image type. | |
static std::shared_ptr< SnapSink > | create (const Config &config, Error &err=Error::Default()) |
Creates a SnapSink using a configuration structure. | |
The snap sink is a sink implementation that allows a program to capture single images or sequences of images on demand, while still having a display showing all images.
To create a snap sink, call SnapSink::create().
To grab a single image out of the stream, call SnapSink::snapSingle(). To grab a sequence of images, call SnapSink::snapSequence().
The snap sink manages the buffers used for background image aquisition as well as for the grabbed images. During stream setup, a number of buffers is allocated depending on the configured allocation strategy. Additional buffers can be automatically created on demand, if the allocation strategy allows. Likewise, if there is a surplus of unused image buffers, unused buffers are reclaimed and released automatically.
Image buffers that were returned by one of the snap functions are owned by their respective caller through a std::shared_ptr
. Once all std::shared_ptr
pointers are reset, they are automatically returned to the snap sink for reuse.
Please note that if there are no buffers available in the sink when the device tries to deliver a frame, the frame will be dropped. Use Grabber::streamStatistics() to find out whether a buffer underrun occurred.
By default, the sink uses buffers provided by the device driver or the implicitly created transformation filter. It is possible to use program-defined buffers be used by providing a BufferAllocator to the sink creation function.
|
strong |
The buffer allocation strategy defines how many buffers are pre-allocated, when additional buffers are created, and when excess buffers are reclaimed.
Enumerator | |
---|---|
Default | Use the default strategy. This strategy pre-allocates an automatically selected number of buffers depending on the requirements of the data stream and the image size. The Config::customAllocationStrategy setting is ignored. |
Custom | Custom allocation strategy. The CustomAllocationStrategy::num_buffers_allocate_on_connect, CustomAllocationStrategy::num_buffers_allocation_threshold CustomAllocationStrategy::num_buffers_free_threshold and CustomAllocationStrategy::num_buffers_max parameters determine the sink's allocation behavior. |
|
inlinestatic |
Creates a SnapSink using a configuration structure.
This generic overload allows specifying a combination of configuration options like allocation strategy, buffer allocator and accepted frame types.
[in] | config | A configuration structure specifying sink behavior |
[out] | err | Reference to an error handler. See Error Handling for details. |
std::shared_ptr
to the new sink, or nullptr
if an error occurred.
|
inlinestatic |
Creates a SnapSink using a customized buffer allocation strategy.
[in] | strategy | A custom buffer allocation strategy |
[out] | err | Reference to an error handler. See Error Handling for details. |
std::shared_ptr
to the new sink, or nullptr
if an error occurred.
|
inlinestatic |
Creates a SnapSink using a custom buffer allocator.
[in] | allocator | A custom buffer allocator |
[out] | err | Reference to an error handler. See Error Handling for details. |
std::shared_ptr
to the new sink, or nullptr
if an error occurred.
|
inlinestatic |
Creates a SnapSink specifying a list of accepted image types.
[in] | acceptedPixelFormats | A std::vector containing the accepted pixel formats. |
[out] | err | Reference to an error handler. See Error Handling for details. |
std::shared_ptr
to the new sink, or nullptr
if an error occurred.
|
inlinestatic |
Creates a SnapSink using the default configuration.
[out] | err | Reference to an error handler. See Error Handling for details. |
std::shared_ptr
to the new sink, or nullptr
if an error occurred.
|
inlinestatic |
Creates a SnapSink specifying an accepted image type.
[in] | acceptedPixelFormat | The pixel format accepted by the sink. |
[out] | err | Reference to an error handler. See Error Handling for details. |
std::shared_ptr
to the new sink, or nullptr
if an error occurred.
|
inline |
Queries the image type of the images the sink is configured to receive.
[out] | err | Reference to an error handler. See Error Handling for details. |
|
inlinefinalvirtualnoexcept |
|
inline |
Grabs a sequence of images out of the video stream received from the video capture device.
This function waits until count images have been grabbed, or the timeout has expired. If the timeout expires, the function returns the number of images grabber and the error value is set to ErrorCode::Timeout.
count | Number of images to grab | |
timeout_ms | Time to wait for all images to arrive | |
[out] | err | Reference to an error handler. See Error Handling for details. |
std::vector
of std::shared_ptr
to image buffers.std::shared_ptr
s own the image buffers.
|
inline |
Grabs a sequence of images out of the video stream received from the video capture device.
This function waits until count images have been grabbed, or the timeout has expired. If the timeout expires, the function returns the number of images grabber and the error value is set to ErrorCode::Timeout.
count | Number of images to grab | |
timeout | Time to wait for all images to arrive | |
[out] | err | Reference to an error handler. See Error Handling for details. |
std::vector
of std::shared_ptr
to image buffers.std::shared_ptr
s own the image buffers.
|
inline |
Grabs a single image out of the video stream received from the video capture device.
timeout_ms | Time to wait for a new image to arrive | |
[out] | err | Reference to an error handler. See Error Handling for details. |
std::shared_ptr
to the filled image buffer, or nullptr
in case of an error.std::shared_ptr
owns the image buffer.
|
inline |
Grabs a single image out of the video stream received from the video capture device.
timeout | Time to wait for a new image to arrive | |
[out] | err | Reference to an error handler. See Error Handling for details. |
std::shared_ptr
to the filled image buffer, or nullptr
in case of an error.std::shared_ptr
owns the image buffer.