ifw-rtmstools 3.0.0
Loading...
Searching...
No Matches
rtmsReceiver.hpp
Go to the documentation of this file.
1
8#ifndef RTMS_RECEIVER_HPP_
9#define RTMS_RECEIVER_HPP_
10
11#define BOOST_BIND_NO_PLACEHOLDERS
12
13#include <boost/asio.hpp>
14#include <boost/array.hpp>
15#include <boost/atomic.hpp>
16
17#include <mudpiif/MudpiPacket.hpp>
18#include <mudpiif/MudpiReceiver.hpp>
19#include <hrtcpif/HrtcpPayloadPacket.hpp>
20#include <hrtcpif/HrtcpLeaderPacket.hpp>
21
23
24namespace ifw::rtmstools {
25
26 inline std::string GetThreadName() {
27 char thread_name[32];
28 pthread_getname_np(pthread_self(), thread_name, 32);
29 return thread_name;
30 }
31
32 constexpr int MAX_PACKETS = 1000;
33 constexpr int PACKET_SIZE = 9600;
34
40 void PrintPacketInfo(mudpiif::mudpiPacketJumbo mudpi_packet,
41 hrtcpif::hrtcpLeaderPacket& hrtcp_packet,
42 int pdu_size);
43
54 public:
55 std::string m_address;
56 int m_port;
57 std::string m_net_if;
60 int m_bpp;
61 long unsigned int m_prev_frames_expected;
62 long unsigned int m_prev_frames_received;
68
69 unsigned int m_sample{0};
71 boost::asio::io_service m_io_service;
72 boost::asio::ip::udp::socket m_socket{m_io_service};
73
74 // Packet size defined assuming a Jumbo packet (9600).
75 boost::array<char, PACKET_SIZE> m_recv_buffer;
76 boost::asio::ip::udp::endpoint m_remote_endpoint;
77
78 struct timeval m_start, m_end;
79 int m_num_frames = 0;
80
81 log4cplus::Logger m_logger;
82
83 RtmsReceiver(std::string address,
84 int port,
85 std::string net_if,
86 int width,
87 int height,
88 int bpp,
89 const int rcv_buf_factor=3);
90
91 virtual ~RtmsReceiver();
92
94 int GetSize() const;
95
96 int GetWidth() const;
97 int GetHeight() const;
98
107 void ReceivePacket(const boost::system::error_code& error, size_t bytes_transferred);
108
112 virtual void HandleLeaderPacket();
113
117 virtual void HandlePayloadPacket(mudpiif::mudpiPacketJumbo& packet);
118
122 virtual void HandleTrailerPacket();
123
127 virtual void HandleLostPackets();
128
132 virtual void HandleWrongFrameId();
133
140 virtual void Wait();
141
150 void StartReceiver();
151
152 void StopReceiver();
153
154 int32_t GetCurrentSampleId() const;
155
156 };
157}
158
159#endif // RTMS_RECEIVER_HPP_
The RtmsReceiver class.
Definition rtmsReceiver.hpp:53
int32_t GetCurrentSampleId() const
Definition rtmsReceiver.cpp:277
virtual void HandleTrailerPacket()
Invoked to handle a MUDPI/RTMS Trailer Packet.
Definition rtmsReceiver.cpp:263
virtual void HandleWrongFrameId()
Handle the case where a wrong frame ID is received.
Definition rtmsReceiver.cpp:267
int GetWidth() const
Definition rtmsReceiver.cpp:269
struct timeval m_start m_end
Definition rtmsReceiver.hpp:78
double m_last_diff_sample_id_log
Definition rtmsReceiver.hpp:66
virtual ~RtmsReceiver()
Definition rtmsReceiver.cpp:73
unsigned int m_sample
Definition rtmsReceiver.hpp:69
boost::asio::ip::udp::endpoint m_remote_endpoint
Definition rtmsReceiver.hpp:76
bool m_io_service_running
Definition rtmsReceiver.hpp:70
virtual void HandleLeaderPacket()
Invoked to handle a MUDPI/RTMS Leader Packet.
Definition rtmsReceiver.cpp:259
RtmsReceiver(std::string address, int port, std::string net_if, int width, int height, int bpp, const int rcv_buf_factor=3)
Definition rtmsReceiver.cpp:52
virtual void Wait()
Wait for incoming network data (for asynchroneous use)
Definition rtmsReceiver.cpp:249
boost::asio::io_service m_io_service
Definition rtmsReceiver.hpp:71
virtual void HandlePayloadPacket(mudpiif::mudpiPacketJumbo &packet)
Invoked to handle a MUDPI/RTMS Payload Packet.
Definition rtmsReceiver.cpp:261
std::string m_net_if
Definition rtmsReceiver.hpp:57
void StopReceiver()
Definition rtmsReceiver.cpp:140
int m_rcv_buf_factor
Definition rtmsReceiver.hpp:64
int m_port
Definition rtmsReceiver.hpp:56
bool m_execute
Definition rtmsReceiver.hpp:63
boost::asio::ip::udp::socket m_socket
Definition rtmsReceiver.hpp:72
log4cplus::Logger m_logger
Definition rtmsReceiver.hpp:81
long unsigned int m_prev_frames_received
Definition rtmsReceiver.hpp:62
int m_height
Definition rtmsReceiver.hpp:59
int GetSize() const
Get image size in bytes.
Definition rtmsReceiver.cpp:79
boost::array< char, PACKET_SIZE > m_recv_buffer
Definition rtmsReceiver.hpp:75
long unsigned int m_prev_frames_expected
Definition rtmsReceiver.hpp:61
int m_width
Definition rtmsReceiver.hpp:58
virtual void HandleLostPackets()
Handle the case where packets are lost.
Definition rtmsReceiver.cpp:265
int32_t m_current_sample_id
Definition rtmsReceiver.hpp:67
double m_last_lost_packets_log
Definition rtmsReceiver.hpp:65
std::string m_address
Definition rtmsReceiver.hpp:55
int m_num_frames
Definition rtmsReceiver.hpp:79
void ReceivePacket(const boost::system::error_code &error, size_t bytes_transferred)
Callback to process RTMS packets.
Definition rtmsReceiver.cpp:149
int m_bpp
Definition rtmsReceiver.hpp:60
void StartReceiver()
Network configuration.
Definition rtmsReceiver.cpp:83
int GetHeight() const
Definition rtmsReceiver.cpp:273
DdtImage Class Implementation.
Definition ddtImage.cpp:10
constexpr int PACKET_SIZE
Definition rtmsReceiver.hpp:33
std::string GetThreadName()
Definition rtmsReceiver.hpp:26
void PrintPacketInfo(mudpiif::mudpiPacketJumbo mudpi_packet, hrtcpif::hrtcpLeaderPacket &hrtcp_packet, int pdu_size)
Print information of the RTMS packets.
Definition rtmsReceiver.cpp:25
constexpr int MAX_PACKETS
Definition rtmsReceiver.hpp:32