CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
multigpu
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
7
#include "
carla/streaming/Server.h
"
8
#include "
carla/streaming/Stream.h
"
9
#include "
carla/streaming/detail/Token.h
"
10
#include "
carla/streaming/detail/Types.h
"
11
12
#include <cstdint>
13
#include <mutex>
14
#include <optional>
15
#include <unordered_map>
16
17
namespace
carla
{
18
namespace
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.
24
class
SensorStreamRegistry
{
25
public
:
26
using
actor_id_type
= uint32_t;
27
using
epoch_type
= uint64_t;
28
using
stream_id_type
=
carla::streaming::detail::stream_id_type
;
29
using
token_type
=
carla::streaming::detail::token_type
;
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
(
35
carla::streaming::Server
&server,
36
actor_id_type
actor_id
,
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
(
44
carla::streaming::Server
&server,
45
actor_id_type
actor_id
,
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.
50
void
Unbind
(
carla::streaming::Server
&server,
actor_id_type
actor_id
);
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]]
55
epoch_type
BeginEpisodeChange
(
carla::streaming::Server
&server);
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
67
private
:
68
struct
Entry
{
69
stream_id_type
stream_id
;
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
;
77
epoch_type
_epoch
= 0u;
78
bool
_bindable
=
false
;
79
std::unordered_map<actor_id_type, Entry>
_entries
;
80
};
81
82
}
// namespace multigpu
83
}
// namespace carla
Stream.h
carla::multigpu::SensorStreamRegistry
Secondary-side map from a primary sensor actor to its local stream, exposed to clients only through a...
Definition
sensorStreamRegistry.h:24
carla::multigpu::SensorStreamRegistry::stream_id_type
carla::streaming::detail::stream_id_type stream_id_type
Definition
sensorStreamRegistry.h:28
carla::multigpu::SensorStreamRegistry::Forget
static void Forget(carla::streaming::Server &server, const Entry &entry)
Definition
sensorStreamRegistry.cpp:137
carla::multigpu::SensorStreamRegistry::Resolve
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...
Definition
sensorStreamRegistry.cpp:14
carla::multigpu::SensorStreamRegistry::CloseEpisode
void CloseEpisode()
Definition
sensorStreamRegistry.cpp:127
carla::multigpu::SensorStreamRegistry::BeginEpisodeChange
epoch_type BeginEpisodeChange(carla::streaming::Server &server)
The primary switched episode: forgets every actor and returns the epoch the secondary must pass to Op...
Definition
sensorStreamRegistry.cpp:112
carla::multigpu::SensorStreamRegistry::_epoch
epoch_type _epoch
Definition
sensorStreamRegistry.h:77
carla::multigpu::SensorStreamRegistry::_bindable
bool _bindable
Definition
sensorStreamRegistry.h:78
carla::multigpu::SensorStreamRegistry::IsEpisodeOpen
bool IsEpisodeOpen()
Whether Bind()/Unbind() are accepted, i.e.
Definition
sensorStreamRegistry.cpp:132
carla::multigpu::SensorStreamRegistry::token_type
carla::streaming::detail::token_type token_type
Definition
sensorStreamRegistry.h:29
carla::multigpu::SensorStreamRegistry::OpenEpisode
void OpenEpisode(epoch_type epoch)
Accepts binding if epoch is the latest one BeginEpisodeChange() issued.
Definition
sensorStreamRegistry.cpp:122
carla::multigpu::SensorStreamRegistry::actor_id_type
uint32_t actor_id_type
Definition
sensorStreamRegistry.h:26
carla::multigpu::SensorStreamRegistry::Bind
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...
Definition
sensorStreamRegistry.cpp:54
carla::multigpu::SensorStreamRegistry::_entries
std::unordered_map< actor_id_type, Entry > _entries
Definition
sensorStreamRegistry.h:79
carla::multigpu::SensorStreamRegistry::_mutex
std::mutex _mutex
Definition
sensorStreamRegistry.h:76
carla::multigpu::SensorStreamRegistry::epoch_type
uint64_t epoch_type
Definition
sensorStreamRegistry.h:27
carla::multigpu::SensorStreamRegistry::Unbind
void Unbind(carla::streaming::Server &server, actor_id_type actor_id)
Forgets actor_id, closing its reserved stream if no sensor adopted it.
Definition
sensorStreamRegistry.cpp:97
carla::streaming::Server
A streaming server.
Definition
streaming/Server.h:23
carla::streaming::detail::token_type
Serializes a stream endpoint.
Definition
detail/Token.h:61
Token.h
carla::multigpu
Definition
commands.h:17
carla::multigpu::actor_id
uint32_t actor_id
Definition
primaryCommands.h:28
carla::streaming::detail::stream_id_type
uint32_t stream_id_type
Definition
streaming/detail/Types.h:18
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
Server.h
Types.h
carla::multigpu::SensorStreamRegistry::Entry
Definition
sensorStreamRegistry.h:68
carla::multigpu::SensorStreamRegistry::Entry::reserved
std::optional< carla::streaming::Stream > reserved
Definition
sensorStreamRegistry.h:70
carla::multigpu::SensorStreamRegistry::Entry::stream_id
stream_id_type stream_id
Definition
sensorStreamRegistry.h:69
carla::multigpu::SensorStreamRegistry::Entry::primary_stream_id
std::optional< stream_id_type > primary_stream_id
Definition
sensorStreamRegistry.h:71
Generated by
1.18.0