ifw-rtmslib 1.0.0-pre2
 
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 int16_t packet_send_delay{-1};
46
47 // The next flag is used to make the RTMS Sender continue trying to send, even if there is
48 // no receiver running.
50 };
51
52
65 class RtmsSender {
66 public:
67
75 RtmsSender(const std::string& src_ip,
76 const std::string& dest_ip,
77 const int dest_port,
78 const int8_t bytes_per_pixel,
79 const size_t raw_image_size,
80 const SenderConfig& sndr_cfg = SenderConfig());
81
82 virtual ~RtmsSender();
83
89 int SendSample(const SampleExtInfo& ext_info,
90 const std::vector<uint8_t>& sample_payload);
91
92 int GetPixelsPerSample() const;
93
94 uint32_t m_sample_id;
95
96 private:
97 void Initialise(const SampleExtInfo& ext_info);
98
99 // Helper to aggregate and throttle logging of connection refused errors
100 void LogConnRefusedIfNeeded(const char* where, const std::error_code& ec);
101
102 std::string m_src_ip;
103 std::string m_dest_ip;
104 int m_dest_port;
105 int8_t m_bytes_per_pixel;
106 size_t m_raw_image_size;
107 SenderConfig m_sndr_cfg;
108
109 size_t m_pixels_per_sample;
110 size_t m_current_raw_image_size{0};
111 int32_t m_nb_of_udp_packets;
112
113 llnetio::UdpTxSocket::Config m_udp_cfg{};
114 std::unique_ptr<llnetio::UdpTxSocket> m_udp_socket;
115 llnetio::mudpi::Sender::Config m_mudpi_cfg{};
116 std::unique_ptr<llnetio::mudpi::Sender> m_mudpi_sender;
117 llnetio::rtms::Sender::Config m_rtms_cfg{};
118 std::unique_ptr<llnetio::rtms::Sender> m_rtms_sender;
119
120 std::vector<uint8_t> m_packed_ext_info;
121
122 // State for connection-refused logging (throttled)
123 std::chrono::steady_clock::time_point m_last_conn_refused_log{};
124 std::uint64_t m_conn_refused_errors{0};
125
126 };
127}
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:176
uint32_t m_sample_id
Definition rtmsSender.hpp:94
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:63
int GetPixelsPerSample() const
Definition rtmsSender.cpp:459
virtual ~RtmsSender()
Definition rtmsSender.cpp:84
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:49
int32_t topic_id
Definition rtmsSender.hpp:38
int16_t packet_send_delay
Definition rtmsSender.hpp:45
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