Show
Ignore:
Timestamp:
08/19/07 21:07:49 (17 months ago)
Author:
liori
Message:

Jingle: a try with popen()ing external file for p2p connection

Files:
1 copied

Legend:

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

    r8498 r8506  
    1515import gajim 
    1616import xmpp 
    17  
    18 # ugly hack 
    19 import sys, dl, gst 
     17import gobject 
     18 
     19import sys, dl, gst, gobject 
    2020sys.setdlopenflags(dl.RTLD_NOW | dl.RTLD_GLOBAL) 
    2121import farsight 
    22 sys.setdlopenflags(dl.RTLD_NOW | dl.RTLD_LOCAL) 
     22 
    2323 
    2424import meta 
     
    7575                } 
    7676 
    77                 # for making streams using farsight 
    78                 import gc 
    79                 gc.disable() 
    80                 print self.weinitiate, "#farsight_session_factory_make" 
    81                 self.p2psession = farsight.farsight_session_factory_make('rtp') 
    82                 self.p2psession.connect('error', self.on_p2psession_error) 
    83  
    8477        ''' Middle-level functions to manage contents. Handle local content 
    8578        cache and send change notifications. ''' 
     
    380373                JingleContent.__init__(self, session, node) 
    381374                self.got_codecs = False 
     375                self.codecs = [] 
    382376 
    383377                #if node is None: 
     
    418412                        if 'channels' in codec: c['channels']=codec['channels'] 
    419413                        codecs.append(c) 
     414                        self.p2pin.write('%d %d %s %d %d %d\n' % (1, farsight.MEDIA_TYPE_AUDIO, 
     415                                codec['encoding_name'], codec['id'], codec['clock_rate'], codec['channels'])) 
    420416                if len(codecs)==0: return 
    421417 
    422418                print self.session.weinitiate, "#farsight_stream_set_remote_codecs" 
    423                 self.p2pstream.set_remote_codecs(codecs) 
     419                #self.p2pstream.set_remote_codecs(codecs) 
     420                self.p2pin.write('%d %d %s %d %d %d\n' % (1, farsight.MEDIA_TYPE_AUDIO, 
     421                        'LAST', 0, 0, 0)) 
    424422                self.got_codecs=True 
    425423 
     
    445443                        if 'pwd' in candidate: cand['password']=candidate['pwd'] 
    446444 
     445                        self.p2pin.write('%d %d %s %s %d %s %s\n' % (0, int(candidate['type']), candidate['cid'], candidate['ip'], int(candidate['port']), candidate['ufrag'], candidate['pwd'])) 
    447446                        candidates.append(cand) 
    448447                print self.session.weinitiate, "#add_remote_candidate" 
    449                 self.p2pstream.add_remote_candidate(candidates) 
     448                #self.p2pstream.add_remote_candidate(candidates) 
    450449 
    451450        def toXML(self): 
     
    464463                        payload=payload) 
    465464 
     465        def new_data(self, *things): 
     466                buf = self.p2pout.readline() 
     467                print "RECV: %r"%buf 
     468                msg = buf.split(' ') 
     469                try: 
     470                        type = int(msg.pop(0)) 
     471                except: 
     472                        return True 
     473                #print msg 
     474                if type==0: 
     475                        media_type, id, ip, port, username, password = msg[:6] 
     476                        media_type=int(media_type) 
     477                        port=int(port) 
     478                        #print "Received %d %s %s %d %s %s" % (media_type, id, ip, port, username, password) 
     479                        self.send_candidate({'candidate_id': id, 'component': 1, 'ip': ip, 
     480                                'port': port, 'username': username, 'password': password, 
     481                                'proto': farsight.NETWORK_PROTOCOL_UDP, 'proto_subtype': 'RTP', 
     482                                'proto_profile': 'AVP', 'preference': 1.0, 'type': 0}) 
     483                elif type==1: 
     484                        media_type, encoding_name, pt, clock_rate, channels=msg[:5] 
     485                        media_type=int(media_type) 
     486                        pt=int(pt) 
     487                        clock_rate=int(clock_rate) 
     488                        channels=int(channels) 
     489 
     490                        #print "Received %d %s %d %d %d" % (media_type, encoding_name, pt, clock_rate, channels) 
     491                        if encoding_name!='LAST': 
     492                                self.codecs.append((media_type, encoding_name, pt, clock_rate, channels)) 
     493                        else: 
     494                                self.got_codecs=True 
     495                return True 
     496 
    466497        def setupStream(self): 
     498                import popen2 
     499                self.p2pout, self.p2pin = popen2.popen2('/home/liori/Projekty/SoC/trunk/src/common/jingle-handler.py') 
     500                gobject.io_add_watch(self.p2pout, gobject.IO_IN, self.new_data) 
     501                while not self.got_codecs: 
     502                        self.new_data() 
     503                return 
    467504                print self.session.weinitiate, "#farsight_session_create_stream" 
    468505                self.p2pstream = self.session.p2psession.create_stream( 
     
    548585 
    549586        def iterCodecs(self): 
    550                 print self.session.weinitiate, "#farsight_stream_get_local_codecs" 
    551                 codecs=self.p2pstream.get_local_codecs() 
    552                 for codec in codecs: 
    553                         a = {'name': codec['encoding_name'], 
    554                              'id': codec['id'], 
    555                              'channels': 1} 
    556                         if 'clock_rate' in codec: a['clockrate']=codec['clock_rate'] 
    557                         if 'optional_params' in codec: 
    558                                 p = (xmpp.Node('parameter', {'name': name, 'value': value}) 
    559                                      for name, value in codec['optional_params'].iteritems()) 
    560                         else:   p = () 
    561                         yield xmpp.Node('payload-type', a, p) 
     587                for codec in self.codecs: 
     588                        media_type, encoding_name, pt, clock_rate, channels=codec 
     589                        yield xmpp.Node('payload-type', { 
     590                                'name': encoding_name, 
     591                                'id': pt, 
     592                                'channels': channels, 
     593                                'clock_rate': clock_rate}) 
     594                 
     595#               print self.session.weinitiate, "#farsight_stream_get_local_codecs" 
     596#               codecs=self.p2pstream.get_local_codecs() 
     597#               for codec in codecs: 
     598#                       a = {'name': codec['encoding_name'], 
     599#                            'id': codec['id'], 
     600#                            'channels': 1} 
     601#                       if 'clock_rate' in codec: a['clockrate']=codec['clock_rate'] 
     602#                       if 'optional_params' in codec: 
     603#                               p = (xmpp.Node('parameter', {'name': name, 'value': value}) 
     604#                                    for name, value in codec['optional_params'].iteritems()) 
     605#                       else:   p = () 
     606#                       yield xmpp.Node('payload-type', a, p) 
    562607 
    563608class ConnectionJingle(object):