LiveKit C++ Client SDK v1.1.0
Real-time audio/video/data SDK for C++
Loading...
Searching...
No Matches
stats.h
1/*
2 * Copyright 2025 LiveKit
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an “AS IS” BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <cstdint>
20#include <optional>
21#include <string>
22#include <unordered_map>
23#include <variant>
24#include <vector>
25
26#include "livekit/visibility.h"
27
28namespace livekit {
29
30namespace proto {
31class RtcStats;
32class RtcStatsData;
33class CodecStats;
34class RtpStreamStats;
35class ReceivedRtpStreamStats;
36class InboundRtpStreamStats;
37class SentRtpStreamStats;
38class OutboundRtpStreamStats;
39class RemoteInboundRtpStreamStats;
40class RemoteOutboundRtpStreamStats;
41class MediaSourceStats;
42class AudioSourceStats;
43class VideoSourceStats;
44class AudioPlayoutStats;
45class PeerConnectionStats;
46class DataChannelStats;
47class TransportStats;
48class CandidatePairStats;
49class IceCandidateStats;
50class CertificateStats;
51class StreamStats;
52} // namespace proto
53
55enum class DataChannelState {
56 Connecting,
57 Open,
58 Closing,
59 Closed,
60 Unknown,
61};
62
65 None,
66 Cpu,
67 Bandwidth,
68 Other,
69};
70
72enum class IceRole {
73 Unknown,
74 Controlling,
75 Controlled,
76};
77
80 New,
81 Connecting,
82 Connected,
83 Closed,
84 Failed,
85 Unknown,
86};
87
90 New,
91 Checking,
92 Connected,
93 Completed,
94 Disconnected,
95 Failed,
96 Closed,
97 Unknown,
98};
99
101enum class DtlsRole {
102 Client,
103 Server,
104 Unknown,
105};
106
109 Frozen,
110 Waiting,
111 InProgress,
112 Failed,
113 Succeeded,
114 Unknown,
115};
116
119 Host,
120 Srflx,
121 Prflx,
122 Relay,
123 Unknown,
124};
125
128 Udp,
129 Tcp,
130 Tls,
131 Unknown,
132};
133
136 Active,
137 Passive,
138 So,
139 Unknown,
140};
141
142// ----------------------
143// Leaf stats types
144// ----------------------
145
148 std::string id;
149 std::int64_t timestamp_ms;
150};
151
154 std::uint32_t payload_type;
155 std::string transport_id;
156 std::string mime_type;
157 std::uint32_t clock_rate;
158 std::uint32_t channels;
159 std::string sdp_fmtp_line;
160};
161
164 std::uint32_t ssrc;
165 std::string kind;
166 std::string transport_id;
167 std::string codec_id;
168};
169
172 std::uint64_t packets_received;
173 std::int64_t packets_lost;
174 double jitter;
175};
176
179 std::string track_identifier;
180 std::string mid;
181 std::string remote_id;
182 std::uint32_t frames_decoded;
183 std::uint32_t key_frames_decoded;
184 std::uint32_t frames_rendered;
185 std::uint32_t frames_dropped;
186 std::uint32_t frame_width;
187 std::uint32_t frame_height;
188 double frames_per_second;
189 std::uint64_t qp_sum;
190 double total_decode_time;
191 double total_inter_frame_delay;
192 double total_squared_inter_frame_delay;
193 std::uint32_t pause_count;
194 double total_pause_duration;
195 std::uint32_t freeze_count;
196 double total_freeze_duration;
197 double last_packet_received_timestamp;
198 std::uint64_t header_bytes_received;
199 std::uint64_t packets_discarded;
200 std::uint64_t fec_bytes_received;
201 std::uint64_t fec_packets_received;
202 std::uint64_t fec_packets_discarded;
203 std::uint64_t bytes_received;
204 std::uint32_t nack_count;
205 std::uint32_t fir_count;
206 std::uint32_t pli_count;
207 double total_processing_delay;
208 double estimated_playout_timestamp;
209 double jitter_buffer_delay;
210 double jitter_buffer_target_delay;
211 std::uint64_t jitter_buffer_emitted_count;
212 double jitter_buffer_minimum_delay;
213 std::uint64_t total_samples_received;
214 std::uint64_t concealed_samples;
215 std::uint64_t silent_concealed_samples;
216 std::uint64_t concealment_events;
217 std::uint64_t inserted_samples_for_deceleration;
218 std::uint64_t removed_samples_for_acceleration;
219 double audio_level;
220 double total_audio_energy;
221 double total_samples_duration;
222 std::uint64_t frames_received;
223 std::string decoder_implementation;
224 std::string playout_id;
225 bool power_efficient_decoder;
226 std::uint64_t frames_assembled_from_multiple_packets;
227 double total_assembly_time;
228 std::uint64_t retransmitted_packets_received;
229 std::uint64_t retransmitted_bytes_received;
230 std::uint32_t rtx_ssrc;
231 std::uint32_t fec_ssrc;
232};
233
236 std::uint64_t packets_sent;
237 std::uint64_t bytes_sent;
238};
239
242 std::string mid;
243 std::string media_source_id;
244 std::string remote_id;
245 std::string rid;
246 std::uint64_t header_bytes_sent;
247 std::uint64_t retransmitted_packets_sent;
248 std::uint64_t retransmitted_bytes_sent;
249 std::uint32_t rtx_ssrc;
250 double target_bitrate;
251 std::uint64_t total_encoded_bytes_target;
252 std::uint32_t frame_width;
253 std::uint32_t frame_height;
254 double frames_per_second;
255 std::uint32_t frames_sent;
256 std::uint32_t huge_frames_sent;
257 std::uint32_t frames_encoded;
258 std::uint32_t key_frames_encoded;
259 std::uint64_t qp_sum;
260 double total_encode_time;
261 double total_packet_send_delay;
262 QualityLimitationReason quality_limitation_reason;
263 std::unordered_map<std::string, double> quality_limitation_durations;
264 std::uint32_t quality_limitation_resolution_changes;
265 std::uint32_t nack_count;
266 std::uint32_t fir_count;
267 std::uint32_t pli_count;
268 std::string encoder_implementation;
269 bool power_efficient_encoder;
270 bool active;
271 std::string scalability_mode;
272};
273
276 std::string local_id;
277 double round_trip_time;
278 double total_round_trip_time;
279 double fraction_lost;
280 std::uint64_t round_trip_time_measurements;
281};
282
285 std::string local_id;
286 double remote_timestamp;
287 std::uint64_t reports_sent;
288 double round_trip_time;
289 double total_round_trip_time;
290 std::uint64_t round_trip_time_measurements;
291};
292
295 std::string track_identifier;
296 std::string kind;
297};
298
301 double audio_level;
302 double total_audio_energy;
303 double total_samples_duration;
304 double echo_return_loss;
305 double echo_return_loss_enhancement;
306 double dropped_samples_duration;
307 std::uint32_t dropped_samples_events;
308 double total_capture_delay;
309 std::uint64_t total_samples_captured;
310};
311
314 std::uint32_t width;
315 std::uint32_t height;
316 std::uint32_t frames;
317 double frames_per_second;
318};
319
334
337 std::uint32_t data_channels_opened;
338 std::uint32_t data_channels_closed;
339};
340
343 std::string label;
344 std::string protocol;
345 std::int32_t data_channel_identifier;
346 std::optional<DataChannelState> state;
347 std::uint32_t messages_sent;
348 std::uint64_t bytes_sent;
349 std::uint32_t messages_received;
350 std::uint64_t bytes_received;
351};
352
355 std::uint64_t packets_sent;
356 std::uint64_t packets_received;
357 std::uint64_t bytes_sent;
358 std::uint64_t bytes_received;
359 IceRole ice_role;
360 std::string ice_local_username_fragment;
361 std::optional<DtlsTransportState> dtls_state;
362 std::optional<IceTransportState> ice_state;
363 std::string selected_candidate_pair_id;
364 std::string local_certificate_id;
365 std::string remote_certificate_id;
366 std::string tls_version;
367 std::string dtls_cipher;
368 DtlsRole dtls_role;
369 std::string srtp_cipher;
370 std::uint32_t selected_candidate_pair_changes;
371};
372
375 std::string transport_id;
376 std::string local_candidate_id;
377 std::string remote_candidate_id;
378 std::optional<IceCandidatePairState> state;
379 bool nominated;
380 std::uint64_t packets_sent;
381 std::uint64_t packets_received;
382 std::uint64_t bytes_sent;
383 std::uint64_t bytes_received;
384 double last_packet_sent_timestamp;
385 double last_packet_received_timestamp;
386 double total_round_trip_time;
387 double current_round_trip_time;
388 double available_outgoing_bitrate;
389 double available_incoming_bitrate;
390 std::uint64_t requests_received;
391 std::uint64_t requests_sent;
392 std::uint64_t responses_received;
393 std::uint64_t responses_sent;
394 std::uint64_t consent_requests_sent;
395 std::uint32_t packets_discarded_on_send;
396 std::uint64_t bytes_discarded_on_send;
397};
398
401 std::string transport_id;
402 std::string address;
403 std::int32_t port;
404 std::string protocol;
405 std::optional<IceCandidateType> candidate_type;
406 std::int32_t priority;
407 std::string url;
408 std::optional<IceServerTransportProtocol> relay_protocol;
409 std::string foundation;
410 std::string related_address;
411 std::int32_t related_port;
412 std::string username_fragment;
413 std::optional<IceTcpCandidateType> tcp_type;
414};
415
418 std::string fingerprint;
419 std::string fingerprint_algorithm;
420 std::string base64_certificate;
421 std::string issuer_certificate_id;
422};
423
426 std::string id;
427 std::string stream_identifier;
428};
429
430// ----------------------
431// High-level RtcStats wrapper
432// ----------------------
433
436 RtcStatsData rtc;
437 CodecStats codec;
438};
439
442 RtcStatsData rtc;
443 RtpStreamStats stream;
444 ReceivedRtpStreamStats received;
445 InboundRtpStreamStats inbound;
446};
447
450 RtcStatsData rtc;
451 RtpStreamStats stream;
453 OutboundRtpStreamStats outbound;
454};
455
458 RtcStatsData rtc;
459 RtpStreamStats stream;
460 ReceivedRtpStreamStats received;
461 RemoteInboundRtpStreamStats remote_inbound;
462};
463
466 RtcStatsData rtc;
467 RtpStreamStats stream;
469 RemoteOutboundRtpStreamStats remote_outbound;
470};
471
474 RtcStatsData rtc;
475 MediaSourceStats source;
476 AudioSourceStats audio;
477 VideoSourceStats video;
478};
479
482 RtcStatsData rtc;
483 AudioPlayoutStats audio_playout;
484};
485
491
494 RtcStatsData rtc;
496};
497
500 RtcStatsData rtc;
501 TransportStats transport;
502};
503
506 RtcStatsData rtc;
507 CandidatePairStats candidate_pair;
508};
509
512 RtcStatsData rtc;
513 IceCandidateStats candidate;
514};
515
518 RtcStatsData rtc;
519 IceCandidateStats candidate;
520};
521
524 RtcStatsData rtc;
525 CertificateStats certificate;
526};
527
530 RtcStatsData rtc;
531 StreamStats stream;
532};
533
534// Deprecated Track omitted on purpose.
535
536using RtcStatsVariant =
541
543struct RtcStats {
544 RtcStatsVariant stats;
545};
546
550 std::vector<RtcStats> publisher_stats;
552 std::vector<RtcStats> subscriber_stats;
553};
554
555// ----------------------
556// fromProto declarations
557// ----------------------
558
559LIVEKIT_API RtcStatsData fromProto(const proto::RtcStatsData&);
560
561LIVEKIT_API CodecStats fromProto(const proto::CodecStats&);
562LIVEKIT_API RtpStreamStats fromProto(const proto::RtpStreamStats&);
563LIVEKIT_API ReceivedRtpStreamStats fromProto(const proto::ReceivedRtpStreamStats&);
564LIVEKIT_API InboundRtpStreamStats fromProto(const proto::InboundRtpStreamStats&);
565LIVEKIT_API SentRtpStreamStats fromProto(const proto::SentRtpStreamStats&);
566LIVEKIT_API OutboundRtpStreamStats fromProto(const proto::OutboundRtpStreamStats&);
567LIVEKIT_API RemoteInboundRtpStreamStats fromProto(const proto::RemoteInboundRtpStreamStats&);
568LIVEKIT_API RemoteOutboundRtpStreamStats fromProto(const proto::RemoteOutboundRtpStreamStats&);
569LIVEKIT_API MediaSourceStats fromProto(const proto::MediaSourceStats&);
570LIVEKIT_API AudioSourceStats fromProto(const proto::AudioSourceStats&);
571LIVEKIT_API VideoSourceStats fromProto(const proto::VideoSourceStats&);
572LIVEKIT_API AudioPlayoutStats fromProto(const proto::AudioPlayoutStats&);
573LIVEKIT_API PeerConnectionStats fromProto(const proto::PeerConnectionStats&);
574LIVEKIT_API DataChannelStats fromProto(const proto::DataChannelStats&);
575LIVEKIT_API TransportStats fromProto(const proto::TransportStats&);
576LIVEKIT_API CandidatePairStats fromProto(const proto::CandidatePairStats&);
577LIVEKIT_API IceCandidateStats fromProto(const proto::IceCandidateStats&);
578LIVEKIT_API CertificateStats fromProto(const proto::CertificateStats&);
579LIVEKIT_API StreamStats fromProto(const proto::StreamStats&);
580
581// High-level:
582LIVEKIT_API RtcStats fromProto(const proto::RtcStats&);
583
584// helper if you have repeated RtcStats in proto:
585LIVEKIT_API std::vector<RtcStats> fromProto(const std::vector<proto::RtcStats>&);
586
587} // namespace livekit
Public API for the LiveKit C++ Client SDK.
Definition audio_frame.h:25
IceCandidatePairState
State of an ICE candidate pair.
Definition stats.h:108
DtlsTransportState
DTLS transport state.
Definition stats.h:79
DtlsRole
DTLS role used by a transport.
Definition stats.h:101
IceRole
ICE role used by a transport.
Definition stats.h:72
IceTcpCandidateType
TCP candidate type for an ICE candidate.
Definition stats.h:135
QualityLimitationReason
Reason outbound media quality is currently limited.
Definition stats.h:64
DataChannelState
State of a WebRTC data channel.
Definition stats.h:55
IceTransportState
ICE transport state.
Definition stats.h:89
IceServerTransportProtocol
Transport protocol used by an ICE server.
Definition stats.h:127
IceCandidateType
Type of ICE candidate.
Definition stats.h:118
Statistics for audio playout performance.
Definition stats.h:324
std::string kind
The type of media ("audio").
Definition stats.h:325
double total_playout_delay
Cumulative playout delay in seconds.
Definition stats.h:331
double synthesized_samples_duration
Duration of synthesized samples in seconds.
Definition stats.h:326
std::uint32_t synthesized_samples_events
Number of synthesis events (e.g., concealment).
Definition stats.h:328
std::uint64_t total_samples_count
Total number of samples played out.
Definition stats.h:332
double total_samples_duration
Total duration of all samples in seconds.
Definition stats.h:330
Statistics for a local audio source.
Definition stats.h:300
Statistics for a selected or candidate ICE pair.
Definition stats.h:374
Statistics for a DTLS certificate.
Definition stats.h:417
Codec statistics for an RTP stream.
Definition stats.h:153
Statistics for a WebRTC data channel.
Definition stats.h:342
Statistics for a local or remote ICE candidate.
Definition stats.h:400
Statistics for inbound RTP media.
Definition stats.h:178
Common statistics for a local media source.
Definition stats.h:294
Statistics for outbound RTP media.
Definition stats.h:241
Statistics for a peer connection.
Definition stats.h:336
Statistics for received RTP streams.
Definition stats.h:171
Statistics reported by a remote receiver for a local outbound RTP stream.
Definition stats.h:275
Statistics reported by a remote sender for a local inbound RTP stream.
Definition stats.h:284
Typed RTC stats wrapper for ICE candidate pair statistics.
Definition stats.h:505
Typed RTC stats wrapper for certificate statistics.
Definition stats.h:523
Typed RTC stats wrapper for codec statistics.
Definition stats.h:435
Typed RTC stats wrapper for data channel statistics.
Definition stats.h:493
Typed RTC stats wrapper for inbound RTP statistics.
Definition stats.h:441
Typed RTC stats wrapper for local ICE candidate statistics.
Definition stats.h:511
Typed RTC stats wrapper for audio playout statistics.
Definition stats.h:481
Typed RTC stats wrapper for media source statistics.
Definition stats.h:473
Typed RTC stats wrapper for outbound RTP statistics.
Definition stats.h:449
Typed RTC stats wrapper for peer connection statistics.
Definition stats.h:487
Typed RTC stats wrapper for remote ICE candidate statistics.
Definition stats.h:517
Typed RTC stats wrapper for remote inbound RTP statistics.
Definition stats.h:457
Typed RTC stats wrapper for remote outbound RTP statistics.
Definition stats.h:465
Base data shared by RTC stats records.
Definition stats.h:147
Variant wrapper for typed RTC stats records.
Definition stats.h:543
Typed RTC stats wrapper for media stream statistics.
Definition stats.h:529
Typed RTC stats wrapper for transport statistics.
Definition stats.h:499
Base statistics for an RTP stream.
Definition stats.h:163
Statistics for sent RTP streams.
Definition stats.h:235
Aggregated WebRTC stats for a connected room session.
Definition stats.h:548
std::vector< RtcStats > publisher_stats
Stats from the publisher peer connection (outbound media).
Definition stats.h:550
std::vector< RtcStats > subscriber_stats
Stats from the subscriber peer connection (inbound media).
Definition stats.h:552
Statistics for a media stream.
Definition stats.h:425
Statistics for a WebRTC transport.
Definition stats.h:354
Statistics for a local video source.
Definition stats.h:313