Changeset 5969 for pjproject


Ignore:
Timestamp:
Apr 15, 2019 10:52:16 AM (5 years ago)
Author:
nanang
Message:

Close #2189: fixed PJSUA2 thread safety issue in list of objects manipulation.

Location:
pjproject/trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/swig/java/android/app/src/main/java/org/pjsip/pjsua2/app/MyApp.java

    r5952 r5969  
    9898                        pjsua_call_media_status.PJSUA_CALL_MEDIA_REMOTE_HOLD)) 
    9999            { 
    100                 // unfortunately, on Java too, the returned Media cannot be 
    101                 // downcasted to AudioMedia  
    102                 Media m = getMedia(i); 
    103                 AudioMedia am = AudioMedia.typecastFromMedia(m); 
    104  
    105100                // connect ports 
    106101                try { 
     102                    AudioMedia am = getAudioMedia(i); 
    107103                    MyApp.ep.audDevManager().getCaptureDevMedia(). 
    108104                                                            startTransmit(am); 
     
    110106                                     getPlaybackDevMedia()); 
    111107                } catch (Exception e) { 
     108                    System.out.println("Failed connecting media ports" + 
     109                                       e.getMessage()); 
    112110                    continue; 
    113111                } 
  • pjproject/trunk/pjsip-apps/src/swig/pjsua2.i

    r5775 r5969  
    106106%template(SipMultipartPartVector)       std::vector<pj::SipMultipartPart>; 
    107107%template(BuddyVector)                  std::vector<pj::Buddy*>; 
     108%template(BuddyVector2)                 std::vector<pj::Buddy>; 
    108109%template(AudioMediaVector)             std::vector<pj::AudioMedia*>; 
     110%template(AudioMediaVector2)            std::vector<pj::AudioMedia>; 
    109111%template(ToneDescVector)               std::vector<pj::ToneDesc>; 
    110112%template(ToneDigitVector)              std::vector<pj::ToneDigit>; 
    111113%template(ToneDigitMapVector)           std::vector<pj::ToneDigitMapDigit>; 
    112 %template(MediaFormatVector)            std::vector<pj::MediaFormat*>; 
    113114%template(AudioDevInfoVector)           std::vector<pj::AudioDevInfo*>; 
     115%template(AudioDevInfoVector2)          std::vector<pj::AudioDevInfo>; 
    114116%template(CodecInfoVector)              std::vector<pj::CodecInfo*>; 
     117%template(CodecInfoVector2)             std::vector<pj::CodecInfo>; 
    115118%template(VideoDevInfoVector)           std::vector<pj::VideoDevInfo*>; 
     119%template(VideoDevInfoVector2)          std::vector<pj::VideoDevInfo>; 
    116120%template(CodecFmtpVector)              std::vector<pj::CodecFmtp>;      
     121%template(MediaFormatAudioVector)       std::vector<pj::MediaFormatAudio>; 
     122%template(MediaFormatVideoVector)       std::vector<pj::MediaFormatVideo>; 
     123%template(CallMediaInfoVector)          std::vector<pj::CallMediaInfo>; 
     124%template(RtcpFbCapVector)              std::vector<pj::RtcpFbCap>; 
     125%template(SslCertNameVector)            std::vector<pj::SslCertName>; 
    117126 
    118127%ignore pj::WindowHandle::display; 
     
    145154%include "pjsua2/call.hpp" 
    146155 
    147 %template(CallMediaInfoVector)          std::vector<pj::CallMediaInfo>; 
    148  
    149156%ignore pj::JsonDocument::allocElement; 
    150157%ignore pj::JsonDocument::getPool; 
  • pjproject/trunk/pjsip/include/pjsua2/account.hpp

    r5820 r5969  
    16491649     * and delete the corresponding account in the PJSUA-LIB. 
    16501650     * 
     1651     * Note that application must delete all Buddy instances belong to this 
     1652     * account before shutting down the account. 
     1653     * 
    16511654     * If application implements a derived class, the derived class should 
    16521655     * call this method in the beginning stage in its destructor, or 
     
    17601763     
    17611764    /** 
     1765     * Warning: deprecated, use enumBuddies2() instead. This function is not 
     1766     * safe in multithreaded environment. 
     1767     * 
    17621768     * Enumerate all buddies of the account. 
    17631769     * 
     
    17671773 
    17681774    /** 
     1775     * Enumerate all buddies of the account. 
     1776     * 
     1777     * @return                  The buddy list. 
     1778     */ 
     1779    BuddyVector2 enumBuddies2() const throw(Error); 
     1780 
     1781    /** 
     1782     * Warning: deprecated, use findBuddy2 instead. This function is not 
     1783     * safe in multithreaded environment. 
     1784     * 
    17691785     * Find a buddy in the buddy list with the specified URI.  
    17701786     * 
     
    17781794    Buddy* findBuddy(string uri, FindBuddyMatch *buddy_match = NULL) const 
    17791795                    throw(Error); 
     1796 
     1797    /** 
     1798     * Find a buddy in the buddy list with the specified URI.  
     1799     * 
     1800     * Exception: if buddy is not found, PJ_ENOTFOUND will be thrown. 
     1801     * 
     1802     * @param uri               The buddy URI. 
     1803     * 
     1804     * @return                  The pointer to buddy. 
     1805     */ 
     1806    Buddy findBuddy2(string uri) const throw(Error); 
    17801807 
    17811808public: 
  • pjproject/trunk/pjsip/include/pjsua2/call.hpp

    r5923 r5969  
    312312     * Default constructor initializes with empty or default values. 
    313313     */ 
    314     CallSetting(pj_bool_t useDefaultValues = false); 
     314    CallSetting(bool useDefaultValues = false); 
    315315 
    316316    /** 
     
    10101010     * which are going to be used. 
    10111011     */ 
    1012     vector<SrtpCrypto>          cryptos; 
     1012    SrtpCryptoVector            cryptos; 
    10131013}; 
    10141014 
     
    12361236     
    12371237    /** 
     1238     * Warning: deprecated, use getAudioMedia() instead. This function is not 
     1239     * safe in multithreaded environment. 
     1240     * 
    12381241     * Get media for the specified media index. 
    12391242     * 
     
    12431246     */ 
    12441247    Media *getMedia(unsigned med_idx) const; 
     1248 
     1249    /** 
     1250     * Get audio media for the specified media index. If the specified media 
     1251     * index is not audio or invalid or inactive, exception will be thrown. 
     1252     * 
     1253     * @param med_idx       Media index. 
     1254     * 
     1255     * @return              The audio media. 
     1256     */ 
     1257    AudioMedia getAudioMedia(unsigned med_idx) const throw(Error); 
    12451258 
    12461259    /** 
  • pjproject/trunk/pjsip/include/pjsua2/endpoint.hpp

    r5964 r5969  
    133133}; 
    134134 
     135/** Array of SSL certificate type and name. */ 
     136typedef std::vector<SslCertName> SslCertNameVector; 
     137 
    135138/** 
    136139 * SSL certificate information. 
     
    156159                                                 date/time use GMT      */ 
    157160 
    158     vector<SslCertName> subjectAltName;     /**< Subject alternative 
     161    SslCertNameVector   subjectAltName;     /**< Subject alternative 
    159162                                                 name extension         */ 
    160163 
     
    13791382 
    13801383    /** 
     1384     * Warning: deprecated, use mediaEnumPorts2() instead. This function is 
     1385     * not safe in multithreaded environment. 
     1386     * 
    13811387     * Enumerate all media port. 
    13821388     * 
     
    13841390     */ 
    13851391    const AudioMediaVector &mediaEnumPorts() const throw(Error); 
     1392 
     1393    /** 
     1394     * Enumerate all audio media port. 
     1395     * 
     1396     * @return          The list of audio media port. 
     1397     */ 
     1398    AudioMediaVector2 mediaEnumPorts2() const throw(Error); 
    13861399 
    13871400    /** 
     
    14041417 
    14051418    /** 
     1419     * Warning: deprecated, use codecEnum2() instead. This function is not 
     1420     * safe in multithreaded environment. 
     1421     * 
    14061422     * Enum all supported codecs in the system. 
    14071423     * 
     
    14091425     */ 
    14101426    const CodecInfoVector &codecEnum() throw(Error); 
     1427 
     1428    /** 
     1429     * Enum all supported codecs in the system. 
     1430     * 
     1431     * @return          Array of codec info. 
     1432     */ 
     1433    CodecInfoVector2 codecEnum2() const throw(Error); 
    14111434 
    14121435    /** 
     
    14451468 
    14461469    /** 
     1470     * Warning: deprecated, use videoCodecEnum2() instead. This function is 
     1471     * not safe in multithreaded environment. 
     1472     * 
    14471473     * Enum all supported video codecs in the system. 
    14481474     *   
     
    14501476     */ 
    14511477    const CodecInfoVector &videoCodecEnum() throw(Error); 
     1478 
     1479    /** 
     1480     * Enum all supported video codecs in the system. 
     1481     *   
     1482     * @return          Array of video codec info. 
     1483     */ 
     1484    CodecInfoVector2 videoCodecEnum2() const throw(Error); 
    14521485 
    14531486    /** 
  • pjproject/trunk/pjsip/include/pjsua2/media.hpp

    r5956 r5969  
    214214 
    215215/** 
    216  * Audio Media. 
     216 * Audio Media. This is a lite wrapper class for audio conference bridge port, 
     217 * i.e: this class only maintains one data member, conference slot ID, and  
     218 * the methods are simply proxies for conference bridge operations. 
     219 * 
     220 * Application can create a derived class and use registerMediaPort2()/ 
     221 * unregisterMediaPort() to register/unregister a media port to/from the 
     222 * conference bridge. 
     223 * 
     224 * The library will not keep a list of AudioMedia instances, so any 
     225 * AudioMedia (descendant) instances instantiated by application must be 
     226 * maintained and destroyed by the application itself. 
     227 * 
     228 * Note that any PJSUA2 APIs that return AudioMedia instance(s) such as 
     229 * Endpoint::mediaEnumPorts2() or Call::getAudioMedia() will just return 
     230 * generated copy. All AudioMedia methods should work normally on this 
     231 * generated copy instance. 
    217232 */ 
    218233class AudioMedia : public Media 
     
    321336 
    322337    /** 
     338     * Warning: deprecated and will be removed in future release. 
     339     * 
    323340     * Typecast from base class Media. This is useful for application written 
    324341     * in language that does not support downcasting such as Python. 
     
    331348 
    332349    /** 
    333      * Virtual Destructor 
     350     * Default Constructor. Normally application will not create AudioMedia 
     351     * object directly, but it may instantiate an AudioMedia derived class. 
     352     */ 
     353    AudioMedia(); 
     354 
     355    /** 
     356     * Virtual Destructor. 
    334357     */ 
    335358    virtual ~AudioMedia(); 
     
    343366protected: 
    344367    /** 
    345      * Default Constructor. 
    346      */ 
    347     AudioMedia(); 
    348  
    349     /** 
     368     * Warning: deprecated and will be removed in future release, use 
     369     * registerMediaPort2() instead. 
     370     * 
    350371     * This method needs to be called by descendants of this class to register 
    351372     * the media port created to the conference bridge and Endpoint's 
    352373     * media list. 
    353374     * 
    354      * param port  the media port to be registered to the conference bridge. 
     375     * param port  The media port to be registered to the conference bridge. 
    355376     * 
    356377     */ 
    357378    void registerMediaPort(MediaPort port) throw(Error); 
     379 
     380    /** 
     381     * This method needs to be called by descendants of this class to register 
     382     * the media port created to the conference bridge and Endpoint's 
     383     * media list. 
     384     * 
     385     * param port  The media port to be registered to the conference bridge. 
     386     * param pool  The memory pool. 
     387     * 
     388     */ 
     389    void registerMediaPort2(MediaPort port, pj_pool_t *pool) throw(Error); 
    358390 
    359391    /** 
     
    366398 
    367399private: 
     400    /* Memory pool for deprecated registerMediaPort() */ 
    368401    pj_caching_pool      mediaCachingPool; 
    369402    pj_pool_t           *mediaPool; 
    370 }; 
     403 
     404    friend class Endpoint; 
     405}; 
     406 
     407/**  
     408 * Warning: deprecated, use AudioMediaVector2 instead. 
     409 * 
     410 * Array of Audio Media. 
     411 */ 
     412typedef std::vector<AudioMedia*> AudioMediaVector; 
     413 
    371414 
    372415/** Array of Audio Media */ 
    373 typedef std::vector<AudioMedia*> AudioMediaVector; 
     416typedef std::vector<AudioMedia> AudioMediaVector2; 
    374417 
    375418/** 
     
    465508 
    466509    /** 
     510     * Warning: deprecated and will be removed in future release. 
     511     * 
    467512     * Typecast from base class AudioMedia. This is useful for application 
    468513     * written in language that does not support downcasting such as Python. 
     
    475520 
    476521    /** 
    477      * Destructor. 
     522     * Destructor. This will unregister the player port from the conference 
     523     * bridge. 
    478524     */ 
    479525    virtual ~AudioMediaPlayer(); 
     
    546592    void createRecorder(const string &file_name, 
    547593                        unsigned enc_type=0, 
    548                         pj_ssize_t max_size=0, 
     594                        long max_size=0, 
    549595                        unsigned options=0) throw(Error); 
    550596 
    551597    /** 
     598     * Warning: deprecated and will be removed in future release. 
     599     * 
    552600     * Typecast from base class AudioMedia. This is useful for application 
    553601     * written in language that does not support downcasting such as Python. 
     
    560608 
    561609    /** 
    562      * Destructor. 
     610     * Destructor. This will unregister the recorder port from the conference 
     611     * bridge. 
    563612     */ 
    564613    virtual ~AudioMediaRecorder(); 
     
    635684 
    636685    /** 
    637      * Destructor. 
     686     * Destructor. This will unregister the tone generator port from the 
     687     * conference bridge. 
    638688     */ 
    639689    ~ToneGenerator(); 
    640690 
    641691    /** 
    642      * Create tone generator. 
     692     * Create tone generator and register the port to the conference bridge. 
    643693     */ 
    644694    void createToneGenerator(unsigned clock_rate = 16000, 
     
    776826}; 
    777827 
     828/**  
     829 * Warning: deprecated, use AudioDevInfoVector2 instead. 
     830 * 
     831 * Array of audio device info. 
     832 */ 
     833typedef std::vector<AudioDevInfo*> AudioDevInfoVector; 
     834 
    778835/** Array of audio device info */ 
    779 typedef std::vector<AudioDevInfo*> AudioDevInfoVector; 
     836typedef std::vector<AudioDevInfo> AudioDevInfoVector2; 
    780837 
    781838/** 
     
    836893 
    837894    /** 
     895     * Warning: deprecated, use enumDev2 instead. This function is not 
     896     * safe in multithreaded environment. 
     897     * 
     898     * Enum all audio devices installed in the system. This function is not 
     899     * safe in multithreaded environment. 
     900     * 
     901     * @return                  The list of audio device info. 
     902     */ 
     903    const AudioDevInfoVector &enumDev() throw(Error); 
     904 
     905    /** 
    838906     * Enum all audio devices installed in the system. 
    839907     * 
    840908     * @return                  The list of audio device info. 
    841909     */ 
    842     const AudioDevInfoVector &enumDev() throw(Error); 
     910    AudioDevInfoVector2 enumDev2() const throw(Error); 
    843911 
    844912    /** 
     
    14171485public: 
    14181486    /** 
    1419      * Constructor 
     1487     * Constructor. 
    14201488     * 
    14211489     * @param playdev           Playback device ID. 
     
    14251493 
    14261494    /** 
    1427      * Destructor 
     1495     * Destructor. 
    14281496     */ 
    14291497    virtual ~ExtraAudioDevice(); 
     
    14321500     * Open the audio device using format (e.g.: clock rate, bit per sample, 
    14331501     * samples per frame) matched to the conference bridge's format, except 
    1434      * the channel count, which will be set to one (mono channel). 
     1502     * the channel count, which will be set to one (mono channel). This will 
     1503     * also register the audio device port to conference bridge. 
    14351504     */ 
    14361505    void open(); 
    14371506 
    14381507    /** 
    1439      * Close the audio device. 
     1508     * Close the audio device and unregister the audio device port from the 
     1509     * conference bridge. 
    14401510     */ 
    14411511    void close(); 
     
    17661836}; 
    17671837 
     1838/**  
     1839 * Warning: deprecated, use VideoDevInfoVector2 instead. 
     1840 * 
     1841 * Array of video device info. 
     1842 */ 
     1843typedef std::vector<VideoDevInfo*> VideoDevInfoVector; 
     1844 
    17681845/** Array of video device info */ 
    1769 typedef std::vector<VideoDevInfo*> VideoDevInfoVector; 
     1846typedef std::vector<VideoDevInfo> VideoDevInfoVector2; 
    17701847 
    17711848/** 
     
    18131890 
    18141891    /** 
     1892     * Warning: deprecated, use enumDev2() instead. This function is not 
     1893     * safe in multithreaded environment. 
     1894     * 
    18151895     * Enum all video devices installed in the system. 
    18161896     * 
     
    18181898     */ 
    18191899    const VideoDevInfoVector &enumDev() throw(Error); 
     1900 
     1901    /** 
     1902     * Enum all video devices installed in the system. 
     1903     * 
     1904     * @return          The list of video device info 
     1905     */ 
     1906    VideoDevInfoVector2 enumDev2() const throw(Error); 
    18201907 
    18211908    /** 
     
    20562143}; 
    20572144 
     2145/**  
     2146 * Warning: deprecated, use CodecInfoVector2 instead. 
     2147 * 
     2148 * Array of codec info. 
     2149 */ 
     2150typedef std::vector<CodecInfo*> CodecInfoVector; 
     2151 
    20582152/** Array of codec info */ 
    2059 typedef std::vector<CodecInfo*> CodecInfoVector; 
     2153typedef std::vector<CodecInfo> CodecInfoVector2; 
    20602154 
    20612155/** 
  • pjproject/trunk/pjsip/include/pjsua2/presence.hpp

    r5672 r5969  
    169169     */ 
    170170    PresenceStatus       presStatus; 
    171      
     171 
    172172public: 
    173173    /** Import from pjsip structure */ 
     
    189189 
    190190/** 
    191  * Buddy. 
     191 * Buddy. This is a lite wrapper class for PJSUA-LIB buddy, i.e: this class 
     192 * only maintains one data member, PJSUA-LIB buddy ID, and the methods are 
     193 * simply proxies for PJSUA-LIB buddy operations. 
     194 * 
     195 * Application can use create() to register a buddy to PJSUA-LIB, and 
     196 * the destructor of the original instance (i.e: the instance that calls 
     197 * create()) will unregister and delete the buddy from PJSUA-LIB. Application 
     198 * must delete all Buddy instances belong to an account before shutting down 
     199 * the account (via Account::shutdown()). 
     200 * 
     201 * The library will not keep a list of Buddy instances, so any Buddy (or 
     202 * descendant) instances instantiated by application must be maintained 
     203 * and destroyed by the application itself. Any PJSUA2 APIs that return Buddy 
     204 * instance(s) such as Account::enumBuddies2() or Account::findBuddy2() will 
     205 * just return generated copy. All Buddy methods should work normally on this 
     206 * generated copy instance. 
    192207 */ 
    193208class Buddy 
     
    200215     
    201216    /** 
    202      * Destructor. Note that if the Buddy instance is deleted, it will also 
    203      * delete the corresponding buddy in the PJSUA-LIB. 
     217     * Destructor. Note that if the Buddy original instance (i.e: the instance 
     218     * that calls Buddy::create()) is destroyed, it will also delete the 
     219     * corresponding buddy in the PJSUA-LIB. While the destructor of 
     220     * a generated copy (i.e: Buddy instance returned by PJSUA2 APIs such as 
     221     * Account::enumBuddies2() or Account::findBuddy2()) will do nothing. 
    204222     */ 
    205223    virtual ~Buddy(); 
     
    207225    /** 
    208226     * Create buddy and register the buddy to PJSUA-LIB. 
     227     * 
     228     * Note that application should maintain the Buddy original instance, i.e: 
     229     * the instance that calls this create() method as it is only the original 
     230     * instance destructor that will delete the underlying Buddy in PJSUA-LIB. 
    209231     * 
    210232     * @param acc               The account for this buddy. 
     
    298320      * Buddy ID. 
    299321      */ 
    300      pjsua_buddy_id      id; 
    301       
    302      /** 
    303       * Account. 
    304       */ 
    305      Account            *acc; 
    306 }; 
    307  
     322    pjsua_buddy_id       id; 
     323 
     324private: 
     325    friend class Endpoint; 
     326    friend class Account; 
     327 
     328    /* Internal constructor/methods used by Endpoint and Account */ 
     329    Buddy(pjsua_buddy_id buddy_id); 
     330    Buddy *getOriginalInstance(); 
     331}; 
     332 
     333 
     334/** 
     335 * Warning: deprecated, use BuddyVector2 instead. 
     336 * 
     337 * Array of buddies. 
     338 */ 
     339typedef std::vector<Buddy*> BuddyVector; 
    308340 
    309341/** Array of buddies */ 
    310 typedef std::vector<Buddy*> BuddyVector; 
     342typedef std::vector<Buddy> BuddyVector2; 
    311343 
    312344 
  • pjproject/trunk/pjsip/src/pjsua2/account.cpp

    r5837 r5969  
    10291029} 
    10301030 
     1031BuddyVector2 Account::enumBuddies2() const throw(Error) 
     1032{ 
     1033    BuddyVector2 bv2; 
     1034    pjsua_buddy_id ids[PJSUA_MAX_BUDDIES]; 
     1035    unsigned i, count = PJSUA_MAX_BUDDIES; 
     1036 
     1037    PJSUA2_CHECK_EXPR( pjsua_enum_buddies(ids, &count) ); 
     1038    for (i = 0; i < count; ++i) { 
     1039        bv2.push_back(Buddy(ids[i])); 
     1040    } 
     1041 
     1042    return bv2; 
     1043} 
     1044 
    10311045Buddy* Account::findBuddy(string uri, FindBuddyMatch *buddy_match) const 
    10321046                throw(Error) 
     
    10421056    } 
    10431057    PJSUA2_RAISE_ERROR(PJ_ENOTFOUND); 
     1058} 
     1059 
     1060Buddy Account::findBuddy2(string uri) const throw(Error) 
     1061{ 
     1062    pj_str_t pj_uri; 
     1063    pjsua_buddy_id id; 
     1064 
     1065    pj_strset2(&pj_uri, (char*)uri.c_str()); 
     1066 
     1067    id = pjsua_buddy_find(&pj_uri); 
     1068    if (id == PJSUA_INVALID_ID) { 
     1069        PJSUA2_RAISE_ERROR(PJ_ENOTFOUND); 
     1070    } 
     1071 
     1072    Buddy buddy(id); 
     1073    return buddy; 
    10441074} 
    10451075 
  • pjproject/trunk/pjsip/src/pjsua2/call.cpp

    r5923 r5969  
    228228} 
    229229 
    230 CallSetting::CallSetting(pj_bool_t useDefaultValues) 
     230CallSetting::CallSetting(bool useDefaultValues) 
    231231{ 
    232232    if (useDefaultValues) { 
     
    522522} 
    523523 
     524AudioMedia Call::getAudioMedia(unsigned med_idx) const throw(Error) 
     525{ 
     526    CallAudioMedia cam; 
     527    CallInfo ci = getInfo(); 
     528 
     529    if (med_idx < ci.media.size() && 
     530        ci.media[med_idx].type == PJMEDIA_TYPE_AUDIO) 
     531    { 
     532        cam.setPortId(ci.media[med_idx].audioConfSlot); 
     533    } 
     534    return cam; 
     535} 
     536 
    524537pjsip_dialog_cap_status Call::remoteHasCap(int htype, 
    525538                                           const string &hname, 
  • pjproject/trunk/pjsip/src/pjsua2/endpoint.cpp

    r5964 r5969  
    978978void Endpoint::on_buddy_state(pjsua_buddy_id buddy_id) 
    979979{ 
    980     Buddy *buddy = (Buddy*)pjsua_buddy_get_user_data(buddy_id); 
     980    Buddy b(buddy_id); 
     981    Buddy *buddy = b.getOriginalInstance(); 
    981982    if (!buddy || !buddy->isValid()) { 
    982983        /* Ignored */ 
     
    993994    PJ_UNUSED_ARG(sub); 
    994995 
    995     Buddy *buddy = (Buddy*)pjsua_buddy_get_user_data(buddy_id); 
     996    Buddy b(buddy_id); 
     997    Buddy *buddy = b.getOriginalInstance(); 
    996998    if (!buddy || !buddy->isValid()) { 
    997999        /* Ignored */ 
     
    20452047} 
    20462048 
     2049AudioMediaVector2 Endpoint::mediaEnumPorts2() const throw(Error) 
     2050{ 
     2051    AudioMediaVector2 amv2; 
     2052    pjsua_conf_port_id ids[PJSUA_MAX_CONF_PORTS]; 
     2053    unsigned i, count = PJSUA_MAX_CONF_PORTS; 
     2054 
     2055    PJSUA2_CHECK_EXPR( pjsua_enum_conf_ports(ids, &count) ); 
     2056    for (i = 0; i < count; ++i) { 
     2057        AudioMedia am; 
     2058        am.id = ids[i]; 
     2059        amv2.push_back(am); 
     2060    } 
     2061 
     2062    return amv2; 
     2063} 
     2064 
    20472065void Endpoint::mediaAdd(AudioMedia &media) 
    20482066{ 
     2067    /* mediaList serves mediaEnumPorts() only, once mediaEnumPorts() 
     2068     * is removed, this function implementation should be no-op. 
     2069     */ 
    20492070    pj_mutex_lock(mediaListMutex); 
    20502071 
     
    20602081void Endpoint::mediaRemove(AudioMedia &media) 
    20612082{ 
     2083    /* mediaList serves mediaEnumPorts() only, once mediaEnumPorts() 
     2084     * is removed, this function implementation should be no-op. 
     2085     */ 
    20622086    pj_mutex_lock(mediaListMutex); 
    20632087    AudioMediaVector::iterator it = std::find(mediaList.begin(), 
     
    20672091    if (it != mediaList.end()) 
    20682092        mediaList.erase(it); 
    2069  
    20702093    pj_mutex_unlock(mediaListMutex); 
    20712094} 
     
    20732096bool Endpoint::mediaExists(const AudioMedia &media) const 
    20742097{ 
    2075     bool exists; 
    2076  
    2077     pj_mutex_lock(mediaListMutex); 
    2078     AudioMediaVector::const_iterator it = std::find(mediaList.begin(), 
    2079                                                     mediaList.end(), 
    2080                                                     &media); 
    2081     exists = (it != mediaList.end()); 
    2082     pj_mutex_unlock(mediaListMutex); 
    2083     return exists; 
     2098    pjsua_conf_port_id id = media.getPortId(); 
     2099    if (id == PJSUA_INVALID_ID || id >= (int)mediaMaxPorts()) 
     2100        return false; 
     2101 
     2102    pjsua_conf_port_info pi; 
     2103    return (pjsua_conf_get_port_info(id, &pi) == PJ_SUCCESS); 
    20842104} 
    20852105 
     
    21082128} 
    21092129 
     2130CodecInfoVector2 Endpoint::codecEnum2() const throw(Error) 
     2131{ 
     2132    CodecInfoVector2 civ2; 
     2133    pjsua_codec_info pj_codec[MAX_CODEC_NUM]; 
     2134    unsigned count = MAX_CODEC_NUM; 
     2135 
     2136    PJSUA2_CHECK_EXPR( pjsua_enum_codecs(pj_codec, &count) ); 
     2137    for (unsigned i = 0; i<count; ++i) { 
     2138        CodecInfo codec_info; 
     2139        codec_info.fromPj(pj_codec[i]); 
     2140        civ2.push_back(codec_info); 
     2141    } 
     2142    return civ2; 
     2143} 
     2144 
    21102145void Endpoint::codecSetPriority(const string &codec_id, 
    21112146                                pj_uint8_t priority) throw(Error) 
     
    21692204#endif 
    21702205    return videoCodecInfoList; 
     2206} 
     2207 
     2208CodecInfoVector2 Endpoint::videoCodecEnum2() const throw(Error) 
     2209{ 
     2210    CodecInfoVector2 civ2; 
     2211#if PJSUA_HAS_VIDEO 
     2212    pjsua_codec_info pj_codec[MAX_CODEC_NUM]; 
     2213    unsigned count = MAX_CODEC_NUM; 
     2214 
     2215    PJSUA2_CHECK_EXPR(pjsua_vid_enum_codecs(pj_codec, &count)); 
     2216    for (unsigned i = 0; i<count; ++i) { 
     2217        CodecInfo codec_info; 
     2218        codec_info.fromPj(pj_codec[i]); 
     2219        civ2.push_back(codec_info); 
     2220    } 
     2221#endif 
     2222    return civ2; 
    21712223} 
    21722224 
  • pjproject/trunk/pjsip/src/pjsua2/media.cpp

    r5956 r5969  
    158158} 
    159159 
     160void AudioMedia::registerMediaPort2(MediaPort port, pj_pool_t *pool) 
     161     throw(Error) 
     162{ 
     163    /* Check if media already added to Conf bridge. */ 
     164    pj_assert(!Endpoint::instance().mediaExists(*this)); 
     165 
     166    if (port != NULL) { 
     167        pj_assert(id == PJSUA_INVALID_ID); 
     168        pj_assert(pool); 
     169 
     170        PJSUA2_CHECK_EXPR( pjsua_conf_add_port(pool, 
     171                                               (pjmedia_port *)port, 
     172                                               &id) ); 
     173    } 
     174 
     175    Endpoint::instance().mediaAdd(*this); 
     176} 
     177 
    160178void AudioMedia::unregisterMediaPort() 
    161179{ 
     
    176194AudioMedia::~AudioMedia()  
    177195{ 
    178     unregisterMediaPort(); 
    179196} 
    180197 
     
    409426void AudioMediaRecorder::createRecorder(const string &file_name, 
    410427                                        unsigned enc_type, 
    411                                         pj_ssize_t max_size, 
     428                                        long max_size, 
    412429                                        unsigned options) 
    413430                                        throw(Error) 
     
    481498    } 
    482499 
    483     registerMediaPort(tonegen); 
     500    registerMediaPort2(tonegen, pool); 
    484501} 
    485502 
     
    746763    pj_leave_critical_section(); 
    747764    return audioDevList; 
     765} 
     766 
     767AudioDevInfoVector2 AudDevManager::enumDev2() const throw(Error) 
     768{ 
     769    pjmedia_aud_dev_info pj_info[MAX_DEV_COUNT]; 
     770    unsigned count = MAX_DEV_COUNT; 
     771    AudioDevInfoVector2 adiv2; 
     772 
     773    PJSUA2_CHECK_EXPR( pjsua_enum_aud_devs(pj_info, &count) ); 
     774 
     775    for (unsigned i = 0; i<count ;++i) { 
     776        AudioDevInfo di; 
     777        di.fromPj(pj_info[i]); 
     778        adiv2.push_back(di); 
     779    } 
     780 
     781    return adiv2; 
    748782} 
    749783 
     
    14271461} 
    14281462 
     1463VideoDevInfoVector2 VidDevManager::enumDev2() const throw(Error) 
     1464{ 
     1465    VideoDevInfoVector2 vdiv2; 
     1466#if PJSUA_HAS_VIDEO 
     1467    pjmedia_vid_dev_info pj_info[MAX_DEV_COUNT]; 
     1468    unsigned count = MAX_DEV_COUNT; 
     1469 
     1470    PJSUA2_CHECK_EXPR(pjsua_vid_enum_devs(pj_info, &count)); 
     1471 
     1472    for (unsigned i = 0; i<count;++i) { 
     1473        VideoDevInfo vdi; 
     1474        vdi.fromPj(pj_info[i]); 
     1475        vdiv2.push_back(vdi); 
     1476    } 
     1477#endif 
     1478    return vdiv2; 
     1479} 
     1480 
    14291481int VidDevManager::lookupDev(const string &drv_name, 
    14301482                             const string &dev_name) const throw(Error) 
  • pjproject/trunk/pjsip/src/pjsua2/presence.cpp

    r4704 r5969  
    7474 
    7575////////////////////////////////////////////////////////////////////////////// 
     76typedef struct BuddyUserData 
     77{ 
     78    Buddy       *self; 
     79    Account     *acc; 
     80} BuddyUserData; 
    7681 
    7782/* 
     
    8388} 
    8489  
     90Buddy::Buddy(pjsua_buddy_id buddy_id) 
     91: id(buddy_id) 
     92{ 
     93} 
     94 
     95Buddy *Buddy::getOriginalInstance() 
     96{ 
     97    BuddyUserData *bud = (BuddyUserData*)pjsua_buddy_get_user_data(id); 
     98    return (bud? bud->self : NULL); 
     99} 
     100 
    85101/* 
    86102 * Destructor. 
     
    88104Buddy::~Buddy() 
    89105{ 
    90     if (isValid()) { 
     106    if (isValid() && getOriginalInstance()==this) { 
     107        Account *acc = NULL; 
     108        BuddyUserData *bud = (BuddyUserData*)pjsua_buddy_get_user_data(id); 
     109        if (bud) { 
     110            acc = bud->acc; 
     111            delete bud; 
     112        } 
     113 
    91114        pjsua_buddy_set_user_data(id, NULL); 
    92115        pjsua_buddy_del(id); 
    93116 
    94117        /* Remove from account buddy list */ 
    95         acc->removeBuddy(this); 
     118        if (acc) 
     119            acc->removeBuddy(this); 
    96120    } 
    97121} 
     
    108132        PJSUA2_RAISE_ERROR3(PJ_EINVAL, "Buddy::create()", "Invalid account"); 
    109133     
     134    BuddyUserData *bud = new BuddyUserData(); 
     135    bud->self = this; 
     136    bud->acc  = &account; 
     137 
    110138    pj_cfg.uri = str2Pj(cfg.uri); 
    111139    pj_cfg.subscribe = cfg.subscribe; 
    112     pj_cfg.user_data = (void*)this; 
     140    pj_cfg.user_data = (void*)bud; 
    113141    PJSUA2_CHECK_EXPR( pjsua_buddy_add(&pj_cfg, &id) ); 
    114142     
    115     acc = &account; 
    116     acc->addBuddy(this); 
     143    account.addBuddy(this); 
    117144} 
    118145     
     
    161188{ 
    162189    BuddyInfo bi = getInfo(); 
     190    BuddyUserData *bud = (BuddyUserData*)pjsua_buddy_get_user_data(id); 
     191    Account *acc = bud? bud->acc : NULL; 
     192 
     193    if (!bud || !acc || !acc->isValid()) { 
     194        PJSUA2_RAISE_ERROR3(PJ_EINVAL, "sendInstantMessage()", 
     195                            "Invalid Buddy"); 
     196    } 
    163197 
    164198    pj_str_t to = str2Pj(bi.contact.empty()? bi.uri : bi.contact); 
     
    180214{ 
    181215    BuddyInfo bi = getInfo(); 
     216    BuddyUserData *bud = (BuddyUserData*)pjsua_buddy_get_user_data(id); 
     217    Account *acc = bud? bud->acc : NULL; 
     218 
     219    if (!bud || !acc || !acc->isValid()) { 
     220        PJSUA2_RAISE_ERROR3(PJ_EINVAL, "sendInstantMessage()", 
     221                            "Invalid Buddy"); 
     222    } 
    182223 
    183224    pj_str_t to = str2Pj(bi.contact.empty()? bi.uri : bi.contact); 
Note: See TracChangeset for help on using the changeset viewer.