def upgradeSDP(currentSession, newSDP): "Read the media description from the new SDP and update the current session by removing the current media." sdp = SDP(currentSession) if newSDP.ipaddr: c = (newSDP.nettype, newSDP.addrfamily, newSDP.ipaddr) sdp.nettype, sdp.addrfamily, sdp.ipaddr = c sdp.mediaDescriptions = newSDP.mediaDescriptions sdp._o_version = str(int(sdp._o_version) + 1) return sdp
def lookupElement(dialog): avatar = self.voicesystem.localElementByName( parseAddress(msg.headers['to'][0])[1].username) dialog.callController = avatar.buildCallController(dialog) if msg.body: sdp = SDP(msg.body) else: sdp = None d = defer.maybeDeferred(dialog.rtp.getSDP, dialog, sdp) def gotSDP(mysdp): dialog.sessionDescription = mysdp if not mysdp.hasMediaDescriptions(): st.messageReceivedFromTU(responseFromRequest(406, msg)) return st if sdp: self.maybeStartAudio(dialog, sdp) self.dialogs[dialog.getDialogID()] = dialog response = dialog.responseFromRequest(200, msg, mysdp.show()) st.messageReceivedFromTU(response) dialog.ackTimerRetry(response) d.addCallback(gotSDP) return d
def command_GET_SDP(self, cookie, othersdp=None): rtp, _ = self.currentRecordings[cookie] if othersdp: sdptxt = SDP(othersdp) else: sdptxt = None return {"sdp": rtp.getSDP(sdptxt).show()}
def acknowledgeInvite(self, dialog, response): #step 7 has just occurred if dialog.clientState == "early": #this is the first 200 we have received sdp = SDP(response.body) self.partyADialog.reinvite(None, sdp) oldtu = self.partyADialog.tu self.partyADialog.tu = UserAgentA(self, self.user, self.host, self.mediaController, self.dialogs) self.partyADialog.tu.transport = self.transport for ct in self.transport.clientTransactions.values(): if ct.tu == oldtu: ct.tu = self.partyADialog.tu break self.ackDeferred = defer.Deferred() self.partyBDialog = dialog def _sendAck(answer): dialog.sendAck(answer.show()) #step 10 dialog.sessionDescription = answer self.ackDeferred = None def _errAck(e): import pdb pdb.set_trace() log.err(e) self.ackDeferred = None self.ackDeferred.addCallback(_sendAck).addErrback(_errAck)
def getSDP(self, dialog, othersdp): if othersdp: othersdp = othersdp.show() else: othersdp = "" return GetSDP( cookie=self.cookies[dialog], othersdp=othersdp).do(self).addCallback(lambda r: SDP(r["sdp"]))
def getSDP(self, rtp, extrartp=None): from xshtoom.sdp import SDP, MediaDescription if extrartp: raise ValueError("can't handle multiple RTP streams in a call yet") s = SDP() addr = rtp.getVisibleAddress() s.setServerIP(addr[0]) md = MediaDescription() # defaults to type 'audio' s.addMediaDescription(md) md.setServerIP(addr[0]) md.setLocalPort(addr[1]) for pt, test in TryCodecs.items(): if test is not None: md.addRtpMap(pt) md.addRtpMap(PT_PCMU) md.addRtpMap(PT_CN) md.addRtpMap(PT_NTE) return s
def getSDP(self, dialog, othersdp): s = SDP() m = MediaDescription() m.port = 54321 s.addMediaDescription(m) m.addRtpMap(PT_PCMU) if othersdp: s.intersect(othersdp) return s
def acknowledgeInvite(self, dialog, response): #RFC 3261, 13.2.2.4 if dialog.sessionDescription: #the INVITE contained the offer, no body in the ACK dialog.sendAck() else: #the 200 contained the offer, answer in the ACK sdp = SDP(response.body) d = defer.maybeDeferred(dialog.rtp.getSDP, dialog, sdp) def gotSDP(mysdpobj): mysdp = mysdpobj.show() dialog.sendAck(mysdp) dialog.sessionDescription = mysdp d.addCallback(gotSDP) return d
def process_ACK(self, st, msg, addr, dialog): #woooo it is an ack for a 200, it is call setup time timer = dialog.ackTimer[0] if timer.active(): timer.cancel() if not getattr(dialog, 'reinviteMsg', None): #only do this for the initial INVITE if not dialog.acked: dialog.callController.callBegan(dialog) dialog.acked = True else: debug("reinvite ACKed") if msg.body: #must've gotten an invite with no SDP #so this is the answer sdp = SDP(msg.body) self.maybeStartAudio(dialog, sdp)
def earlyResponseReceived(self, dialog, response, ct): if 200 <= response.code < 300: #RFC 3261 12.1.2 dialog.clientState = "confirmed" dialog.remoteAddress = parseAddress(response.headers['to'][0]) dialog.routeSet = [ parseAddress(route) for route in response.headers.get('record-route', [])[::-1] ] self.dialogs[dialog.getDialogID()] = dialog sdp = SDP(response.body) self.maybeStartAudio(dialog, sdp) if self.controller: self.controller.callBegan(dialog) elif 300 <= response.code < 400: raise NotImplemented, "Dunno about redirects yet" elif 400 <= response.code < 700: if dialog.getDialogID() in self.dialogs: del self.dialogs[dialog.getDialogID()] del self.cts[ct] self.controller.callFailed(dialog, response)
def process_INVITE(self, st, msg, addr, dialog): #RFC 3261 13.3.1 if dialog: #it's a reinvite if msg.body: #new SDP ahoy sdp = SDP(msg.body) else: sdp = None d = defer.maybeDeferred(dialog.rtp.getSDP, dialog, sdp) def gotSDP(mysdp): if not mysdp.hasMediaDescriptions(): st.messageReceivedFromTU(responseFromRequest(488, msg)) return st dialog.sessionDescription = mysdp if dialog.clientState == "reinviteSent": st.messageReceivedFromTU( dialog.responseFromRequest(491, msg)) else: if sdp: self.maybeStartAudio(dialog, sdp) dialog.msg = msg dialog.reinviteMsg = True dialog.remoteAddress = parseAddress(msg.headers['from'][0]) response = dialog.responseFromRequest( 200, msg, mysdp.show()) st.messageReceivedFromTU(response) dialog.ackTimerRetry(response) return st return d.addCallback(gotSDP) #otherwise, time to start a new dialog d = Dialog.forServer( self, URL(self.host, parseAddress(msg.headers['to'][0])[1].username), msg) def lookupElement(dialog): avatar = self.voicesystem.localElementByName( parseAddress(msg.headers['to'][0])[1].username) dialog.callController = avatar.buildCallController(dialog) if msg.body: sdp = SDP(msg.body) else: sdp = None d = defer.maybeDeferred(dialog.rtp.getSDP, dialog, sdp) def gotSDP(mysdp): dialog.sessionDescription = mysdp if not mysdp.hasMediaDescriptions(): st.messageReceivedFromTU(responseFromRequest(406, msg)) return st if sdp: self.maybeStartAudio(dialog, sdp) self.dialogs[dialog.getDialogID()] = dialog response = dialog.responseFromRequest(200, msg, mysdp.show()) st.messageReceivedFromTU(response) dialog.ackTimerRetry(response) d.addCallback(gotSDP) return d def failedLookup(err): err.trap(NoSuchUser, UnauthorizedLogin) raise SIPLookupError(604) return d.addCallback(lookupElement).addErrback(failedLookup)
def acknowledgeInvite(self, dialog, response): #step 9 has just occurred sdp = SDP(response.body) if self.userAgentB.ackDeferred: self.userAgentB.ackDeferred.callback(sdp) dialog.sendAck() #step 11