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...
Data Structures | |
struct | IC4_SNAPSINK_CONFIG |
Configures the behavior of a snap sink. More... | |
Enumerations | |
enum | IC4_SNAPSINK_ALLOCATION_STRATEGY { IC4_SNAPSINK_ALLOCATION_STRATEGY_DEFAULT = 0 , 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... | |
Functions | |
bool | ic4_snapsink_create (struct IC4_SINK **ppSink, const struct IC4_SNAPSINK_CONFIG *config) |
Creates a new Snap Sink. | |
bool | ic4_snapsink_get_output_image_type (const struct IC4_SINK *pSink, struct IC4_IMAGE_TYPE *image_type) |
Queries the image type of the images the sink is configured to receive. | |
bool | ic4_snapsink_snap_single (const struct IC4_SINK *pSink, struct IC4_IMAGE_BUFFER **ppImageBuffer, int64_t timeout_ms) |
Grabs a single image out of the video stream received from the video capture device. | |
size_t | ic4_snapsink_snap_sequence (const struct IC4_SINK *pSink, struct IC4_IMAGE_BUFFER **pImageBufferList, size_t count, int64_t timeout_ms) |
Grabs a sequence of images out of the video stream received from the video capture device. | |
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 ic4_snapsink_create().
To grab a single image out of the stream, call ic4_snapsink_snap_single(). To grab a sequence of images, call ic4_snapsink_snap_sequence().
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 until ic4_imagebuffer_unref() is called on them. Once the image buffer objects are released, 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 ic4_grabber_get_stream_stats() 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 setting allocator callback functions in IC4_SNAPSINK_CONFIG::allocator.
The buffer allocation strategy defines how many buffers are pre-allocated, when additional buffers are created, and when excess buffers are reclaimed.
Enumerator | |
---|---|
IC4_SNAPSINK_ALLOCATION_STRATEGY_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 custom strategy parameters in IC4_SNAPSINK_CONFIG setting are ignored. |
IC4_SNAPSINK_ALLOCATION_STRATEGY_CUSTOM | Custom allocation strategy. The IC4_SNAPSINK_CONFIG::num_buffers_alloc_on_connect, IC4_SNAPSINK_CONFIG::num_buffers_allocation_threshold IC4_SNAPSINK_CONFIG::num_buffers_free_threshold and IC4_SNAPSINK_CONFIG::num_buffers_max parameters determine the sink's allocation behavior. |
bool ic4_snapsink_create | ( | struct IC4_SINK ** | ppSink, |
const struct IC4_SNAPSINK_CONFIG * | config | ||
) |
Creates a new Snap Sink.
[in] | ppSink | Pointer to a sink handle to receive the new snap sink. |
[in] | config | Pointer to a structure containing the sink configuration. This parameter is optional; passing NULL will use the default configuration. |
true
on success, otherwise false
.The image type of the images the sink receives is determined when the data stream to the sink is created in a call to ic4_grabber_stream_setup() using the following steps:
0
, the device format is selected.bool ic4_snapsink_get_output_image_type | ( | const struct IC4_SINK * | pSink, |
struct IC4_IMAGE_TYPE * | image_type | ||
) |
Queries the image type of the images the sink is configured to receive.
[in] | pSink | A queue sink |
[out] | image_type | A structure receiving the image type information |
true
on success, otherwise false
.size_t ic4_snapsink_snap_sequence | ( | const struct IC4_SINK * | pSink, |
struct IC4_IMAGE_BUFFER ** | pImageBufferList, | ||
size_t | count, | ||
int64_t | timeout_ms | ||
) |
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 timeout_ms milliseconds have passed. If the timeout expires, the function returns the number of images grabber and the error value is set to IC4_ERROR_TIMEOUT.
[in] | pSink | A snap sink |
[out] | pImageBufferList | A pointer to an array of frame handles to receive the newly-filled images |
[in] | count | Number of images to grab |
[in] | timeout_ms | Time to wait for all images to arrive |
0
. Use ic4_get_last_error() to query error information.pImageBufferList
own the frame objects.bool ic4_snapsink_snap_single | ( | const struct IC4_SINK * | pSink, |
struct IC4_IMAGE_BUFFER ** | ppImageBuffer, | ||
int64_t | timeout_ms | ||
) |
Grabs a single image out of the video stream received from the video capture device.
This function waits until either the next buffer from the video capture device is received, or timeout_ms
milliseconds have passed. If the timeout expires, the function fails and the error value is set to IC4_ERROR_TIMEOUT.
[in] | pSink | A snap sink |
[out] | ppImageBuffer | A pointer to a frame handle to receive the newly-filled image |
[in] | timeout_ms | Time to wait for a new image to arrive |
true
on success, otherwise false
.ppImageBuffer
owns the frame object.