39#include <condition_variable>
71 const std::chrono::nanoseconds &tolerance,
72 size_t max_queue_size = 0):
73 m_owned_channels(std::move(channels)),
74 m_tolerance(tolerance),
75 m_max_queue_size(max_queue_size)
77 for (
auto &channel : m_owned_channels)
79 const auto config = channel->get_config();
81 if (!config.time_config || !config.time_config->ptp_enabled)
83 throw std::runtime_error(
"Creating a MultiChannelSynchronizer with PTP disabled");
86 m_channels.push_back(channel.get());
89 m_active_frames.resize(m_channels.size());
101 const std::chrono::nanoseconds &tolerance,
102 size_t max_queue_size = 0):
103 m_channels(std::move(channels)),
104 m_tolerance(tolerance),
105 m_max_queue_size(max_queue_size)
107 m_active_frames.resize(m_channels.size());
108 add_user_callbacks();
118 if (index >= m_channels.size())
120 throw std::runtime_error(
"Invalid multi-channel access");
123 return *m_channels.at(index);
133 return get_synchronized_frame(std::nullopt);
155 std::vector<Channel*> m_channels{};
160 std::vector<std::unique_ptr<Channel>> m_owned_channels{};
165 std::vector<ImageFrame> m_active_frames{};
170 std::chrono::nanoseconds m_tolerance{};
175 size_t m_max_queue_size = 0;
190 std::deque<std::vector<ImageFrame>> m_ready_frames{};
Copyright 2013-2025 Carnegie Robotics, LLC 4501 Hatfield Street, Pittsburgh, PA 15201 http://www....
Helper class which provides a interface to synchronize data across multiple channels.
std::condition_variable m_frame_cv
Condition variable to notify the user a collection of synchronized frames is ready.
std::mutex m_frame_mutex
Mutex to notify the user a collection of synchronized frames is ready.
MultiChannelSynchronizer(std::vector< std::unique_ptr< Channel > > channels, const std::chrono::nanoseconds &tolerance, size_t max_queue_size=0)
Construct a synchronizer owning the underlying channels.
~MultiChannelSynchronizer()=default
void add_user_callbacks()
Helper to add user callbacks to the input channels.
std::optional< std::vector< ImageFrame > > get_synchronized_frame()
Get a collection synchronized frames from the input channels with no timeout on waiting.
std::optional< std::vector< ImageFrame > > get_synchronized_frame(const std::optional< std::chrono::nanoseconds > &timeout)
Get a collection synchronized frames from the input channels and return if we have not recieved a col...
Channel & channel(size_t index)
Access a channel by index.
MultiChannelSynchronizer(std::vector< Channel * > channels, const std::chrono::nanoseconds &tolerance, size_t max_queue_size=0)
Construct a synchronizer without owning the underlying channels.
MULTISENSE_API bool frames_synchronized(const std::vector< ImageFrame > &frames, const std::chrono::nanoseconds &tolerance)
Free function which determines if a collection of frames are synchronized within a given tolerance.