stats.go 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. package webrtc
  4. import (
  5. "fmt"
  6. "sync"
  7. "time"
  8. "github.com/pion/ice/v2"
  9. )
  10. // A Stats object contains a set of statistics copies out of a monitored component
  11. // of the WebRTC stack at a specific time.
  12. type Stats interface{}
  13. // StatsType indicates the type of the object that a Stats object represents.
  14. type StatsType string
  15. const (
  16. // StatsTypeCodec is used by CodecStats.
  17. StatsTypeCodec StatsType = "codec"
  18. // StatsTypeInboundRTP is used by InboundRTPStreamStats.
  19. StatsTypeInboundRTP StatsType = "inbound-rtp"
  20. // StatsTypeOutboundRTP is used by OutboundRTPStreamStats.
  21. StatsTypeOutboundRTP StatsType = "outbound-rtp"
  22. // StatsTypeRemoteInboundRTP is used by RemoteInboundRTPStreamStats.
  23. StatsTypeRemoteInboundRTP StatsType = "remote-inbound-rtp"
  24. // StatsTypeRemoteOutboundRTP is used by RemoteOutboundRTPStreamStats.
  25. StatsTypeRemoteOutboundRTP StatsType = "remote-outbound-rtp"
  26. // StatsTypeCSRC is used by RTPContributingSourceStats.
  27. StatsTypeCSRC StatsType = "csrc"
  28. // StatsTypePeerConnection used by PeerConnectionStats.
  29. StatsTypePeerConnection StatsType = "peer-connection"
  30. // StatsTypeDataChannel is used by DataChannelStats.
  31. StatsTypeDataChannel StatsType = "data-channel"
  32. // StatsTypeStream is used by MediaStreamStats.
  33. StatsTypeStream StatsType = "stream"
  34. // StatsTypeTrack is used by SenderVideoTrackAttachmentStats and SenderAudioTrackAttachmentStats.
  35. StatsTypeTrack StatsType = "track"
  36. // StatsTypeSender is used by by the AudioSenderStats or VideoSenderStats depending on kind.
  37. StatsTypeSender StatsType = "sender"
  38. // StatsTypeReceiver is used by the AudioReceiverStats or VideoReceiverStats depending on kind.
  39. StatsTypeReceiver StatsType = "receiver"
  40. // StatsTypeTransport is used by TransportStats.
  41. StatsTypeTransport StatsType = "transport"
  42. // StatsTypeCandidatePair is used by ICECandidatePairStats.
  43. StatsTypeCandidatePair StatsType = "candidate-pair"
  44. // StatsTypeLocalCandidate is used by ICECandidateStats for the local candidate.
  45. StatsTypeLocalCandidate StatsType = "local-candidate"
  46. // StatsTypeRemoteCandidate is used by ICECandidateStats for the remote candidate.
  47. StatsTypeRemoteCandidate StatsType = "remote-candidate"
  48. // StatsTypeCertificate is used by CertificateStats.
  49. StatsTypeCertificate StatsType = "certificate"
  50. )
  51. // StatsTimestamp is a timestamp represented by the floating point number of
  52. // milliseconds since the epoch.
  53. type StatsTimestamp float64
  54. // Time returns the time.Time represented by this timestamp.
  55. func (s StatsTimestamp) Time() time.Time {
  56. millis := float64(s)
  57. nanos := int64(millis * float64(time.Millisecond))
  58. return time.Unix(0, nanos).UTC()
  59. }
  60. func statsTimestampFrom(t time.Time) StatsTimestamp {
  61. return StatsTimestamp(t.UnixNano() / int64(time.Millisecond))
  62. }
  63. func statsTimestampNow() StatsTimestamp {
  64. return statsTimestampFrom(time.Now())
  65. }
  66. // StatsReport collects Stats objects indexed by their ID.
  67. type StatsReport map[string]Stats
  68. type statsReportCollector struct {
  69. collectingGroup sync.WaitGroup
  70. report StatsReport
  71. mux sync.Mutex
  72. }
  73. func newStatsReportCollector() *statsReportCollector {
  74. return &statsReportCollector{report: make(StatsReport)}
  75. }
  76. func (src *statsReportCollector) Collecting() {
  77. src.collectingGroup.Add(1)
  78. }
  79. func (src *statsReportCollector) Collect(id string, stats Stats) {
  80. src.mux.Lock()
  81. defer src.mux.Unlock()
  82. src.report[id] = stats
  83. src.collectingGroup.Done()
  84. }
  85. func (src *statsReportCollector) Done() {
  86. src.collectingGroup.Done()
  87. }
  88. func (src *statsReportCollector) Ready() StatsReport {
  89. src.collectingGroup.Wait()
  90. src.mux.Lock()
  91. defer src.mux.Unlock()
  92. return src.report
  93. }
  94. // CodecType specifies whether a CodecStats objects represents a media format
  95. // that is being encoded or decoded
  96. type CodecType string
  97. const (
  98. // CodecTypeEncode means the attached CodecStats represents a media format that
  99. // is being encoded, or that the implementation is prepared to encode.
  100. CodecTypeEncode CodecType = "encode"
  101. // CodecTypeDecode means the attached CodecStats represents a media format
  102. // that the implementation is prepared to decode.
  103. CodecTypeDecode CodecType = "decode"
  104. )
  105. // CodecStats contains statistics for a codec that is currently being used by RTP streams
  106. // being sent or received by this PeerConnection object.
  107. type CodecStats struct {
  108. // Timestamp is the timestamp associated with this object.
  109. Timestamp StatsTimestamp `json:"timestamp"`
  110. // Type is the object's StatsType
  111. Type StatsType `json:"type"`
  112. // ID is a unique id that is associated with the component inspected to produce
  113. // this Stats object. Two Stats objects will have the same ID if they were produced
  114. // by inspecting the same underlying object.
  115. ID string `json:"id"`
  116. // PayloadType as used in RTP encoding or decoding
  117. PayloadType PayloadType `json:"payloadType"`
  118. // CodecType of this CodecStats
  119. CodecType CodecType `json:"codecType"`
  120. // TransportID is the unique identifier of the transport on which this codec is
  121. // being used, which can be used to look up the corresponding TransportStats object.
  122. TransportID string `json:"transportId"`
  123. // MimeType is the codec MIME media type/subtype. e.g., video/vp8 or equivalent.
  124. MimeType string `json:"mimeType"`
  125. // ClockRate represents the media sampling rate.
  126. ClockRate uint32 `json:"clockRate"`
  127. // Channels is 2 for stereo, missing for most other cases.
  128. Channels uint8 `json:"channels"`
  129. // SDPFmtpLine is the a=fmtp line in the SDP corresponding to the codec,
  130. // i.e., after the colon following the PT.
  131. SDPFmtpLine string `json:"sdpFmtpLine"`
  132. // Implementation identifies the implementation used. This is useful for diagnosing
  133. // interoperability issues.
  134. Implementation string `json:"implementation"`
  135. }
  136. // InboundRTPStreamStats contains statistics for an inbound RTP stream that is
  137. // currently received with this PeerConnection object.
  138. type InboundRTPStreamStats struct {
  139. // Timestamp is the timestamp associated with this object.
  140. Timestamp StatsTimestamp `json:"timestamp"`
  141. // Type is the object's StatsType
  142. Type StatsType `json:"type"`
  143. // ID is a unique id that is associated with the component inspected to produce
  144. // this Stats object. Two Stats objects will have the same ID if they were produced
  145. // by inspecting the same underlying object.
  146. ID string `json:"id"`
  147. // SSRC is the 32-bit unsigned integer value used to identify the source of the
  148. // stream of RTP packets that this stats object concerns.
  149. SSRC SSRC `json:"ssrc"`
  150. // Kind is either "audio" or "video"
  151. Kind string `json:"kind"`
  152. // It is a unique identifier that is associated to the object that was inspected
  153. // to produce the TransportStats associated with this RTP stream.
  154. TransportID string `json:"transportId"`
  155. // CodecID is a unique identifier that is associated to the object that was inspected
  156. // to produce the CodecStats associated with this RTP stream.
  157. CodecID string `json:"codecId"`
  158. // FIRCount counts the total number of Full Intra Request (FIR) packets received
  159. // by the sender. This metric is only valid for video and is sent by receiver.
  160. FIRCount uint32 `json:"firCount"`
  161. // PLICount counts the total number of Picture Loss Indication (PLI) packets
  162. // received by the sender. This metric is only valid for video and is sent by receiver.
  163. PLICount uint32 `json:"pliCount"`
  164. // NACKCount counts the total number of Negative ACKnowledgement (NACK) packets
  165. // received by the sender and is sent by receiver.
  166. NACKCount uint32 `json:"nackCount"`
  167. // SLICount counts the total number of Slice Loss Indication (SLI) packets received
  168. // by the sender. This metric is only valid for video and is sent by receiver.
  169. SLICount uint32 `json:"sliCount"`
  170. // QPSum is the sum of the QP values of frames passed. The count of frames is
  171. // in FramesDecoded for inbound stream stats, and in FramesEncoded for outbound stream stats.
  172. QPSum uint64 `json:"qpSum"`
  173. // PacketsReceived is the total number of RTP packets received for this SSRC.
  174. PacketsReceived uint32 `json:"packetsReceived"`
  175. // PacketsLost is the total number of RTP packets lost for this SSRC. Note that
  176. // because of how this is estimated, it can be negative if more packets are received than sent.
  177. PacketsLost int32 `json:"packetsLost"`
  178. // Jitter is the packet jitter measured in seconds for this SSRC
  179. Jitter float64 `json:"jitter"`
  180. // PacketsDiscarded is the cumulative number of RTP packets discarded by the jitter
  181. // buffer due to late or early-arrival, i.e., these packets are not played out.
  182. // RTP packets discarded due to packet duplication are not reported in this metric.
  183. PacketsDiscarded uint32 `json:"packetsDiscarded"`
  184. // PacketsRepaired is the cumulative number of lost RTP packets repaired after applying
  185. // an error-resilience mechanism. It is measured for the primary source RTP packets
  186. // and only counted for RTP packets that have no further chance of repair.
  187. PacketsRepaired uint32 `json:"packetsRepaired"`
  188. // BurstPacketsLost is the cumulative number of RTP packets lost during loss bursts.
  189. BurstPacketsLost uint32 `json:"burstPacketsLost"`
  190. // BurstPacketsDiscarded is the cumulative number of RTP packets discarded during discard bursts.
  191. BurstPacketsDiscarded uint32 `json:"burstPacketsDiscarded"`
  192. // BurstLossCount is the cumulative number of bursts of lost RTP packets.
  193. BurstLossCount uint32 `json:"burstLossCount"`
  194. // BurstDiscardCount is the cumulative number of bursts of discarded RTP packets.
  195. BurstDiscardCount uint32 `json:"burstDiscardCount"`
  196. // BurstLossRate is the fraction of RTP packets lost during bursts to the
  197. // total number of RTP packets expected in the bursts.
  198. BurstLossRate float64 `json:"burstLossRate"`
  199. // BurstDiscardRate is the fraction of RTP packets discarded during bursts to
  200. // the total number of RTP packets expected in bursts.
  201. BurstDiscardRate float64 `json:"burstDiscardRate"`
  202. // GapLossRate is the fraction of RTP packets lost during the gap periods.
  203. GapLossRate float64 `json:"gapLossRate"`
  204. // GapDiscardRate is the fraction of RTP packets discarded during the gap periods.
  205. GapDiscardRate float64 `json:"gapDiscardRate"`
  206. // TrackID is the identifier of the stats object representing the receiving track,
  207. // a ReceiverAudioTrackAttachmentStats or ReceiverVideoTrackAttachmentStats.
  208. TrackID string `json:"trackId"`
  209. // ReceiverID is the stats ID used to look up the AudioReceiverStats or VideoReceiverStats
  210. // object receiving this stream.
  211. ReceiverID string `json:"receiverId"`
  212. // RemoteID is used for looking up the remote RemoteOutboundRTPStreamStats object
  213. // for the same SSRC.
  214. RemoteID string `json:"remoteId"`
  215. // FramesDecoded represents the total number of frames correctly decoded for this SSRC,
  216. // i.e., frames that would be displayed if no frames are dropped. Only valid for video.
  217. FramesDecoded uint32 `json:"framesDecoded"`
  218. // LastPacketReceivedTimestamp represents the timestamp at which the last packet was
  219. // received for this SSRC. This differs from Timestamp, which represents the time
  220. // at which the statistics were generated by the local endpoint.
  221. LastPacketReceivedTimestamp StatsTimestamp `json:"lastPacketReceivedTimestamp"`
  222. // AverageRTCPInterval is the average RTCP interval between two consecutive compound RTCP packets.
  223. // This is calculated by the sending endpoint when sending compound RTCP reports.
  224. // Compound packets must contain at least a RTCP RR or SR packet and an SDES packet
  225. // with the CNAME item.
  226. AverageRTCPInterval float64 `json:"averageRtcpInterval"`
  227. // FECPacketsReceived is the total number of RTP FEC packets received for this SSRC.
  228. // This counter can also be incremented when receiving FEC packets in-band with media packets (e.g., with Opus).
  229. FECPacketsReceived uint32 `json:"fecPacketsReceived"`
  230. // BytesReceived is the total number of bytes received for this SSRC.
  231. BytesReceived uint64 `json:"bytesReceived"`
  232. // PacketsFailedDecryption is the cumulative number of RTP packets that failed
  233. // to be decrypted. These packets are not counted by PacketsDiscarded.
  234. PacketsFailedDecryption uint32 `json:"packetsFailedDecryption"`
  235. // PacketsDuplicated is the cumulative number of packets discarded because they
  236. // are duplicated. Duplicate packets are not counted in PacketsDiscarded.
  237. //
  238. // Duplicated packets have the same RTP sequence number and content as a previously
  239. // received packet. If multiple duplicates of a packet are received, all of them are counted.
  240. // An improved estimate of lost packets can be calculated by adding PacketsDuplicated to PacketsLost.
  241. PacketsDuplicated uint32 `json:"packetsDuplicated"`
  242. // PerDSCPPacketsReceived is the total number of packets received for this SSRC,
  243. // per Differentiated Services code point (DSCP) [RFC2474]. DSCPs are identified
  244. // as decimal integers in string form. Note that due to network remapping and bleaching,
  245. // these numbers are not expected to match the numbers seen on sending. Not all
  246. // OSes make this information available.
  247. PerDSCPPacketsReceived map[string]uint32 `json:"perDscpPacketsReceived"`
  248. }
  249. // QualityLimitationReason lists the reason for limiting the resolution and/or framerate.
  250. // Only valid for video.
  251. type QualityLimitationReason string
  252. const (
  253. // QualityLimitationReasonNone means the resolution and/or framerate is not limited.
  254. QualityLimitationReasonNone QualityLimitationReason = "none"
  255. // QualityLimitationReasonCPU means the resolution and/or framerate is primarily limited due to CPU load.
  256. QualityLimitationReasonCPU QualityLimitationReason = "cpu"
  257. // 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.
  258. QualityLimitationReasonBandwidth QualityLimitationReason = "bandwidth"
  259. // QualityLimitationReasonOther means the resolution and/or framerate is primarily limited for a reason other than the above.
  260. QualityLimitationReasonOther QualityLimitationReason = "other"
  261. )
  262. // OutboundRTPStreamStats contains statistics for an outbound RTP stream that is
  263. // currently sent with this PeerConnection object.
  264. type OutboundRTPStreamStats struct {
  265. // Timestamp is the timestamp associated with this object.
  266. Timestamp StatsTimestamp `json:"timestamp"`
  267. // Type is the object's StatsType
  268. Type StatsType `json:"type"`
  269. // ID is a unique id that is associated with the component inspected to produce
  270. // this Stats object. Two Stats objects will have the same ID if they were produced
  271. // by inspecting the same underlying object.
  272. ID string `json:"id"`
  273. // SSRC is the 32-bit unsigned integer value used to identify the source of the
  274. // stream of RTP packets that this stats object concerns.
  275. SSRC SSRC `json:"ssrc"`
  276. // Kind is either "audio" or "video"
  277. Kind string `json:"kind"`
  278. // It is a unique identifier that is associated to the object that was inspected
  279. // to produce the TransportStats associated with this RTP stream.
  280. TransportID string `json:"transportId"`
  281. // CodecID is a unique identifier that is associated to the object that was inspected
  282. // to produce the CodecStats associated with this RTP stream.
  283. CodecID string `json:"codecId"`
  284. // FIRCount counts the total number of Full Intra Request (FIR) packets received
  285. // by the sender. This metric is only valid for video and is sent by receiver.
  286. FIRCount uint32 `json:"firCount"`
  287. // PLICount counts the total number of Picture Loss Indication (PLI) packets
  288. // received by the sender. This metric is only valid for video and is sent by receiver.
  289. PLICount uint32 `json:"pliCount"`
  290. // NACKCount counts the total number of Negative ACKnowledgement (NACK) packets
  291. // received by the sender and is sent by receiver.
  292. NACKCount uint32 `json:"nackCount"`
  293. // SLICount counts the total number of Slice Loss Indication (SLI) packets received
  294. // by the sender. This metric is only valid for video and is sent by receiver.
  295. SLICount uint32 `json:"sliCount"`
  296. // QPSum is the sum of the QP values of frames passed. The count of frames is
  297. // in FramesDecoded for inbound stream stats, and in FramesEncoded for outbound stream stats.
  298. QPSum uint64 `json:"qpSum"`
  299. // PacketsSent is the total number of RTP packets sent for this SSRC.
  300. PacketsSent uint32 `json:"packetsSent"`
  301. // PacketsDiscardedOnSend is the total number of RTP packets for this SSRC that
  302. // have been discarded due to socket errors, i.e. a socket error occurred when handing
  303. // the packets to the socket. This might happen due to various reasons, including
  304. // full buffer or no available memory.
  305. PacketsDiscardedOnSend uint32 `json:"packetsDiscardedOnSend"`
  306. // FECPacketsSent is the total number of RTP FEC packets sent for this SSRC.
  307. // This counter can also be incremented when sending FEC packets in-band with
  308. // media packets (e.g., with Opus).
  309. FECPacketsSent uint32 `json:"fecPacketsSent"`
  310. // BytesSent is the total number of bytes sent for this SSRC.
  311. BytesSent uint64 `json:"bytesSent"`
  312. // BytesDiscardedOnSend is the total number of bytes for this SSRC that have
  313. // been discarded due to socket errors, i.e. a socket error occurred when handing
  314. // the packets containing the bytes to the socket. This might happen due to various
  315. // reasons, including full buffer or no available memory.
  316. BytesDiscardedOnSend uint64 `json:"bytesDiscardedOnSend"`
  317. // TrackID is the identifier of the stats object representing the current track
  318. // attachment to the sender of this stream, a SenderAudioTrackAttachmentStats
  319. // or SenderVideoTrackAttachmentStats.
  320. TrackID string `json:"trackId"`
  321. // SenderID is the stats ID used to look up the AudioSenderStats or VideoSenderStats
  322. // object sending this stream.
  323. SenderID string `json:"senderId"`
  324. // RemoteID is used for looking up the remote RemoteInboundRTPStreamStats object
  325. // for the same SSRC.
  326. RemoteID string `json:"remoteId"`
  327. // LastPacketSentTimestamp represents the timestamp at which the last packet was
  328. // sent for this SSRC. This differs from timestamp, which represents the time at
  329. // which the statistics were generated by the local endpoint.
  330. LastPacketSentTimestamp StatsTimestamp `json:"lastPacketSentTimestamp"`
  331. // TargetBitrate is the current target bitrate configured for this particular SSRC
  332. // and is the Transport Independent Application Specific (TIAS) bitrate [RFC3890].
  333. // Typically, the target bitrate is a configuration parameter provided to the codec's
  334. // encoder and does not count the size of the IP or other transport layers like TCP or UDP.
  335. // It is measured in bits per second and the bitrate is calculated over a 1 second window.
  336. TargetBitrate float64 `json:"targetBitrate"`
  337. // FramesEncoded represents the total number of frames successfully encoded for this RTP media stream.
  338. // Only valid for video.
  339. FramesEncoded uint32 `json:"framesEncoded"`
  340. // TotalEncodeTime is the total number of seconds that has been spent encoding the
  341. // framesEncoded frames of this stream. The average encode time can be calculated by
  342. // dividing this value with FramesEncoded. The time it takes to encode one frame is the
  343. // time passed between feeding the encoder a frame and the encoder returning encoded data
  344. // for that frame. This does not include any additional time it may take to packetize the resulting data.
  345. TotalEncodeTime float64 `json:"totalEncodeTime"`
  346. // AverageRTCPInterval is the average RTCP interval between two consecutive compound RTCP
  347. // packets. This is calculated by the sending endpoint when sending compound RTCP reports.
  348. // Compound packets must contain at least a RTCP RR or SR packet and an SDES packet with the CNAME item.
  349. AverageRTCPInterval float64 `json:"averageRtcpInterval"`
  350. // QualityLimitationReason is the current reason for limiting the resolution and/or framerate,
  351. // or "none" if not limited. Only valid for video.
  352. QualityLimitationReason QualityLimitationReason `json:"qualityLimitationReason"`
  353. // QualityLimitationDurations is record of the total time, in seconds, that this
  354. // stream has spent in each quality limitation state. The record includes a mapping
  355. // for all QualityLimitationReason types, including "none". Only valid for video.
  356. QualityLimitationDurations map[string]float64 `json:"qualityLimitationDurations"`
  357. // PerDSCPPacketsSent is the total number of packets sent for this SSRC, per DSCP.
  358. // DSCPs are identified as decimal integers in string form.
  359. PerDSCPPacketsSent map[string]uint32 `json:"perDscpPacketsSent"`
  360. }
  361. // RemoteInboundRTPStreamStats contains statistics for the remote endpoint's inbound
  362. // RTP stream corresponding to an outbound stream that is currently sent with this
  363. // PeerConnection object. It is measured at the remote endpoint and reported in an RTCP
  364. // Receiver Report (RR) or RTCP Extended Report (XR).
  365. type RemoteInboundRTPStreamStats struct {
  366. // Timestamp is the timestamp associated with this object.
  367. Timestamp StatsTimestamp `json:"timestamp"`
  368. // Type is the object's StatsType
  369. Type StatsType `json:"type"`
  370. // ID is a unique id that is associated with the component inspected to produce
  371. // this Stats object. Two Stats objects will have the same ID if they were produced
  372. // by inspecting the same underlying object.
  373. ID string `json:"id"`
  374. // SSRC is the 32-bit unsigned integer value used to identify the source of the
  375. // stream of RTP packets that this stats object concerns.
  376. SSRC SSRC `json:"ssrc"`
  377. // Kind is either "audio" or "video"
  378. Kind string `json:"kind"`
  379. // It is a unique identifier that is associated to the object that was inspected
  380. // to produce the TransportStats associated with this RTP stream.
  381. TransportID string `json:"transportId"`
  382. // CodecID is a unique identifier that is associated to the object that was inspected
  383. // to produce the CodecStats associated with this RTP stream.
  384. CodecID string `json:"codecId"`
  385. // FIRCount counts the total number of Full Intra Request (FIR) packets received
  386. // by the sender. This metric is only valid for video and is sent by receiver.
  387. FIRCount uint32 `json:"firCount"`
  388. // PLICount counts the total number of Picture Loss Indication (PLI) packets
  389. // received by the sender. This metric is only valid for video and is sent by receiver.
  390. PLICount uint32 `json:"pliCount"`
  391. // NACKCount counts the total number of Negative ACKnowledgement (NACK) packets
  392. // received by the sender and is sent by receiver.
  393. NACKCount uint32 `json:"nackCount"`
  394. // SLICount counts the total number of Slice Loss Indication (SLI) packets received
  395. // by the sender. This metric is only valid for video and is sent by receiver.
  396. SLICount uint32 `json:"sliCount"`
  397. // QPSum is the sum of the QP values of frames passed. The count of frames is
  398. // in FramesDecoded for inbound stream stats, and in FramesEncoded for outbound stream stats.
  399. QPSum uint64 `json:"qpSum"`
  400. // PacketsReceived is the total number of RTP packets received for this SSRC.
  401. PacketsReceived uint32 `json:"packetsReceived"`
  402. // PacketsLost is the total number of RTP packets lost for this SSRC. Note that
  403. // because of how this is estimated, it can be negative if more packets are received than sent.
  404. PacketsLost int32 `json:"packetsLost"`
  405. // Jitter is the packet jitter measured in seconds for this SSRC
  406. Jitter float64 `json:"jitter"`
  407. // PacketsDiscarded is the cumulative number of RTP packets discarded by the jitter
  408. // buffer due to late or early-arrival, i.e., these packets are not played out.
  409. // RTP packets discarded due to packet duplication are not reported in this metric.
  410. PacketsDiscarded uint32 `json:"packetsDiscarded"`
  411. // PacketsRepaired is the cumulative number of lost RTP packets repaired after applying
  412. // an error-resilience mechanism. It is measured for the primary source RTP packets
  413. // and only counted for RTP packets that have no further chance of repair.
  414. PacketsRepaired uint32 `json:"packetsRepaired"`
  415. // BurstPacketsLost is the cumulative number of RTP packets lost during loss bursts.
  416. BurstPacketsLost uint32 `json:"burstPacketsLost"`
  417. // BurstPacketsDiscarded is the cumulative number of RTP packets discarded during discard bursts.
  418. BurstPacketsDiscarded uint32 `json:"burstPacketsDiscarded"`
  419. // BurstLossCount is the cumulative number of bursts of lost RTP packets.
  420. BurstLossCount uint32 `json:"burstLossCount"`
  421. // BurstDiscardCount is the cumulative number of bursts of discarded RTP packets.
  422. BurstDiscardCount uint32 `json:"burstDiscardCount"`
  423. // BurstLossRate is the fraction of RTP packets lost during bursts to the
  424. // total number of RTP packets expected in the bursts.
  425. BurstLossRate float64 `json:"burstLossRate"`
  426. // BurstDiscardRate is the fraction of RTP packets discarded during bursts to
  427. // the total number of RTP packets expected in bursts.
  428. BurstDiscardRate float64 `json:"burstDiscardRate"`
  429. // GapLossRate is the fraction of RTP packets lost during the gap periods.
  430. GapLossRate float64 `json:"gapLossRate"`
  431. // GapDiscardRate is the fraction of RTP packets discarded during the gap periods.
  432. GapDiscardRate float64 `json:"gapDiscardRate"`
  433. // LocalID is used for looking up the local OutboundRTPStreamStats object for the same SSRC.
  434. LocalID string `json:"localId"`
  435. // RoundTripTime is the estimated round trip time for this SSRC based on the
  436. // RTCP timestamps in the RTCP Receiver Report (RR) and measured in seconds.
  437. RoundTripTime float64 `json:"roundTripTime"`
  438. // FractionLost is the the fraction packet loss reported for this SSRC.
  439. FractionLost float64 `json:"fractionLost"`
  440. }
  441. // RemoteOutboundRTPStreamStats contains statistics for the remote endpoint's outbound
  442. // RTP stream corresponding to an inbound stream that is currently received with this
  443. // PeerConnection object. It is measured at the remote endpoint and reported in an
  444. // RTCP Sender Report (SR).
  445. type RemoteOutboundRTPStreamStats struct {
  446. // Timestamp is the timestamp associated with this object.
  447. Timestamp StatsTimestamp `json:"timestamp"`
  448. // Type is the object's StatsType
  449. Type StatsType `json:"type"`
  450. // ID is a unique id that is associated with the component inspected to produce
  451. // this Stats object. Two Stats objects will have the same ID if they were produced
  452. // by inspecting the same underlying object.
  453. ID string `json:"id"`
  454. // SSRC is the 32-bit unsigned integer value used to identify the source of the
  455. // stream of RTP packets that this stats object concerns.
  456. SSRC SSRC `json:"ssrc"`
  457. // Kind is either "audio" or "video"
  458. Kind string `json:"kind"`
  459. // It is a unique identifier that is associated to the object that was inspected
  460. // to produce the TransportStats associated with this RTP stream.
  461. TransportID string `json:"transportId"`
  462. // CodecID is a unique identifier that is associated to the object that was inspected
  463. // to produce the CodecStats associated with this RTP stream.
  464. CodecID string `json:"codecId"`
  465. // FIRCount counts the total number of Full Intra Request (FIR) packets received
  466. // by the sender. This metric is only valid for video and is sent by receiver.
  467. FIRCount uint32 `json:"firCount"`
  468. // PLICount counts the total number of Picture Loss Indication (PLI) packets
  469. // received by the sender. This metric is only valid for video and is sent by receiver.
  470. PLICount uint32 `json:"pliCount"`
  471. // NACKCount counts the total number of Negative ACKnowledgement (NACK) packets
  472. // received by the sender and is sent by receiver.
  473. NACKCount uint32 `json:"nackCount"`
  474. // SLICount counts the total number of Slice Loss Indication (SLI) packets received
  475. // by the sender. This metric is only valid for video and is sent by receiver.
  476. SLICount uint32 `json:"sliCount"`
  477. // QPSum is the sum of the QP values of frames passed. The count of frames is
  478. // in FramesDecoded for inbound stream stats, and in FramesEncoded for outbound stream stats.
  479. QPSum uint64 `json:"qpSum"`
  480. // PacketsSent is the total number of RTP packets sent for this SSRC.
  481. PacketsSent uint32 `json:"packetsSent"`
  482. // PacketsDiscardedOnSend is the total number of RTP packets for this SSRC that
  483. // have been discarded due to socket errors, i.e. a socket error occurred when handing
  484. // the packets to the socket. This might happen due to various reasons, including
  485. // full buffer or no available memory.
  486. PacketsDiscardedOnSend uint32 `json:"packetsDiscardedOnSend"`
  487. // FECPacketsSent is the total number of RTP FEC packets sent for this SSRC.
  488. // This counter can also be incremented when sending FEC packets in-band with
  489. // media packets (e.g., with Opus).
  490. FECPacketsSent uint32 `json:"fecPacketsSent"`
  491. // BytesSent is the total number of bytes sent for this SSRC.
  492. BytesSent uint64 `json:"bytesSent"`
  493. // BytesDiscardedOnSend is the total number of bytes for this SSRC that have
  494. // been discarded due to socket errors, i.e. a socket error occurred when handing
  495. // the packets containing the bytes to the socket. This might happen due to various
  496. // reasons, including full buffer or no available memory.
  497. BytesDiscardedOnSend uint64 `json:"bytesDiscardedOnSend"`
  498. // LocalID is used for looking up the local InboundRTPStreamStats object for the same SSRC.
  499. LocalID string `json:"localId"`
  500. // RemoteTimestamp represents the remote timestamp at which these statistics were
  501. // sent by the remote endpoint. This differs from timestamp, which represents the
  502. // time at which the statistics were generated or received by the local endpoint.
  503. // The RemoteTimestamp, if present, is derived from the NTP timestamp in an RTCP
  504. // Sender Report (SR) packet, which reflects the remote endpoint's clock.
  505. // That clock may not be synchronized with the local clock.
  506. RemoteTimestamp StatsTimestamp `json:"remoteTimestamp"`
  507. }
  508. // RTPContributingSourceStats contains statistics for a contributing source (CSRC) that contributed
  509. // to an inbound RTP stream.
  510. type RTPContributingSourceStats struct {
  511. // Timestamp is the timestamp associated with this object.
  512. Timestamp StatsTimestamp `json:"timestamp"`
  513. // Type is the object's StatsType
  514. Type StatsType `json:"type"`
  515. // ID is a unique id that is associated with the component inspected to produce
  516. // this Stats object. Two Stats objects will have the same ID if they were produced
  517. // by inspecting the same underlying object.
  518. ID string `json:"id"`
  519. // ContributorSSRC is the SSRC identifier of the contributing source represented
  520. // by this stats object. It is a 32-bit unsigned integer that appears in the CSRC
  521. // list of any packets the relevant source contributed to.
  522. ContributorSSRC SSRC `json:"contributorSsrc"`
  523. // InboundRTPStreamID is the ID of the InboundRTPStreamStats object representing
  524. // the inbound RTP stream that this contributing source is contributing to.
  525. InboundRTPStreamID string `json:"inboundRtpStreamId"`
  526. // PacketsContributedTo is the total number of RTP packets that this contributing
  527. // source contributed to. This value is incremented each time a packet is counted
  528. // by InboundRTPStreamStats.packetsReceived, and the packet's CSRC list contains
  529. // the SSRC identifier of this contributing source, ContributorSSRC.
  530. PacketsContributedTo uint32 `json:"packetsContributedTo"`
  531. // AudioLevel is present if the last received RTP packet that this source contributed
  532. // to contained an [RFC6465] mixer-to-client audio level header extension. The value
  533. // of audioLevel is between 0..1 (linear), where 1.0 represents 0 dBov, 0 represents
  534. // silence, and 0.5 represents approximately 6 dBSPL change in the sound pressure level from 0 dBov.
  535. AudioLevel float64 `json:"audioLevel"`
  536. }
  537. // PeerConnectionStats contains statistics related to the PeerConnection object.
  538. type PeerConnectionStats struct {
  539. // Timestamp is the timestamp associated with this object.
  540. Timestamp StatsTimestamp `json:"timestamp"`
  541. // Type is the object's StatsType
  542. Type StatsType `json:"type"`
  543. // ID is a unique id that is associated with the component inspected to produce
  544. // this Stats object. Two Stats objects will have the same ID if they were produced
  545. // by inspecting the same underlying object.
  546. ID string `json:"id"`
  547. // DataChannelsOpened represents the number of unique DataChannels that have
  548. // entered the "open" state during their lifetime.
  549. DataChannelsOpened uint32 `json:"dataChannelsOpened"`
  550. // DataChannelsClosed represents the number of unique DataChannels that have
  551. // left the "open" state during their lifetime (due to being closed by either
  552. // end or the underlying transport being closed). DataChannels that transition
  553. // from "connecting" to "closing" or "closed" without ever being "open"
  554. // are not counted in this number.
  555. DataChannelsClosed uint32 `json:"dataChannelsClosed"`
  556. // DataChannelsRequested Represents the number of unique DataChannels returned
  557. // from a successful createDataChannel() call on the PeerConnection. If the
  558. // underlying data transport is not established, these may be in the "connecting" state.
  559. DataChannelsRequested uint32 `json:"dataChannelsRequested"`
  560. // DataChannelsAccepted represents the number of unique DataChannels signaled
  561. // in a "datachannel" event on the PeerConnection.
  562. DataChannelsAccepted uint32 `json:"dataChannelsAccepted"`
  563. }
  564. // DataChannelStats contains statistics related to each DataChannel ID.
  565. type DataChannelStats struct {
  566. // Timestamp is the timestamp associated with this object.
  567. Timestamp StatsTimestamp `json:"timestamp"`
  568. // Type is the object's StatsType
  569. Type StatsType `json:"type"`
  570. // ID is a unique id that is associated with the component inspected to produce
  571. // this Stats object. Two Stats objects will have the same ID if they were produced
  572. // by inspecting the same underlying object.
  573. ID string `json:"id"`
  574. // Label is the "label" value of the DataChannel object.
  575. Label string `json:"label"`
  576. // Protocol is the "protocol" value of the DataChannel object.
  577. Protocol string `json:"protocol"`
  578. // DataChannelIdentifier is the "id" attribute of the DataChannel object.
  579. DataChannelIdentifier int32 `json:"dataChannelIdentifier"`
  580. // TransportID the ID of the TransportStats object for transport used to carry this datachannel.
  581. TransportID string `json:"transportId"`
  582. // State is the "readyState" value of the DataChannel object.
  583. State DataChannelState `json:"state"`
  584. // MessagesSent represents the total number of API "message" events sent.
  585. MessagesSent uint32 `json:"messagesSent"`
  586. // BytesSent represents the total number of payload bytes sent on this
  587. // datachannel not including headers or padding.
  588. BytesSent uint64 `json:"bytesSent"`
  589. // MessagesReceived represents the total number of API "message" events received.
  590. MessagesReceived uint32 `json:"messagesReceived"`
  591. // BytesReceived represents the total number of bytes received on this
  592. // datachannel not including headers or padding.
  593. BytesReceived uint64 `json:"bytesReceived"`
  594. }
  595. // MediaStreamStats contains statistics related to a specific MediaStream.
  596. type MediaStreamStats struct {
  597. // Timestamp is the timestamp associated with this object.
  598. Timestamp StatsTimestamp `json:"timestamp"`
  599. // Type is the object's StatsType
  600. Type StatsType `json:"type"`
  601. // ID is a unique id that is associated with the component inspected to produce
  602. // this Stats object. Two Stats objects will have the same ID if they were produced
  603. // by inspecting the same underlying object.
  604. ID string `json:"id"`
  605. // StreamIdentifier is the "id" property of the MediaStream
  606. StreamIdentifier string `json:"streamIdentifier"`
  607. // TrackIDs is a list of the identifiers of the stats object representing the
  608. // stream's tracks, either ReceiverAudioTrackAttachmentStats or ReceiverVideoTrackAttachmentStats.
  609. TrackIDs []string `json:"trackIds"`
  610. }
  611. // AudioSenderStats represents the stats about one audio sender of a PeerConnection
  612. // object for which one calls GetStats.
  613. //
  614. // It appears in the stats as soon as the RTPSender is added by either AddTrack
  615. // or AddTransceiver, or by media negotiation.
  616. type AudioSenderStats struct {
  617. // Timestamp is the timestamp associated with this object.
  618. Timestamp StatsTimestamp `json:"timestamp"`
  619. // Type is the object's StatsType
  620. Type StatsType `json:"type"`
  621. // ID is a unique id that is associated with the component inspected to produce
  622. // this Stats object. Two Stats objects will have the same ID if they were produced
  623. // by inspecting the same underlying object.
  624. ID string `json:"id"`
  625. // TrackIdentifier represents the id property of the track.
  626. TrackIdentifier string `json:"trackIdentifier"`
  627. // RemoteSource is true if the source is remote, for instance if it is sourced
  628. // from another host via a PeerConnection. False otherwise. Only applicable for 'track' stats.
  629. RemoteSource bool `json:"remoteSource"`
  630. // Ended reflects the "ended" state of the track.
  631. Ended bool `json:"ended"`
  632. // Kind is either "audio" or "video". This reflects the "kind" attribute of the MediaStreamTrack.
  633. Kind string `json:"kind"`
  634. // AudioLevel represents the output audio level of the track.
  635. //
  636. // The value is a value between 0..1 (linear), where 1.0 represents 0 dBov,
  637. // 0 represents silence, and 0.5 represents approximately 6 dBSPL change in
  638. // the sound pressure level from 0 dBov.
  639. //
  640. // If the track is sourced from an Receiver, does no audio processing, has a
  641. // constant level, and has a volume setting of 1.0, the audio level is expected
  642. // to be the same as the audio level of the source SSRC, while if the volume setting
  643. // is 0.5, the AudioLevel is expected to be half that value.
  644. //
  645. // For outgoing audio tracks, the AudioLevel is the level of the audio being sent.
  646. AudioLevel float64 `json:"audioLevel"`
  647. // TotalAudioEnergy is the total energy of all the audio samples sent/received
  648. // for this object, calculated by duration * Math.pow(energy/maxEnergy, 2) for
  649. // each audio sample seen.
  650. TotalAudioEnergy float64 `json:"totalAudioEnergy"`
  651. // VoiceActivityFlag represents whether the last RTP packet sent or played out
  652. // by this track contained voice activity or not based on the presence of the
  653. // V bit in the extension header, as defined in [RFC6464].
  654. //
  655. // This value indicates the voice activity in the latest RTP packet played out
  656. // from a given SSRC, and is defined in RTPSynchronizationSource.voiceActivityFlag.
  657. VoiceActivityFlag bool `json:"voiceActivityFlag"`
  658. // TotalSamplesDuration represents the total duration in seconds of all samples
  659. // that have sent or received (and thus counted by TotalSamplesSent or TotalSamplesReceived).
  660. // Can be used with TotalAudioEnergy to compute an average audio level over different intervals.
  661. TotalSamplesDuration float64 `json:"totalSamplesDuration"`
  662. // EchoReturnLoss is only present while the sender is sending a track sourced from
  663. // a microphone where echo cancellation is applied. Calculated in decibels.
  664. EchoReturnLoss float64 `json:"echoReturnLoss"`
  665. // EchoReturnLossEnhancement is only present while the sender is sending a track
  666. // sourced from a microphone where echo cancellation is applied. Calculated in decibels.
  667. EchoReturnLossEnhancement float64 `json:"echoReturnLossEnhancement"`
  668. // TotalSamplesSent is the total number of samples that have been sent by this sender.
  669. TotalSamplesSent uint64 `json:"totalSamplesSent"`
  670. }
  671. // SenderAudioTrackAttachmentStats object represents the stats about one attachment
  672. // of an audio MediaStreamTrack to the PeerConnection object for which one calls GetStats.
  673. //
  674. // It appears in the stats as soon as it is attached (via AddTrack, via AddTransceiver,
  675. // via ReplaceTrack on an RTPSender object).
  676. //
  677. // If an audio track is attached twice (via AddTransceiver or ReplaceTrack), there
  678. // will be two SenderAudioTrackAttachmentStats objects, one for each attachment.
  679. // They will have the same "TrackIdentifier" attribute, but different "ID" attributes.
  680. //
  681. // If the track is detached from the PeerConnection (via removeTrack or via replaceTrack),
  682. // it continues to appear, but with the "ObjectDeleted" member set to true.
  683. type SenderAudioTrackAttachmentStats AudioSenderStats
  684. // VideoSenderStats represents the stats about one video sender of a PeerConnection
  685. // object for which one calls GetStats.
  686. //
  687. // It appears in the stats as soon as the sender is added by either AddTrack or
  688. // AddTransceiver, or by media negotiation.
  689. type VideoSenderStats struct {
  690. // Timestamp is the timestamp associated with this object.
  691. Timestamp StatsTimestamp `json:"timestamp"`
  692. // Type is the object's StatsType
  693. Type StatsType `json:"type"`
  694. // ID is a unique id that is associated with the component inspected to produce
  695. // this Stats object. Two Stats objects will have the same ID if they were produced
  696. // by inspecting the same underlying object.
  697. ID string `json:"id"`
  698. // FramesCaptured represents the total number of frames captured, before encoding,
  699. // for this RTPSender (or for this MediaStreamTrack, if type is "track"). For example,
  700. // if type is "sender" and this sender's track represents a camera, then this is the
  701. // number of frames produced by the camera for this track while being sent by this sender,
  702. // combined with the number of frames produced by all tracks previously attached to this
  703. // sender while being sent by this sender. Framerates can vary due to hardware limitations
  704. // or environmental factors such as lighting conditions.
  705. FramesCaptured uint32 `json:"framesCaptured"`
  706. // FramesSent represents the total number of frames sent by this RTPSender
  707. // (or for this MediaStreamTrack, if type is "track").
  708. FramesSent uint32 `json:"framesSent"`
  709. // HugeFramesSent represents the total number of huge frames sent by this RTPSender
  710. // (or for this MediaStreamTrack, if type is "track"). Huge frames, by definition,
  711. // are frames that have an encoded size at least 2.5 times the average size of the frames.
  712. // The average size of the frames is defined as the target bitrate per second divided
  713. // by the target fps at the time the frame was encoded. These are usually complex
  714. // to encode frames with a lot of changes in the picture. This can be used to estimate,
  715. // e.g slide changes in the streamed presentation. If a huge frame is also a key frame,
  716. // then both counters HugeFramesSent and KeyFramesSent are incremented.
  717. HugeFramesSent uint32 `json:"hugeFramesSent"`
  718. // KeyFramesSent represents the total number of key frames sent by this RTPSender
  719. // (or for this MediaStreamTrack, if type is "track"), such as Infra-frames in
  720. // VP8 [RFC6386] or I-frames in H.264 [RFC6184]. This is a subset of FramesSent.
  721. // FramesSent - KeyFramesSent gives you the number of delta frames sent.
  722. KeyFramesSent uint32 `json:"keyFramesSent"`
  723. }
  724. // SenderVideoTrackAttachmentStats represents the stats about one attachment of a
  725. // video MediaStreamTrack to the PeerConnection object for which one calls GetStats.
  726. //
  727. // It appears in the stats as soon as it is attached (via AddTrack, via AddTransceiver,
  728. // via ReplaceTrack on an RTPSender object).
  729. //
  730. // If a video track is attached twice (via AddTransceiver or ReplaceTrack), there
  731. // will be two SenderVideoTrackAttachmentStats objects, one for each attachment.
  732. // They will have the same "TrackIdentifier" attribute, but different "ID" attributes.
  733. //
  734. // If the track is detached from the PeerConnection (via RemoveTrack or via ReplaceTrack),
  735. // it continues to appear, but with the "ObjectDeleted" member set to true.
  736. type SenderVideoTrackAttachmentStats VideoSenderStats
  737. // AudioReceiverStats contains audio metrics related to a specific receiver.
  738. type AudioReceiverStats struct {
  739. // Timestamp is the timestamp associated with this object.
  740. Timestamp StatsTimestamp `json:"timestamp"`
  741. // Type is the object's StatsType
  742. Type StatsType `json:"type"`
  743. // ID is a unique id that is associated with the component inspected to produce
  744. // this Stats object. Two Stats objects will have the same ID if they were produced
  745. // by inspecting the same underlying object.
  746. ID string `json:"id"`
  747. // AudioLevel represents the output audio level of the track.
  748. //
  749. // The value is a value between 0..1 (linear), where 1.0 represents 0 dBov,
  750. // 0 represents silence, and 0.5 represents approximately 6 dBSPL change in
  751. // the sound pressure level from 0 dBov.
  752. //
  753. // If the track is sourced from an Receiver, does no audio processing, has a
  754. // constant level, and has a volume setting of 1.0, the audio level is expected
  755. // to be the same as the audio level of the source SSRC, while if the volume setting
  756. // is 0.5, the AudioLevel is expected to be half that value.
  757. //
  758. // For outgoing audio tracks, the AudioLevel is the level of the audio being sent.
  759. AudioLevel float64 `json:"audioLevel"`
  760. // TotalAudioEnergy is the total energy of all the audio samples sent/received
  761. // for this object, calculated by duration * Math.pow(energy/maxEnergy, 2) for
  762. // each audio sample seen.
  763. TotalAudioEnergy float64 `json:"totalAudioEnergy"`
  764. // VoiceActivityFlag represents whether the last RTP packet sent or played out
  765. // by this track contained voice activity or not based on the presence of the
  766. // V bit in the extension header, as defined in [RFC6464].
  767. //
  768. // This value indicates the voice activity in the latest RTP packet played out
  769. // from a given SSRC, and is defined in RTPSynchronizationSource.voiceActivityFlag.
  770. VoiceActivityFlag bool `json:"voiceActivityFlag"`
  771. // TotalSamplesDuration represents the total duration in seconds of all samples
  772. // that have sent or received (and thus counted by TotalSamplesSent or TotalSamplesReceived).
  773. // Can be used with TotalAudioEnergy to compute an average audio level over different intervals.
  774. TotalSamplesDuration float64 `json:"totalSamplesDuration"`
  775. // EstimatedPlayoutTimestamp is the estimated playout time of this receiver's
  776. // track. The playout time is the NTP timestamp of the last playable sample that
  777. // has a known timestamp (from an RTCP SR packet mapping RTP timestamps to NTP
  778. // timestamps), extrapolated with the time elapsed since it was ready to be played out.
  779. // This is the "current time" of the track in NTP clock time of the sender and
  780. // can be present even if there is no audio currently playing.
  781. //
  782. // This can be useful for estimating how much audio and video is out of
  783. // sync for two tracks from the same source:
  784. // AudioTrackStats.EstimatedPlayoutTimestamp - VideoTrackStats.EstimatedPlayoutTimestamp
  785. EstimatedPlayoutTimestamp StatsTimestamp `json:"estimatedPlayoutTimestamp"`
  786. // JitterBufferDelay is the sum of the time, in seconds, each sample takes from
  787. // the time it is received and to the time it exits the jitter buffer.
  788. // This increases upon samples exiting, having completed their time in the buffer
  789. // (incrementing JitterBufferEmittedCount). The average jitter buffer delay can
  790. // be calculated by dividing the JitterBufferDelay with the JitterBufferEmittedCount.
  791. JitterBufferDelay float64 `json:"jitterBufferDelay"`
  792. // JitterBufferEmittedCount is the total number of samples that have come out
  793. // of the jitter buffer (increasing JitterBufferDelay).
  794. JitterBufferEmittedCount uint64 `json:"jitterBufferEmittedCount"`
  795. // TotalSamplesReceived is the total number of samples that have been received
  796. // by this receiver. This includes ConcealedSamples.
  797. TotalSamplesReceived uint64 `json:"totalSamplesReceived"`
  798. // ConcealedSamples is the total number of samples that are concealed samples.
  799. // A concealed sample is a sample that is based on data that was synthesized
  800. // to conceal packet loss and does not represent incoming data.
  801. ConcealedSamples uint64 `json:"concealedSamples"`
  802. // ConcealmentEvents is the number of concealment events. This counter increases
  803. // every time a concealed sample is synthesized after a non-concealed sample.
  804. // That is, multiple consecutive concealed samples will increase the concealedSamples
  805. // count multiple times but is a single concealment event.
  806. ConcealmentEvents uint64 `json:"concealmentEvents"`
  807. }
  808. // VideoReceiverStats contains video metrics related to a specific receiver.
  809. type VideoReceiverStats struct {
  810. // Timestamp is the timestamp associated with this object.
  811. Timestamp StatsTimestamp `json:"timestamp"`
  812. // Type is the object's StatsType
  813. Type StatsType `json:"type"`
  814. // ID is a unique id that is associated with the component inspected to produce
  815. // this Stats object. Two Stats objects will have the same ID if they were produced
  816. // by inspecting the same underlying object.
  817. ID string `json:"id"`
  818. // FrameWidth represents the width of the last processed frame for this track.
  819. // Before the first frame is processed this attribute is missing.
  820. FrameWidth uint32 `json:"frameWidth"`
  821. // FrameHeight represents the height of the last processed frame for this track.
  822. // Before the first frame is processed this attribute is missing.
  823. FrameHeight uint32 `json:"frameHeight"`
  824. // FramesPerSecond represents the nominal FPS value before the degradation preference
  825. // is applied. It is the number of complete frames in the last second. For sending
  826. // tracks it is the current captured FPS and for the receiving tracks it is the
  827. // current decoding framerate.
  828. FramesPerSecond float64 `json:"framesPerSecond"`
  829. // EstimatedPlayoutTimestamp is the estimated playout time of this receiver's
  830. // track. The playout time is the NTP timestamp of the last playable sample that
  831. // has a known timestamp (from an RTCP SR packet mapping RTP timestamps to NTP
  832. // timestamps), extrapolated with the time elapsed since it was ready to be played out.
  833. // This is the "current time" of the track in NTP clock time of the sender and
  834. // can be present even if there is no audio currently playing.
  835. //
  836. // This can be useful for estimating how much audio and video is out of
  837. // sync for two tracks from the same source:
  838. // AudioTrackStats.EstimatedPlayoutTimestamp - VideoTrackStats.EstimatedPlayoutTimestamp
  839. EstimatedPlayoutTimestamp StatsTimestamp `json:"estimatedPlayoutTimestamp"`
  840. // JitterBufferDelay is the sum of the time, in seconds, each sample takes from
  841. // the time it is received and to the time it exits the jitter buffer.
  842. // This increases upon samples exiting, having completed their time in the buffer
  843. // (incrementing JitterBufferEmittedCount). The average jitter buffer delay can
  844. // be calculated by dividing the JitterBufferDelay with the JitterBufferEmittedCount.
  845. JitterBufferDelay float64 `json:"jitterBufferDelay"`
  846. // JitterBufferEmittedCount is the total number of samples that have come out
  847. // of the jitter buffer (increasing JitterBufferDelay).
  848. JitterBufferEmittedCount uint64 `json:"jitterBufferEmittedCount"`
  849. // FramesReceived Represents the total number of complete frames received for
  850. // this receiver. This metric is incremented when the complete frame is received.
  851. FramesReceived uint32 `json:"framesReceived"`
  852. // KeyFramesReceived represents the total number of complete key frames received
  853. // for this MediaStreamTrack, such as Infra-frames in VP8 [RFC6386] or I-frames
  854. // in H.264 [RFC6184]. This is a subset of framesReceived. `framesReceived - keyFramesReceived`
  855. // gives you the number of delta frames received. This metric is incremented when
  856. // the complete key frame is received. It is not incremented if a partial key
  857. // frames is received and sent for decoding, i.e., the frame could not be recovered
  858. // via retransmission or FEC.
  859. KeyFramesReceived uint32 `json:"keyFramesReceived"`
  860. // FramesDecoded represents the total number of frames correctly decoded for this
  861. // SSRC, i.e., frames that would be displayed if no frames are dropped.
  862. FramesDecoded uint32 `json:"framesDecoded"`
  863. // FramesDropped is the total number of frames dropped predecode or dropped
  864. // because the frame missed its display deadline for this receiver's track.
  865. FramesDropped uint32 `json:"framesDropped"`
  866. // The cumulative number of partial frames lost. This metric is incremented when
  867. // the frame is sent to the decoder. If the partial frame is received and recovered
  868. // via retransmission or FEC before decoding, the FramesReceived counter is incremented.
  869. PartialFramesLost uint32 `json:"partialFramesLost"`
  870. // FullFramesLost is the cumulative number of full frames lost.
  871. FullFramesLost uint32 `json:"fullFramesLost"`
  872. }
  873. // TransportStats contains transport statistics related to the PeerConnection object.
  874. type TransportStats struct {
  875. // Timestamp is the timestamp associated with this object.
  876. Timestamp StatsTimestamp `json:"timestamp"`
  877. // Type is the object's StatsType
  878. Type StatsType `json:"type"`
  879. // ID is a unique id that is associated with the component inspected to produce
  880. // this Stats object. Two Stats objects will have the same ID if they were produced
  881. // by inspecting the same underlying object.
  882. ID string `json:"id"`
  883. // PacketsSent represents the total number of packets sent over this transport.
  884. PacketsSent uint32 `json:"packetsSent"`
  885. // PacketsReceived represents the total number of packets received on this transport.
  886. PacketsReceived uint32 `json:"packetsReceived"`
  887. // BytesSent represents the total number of payload bytes sent on this PeerConnection
  888. // not including headers or padding.
  889. BytesSent uint64 `json:"bytesSent"`
  890. // BytesReceived represents the total number of bytes received on this PeerConnection
  891. // not including headers or padding.
  892. BytesReceived uint64 `json:"bytesReceived"`
  893. // RTCPTransportStatsID is the ID of the transport that gives stats for the RTCP
  894. // component If RTP and RTCP are not multiplexed and this record has only
  895. // the RTP component stats.
  896. RTCPTransportStatsID string `json:"rtcpTransportStatsId"`
  897. // ICERole is set to the current value of the "role" attribute of the underlying
  898. // DTLSTransport's "transport".
  899. ICERole ICERole `json:"iceRole"`
  900. // DTLSState is set to the current value of the "state" attribute of the underlying DTLSTransport.
  901. DTLSState DTLSTransportState `json:"dtlsState"`
  902. // SelectedCandidatePairID is a unique identifier that is associated to the object
  903. // that was inspected to produce the ICECandidatePairStats associated with this transport.
  904. SelectedCandidatePairID string `json:"selectedCandidatePairId"`
  905. // LocalCertificateID is the ID of the CertificateStats for the local certificate.
  906. // Present only if DTLS is negotiated.
  907. LocalCertificateID string `json:"localCertificateId"`
  908. // LocalCertificateID is the ID of the CertificateStats for the remote certificate.
  909. // Present only if DTLS is negotiated.
  910. RemoteCertificateID string `json:"remoteCertificateId"`
  911. // DTLSCipher is the descriptive name of the cipher suite used for the DTLS transport,
  912. // as defined in the "Description" column of the IANA cipher suite registry.
  913. DTLSCipher string `json:"dtlsCipher"`
  914. // SRTPCipher is the descriptive name of the protection profile used for the SRTP
  915. // transport, as defined in the "Profile" column of the IANA DTLS-SRTP protection
  916. // profile registry.
  917. SRTPCipher string `json:"srtpCipher"`
  918. }
  919. // StatsICECandidatePairState is the state of an ICE candidate pair used in the
  920. // ICECandidatePairStats object.
  921. type StatsICECandidatePairState string
  922. func toStatsICECandidatePairState(state ice.CandidatePairState) (StatsICECandidatePairState, error) {
  923. switch state {
  924. case ice.CandidatePairStateWaiting:
  925. return StatsICECandidatePairStateWaiting, nil
  926. case ice.CandidatePairStateInProgress:
  927. return StatsICECandidatePairStateInProgress, nil
  928. case ice.CandidatePairStateFailed:
  929. return StatsICECandidatePairStateFailed, nil
  930. case ice.CandidatePairStateSucceeded:
  931. return StatsICECandidatePairStateSucceeded, nil
  932. default:
  933. // NOTE: this should never happen[tm]
  934. err := fmt.Errorf("%w: %s", errStatsICECandidateStateInvalid, state.String())
  935. return StatsICECandidatePairState("Unknown"), err
  936. }
  937. }
  938. const (
  939. // StatsICECandidatePairStateFrozen means a check for this pair hasn't been
  940. // performed, and it can't yet be performed until some other check succeeds,
  941. // allowing this pair to unfreeze and move into the Waiting state.
  942. StatsICECandidatePairStateFrozen StatsICECandidatePairState = "frozen"
  943. // StatsICECandidatePairStateWaiting means a check has not been performed for
  944. // this pair, and can be performed as soon as it is the highest-priority Waiting
  945. // pair on the check list.
  946. StatsICECandidatePairStateWaiting StatsICECandidatePairState = "waiting"
  947. // StatsICECandidatePairStateInProgress means a check has been sent for this pair,
  948. // but the transaction is in progress.
  949. StatsICECandidatePairStateInProgress StatsICECandidatePairState = "in-progress"
  950. // StatsICECandidatePairStateFailed means a check for this pair was already done
  951. // and failed, either never producing any response or producing an unrecoverable
  952. // failure response.
  953. StatsICECandidatePairStateFailed StatsICECandidatePairState = "failed"
  954. // StatsICECandidatePairStateSucceeded means a check for this pair was already
  955. // done and produced a successful result.
  956. StatsICECandidatePairStateSucceeded StatsICECandidatePairState = "succeeded"
  957. )
  958. // ICECandidatePairStats contains ICE candidate pair statistics related
  959. // to the ICETransport objects.
  960. type ICECandidatePairStats struct {
  961. // Timestamp is the timestamp associated with this object.
  962. Timestamp StatsTimestamp `json:"timestamp"`
  963. // Type is the object's StatsType
  964. Type StatsType `json:"type"`
  965. // ID is a unique id that is associated with the component inspected to produce
  966. // this Stats object. Two Stats objects will have the same ID if they were produced
  967. // by inspecting the same underlying object.
  968. ID string `json:"id"`
  969. // TransportID is a unique identifier that is associated to the object that
  970. // was inspected to produce the TransportStats associated with this candidate pair.
  971. TransportID string `json:"transportId"`
  972. // LocalCandidateID is a unique identifier that is associated to the object
  973. // that was inspected to produce the ICECandidateStats for the local candidate
  974. // associated with this candidate pair.
  975. LocalCandidateID string `json:"localCandidateId"`
  976. // RemoteCandidateID is a unique identifier that is associated to the object
  977. // that was inspected to produce the ICECandidateStats for the remote candidate
  978. // associated with this candidate pair.
  979. RemoteCandidateID string `json:"remoteCandidateId"`
  980. // State represents the state of the checklist for the local and remote
  981. // candidates in a pair.
  982. State StatsICECandidatePairState `json:"state"`
  983. // Nominated is true when this valid pair that should be used for media
  984. // if it is the highest-priority one amongst those whose nominated flag is set
  985. Nominated bool `json:"nominated"`
  986. // PacketsSent represents the total number of packets sent on this candidate pair.
  987. PacketsSent uint32 `json:"packetsSent"`
  988. // PacketsReceived represents the total number of packets received on this candidate pair.
  989. PacketsReceived uint32 `json:"packetsReceived"`
  990. // BytesSent represents the total number of payload bytes sent on this candidate pair
  991. // not including headers or padding.
  992. BytesSent uint64 `json:"bytesSent"`
  993. // BytesReceived represents the total number of payload bytes received on this candidate pair
  994. // not including headers or padding.
  995. BytesReceived uint64 `json:"bytesReceived"`
  996. // LastPacketSentTimestamp represents the timestamp at which the last packet was
  997. // sent on this particular candidate pair, excluding STUN packets.
  998. LastPacketSentTimestamp StatsTimestamp `json:"lastPacketSentTimestamp"`
  999. // LastPacketReceivedTimestamp represents the timestamp at which the last packet
  1000. // was received on this particular candidate pair, excluding STUN packets.
  1001. LastPacketReceivedTimestamp StatsTimestamp `json:"lastPacketReceivedTimestamp"`
  1002. // FirstRequestTimestamp represents the timestamp at which the first STUN request
  1003. // was sent on this particular candidate pair.
  1004. FirstRequestTimestamp StatsTimestamp `json:"firstRequestTimestamp"`
  1005. // LastRequestTimestamp represents the timestamp at which the last STUN request
  1006. // was sent on this particular candidate pair. The average interval between two
  1007. // consecutive connectivity checks sent can be calculated with
  1008. // (LastRequestTimestamp - FirstRequestTimestamp) / RequestsSent.
  1009. LastRequestTimestamp StatsTimestamp `json:"lastRequestTimestamp"`
  1010. // LastResponseTimestamp represents the timestamp at which the last STUN response
  1011. // was received on this particular candidate pair.
  1012. LastResponseTimestamp StatsTimestamp `json:"lastResponseTimestamp"`
  1013. // TotalRoundTripTime represents the sum of all round trip time measurements
  1014. // in seconds since the beginning of the session, based on STUN connectivity
  1015. // check responses (ResponsesReceived), including those that reply to requests
  1016. // that are sent in order to verify consent. The average round trip time can
  1017. // be computed from TotalRoundTripTime by dividing it by ResponsesReceived.
  1018. TotalRoundTripTime float64 `json:"totalRoundTripTime"`
  1019. // CurrentRoundTripTime represents the latest round trip time measured in seconds,
  1020. // computed from both STUN connectivity checks, including those that are sent
  1021. // for consent verification.
  1022. CurrentRoundTripTime float64 `json:"currentRoundTripTime"`
  1023. // AvailableOutgoingBitrate is calculated by the underlying congestion control
  1024. // by combining the available bitrate for all the outgoing RTP streams using
  1025. // this candidate pair. The bitrate measurement does not count the size of the
  1026. // IP or other transport layers like TCP or UDP. It is similar to the TIAS defined
  1027. // in RFC 3890, i.e., it is measured in bits per second and the bitrate is calculated
  1028. // over a 1 second window.
  1029. AvailableOutgoingBitrate float64 `json:"availableOutgoingBitrate"`
  1030. // AvailableIncomingBitrate is calculated by the underlying congestion control
  1031. // by combining the available bitrate for all the incoming RTP streams using
  1032. // this candidate pair. The bitrate measurement does not count the size of the
  1033. // IP or other transport layers like TCP or UDP. It is similar to the TIAS defined
  1034. // in RFC 3890, i.e., it is measured in bits per second and the bitrate is
  1035. // calculated over a 1 second window.
  1036. AvailableIncomingBitrate float64 `json:"availableIncomingBitrate"`
  1037. // CircuitBreakerTriggerCount represents the number of times the circuit breaker
  1038. // is triggered for this particular 5-tuple, ceasing transmission.
  1039. CircuitBreakerTriggerCount uint32 `json:"circuitBreakerTriggerCount"`
  1040. // RequestsReceived represents the total number of connectivity check requests
  1041. // received (including retransmissions). It is impossible for the receiver to
  1042. // tell whether the request was sent in order to check connectivity or check
  1043. // consent, so all connectivity checks requests are counted here.
  1044. RequestsReceived uint64 `json:"requestsReceived"`
  1045. // RequestsSent represents the total number of connectivity check requests
  1046. // sent (not including retransmissions).
  1047. RequestsSent uint64 `json:"requestsSent"`
  1048. // ResponsesReceived represents the total number of connectivity check responses received.
  1049. ResponsesReceived uint64 `json:"responsesReceived"`
  1050. // ResponsesSent represents the total number of connectivity check responses sent.
  1051. // Since we cannot distinguish connectivity check requests and consent requests,
  1052. // all responses are counted.
  1053. ResponsesSent uint64 `json:"responsesSent"`
  1054. // RetransmissionsReceived represents the total number of connectivity check
  1055. // request retransmissions received.
  1056. RetransmissionsReceived uint64 `json:"retransmissionsReceived"`
  1057. // RetransmissionsSent represents the total number of connectivity check
  1058. // request retransmissions sent.
  1059. RetransmissionsSent uint64 `json:"retransmissionsSent"`
  1060. // ConsentRequestsSent represents the total number of consent requests sent.
  1061. ConsentRequestsSent uint64 `json:"consentRequestsSent"`
  1062. // ConsentExpiredTimestamp represents the timestamp at which the latest valid
  1063. // STUN binding response expired.
  1064. ConsentExpiredTimestamp StatsTimestamp `json:"consentExpiredTimestamp"`
  1065. }
  1066. // ICECandidateStats contains ICE candidate statistics related to the ICETransport objects.
  1067. type ICECandidateStats struct {
  1068. // Timestamp is the timestamp associated with this object.
  1069. Timestamp StatsTimestamp `json:"timestamp"`
  1070. // Type is the object's StatsType
  1071. Type StatsType `json:"type"`
  1072. // ID is a unique id that is associated with the component inspected to produce
  1073. // this Stats object. Two Stats objects will have the same ID if they were produced
  1074. // by inspecting the same underlying object.
  1075. ID string `json:"id"`
  1076. // TransportID is a unique identifier that is associated to the object that
  1077. // was inspected to produce the TransportStats associated with this candidate.
  1078. TransportID string `json:"transportId"`
  1079. // NetworkType represents the type of network interface used by the base of a
  1080. // local candidate (the address the ICE agent sends from). Only present for
  1081. // local candidates; it's not possible to know what type of network interface
  1082. // a remote candidate is using.
  1083. //
  1084. // Note:
  1085. // This stat only tells you about the network interface used by the first "hop";
  1086. // it's possible that a connection will be bottlenecked by another type of network.
  1087. // For example, when using Wi-Fi tethering, the networkType of the relevant candidate
  1088. // would be "wifi", even when the next hop is over a cellular connection.
  1089. NetworkType NetworkType `json:"networkType"`
  1090. // IP is the IP address of the candidate, allowing for IPv4 addresses and
  1091. // IPv6 addresses, but fully qualified domain names (FQDNs) are not allowed.
  1092. IP string `json:"ip"`
  1093. // Port is the port number of the candidate.
  1094. Port int32 `json:"port"`
  1095. // Protocol is one of udp and tcp.
  1096. Protocol string `json:"protocol"`
  1097. // CandidateType is the "Type" field of the ICECandidate.
  1098. CandidateType ICECandidateType `json:"candidateType"`
  1099. // Priority is the "Priority" field of the ICECandidate.
  1100. Priority int32 `json:"priority"`
  1101. // URL is the URL of the TURN or STUN server indicated in the that translated
  1102. // this IP address. It is the URL address surfaced in an PeerConnectionICEEvent.
  1103. URL string `json:"url"`
  1104. // RelayProtocol is the protocol used by the endpoint to communicate with the
  1105. // TURN server. This is only present for local candidates. Valid values for
  1106. // the TURN URL protocol is one of udp, tcp, or tls.
  1107. RelayProtocol string `json:"relayProtocol"`
  1108. // Deleted is true if the candidate has been deleted/freed. For host candidates,
  1109. // this means that any network resources (typically a socket) associated with the
  1110. // candidate have been released. For TURN candidates, this means the TURN allocation
  1111. // is no longer active.
  1112. //
  1113. // Only defined for local candidates. For remote candidates, this property is not applicable.
  1114. Deleted bool `json:"deleted"`
  1115. }
  1116. // CertificateStats contains information about a certificate used by an ICETransport.
  1117. type CertificateStats struct {
  1118. // Timestamp is the timestamp associated with this object.
  1119. Timestamp StatsTimestamp `json:"timestamp"`
  1120. // Type is the object's StatsType
  1121. Type StatsType `json:"type"`
  1122. // ID is a unique id that is associated with the component inspected to produce
  1123. // this Stats object. Two Stats objects will have the same ID if they were produced
  1124. // by inspecting the same underlying object.
  1125. ID string `json:"id"`
  1126. // Fingerprint is the fingerprint of the certificate.
  1127. Fingerprint string `json:"fingerprint"`
  1128. // FingerprintAlgorithm is the hash function used to compute the certificate fingerprint. For instance, "sha-256".
  1129. FingerprintAlgorithm string `json:"fingerprintAlgorithm"`
  1130. // Base64Certificate is the DER-encoded base-64 representation of the certificate.
  1131. Base64Certificate string `json:"base64Certificate"`
  1132. // IssuerCertificateID refers to the stats object that contains the next certificate
  1133. // in the certificate chain. If the current certificate is at the end of the chain
  1134. // (i.e. a self-signed certificate), this will not be set.
  1135. IssuerCertificateID string `json:"issuerCertificateId"`
  1136. }