Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/selkies/webrtc/stats.py: 96%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

56 statements  

1# This Source Code Form is subject to the terms of the Mozilla Public 

2# License, v. 2.0. If a copy of the MPL was not distributed with this 

3# file, You can obtain one at https://mozilla.org/MPL/2.0/. 

4# 

5# This file incorporates work covered by the following copyright and 

6# permission notice: 

7# 

8# Copyright (c) Jeremy Lainé. 

9# All rights reserved. 

10# 

11# Redistribution and use in source and binary forms, with or without 

12# modification, are permitted provided that the following conditions are met: 

13# 

14# * Redistributions of source code must retain the above copyright notice, 

15# this list of conditions and the following disclaimer. 

16# * Redistributions in binary form must reproduce the above copyright notice, 

17# this list of conditions and the following disclaimer in the documentation 

18# and/or other materials provided with the distribution. 

19# * Neither the name of aiortc nor the names of its contributors may 

20# be used to endorse or promote products derived from this software without 

21# specific prior written permission. 

22# 

23# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 

24# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 

25# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 

26# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 

27# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 

28# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 

29# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 

30# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 

31# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 

32# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 

33 

34import datetime 

35from dataclasses import dataclass 

36from typing import Optional 

37 

38 

39@dataclass 

40class RTCStats: 

41 """ 

42 Base class for statistics. 

43 """ 

44 

45 timestamp: datetime.datetime 

46 "The timestamp associated with this object." 

47 type: str 

48 id: str 

49 

50 

51@dataclass 

52class RTCRtpStreamStats(RTCStats): 

53 ssrc: int 

54 kind: str 

55 transportId: str 

56 

57 

58@dataclass 

59class RTCReceivedRtpStreamStats(RTCRtpStreamStats): 

60 packetsReceived: int 

61 packetsLost: int 

62 jitter: int 

63 

64 

65@dataclass 

66class RTCSentRtpStreamStats(RTCRtpStreamStats): 

67 packetsSent: int 

68 "Total number of RTP packets sent for this SSRC." 

69 bytesSent: int 

70 "Total number of bytes sent for this SSRC." 

71 

72 

73@dataclass 

74class RTCInboundRtpStreamStats(RTCReceivedRtpStreamStats): 

75 """ 

76 The :class:`RTCInboundRtpStreamStats` dictionary represents the measurement 

77 metrics for the incoming RTP media stream. 

78 """ 

79 

80 pass 

81 

82 

83@dataclass 

84class RTCRemoteInboundRtpStreamStats(RTCReceivedRtpStreamStats): 

85 """ 

86 The :class:`RTCRemoteInboundRtpStreamStats` dictionary represents the remote 

87 endpoint's measurement metrics for a particular incoming RTP stream. 

88 """ 

89 

90 roundTripTime: float 

91 fractionLost: float 

92 

93 

94@dataclass 

95class RTCOutboundRtpStreamStats(RTCSentRtpStreamStats): 

96 """ 

97 The :class:`RTCOutboundRtpStreamStats` dictionary represents the measurement 

98 metrics for the outgoing RTP stream. 

99 """ 

100 

101 trackId: str 

102 

103 

104@dataclass 

105class RTCRemoteOutboundRtpStreamStats(RTCSentRtpStreamStats): 

106 """ 

107 The :class:`RTCRemoteOutboundRtpStreamStats` dictionary represents the remote 

108 endpoint's measurement metrics for its outgoing RTP stream. 

109 """ 

110 

111 remoteTimestamp: Optional[datetime.datetime] = None 

112 

113 

114@dataclass 

115class RTCTransportStats(RTCStats): 

116 packetsSent: int 

117 "Total number of packets sent over this transport." 

118 packetsReceived: int 

119 "Total number of packets received over this transport." 

120 bytesSent: int 

121 "Total number of bytes sent over this transport." 

122 bytesReceived: int 

123 "Total number of bytes received over this transport." 

124 iceRole: str 

125 "The current value of :attr:`RTCIceTransport.role`." 

126 dtlsState: str 

127 "The current value of :attr:`RTCDtlsTransport.state`." 

128 

129 

130class RTCStatsReport(dict): 

131 """ 

132 Provides statistics data about WebRTC connections as returned by the 

133 :meth:`RTCPeerConnection.getStats()`, :meth:`RTCRtpReceiver.getStats()`, 

134 and :meth:`RTCRtpSender.getStats()` coroutines. 

135 

136 This object consists of a mapping of string identifiers to objects which 

137 are instances of: 

138 

139 - :class:`RTCInboundRtpStreamStats` 

140 - :class:`RTCOutboundRtpStreamStats` 

141 - :class:`RTCRemoteInboundRtpStreamStats` 

142 - :class:`RTCRemoteOutboundRtpStreamStats` 

143 - :class:`RTCTransportStats` 

144 """ 

145 

146 def add(self, stats: RTCStats) -> None: 

147 self[stats.id] = stats