Stay organized with collectionsSave and categorize content based on your preferences.
visionai::StreamReceiver
#include <streams.h>
StreamReceiveris the client through which users receivePackets from a stream.
Summary
Each instance of theStreamReceiverrepresents a single connection to a specific stream. Once created, the user may repeatedly callReceive.
Example - Repeatedly receivePackets from a specific stream.
// First populate the options.StreamReceiver::Optionsoptions;options.service_connection_options=...;options.stream_id="my-stream";// Create an instance of the `StreamReceiver`.autostream_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.}autostream_receiver=std::move(*stream_receiver_statusor);// Now you can repeatedly receive Packets.while(true){Packetp;autostatus=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();
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 noPackets in the server beforetimeouthas 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 newStreamReceiverto read from a different event.
Other error codes: To retry, create a new instance of theStreamReceiverandReceivethrough that.
The first overload blocks until either there is a newPacketor until a non-transient error has occurred.
The second overload blocks up totimeoutbefore returning NOT_FOUND. Otherwise, either yields aPacketor returns a non-transient error.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-27 UTC."],[],[],null,["# visionai::StreamReceiver Class Reference\n\nvisionai::StreamReceiver\n========================\n\n`#include \u003cstreams.h\u003e`\n\n[StreamReceiver](/vision-ai/docs/reference/cpp/class/visionai/stream-receiver#classvisionai_1_1_stream_receiver) is the client through which users receive `Packet`s from a stream.\n\nSummary\n-------\n\nEach instance of the [StreamReceiver](/vision-ai/docs/reference/cpp/class/visionai/stream-receiver#classvisionai_1_1_stream_receiver) represents a single connection to a specific stream. Once created, the user may repeatedly call `Receive`.\n\nExample - Repeatedly receive `Packet`s from a specific stream.\n\n\n```c++\n// First populate the options.\nStreamReceiver::Options options;\noptions.service_connection_options = ...;\noptions.stream_id = \"my-stream\";\n\n// Create an instance of the `StreamReceiver`.\nauto stream_receiver_statusor = StreamReceiver::Create(options);\nif (!stream_receiver.ok()) {\n // An error occurred during the setup of the receiver.\n // You can fix the problem and try again.\n}\nauto stream_receiver = std::move(*stream_receiver_statusor);\n\n// Now you can repeatedly receive Packets.\nwhile (true) {\n Packet p;\n auto status = stream_receiver-\u003eReceive(&p);\n if (!status.ok()) {\n // An error occurred. If the error is transient, then you can retry\n // with the same receiver. Otherwise, create a new instance to retry.\n }\n}\n\n// When no more packets are desired, destroy the receiver.\nstream_receiver-\u003ereset();\n```\n\n\u003cbr /\u003e\n\nPublic static functions\n-----------------------\n\n### Create\n\n```c++\nabsl::StatusOr\u003c std::unique_ptr\u003c StreamReceiver \u003e \u003e Create(\n const Options &\n)\n``` \nCreate a readily usable instance of a [StreamReceiver](/vision-ai/docs/reference/cpp/class/visionai/stream-receiver#classvisionai_1_1_stream_receiver).\n\nPublic functions\n----------------\n\n### Receive\n\n```c++\nabsl::Status Receive(\n Packet *packet\n)\n``` \nReceive a `Packet` from a stream.\n\nReturns OK on success. Otherwise, returns the following possible errors:\n\nNOT_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.\n\nOUT_OF_RANGE: This indicates that the last packet in the event has been delivered. You can create a new [StreamReceiver](/vision-ai/docs/reference/cpp/class/visionai/stream-receiver#classvisionai_1_1_stream_receiver) to read from a different event.\n\nOther error codes: To retry, create a new instance of the [StreamReceiver](/vision-ai/docs/reference/cpp/class/visionai/stream-receiver#classvisionai_1_1_stream_receiver) and `Receive` through that.\n\nThe first overload blocks until either there is a new `Packet` or until a non-transient error has occurred.\n\nThe second overload blocks up to `timeout` before returning NOT_FOUND. Otherwise, either yields a `Packet` or returns a non-transient error. \n\n### Receive\n\n```c++\nabsl::Status Receive(\n absl::Duration timeout,\n Packet *packet\n)\n``` \n\n### StreamReceiver\n\n```c++\n StreamReceiver()=default\n``` \n\n### StreamReceiver\n\n```c++\n StreamReceiver(\n const StreamReceiver &\n)=delete\n``` \n\n### operator=\n\n```c++\nStreamReceiver & operator=(\n const StreamReceiver &\n)=delete\n``` \n\n### \\~StreamReceiver\n\n```c++\n ~StreamReceiver()=default\n```"]]