stream#

Module: stream.client#

FuryStreamClient(showm, *[, ...])

This obj is responsible to create a StreamClient.

FuryStreamInteraction(showm, *[, ...])

This obj.

callback_stream_client(stream_client)

This callback is used to update the image inside of the ImageManager instance

interaction_callback(circular_queue, showm, ...)

This callback is used to invoke vtk interaction events reading those events from the provided circular_queue instance

Module: stream.constants#

_CQUEUE_EVENT_IDs

CQUEUE_EVENT_IDS(mouse_weel, mouse_move, mouse_ids, left_btn_press, left_btn_release, middle_btn_press, middle_btn_release, right_btn_press, right_btn_release)

_CQUEUE_INDEX_INFO

CQUEUE_INDEX_INFO(weel, x, y, ctrl, shift, user_timestamp)

_CQUEUE

CQUEUE(dimension, event_ids, index_info)

Module: stream.server#

Module: stream.server.async_app#

pcs

set() -> new empty set object set(iterable) -> new set object

set_weel(data, circular_queue)

set_mouse(data, circular_queue)

set_mouse_click(data, circular_queue)

3 | LeftButtonPressEvent 4 | LeftButtonReleaseEvent 5 | MiddleButtonPressEvent 6 | MiddleButtonReleaseEvent 7 | RightButtonPressEvent 8 | RightButtonReleaseEvent

get_app(*[, rtc_server, folder, ...])

Module: stream.server.main#

RTCServer(image_buffer_manager)

This Obj it's responsible to create the VideoStream for the WebRTCServer

web_server_raw_array(*[, image_buffers, ...])

This will create a streaming webserver running on the given port and host using RawArrays.

web_server(*[, image_buffer_names, ...])

This will create a streaming webserver running on the given port and host using SharedMemory.

Module: stream.tools#

GenericMultiDimensionalBuffer(*[, max_size, ...])

This implements a abstract (generic) multidimensional buffer.

RawArrayMultiDimensionalBuffer(max_size, *)

This implements a multidimensional buffer with RawArray.

SharedMemMultiDimensionalBuffer(max_size, *)

This implements a generic multidimensional buffer with SharedMemory.

GenericCircularQueue(*[, max_size, ...])

This implements a generic circular queue which works with shared memory resources.

ArrayCircularQueue(*[, max_size, dimension, ...])

This implements a MultiDimensional Queue which works with Arrays and RawArrays.

SharedMemCircularQueue(*[, max_size, ...])

This implements a MultiDimensional Queue which works with SharedMemory.

GenericImageBufferManager(*[, ...])

This implements a abstract (generic) ImageBufferManager with the n-buffer technique.

RawArrayImageBufferManager(*[, ...])

This implements an ImageBufferManager using RawArrays.

SharedMemImageBufferManager(*[, ...])

This implements an ImageBufferManager using the SharedMemory approach.

IntervalTimerThreading(seconds, callback, ...)

Implements a object with the same behavior of setInterval from Js

IntervalTimer(seconds, callback, *args, **kwargs)

A object that creates a timer that calls a function periodically.

remove_shm_from_resource_tracker()

Monkey-patch multiprocessing.resource_tracker so SharedMemory won't be tracked

Module: stream.widget#

Widget(showm, *[, ms_stream, ...])

This Obj it's able execute the fury streaming system using the SharedMemory object from Python multiprocessing.

check_port_is_available(host, port)

Check if a given port it's available

FuryStreamClient#

class fury.stream.client.FuryStreamClient(showm, *, max_window_size=None, use_raw_array=True, whithout_iren_start=False, num_buffers=2)[source]#

Bases: object

This obj is responsible to create a StreamClient.

__init__(showm, *, max_window_size=None, use_raw_array=True, whithout_iren_start=False, num_buffers=2)[source]#

A StreamClient extracts a framebuffer from the OpenGL context and writes into a shared memory resource.

Parameters:
  • showm (ShowManager) –

  • max_window_size (tuple of ints, optional) – This allows resize events inside of the FURY window instance. Should be greater than the window size.

  • use_raw_array (bool, optional) – If False then FuryStreamClient will use SharedMemory instead of RawArrays. Notice that Python >=3.8 it’s a requirement to use SharedMemory)

  • whithout_iren_start (bool, optional) – Sometimes you can’t initiate the vtkInteractor instance.

  • num_buffers (int, optional) – Number of buffers to be used in the n-buffering technique.

cleanup()[source]#

Release the shared memory resources if necessary.

start(*, ms=0, use_asyncio=False)[source]#

Start the stream client.

Parameters:
  • ms (float, optional) – positive number. This update the image buffer using a interval of ms milliseconds. If ms is 0 then the stream client will update the buffer after every Render event.

  • use_asyncio (bool, optional) – If False then the stream client will update the image using a threading technique.

stop()[source]#

Stop the stream client.

FuryStreamInteraction#

class fury.stream.client.FuryStreamInteraction(showm, *, max_queue_size=50, use_raw_array=True, whithout_iren_start=False)[source]#

Bases: object

This obj. is responsible to manage the user interaction

__init__(showm, *, max_queue_size=50, use_raw_array=True, whithout_iren_start=False)[source]#

Initialize the StreamInteraction obj.

Parameters:
  • showm (ShowmManager) –

  • max_queue_size (int, optional) – maximum number of events to be stored.

  • use_raw_array (bool, optional) – If False then a CircularQueue will be created using SharedMemory instead of RawArrays. Notice that Python >=3.8 it’s requirement to use SharedMemory.

  • whithout_iren_start (bool, optional) – Set that to True if you can’t initiate the vtkInteractor instance.

cleanup()[source]#

Release the shared memory resources if necessary.

start(*, ms=3, use_asyncio=False)[source]#

Start the stream interaction client.

Parameters:
  • ms (float, optional) – positive number greater than zero.

  • use_asyncio (bool, optional) – If False then the interaction will be performed in a separate thread.

stop()[source]#

Stop the stream interaction client.

callback_stream_client#

fury.stream.client.callback_stream_client(stream_client)[source]#

This callback is used to update the image inside of the ImageManager instance

Parameters:

stream_client (StreamClient) –

interaction_callback#

fury.stream.client.interaction_callback(circular_queue, showm, iren, render_after)[source]#

This callback is used to invoke vtk interaction events reading those events from the provided circular_queue instance

Parameters:
  • circular_queue (CircularQueue) –

  • showm (ShowmManager) –

  • iren (vtkInteractor) –

  • render_after (bool, optional) – If the render method should be called after an dequeue

_CQUEUE_EVENT_IDs#

fury.stream.constants._CQUEUE_EVENT_IDs()#

CQUEUE_EVENT_IDS(mouse_weel, mouse_move, mouse_ids, left_btn_press, left_btn_release, middle_btn_press, middle_btn_release, right_btn_press, right_btn_release)

_CQUEUE_INDEX_INFO#

fury.stream.constants._CQUEUE_INDEX_INFO()#

CQUEUE_INDEX_INFO(weel, x, y, ctrl, shift, user_timestamp)

_CQUEUE#

fury.stream.constants._CQUEUE()#

CQUEUE(dimension, event_ids, index_info)

pcs#

fury.stream.server.async_app.pcs()#

set() -> new empty set object set(iterable) -> new set object

Build an unordered collection of unique elements.

set_weel#

fury.stream.server.async_app.set_weel(data, circular_queue)[source]#

set_mouse#

fury.stream.server.async_app.set_mouse(data, circular_queue)[source]#

set_mouse_click#

fury.stream.server.async_app.set_mouse_click(data, circular_queue)[source]#

3 | LeftButtonPressEvent 4 | LeftButtonReleaseEvent 5 | MiddleButtonPressEvent 6 | MiddleButtonReleaseEvent 7 | RightButtonPressEvent 8 | RightButtonReleaseEvent

get_app#

fury.stream.server.async_app.get_app(*, rtc_server=None, folder=None, circular_queue=None, image_buffer_manager=None, provides_mjpeg=False, broadcast=True)[source]#

RTCServer#

class fury.stream.server.main.RTCServer(image_buffer_manager)[source]#

Bases: object

This Obj it’s responsible to create the VideoStream for the WebRTCServer

__init__(image_buffer_manager)[source]#

Initialize the RTCServer

Parameters:

image_buffer_manager (ImageBufferManager) –

async recv()[source]#

Return a VideoFrame to be used in the WebRTC Server

The frame will be created using the image stored in the shared memory

Returns:

frame

Return type:

VideoFrame

release()[source]#

Release the RTCServer

web_server_raw_array#

fury.stream.server.main.web_server_raw_array(*, image_buffers=None, info_buffer=None, queue_head_tail_buffer=None, queue_buffer=None, port=8000, host='localhost', provides_mjpeg=True, provides_webrtc=True, ms_jpeg=16, run_app=True)[source]#

This will create a streaming webserver running on the given port and host using RawArrays.

Parameters:
  • image_buffers (list of buffers) – A list of buffers with each one containing a frame.

  • info_buffer (buffer) – A buffer with the information about the current frame to be streamed and the respective sizes

  • queue_head_tail_buffer (buffer) – If buffer is passed than this Obj will read a a already created RawArray.

  • queue_buffer (buffer) – If queue_buffer is passed than this Obj will read a a already created RawArray containing the user interactions events stored in the queue_buffer.

  • port (int, optional) – Port to be used by the aiohttp server

  • host (str, optional, default localhost) – host to be used by the aiohttp server

  • provides_mjpeg (bool, default True) – If a MJPEG streaming should be available. If True you can consume that through host:port/video/mjpeg or if you want to interact you can consume that through your browser http://host:port?encoding=mjpeg

  • provides_webrtc (bool, default True) – If a WebRTC streaming should be available. http://host:port

  • ms_jpeg (float, optional) – This it’s used only if the MJPEG will be used. The ms_jpeg represents the amount of milliseconds between to consecutive calls of the jpeg encoding.

  • run_app (bool, default True) – This will run the aiohttp application. The False condition is used just to be able to test the server.

web_server#

fury.stream.server.main.web_server(*, image_buffer_names=None, info_buffer_name=None, queue_head_tail_buffer_name=None, queue_buffer_name=None, port=8000, host='localhost', provides_mjpeg=True, provides_webrtc=True, avoid_unlink_shared_mem=True, ms_jpeg=16, run_app=True)[source]#

This will create a streaming webserver running on the given port and host using SharedMemory.

Parameters:
  • image_buffers_name (list of str) – A list of buffers with each one containing a frame.

  • info_buffer_name (str) – A buffer with the information about the current frame to be streamed and the respective sizes

  • queue_head_tail_buffer_name (str, optional) – If buffer is passed than this Obj will read a a already created RawArray.

  • buffer_name (str, optional) – If queue_buffer is passed than this Obj will read a a already created RawArray containing the user interactions events stored in the queue_buffer.

  • port (int, optional) – Port to be used by the aiohttp server

  • host (str, optional, default localhost) – host to be used by the aiohttp server

  • provides_mjpeg (bool, default True) – If a MJPEG streaming should be available. If True you can consume that through host:port/video/mjpeg or if you want to interact you can consume that through your browser http://host:port?encoding=mjpeg

  • provides_webrtc (bool, default True) – If a WebRTC streaming should be available. http://host:port

  • avoid_unlink_shared_mem (bool, default False) – If True, then this will apply a monkey-patch solution to a python>=3.8 core bug

  • ms_jpeg (float, optional) – This it’s used only if the MJPEG will be used. The ms_jpeg represents the amount of milliseconds between to consecutive calls of the jpeg encoding.

  • run_app (bool, default True) – This will run the aiohttp application. The False condition is used just to be able to test the server.

GenericMultiDimensionalBuffer#

class fury.stream.tools.GenericMultiDimensionalBuffer(*, max_size=None, dimension=8)[source]#

Bases: ABC

This implements a abstract (generic) multidimensional buffer.

__init__(*, max_size=None, dimension=8)[source]#

Initialize the multidimensional buffer.

Parameters:
  • max_size (int, optional) – If buffer_name or buffer was not passed then max_size it’s mandatory

  • dimension (int, default 8) –

property buffer#
abstract cleanup()[source]#
abstract create_mem_resource()[source]#
get_start_end(idx)[source]#
abstract load_mem_resource()[source]#

RawArrayMultiDimensionalBuffer#

class fury.stream.tools.RawArrayMultiDimensionalBuffer(max_size, *, dimension=4, buffer=None)[source]#

Bases: GenericMultiDimensionalBuffer

This implements a multidimensional buffer with RawArray.

__init__(max_size, *, dimension=4, buffer=None)[source]#

Stream system uses that to implement the CircularQueue with shared memory resources.

Parameters:
  • max_size (int, optional) – If buffer_name or buffer was not passed then max_size it’s mandatory

  • dimension (int, default 8) –

  • buffer (buffer, optional) – If buffer is not passed to __init__ then the multidimensional buffer obj will create a new RawArray object to store the data If buffer is passed than this Obj will read a a already created RawArray

cleanup()[source]#
create_mem_resource()[source]#
load_mem_resource()[source]#

SharedMemMultiDimensionalBuffer#

class fury.stream.tools.SharedMemMultiDimensionalBuffer(max_size, *, dimension=4, buffer_name=None)[source]#

Bases: GenericMultiDimensionalBuffer

This implements a generic multidimensional buffer with SharedMemory.

__init__(max_size, *, dimension=4, buffer_name=None)[source]#

Stream system uses that to implement the CircularQueue with shared memory resources.

Parameters:
  • max_size (int, optional) – If buffer_name or buffer was not passed then max_size it’s mandatory

  • dimension (int, default 8) –

  • buffer_name (str, optional) – if buffer_name is passed than this Obj will read a a already created SharedMemory

cleanup()[source]#
create_mem_resource()[source]#
load_mem_resource()[source]#

GenericCircularQueue#

class fury.stream.tools.GenericCircularQueue(*, max_size=None, dimension=8, use_shared_mem=False, buffer=None, buffer_name=None)[source]#

Bases: ABC

This implements a generic circular queue which works with shared memory resources.

__init__(*, max_size=None, dimension=8, use_shared_mem=False, buffer=None, buffer_name=None)[source]#

Initialize the circular queue.

Parameters:
  • max_size (int, optional) – If buffer_name or buffer was not passed then max_size it’s mandatory. This will be used to construct the multidimensional buffer

  • dimension (int, default 8) – This will be used to construct the multidimensional buffer

  • use_shared_mem (bool, default False) – If the multidimensional memory resource should create or read using SharedMemory or RawArrays

  • buffer (RawArray, optional) –

  • buffer_name (str, optional) –

abstract cleanup()[source]#
abstract create_mem_resource()[source]#
abstract dequeue()[source]#
abstract enqueue(data)[source]#
property head#
abstract load_mem_resource()[source]#
set_head_tail(head, tail, lock=1)[source]#
property tail#

ArrayCircularQueue#

class fury.stream.tools.ArrayCircularQueue(*, max_size=10, dimension=6, head_tail_buffer=None, buffer=None)[source]#

Bases: GenericCircularQueue

This implements a MultiDimensional Queue which works with Arrays and RawArrays.

__init__(*, max_size=10, dimension=6, head_tail_buffer=None, buffer=None)[source]#

Stream system uses that to implement user interactions

Parameters:
  • max_size (int, optional) – If buffer_name or buffer was not passed then max_size it’s mandatory. This will be used to construct the multidimensional buffer

  • dimension (int, default 8) – This will be used to construct the multidimensional buffer

  • head_tail_buffer (buffer, optional) – If buffer is not passed to __init__ then this obj will create a new RawArray to store head and tail position.

  • buffer (buffer, optional) – If buffer is not passed to __init__ then the multidimensional buffer obj will create a new RawArray to store the data

cleanup()[source]#
create_mem_resource()[source]#
dequeue()[source]#
enqueue(data)[source]#
load_mem_resource()[source]#

SharedMemCircularQueue#

class fury.stream.tools.SharedMemCircularQueue(*, max_size=10, dimension=6, head_tail_buffer_name=None, buffer_name=None)[source]#

Bases: GenericCircularQueue

This implements a MultiDimensional Queue which works with SharedMemory.

__init__(*, max_size=10, dimension=6, head_tail_buffer_name=None, buffer_name=None)[source]#

Stream system uses that to implement user interactions

Parameters:
  • max_size (int, optional) – If buffer_name or buffer was not passed then max_size it’s mandatory. This will be used to construct the multidimensional buffer

  • dimension (int, default 8) – This will be used to construct the multidimensional buffer

  • head_tail_buffer_name (str, optional) – if buffer_name is passed than this Obj will read a a already created SharedMemory with the head and tail information

  • buffer_name (str, optional) – if buffer_name is passed than this Obj will read a a already created SharedMemory to create the MultiDimensionalBuffer

cleanup()[source]#
create_mem_resource()[source]#
dequeue()[source]#
enqueue(data)[source]#
is_unlocked()[source]#
load_mem_resource()[source]#
lock()[source]#
unlock()[source]#

GenericImageBufferManager#

class fury.stream.tools.GenericImageBufferManager(*, max_window_size=None, num_buffers=2, use_shared_mem=False)[source]#

Bases: ABC

This implements a abstract (generic) ImageBufferManager with the n-buffer technique.

__init__(*, max_window_size=None, num_buffers=2, use_shared_mem=False)[source]#

Initialize the ImageBufferManager.

Parameters:
  • max_window_size (tuple of ints, optional) – This allows resize events inside of the FURY window instance. Should be greater than the window size.

  • num_buffers (int, optional) – Number of buffers to be used in the n-buffering technique.

  • use_shared_mem (bool, default False) –

async_get_jpeg(*, ms=33)[source]#
property buffer_index#
abstract cleanup()[source]#
abstract create_mem_resource()[source]#
get_current_frame()[source]#

Get the current frame from the buffer.

get_jpeg()[source]#

Returns a jpeg image from the buffer.

Returns:

bytes

Return type:

jpeg image.

abstract load_mem_resource()[source]#
property next_buffer_index#
write_into(w, h, np_arr)[source]#

RawArrayImageBufferManager#

class fury.stream.tools.RawArrayImageBufferManager(*, max_window_size=(100, 100), num_buffers=2, image_buffers=None, info_buffer=None)[source]#

Bases: GenericImageBufferManager

This implements an ImageBufferManager using RawArrays.

__init__(*, max_window_size=(100, 100), num_buffers=2, image_buffers=None, info_buffer=None)[source]#

Initialize the ImageBufferManager.

Parameters:
  • max_window_size (tuple of ints, optional) – This allows resize events inside of the FURY window instance. Should be greater than the window size.

  • num_buffers (int, optional) – Number of buffers to be used in the n-buffering technique.

  • info_buffer (buffer, optional) – A buffer with the information about the current frame to be streamed and the respective sizes

  • image_buffers (list of buffers, optional) – A list of buffers with each one containing a frame.

cleanup()[source]#
create_mem_resource()[source]#
load_mem_resource()[source]#

SharedMemImageBufferManager#

class fury.stream.tools.SharedMemImageBufferManager(*, max_window_size=(100, 100), num_buffers=2, image_buffer_names=None, info_buffer_name=None)[source]#

Bases: GenericImageBufferManager

This implements an ImageBufferManager using the SharedMemory approach.

__init__(*, max_window_size=(100, 100), num_buffers=2, image_buffer_names=None, info_buffer_name=None)[source]#

Initialize the ImageBufferManager.

Parameters:
  • max_window_size (tuple of ints, optional) – This allows resize events inside of the FURY window instance. Should be greater than the window size.

  • num_buffers (int, optional) – Number of buffers to be used in the n-buffering technique.

  • info_buffer_name (str) – The name of a buffer with the information about the current frame to be streamed and the respective sizes

  • image_buffer_names (list of str, optional) – a list of buffer names. Each buffer contains a frame

Notes

Python >=3.8 is a requirement to use this object.

cleanup()[source]#

Release the resources used by the Shared Memory Manager

create_mem_resource()[source]#
load_mem_resource()[source]#

IntervalTimerThreading#

class fury.stream.tools.IntervalTimerThreading(seconds, callback, *args, **kwargs)[source]#

Bases: object

Implements a object with the same behavior of setInterval from Js

__init__(seconds, callback, *args, **kwargs)[source]#
Parameters:
  • seconds (float) – A positive float number. Represents the total amount of seconds between each call

  • callback (function) – The function to be called

  • *args (args) – args to be passed to callback

  • **kwargs (kwargs) – kwargs to be passed to callback

Examples

def callback(arr):
    arr += [len(arr)]
arr = []
interval_timer = tools.IntervalTimer(1, callback, arr)
interval_timer.start()
time.sleep(5)
interval_timer.stop()
# len(arr) == 5

References

[1] https://stackoverflow.com/questions/3393612/run-certain-code-every-n-seconds

start()[source]#

Start the timer

stop()[source]#

Stop the timer

IntervalTimer#

class fury.stream.tools.IntervalTimer(seconds, callback, *args, **kwargs)[source]#

Bases: object

A object that creates a timer that calls a function periodically.

__init__(seconds, callback, *args, **kwargs)[source]#
Parameters:
  • seconds (float) – A positive float number. Represents the total amount of seconds between each call

  • callback (function) – The function to be called

  • *args (args) – args to be passed to callback

  • **kwargs (kwargs) – kwargs to be passed to callback

start()[source]#

Start the timer

stop()[source]#

Stop the timer

remove_shm_from_resource_tracker#

fury.stream.tools.remove_shm_from_resource_tracker()[source]#

Monkey-patch multiprocessing.resource_tracker so SharedMemory won’t be tracked

Notes

More details at: https://bugs.python.org/issue38119

Widget#

class fury.stream.widget.Widget(showm, *, ms_stream=33, ms_interaction=33, host='localhost', port=None, encoding='mjpeg', ms_jpeg=33, queue_size=20)[source]#

Bases: object

This Obj it’s able execute the fury streaming system using the SharedMemory object from Python multiprocessing.

__init__(showm, *, ms_stream=33, ms_interaction=33, host='localhost', port=None, encoding='mjpeg', ms_jpeg=33, queue_size=20)[source]#

Initialize the widget.

Parameters:
  • showm (ShowmManager) –

  • ms_stream (float, optional) – time in mileseconds between each frame buffer update.

  • ms_interaction (float, optional) – time in mileseconds between each user interaction update.

  • host (str, optional) –

  • port (int, optional) –

  • encoding (str, optional) – If should use MJPEG streaming or WebRTC.

  • ms_jpeg (float, optional) – This it’s used only if the MJPEG will be used. The ms_jpeg represents the amount of milliseconds between to consecutive calls of the jpeg encoding.

  • queue_size (int, optional) – maximum number of user interactions to be stored

cleanup()[source]#

Release the shared memory

property command_string#

Return the command string to start the server

Returns:

command_string

Return type:

str

display(*, height=150)[source]#

Start the server and display the url in an iframe

return_iframe(*, height=200)[source]#

Return the jupyter div iframe used to show the stream

run_command()[source]#

Evaluate the command string to start the server

start(*, use_asyncio=False)[source]#

Start the fury client and the interaction client and return the url

Parameters:

use_asyncio (bool, optional) – If should use the asyncio version of the server. Default is False.

stop()[source]#

Stop the streaming server and release the shared memory

property url#

Return the url to access the server

check_port_is_available#

fury.stream.widget.check_port_is_available(host, port)[source]#

Check if a given port it’s available

Parameters:
  • host (str) –

  • port (int) –

Returns:

available

Return type:

bool