10#include <condition_variable>
15#include <unordered_map>
31namespace frame_collector {
143 std::shared_ptr<frame_queue_t> queue,
144 int64_t frameCount = -1);
186 std::pair<std::vector<irsol::types::client_id_t>, std::vector<irsol::types::timepoint_t>>
194 void cleanUpSchedule(
const std::vector<irsol::types::timepoint_t> schedules);
202 std::optional<std::pair<FrameMetadata, std::vector<irsol::types::byte_t>>>
grabImageData()
const;
217 std::unordered_map<irsol::types::client_id_t, ClientCollectionParams>
219 std::map<irsol::types::timepoint_t, std::vector<irsol::types::client_id_t>>
High-level wrapper around the NeoAPI camera for synchronized access.
Coordinates frame acquisition from a camera and distributes frames to registered clients.
std::atomic< bool > m_stop
Indicates whether the collector is stopping due to an external request.
void run()
Runs the frame distribution loop in a background thread.
void deregisterClient(irsol::types::client_id_t clientId)
Deregisters a client and stops frame delivery.
void start()
Starts the frame collection and distribution thread.
void deregisterClientNonThreadSafe(irsol::types::client_id_t clientId)
Deregisters a client and stops frame delivery (not thread-safe).
std::thread m_distributorThread
Thread responsible for frame distribution.
std::pair< std::vector< irsol::types::client_id_t >, std::vector< irsol::types::timepoint_t > > collectReadyClients(irsol::types::timepoint_t now, irsol::types::duration_t slack) const
Collects clients who are scheduled to receive a frame at the given time.
std::map< irsol::types::timepoint_t, std::vector< irsol::types::client_id_t > > m_scheduleMap
Maps timestamps to client IDs scheduled at that time.
~FrameCollector()
Destructor. Stops any running threads and cleans up resources.
std::condition_variable m_scheduleCondition
Signals when a new client is scheduled.
void registerClient(irsol::types::client_id_t clientId, double fps, std::shared_ptr< frame_queue_t > queue, int64_t frameCount=-1)
Registers a client to receive frames at a specified frame rate.
irsol::camera::Interface & m_cam
Reference to the camera interface used for capturing.
bool schedule(const irsol::types::client_id_t &clientId, irsol::types::timepoint_t nextFrameDue)
Schedules the next frame delivery for a client.
bool isBusy() const
Checks whether the collector is currently serving any clients.
std::unordered_map< irsol::types::client_id_t, ClientCollectionParams > m_clients
Stores parameters for each registered client.
static constexpr irsol::types::duration_t SLACK
Slack window for batching frame delivery to clients.
std::optional< std::pair< FrameMetadata, std::vector< irsol::types::byte_t > > > grabImageData() const
Captures an image and returns it along with associated metadata.
void stop()
Stops the frame collector and joins worker threads.
std::mutex m_clientsMutex
Protects access to m_clients and m_scheduleMap.
static std::shared_ptr< frame_queue_t > makeQueuePtr()
Utility static function to create a shared pointer to a frame queue.
void cleanUpSchedule(const std::vector< irsol::types::timepoint_t > schedules)
Removes schedules from the schedule map.
A thread-safe, optionally bounded queue with blocking push and pop operations.
High-level wrapper around NeoAPI camera control for the irsol library.
clock_t::duration duration_t
Alias for a duration of time as defined by clock_t.
std::string client_id_t
Represents a unique client identifier. Typically used to identify connected clients by string IDs.
clock_t::time_point timepoint_t
Alias for a point in time as defined by clock_t.
irsol::utils::SafeQueue< std::unique_ptr< Frame > > frame_queue_t
Core type definitions for networking, time handling, and protocol values used throughout the irsol li...
General utility functions used throughout the irsol library.