RTC Toolkit  2.0.0
packetCombiner.hpp
Go to the documentation of this file.
1 
12 #include <map>
13 #include <vector>
14 
15 #include "fitsConverterIf.hpp"
16 
24 
25  bool operator <(const StreamIdentifier& rhs) const {
26  if(topic_id != rhs.topic_id) {
27  return topic_id < rhs.topic_id;
28  }
29  if(component_id != rhs.component_id) {
30  return component_id < rhs.component_id;
31  }
32 
33  return application_tag < rhs.application_tag;
34  }
35  bool operator ==(const StreamIdentifier& rhs) const {
36  return topic_id == rhs.topic_id &&
37  component_id == rhs.component_id &&
39  }
40  bool operator !=(const StreamIdentifier& rhs) const {
41  return not (*this == rhs);
42  }
43 
44  explicit StreamIdentifier(
45  int32_t new_topic_id,
46  uint16_t new_component_id,
47  uint16_t new_application_tag
48  ) : topic_id{new_topic_id}, component_id{new_component_id}, application_tag{new_application_tag} {}
49  StreamIdentifier() = default;
50 };
51 
58  bool operator <(const SampleIdentifier& rhs) const
59  {
60  if(stream_id != rhs.stream_id) {
61  stream_id < rhs.stream_id;
62  }
63  return sample_id < rhs.sample_id;
64  }
65  bool operator ==(const SampleIdentifier& rhs) const {
66  return stream_id == rhs.stream_id &&
67  sample_id == rhs.sample_id;
68  }
69  bool operator !=(const SampleIdentifier& rhs) const {
70  return not (*this == rhs);
71  }
72  explicit SampleIdentifier(
73  StreamIdentifier new_stream_id,
74  uint32_t new_sample_id
75  ) : stream_id{new_stream_id}, sample_id{new_sample_id} {}
76  SampleIdentifier() = default;
77 };
78 
85 
86  bool operator <(const FrameIdentifier& rhs) const
87  {
88  if(sample_id != rhs.sample_id) {
89  sample_id < rhs.sample_id;
90  }
91  return frame_id < rhs.frame_id;
92  }
93  bool operator ==(const FrameIdentifier& rhs) const {
94  return sample_id == rhs.sample_id &&
95  frame_id == rhs.frame_id;
96  }
97  bool operator !=(const FrameIdentifier& rhs) const {
98  return not (*this == rhs);
99  }
100 
101  explicit FrameIdentifier(
102  SampleIdentifier new_sample_id,
103  uint16_t new_frame_id
104  ) : sample_id{new_sample_id}, frame_id{new_frame_id} {}
105  FrameIdentifier() = default;
106 };
107 
115 };
116 
121  // MUDPI frame_id value
123  // MUDPI frame_count value
125  // Frame type
127  // rtms simulated flag
128  bool simulated;
129  // rtms little_endian flag
131  // rtms status field
133  // mudpi timestamp
135  // timestamp from the pcap capture
137 
138  explicit FrameMetadata(uint16_t new_frame_id,
139  uint16_t new_frame_count,
140  enum RTMSFrameType new_frame_type,
141  bool new_simulated,
142  bool new_little_endian,
143  uint32_t new_status,
144  double new_mudpi_timestamp,
145  double new_pcap_timestamp)
146  : frame_id{new_frame_id}
147  , frame_count{new_frame_count}
148  , frame_type{new_frame_type}
149  , simulated{new_simulated}
150  , little_endian{new_little_endian}
151  , status{new_status}
152  , mudpi_timestamp{new_mudpi_timestamp}
153  , pcap_timestamp{new_pcap_timestamp} { }
154  FrameMetadata() = default;
155 };
156 
162  std::vector<uint8_t> payload_data;
163  std::map<uint16_t, FrameMetadata> metadata;
164 
165  explicit CombinedFrames(SampleIdentifier new_identifier,
166  std::vector<uint8_t> new_payload_data,
167  std::map<uint16_t, FrameMetadata> new_metadata)
168  : identifier{new_identifier}, payload_data{std::move(new_payload_data)}, metadata{std::move(new_metadata)} { }
169  CombinedFrames() = default;
170 };
171 
176  public:
181  explicit PacketCombiner(std::function<void(const CombinedFrames&)> callback);
186  void AddSample(const PacketData& data);
187 
188  private:
189  void CombineFrames(const SampleIdentifier& sample_id);
190  std::map<SampleIdentifier, std::map<uint16_t, FrameMetadata>> m_packet_meta_data;
191  std::map<SampleIdentifier, std::map<uint16_t, std::vector<uint8_t>>> m_packet_payloads;
192  std::map<SampleIdentifier, uint16_t> m_frame_count;
193  std::function<void(const CombinedFrames&)> m_callback;
194 
195 };
RTMSFrameType
RTMSFrameType
Possible frame types of a RTMS packet.
Definition: packetCombiner.hpp:111
SampleIdentifier::operator==
bool operator==(const SampleIdentifier &rhs) const
Definition: packetCombiner.hpp:65
StreamIdentifier::operator<
bool operator<(const StreamIdentifier &rhs) const
Definition: packetCombiner.hpp:25
RTMS_PAYLOAD
@ RTMS_PAYLOAD
Definition: packetCombiner.hpp:113
StreamIdentifier
Unique identifier for packets of a single stream.
Definition: packetCombiner.hpp:20
fitsConverterIf.hpp
Fits converter Interface.
FrameMetadata::mudpi_timestamp
double mudpi_timestamp
Definition: packetCombiner.hpp:134
StreamIdentifier::StreamIdentifier
StreamIdentifier(int32_t new_topic_id, uint16_t new_component_id, uint16_t new_application_tag)
Definition: packetCombiner.hpp:44
FrameMetadata::pcap_timestamp
double pcap_timestamp
Definition: packetCombiner.hpp:136
FrameIdentifier::FrameIdentifier
FrameIdentifier(SampleIdentifier new_sample_id, uint16_t new_frame_id)
Definition: packetCombiner.hpp:101
FrameMetadata::little_endian
bool little_endian
Definition: packetCombiner.hpp:130
FrameIdentifier::sample_id
SampleIdentifier sample_id
Definition: packetCombiner.hpp:83
PacketCombiner::PacketCombiner
PacketCombiner(std::function< void(const CombinedFrames &)> callback)
This creates a new Packet combiner.
Definition: packetCombiner.cpp:15
FrameMetadata::frame_count
uint16_t frame_count
Definition: packetCombiner.hpp:124
FrameIdentifier::FrameIdentifier
FrameIdentifier()=default
FrameMetadata::frame_id
uint16_t frame_id
Definition: packetCombiner.hpp:122
StreamIdentifier::operator!=
bool operator!=(const StreamIdentifier &rhs) const
Definition: packetCombiner.hpp:40
FrameIdentifier::operator!=
bool operator!=(const FrameIdentifier &rhs) const
Definition: packetCombiner.hpp:97
CombinedFrames
Data about the combined packets of a single sample.
Definition: packetCombiner.hpp:160
FrameMetadata::status
uint32_t status
Definition: packetCombiner.hpp:132
PacketCombiner::AddSample
void AddSample(const PacketData &data)
This function is called to add a new packet to be combined with the others.
Definition: packetCombiner.cpp:21
SampleIdentifier
Unique identifier for packets of a single sample.
Definition: packetCombiner.hpp:55
RTMS_TRAILER
@ RTMS_TRAILER
Definition: packetCombiner.hpp:114
StreamIdentifier::component_id
uint16_t component_id
Definition: packetCombiner.hpp:22
mudpi::uint16_t
unsigned short uint16_t
Definition: mudpi.h:15
StreamIdentifier::StreamIdentifier
StreamIdentifier()=default
SampleIdentifier::SampleIdentifier
SampleIdentifier(StreamIdentifier new_stream_id, uint32_t new_sample_id)
Definition: packetCombiner.hpp:72
FrameMetadata::FrameMetadata
FrameMetadata(uint16_t new_frame_id, uint16_t new_frame_count, enum RTMSFrameType new_frame_type, bool new_simulated, bool new_little_endian, uint32_t new_status, double new_mudpi_timestamp, double new_pcap_timestamp)
Definition: packetCombiner.hpp:138
CombinedFrames::CombinedFrames
CombinedFrames()=default
FrameIdentifier::operator==
bool operator==(const FrameIdentifier &rhs) const
Definition: packetCombiner.hpp:93
SampleIdentifier::operator<
bool operator<(const SampleIdentifier &rhs) const
Definition: packetCombiner.hpp:58
StreamIdentifier::operator==
bool operator==(const StreamIdentifier &rhs) const
Definition: packetCombiner.hpp:35
FrameMetadata
Metadata for a single frame.
Definition: packetCombiner.hpp:120
FrameIdentifier::frame_id
uint16_t frame_id
Definition: packetCombiner.hpp:84
FrameMetadata::frame_type
enum RTMSFrameType frame_type
Definition: packetCombiner.hpp:126
SampleIdentifier::SampleIdentifier
SampleIdentifier()=default
FrameIdentifier::operator<
bool operator<(const FrameIdentifier &rhs) const
Definition: packetCombiner.hpp:86
mudpi::uint32_t
unsigned int uint32_t
Definition: mudpi.h:16
PacketCombiner
This class combines the packets of a sample.
Definition: packetCombiner.hpp:175
PacketData
Definition: fitsConverterIf.hpp:22
mudpi::int32_t
int int32_t
Definition: mudpi.h:17
CombinedFrames::payload_data
std::vector< uint8_t > payload_data
Definition: packetCombiner.hpp:162
CombinedFrames::identifier
SampleIdentifier identifier
Definition: packetCombiner.hpp:161
FrameMetadata::FrameMetadata
FrameMetadata()=default
StreamIdentifier::topic_id
int32_t topic_id
Definition: packetCombiner.hpp:21
CombinedFrames::CombinedFrames
CombinedFrames(SampleIdentifier new_identifier, std::vector< uint8_t > new_payload_data, std::map< uint16_t, FrameMetadata > new_metadata)
Definition: packetCombiner.hpp:165
FrameIdentifier
Unique identifier for packets of a single frame.
Definition: packetCombiner.hpp:82
CombinedFrames::metadata
std::map< uint16_t, FrameMetadata > metadata
Definition: packetCombiner.hpp:163
SampleIdentifier::operator!=
bool operator!=(const SampleIdentifier &rhs) const
Definition: packetCombiner.hpp:69
StreamIdentifier::application_tag
uint16_t application_tag
Definition: packetCombiner.hpp:23
RTMS_LEADER
@ RTMS_LEADER
Definition: packetCombiner.hpp:112
SampleIdentifier::stream_id
StreamIdentifier stream_id
Definition: packetCombiner.hpp:56
FrameMetadata::simulated
bool simulated
Definition: packetCombiner.hpp:128
SampleIdentifier::sample_id
uint32_t sample_id
Definition: packetCombiner.hpp:57