rtcstats_objects.h (19968B)
1 /* 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef API_STATS_RTCSTATS_OBJECTS_H_ 12 #define API_STATS_RTCSTATS_OBJECTS_H_ 13 14 #include <stdint.h> 15 16 #include <map> 17 #include <memory> 18 #include <optional> 19 #include <string> 20 21 #include "api/stats/rtc_stats.h" 22 #include "api/units/timestamp.h" 23 #include "rtc_base/system/rtc_export.h" 24 25 namespace webrtc { 26 27 // https://w3c.github.io/webrtc-stats/#certificatestats-dict* 28 class RTC_EXPORT RTCCertificateStats final : public RTCStats { 29 public: 30 WEBRTC_RTCSTATS_DECL(RTCCertificateStats); 31 RTCCertificateStats(std::string id, Timestamp timestamp); 32 ~RTCCertificateStats() override; 33 34 std::optional<std::string> fingerprint; 35 std::optional<std::string> fingerprint_algorithm; 36 std::optional<std::string> base64_certificate; 37 std::optional<std::string> issuer_certificate_id; 38 }; 39 40 // https://w3c.github.io/webrtc-stats/#codec-dict* 41 class RTC_EXPORT RTCCodecStats final : public RTCStats { 42 public: 43 WEBRTC_RTCSTATS_DECL(RTCCodecStats); 44 RTCCodecStats(std::string id, Timestamp timestamp); 45 ~RTCCodecStats() override; 46 47 std::optional<std::string> transport_id; 48 std::optional<uint32_t> payload_type; 49 std::optional<std::string> mime_type; 50 std::optional<uint32_t> clock_rate; 51 std::optional<uint32_t> channels; 52 std::optional<std::string> sdp_fmtp_line; 53 }; 54 55 // https://w3c.github.io/webrtc-stats/#dcstats-dict* 56 class RTC_EXPORT RTCDataChannelStats final : public RTCStats { 57 public: 58 WEBRTC_RTCSTATS_DECL(RTCDataChannelStats); 59 RTCDataChannelStats(std::string id, Timestamp timestamp); 60 ~RTCDataChannelStats() override; 61 62 std::optional<std::string> label; 63 std::optional<std::string> protocol; 64 std::optional<int32_t> data_channel_identifier; 65 std::optional<std::string> state; 66 std::optional<uint32_t> messages_sent; 67 std::optional<uint64_t> bytes_sent; 68 std::optional<uint32_t> messages_received; 69 std::optional<uint64_t> bytes_received; 70 }; 71 72 // https://w3c.github.io/webrtc-stats/#candidatepair-dict* 73 class RTC_EXPORT RTCIceCandidatePairStats final : public RTCStats { 74 public: 75 WEBRTC_RTCSTATS_DECL(RTCIceCandidatePairStats); 76 RTCIceCandidatePairStats(std::string id, Timestamp timestamp); 77 ~RTCIceCandidatePairStats() override; 78 79 std::optional<std::string> transport_id; 80 std::optional<std::string> local_candidate_id; 81 std::optional<std::string> remote_candidate_id; 82 std::optional<std::string> state; 83 // Obsolete: priority 84 std::optional<uint64_t> priority; 85 std::optional<bool> nominated; 86 // `writable` does not exist in the spec and old comments suggest it used to 87 // exist but was incorrectly implemented. 88 // TODO(https://crbug.com/webrtc/14171): Standardize and/or modify 89 // implementation. 90 std::optional<bool> writable; 91 std::optional<uint64_t> packets_sent; 92 std::optional<uint64_t> packets_received; 93 std::optional<uint64_t> bytes_sent; 94 std::optional<uint64_t> bytes_received; 95 std::optional<double> total_round_trip_time; 96 std::optional<double> current_round_trip_time; 97 std::optional<double> available_outgoing_bitrate; 98 std::optional<double> available_incoming_bitrate; 99 std::optional<uint64_t> requests_received; 100 std::optional<uint64_t> requests_sent; 101 std::optional<uint64_t> responses_received; 102 std::optional<uint64_t> responses_sent; 103 std::optional<uint64_t> consent_requests_sent; 104 std::optional<uint64_t> packets_discarded_on_send; 105 std::optional<uint64_t> bytes_discarded_on_send; 106 std::optional<double> last_packet_received_timestamp; 107 std::optional<double> last_packet_sent_timestamp; 108 }; 109 110 // https://w3c.github.io/webrtc-stats/#icecandidate-dict* 111 class RTC_EXPORT RTCIceCandidateStats : public RTCStats { 112 public: 113 WEBRTC_RTCSTATS_DECL(RTCIceCandidateStats); 114 ~RTCIceCandidateStats() override; 115 116 std::optional<std::string> transport_id; 117 // Obsolete: is_remote 118 std::optional<bool> is_remote; 119 std::optional<std::string> network_type; 120 std::optional<std::string> ip; 121 std::optional<std::string> address; 122 std::optional<int32_t> port; 123 std::optional<std::string> protocol; 124 std::optional<std::string> relay_protocol; 125 std::optional<std::string> candidate_type; 126 std::optional<int32_t> priority; 127 std::optional<std::string> url; 128 std::optional<std::string> foundation; 129 std::optional<std::string> related_address; 130 std::optional<int32_t> related_port; 131 std::optional<std::string> username_fragment; 132 std::optional<std::string> tcp_type; 133 134 // The following metrics are NOT exposed to JavaScript. We should consider 135 // standardizing or removing them. 136 std::optional<bool> vpn; 137 std::optional<std::string> network_adapter_type; 138 139 protected: 140 RTCIceCandidateStats(std::string id, Timestamp timestamp, bool is_remote); 141 }; 142 143 // In the spec both local and remote varieties are of type RTCIceCandidateStats. 144 // But here we define them as subclasses of `RTCIceCandidateStats` because the 145 // `kType` need to be different ("RTCStatsType type") in the local/remote case. 146 // https://w3c.github.io/webrtc-stats/#rtcstatstype-str* 147 // This forces us to have to override copy() and type(). 148 class RTC_EXPORT RTCLocalIceCandidateStats final : public RTCIceCandidateStats { 149 public: 150 static const char kType[]; 151 RTCLocalIceCandidateStats(std::string id, Timestamp timestamp); 152 std::unique_ptr<RTCStats> copy() const override; 153 const char* type() const override; 154 }; 155 156 class RTC_EXPORT RTCRemoteIceCandidateStats final 157 : public RTCIceCandidateStats { 158 public: 159 static const char kType[]; 160 RTCRemoteIceCandidateStats(std::string id, Timestamp timestamp); 161 std::unique_ptr<RTCStats> copy() const override; 162 const char* type() const override; 163 }; 164 165 // https://w3c.github.io/webrtc-stats/#pcstats-dict* 166 class RTC_EXPORT RTCPeerConnectionStats final : public RTCStats { 167 public: 168 WEBRTC_RTCSTATS_DECL(RTCPeerConnectionStats); 169 RTCPeerConnectionStats(std::string id, Timestamp timestamp); 170 ~RTCPeerConnectionStats() override; 171 172 std::optional<uint32_t> data_channels_opened; 173 std::optional<uint32_t> data_channels_closed; 174 }; 175 176 // https://w3c.github.io/webrtc-stats/#streamstats-dict* 177 class RTC_EXPORT RTCRtpStreamStats : public RTCStats { 178 public: 179 WEBRTC_RTCSTATS_DECL(RTCRtpStreamStats); 180 ~RTCRtpStreamStats() override; 181 182 std::optional<uint32_t> ssrc; 183 std::optional<std::string> kind; 184 std::optional<std::string> transport_id; 185 std::optional<std::string> codec_id; 186 187 protected: 188 RTCRtpStreamStats(std::string id, Timestamp timestamp); 189 }; 190 191 // https://www.w3.org/TR/webrtc-stats/#receivedrtpstats-dict* 192 class RTC_EXPORT RTCReceivedRtpStreamStats : public RTCRtpStreamStats { 193 public: 194 WEBRTC_RTCSTATS_DECL(RTCReceivedRtpStreamStats); 195 ~RTCReceivedRtpStreamStats() override; 196 197 std::optional<double> jitter; 198 std::optional<int32_t> packets_lost; // Signed per RFC 3550 199 // https://w3c.github.io/webrtc-stats/#dom-rtcreceivedrtpstreamstats-packetsreceivedwithect1 200 std::optional<int64_t> packets_received_with_ect1; 201 // https://w3c.github.io/webrtc-stats/#dom-rtcreceivedrtpstreamstats-packetsreceivedwithce 202 std::optional<int64_t> packets_received_with_ce; 203 204 protected: 205 RTCReceivedRtpStreamStats(std::string id, Timestamp timestamp); 206 }; 207 208 // https://www.w3.org/TR/webrtc-stats/#sentrtpstats-dict* 209 class RTC_EXPORT RTCSentRtpStreamStats : public RTCRtpStreamStats { 210 public: 211 WEBRTC_RTCSTATS_DECL(RTCSentRtpStreamStats); 212 ~RTCSentRtpStreamStats() override; 213 214 std::optional<uint64_t> packets_sent; 215 std::optional<uint64_t> bytes_sent; 216 217 protected: 218 RTCSentRtpStreamStats(std::string id, Timestamp timestamp); 219 }; 220 221 // https://w3c.github.io/webrtc-stats/#inboundrtpstats-dict* 222 class RTC_EXPORT RTCInboundRtpStreamStats final 223 : public RTCReceivedRtpStreamStats { 224 public: 225 WEBRTC_RTCSTATS_DECL(RTCInboundRtpStreamStats); 226 RTCInboundRtpStreamStats(std::string id, Timestamp timestamp); 227 ~RTCInboundRtpStreamStats() override; 228 229 std::optional<std::string> playout_id; 230 std::optional<std::string> track_identifier; 231 std::optional<std::string> mid; 232 std::optional<std::string> remote_id; 233 std::optional<uint32_t> packets_received; 234 std::optional<uint64_t> packets_discarded; 235 std::optional<uint64_t> fec_packets_received; 236 std::optional<uint64_t> fec_bytes_received; 237 std::optional<uint64_t> fec_packets_discarded; 238 // Inbound FEC SSRC. Only present if a mechanism like FlexFEC is negotiated. 239 std::optional<uint32_t> fec_ssrc; 240 std::optional<uint64_t> bytes_received; 241 std::optional<uint64_t> header_bytes_received; 242 // Inbound RTX stats. Only defined when RTX is used and it is therefore 243 // possible to distinguish retransmissions. 244 std::optional<uint64_t> retransmitted_packets_received; 245 std::optional<uint64_t> retransmitted_bytes_received; 246 std::optional<uint32_t> rtx_ssrc; 247 248 std::optional<double> last_packet_received_timestamp; 249 std::optional<double> jitter_buffer_delay; 250 std::optional<double> jitter_buffer_target_delay; 251 std::optional<double> jitter_buffer_minimum_delay; 252 std::optional<uint64_t> jitter_buffer_emitted_count; 253 std::optional<uint64_t> total_samples_received; 254 std::optional<uint64_t> concealed_samples; 255 std::optional<uint64_t> silent_concealed_samples; 256 std::optional<uint64_t> concealment_events; 257 std::optional<uint64_t> inserted_samples_for_deceleration; 258 std::optional<uint64_t> removed_samples_for_acceleration; 259 std::optional<double> audio_level; 260 std::optional<double> total_audio_energy; 261 std::optional<double> total_samples_duration; 262 // Stats below are only implemented or defined for video. 263 std::optional<uint32_t> frames_received; 264 std::optional<uint32_t> frame_width; 265 std::optional<uint32_t> frame_height; 266 std::optional<double> frames_per_second; 267 std::optional<uint32_t> frames_decoded; 268 std::optional<uint32_t> key_frames_decoded; 269 std::optional<uint32_t> frames_dropped; 270 std::optional<double> total_decode_time; 271 std::optional<double> total_processing_delay; 272 std::optional<double> total_assembly_time; 273 std::optional<uint32_t> frames_assembled_from_multiple_packets; 274 // TODO(https://crbug.com/webrtc/15600): Implement framesRendered, which is 275 // incremented at the same time that totalInterFrameDelay and 276 // totalSquaredInterFrameDelay is incremented. (Dividing inter-frame delay by 277 // framesDecoded is slightly wrong.) 278 // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-framesrendered 279 // 280 // TODO(https://crbug.com/webrtc/15601): Inter-frame, pause and freeze metrics 281 // all related to when the frame is rendered, but our implementation measures 282 // at delivery to sink, not at actual render time. When we have an actual 283 // frame rendered callback, move the calculating of these metrics to there in 284 // order to make them more accurate. 285 std::optional<double> total_inter_frame_delay; 286 std::optional<double> total_squared_inter_frame_delay; 287 std::optional<uint32_t> pause_count; 288 std::optional<double> total_pauses_duration; 289 std::optional<uint32_t> freeze_count; 290 std::optional<double> total_freezes_duration; 291 // https://w3c.github.io/webrtc-provisional-stats/#dom-rtcinboundrtpstreamstats-contenttype 292 std::optional<std::string> content_type; 293 // Only populated if audio/video sync is enabled. 294 // TODO(https://crbug.com/webrtc/14177): Expose even if A/V sync is off? 295 std::optional<double> estimated_playout_timestamp; 296 // Only defined for video. 297 // In JavaScript, this is only exposed if HW exposure is allowed. 298 std::optional<std::string> decoder_implementation; 299 // FIR and PLI counts are only defined for |kind == "video"|. 300 std::optional<uint32_t> fir_count; 301 std::optional<uint32_t> pli_count; 302 std::optional<uint32_t> nack_count; 303 std::optional<uint64_t> qp_sum; 304 std::optional<double> total_corruption_probability; 305 std::optional<double> total_squared_corruption_probability; 306 std::optional<uint64_t> corruption_measurements; 307 // This is a remnant of the legacy getStats() API. When the "video-timing" 308 // header extension is used, 309 // https://webrtc.github.io/webrtc-org/experiments/rtp-hdrext/video-timing/, 310 // `googTimingFrameInfo` is exposed with the value of 311 // TimingFrameInfo::ToString(). 312 // TODO(https://crbug.com/webrtc/14586): Unship or standardize this metric. 313 std::optional<std::string> goog_timing_frame_info; 314 // In JavaScript, this is only exposed if HW exposure is allowed. 315 std::optional<bool> power_efficient_decoder; 316 317 // The following metrics are NOT exposed to JavaScript. We should consider 318 // standardizing or removing them. 319 std::optional<uint64_t> jitter_buffer_flushes; 320 std::optional<uint64_t> delayed_packet_outage_samples; 321 std::optional<double> relative_packet_arrival_delay; 322 std::optional<uint32_t> interruption_count; 323 std::optional<double> total_interruption_duration; 324 std::optional<double> min_playout_delay; 325 }; 326 327 // https://w3c.github.io/webrtc-stats/#outboundrtpstats-dict* 328 class RTC_EXPORT RTCOutboundRtpStreamStats final 329 : public RTCSentRtpStreamStats { 330 public: 331 WEBRTC_RTCSTATS_DECL(RTCOutboundRtpStreamStats); 332 RTCOutboundRtpStreamStats(std::string id, Timestamp timestamp); 333 ~RTCOutboundRtpStreamStats() override; 334 335 std::optional<std::string> media_source_id; 336 std::optional<std::string> remote_id; 337 std::optional<std::string> mid; 338 std::optional<std::string> rid; 339 std::optional<uint32_t> encoding_index; 340 std::optional<uint64_t> retransmitted_packets_sent; 341 std::optional<uint64_t> header_bytes_sent; 342 std::optional<uint64_t> retransmitted_bytes_sent; 343 std::optional<double> target_bitrate; 344 std::optional<uint32_t> frames_encoded; 345 std::optional<uint32_t> key_frames_encoded; 346 std::optional<double> total_encode_time; 347 std::optional<uint64_t> total_encoded_bytes_target; 348 std::optional<uint32_t> frame_width; 349 std::optional<uint32_t> frame_height; 350 std::optional<double> frames_per_second; 351 std::optional<uint32_t> frames_sent; 352 std::optional<uint32_t> huge_frames_sent; 353 std::optional<double> total_packet_send_delay; 354 std::optional<std::string> quality_limitation_reason; 355 std::optional<std::map<std::string, double>> quality_limitation_durations; 356 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationresolutionchanges 357 std::optional<uint32_t> quality_limitation_resolution_changes; 358 // https://w3c.github.io/webrtc-provisional-stats/#dom-rtcoutboundrtpstreamstats-contenttype 359 std::optional<std::string> content_type; 360 // In JavaScript, this is only exposed if HW exposure is allowed. 361 // Only implemented for video. 362 // TODO(https://crbug.com/webrtc/14178): Implement for audio as well. 363 std::optional<std::string> encoder_implementation; 364 // FIR and PLI counts are only defined for |kind == "video"|. 365 std::optional<uint32_t> fir_count; 366 std::optional<uint32_t> pli_count; 367 std::optional<uint32_t> nack_count; 368 // QP and PSNR are only defined for video. 369 std::optional<uint64_t> qp_sum; 370 std::optional<std::map<std::string, double>> psnr_sum; // y, u, v. 371 std::optional<uint32_t> psnr_measurements; 372 std::optional<bool> active; 373 // In JavaScript, this is only exposed if HW exposure is allowed. 374 std::optional<bool> power_efficient_encoder; 375 std::optional<std::string> scalability_mode; 376 377 // RTX ssrc. Only present if RTX is negotiated. 378 std::optional<uint32_t> rtx_ssrc; 379 380 // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-packetssentwithect1 381 std::optional<int64_t> packets_sent_with_ect1; 382 }; 383 384 // https://w3c.github.io/webrtc-stats/#remoteinboundrtpstats-dict* 385 class RTC_EXPORT RTCRemoteInboundRtpStreamStats final 386 : public RTCReceivedRtpStreamStats { 387 public: 388 WEBRTC_RTCSTATS_DECL(RTCRemoteInboundRtpStreamStats); 389 RTCRemoteInboundRtpStreamStats(std::string id, Timestamp timestamp); 390 ~RTCRemoteInboundRtpStreamStats() override; 391 392 std::optional<std::string> local_id; 393 std::optional<double> round_trip_time; 394 std::optional<double> fraction_lost; 395 std::optional<double> total_round_trip_time; 396 std::optional<int32_t> round_trip_time_measurements; 397 }; 398 399 // https://w3c.github.io/webrtc-stats/#remoteoutboundrtpstats-dict* 400 class RTC_EXPORT RTCRemoteOutboundRtpStreamStats final 401 : public RTCSentRtpStreamStats { 402 public: 403 WEBRTC_RTCSTATS_DECL(RTCRemoteOutboundRtpStreamStats); 404 RTCRemoteOutboundRtpStreamStats(std::string id, Timestamp timestamp); 405 ~RTCRemoteOutboundRtpStreamStats() override; 406 407 std::optional<std::string> local_id; 408 std::optional<double> remote_timestamp; 409 std::optional<uint64_t> reports_sent; 410 std::optional<double> round_trip_time; 411 std::optional<uint64_t> round_trip_time_measurements; 412 std::optional<double> total_round_trip_time; 413 }; 414 415 // https://w3c.github.io/webrtc-stats/#dom-rtcmediasourcestats 416 class RTC_EXPORT RTCMediaSourceStats : public RTCStats { 417 public: 418 WEBRTC_RTCSTATS_DECL(RTCMediaSourceStats); 419 ~RTCMediaSourceStats() override; 420 421 std::optional<std::string> track_identifier; 422 std::optional<std::string> kind; 423 424 protected: 425 RTCMediaSourceStats(std::string id, Timestamp timestamp); 426 }; 427 428 // https://w3c.github.io/webrtc-stats/#dom-rtcaudiosourcestats 429 class RTC_EXPORT RTCAudioSourceStats final : public RTCMediaSourceStats { 430 public: 431 WEBRTC_RTCSTATS_DECL(RTCAudioSourceStats); 432 RTCAudioSourceStats(std::string id, Timestamp timestamp); 433 ~RTCAudioSourceStats() override; 434 435 std::optional<double> audio_level; 436 std::optional<double> total_audio_energy; 437 std::optional<double> total_samples_duration; 438 std::optional<double> echo_return_loss; 439 std::optional<double> echo_return_loss_enhancement; 440 }; 441 442 // https://w3c.github.io/webrtc-stats/#dom-rtcvideosourcestats 443 class RTC_EXPORT RTCVideoSourceStats final : public RTCMediaSourceStats { 444 public: 445 WEBRTC_RTCSTATS_DECL(RTCVideoSourceStats); 446 RTCVideoSourceStats(std::string id, Timestamp timestamp); 447 ~RTCVideoSourceStats() override; 448 449 std::optional<uint32_t> width; 450 std::optional<uint32_t> height; 451 std::optional<uint32_t> frames; 452 std::optional<double> frames_per_second; 453 }; 454 455 // https://w3c.github.io/webrtc-stats/#transportstats-dict* 456 class RTC_EXPORT RTCTransportStats final : public RTCStats { 457 public: 458 WEBRTC_RTCSTATS_DECL(RTCTransportStats); 459 RTCTransportStats(std::string id, Timestamp timestamp); 460 ~RTCTransportStats() override; 461 462 std::optional<uint64_t> bytes_sent; 463 std::optional<uint64_t> packets_sent; 464 std::optional<uint64_t> bytes_received; 465 std::optional<uint64_t> packets_received; 466 std::optional<std::string> rtcp_transport_stats_id; 467 std::optional<std::string> dtls_state; 468 std::optional<std::string> selected_candidate_pair_id; 469 std::optional<std::string> local_certificate_id; 470 std::optional<std::string> remote_certificate_id; 471 std::optional<std::string> tls_version; 472 std::optional<std::string> dtls_cipher; 473 std::optional<std::string> dtls_role; 474 std::optional<std::string> srtp_cipher; 475 std::optional<uint32_t> selected_candidate_pair_changes; 476 std::optional<std::string> ice_role; 477 std::optional<std::string> ice_local_username_fragment; 478 std::optional<std::string> ice_state; 479 // https://w3c.github.io/webrtc-stats/#dom-rtctransportstats-ccfbmessagesreceived 480 std::optional<int> ccfb_messages_received; 481 }; 482 483 // https://w3c.github.io/webrtc-stats/#playoutstats-dict* 484 class RTC_EXPORT RTCAudioPlayoutStats final : public RTCStats { 485 public: 486 WEBRTC_RTCSTATS_DECL(RTCAudioPlayoutStats); 487 RTCAudioPlayoutStats(const std::string& id, Timestamp timestamp); 488 ~RTCAudioPlayoutStats() override; 489 490 std::optional<std::string> kind; 491 std::optional<double> synthesized_samples_duration; 492 std::optional<uint64_t> synthesized_samples_events; 493 std::optional<double> total_samples_duration; 494 std::optional<double> total_playout_delay; 495 std::optional<uint64_t> total_samples_count; 496 }; 497 498 } // namespace webrtc 499 500 #endif // API_STATS_RTCSTATS_OBJECTS_H_