Skip to main content

Post-processing tools 2023 R2

shared_memory_image_client_priv.h File Reference

Last update: 17.04.2023

C API the shared memory image transport API server interface. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "shared_memory_image_client.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <pthread.h>
#include <unistd.h>

Go to the source code of this file.

Macros

#define IMAGESTREAM_OPTIONS_INITBUFFERHEADERS   0x00000001
 
#define IMAGESTREAM_OPTIONS_NOTHREADS   0x00000002
 
#define IMAGESTREAM_OPTIONS_SERVER   IMAGESTREAM_OPTIONS_INITBUFFERHEADERS|IMAGESTREAM_OPTIONS_NOTHREADS
 

Functions

DEV SharedMemoryImageError SharedMemoryImageStream_putframe (SharedMemoryImageStream stream, SharedMemoryFrame frame)
 SharedMemoryImageStream_putframe push a new image into a server image stream channel. More...
 

Detailed Description

C API the shared memory image transport API server interface.

Version
1.0

This file describes the internal format of the shared memory system and the inner workings of the buffer state machine. It also provides the interface to a shared memory image server.

When creating a shared memory transport server, the shared_memory_image_client.h interface is used to create/destroy a stream, albeit with unique option flags. The server does not use the SharedMemoryImageStream_lock() / SharedMemoryImageStream_unlock() functions. Instead, it calls SharedMemoryImageStream_putframe() whenever it has new imagery it wants to push to the client.

Server operations are as follows:

  1. The client creates/sizes the shared memory file that is to be used and passes the filename to the server.
  2. The server creates/initializes the shared memory stream by calling SharedMemoryImageStream_create() with the IMAGESTREAM_OPTIONS_SERVER option.
    err = SharedMemoryImageStream_create("shared_memory_file",
    if (err < IMAGESTREAM_NOERROR) <handle error>
    SharedMemoryImageError SharedMemoryImageStream_create(const char *filename, uint32_t options, SharedMemoryImageStream *stream)
    SharedMemoryImageStream_create create a stream client instance.
    int SharedMemoryImageError
    common error codes see the non-hex, non-string IMAGESTREAM macros
    struct _SharedMemoryImageStream * SharedMemoryImageStream
    image transport stream pointer
    #define IMAGESTREAM_NOERROR
    #define IMAGESTREAM_OPTIONS_SERVER
  3. Periodically, the server may push a new image:
    struct _SharedMemoryFrame frame;
    frame.iFrame = 10;
    frame.iWidth = 640;
    frame.iHeight = 480;
    frame.buffer = <some application buffer at least 648x480x3 bytes in size>;
    err = SharedMemoryImageStream_lock(stream, &frame));
    SharedMemoryImageError SharedMemoryImageStream_lock(SharedMemoryImageStream stream, SharedMemoryFrame *frame)
    SharedMemoryImageStream_lock get a frame of pixels from the server.
    uint32_t iFrame
    monotonically increasing frame number
    uint8_t * buffer
    pointer to a packed RGBRGBRGB... (iWidth*iHeight*3) bytes array of pixels

    The data passed via buffer is copied into the shared memory space. Note, in some conditions, this function does not return a fatal error (<0), instead the error code return can report that no client has made a connection or that the frame was dropped because the client has not been responding to the frames being pushed fast enough.
  4. When the communication is finished, the server should call:
    SharedMemoryImageError SharedMemoryImageStream_destroy(SharedMemoryImageStream stream)
    SharedMemoryImageStream_destroy destroy a stream interface, releasing its resources.

Definition in file shared_memory_image_client_priv.h.

Macro Definition Documentation

◆ IMAGESTREAM_OPTIONS_INITBUFFERHEADERS

#define IMAGESTREAM_OPTIONS_INITBUFFERHEADERS   0x00000001

set if the create call should initialize the buffer state

Definition at line 132 of file shared_memory_image_client_priv.h.

◆ IMAGESTREAM_OPTIONS_NOTHREADS

#define IMAGESTREAM_OPTIONS_NOTHREADS   0x00000002

if set, the mutex and monitoring thread will not be created

Definition at line 133 of file shared_memory_image_client_priv.h.

◆ IMAGESTREAM_OPTIONS_SERVER

these options should be set for server streams

Definition at line 135 of file shared_memory_image_client_priv.h.

Function Documentation

◆ SharedMemoryImageStream_putframe()

DEV SharedMemoryImageError SharedMemoryImageStream_putframe ( SharedMemoryImageStream  stream,
SharedMemoryFrame  frame 
)

SharedMemoryImageStream_putframe push a new image into a server image stream channel.

This function can only be called on a shared memory image stream created in server mode (options = IMAGESTREAM_OPTIONS_SERVER). The caller should create a frame structure with the frame number, the image size in pixels and a pointer to the image data (row major, tightly packed, RGB byte ordering). This call will copy the data pointed to by the buffer field, so the frame structure can be discarded after this call.

Return codes: These are not technically errors, but they do provide some feedback on the current disposition of the image transport stream.

IMAGESTREAM_UNCONNECTED - no client has connected to this stream yet. IMAGESTREAM_NO_BUFFERAVAILABLE - the frame has not been queued because the client has not yet read previous frames. IMAGESTREAM_NOERROR - the image frame has been queued up to be read by the client.

Parameters
[in]stream- the stream to push the image into
[in]frame- the image to push into the stream
Returns
SharedMemoryImageError - the return code for the operation