Package: gabriel-client
Gabriel Python ModuleInstallationRequires Python 3.6 or later.Runpip install gabriel-clientUsageCreate an instance ofwebsocket_client.WebsocketClient. Then call
thelaunch()method. TheWebsocketClientconstructor's arguments arehost,port,producer_wrappers(a list ofwebsocket_client.ProducerWrapperinstances), andconsumer(a
function called whenever a new result is available).opencv_adater.OpencvAdapterprovidesproducer_wrappersand a consumer.push_source.Sourceprovidesproducer_wrappers.
Use of either of these classes is optional. You can define your own producers
and/or a consumer, and just useWebsocketClientwith these.OpencvAdapteris
intended for clients that send image frames from a webcam or a video file,
without doing early discard.OpencvAdapter.consumerdecodes images returned
by the server and then calls theconsume_framecallback that was passed to theOpencvAdapter's constructor. This consumer will not work when aResultWrappercontains more than one result, or a result that is not an
image. However, you can still use the producer fromOpencvAdapterand write
your own custom consumer. TheOpencvAdapterrequires OpenCV to be
installed and accessible to Python. Theopencv-pythonpackage is a convenient
way to install OpenCV for Python. If you do not useOpencvAdapter, you do not
have to have OpenCV installed.If you choose to write your ownProducerWrapper, you must pass acoroutine functionas theproducerargument to the constructor ofProducerWrapper. Theproduceris run on anasyncio event loop,
so it is important that theproducerdoes 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 usepush_source.Source. You should also usepush_source.Sourcewhenever you want
to run the code to produce a frame before a token is available.push_source.Sourceshould always be used for sending frames that pass early
discard filters. Create an instance ofpush_source.Sourceand include theProducerWrapperreturned frompush_source.Source.get_producer_wrapper()in
the list ofproducer_wrappersyou pass to the constructor ofWebsocketClient. You can then pass thepush_source.Sourceinstance to a separate process started using themultiprocessingmodule. When
results are ready, send them withpush_source.Source.send().push_source.Source.send()should only ever be called from one process. Create
at least onepush_source.Sourceper process that you want to send frames from.
Frames sent withpush_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. Ifpush_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 afterpush_source.Source.send()is called.push_source.Sourcewill not block the event loop.If you want the client to ignore results, you can passpush_source.consumeras theconsumerargument toWebsocketClient.WebsocketClientdoes 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.Sourceallows frames to be generated asynchronously from tokens
returning. The two downsides to this approach are:Some frames might be generated and never sent.When a token does come back, the last frame sent to apush_source.Sourceinstance 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), usemeasurement_client.MeasurementClientin place ofWebsocketClient.
average RTT and FPS information will be printed automatically, everyoutput_freqframes.ExamplesThe round trip exampleclientusesOpencvAdapter.The one way exampleproducer clientuses a custom producer.The one way examplepush clientusespush_source.Source.The OpenRTiSTplayback stream clientusesMeasurementClient.Publishing Changes to PyPiUpdate the version number in setup.py. Then followthese instructions.