CARLA
Loading...
Searching...
No Matches
sensorStreamRegistry.h
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma de Barcelona (UAB).
2// This work is licensed under the terms of the MIT license.
3// For a copy, see <https://opensource.org/licenses/MIT>.
4
5#pragma once
6
11
12#include <cstdint>
13#include <mutex>
14#include <optional>
15#include <unordered_map>
16
17namespace carla {
18namespace multigpu {
19
20/// Secondary-side map from a primary sensor actor to its local stream, exposed
21/// to clients only through an alias of the primary's stream id. Entries are
22/// per primary episode. Resolve() and BeginEpisodeChange() run on the multi-GPU
23/// command thread, the rest on the game thread.
25public:
26 using actor_id_type = uint32_t;
27 using epoch_type = uint64_t;
30
31 /// Token that serves primary actor @a actor_id under @a primary_stream_id,
32 /// reserving a local stream if the sensor has not spawned here yet.
33 [[nodiscard]]
34 std::optional<token_type> Resolve(
37 stream_id_type primary_stream_id);
38
39 /// Returns the stream reserved for @a actor_id if @a can_adopt (the sensor
40 /// has never ticked) and the sensor must adopt it; otherwise the alias is
41 /// retargeted to @a sensor_stream_id. A stream bound to another actor is refused.
42 [[nodiscard]]
43 std::optional<carla::streaming::Stream> Bind(
46 stream_id_type sensor_stream_id,
47 bool can_adopt);
48
49 /// Forgets @a actor_id, closing its reserved stream if no sensor adopted it.
51
52 /// The primary switched episode: forgets every actor and returns the epoch
53 /// the secondary must pass to OpenEpisode() once it runs the new episode.
54 [[nodiscard]]
56
57 /// Accepts binding if @a epoch is the latest one BeginEpisodeChange() issued.
58 void OpenEpisode(epoch_type epoch);
59
60 void CloseEpisode();
61
62 /// Whether Bind()/Unbind() are accepted, i.e. the episode of the latest
63 /// BeginEpisodeChange() is open.
64 [[nodiscard]]
65 bool IsEpisodeOpen();
66
67private:
68 struct Entry {
70 std::optional<carla::streaming::Stream> reserved;
71 std::optional<stream_id_type> primary_stream_id;
72 };
73
74 static void Forget(carla::streaming::Server &server, const Entry &entry);
75
76 std::mutex _mutex;
78 bool _bindable = false;
79 std::unordered_map<actor_id_type, Entry> _entries;
80};
81
82} // namespace multigpu
83} // namespace carla
Secondary-side map from a primary sensor actor to its local stream, exposed to clients only through a...
carla::streaming::detail::stream_id_type stream_id_type
static void Forget(carla::streaming::Server &server, const Entry &entry)
std::optional< token_type > Resolve(carla::streaming::Server &server, actor_id_type actor_id, stream_id_type primary_stream_id)
Token that serves primary actor actor_id under primary_stream_id, reserving a local stream if the sen...
epoch_type BeginEpisodeChange(carla::streaming::Server &server)
The primary switched episode: forgets every actor and returns the epoch the secondary must pass to Op...
bool IsEpisodeOpen()
Whether Bind()/Unbind() are accepted, i.e.
void OpenEpisode(epoch_type epoch)
Accepts binding if epoch is the latest one BeginEpisodeChange() issued.
std::optional< carla::streaming::Stream > Bind(carla::streaming::Server &server, actor_id_type actor_id, stream_id_type sensor_stream_id, bool can_adopt)
Returns the stream reserved for actor_id if can_adopt (the sensor has never ticked) and the sensor mu...
std::unordered_map< actor_id_type, Entry > _entries
void Unbind(carla::streaming::Server &server, actor_id_type actor_id)
Forgets actor_id, closing its reserved stream if no sensor adopted it.
A streaming server.
Serializes a stream endpoint.
This file contains definitions of common data structures used in traffic manager.
std::optional< carla::streaming::Stream > reserved
std::optional< stream_id_type > primary_stream_id