stats.go 66 KB

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