1#ifndef MILLICAST_API_STATS_H
2#define MILLICAST_API_STATS_H
59 const T* cast_to()
const {
60 return static_cast<const T*
>(
this);
63 virtual ~Stats() =
default;
66struct Codecs :
public Stats {
67 enum class Type { ENCODE, DECODE };
68 static constexpr auto STYPE = ::millicast::rtcstats::Type::CODEC;
70 unsigned long payload_type;
71 std::string transport_id;
72 std::string mime_type;
74 std::optional<Type> codec_type;
75 std::optional<unsigned long> clock_rate;
76 std::optional<unsigned long> channels;
77 std::optional<std::string> sdp_fmtp_line;
80struct RTCIceCandidatePair :
public Stats {
81 static constexpr auto STYPE = Type::RTC_ICE_CANDIDATE;
82 std::optional<double> total_round_trip_time;
83 std::optional<double> current_round_trip_time;
84 std::optional<double> available_outgoing_bitrate;
85 std::optional<double> available_incoming_bitrate;
88struct RtpStream :
public Stats {
91 std::optional<std::string> transport_id;
92 std::optional<std::string> codec_id;
95struct ReceivedRtpStream :
public RtpStream {
96 static constexpr auto STYPE = Type::INBOUND_RTP;
98 std::optional<unsigned long long> packets_received;
99 std::optional<double> jitter;
100 std::optional<long long> packets_lost;
101 std::optional<unsigned long long> frames_dropped;
104struct InboundRtpStream :
public ReceivedRtpStream {
105 static constexpr auto STYPE = Type::INBOUND_RTP;
107 std::optional<std::string> remote_id;
108 std::optional<std::string> mid;
109 std::optional<std::string> track_identifier;
110 std::optional<unsigned long> frames_decoded;
111 std::optional<unsigned long> key_frames_decoded;
112 std::optional<unsigned long> nack_count;
113 std::optional<unsigned long long> fir_count;
114 std::optional<unsigned long long> pli_count;
115 std::optional<unsigned long> frames_received;
116 std::optional<unsigned long> frame_width;
117 std::optional<unsigned long> frame_height;
118 std::optional<double> frames_per_second;
119 std::optional<unsigned long long> bytes_received;
120 std::optional<unsigned long long> header_bytes_received;
121 std::optional<unsigned long long> last_packet_received_timestamp;
122 std::optional<double> audio_level;
123 std::optional<double> total_audio_energy;
124 std::optional<unsigned long long> fec_packets_received;
125 std::optional<unsigned long long> fec_packets_discarded;
126 std::optional<unsigned long long> total_samples_received;
127 std::optional<unsigned long long> concealed_samples;
128 std::optional<unsigned long long> silent_concealed_samples;
129 std::optional<unsigned long long> concealment_events;
130 std::optional<unsigned long long> inserted_samples_for_deceleration;
131 std::optional<unsigned long long> removed_samples_for_acceleration;
132 std::optional<unsigned long long> frames_assembled_from_multiple_packets;
133 std::optional<double> total_samples_duration;
134 std::optional<std::string> decoder_implementation;
136 std::optional<unsigned long long> retransmitted_packets_received;
137 std::optional<unsigned long long> retransmitted_bytes_received;
139 std::optional<double> jitter_buffer_delay;
140 std::optional<double> jitter_buffer_target_delay;
141 std::optional<double> jitter_buffer_minimum_delay;
142 std::optional<double> total_processing_delay;
143 std::optional<double> total_decode_time;
144 std::optional<double> total_assembly_time;
145 std::optional<double> total_inter_frame_delay;
146 std::optional<double> total_squared_inter_frame_delay;
148 std::optional<uint32_t> freeze_count;
149 std::optional<double> total_freezes_duration;
151 std::optional<uint32_t> pause_count;
152 std::optional<double> total_pauses_duration;
154 std::optional<uint64_t> jitter_buffer_emitted_count;
155 std::optional<uint64_t> estimated_playout_timestamp;
156 std::optional<double> min_playout_delay;
159struct SentRtpStream :
public RtpStream {
160 static constexpr auto STYPE = Type::OUTBOUND_RTP;
161 unsigned long packets_sent;
162 unsigned long retransmitted_packets_sent;
163 unsigned long long bytes_sent;
164 unsigned long retransmitted_bytes_sent;
165 unsigned long long header_bytes_sent;
168struct OutboundRtpStream :
public SentRtpStream {
169 static constexpr auto STYPE = Type::OUTBOUND_RTP;
170 std::optional<std::string> sender_id;
171 std::optional<std::string> remote_id;
172 std::optional<double> target_bitrate;
173 std::optional<unsigned long> frame_width;
174 std::optional<unsigned long> frame_height;
175 std::optional<double> frames_per_second;
176 std::optional<unsigned long> frames_sent;
177 std::optional<unsigned long> huge_frames_sent;
178 std::optional<unsigned long> total_packet_send_delay;
179 std::optional<unsigned long> frames_encoded;
180 std::optional<unsigned long> key_frames_encoded;
181 std::optional<unsigned long> total_encoded_bytes_target;
182 std::optional<unsigned long> nack_count;
183 std::optional<unsigned long> fir_count;
184 std::optional<unsigned long> pli_count;
185 std::optional<unsigned long> qp_sum;
186 std::optional<std::string> quality_limitation_durations;
187 std::optional<unsigned int> quality_limitation_resolution_changes;
188 std::optional<std::string> quality_limitation_reason;
189 std::optional<std::string> encoder_implementation;
192struct RemoteOutboundRtpStream :
public SentRtpStream {
193 static constexpr auto STYPE = Type::REMOTE_OUTBOUND_RTP;
194 std::string local_id;
195 double remote_timestamp;
196 unsigned long long reports_sent;
197 double round_trip_time;
198 unsigned long long round_trip_time_measurements;
199 double total_round_trip_time;
202struct RemoteInboundRtpStream :
public ReceivedRtpStream {
203 static constexpr auto STYPE = Type::REMOTE_INBOUND_RTP;
204 std::string local_id;
205 double round_trip_time;
206 double total_round_trip_time;
207 unsigned long round_trip_time_measurements;
208 double fraction_lost;
211struct MediaSource :
public Stats {
212 static constexpr auto STYPE = Type::MEDIA_SOURCE;
213 std::string track_identifier;
217struct VideoSource :
public MediaSource {
218 static constexpr auto STYPE = Type::VIDEO_SOURCE;
219 std::optional<unsigned long> width;
220 std::optional<unsigned long> height;
221 std::optional<unsigned long> frames;
222 std::optional<double> frames_per_second;
225struct AudioSource :
public MediaSource {
226 static constexpr auto STYPE = Type::AUDIO_SOURCE;
227 std::optional<double> audio_level;
228 std::optional<double> total_audio_energy;
229 std::optional<double> total_samples_duration;
230 std::optional<double> echo_return_loss;
231 std::optional<double> echo_return_loss_enhancement;
235using StatObject = std::unique_ptr<const rtcstats::Stats>;
239 class const_iterator {
240 std::map<std::string, StatObject>::const_iterator _it;
243 const_iterator(std::map<std::string, StatObject>::const_iterator it)
245 const_iterator(const_iterator&& other) =
default;
246 ~const_iterator() =
default;
248 const_iterator& operator++() {
252 const_iterator& operator++(
int) {
return ++(*this); }
253 const rtcstats::Stats& operator*()
const {
return *_it->second.get(); }
254 const rtcstats::Stats* operator->()
const {
return _it->second.get(); }
255 bool operator==(
const const_iterator& other)
const {
256 return _it == other._it;
258 bool operator!=(
const const_iterator& other)
const {
259 return !(*
this == other);
264 virtual ~StatsReport() =
default;
266 virtual void add_stats(StatObject stats) = 0;
267 [[nodiscard]]
virtual const rtcstats::Stats* get(
268 const std::string&
id)
const = 0;
269 template <
typename T>
270 const T* get_as(
const std::string&
id)
const {
271 const rtcstats::Stats* stats = get(
id);
272 if (!stats || stats->type != T::STYPE) {
276 return stats->cast_to<
const T>();
279 [[nodiscard]]
virtual const_iterator begin()
const = 0;
280 [[nodiscard]]
virtual const_iterator end()
const = 0;
282 template <
typename T>
283 std::vector<const T*> get_stats_of_type()
const {
284 std::vector<const T*> stats_of_type;
285 for (
const auto& stats : *
this) {
286 if (stats.type == T::STYPE) {
287 stats_of_type.push_back(stats.cast_to<
const T>());
290 return stats_of_type;
296 virtual StreamDetails stream_details()
const = 0;
300 virtual StatObject take(
const std::string&
id) = 0;
302 [[nodiscard]]
virtual size_t size()
const = 0;
#define MILLICAST_API
Definition exports.h:51