Skip to main content

Post-processing tools 2023 R2

shared_memory_image_client_python.c File Reference

Last update: 17.04.2023

Python interface to the shared_memory_image_client.h API. More...

#include <Python.h>
#include "shared_memory_image_client_priv.h"

Go to the source code of this file.

Macros

#define MAX_STREAMS   50
 

Functions

stream_id stream_create (str filename, int options=IMAGESTREAM_OPTIONS_NONE)
 Create a shared memory image stream. More...
 
frame stream_lock (stream_id id)
 Get any available image frame. More...
 
SharedMemoryImageError stream_unlock (stream_id id)
 Unlock the frame allocated by stream_lock(). More...
 
SharedMemoryImageError stream_destroy (stream_id id)
 Close down and destroy a shared memory transport interface. More...
 
SharedMemoryImageError stream_putframe (stream_id id, int width, int height, int framenumber, bytes pixeldata)
 Push an image into the shared memory transport buffer. More...
 

Detailed Description

Python interface to the shared_memory_image_client.h API.

Author
Randy Frank (randy.nosp@m..fra.nosp@m.nk@an.nosp@m.sys..nosp@m.com)
Version
1.0

ensight_grpc_shmem python module

This module implements a set of Python bindings to the shared memory image transport API.

A simple example exercising the API might be:

import ensight_grpc_shmem
import time
def run_server(dx=1920, dy=1080, n=500):
s = ensight_grpc_shmem.stream_create("shmem.bin", ensight_grpc_shmem.IMAGESTREAM_OPTIONS_SERVER)
img = b'\0'*dx*dy*3
for i in range(n):
time.sleep(1./60.)
err = ensight_grpc_shmem.stream_putframe(s, dx, dy, i, img)
print("Frame: {} {}".format(i, err))
if i == 0:
time.sleep(5)
ensight_grpc_shmem.stream_destroy(s)
def run_client(num=200):
c = ensight_grpc_shmem.stream_create("shmem.bin")
count = 0
while True:
img = ensight_grpc_shmem.stream_lock(c)
if type(img) is dict:
print("Frame: {} {} {} {}".format(img['framenumber'], img['width'], img['height'],count))
ensight_grpc_shmem.stream_unlock(c)
count += 1
if count > num:
break
ensight_grpc_shmem.stream_destroy(c)

Definition in file shared_memory_image_client_python.c.

Macro Definition Documentation

◆ MAX_STREAMS

#define MAX_STREAMS   50

the maximum number of active streams we allow

Definition at line 30 of file shared_memory_image_client_python.c.

Function Documentation

◆ stream_create()

stream_id stream_create ( str  filename,
int  options = IMAGESTREAM_OPTIONS_NONE 
)

Create a shared memory image stream.

Python wrapper for SharedMemoryImageStream_create(). Function in the ensight_grpc_shmem python module Python module.

See also
SharedMemoryImageStream_create().
Parameters
filenamethe name of the shared memory file to use.
optionsthe stream creation options
Exceptions
IMAGESTREAM_BAD_ARGS
IMAGESTREAM_BAD_FILE_SIZE
IMAGESTREAM_UNABLE_TO_OPEN_FILE
IMAGESTREAM_UNABLE_TO_MAP_FILE
IMAGESTREAM_MEMORY_ALLOC_ERROR
IMAGESTREAM_THREAD_CREATE_ERROR
Returns
the allocated stream id.

◆ stream_destroy()

SharedMemoryImageError stream_destroy ( stream_id  id)

Close down and destroy a shared memory transport interface.

Python wrapper for SharedMemoryImageStream_destroy(). Function in the ensight_grpc_shmem python module Python module.

See also
SharedMemoryImageStream_destroy().
Parameters
idthe stream to be destroyed.
Exceptions
IMAGESTREAM_BAD_ARGS
Returns
IMAGESTREAM_NOERROR

◆ stream_lock()

frame stream_lock ( stream_id  id)

Get any available image frame.

Python wrapper for SharedMemoryImageStream_lock(). Function in the ensight_grpc_shmem python module Python module.

See also
SharedMemoryImageStream_lock().
Parameters
idthe stream to read from.
Exceptions
IMAGESTREAM_BAD_ARGS
IMAGESTREAM_IS_SERVER
IMAGESTREAM_LOCKED
Returns
SharedMemoryImageError if no images are read or a dictionary with the same fields as _SharedMemoryFrame.

◆ stream_putframe()

SharedMemoryImageError stream_putframe ( stream_id  id,
int  width,
int  height,
int  framenumber,
bytes  pixeldata 
)

Push an image into the shared memory transport buffer.

Python wrapper for SharedMemoryImageStream_putframe(). Only used by server connections. Function in the ensight_grpc_shmem python module Python module.

See also
SharedMemoryImageStream_putframe().
Parameters
idthe stream to write to.
widthwidth of the frame in pixels
heightheight of the frame in pixels
framenumberthe sequence number of this frame
pixeldataa bytes() object of at least width*height*3 bytes in size
Exceptions
IMAGESTREAM_BAD_ARGS
IMAGESTREAM_IS_NOTSERVER
IMAGESTREAM_FRAME_TOO_LARGE
Returns
SharedMemoryImageError IMAGESTREAM_UNCONNECTED, IMAGESTREAM_NO_BUFFERAVAILABLE, IMAGESTREAM_NOERROR

◆ stream_unlock()

SharedMemoryImageError stream_unlock ( stream_id  id)

Unlock the frame allocated by stream_lock().

Python wrapper for SharedMemoryImageStream_unlock(). Function in the ensight_grpc_shmem python module Python module.

See also
SharedMemoryImageStream_unlock().
Parameters
idthe stream to read from.
Exceptions
IMAGESTREAM_BAD_ARGS
IMAGESTREAM_IS_SERVER
IMAGESTREAM_NOT_LOCKED
Returns
SharedMemoryImageError if no images are read or a dictionary with the same fields as _SharedMemoryFrame.