-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
stats.go
1455 lines (1136 loc) · 66.4 KB
/
stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package webrtc
import (
"fmt"
"sync"
"time"
"github.com/pion/ice/v2"
)
// A Stats object contains a set of statistics copies out of a monitored component
// of the WebRTC stack at a specific time.
type Stats interface{}
// StatsType indicates the type of the object that a Stats object represents.
type StatsType string
const (
// StatsTypeCodec is used by CodecStats.
StatsTypeCodec StatsType = "codec"
// StatsTypeInboundRTP is used by InboundRTPStreamStats.
StatsTypeInboundRTP StatsType = "inbound-rtp"
// StatsTypeOutboundRTP is used by OutboundRTPStreamStats.
StatsTypeOutboundRTP StatsType = "outbound-rtp"
// StatsTypeRemoteInboundRTP is used by RemoteInboundRTPStreamStats.
StatsTypeRemoteInboundRTP StatsType = "remote-inbound-rtp"
// StatsTypeRemoteOutboundRTP is used by RemoteOutboundRTPStreamStats.
StatsTypeRemoteOutboundRTP StatsType = "remote-outbound-rtp"
// StatsTypeCSRC is used by RTPContributingSourceStats.
StatsTypeCSRC StatsType = "csrc"
// StatsTypePeerConnection used by PeerConnectionStats.
StatsTypePeerConnection StatsType = "peer-connection"
// StatsTypeDataChannel is used by DataChannelStats.
StatsTypeDataChannel StatsType = "data-channel"
// StatsTypeStream is used by MediaStreamStats.
StatsTypeStream StatsType = "stream"
// StatsTypeTrack is used by SenderVideoTrackAttachmentStats and SenderAudioTrackAttachmentStats.
StatsTypeTrack StatsType = "track"
// StatsTypeSender is used by by the AudioSenderStats or VideoSenderStats depending on kind.
StatsTypeSender StatsType = "sender"
// StatsTypeReceiver is used by the AudioReceiverStats or VideoReceiverStats depending on kind.
StatsTypeReceiver StatsType = "receiver"
// StatsTypeTransport is used by TransportStats.
StatsTypeTransport StatsType = "transport"
// StatsTypeCandidatePair is used by ICECandidatePairStats.
StatsTypeCandidatePair StatsType = "candidate-pair"
// StatsTypeLocalCandidate is used by ICECandidateStats for the local candidate.
StatsTypeLocalCandidate StatsType = "local-candidate"
// StatsTypeRemoteCandidate is used by ICECandidateStats for the remote candidate.
StatsTypeRemoteCandidate StatsType = "remote-candidate"
// StatsTypeCertificate is used by CertificateStats.
StatsTypeCertificate StatsType = "certificate"
)
// StatsTimestamp is a timestamp represented by the floating point number of
// milliseconds since the epoch.
type StatsTimestamp float64
// Time returns the time.Time represented by this timestamp.
func (s StatsTimestamp) Time() time.Time {
millis := float64(s)
nanos := int64(millis * float64(time.Millisecond))
return time.Unix(0, nanos).UTC()
}
func statsTimestampFrom(t time.Time) StatsTimestamp {
return StatsTimestamp(t.UnixNano() / int64(time.Millisecond))
}
func statsTimestampNow() StatsTimestamp {
return statsTimestampFrom(time.Now())
}
// StatsReport collects Stats objects indexed by their ID.
type StatsReport map[string]Stats
type statsReportCollector struct {
collectingGroup sync.WaitGroup
report StatsReport
mux sync.Mutex
}
func newStatsReportCollector() *statsReportCollector {
return &statsReportCollector{report: make(StatsReport)}
}
func (src *statsReportCollector) Collecting() {
src.collectingGroup.Add(1)
}
func (src *statsReportCollector) Collect(id string, stats Stats) {
src.mux.Lock()
defer src.mux.Unlock()
src.report[id] = stats
src.collectingGroup.Done()
}
func (src *statsReportCollector) Done() {
src.collectingGroup.Done()
}
func (src *statsReportCollector) Ready() StatsReport {
src.collectingGroup.Wait()
src.mux.Lock()
defer src.mux.Unlock()
return src.report
}
// CodecType specifies whether a CodecStats objects represents a media format
// that is being encoded or decoded
type CodecType string
const (
// CodecTypeEncode means the attached CodecStats represents a media format that
// is being encoded, or that the implementation is prepared to encode.
CodecTypeEncode CodecType = "encode"
// CodecTypeDecode means the attached CodecStats represents a media format
// that the implementation is prepared to decode.
CodecTypeDecode CodecType = "decode"
)
// CodecStats contains statistics for a codec that is currently being used by RTP streams
// being sent or received by this PeerConnection object.
type CodecStats struct {
// Timestamp is the timestamp associated with this object.
Timestamp StatsTimestamp `json:"timestamp"`
// Type is the object's StatsType
Type StatsType `json:"type"`
// ID is a unique id that is associated with the component inspected to produce
// this Stats object. Two Stats objects will have the same ID if they were produced
// by inspecting the same underlying object.
ID string `json:"id"`
// PayloadType as used in RTP encoding or decoding
PayloadType PayloadType `json:"payloadType"`
// CodecType of this CodecStats
CodecType CodecType `json:"codecType"`
// TransportID is the unique identifier of the transport on which this codec is
// being used, which can be used to look up the corresponding TransportStats object.
TransportID string `json:"transportId"`
// MimeType is the codec MIME media type/subtype. e.g., video/vp8 or equivalent.
MimeType string `json:"mimeType"`
// ClockRate represents the media sampling rate.
ClockRate uint32 `json:"clockRate"`
// Channels is 2 for stereo, missing for most other cases.
Channels uint8 `json:"channels"`
// SDPFmtpLine is the a=fmtp line in the SDP corresponding to the codec,
// i.e., after the colon following the PT.
SDPFmtpLine string `json:"sdpFmtpLine"`
// Implementation identifies the implementation used. This is useful for diagnosing
// interoperability issues.
Implementation string `json:"implementation"`
}
// InboundRTPStreamStats contains statistics for an inbound RTP stream that is
// currently received with this PeerConnection object.
type InboundRTPStreamStats struct {
// Timestamp is the timestamp associated with this object.
Timestamp StatsTimestamp `json:"timestamp"`
// Type is the object's StatsType
Type StatsType `json:"type"`
// ID is a unique id that is associated with the component inspected to produce
// this Stats object. Two Stats objects will have the same ID if they were produced
// by inspecting the same underlying object.
ID string `json:"id"`
// SSRC is the 32-bit unsigned integer value used to identify the source of the
// stream of RTP packets that this stats object concerns.
SSRC SSRC `json:"ssrc"`
// Kind is either "audio" or "video"
Kind string `json:"kind"`
// It is a unique identifier that is associated to the object that was inspected
// to produce the TransportStats associated with this RTP stream.
TransportID string `json:"transportId"`
// CodecID is a unique identifier that is associated to the object that was inspected
// to produce the CodecStats associated with this RTP stream.
CodecID string `json:"codecId"`
// FIRCount counts the total number of Full Intra Request (FIR) packets received
// by the sender. This metric is only valid for video and is sent by receiver.
FIRCount uint32 `json:"firCount"`
// PLICount counts the total number of Picture Loss Indication (PLI) packets
// received by the sender. This metric is only valid for video and is sent by receiver.
PLICount uint32 `json:"pliCount"`
// NACKCount counts the total number of Negative ACKnowledgement (NACK) packets
// received by the sender and is sent by receiver.
NACKCount uint32 `json:"nackCount"`
// SLICount counts the total number of Slice Loss Indication (SLI) packets received
// by the sender. This metric is only valid for video and is sent by receiver.
SLICount uint32 `json:"sliCount"`
// QPSum is the sum of the QP values of frames passed. The count of frames is
// in FramesDecoded for inbound stream stats, and in FramesEncoded for outbound stream stats.
QPSum uint64 `json:"qpSum"`
// PacketsReceived is the total number of RTP packets received for this SSRC.
PacketsReceived uint32 `json:"packetsReceived"`
// PacketsLost is the total number of RTP packets lost for this SSRC. Note that
// because of how this is estimated, it can be negative if more packets are received than sent.
PacketsLost int32 `json:"packetsLost"`
// Jitter is the packet jitter measured in seconds for this SSRC
Jitter float64 `json:"jitter"`
// PacketsDiscarded is the cumulative number of RTP packets discarded by the jitter
// buffer due to late or early-arrival, i.e., these packets are not played out.
// RTP packets discarded due to packet duplication are not reported in this metric.
PacketsDiscarded uint32 `json:"packetsDiscarded"`
// PacketsRepaired is the cumulative number of lost RTP packets repaired after applying
// an error-resilience mechanism. It is measured for the primary source RTP packets
// and only counted for RTP packets that have no further chance of repair.
PacketsRepaired uint32 `json:"packetsRepaired"`
// BurstPacketsLost is the cumulative number of RTP packets lost during loss bursts.
BurstPacketsLost uint32 `json:"burstPacketsLost"`
// BurstPacketsDiscarded is the cumulative number of RTP packets discarded during discard bursts.
BurstPacketsDiscarded uint32 `json:"burstPacketsDiscarded"`
// BurstLossCount is the cumulative number of bursts of lost RTP packets.
BurstLossCount uint32 `json:"burstLossCount"`
// BurstDiscardCount is the cumulative number of bursts of discarded RTP packets.
BurstDiscardCount uint32 `json:"burstDiscardCount"`
// BurstLossRate is the fraction of RTP packets lost during bursts to the
// total number of RTP packets expected in the bursts.
BurstLossRate float64 `json:"burstLossRate"`
// BurstDiscardRate is the fraction of RTP packets discarded during bursts to
// the total number of RTP packets expected in bursts.
BurstDiscardRate float64 `json:"burstDiscardRate"`
// GapLossRate is the fraction of RTP packets lost during the gap periods.
GapLossRate float64 `json:"gapLossRate"`
// GapDiscardRate is the fraction of RTP packets discarded during the gap periods.
GapDiscardRate float64 `json:"gapDiscardRate"`
// TrackID is the identifier of the stats object representing the receiving track,
// a ReceiverAudioTrackAttachmentStats or ReceiverVideoTrackAttachmentStats.
TrackID string `json:"trackId"`
// ReceiverID is the stats ID used to look up the AudioReceiverStats or VideoReceiverStats
// object receiving this stream.
ReceiverID string `json:"receiverId"`
// RemoteID is used for looking up the remote RemoteOutboundRTPStreamStats object
// for the same SSRC.
RemoteID string `json:"remoteId"`
// FramesDecoded represents the total number of frames correctly decoded for this SSRC,
// i.e., frames that would be displayed if no frames are dropped. Only valid for video.
FramesDecoded uint32 `json:"framesDecoded"`
// LastPacketReceivedTimestamp represents the timestamp at which the last packet was
// received for this SSRC. This differs from Timestamp, which represents the time
// at which the statistics were generated by the local endpoint.
LastPacketReceivedTimestamp StatsTimestamp `json:"lastPacketReceivedTimestamp"`
// AverageRTCPInterval is the average RTCP interval between two consecutive compound RTCP packets.
// This is calculated by the sending endpoint when sending compound RTCP reports.
// Compound packets must contain at least a RTCP RR or SR packet and an SDES packet
// with the CNAME item.
AverageRTCPInterval float64 `json:"averageRtcpInterval"`
// FECPacketsReceived is the total number of RTP FEC packets received for this SSRC.
// This counter can also be incremented when receiving FEC packets in-band with media packets (e.g., with Opus).
FECPacketsReceived uint32 `json:"fecPacketsReceived"`
// BytesReceived is the total number of bytes received for this SSRC.
BytesReceived uint64 `json:"bytesReceived"`
// PacketsFailedDecryption is the cumulative number of RTP packets that failed
// to be decrypted. These packets are not counted by PacketsDiscarded.
PacketsFailedDecryption uint32 `json:"packetsFailedDecryption"`
// PacketsDuplicated is the cumulative number of packets discarded because they
// are duplicated. Duplicate packets are not counted in PacketsDiscarded.
//
// Duplicated packets have the same RTP sequence number and content as a previously
// received packet. If multiple duplicates of a packet are received, all of them are counted.
// An improved estimate of lost packets can be calculated by adding PacketsDuplicated to PacketsLost.
PacketsDuplicated uint32 `json:"packetsDuplicated"`
// PerDSCPPacketsReceived is the total number of packets received for this SSRC,
// per Differentiated Services code point (DSCP) [RFC2474]. DSCPs are identified
// as decimal integers in string form. Note that due to network remapping and bleaching,
// these numbers are not expected to match the numbers seen on sending. Not all
// OSes make this information available.
PerDSCPPacketsReceived map[string]uint32 `json:"perDscpPacketsReceived"`
}
// QualityLimitationReason lists the reason for limiting the resolution and/or framerate.
// Only valid for video.
type QualityLimitationReason string
const (
// QualityLimitationReasonNone means the resolution and/or framerate is not limited.
QualityLimitationReasonNone QualityLimitationReason = "none"
// QualityLimitationReasonCPU means the resolution and/or framerate is primarily limited due to CPU load.
QualityLimitationReasonCPU QualityLimitationReason = "cpu"
// QualityLimitationReasonBandwidth means the resolution and/or framerate is primarily limited due to congestion cues during bandwidth estimation. Typical, congestion control algorithms use inter-arrival time, round-trip time, packet or other congestion cues to perform bandwidth estimation.
QualityLimitationReasonBandwidth QualityLimitationReason = "bandwidth"
// QualityLimitationReasonOther means the resolution and/or framerate is primarily limited for a reason other than the above.
QualityLimitationReasonOther QualityLimitationReason = "other"
)
// OutboundRTPStreamStats contains statistics for an outbound RTP stream that is
// currently sent with this PeerConnection object.
type OutboundRTPStreamStats struct {
// Timestamp is the timestamp associated with this object.
Timestamp StatsTimestamp `json:"timestamp"`
// Type is the object's StatsType
Type StatsType `json:"type"`
// ID is a unique id that is associated with the component inspected to produce
// this Stats object. Two Stats objects will have the same ID if they were produced
// by inspecting the same underlying object.
ID string `json:"id"`
// SSRC is the 32-bit unsigned integer value used to identify the source of the
// stream of RTP packets that this stats object concerns.
SSRC SSRC `json:"ssrc"`
// Kind is either "audio" or "video"
Kind string `json:"kind"`
// It is a unique identifier that is associated to the object that was inspected
// to produce the TransportStats associated with this RTP stream.
TransportID string `json:"transportId"`
// CodecID is a unique identifier that is associated to the object that was inspected
// to produce the CodecStats associated with this RTP stream.
CodecID string `json:"codecId"`
// FIRCount counts the total number of Full Intra Request (FIR) packets received
// by the sender. This metric is only valid for video and is sent by receiver.
FIRCount uint32 `json:"firCount"`
// PLICount counts the total number of Picture Loss Indication (PLI) packets
// received by the sender. This metric is only valid for video and is sent by receiver.
PLICount uint32 `json:"pliCount"`
// NACKCount counts the total number of Negative ACKnowledgement (NACK) packets
// received by the sender and is sent by receiver.
NACKCount uint32 `json:"nackCount"`
// SLICount counts the total number of Slice Loss Indication (SLI) packets received
// by the sender. This metric is only valid for video and is sent by receiver.
SLICount uint32 `json:"sliCount"`
// QPSum is the sum of the QP values of frames passed. The count of frames is
// in FramesDecoded for inbound stream stats, and in FramesEncoded for outbound stream stats.
QPSum uint64 `json:"qpSum"`
// PacketsSent is the total number of RTP packets sent for this SSRC.
PacketsSent uint32 `json:"packetsSent"`
// PacketsDiscardedOnSend is the total number of RTP packets for this SSRC that
// have been discarded due to socket errors, i.e. a socket error occurred when handing
// the packets to the socket. This might happen due to various reasons, including
// full buffer or no available memory.
PacketsDiscardedOnSend uint32 `json:"packetsDiscardedOnSend"`
// FECPacketsSent is the total number of RTP FEC packets sent for this SSRC.
// This counter can also be incremented when sending FEC packets in-band with
// media packets (e.g., with Opus).
FECPacketsSent uint32 `json:"fecPacketsSent"`
// BytesSent is the total number of bytes sent for this SSRC.
BytesSent uint64 `json:"bytesSent"`
// BytesDiscardedOnSend is the total number of bytes for this SSRC that have
// been discarded due to socket errors, i.e. a socket error occurred when handing
// the packets containing the bytes to the socket. This might happen due to various
// reasons, including full buffer or no available memory.
BytesDiscardedOnSend uint64 `json:"bytesDiscardedOnSend"`
// TrackID is the identifier of the stats object representing the current track
// attachment to the sender of this stream, a SenderAudioTrackAttachmentStats
// or SenderVideoTrackAttachmentStats.
TrackID string `json:"trackId"`
// SenderID is the stats ID used to look up the AudioSenderStats or VideoSenderStats
// object sending this stream.
SenderID string `json:"senderId"`
// RemoteID is used for looking up the remote RemoteInboundRTPStreamStats object
// for the same SSRC.
RemoteID string `json:"remoteId"`
// LastPacketSentTimestamp represents the timestamp at which the last packet was
// sent for this SSRC. This differs from timestamp, which represents the time at
// which the statistics were generated by the local endpoint.
LastPacketSentTimestamp StatsTimestamp `json:"lastPacketSentTimestamp"`
// TargetBitrate is the current target bitrate configured for this particular SSRC
// and is the Transport Independent Application Specific (TIAS) bitrate [RFC3890].
// Typically, the target bitrate is a configuration parameter provided to the codec's
// encoder and does not count the size of the IP or other transport layers like TCP or UDP.
// It is measured in bits per second and the bitrate is calculated over a 1 second window.
TargetBitrate float64 `json:"targetBitrate"`
// FramesEncoded represents the total number of frames successfully encoded for this RTP media stream.
// Only valid for video.
FramesEncoded uint32 `json:"framesEncoded"`
// TotalEncodeTime is the total number of seconds that has been spent encoding the
// framesEncoded frames of this stream. The average encode time can be calculated by
// dividing this value with FramesEncoded. The time it takes to encode one frame is the
// time passed between feeding the encoder a frame and the encoder returning encoded data
// for that frame. This does not include any additional time it may take to packetize the resulting data.
TotalEncodeTime float64 `json:"totalEncodeTime"`
// AverageRTCPInterval is the average RTCP interval between two consecutive compound RTCP
// packets. This is calculated by the sending endpoint when sending compound RTCP reports.
// Compound packets must contain at least a RTCP RR or SR packet and an SDES packet with the CNAME item.
AverageRTCPInterval float64 `json:"averageRtcpInterval"`
// QualityLimitationReason is the current reason for limiting the resolution and/or framerate,
// or "none" if not limited. Only valid for video.
QualityLimitationReason QualityLimitationReason `json:"qualityLimitationReason"`
// QualityLimitationDurations is record of the total time, in seconds, that this
// stream has spent in each quality limitation state. The record includes a mapping
// for all QualityLimitationReason types, including "none". Only valid for video.
QualityLimitationDurations map[string]float64 `json:"qualityLimitationDurations"`
// PerDSCPPacketsSent is the total number of packets sent for this SSRC, per DSCP.
// DSCPs are identified as decimal integers in string form.
PerDSCPPacketsSent map[string]uint32 `json:"perDscpPacketsSent"`
}
// RemoteInboundRTPStreamStats contains statistics for the remote endpoint's inbound
// RTP stream corresponding to an outbound stream that is currently sent with this
// PeerConnection object. It is measured at the remote endpoint and reported in an RTCP
// Receiver Report (RR) or RTCP Extended Report (XR).
type RemoteInboundRTPStreamStats struct {
// Timestamp is the timestamp associated with this object.
Timestamp StatsTimestamp `json:"timestamp"`
// Type is the object's StatsType
Type StatsType `json:"type"`
// ID is a unique id that is associated with the component inspected to produce
// this Stats object. Two Stats objects will have the same ID if they were produced
// by inspecting the same underlying object.
ID string `json:"id"`
// SSRC is the 32-bit unsigned integer value used to identify the source of the
// stream of RTP packets that this stats object concerns.
SSRC SSRC `json:"ssrc"`
// Kind is either "audio" or "video"
Kind string `json:"kind"`
// It is a unique identifier that is associated to the object that was inspected
// to produce the TransportStats associated with this RTP stream.
TransportID string `json:"transportId"`
// CodecID is a unique identifier that is associated to the object that was inspected
// to produce the CodecStats associated with this RTP stream.
CodecID string `json:"codecId"`
// FIRCount counts the total number of Full Intra Request (FIR) packets received
// by the sender. This metric is only valid for video and is sent by receiver.
FIRCount uint32 `json:"firCount"`
// PLICount counts the total number of Picture Loss Indication (PLI) packets
// received by the sender. This metric is only valid for video and is sent by receiver.
PLICount uint32 `json:"pliCount"`
// NACKCount counts the total number of Negative ACKnowledgement (NACK) packets
// received by the sender and is sent by receiver.
NACKCount uint32 `json:"nackCount"`
// SLICount counts the total number of Slice Loss Indication (SLI) packets received
// by the sender. This metric is only valid for video and is sent by receiver.
SLICount uint32 `json:"sliCount"`
// QPSum is the sum of the QP values of frames passed. The count of frames is
// in FramesDecoded for inbound stream stats, and in FramesEncoded for outbound stream stats.
QPSum uint64 `json:"qpSum"`
// PacketsReceived is the total number of RTP packets received for this SSRC.
PacketsReceived uint32 `json:"packetsReceived"`
// PacketsLost is the total number of RTP packets lost for this SSRC. Note that
// because of how this is estimated, it can be negative if more packets are received than sent.
PacketsLost int32 `json:"packetsLost"`
// Jitter is the packet jitter measured in seconds for this SSRC
Jitter float64 `json:"jitter"`
// PacketsDiscarded is the cumulative number of RTP packets discarded by the jitter
// buffer due to late or early-arrival, i.e., these packets are not played out.
// RTP packets discarded due to packet duplication are not reported in this metric.
PacketsDiscarded uint32 `json:"packetsDiscarded"`
// PacketsRepaired is the cumulative number of lost RTP packets repaired after applying
// an error-resilience mechanism. It is measured for the primary source RTP packets
// and only counted for RTP packets that have no further chance of repair.
PacketsRepaired uint32 `json:"packetsRepaired"`
// BurstPacketsLost is the cumulative number of RTP packets lost during loss bursts.
BurstPacketsLost uint32 `json:"burstPacketsLost"`
// BurstPacketsDiscarded is the cumulative number of RTP packets discarded during discard bursts.
BurstPacketsDiscarded uint32 `json:"burstPacketsDiscarded"`
// BurstLossCount is the cumulative number of bursts of lost RTP packets.
BurstLossCount uint32 `json:"burstLossCount"`
// BurstDiscardCount is the cumulative number of bursts of discarded RTP packets.
BurstDiscardCount uint32 `json:"burstDiscardCount"`
// BurstLossRate is the fraction of RTP packets lost during bursts to the
// total number of RTP packets expected in the bursts.
BurstLossRate float64 `json:"burstLossRate"`
// BurstDiscardRate is the fraction of RTP packets discarded during bursts to
// the total number of RTP packets expected in bursts.
BurstDiscardRate float64 `json:"burstDiscardRate"`
// GapLossRate is the fraction of RTP packets lost during the gap periods.
GapLossRate float64 `json:"gapLossRate"`
// GapDiscardRate is the fraction of RTP packets discarded during the gap periods.
GapDiscardRate float64 `json:"gapDiscardRate"`
// LocalID is used for looking up the local OutboundRTPStreamStats object for the same SSRC.
LocalID string `json:"localId"`
// RoundTripTime is the estimated round trip time for this SSRC based on the
// RTCP timestamps in the RTCP Receiver Report (RR) and measured in seconds.
RoundTripTime float64 `json:"roundTripTime"`
// FractionLost is the the fraction packet loss reported for this SSRC.
FractionLost float64 `json:"fractionLost"`
}
// RemoteOutboundRTPStreamStats contains statistics for the remote endpoint's outbound
// RTP stream corresponding to an inbound stream that is currently received with this
// PeerConnection object. It is measured at the remote endpoint and reported in an
// RTCP Sender Report (SR).
type RemoteOutboundRTPStreamStats struct {
// Timestamp is the timestamp associated with this object.
Timestamp StatsTimestamp `json:"timestamp"`
// Type is the object's StatsType
Type StatsType `json:"type"`
// ID is a unique id that is associated with the component inspected to produce
// this Stats object. Two Stats objects will have the same ID if they were produced
// by inspecting the same underlying object.
ID string `json:"id"`
// SSRC is the 32-bit unsigned integer value used to identify the source of the
// stream of RTP packets that this stats object concerns.
SSRC SSRC `json:"ssrc"`
// Kind is either "audio" or "video"
Kind string `json:"kind"`
// It is a unique identifier that is associated to the object that was inspected
// to produce the TransportStats associated with this RTP stream.
TransportID string `json:"transportId"`
// CodecID is a unique identifier that is associated to the object that was inspected
// to produce the CodecStats associated with this RTP stream.
CodecID string `json:"codecId"`
// FIRCount counts the total number of Full Intra Request (FIR) packets received
// by the sender. This metric is only valid for video and is sent by receiver.
FIRCount uint32 `json:"firCount"`
// PLICount counts the total number of Picture Loss Indication (PLI) packets
// received by the sender. This metric is only valid for video and is sent by receiver.
PLICount uint32 `json:"pliCount"`
// NACKCount counts the total number of Negative ACKnowledgement (NACK) packets
// received by the sender and is sent by receiver.
NACKCount uint32 `json:"nackCount"`
// SLICount counts the total number of Slice Loss Indication (SLI) packets received
// by the sender. This metric is only valid for video and is sent by receiver.
SLICount uint32 `json:"sliCount"`
// QPSum is the sum of the QP values of frames passed. The count of frames is
// in FramesDecoded for inbound stream stats, and in FramesEncoded for outbound stream stats.
QPSum uint64 `json:"qpSum"`
// PacketsSent is the total number of RTP packets sent for this SSRC.
PacketsSent uint32 `json:"packetsSent"`
// PacketsDiscardedOnSend is the total number of RTP packets for this SSRC that
// have been discarded due to socket errors, i.e. a socket error occurred when handing
// the packets to the socket. This might happen due to various reasons, including
// full buffer or no available memory.
PacketsDiscardedOnSend uint32 `json:"packetsDiscardedOnSend"`
// FECPacketsSent is the total number of RTP FEC packets sent for this SSRC.
// This counter can also be incremented when sending FEC packets in-band with
// media packets (e.g., with Opus).
FECPacketsSent uint32 `json:"fecPacketsSent"`
// BytesSent is the total number of bytes sent for this SSRC.
BytesSent uint64 `json:"bytesSent"`
// BytesDiscardedOnSend is the total number of bytes for this SSRC that have
// been discarded due to socket errors, i.e. a socket error occurred when handing
// the packets containing the bytes to the socket. This might happen due to various
// reasons, including full buffer or no available memory.
BytesDiscardedOnSend uint64 `json:"bytesDiscardedOnSend"`
// LocalID is used for looking up the local InboundRTPStreamStats object for the same SSRC.
LocalID string `json:"localId"`
// RemoteTimestamp represents the remote timestamp at which these statistics were
// sent by the remote endpoint. This differs from timestamp, which represents the
// time at which the statistics were generated or received by the local endpoint.
// The RemoteTimestamp, if present, is derived from the NTP timestamp in an RTCP
// Sender Report (SR) packet, which reflects the remote endpoint's clock.
// That clock may not be synchronized with the local clock.
RemoteTimestamp StatsTimestamp `json:"remoteTimestamp"`
}
// RTPContributingSourceStats contains statistics for a contributing source (CSRC) that contributed
// to an inbound RTP stream.
type RTPContributingSourceStats struct {
// Timestamp is the timestamp associated with this object.
Timestamp StatsTimestamp `json:"timestamp"`
// Type is the object's StatsType
Type StatsType `json:"type"`
// ID is a unique id that is associated with the component inspected to produce
// this Stats object. Two Stats objects will have the same ID if they were produced
// by inspecting the same underlying object.
ID string `json:"id"`
// ContributorSSRC is the SSRC identifier of the contributing source represented
// by this stats object. It is a 32-bit unsigned integer that appears in the CSRC
// list of any packets the relevant source contributed to.
ContributorSSRC SSRC `json:"contributorSsrc"`
// InboundRTPStreamID is the ID of the InboundRTPStreamStats object representing
// the inbound RTP stream that this contributing source is contributing to.
InboundRTPStreamID string `json:"inboundRtpStreamId"`
// PacketsContributedTo is the total number of RTP packets that this contributing
// source contributed to. This value is incremented each time a packet is counted
// by InboundRTPStreamStats.packetsReceived, and the packet's CSRC list contains
// the SSRC identifier of this contributing source, ContributorSSRC.
PacketsContributedTo uint32 `json:"packetsContributedTo"`
// AudioLevel is present if the last received RTP packet that this source contributed
// to contained an [RFC6465] mixer-to-client audio level header extension. The value
// of audioLevel is between 0..1 (linear), where 1.0 represents 0 dBov, 0 represents
// silence, and 0.5 represents approximately 6 dBSPL change in the sound pressure level from 0 dBov.
AudioLevel float64 `json:"audioLevel"`
}
// PeerConnectionStats contains statistics related to the PeerConnection object.
type PeerConnectionStats struct {
// Timestamp is the timestamp associated with this object.
Timestamp StatsTimestamp `json:"timestamp"`
// Type is the object's StatsType
Type StatsType `json:"type"`
// ID is a unique id that is associated with the component inspected to produce
// this Stats object. Two Stats objects will have the same ID if they were produced
// by inspecting the same underlying object.
ID string `json:"id"`
// DataChannelsOpened represents the number of unique DataChannels that have
// entered the "open" state during their lifetime.
DataChannelsOpened uint32 `json:"dataChannelsOpened"`
// DataChannelsClosed represents the number of unique DataChannels that have
// left the "open" state during their lifetime (due to being closed by either
// end or the underlying transport being closed). DataChannels that transition
// from "connecting" to "closing" or "closed" without ever being "open"
// are not counted in this number.
DataChannelsClosed uint32 `json:"dataChannelsClosed"`
// DataChannelsRequested Represents the number of unique DataChannels returned
// from a successful createDataChannel() call on the PeerConnection. If the
// underlying data transport is not established, these may be in the "connecting" state.
DataChannelsRequested uint32 `json:"dataChannelsRequested"`
// DataChannelsAccepted represents the number of unique DataChannels signaled
// in a "datachannel" event on the PeerConnection.
DataChannelsAccepted uint32 `json:"dataChannelsAccepted"`
}
// DataChannelStats contains statistics related to each DataChannel ID.
type DataChannelStats struct {
// Timestamp is the timestamp associated with this object.
Timestamp StatsTimestamp `json:"timestamp"`
// Type is the object's StatsType
Type StatsType `json:"type"`
// ID is a unique id that is associated with the component inspected to produce
// this Stats object. Two Stats objects will have the same ID if they were produced
// by inspecting the same underlying object.
ID string `json:"id"`
// Label is the "label" value of the DataChannel object.
Label string `json:"label"`
// Protocol is the "protocol" value of the DataChannel object.
Protocol string `json:"protocol"`
// DataChannelIdentifier is the "id" attribute of the DataChannel object.
DataChannelIdentifier int32 `json:"dataChannelIdentifier"`
// TransportID the ID of the TransportStats object for transport used to carry this datachannel.
TransportID string `json:"transportId"`
// State is the "readyState" value of the DataChannel object.
State DataChannelState `json:"state"`
// MessagesSent represents the total number of API "message" events sent.
MessagesSent uint32 `json:"messagesSent"`
// BytesSent represents the total number of payload bytes sent on this
// datachannel not including headers or padding.
BytesSent uint64 `json:"bytesSent"`
// MessagesReceived represents the total number of API "message" events received.
MessagesReceived uint32 `json:"messagesReceived"`
// BytesReceived represents the total number of bytes received on this
// datachannel not including headers or padding.
BytesReceived uint64 `json:"bytesReceived"`
}
// MediaStreamStats contains statistics related to a specific MediaStream.
type MediaStreamStats struct {
// Timestamp is the timestamp associated with this object.
Timestamp StatsTimestamp `json:"timestamp"`
// Type is the object's StatsType
Type StatsType `json:"type"`
// ID is a unique id that is associated with the component inspected to produce
// this Stats object. Two Stats objects will have the same ID if they were produced
// by inspecting the same underlying object.
ID string `json:"id"`
// StreamIdentifier is the "id" property of the MediaStream
StreamIdentifier string `json:"streamIdentifier"`
// TrackIDs is a list of the identifiers of the stats object representing the
// stream's tracks, either ReceiverAudioTrackAttachmentStats or ReceiverVideoTrackAttachmentStats.
TrackIDs []string `json:"trackIds"`
}
// AudioSenderStats represents the stats about one audio sender of a PeerConnection
// object for which one calls GetStats.
//
// It appears in the stats as soon as the RTPSender is added by either AddTrack
// or AddTransceiver, or by media negotiation.
type AudioSenderStats struct {
// Timestamp is the timestamp associated with this object.
Timestamp StatsTimestamp `json:"timestamp"`
// Type is the object's StatsType
Type StatsType `json:"type"`
// ID is a unique id that is associated with the component inspected to produce
// this Stats object. Two Stats objects will have the same ID if they were produced
// by inspecting the same underlying object.
ID string `json:"id"`
// TrackIdentifier represents the id property of the track.
TrackIdentifier string `json:"trackIdentifier"`
// RemoteSource is true if the source is remote, for instance if it is sourced
// from another host via a PeerConnection. False otherwise. Only applicable for 'track' stats.
RemoteSource bool `json:"remoteSource"`
// Ended reflects the "ended" state of the track.
Ended bool `json:"ended"`
// Kind is either "audio" or "video". This reflects the "kind" attribute of the MediaStreamTrack.
Kind string `json:"kind"`
// AudioLevel represents the output audio level of the track.
//
// The value is a value between 0..1 (linear), where 1.0 represents 0 dBov,
// 0 represents silence, and 0.5 represents approximately 6 dBSPL change in
// the sound pressure level from 0 dBov.
//
// If the track is sourced from an Receiver, does no audio processing, has a
// constant level, and has a volume setting of 1.0, the audio level is expected
// to be the same as the audio level of the source SSRC, while if the volume setting
// is 0.5, the AudioLevel is expected to be half that value.
//
// For outgoing audio tracks, the AudioLevel is the level of the audio being sent.
AudioLevel float64 `json:"audioLevel"`
// TotalAudioEnergy is the total energy of all the audio samples sent/received
// for this object, calculated by duration * Math.pow(energy/maxEnergy, 2) for
// each audio sample seen.
TotalAudioEnergy float64 `json:"totalAudioEnergy"`
// VoiceActivityFlag represents whether the last RTP packet sent or played out
// by this track contained voice activity or not based on the presence of the
// V bit in the extension header, as defined in [RFC6464].
//
// This value indicates the voice activity in the latest RTP packet played out
// from a given SSRC, and is defined in RTPSynchronizationSource.voiceActivityFlag.
VoiceActivityFlag bool `json:"voiceActivityFlag"`
// TotalSamplesDuration represents the total duration in seconds of all samples
// that have sent or received (and thus counted by TotalSamplesSent or TotalSamplesReceived).
// Can be used with TotalAudioEnergy to compute an average audio level over different intervals.
TotalSamplesDuration float64 `json:"totalSamplesDuration"`
// EchoReturnLoss is only present while the sender is sending a track sourced from
// a microphone where echo cancellation is applied. Calculated in decibels.
EchoReturnLoss float64 `json:"echoReturnLoss"`
// EchoReturnLossEnhancement is only present while the sender is sending a track
// sourced from a microphone where echo cancellation is applied. Calculated in decibels.
EchoReturnLossEnhancement float64 `json:"echoReturnLossEnhancement"`
// TotalSamplesSent is the total number of samples that have been sent by this sender.
TotalSamplesSent uint64 `json:"totalSamplesSent"`
}
// SenderAudioTrackAttachmentStats object represents the stats about one attachment
// of an audio MediaStreamTrack to the PeerConnection object for which one calls GetStats.
//
// It appears in the stats as soon as it is attached (via AddTrack, via AddTransceiver,
// via ReplaceTrack on an RTPSender object).
//
// If an audio track is attached twice (via AddTransceiver or ReplaceTrack), there
// will be two SenderAudioTrackAttachmentStats objects, one for each attachment.
// They will have the same "TrackIdentifier" attribute, but different "ID" attributes.
//
// If the track is detached from the PeerConnection (via removeTrack or via replaceTrack),
// it continues to appear, but with the "ObjectDeleted" member set to true.
type SenderAudioTrackAttachmentStats AudioSenderStats
// VideoSenderStats represents the stats about one video sender of a PeerConnection
// object for which one calls GetStats.
//
// It appears in the stats as soon as the sender is added by either AddTrack or
// AddTransceiver, or by media negotiation.
type VideoSenderStats struct {
// Timestamp is the timestamp associated with this object.
Timestamp StatsTimestamp `json:"timestamp"`
// Type is the object's StatsType
Type StatsType `json:"type"`
// ID is a unique id that is associated with the component inspected to produce
// this Stats object. Two Stats objects will have the same ID if they were produced
// by inspecting the same underlying object.
ID string `json:"id"`
// FramesCaptured represents the total number of frames captured, before encoding,
// for this RTPSender (or for this MediaStreamTrack, if type is "track"). For example,
// if type is "sender" and this sender's track represents a camera, then this is the
// number of frames produced by the camera for this track while being sent by this sender,
// combined with the number of frames produced by all tracks previously attached to this
// sender while being sent by this sender. Framerates can vary due to hardware limitations
// or environmental factors such as lighting conditions.
FramesCaptured uint32 `json:"framesCaptured"`
// FramesSent represents the total number of frames sent by this RTPSender
// (or for this MediaStreamTrack, if type is "track").
FramesSent uint32 `json:"framesSent"`
// HugeFramesSent represents the total number of huge frames sent by this RTPSender
// (or for this MediaStreamTrack, if type is "track"). Huge frames, by definition,
// are frames that have an encoded size at least 2.5 times the average size of the frames.
// The average size of the frames is defined as the target bitrate per second divided
// by the target fps at the time the frame was encoded. These are usually complex
// to encode frames with a lot of changes in the picture. This can be used to estimate,
// e.g slide changes in the streamed presentation. If a huge frame is also a key frame,
// then both counters HugeFramesSent and KeyFramesSent are incremented.
HugeFramesSent uint32 `json:"hugeFramesSent"`
// KeyFramesSent represents the total number of key frames sent by this RTPSender
// (or for this MediaStreamTrack, if type is "track"), such as Infra-frames in
// VP8 [RFC6386] or I-frames in H.264 [RFC6184]. This is a subset of FramesSent.
// FramesSent - KeyFramesSent gives you the number of delta frames sent.
KeyFramesSent uint32 `json:"keyFramesSent"`
}
// SenderVideoTrackAttachmentStats represents the stats about one attachment of a
// video MediaStreamTrack to the PeerConnection object for which one calls GetStats.
//
// It appears in the stats as soon as it is attached (via AddTrack, via AddTransceiver,
// via ReplaceTrack on an RTPSender object).
//
// If a video track is attached twice (via AddTransceiver or ReplaceTrack), there
// will be two SenderVideoTrackAttachmentStats objects, one for each attachment.
// They will have the same "TrackIdentifier" attribute, but different "ID" attributes.
//
// If the track is detached from the PeerConnection (via RemoveTrack or via ReplaceTrack),
// it continues to appear, but with the "ObjectDeleted" member set to true.
type SenderVideoTrackAttachmentStats VideoSenderStats
// AudioReceiverStats contains audio metrics related to a specific receiver.
type AudioReceiverStats struct {
// Timestamp is the timestamp associated with this object.
Timestamp StatsTimestamp `json:"timestamp"`
// Type is the object's StatsType
Type StatsType `json:"type"`
// ID is a unique id that is associated with the component inspected to produce
// this Stats object. Two Stats objects will have the same ID if they were produced
// by inspecting the same underlying object.
ID string `json:"id"`
// AudioLevel represents the output audio level of the track.
//
// The value is a value between 0..1 (linear), where 1.0 represents 0 dBov,
// 0 represents silence, and 0.5 represents approximately 6 dBSPL change in
// the sound pressure level from 0 dBov.
//
// If the track is sourced from an Receiver, does no audio processing, has a
// constant level, and has a volume setting of 1.0, the audio level is expected
// to be the same as the audio level of the source SSRC, while if the volume setting
// is 0.5, the AudioLevel is expected to be half that value.
//
// For outgoing audio tracks, the AudioLevel is the level of the audio being sent.
AudioLevel float64 `json:"audioLevel"`
// TotalAudioEnergy is the total energy of all the audio samples sent/received
// for this object, calculated by duration * Math.pow(energy/maxEnergy, 2) for
// each audio sample seen.
TotalAudioEnergy float64 `json:"totalAudioEnergy"`
// VoiceActivityFlag represents whether the last RTP packet sent or played out
// by this track contained voice activity or not based on the presence of the
// V bit in the extension header, as defined in [RFC6464].
//
// This value indicates the voice activity in the latest RTP packet played out
// from a given SSRC, and is defined in RTPSynchronizationSource.voiceActivityFlag.
VoiceActivityFlag bool `json:"voiceActivityFlag"`
// TotalSamplesDuration represents the total duration in seconds of all samples
// that have sent or received (and thus counted by TotalSamplesSent or TotalSamplesReceived).
// Can be used with TotalAudioEnergy to compute an average audio level over different intervals.
TotalSamplesDuration float64 `json:"totalSamplesDuration"`