def _create_local_media(self, uri_path): transport = "TCP/TLS/MSRP" if uri_path[-1].use_tls else "TCP/MSRP" attributes = [] path = " ".join(str(uri) for uri in uri_path) attributes.append(SDPAttribute(b"path", path.encode())) if self.direction not in [None, 'sendrecv']: attributes.append(SDPAttribute(self.direction.encode(), b'')) if self.accept_types is not None: a_types = " ".join(self.accept_types) attributes.append(SDPAttribute(b"accept-types", a_types.encode())) if self.accept_wrapped_types is not None: a_w_types = " ".join(self.accept_wrapped_types) attributes.append( SDPAttribute(b"accept-wrapped-types", a_w_types.encode())) attributes.append( SDPAttribute( b"setup", self.local_role.encode() if self.local_role else None)) local_ip = uri_path[-1].host connection = SDPConnection(local_ip.encode()) return SDPMediaStream(self.media_type.encode(), uri_path[-1].port or 2855, transport.encode(), connection=connection, formats=[b"*"], attributes=attributes)
def content_to_sdpstream(content): if content.description is None: raise ValueError('Missing media description') if content.transport is None: raise ValueError('Missing media transport') media_stream = SDPMediaStream(str(content.description.media), 0, 'RTP/AVP') formats = [] attributes = [] for item in content.description.payloads: formats.append(item.id) attributes.append(SDPAttribute('rtpmap', '%d %s/%d' % (item.id, str(item.name), item.clockrate))) if item.maxptime: attributes.append(SDPAttribute('maxptime', str(item.maxptime))) if item.ptime: attributes.append(SDPAttribute('ptime', str(item.ptime))) if item.parameters: parameters_str = ';'.join(('%s=%s' % (p.name, p.value) for p in item.parameters)) attributes.append(SDPAttribute('fmtp', '%d %s' % (item.id, str(parameters_str)))) media_stream.formats = map(str, formats) media_stream.attributes = attributes # set attributes so that _codec_list is generated if content.description.encryption: if content.description.encryption.required: media_stream.transport = 'RTP/SAVP' for crypto in content.description.encryption.cryptos: crypto_str = '%s %s %s' % (crypto.tag, crypto.crypto_suite, crypto.key_params) if crypto.session_params: crypto_str += ' %s' % crypto.session_params media_stream.attributes.append(SDPAttribute('crypto', str(crypto_str))) if isinstance(content.transport, jingle.IceUdpTransport): if content.transport.ufrag: media_stream.attributes.append(SDPAttribute('ice-ufrag', str(content.transport.ufrag))) if content.transport.password: media_stream.attributes.append(SDPAttribute('ice-pwd', str(content.transport.password))) for candidate in content.transport.candidates: if not ipv4_re.match(candidate.ip): continue candidate_str = '%s %d %s %d %s %d typ %s' % (candidate.foundation, candidate.component, candidate.protocol.upper(), candidate.priority, candidate.ip, candidate.port, candidate.typ) if candidate.related_addr and candidate.related_port: candidate_str += ' raddr %s rport %d' % (candidate.related_addr, candidate.related_port) media_stream.attributes.append(SDPAttribute('candidate', str(candidate_str))) if content.transport.remote_candidate: remote_candidate = content.transport.remote_candidate remote_candidates_str = '%d %s %d' % (remote_candidate.component, remote_candidate.ip, remote_candidate.port) media_stream.attributes.append(SDPAttribute('remote-candidates', str(remote_candidates_str))) elif isinstance(content.transport, jingle.RawUdpTransport): # Nothing to do here pass else: raise ValueError # Set the proper connection information, pick the first RTP candidate and use that try: candidate = next(c for c in content.transport.candidates if c.component == 1 and ipv4_re.match(c.ip)) except StopIteration: raise ValueError media_stream.connection = SDPConnection(str(candidate.ip)) media_stream.port = candidate.port return media_stream
def _create_local_media(self, uri_path): transport = "TCP/TLS/MSRP" if uri_path[-1].use_tls else "TCP/MSRP" attributes = [ SDPAttribute("path", " ".join(str(uri) for uri in uri_path)) ] if self.direction not in [None, 'sendrecv']: attributes.append(SDPAttribute(self.direction, '')) if self.accept_types is not None: attributes.append( SDPAttribute("accept-types", " ".join(self.accept_types))) if self.accept_wrapped_types is not None: attributes.append( SDPAttribute("accept-wrapped-types", " ".join(self.accept_wrapped_types))) attributes.append(SDPAttribute("setup", self.local_role)) local_ip = uri_path[-1].host connection = SDPConnection(local_ip) return SDPMediaStream(self.media_type, uri_path[-1].port or 2855, transport, connection=connection, formats=["*"], attributes=attributes)