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

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

95 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 

34from dataclasses import dataclass, field 

35from typing import Optional, Union 

36 

37ParametersDict = dict[str, Union[int, str, None]] 

38 

39 

40@dataclass 

41class RTCRtpCodecCapability: 

42 """ 

43 The :class:`RTCRtpCodecCapability` dictionary provides information on 

44 codec capabilities. 

45 """ 

46 

47 mimeType: str 

48 "The codec MIME media type/subtype, for instance `'audio/PCMU'`." 

49 clockRate: int 

50 "The codec clock rate expressed in Hertz." 

51 channels: Optional[int] = None 

52 "The number of channels supported (e.g. two for stereo)." 

53 parameters: ParametersDict = field(default_factory=dict) 

54 "Codec-specific parameters available for signaling." 

55 

56 @property 

57 def name(self) -> str: 

58 return self.mimeType.split("/")[1] 

59 

60 

61@dataclass 

62class RTCRtpCodecParameters: 

63 """ 

64 The :class:`RTCRtpCodecParameters` dictionary provides information on 

65 codec settings. 

66 """ 

67 

68 mimeType: str 

69 "The codec MIME media type/subtype, for instance `'audio/PCMU'`." 

70 clockRate: int 

71 "The codec clock rate expressed in Hertz." 

72 channels: Optional[int] = None 

73 "The number of channels supported (e.g. two for stereo)." 

74 payloadType: Optional[int] = None 

75 "The value that goes in the RTP Payload Type Field." 

76 rtcpFeedback: list["RTCRtcpFeedback"] = field(default_factory=list) 

77 "Transport layer and codec-specific feedback messages for this codec." 

78 parameters: ParametersDict = field(default_factory=dict) 

79 "Codec-specific parameters available for signaling." 

80 

81 @property 

82 def name(self) -> str: 

83 return self.mimeType.split("/")[1] 

84 

85 def __str__(self) -> str: 

86 s = f"{self.name}/{self.clockRate}" 

87 # Multi-channel audio (stereo opus, surround multiopus) carries its channel 

88 # count in the rtpmap encoding parameters. 

89 if self.channels is not None and self.channels >= 2: 

90 s += f"/{self.channels}" 

91 return s 

92 

93 

94@dataclass 

95class RTCRtpRtxParameters: 

96 ssrc: int 

97 

98 

99@dataclass 

100class RTCRtpCodingParameters: 

101 ssrc: int 

102 payloadType: int 

103 rtx: Optional[RTCRtpRtxParameters] = None 

104 

105 

106class RTCRtpDecodingParameters(RTCRtpCodingParameters): 

107 pass 

108 

109 

110class RTCRtpEncodingParameters(RTCRtpCodingParameters): 

111 pass 

112 

113 

114@dataclass 

115class RTCRtpHeaderExtensionCapability: 

116 """ 

117 The :class:`RTCRtpHeaderExtensionCapability` dictionary provides information 

118 on a supported header extension. 

119 """ 

120 

121 uri: str 

122 "The URI of the RTP header extension." 

123 

124 

125@dataclass 

126class RTCRtpHeaderExtensionParameters: 

127 """ 

128 The :class:`RTCRtpHeaderExtensionParameters` dictionary enables a header 

129 extension to be configured for use within an :class:`RTCRtpSender` or 

130 :class:`RTCRtpReceiver`. 

131 """ 

132 

133 id: int 

134 "The value that goes in the packet." 

135 uri: str 

136 "The URI of the RTP header extension." 

137 

138 

139@dataclass 

140class RTCRtpCapabilities: 

141 """ 

142 The :class:`RTCRtpCapabilities` dictionary provides information about 

143 support codecs and header extensions. 

144 """ 

145 

146 codecs: list[RTCRtpCodecCapability] = field(default_factory=list) 

147 "A list of :class:`RTCRtpCodecCapability`." 

148 headerExtensions: list[RTCRtpHeaderExtensionCapability] = field( 

149 default_factory=list 

150 ) 

151 "A list of :class:`RTCRtpHeaderExtensionCapability`." 

152 

153 

154@dataclass 

155class RTCRtcpFeedback: 

156 """ 

157 The :class:`RTCRtcpFeedback` dictionary provides information on RTCP feedback 

158 messages. 

159 """ 

160 

161 type: str 

162 parameter: Optional[str] = None 

163 

164 

165@dataclass 

166class RTCRtcpParameters: 

167 """ 

168 The :class:`RTCRtcpParameters` dictionary provides information on RTCP settings. 

169 """ 

170 

171 cname: Optional[str] = None 

172 "The Canonical Name (CNAME) used by RTCP." 

173 mux: bool = False 

174 "Whether RTP and RTCP are multiplexed." 

175 ssrc: Optional[int] = None 

176 "The Synchronization Source identifier." 

177 

178 

179@dataclass 

180class RTCRtpParameters: 

181 """ 

182 The :class:`RTCRtpParameters` dictionary describes the configuration of 

183 an :class:`RTCRtpReceiver` or an :class:`RTCRtpSender`. 

184 """ 

185 

186 codecs: list[RTCRtpCodecParameters] = field(default_factory=list) 

187 "A list of :class:`RTCRtpCodecParameters` to send or receive." 

188 headerExtensions: list[RTCRtpHeaderExtensionParameters] = field( 

189 default_factory=list 

190 ) 

191 "A list of :class:`RTCRtpHeaderExtensionParameters`." 

192 muxId: str = "" 

193 "The muxId assigned to the RTP stream, if any, empty string if unset." 

194 rtcp: RTCRtcpParameters = field(default_factory=RTCRtcpParameters) 

195 "Parameters to configure RTCP." 

196 

197 

198@dataclass 

199class RTCRtpReceiveParameters(RTCRtpParameters): 

200 encodings: list[RTCRtpDecodingParameters] = field(default_factory=list) 

201 

202 

203@dataclass 

204class RTCRtpSendParameters(RTCRtpParameters): 

205 encodings: list[RTCRtpEncodingParameters] = field(default_factory=list)