Skip to main content
C API for using the EnSight grpc shared memory image transport API. version
1.0
This library implements a shared memory (memory mapped file) image transport system. To use the system, the client needs to do the following:
  1. Create a physical file on disk that will serve as the memory mapped interface.
  2. Make sure the file is large enough to hold 2 frames of imagery at maximum size plus 2K. So if the largest image would be for a 4K display, the file needs to be at least 24M + 2K in size (4K3bytes/pixel2 frames).
  3. Make an EnSight grpc SubscribeImages() call with SubscribeImageOptions.type=GRPC and the name of the file created in the previous step passed with the “filename” key in SubscribeImageOptions.options. Note: that SubscribeImageOptions.prefix needs to be set to a unique string that will identify this channel. It is suggested that a GUID be used.
  4. The EnSight grpc server will initialize the shared memory communication block and register it with the ‘prefix’ passed in the SubscribeImages() call. If the shared memory system can be constructed, it returns success.
  5. On successful return from SubscribeImages(), the client then calls SharedMemoryImageStream_create() to connect to the server.
  1. Periodically, the client checks for a new image:
If a lock is successful, the frame will be valid and the shared memory system potentially blocked until unlock is called. Once unlock is called, the data returned in frame is no longer valid.
  1. When the communication is finished, the client should make the grpc Unsubscribe() call with the same prefix passed in (3) and then call:

Classes

Includes

  • <stdint.h>

Included by

Macros

Macro IMAGESTREAM_API_VERSION

The current API version

Macro IMAGESTREAM_UNCONNECTED

Not an error, but no client is listening to the stream

Macro IMAGESTREAM_RECONNECTING

The stream being connected to was already active, this may or may not be an error

Macro IMAGESTREAM_NO_FRAMEAVAILABLE

Not an error, but there was no frame available to read

Macro IMAGESTREAM_NO_BUFFERAVAILABLE

Not an error, but there were no free buffers to put the frame into

Macro IMAGESTREAM_NOERROR

Operation successful

Macro IMAGESTREAM_BAD_ARGS

one of the input parameters is invalid

Macro IMAGESTREAM_NOT_LOCKED

an attempt was made to unlock without it having been locked

Macro IMAGESTREAM_BAD_FILE_SIZE

the shared memory file is too small (<10MB) or non-existant

Macro IMAGESTREAM_UNABLE_TO_OPEN_FILE

the shared memory file could not be opened with necessary permissions

Macro IMAGESTREAM_UNABLE_TO_MAP_FILE

the shared memory file could not be memory mapped

Macro IMAGESTREAM_MEMORY_ALLOC_ERROR

insufficient system memory for internal object allocation

Macro IMAGESTREAM_THREAD_CREATE_ERROR

unable to create background processing threads

Macro IMAGESTREAM_IS_SERVER

the call is not valid for shared memory server to make

Macro IMAGESTREAM_IS_NOTSERVER

the call is not valid for shared memory client to make

Macro IMAGESTREAM_FRAME_TOO_LARGE

the image frame is too large for the size of the shared memory file

Macro IMAGESTREAM_LOCKED

this call is not legal until the stream has been unlocked

Macro IMAGESTREAM_OPTIONS_NONE

the default options for a client stream

Macro IMAGESTREAM_OPTIONS_FLIPVERTICAL

this is a server flag that requests that pixels be flipped vertically relative to the input buffer

Typedefs

Typedef SharedMemoryImageError

common error codes see the non-hex, non-string IMAGESTREAM macros Return type: int

Typedef SharedMemoryImageStream

image transport stream pointer Return type: struct _SharedMemoryImageStream *

Typedef SharedMemoryFrame

A reference to a frame of imagery. Note it does not own the buffer pointer. Structure representing a frame of imagery in sequence Return type: struct _SharedMemoryFrame *

Functions

Function SharedMemoryImageStream_create

SharedMemoryImageStream_create create a stream client instance. This function will map the file pointed to by filename as shared memory an use it to stream images between two applications. The file must (1) exist, (2) be at least 20MB in size and (3) be opened by a server stream before the client stream is created. Once created, the stream interface handle must be destroyed by SharedMemoryImageStream_destroy to release the stream resources. The file to be used as the shared memory map should be at least 2x the size of the largest image that will be used. For example if you want to transport 4K images, the file should be at least 4000pixels3bytes/pixel2 + 500bytes in size. The file must be on a filesystem that support memory mapped I/O. Negative error codes are a failure of the operation for various reasons. The IMAGESTREAM_RECONNECTING error code can occur if the file has been (or currently is) already supporting a stream and may or may not be an actual error. Note: server instances can be created using undocumented option flags. Parameters:
  • filename: - the name of a pre-existing file to use as the shared memory window
  • options: - stream creation options
  • stream: - if the returned error value is >=0, this pointer will be returned.
Returns: SharedMemoryImageError - the error code for this call. Parameters: Return type: SharedMemoryImageError

Function SharedMemoryImageStream_lock

SharedMemoryImageStream_lock get a frame of pixels from the server. This call should be made periodically by the client application to read images from the server. If the function returns IMAGESTREAM_NOERROR, then the frame argument contains the raw pixel data and the data pointer in that structure is valid until SharedMemoryImageStream_unlock() is called. If the function returns IMAGESTREAM_NO_FRAMEAVAILABLE, no new imagery is available from the server and SharedMemoryImageStream_unlock() does not need to be called. The frame structure is filled out by this call and the buffer field will be a pointer to the packed RGB image array in row major RBG order. The pointer will point to iWidthiHeight3 bytes of data. iFrame will be the frame number. The frame number will always increase, but there may be gaps in the numbering, depending on the render vs image read speeds. The buffer pointer must not be deallocated by the application. Parameters:
  • stream: - the stream to check for imagery
  • frame: - the currently available image (if any)
Returns: SharedMemoryImageError - the error code for the operation. Parameters: Return type: SharedMemoryImageError

Function SharedMemoryImageStream_unlock

SharedMemoryImageStream_unlock release a frame obtained by SharedMemoryImageStream_lock. If SharedMemoryImageStream_lock() was called and returned IMAGESTREAM_NOERROR, this function must be called to release the frame back to the stream manager. Note, after making this call, the calling application should no longer access any of the fields in the frame returned by the locking call. Parameters:
  • stream: - the stream to use
Returns: SharedMemoryImageError - error code for the operation Parameters: Return type: SharedMemoryImageError

Function SharedMemoryImageStream_destroy

SharedMemoryImageStream_destroy destroy a stream interface, releasing its resources. This function is called to shutdown one end of an image transport stream. It can be the client or server end of the stream. Parameters:
  • stream: - the stream to use
Returns: SharedMemoryImageError - error code for the operation Parameters: Return type: SharedMemoryImageError

Function SharedMemoryImageStream_errorstring

SharedMemoryImageStream_errorstring convert an error code into a human string. For a given SharedMemoryImageError error code, return a const char * pointer to a utf8 encoded string with a human readable description of the error. Parameters:
  • err: - the error code
Returns: const char * - The string describing the error (utf8 encoding) Parameters: Return type: const char *

Source