全部博文(165)
分类: Android平台
2015-04-20 11:24:41
try:self.listener_rtp = reactor.listenUDP(port_rtp, StreamListenerProtocol(), interface=Config.relay_ip)self.listener_rtcp = reactor.listenUDP(port_rtcp, StreamListenerProtocol(), interface=Config.relay_ip)
self.rtp = MediaSubStream(self, self.caller.listener_rtp, self.callee.listener_rtp)self.rtcp = MediaSubStream(self, self.caller.listener_rtcp, self.callee.listener_rtcp)
self.caller = MediaSubParty(self, listener_caller)self.callee = MediaSubParty(self, listener_callee)
self.listener.protocol.cb_func = self.got_data
if (host, port) == tuple(self.remote):if self.remote.obsolete:# the received packet matches the previously used IP/port,# which has been made obsolete, so ignore itreturnelse:if self.remote.in_use:# the received packet is different than the recorded IP/port,# so we will discard itreturn# we have learnt the remote IP/portself.remote.host, self.remote.port = host, portself.remote.in_use = Truelog.debug("Got traffic information for stream: %s" % self.substream.stream)is_stun, is_binding_request = _stun_test(data)self.substream.send_data(self, data, is_stun)
if self.timer and self.timer.active():self.timer.cancel()self.timer = reactor.callLater(Config.stream_timeout, self.substream.expired, "no-traffic timeout", Config.stream_timeout)
if not self.remote.got_rtp and not is_stun:# This is the first RTP packet receivedself.remote.got_rtp = Trueif self.timer:if self.timer.active():self.timer.cancel()self.timer = Noneself.substream.check_create_conntrack()
if self.caller.remote.in_use and self.caller.remote.got_rtp and self.callee.remote.in_use and self.callee.remote.got_rtp:self.forwarding_rule = _conntrack.ForwardingRule(self.caller.remote, self.caller.local, self.callee.remote, self.callee.local, self.stream.session.mark)self.forwarding_rule.expired_func = self.conntrack_expired
def expired(self, reason, timeout_wait):self._stop_relaying()self.stream.substream_expired(self, reason, timeout_wait)