gbvision.utils.net package

Submodules

gbvision.utils.net.async_fragmented_udp_stream_receiver module

class gbvision.utils.net.async_fragmented_udp_stream_receiver.AsyncFragmentedUDPStreamReceiver(port, *args, **kwargs)[source]

Bases: gbvision.utils.net.async_stream_receiver.AsyncStreamReceiver, gbvision.utils.net.fragmented_udp_stream_receiver.FragmentedUDPStreamReceiver

gbvision.utils.net.async_stream_receiver module

class gbvision.utils.net.async_stream_receiver.AsyncStreamReceiver(*args, **kwargs)[source]

Bases: gbvision.utils.async_readable.AsyncReadable, gbvision.utils.net.stream_receiver.StreamReceiver, abc.ABC

An abstract async tcp stream receiver that receives frames on another thread None! when inheriting from this class and another StreamReceiver class, make sure you call the other class’ constructor before this class’ constructor, but also make sure you inherit from this class first in order

gbvision.utils.net.async_tcp_stream_receiver module

class gbvision.utils.net.async_tcp_stream_receiver.AsyncTCPStreamReceiver(ip, port, *args, **kwargs)[source]

Bases: gbvision.utils.net.async_stream_receiver.AsyncStreamReceiver, gbvision.utils.net.tcp_stream_receiver.TCPStreamReceiver

gbvision.utils.net.async_udp_stream_receiver module

class gbvision.utils.net.async_udp_stream_receiver.AsyncUDPStreamReceiver(port, *args, **kwargs)[source]

Bases: gbvision.utils.net.async_stream_receiver.AsyncStreamReceiver, gbvision.utils.net.udp_stream_receiver.UDPStreamReceiver

gbvision.utils.net.fragmented_udp_stream_broadcaster module

class gbvision.utils.net.fragmented_udp_stream_broadcaster.FragmentedUDPStreamBroadcaster(*args, mtu: Union[int, float] = 65499, **kwargs)[source]

Bases: gbvision.utils.net.udp_stream_broadcaster.UDPStreamBroadcaster

A UDP broadcaster that can fragment big frames and send them in chunks, thus allowing it to bypass the size limit of the UDP broadcaster

Parameters:mtu – The maximum size of a single fragment (without the fragment headers)
HEADER_SIZE = 8

gbvision.utils.net.fragmented_udp_stream_receiver module

class gbvision.utils.net.fragmented_udp_stream_receiver.FragmentedUDPStreamReceiver(*args, max_wait: Union[int, float, None] = 1, **kwargs)[source]

Bases: gbvision.utils.net.udp_stream_receiver.UDPStreamReceiver

A UDP receiver that can de-fragment packets sent from the fragmented UDP broadcaster, and rebuild large frames from several chunks

Parameters:max_wait – The maximum time in seconds the receiver will wait for chunks of a frame to arrive from

the moment it received the first chunk, if this time passed and not all fragments have arrived, the receiver will stop handling the current frame and move on the the next frame that will arrive can be None to not set a wait limit (same as infinity) If this value is too large, a single frame might block the entire receiver if not all fragments arrive If this value is too small, a frame might be dropped just because this time passed before all fragments could arrive

gbvision.utils.net.stream_broadcaster module

class gbvision.utils.net.stream_broadcaster.StreamBroadcaster(shape: Optional[Tuple[int, int]] = None, fx: Optional[float] = None, fy: Optional[float] = None, use_grayscale: bool = False, max_fps: int = None, im_encode='.jpg', max_bitrate: int = None)[source]

Bases: gbvision.utils.releasable.Releasable, abc.ABC

An abstract broadcaster that sends stream to a stream receiver

Parameters:
  • shape – Optional, the shape (x, y) of the sent frame, when set to something other then (0, 0) it overrides the fx and fy parameters, when set to (0, 0) it is not used
  • fx – Ratio between width of the given frame to the width of the frame sent, default is 1 (same width)
  • fy – ratio between height of the given frame to the height of the frame sent, default is 1 (same height)
  • use_grayscale – boolean indicating if the frame should be converted to grayscale when sent, default is False
  • max_fps – integer representing the maximum fps (frames per second) of the stream, when set to None there is no fps limitation, default is None
  • max_bitrate – Integer that determines the max bitrate of video stream. The bitrate is messured with Kbps and default is None.
send_frame(frame: Optional[numpy.ndarray]) → None[source]

safely sends the frame, doing all the pre-processing required :param frame: :return:

gbvision.utils.net.stream_receiver module

class gbvision.utils.net.stream_receiver.StreamReceiver(shape: Optional[Tuple[int, int]] = None, fx: Optional[float] = None, fy: Optional[float] = None, convert_from_grayscale: bool = True)[source]

Bases: gbvision.utils.readable.Readable, abc.ABC

this is an abstract receiver that receives stream from a broadcast receiver this class should not be instanced but inherited from

Parameters:
  • shape – Optional. The shape (x, y) of the sent frame (None to use the given frame’s shape)
  • fx – Optional, The ratio between width of the read frame to the width of the frame returned (None for 1)
  • fy – ratio between height of the read frame to the height of the frame returned (None for 1)
  • convert_from_grayscale – Should this receiver convert grayscale images to BGR images (default True)
get_height() → int[source]
Returns:The height of the frames read by this readable
get_width() → int[source]
Returns:The width of the frames read by this readable
read()[source]

Reads from the readable and returns the result

Returns:False, None if the operation was unsuccessful, else True, frame_result
set_height(height: int) → None[source]
set_width(width: int) → None[source]

gbvision.utils.net.tcp_stream_broadcaster module

class gbvision.utils.net.tcp_stream_broadcaster.TCPStreamBroadcaster(port: int, *args, **kwargs)[source]

Bases: gbvision.utils.net.stream_broadcaster.StreamBroadcaster

This class uses TCP to send a stream over the network, the stream is by default set to be MJPEG the broadcaster is the server and the receiver is the client

Parameters:port – The TCP port to use
is_opened() → bool[source]

Checks if this releasable is open and can be read from

Returns:True if the releasable is opened, False otherwise
release() → None[source]

Closes this releasable and releases it’s resource

gbvision.utils.net.tcp_stream_receiver module

class gbvision.utils.net.tcp_stream_receiver.TCPStreamReceiver(ip: str, port: int, *args, **kwargs)[source]

Bases: gbvision.utils.net.stream_receiver.StreamReceiver

This class uses TCP to receive a stream over the network, the stream is by default set to be MJPEG the broadcaster is the server and the receiver is the client

Parameters:
  • ip – The IPv4 address of the stream broadcaster, for example ‘10.45.90.8’
  • port – The TCP port to use
is_opened() → bool[source]

Checks if this releasable is open and can be read from

Returns:True if the releasable is opened, False otherwise
release() → None[source]

Closes this releasable and releases it’s resource

gbvision.utils.net.udp_stream_broadcaster module

class gbvision.utils.net.udp_stream_broadcaster.UDPStreamBroadcaster(ip: str, port: int, *args, **kwargs)[source]

Bases: gbvision.utils.net.stream_broadcaster.StreamBroadcaster

this class uses UDP to send a stream over the network, the stream is by default set to be MJPEG the broadcaster is the client and the receiver is the server WARNING: Do not use this class to send large images, UDP has a limited packet size (the IPv4 limit) To send a stream of frames larger then the maximum size of an IP packet, use FragmentedUDPStreamBroadcaster

Parameters:
  • ip – The IPv4 address of the udp stream receiver, for example ‘10.45.90.5’
  • port – The UDP port to use
is_opened() → bool[source]

Checks if this releasable is open and can be read from

Returns:True if the releasable is opened, False otherwise
release() → None[source]

Closes this releasable and releases it’s resource

gbvision.utils.net.udp_stream_receiver module

class gbvision.utils.net.udp_stream_receiver.UDPStreamReceiver(port: int, *args, **kwargs)[source]

Bases: gbvision.utils.net.stream_receiver.StreamReceiver

This class uses UDP to receive a stream over the network, the stream is by default set to be MJPEG the broadcaster is the client and the receiver is the server WARNING: Do not use this class to send large images, udp has a limited packet size To send a stream of frames larger then the maximum size of an IP packet, use FragmentedUDPStreamReceiver

Parameters:port – The UDP port to use
is_opened() → bool[source]

Checks if this releasable is open and can be read from

Returns:True if the releasable is opened, False otherwise
release() → None[source]

Closes this releasable and releases it’s resource

Module contents