Skip to main content

Networking components for Gabriel Python clients

Project description

Gabriel Python Module

Installation

Requires Python 3.6 or later.

Run pip install gabriel-client

Usage

Create an instance of websocket_client.WebsocketClient. Then call the launch() method. The WebsocketClient constructor's arguments are host, port, producer_wrappers (a list of websocket_client.ProducerWrapper instances), and consumer (a function called whenever a new result is available).

opencv_adater.OpencvAdapter provides producer_wrappers and a consumer. push_source.Source provides producer_wrappers. Use of either of these classes is optional. You can define your own producers and/or a consumer, and just use WebsocketClient with these. OpencvAdapter is intended for clients that send image frames from a webcam or a video file, without doing early discard. OpencvAdapter.consumer decodes images returned by the server and then calls the consume_frame callback that was passed to the OpencvAdapter's constructor. This consumer will not work when a ResultWrapper contains more than one result, or a result that is not an image. However, you can still use the producer from OpencvAdapter and write your own custom consumer. The OpencvAdapter requires OpenCV to be installed and accessible to Python. The opencv-python package is a convenient way to install OpenCV for Python. If you do not use OpencvAdapter, you do not have to have OpenCV installed.

If you choose to write your own ProducerWrapper, you must pass a coroutine function as the producer argument to the constructor of ProducerWrapper. The producer is run on an asyncio event loop, so it is important that the producer does not include any blocking code. This would cause the whole event loop to block.

If you need to run blocking code to get an input for Gabriel, you can use push_source.Source. You should also use push_source.Source whenever you want to run the code to produce a frame before a token is available. push_source.Source should always be used for sending frames that pass early discard filters. Create an instance of push_source.Source and include the ProducerWrapper returned from push_source.Source.get_producer_wrapper() in the list of producer_wrappers you pass to the constructor of WebsocketClient. You can then pass the push_source.Source instance to a separate process started using the multiprocessing module. When results are ready, send them with push_source.Source.send(). push_source.Source.send() should only ever be called from one process. Create at least one push_source.Source per process that you want to send frames from. Frames sent with push_source.Source.send() are not guaranteed to be sent to the server. As soon as a token becomes available, the most recent unsent frame will be sent. If push_source.Source.send() is called multiple times before a token becomes available, only the most recent frame will actually be sent to the server. If a token becomes available before the next frame is ready, Gabriel will send the next frame after push_source.Source.send() is called. push_source.Source will not block the event loop.

If you want the client to ignore results, you can pass push_source.consumer as the consumer argument to WebsocketClient.

WebsocketClient does not run producers until there is a token available to send a result from them. This guarantees that producers are not run more frequently than they need to be, and when results are sent to the server, they are as recent as possible. However, running the producer introduces a delay between when a token comes back and when the next frame is sent. push_source.Source allows frames to be generated asynchronously from tokens returning. The two downsides to this approach are:

  1. Some frames might be generated and never sent.
  2. When a token does come back, the last frame sent to a push_source.Source instance might have been generated a while ago. In practice, hopefully tokens will be returned to the client at a reasonable rate.

If you want to measure average round trip time (RTT) and frames per second (FPS), use measurement_client.MeasurementClient in place of WebsocketClient. average RTT and FPS information will be printed automatically, every output_freq frames.

Examples

  1. The round trip example client uses OpencvAdapter.
  2. The one way example producer client uses a custom producer.
  3. The one way example push client uses push_source.Source.
  4. The OpenRTiST playback stream client uses MeasurementClient.

Publishing Changes to PyPi

Update the version number in setup.py. Then follow these instructions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gabriel-client-2.1.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

gabriel_client-2.1.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file gabriel-client-2.1.0.tar.gz.

File metadata

  • Download URL: gabriel-client-2.1.0.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.21.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for gabriel-client-2.1.0.tar.gz
Algorithm Hash digest
SHA256 c30363fc2903237b1a18715dbd668a63871a7be664f1e0ad1ad5ece34a447a87
MD5 a359bc6199920ef2cadd70d69a1634de
BLAKE2b-256 094428c6b417fa754d29f0662f80461518aa02d8b527f044eef3367a4f8374f2

See more details on using hashes here.

File details

Details for the file gabriel_client-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: gabriel_client-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.21.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for gabriel_client-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b2ace2de34b5ca5c9f45b132a1aa0765600ac610a9a3c6a94dfdd3572f28549e
MD5 0d4b325baa3f9b525141cbafc8c1093f
BLAKE2b-256 e11f3f9c454829df34826cec27dfecf92b53b3cbe1fa880d34b46a4805db571b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page