Skip to content

Commit

Permalink
Hold upgrade: ignore incoming rtp data, hold now can deal with None i…
Browse files Browse the repository at this point in the history
…n self.net, hold also now sends a=sendonly or sendrecv in sdp reinvite for hold
  • Loading branch information
luke.weber@gmail.com committed Jan 26, 2012
1 parent 24c6858 commit 489a8e0
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/app/voip.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ def __init__(self, app, streams, request=None, yoursdp=None, listen_ip='0.0.0.0'
and request is a SIP message containing SDP offer if this is an incoming call.'''
if len(streams) == 0: raise ValueError('must supply at least one stream')
self.app, self.streams = app, streams
self.is_hold = False
self.mysdp = self.yoursdp = None; self.rtp, self.net, self._types = [], [], []
if not request and not yoursdp: # this is for outgoing call, build an offer SDP as mysdp.
net = [NetworkClass(app=None, src=(listen_ip, 0)) for i in xrange(len(streams))] # first create as many RTP network objects as streams.
Expand Down Expand Up @@ -664,10 +665,19 @@ def __init__(self, app, streams, request=None, yoursdp=None, listen_ip='0.0.0.0'
if _debug: print 'request does not have SDP body'

def hold(self, value): # enable/disable hold mode.
ip = map(lambda n: n.src[0] if n.src[0] != '0.0.0.0' else getlocaladdr(n.rtp)[0], self.net)
ip = []
for i in self.net:
if i is None:
ip.append(i)
elif i.src and i.src[0] != '0.0.0.0':
ip.append(i.src[0])
else:
ip.append(getlocaladdr(i.rtp[0]))
if self.mysdp['c']: self.mysdp['c'].address = ip[0] if not value else '0.0.0.0'
for m, i in zip(self.mysdp['m'], ip):
self.mysdp['a'] = ['sendrecv'] if not value else ['sendonly']
for m, i in zip(self.mysdp['m'], ip):
if m['c']: m['c'].address = i if not value else '0.0.0.0'
self.is_hold = value

def setRemote(self, sdp):
'''Update the RTP network's destination ip:port based on remote SDP. It also creates RTP Session if
Expand Down Expand Up @@ -715,7 +725,7 @@ def createTimer(self, app): # Callback to create a timer object.
return Timer(app)

def received(self, member, packet): # an RTP packet is received. Hand over to sip_data.
if self.app and hasattr(self.app, 'received') and callable(self.app.received):
if self.app and hasattr(self.app, 'received') and callable(self.app.received) and not self.is_hold:
self.app.received(media=self, fmt=self._getMyFormat(packet.pt), packet=packet)

def send(self, payload, ts, marker, fmt):
Expand Down

0 comments on commit 489a8e0

Please sign in to comment.