Show
Ignore:
Timestamp:
08/21/07 20:18:48 (17 months ago)
Author:
liori
Message:

Jingle: lots of debug prints cut

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/jingle/src/common/jingle.py

    r8524 r8532  
    2222sys.setdlopenflags(dl.RTLD_NOW | dl.RTLD_LOCAL) 
    2323 
    24 import meta 
    25  
    2624class JingleStates(object): 
    2725        ''' States in which jingle session may exist. ''' 
     
    3634class JingleSession(object): 
    3735        ''' This represents one jingle session. ''' 
    38         __metaclass__=meta.VerboseClassType 
    3936        def __init__(self, con, weinitiate, jid, sid=None): 
    4037                ''' con -- connection object, 
     
    7673 
    7774                # for making streams using farsight 
    78                 import gc 
    79                 gc.disable() 
    80                 print self.weinitiate, "#farsight_session_factory_make" 
    8175                self.p2psession = farsight.farsight_session_factory_make('rtp') 
    8276                self.p2psession.connect('error', self.on_p2psession_error) 
     
    191185                        cn.stanzaCB(stanza, content, error, action) 
    192186 
    193         def on_p2psession_error(self, *anything): 
    194                 print self.weinitiate, "Farsight session error!" 
     187        def on_p2psession_error(self, *anything): pass 
    195188 
    196189        ''' Methods that make/send proper pieces of XML. They check if the session 
     
    269262        def sessionTerminateCB(self, stanza): pass 
    270263 
    271 class Codec(object): 
    272         ''' This class keeps description of a single codec. ''' 
    273         def __init__(self, name, id=None, **params): 
    274                 ''' Create new codec description. ''' 
    275                 self.name = name 
    276                 self.id = id 
    277                 self.attrs = {'name': self.name, 'id': self.id, 'channels': 1} 
    278                 for key in ('channels', 'clockrate', 'maxptime', 'ptime'): 
    279                         if key in params: 
    280                                 self.attrs[key]=params[key] 
    281                                 del params[key] 
    282                 self.params = params 
    283  
    284         def __eq__(a, b): 
    285                 ''' Compare two codec descriptions. ''' 
    286                 # TODO: check out what should be tested... 
    287                 if a.name!=b.name: return False 
    288                 # ... 
    289                 return True 
    290  
    291         def toXML(self): 
    292                 return xmpp.Node('payload-type', 
    293                         attrs=self.attrs, 
    294                         payload=(xmpp.Node('parameter', {'name': k, 'value': v}) for k,v in self.params)) 
    295  
    296 class JingleAudioSession(object): 
    297 #       __metaclass__=meta.VerboseClassType 
    298         def __init__(self, content, fromNode): 
    299                 self.content = content 
    300  
    301                 self.initiator_codecs=[] 
    302                 self.responder_codecs=[] 
    303  
    304                 if fromNode: 
    305                         # read all codecs peer understand 
    306                         for payload in fromNode.iterTags('payload-type'): 
    307                                 attrs = fromNode.getAttrs().copy() 
    308                                 for param in fromNode.iterTags('parameter'): 
    309                                         attrs[param['name']]=param['value'] 
    310                                 self.initiator_codecs.append(Codec(**attrs)) 
    311  
    312         def sessionInitiateCB(self, stanza, ourcontent): 
    313                 pass 
    314  
    315         ''' "Negotiation" of codecs... simply presenting what *we* can do, nothing more... ''' 
    316         def getOurCodecs(self, other=None): 
    317                 ''' Get a list of codecs we support. Try to get them in the same 
    318                 order as the codecs of our peer. If other!=None, raise 
    319                 a NoCommonCodec error if no codecs both sides support (None means 
    320                 we are initiating the connection and we don't know the other 
    321                 peer's codecs.) ''' 
    322                 # for now we "understand" only one codec -- speex with clockrate 16000 
    323                 # so we have an easy job to do... (codecs sorted in order of preference) 
    324                 supported_codecs=[ 
    325                         Codec('speex', clockrate='16000'), 
    326                 ] 
    327  
    328                 if other is not None: 
    329                         other_l = other 
    330                 else: 
    331                         other_l = [] 
    332                 our_l = supported_codecs[:] 
    333                 out = [] 
    334                 ids = range(128) 
    335                 for codec in other_l: 
    336                         if codec in our_l: 
    337                                 out.append(codec) 
    338                                 our_l.remove(codec) 
    339                                 try: ids.remove(codec.id) 
    340                                 except ValueError: pass # when id is not a dynamic one 
    341  
    342                 if other is not None and len(out)==0: 
    343                         raise NoCommonCodec 
    344  
    345                 for codec in our_l: 
    346                         if not codec.id or codec.id not in ids: 
    347                                 codec.id = ids.pop() 
    348                         out.append(codec) 
    349  
    350                 return out 
    351  
    352         ''' Methods for making proper pieces of XML. ''' 
    353         def __codecsList(self, codecs): 
    354                 ''' Prepares a description element with codecs given as a parameter. ''' 
    355                 return xmpp.Node(xmpp.NS_JINGLE_AUDIO+' description', 
    356                         payload=(codec.toXML() for codec in codecs)) 
    357  
    358         def toXML(self): 
    359                 if not self.initiator_codecs: 
    360                         # we are the initiator, so just send our codecs 
    361                         self.initiator_codecs = self.getOurCodecs() 
    362                         return self.__codecsList(self.initiator_codecs) 
    363                 else: 
    364                         # we are the responder, we SHOULD adjust our codec list 
    365                         self.responder_codecs = self.getOurCodecs(self.initiator_codecs) 
    366                         return self.__codecsList(self.responder_codecs) 
    367  
    368264class JingleContent(object): 
    369265        ''' An abstraction of content in Jingle sessions. ''' 
     
    379275        ''' Jingle VoiP sessions consist of audio content transported 
    380276        over an ICE UDP protocol. ''' 
    381 #       __metaclass__=meta.VerboseClassType 
    382277        def __init__(self, session, node=None): 
    383278                JingleContent.__init__(self, session, node) 
     
    423318                if len(codecs)==0: return 
    424319 
    425                 print self.session.weinitiate, "#farsight_stream_set_remote_codecs" 
    426320                self.p2pstream.set_remote_codecs(codecs) 
    427321                self.got_codecs=True 
     
    432326                for candidate in content.getTag('transport').iterTags('candidate'): 
    433327                        cand={ 
    434                                 'candidate_id': candidate['cid'], 
     328                                'candidate_id': self.session.connection.connection.getAnID(), 
    435329                                'component':    int(candidate['component']), 
    436330                                'ip':           candidate['ip'], 
     
    452346 
    453347                        candidates.append(cand) 
    454                 print self.session.weinitiate, "#add_remote_candidate" 
    455348                self.p2pstream.add_remote_candidate(candidates) 
    456349 
     
    471364 
    472365        def setupStream(self): 
    473                 print self.session.weinitiate, "#farsight_session_create_stream" 
    474366                self.p2pstream = self.session.p2psession.create_stream( 
    475367                        farsight.MEDIA_TYPE_AUDIO, farsight.STREAM_DIRECTION_BOTH) 
     
    484376                self.p2pstream.set_remote_codecs(self.p2pstream.get_local_codecs()) 
    485377 
    486                 print self.session.weinitiate, "#farsight_stream_prepare_transports" 
    487378                self.p2pstream.prepare_transports() 
    488379 
    489                 print self.session.weinitiate, "#farsight_stream_set_active_codec" 
    490380                self.p2pstream.set_active_codec(8)      #??? 
    491381 
     
    500390                src.set_property('is-live', True) 
    501391 
    502                 print self.session.weinitiate, "#farsight_stream_set_sink" 
    503392                self.p2pstream.set_sink(sink) 
    504                 print self.session.weinitiate, "#farsight_stream_set_source" 
    505393                self.p2pstream.set_source(src) 
    506394 
    507395        def on_p2pstream_error(self, *whatever): pass 
    508         def on_p2pstream_new_active_candidate_pair(self, stream, native, remote): 
    509                 print self.session.weinitiate, "##new_active_candidate_pair" 
    510                 #print "New native candidate pair: %s, %s" % (native, remote) 
    511         def on_p2pstream_codec_changed(self, stream, codecid): 
    512                 print self.session.weinitiate, "##codec_changed" 
    513                 #print "Codec changed: %d" % codecid 
     396        def on_p2pstream_new_active_candidate_pair(self, stream, native, remote): pass 
     397        def on_p2pstream_codec_changed(self, stream, codecid): pass 
    514398        def on_p2pstream_native_candidates_prepared(self, *whatever): 
    515                 print self.session.weinitiate, "##native_candidates_prepared" 
    516                 #print "Native candidates prepared: %r" % whatever 
    517399                for candidate in self.p2pstream.get_native_candidate_list(): 
    518400                        self.send_candidate(candidate) 
    519401        def on_p2pstream_state_changed(self, stream, state, dir): 
    520                 print self.session.weinitiate, "##state_changed" 
    521                 #print "State: %d, Dir: %d" % (state, dir) 
    522402                if state==farsight.STREAM_STATE_CONNECTED: 
    523                         print self.session.weinitiate, "#farsight_stream_signal_native_candidates_prepared" 
    524403                        stream.signal_native_candidates_prepared() 
    525                         print self.session.weinitiate, "#farsight_stream_start" 
    526404                        stream.start() 
    527405        def on_p2pstream_new_native_candidate(self, p2pstream, candidate_id): 
    528                 print self.session.weinitiate, "##new_native_candidate" 
    529                 print self.session.weinitiate, "#get_native_candidate" 
    530406                candidates = p2pstream.get_native_candidate(candidate_id) 
    531                 print self.session.weinitiate, "#!", repr(candidates) 
    532407 
    533408                for candidate in candidates: 
     
    535410        def send_candidate(self, candidate): 
    536411                attrs={ 
    537                         'cid': candidate['candidate_id'], 
    538412                        'component': candidate['component'], 
    539413                        'foundation': '1', # hack 
    540414                        'generation': '0', 
    541                         'type': candidate['type'], 
    542415                        'ip': candidate['ip'], 
    543416                        'network': '0', 
     
    558431 
    559432        def iterCodecs(self): 
    560                 print self.session.weinitiate, "#farsight_stream_get_local_codecs" 
    561433                codecs=self.p2pstream.get_local_codecs() 
    562434                for codec in codecs: