visionai:: StreamReceiver
#include <streams.h>
StreamReceiver
is the client through which users receive Packet
s from a stream.
Summary
Each instance of the StreamReceiver
represents a single connection to a specific stream. Once created, the user may repeatedly call Receive
.
Example - Repeatedly receive Packet
s from a specific stream.
// First populate the options. StreamReceiver::Options options; options.service_connection_options = ...; options.stream_id = "my-stream"; // Create an instance of the `StreamReceiver`. auto stream_receiver_statusor = StreamReceiver::Create(options); if (!stream_receiver.ok()) { // An error occurred during the setup of the receiver. // You can fix the problem and try again. } auto stream_receiver = std::move(*stream_receiver_statusor); // Now you can repeatedly receive Packets. while (true) { Packet p; auto status = stream_receiver->Receive(&p); if (!status.ok()) { // An error occurred. If the error is transient, then you can retry // with the same receiver. Otherwise, create a new instance to retry. } } // When no more packets are desired, destroy the receiver. stream_receiver->reset();
Constructors and Destructors |
|
---|---|
StreamReceiver()
|
|
StreamReceiver(const StreamReceiver &)
|
|
~StreamReceiver()
|
Public static functions |
|
---|---|
Create(const Options &)
|
absl::StatusOr< std::unique_ptr< StreamReceiver > >
Create a readily usable instance of a
StreamReceiver . |
Public functions |
|
---|---|
Receive(Packet *packet)
|
absl::Status
Receive a
Packet from a stream. |
Receive(absl::Duration timeout, Packet *packet)
|
absl::Status
|
operator=(const StreamReceiver &)=delete
|
Structs |
|
---|---|
visionai:: |
Options to configure the |
Public static functions
Create
absl::StatusOr< std::unique_ptr< StreamReceiver > > Create( const Options & )
Create a readily usable instance of a StreamReceiver
.
Public functions
Receive
absl::Status Receive( Packet *packet )
Receive a Packet
from a stream.
Returns OK on success. Otherwise, returns the following possible errors:
NOT_FOUND: This is only possible with the second overload. It is returned when there are no Packet
s in the server before timeout
has run out. You may immediately retry with the same receiver instance.
OUT_OF_RANGE: This indicates that the last packet in the event has been delivered. You can create a new StreamReceiver
to read from a different event.
Other error codes: To retry, create a new instance of the StreamReceiver
and Receive
through that.
The first overload blocks until either there is a new Packet
or until a non-transient error has occurred.
The second overload blocks up to timeout
before returning NOT_FOUND. Otherwise, either yields a Packet
or returns a non-transient error.
Receive
absl::Status Receive( absl::Duration timeout, Packet *packet )
StreamReceiver
StreamReceiver()=default
StreamReceiver
StreamReceiver( const StreamReceiver & )=delete
operator=
StreamReceiver & operator=( const StreamReceiver & )=delete
~StreamReceiver
~StreamReceiver()=default