ifw-fgf 2.0.0
 
Loading...
Searching...
No Matches
rtmsLlnetioPublisher.hpp
Go to the documentation of this file.
1
8
9#ifndef FGF_ANDOR_RTMS_LLNETIO_PUBLISHER_HPP_H_
10#define FGF_ANDOR_RTMS_LLNETIO_PUBLISHER_HPP_H_
11
12#include <cstdint>
13#include <list>
14#include <memory>
15#include <string>
16#include <thread>
17#include <condition_variable>
18#include <mutex>
19#include <vector>
20
21#include <boost/atomic.hpp>
22#include <boost/lockfree/spsc_queue.hpp>
23
24#include <ifw/rtmslib_llnetio/rtmsSender.hpp>
25#include <ifw/rtmslib_llnetio/sampleExtInfo.hpp>
27
28namespace ifw::fgf::andor {
29
30 constexpr auto PUBLISHER_STAT_WINDOW_SIZE = 1000;
31 constexpr auto PUBLISHER_QUEUE_CAPACITY = 8;
32
35 std::string src_ip;
36 std::string dest_ip;
37 int dest_port{0};
38 ifw::rtmslib::SenderConfig sender_cfg{};
39 };
40
43 std::vector<uint8_t> data;
44 double timestamp{0};
45 int width{0};
46 int height{0};
47 int bpp{0};
48 };
49
55
62 public:
63
65 bool compute_latency = false,
66 const PublisherThreadConfig& thread_cfg = PublisherThreadConfig());
67
68 virtual ~RtmsLlnetioPublisher();
69
72 bool Push(std::shared_ptr<PublishFramePacket> pkt);
73
75 void PushLatencyStart(double ts);
76
78 void Notify();
79
81 void Stop();
82
84 bool IsStopped() const;
85
87 void SetOffsets(int offset_x, int offset_y);
88
89 // ---- Latency statistics (runtime toggle)
90 void SetComputeLatency(bool enable);
91 bool GetComputeLatency() const;
92 void ResetLatency();
93
94 void GetFirstPacketSentLatency(double& latency, double& stddev,
95 double& variance, int& nb_of_samples);
96 void GetFrameSentLatency(double& latency, double& stddev,
97 double& variance, int& nb_of_samples);
98
99 private:
100 void Run();
101
102 void SetThreadAffinity(int cpu_id);
103 void SetThreadPriority(int priority);
104
105 void ComputeStat(const std::list<double>& samples,
106 double& mean, double& stddev,
107 double& variance, int& nb_of_samples) const;
108
110 void LogStatsIfNeeded();
111
112 // ---- SPSC queue ----
113 boost::lockfree::spsc_queue<std::shared_ptr<PublishFramePacket>,
114 boost::lockfree::capacity<PUBLISHER_QUEUE_CAPACITY>> m_queue;
115
116 // ---- Publisher thread ----
117 std::thread m_pub_thread;
118 std::condition_variable m_pub_condvar;
119 std::mutex m_pub_mtx;
120 static std::atomic<bool> m_stopped;
121
122 // ---- Sender ----
123 RtmsNetworkConfig m_rtms_cfg;
124 std::unique_ptr<ifw::rtmslib::RtmsSender> m_sender;
125 int m_active_sender_bpp{0};
126 size_t m_active_sender_size{0};
127
128 // ---- Offsets (set from CommAdapter) ----
129 int m_offset_x{0};
130 int m_offset_y{0};
131
132 // ---- Logging ----
133 log4cplus::Logger m_logger;
134
135 // ---- Latency tracking ----
136 bool m_compute_latency{false};
137 std::mutex m_start_times_mtx;
138 std::list<double> m_start_times;
139
140 std::mutex m_first_pkt_lat_mtx;
141 std::list<double> m_first_pkt_latencies;
142
143 std::mutex m_frame_lat_mtx;
144 std::list<double> m_frame_latencies;
145
146 // ---- Periodic stats logging ----
147 std::mutex m_stats_mtx;
148 int m_frames_sent{0};
149 int m_frames_dropped{0};
150 double m_last_stats_time{0};
151
152 // ---- Thread tuning ----
153 PublisherThreadConfig m_thread_cfg;
154 };
155
156} // namespace ifw::fgf::andor
157
158#endif // FGF_ANDOR_RTMS_LLNETIO_PUBLISHER_HPP_H_
void Stop()
Stop the publisher thread (wait for drain timeout).
Definition rtmsLlnetioPublisher.cpp:83
void PushLatencyStart(double ts)
Record a latency start timestamp (to be matched with send completion).
Definition rtmsLlnetioPublisher.cpp:72
void SetComputeLatency(bool enable)
Definition rtmsLlnetioPublisher.cpp:365
bool Push(std::shared_ptr< PublishFramePacket > pkt)
Push a frame packet onto the SPSC queue.
Definition rtmsLlnetioPublisher.cpp:65
virtual ~RtmsLlnetioPublisher()
Definition rtmsLlnetioPublisher.cpp:61
bool GetComputeLatency() const
Definition rtmsLlnetioPublisher.cpp:369
bool IsStopped() const
Check if the publisher thread has been stopped.
Definition rtmsLlnetioPublisher.cpp:92
void GetFirstPacketSentLatency(double &latency, double &stddev, double &variance, int &nb_of_samples)
Definition rtmsLlnetioPublisher.cpp:388
void ResetLatency()
Definition rtmsLlnetioPublisher.cpp:373
void SetOffsets(int offset_x, int offset_y)
Set the AOI offset values for BasicImageInfo ext_info header.
Definition rtmsLlnetioPublisher.cpp:96
void GetFrameSentLatency(double &latency, double &stddev, double &variance, int &nb_of_samples)
Definition rtmsLlnetioPublisher.cpp:394
void Notify()
Signal the publisher thread that data is available.
Definition rtmsLlnetioPublisher.cpp:79
RtmsLlnetioPublisher(const RtmsNetworkConfig &rtms_cfg, bool compute_latency=false, const PublisherThreadConfig &thread_cfg=PublisherThreadConfig())
Definition rtmsLlnetioPublisher.cpp:46
Logging definitions.
Definition commAdaptor.cpp:34
constexpr auto PUBLISHER_STAT_WINDOW_SIZE
Definition rtmsLlnetioPublisher.hpp:30
constexpr auto PUBLISHER_QUEUE_CAPACITY
Definition rtmsLlnetioPublisher.hpp:31
A packet carrying one frame's data ready for network send.
Definition rtmsLlnetioPublisher.hpp:42
int bpp
Definition rtmsLlnetioPublisher.hpp:47
double timestamp
Definition rtmsLlnetioPublisher.hpp:44
int width
Definition rtmsLlnetioPublisher.hpp:45
int height
Definition rtmsLlnetioPublisher.hpp:46
std::vector< uint8_t > data
Definition rtmsLlnetioPublisher.hpp:43
Thread-level tuning for the publisher.
Definition rtmsLlnetioPublisher.hpp:51
int cpu_affinity
Definition rtmsLlnetioPublisher.hpp:52
int scheduler_priority
Definition rtmsLlnetioPublisher.hpp:53
RTMS network configuration (shared with CommAdapter).
Definition rtmsLlnetioPublisher.hpp:34
std::string dest_ip
Definition rtmsLlnetioPublisher.hpp:36
ifw::rtmslib::SenderConfig sender_cfg
Definition rtmsLlnetioPublisher.hpp:38
std::string src_ip
Definition rtmsLlnetioPublisher.hpp:35
int dest_port
Definition rtmsLlnetioPublisher.hpp:37