MillicastSDK 2.0.0
Loading...
Searching...
No Matches
stats.h
Go to the documentation of this file.
1#ifndef MILLICAST_API_STATS_H
2#define MILLICAST_API_STATS_H
3
11#include <map>
12#include <memory>
13#include <optional>
14#include <string>
15#include <vector>
16
19
20namespace millicast {
21namespace rtcstats {
22
23enum class Type {
24 CODEC,
33};
34
35struct Stats {
40 int64_t timestamp;
41
45 std::string id;
46
51
56 template <typename T>
57 const T* cast_to() const {
58 return static_cast<const T*>(this);
59 }
60
61 virtual ~Stats() = default;
62};
63
64struct Codecs : public Stats {
65 enum class Type { ENCODE, DECODE };
67
68 unsigned long payload_type;
69 std::string transport_id;
70 std::string mime_type;
71
72 std::optional<Type> codec_type;
73 std::optional<unsigned long> clock_rate;
74 std::optional<unsigned long> channels;
75 std::optional<std::string> sdp_fmtp_line;
76};
77
78struct RTCIceCandidatePair : public Stats {
79 static constexpr auto STYPE = Type::RTC_ICE_CANDIDATE;
80 std::optional<double> total_round_trip_time;
81 std::optional<double> current_round_trip_time;
82 std::optional<double> available_outgoing_bitrate;
83 std::optional<double> available_incoming_bitrate;
84};
85
86struct RtpStream : public Stats {
87 unsigned long ssrc;
88 std::string kind;
89 std::optional<std::string> transport_id;
90 std::optional<std::string> codec_id;
91};
92
94 static constexpr auto STYPE = Type::INBOUND_RTP;
95
96 std::optional<unsigned long long> packets_received;
97 std::optional<double> jitter;
98 std::optional<long long> packets_lost;
99 std::optional<unsigned long long> frames_dropped;
100};
101
103 static constexpr auto STYPE = Type::INBOUND_RTP;
104
105 std::optional<std::string> remote_id;
106 std::optional<std::string> mid;
107 std::optional<std::string> track_identifier;
108 std::optional<unsigned long> frames_decoded;
109 std::optional<unsigned long> key_frames_decoded;
110 std::optional<unsigned long> nack_count;
111 std::optional<unsigned long long> fir_count;
112 std::optional<unsigned long long> pli_count;
113 std::optional<unsigned long> frames_received;
114 std::optional<unsigned long> frame_width;
115 std::optional<unsigned long> frame_height;
116 std::optional<double> frames_per_second;
117 std::optional<unsigned long long> bytes_received;
118 std::optional<unsigned long long> header_bytes_received;
119 std::optional<unsigned long long> last_packet_received_timestamp;
120 std::optional<double> audio_level;
121 std::optional<double> total_audio_energy;
122 std::optional<unsigned long long> fec_packets_received;
123 std::optional<unsigned long long> fec_packets_discarded;
124 std::optional<unsigned long long> total_samples_received;
125 std::optional<unsigned long long> concealed_samples;
126 std::optional<unsigned long long> silent_concealed_samples;
127 std::optional<unsigned long long> concealment_events;
128 std::optional<unsigned long long> inserted_samples_for_deceleration;
129 std::optional<unsigned long long> removed_samples_for_acceleration;
130 std::optional<unsigned long long> frames_assembled_from_multiple_packets;
131 std::optional<double> total_samples_duration;
132 std::optional<std::string> decoder_implementation;
133
134 std::optional<unsigned long long> retransmitted_packets_received;
135 std::optional<unsigned long long> retransmitted_bytes_received;
136
137 std::optional<double> jitter_buffer_delay;
138 std::optional<double> jitter_buffer_target_delay;
139 std::optional<double> jitter_buffer_minimum_delay;
140 std::optional<double> total_processing_delay;
141 std::optional<double> total_decode_time;
142 std::optional<double> total_assembly_time;
143 std::optional<double> total_inter_frame_delay;
144 std::optional<double> total_squared_inter_frame_delay;
145
146 std::optional<uint32_t> freeze_count;
147 std::optional<double> total_freezes_duration;
148
149 std::optional<uint32_t> pause_count;
150 std::optional<double> total_pauses_duration;
151
152 std::optional<uint64_t> jitter_buffer_emitted_count;
153 std::optional<uint64_t> estimated_playout_timestamp;
154 std::optional<double> min_playout_delay;
155};
156
157struct SentRtpStream : public RtpStream {
158 static constexpr auto STYPE = Type::OUTBOUND_RTP;
159 unsigned long packets_sent;
161 unsigned long long bytes_sent;
163 unsigned long long header_bytes_sent;
164};
165
167 static constexpr auto STYPE = Type::OUTBOUND_RTP;
168 std::optional<std::string> sender_id;
169 std::optional<std::string> remote_id;
170 std::optional<double> target_bitrate;
171 std::optional<unsigned long> frame_width;
172 std::optional<unsigned long> frame_height;
173 std::optional<double> frames_per_second;
174 std::optional<unsigned long> frames_sent;
175 std::optional<unsigned long> huge_frames_sent;
176 std::optional<unsigned long> total_packet_send_delay;
177 std::optional<unsigned long> frames_encoded;
178 std::optional<unsigned long> key_frames_encoded;
179 std::optional<unsigned long> total_encoded_bytes_target;
180 std::optional<unsigned long> nack_count;
181 std::optional<unsigned long> fir_count;
182 std::optional<unsigned long> pli_count;
183 std::optional<unsigned long> qp_sum;
184 std::optional<std::string> quality_limitation_durations;
185 std::optional<unsigned int> quality_limitation_resolution_changes;
186 std::optional<std::string> quality_limitation_reason;
187 std::optional<std::string> encoder_implementation;
188};
189
191 static constexpr auto STYPE = Type::REMOTE_OUTBOUND_RTP;
192 std::string local_id;
194 unsigned long long reports_sent;
198};
199
201 static constexpr auto STYPE = Type::REMOTE_INBOUND_RTP;
202 std::string local_id;
206 double fraction_lost; // fraction packet loss
207};
208
209struct MediaSource : public Stats {
210 static constexpr auto STYPE = Type::MEDIA_SOURCE;
211 std::string track_identifier;
212 std::string kind;
213};
214
215struct VideoSource : public MediaSource {
216 static constexpr auto STYPE = Type::VIDEO_SOURCE;
217 std::optional<unsigned long> width;
218 std::optional<unsigned long> height;
219 std::optional<unsigned long> frames;
220 std::optional<double> frames_per_second;
221};
222
223struct AudioSource : public MediaSource {
224 static constexpr auto STYPE = Type::AUDIO_SOURCE;
225 std::optional<double> audio_level;
226 std::optional<double> total_audio_energy;
227 std::optional<double> total_samples_duration;
228 std::optional<double> echo_return_loss;
229 std::optional<double> echo_return_loss_enhancement;
230};
231} // namespace rtcstats
232
233using StatObject = std::unique_ptr<const rtcstats::Stats>;
234
236 public:
237 class const_iterator { // NOLINT
238 std::map<std::string, StatObject>::const_iterator _it;
239
240 public:
241 const_iterator(std::map<std::string, StatObject>::const_iterator it)
242 : _it(it) {}
243 const_iterator(const_iterator&& other) = default;
244 ~const_iterator() = default;
245
247 ++_it;
248 return *this;
249 }
250 const_iterator& operator++(int) { return ++(*this); }
251 const rtcstats::Stats& operator*() const { return *_it->second.get(); }
252 const rtcstats::Stats* operator->() const { return _it->second.get(); }
253 bool operator==(const const_iterator& other) const {
254 return _it == other._it;
255 }
256 bool operator!=(const const_iterator& other) const {
257 return !(*this == other);
258 }
259 };
260
262 virtual ~StatsReport() = default;
263
264 virtual void add_stats(StatObject stats) = 0;
265 [[nodiscard]] virtual const rtcstats::Stats* get(
266 const std::string& id) const = 0;
267 template <typename T>
268 const T* get_as(const std::string& id) const {
269 const rtcstats::Stats* stats = get(id);
270 if (!stats || stats->type != T::STYPE) {
271 return nullptr;
272 }
273
274 return stats->cast_to<const T>();
275 }
276
277 [[nodiscard]] virtual const_iterator begin() const = 0;
278 [[nodiscard]] virtual const_iterator end() const = 0;
279
280 template <typename T>
281 std::vector<const T*> get_stats_of_type() const {
282 std::vector<const T*> stats_of_type;
283 for (const auto& stats : *this) {
284 if (stats.type == T::STYPE) {
285 stats_of_type.push_back(stats.cast_to<const T>());
286 }
287 }
288 return stats_of_type;
289 }
294 virtual StreamDetails stream_details() const = 0;
295
296 // Removes the stats object from the report, returning ownership of it or null
297 // if there is no object with `id`.
298 virtual StatObject take(const std::string& id) = 0;
299
300 [[nodiscard]] virtual size_t size() const = 0;
301};
302
303} // namespace millicast
304
305#endif /* MILLICAST_API_STATS_H */
const_iterator(std::map< std::string, StatObject >::const_iterator it)
Definition stats.h:241
const_iterator(const_iterator &&other)=default
const_iterator & operator++(int)
Definition stats.h:250
const rtcstats::Stats & operator*() const
Definition stats.h:251
const rtcstats::Stats * operator->() const
Definition stats.h:252
bool operator!=(const const_iterator &other) const
Definition stats.h:256
const_iterator & operator++()
Definition stats.h:246
bool operator==(const const_iterator &other) const
Definition stats.h:253
Definition stats.h:235
virtual ~StatsReport()=default
const T * get_as(const std::string &id) const
Definition stats.h:268
virtual const rtcstats::Stats * get(const std::string &id) const =0
std::vector< const T * > get_stats_of_type() const
Definition stats.h:281
virtual const_iterator end() const =0
virtual StreamDetails stream_details() const =0
Get the current stream details associated with this session.
virtual const_iterator begin() const =0
virtual void add_stats(StatObject stats)=0
virtual size_t size() const =0
virtual StatObject take(const std::string &id)=0
#define MILLICAST_API
Definition exports.h:51
Type
Definition stats.h:23
Definition capabilities.h:15
std::variant< StreamViewDetails, StreamPublishDetails > StreamDetails
Definition diagnostics.h:33
std::unique_ptr< const rtcstats::Stats > StatObject
Definition stats.h:233
Definition stats.h:223
static constexpr auto STYPE
Definition stats.h:224
std::optional< double > echo_return_loss_enhancement
Definition stats.h:229
std::optional< double > total_samples_duration
Definition stats.h:227
std::optional< double > total_audio_energy
Definition stats.h:226
std::optional< double > echo_return_loss
Definition stats.h:228
std::optional< double > audio_level
Definition stats.h:225
Definition stats.h:64
std::string transport_id
Definition stats.h:69
std::string mime_type
Definition stats.h:70
std::optional< unsigned long > clock_rate
Definition stats.h:73
std::optional< unsigned long > channels
Definition stats.h:74
static constexpr auto STYPE
Definition stats.h:66
std::optional< Type > codec_type
Definition stats.h:72
std::optional< std::string > sdp_fmtp_line
Definition stats.h:75
unsigned long payload_type
Definition stats.h:68
Type
Definition stats.h:65
std::optional< unsigned long long > fir_count
Definition stats.h:111
std::optional< double > total_pauses_duration
Definition stats.h:150
std::optional< unsigned long long > frames_assembled_from_multiple_packets
Definition stats.h:130
std::optional< uint64_t > estimated_playout_timestamp
Definition stats.h:153
std::optional< double > total_freezes_duration
Definition stats.h:147
std::optional< unsigned long long > retransmitted_packets_received
Definition stats.h:134
std::optional< unsigned long long > last_packet_received_timestamp
Definition stats.h:119
std::optional< unsigned long long > concealment_events
Definition stats.h:127
std::optional< double > total_samples_duration
Definition stats.h:131
std::optional< double > total_assembly_time
Definition stats.h:142
std::optional< unsigned long > frames_received
Definition stats.h:113
std::optional< std::string > decoder_implementation
Definition stats.h:132
std::optional< double > total_audio_energy
Definition stats.h:121
std::optional< unsigned long long > concealed_samples
Definition stats.h:125
std::optional< double > jitter_buffer_target_delay
Definition stats.h:138
std::optional< std::string > mid
Definition stats.h:106
std::optional< unsigned long long > total_samples_received
Definition stats.h:124
std::optional< double > jitter_buffer_delay
Definition stats.h:137
std::optional< unsigned long > nack_count
Definition stats.h:110
std::optional< unsigned long long > pli_count
Definition stats.h:112
std::optional< unsigned long long > header_bytes_received
Definition stats.h:118
std::optional< unsigned long > frame_width
Definition stats.h:114
std::optional< unsigned long > frame_height
Definition stats.h:115
std::optional< unsigned long long > removed_samples_for_acceleration
Definition stats.h:129
std::optional< double > frames_per_second
Definition stats.h:116
std::optional< unsigned long long > bytes_received
Definition stats.h:117
std::optional< std::string > track_identifier
Definition stats.h:107
std::optional< double > total_decode_time
Definition stats.h:141
std::optional< uint32_t > freeze_count
Definition stats.h:146
std::optional< unsigned long > key_frames_decoded
Definition stats.h:109
std::optional< double > total_processing_delay
Definition stats.h:140
std::optional< unsigned long long > inserted_samples_for_deceleration
Definition stats.h:128
std::optional< uint64_t > jitter_buffer_emitted_count
Definition stats.h:152
std::optional< double > min_playout_delay
Definition stats.h:154
std::optional< double > audio_level
Definition stats.h:120
std::optional< unsigned long long > fec_packets_received
Definition stats.h:122
std::optional< uint32_t > pause_count
Definition stats.h:149
std::optional< unsigned long long > fec_packets_discarded
Definition stats.h:123
std::optional< double > total_inter_frame_delay
Definition stats.h:143
std::optional< double > jitter_buffer_minimum_delay
Definition stats.h:139
std::optional< unsigned long long > retransmitted_bytes_received
Definition stats.h:135
std::optional< std::string > remote_id
Definition stats.h:105
std::optional< double > total_squared_inter_frame_delay
Definition stats.h:144
std::optional< unsigned long > frames_decoded
Definition stats.h:108
static constexpr auto STYPE
Definition stats.h:103
std::optional< unsigned long long > silent_concealed_samples
Definition stats.h:126
Definition stats.h:209
std::string track_identifier
Definition stats.h:211
static constexpr auto STYPE
Definition stats.h:210
std::string kind
Definition stats.h:212
std::optional< unsigned long > huge_frames_sent
Definition stats.h:175
std::optional< unsigned int > quality_limitation_resolution_changes
Definition stats.h:185
std::optional< std::string > sender_id
Definition stats.h:168
static constexpr auto STYPE
Definition stats.h:167
std::optional< std::string > quality_limitation_durations
Definition stats.h:184
std::optional< std::string > encoder_implementation
Definition stats.h:187
std::optional< std::string > remote_id
Definition stats.h:169
std::optional< unsigned long > frames_sent
Definition stats.h:174
std::optional< unsigned long > pli_count
Definition stats.h:182
std::optional< unsigned long > frames_encoded
Definition stats.h:177
std::optional< double > target_bitrate
Definition stats.h:170
std::optional< unsigned long > qp_sum
Definition stats.h:183
std::optional< unsigned long > frame_height
Definition stats.h:172
std::optional< unsigned long > nack_count
Definition stats.h:180
std::optional< unsigned long > total_packet_send_delay
Definition stats.h:176
std::optional< unsigned long > fir_count
Definition stats.h:181
std::optional< double > frames_per_second
Definition stats.h:173
std::optional< unsigned long > total_encoded_bytes_target
Definition stats.h:179
std::optional< unsigned long > key_frames_encoded
Definition stats.h:178
std::optional< std::string > quality_limitation_reason
Definition stats.h:186
std::optional< unsigned long > frame_width
Definition stats.h:171
std::optional< double > total_round_trip_time
Definition stats.h:80
std::optional< double > available_outgoing_bitrate
Definition stats.h:82
std::optional< double > current_round_trip_time
Definition stats.h:81
static constexpr auto STYPE
Definition stats.h:79
std::optional< double > available_incoming_bitrate
Definition stats.h:83
std::optional< unsigned long long > frames_dropped
Definition stats.h:99
std::optional< unsigned long long > packets_received
Definition stats.h:96
std::optional< long long > packets_lost
Definition stats.h:98
static constexpr auto STYPE
Definition stats.h:94
std::optional< double > jitter
Definition stats.h:97
double total_round_trip_time
Definition stats.h:204
unsigned long round_trip_time_measurements
Definition stats.h:205
double fraction_lost
Definition stats.h:206
std::string local_id
Definition stats.h:202
double round_trip_time
Definition stats.h:203
static constexpr auto STYPE
Definition stats.h:201
double round_trip_time
Definition stats.h:195
double total_round_trip_time
Definition stats.h:197
unsigned long long round_trip_time_measurements
Definition stats.h:196
unsigned long long reports_sent
Definition stats.h:194
double remote_timestamp
Definition stats.h:193
std::string local_id
Definition stats.h:192
static constexpr auto STYPE
Definition stats.h:191
Definition stats.h:86
std::optional< std::string > codec_id
Definition stats.h:90
std::optional< std::string > transport_id
Definition stats.h:89
unsigned long ssrc
Definition stats.h:87
std::string kind
Definition stats.h:88
unsigned long long bytes_sent
Definition stats.h:161
unsigned long retransmitted_bytes_sent
Definition stats.h:162
unsigned long retransmitted_packets_sent
Definition stats.h:160
static constexpr auto STYPE
Definition stats.h:158
unsigned long long header_bytes_sent
Definition stats.h:163
unsigned long packets_sent
Definition stats.h:159
Definition stats.h:35
std::string id
The WebRTC identifier for the statistics.
Definition stats.h:45
Type type
Type of statistics.
Definition stats.h:50
int64_t timestamp
The timestamp in Milliseconds since Unix Epoch (Jan 1, 1970 00:00:00 UTC).
Definition stats.h:40
const T * cast_to() const
Cast the statistics to their true type. Make sure to use.
Definition stats.h:57
virtual ~Stats()=default
Definition stats.h:215
std::optional< unsigned long > frames
Definition stats.h:219
static constexpr auto STYPE
Definition stats.h:216
std::optional< unsigned long > width
Definition stats.h:217
std::optional< double > frames_per_second
Definition stats.h:220
std::optional< unsigned long > height
Definition stats.h:218