ifw-rtmslib 1.0.0
 
Loading...
Searching...
No Matches
rtmsSender.hpp
Go to the documentation of this file.
1
7
8#pragma once
9
10#include <csignal>
11#include <cerrno>
12#include <thread>
13#include <chrono>
14#include <cstdint>
15
16#include <boost/endian/arithmetic.hpp>
17
18#include <fmt/format.h>
19
20#include <llnetio/ipv4.hpp>
21#include <llnetio/mudpi/io.hpp>
22#include <llnetio/rtms/io.hpp>
23#include <llnetio/rtms/rtms.hpp>
24#include <llnetio/udpSocket.hpp>
25#include <llnetio/mockSocket.hpp>
26
30
31namespace ifw::rtmslib {
32
34 public:
36
37 uint16_t mtu_size{1500};
38 int32_t topic_id{10};
39 uint16_t component_id{12345};
40 bool simulation{false};
41
42 // Extended info layout to emit in leader packets.
44
45 // Optional per-packet pacing delay in MICROSECONDS. <= 0 disables pacing.
46 // Implemented as a deadline-based busy-spin (see SpinWaitUntil in the .cpp),
47 // NOT a sleep_for: at high packet rates a syscall sleep's granularity floor
48 // (~tens-hundreds of µs) and overhead would dwarf the intended delay and
49 // accumulate into large per-frame stalls. The deadline scheme is also
50 // drift-free (the average inter-packet rate stays accurate).
51 int16_t packet_send_delay{-1};
52
53 // The next flag is used to make the RTMS Sender continue trying to send, even if there is
54 // no receiver running.
56 };
57
58
71 class RtmsSender {
72 public:
73
81 RtmsSender(const std::string& src_ip,
82 const std::string& dest_ip,
83 const int dest_port,
84 const int8_t bytes_per_pixel,
85 const size_t raw_image_size,
86 const SenderConfig& sndr_cfg = SenderConfig());
87
88 virtual ~RtmsSender();
89
95 int SendSample(const SampleExtInfo& ext_info,
96 const std::vector<uint8_t>& sample_payload);
97
98 int GetPixelsPerSample() const;
99
100 uint32_t m_sample_id;
101
102 private:
103 void Initialise(const SampleExtInfo& ext_info);
104
105 // Helper to aggregate and throttle logging of connection refused errors
106 void LogConnRefusedIfNeeded(const char* where, const std::error_code& ec);
107
108 std::string m_src_ip;
109 std::string m_dest_ip;
110 int m_dest_port;
111 int8_t m_bytes_per_pixel;
112 size_t m_raw_image_size;
113 SenderConfig m_sndr_cfg;
114
115 size_t m_pixels_per_sample;
116 size_t m_current_raw_image_size{0};
117 int32_t m_nb_of_udp_packets;
118
119 llnetio::UdpTxSocket::Config m_udp_cfg{};
120 std::unique_ptr<llnetio::UdpTxSocket> m_udp_socket;
121 llnetio::mudpi::Sender::Config m_mudpi_cfg{};
122 std::unique_ptr<llnetio::mudpi::Sender> m_mudpi_sender;
123 llnetio::rtms::Sender::Config m_rtms_cfg{};
124 std::unique_ptr<llnetio::rtms::Sender> m_rtms_sender;
125
126 std::vector<uint8_t> m_packed_ext_info;
127
128 // State for connection-refused logging (throttled)
129 std::chrono::steady_clock::time_point m_last_conn_refused_log{};
130 std::uint64_t m_conn_refused_errors{0};
131
132 };
133}
int SendSample(const SampleExtInfo &ext_info, const std::vector< uint8_t > &sample_payload)
User provided method to send an image as an RTMS Sample.
Definition rtmsSender.cpp:198
uint32_t m_sample_id
Definition rtmsSender.hpp:100
RtmsSender(const std::string &src_ip, const std::string &dest_ip, const int dest_port, const int8_t bytes_per_pixel, const size_t raw_image_size, const SenderConfig &sndr_cfg=SenderConfig())
Simple RTMS Sender class.
Definition rtmsSender.cpp:85
int GetPixelsPerSample() const
Definition rtmsSender.cpp:578
virtual ~RtmsSender()
Definition rtmsSender.cpp:106
Definition sampleExtInfo.hpp:33
Definition rtmsSender.hpp:33
uint16_t component_id
Definition rtmsSender.hpp:39
bool simulation
Definition rtmsSender.hpp:40
uint16_t mtu_size
Definition rtmsSender.hpp:37
SenderConfig()
Definition rtmsSender.hpp:35
bool ignore_connection_refused
Definition rtmsSender.hpp:55
int32_t topic_id
Definition rtmsSender.hpp:38
int16_t packet_send_delay
Definition rtmsSender.hpp:51
ExtendedInfoMode ext_info_mode
Definition rtmsSender.hpp:43
Common utilities for RTMS Lib.
Definition common.cpp:21
ExtendedInfoMode
Definition common.hpp:29
@ None
Leader packets carry no extended info.
Definition common.hpp:30