Changeset 4669


Ignore:
Timestamp:
Dec 3, 2013 10:45:36 AM (10 years ago)
Author:
riza
Message:

Re #1519: Added codec management operations to Media API in pjsua2.

Location:
pjproject/branches/projects/pjsua2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/pjsua2/pjsip-apps/src/swig/pjsua2.i

    r4668 r4669  
    7575%template(AudioMediaVector)             std::vector<pj::AudioMedia*>; 
    7676%template(MediaFormatVector)            std::vector<pj::MediaFormat*>; 
    77 %template(AudioDevInfoVector)   std::vector<AudioDevInfo*>; 
     77%template(AudioDevInfoVector)           std::vector<AudioDevInfo*>; 
     78%template(CodecInfoVector)              std::vector<pj::CodecInfo*>; 
    7879 
    7980%include "pjsua2/media.hpp" 
  • pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/endpoint.hpp

    r4668 r4669  
    10071007    AudDevManager &audDevManager(); 
    10081008 
     1009    /************************************************************************* 
     1010     * Codec management operations 
     1011     */ 
     1012 
     1013    /** 
     1014     * Enum all supported codecs in the system. 
     1015     * 
     1016     * @return          Array of codec info. 
     1017     */ 
     1018    const CodecInfoVector &codecEnum() throw(Error); 
     1019 
     1020    /** 
     1021     * Change codec priority. 
     1022     * 
     1023     * @param codec_id  Codec ID, which is a string that uniquely identify 
     1024     *                  the codec (such as "speex/8000"). 
     1025     * @param priority  Codec priority, 0-255, where zero means to disable 
     1026     *                  the codec. 
     1027     * 
     1028     */ 
     1029    void codecSetPriority(const string &codec_id, 
     1030                          pj_uint8_t priority) throw(Error); 
     1031 
     1032    /** 
     1033     * Get codec parameters. 
     1034     * 
     1035     * @param codec_id          Codec ID. 
     1036     * 
     1037     * @return                  Codec parameters. If codec is not found, Error 
     1038     *                          will be thrown. 
     1039     * 
     1040     */ 
     1041    CodecParam codecGetParam(const string &codec_id) const throw(Error); 
     1042 
     1043    /** 
     1044     * Set codec parameters. 
     1045     * 
     1046     * @param codec_id  Codec ID. 
     1047     * @param param     Codec parameter to set. Set to NULL to reset 
     1048     *                  codec parameter to library default settings. 
     1049     * 
     1050     */ 
     1051    void codecSetParam(const string &codec_id, 
     1052                       const CodecParam param) throw(Error); 
     1053 
     1054 
    10091055public: 
    10101056    /* 
     
    10751121    AudioMediaVector             mediaList; 
    10761122    AudDevManager                audioDevMgr; 
     1123    CodecInfoVector              codecInfoList; 
    10771124 
    10781125    /* Endpoint static callbacks */ 
     
    11971244                              unsigned flags); 
    11981245 
     1246private: 
     1247    void clearCodecInfoList(); 
     1248 
    11991249}; 
    12001250 
  • pjproject/branches/projects/pjsua2/pjsip/include/pjsua2/media.hpp

    r4668 r4669  
    276276     * the media port from the conference bridge and Endpoint's media list. 
    277277     * Descendant should only call this method if it has registered the media 
    278      * with the previous call to #registerMediaPort(). 
     278     * with the previous call to registerMediaPort(). 
    279279     */ 
    280280    void unregisterMediaPort(); 
     
    432432 
    433433    /** 
    434      * Device capabilities, as bitmask combination of #pjmedia_aud_dev_cap. 
     434     * Device capabilities, as bitmask combination of pjmedia_aud_dev_cap. 
    435435     */ 
    436436    unsigned caps; 
     
    438438    /** 
    439439     * Supported audio device routes, as bitmask combination of 
    440      * #pjmedia_aud_dev_route. The value may be zero if the device 
     440     * pjmedia_aud_dev_route. The value may be zero if the device 
    441441     * does not support audio routing. 
    442442     */ 
     
    562562     * Check whether the sound device is currently active. The sound device 
    563563     * may be inactive if the application has set the auto close feature to 
    564      * non-zero (the sndAutoCloseTime setting in #MediaConfig), or 
     564     * non-zero (the sndAutoCloseTime setting in MediaConfig), or 
    565565     * if null sound device or no sound device has been configured via the 
    566      * #setNoDev() function. 
     566     * setNoDev() function. 
    567567     */ 
    568568    bool sndIsActive() const; 
     
    10541054}; 
    10551055 
     1056/************************************************************************* 
     1057* Codec management 
     1058*/ 
     1059 
     1060/** 
     1061 * This structure describes codec information. 
     1062 */ 
     1063struct CodecInfo 
     1064{ 
     1065    /** 
     1066     * Codec unique identification. 
     1067     */ 
     1068    string              codecId; 
     1069 
     1070    /** 
     1071     * Codec priority (integer 0-255). 
     1072     */ 
     1073    pj_uint8_t          priority; 
     1074 
     1075    /** 
     1076     * Codec description. 
     1077     */ 
     1078    string              desc; 
     1079 
     1080    /** 
     1081     * Construct from pjsua_codec_info. 
     1082     */ 
     1083    void fromPj(const pjsua_codec_info &codec_info); 
     1084}; 
     1085 
     1086/** Array of codec info */ 
     1087typedef std::vector<CodecInfo*> CodecInfoVector; 
     1088 
     1089/** 
     1090 * Codec parameters, corresponds to pjmedia_codec_param or 
     1091 * pjmedia_vid_codec_param. 
     1092 */ 
     1093typedef void *CodecParam; 
     1094 
    10561095} // namespace pj 
    10571096 
  • pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/endpoint.cpp

    r4668 r4669  
    3232#define MAX_STUN_SERVERS        32 
    3333#define TIMER_SIGNATURE         0x600D878A 
     34#define MAX_CODEC_NUM           64 
    3435 
    3536struct UserTimer 
     
    376377    } 
    377378 
     379    clearCodecInfoList(); 
     380 
    378381    instance_ = NULL; 
    379382} 
     
    13651368    return audioDevMgr; 
    13661369} 
     1370 
     1371/* 
     1372 * Codec operations. 
     1373 */ 
     1374const CodecInfoVector &Endpoint::codecEnum() throw(Error) 
     1375{ 
     1376    pjsua_codec_info pj_codec[MAX_CODEC_NUM]; 
     1377    unsigned count = 0; 
     1378 
     1379    PJSUA2_CHECK_EXPR( pjsua_enum_codecs(pj_codec, &count) ); 
     1380 
     1381    clearCodecInfoList(); 
     1382 
     1383    pj_enter_critical_section(); 
     1384    for (unsigned i=0;(i<count && i<MAX_CODEC_NUM);++i) { 
     1385        CodecInfo *codec_info = new CodecInfo; 
     1386 
     1387        codec_info->fromPj(pj_codec[i]); 
     1388        codecInfoList.push_back(codec_info); 
     1389    } 
     1390    pj_leave_critical_section(); 
     1391    return codecInfoList; 
     1392} 
     1393 
     1394void Endpoint::codecSetPriority(const string &codec_id, 
     1395                                pj_uint8_t priority) throw(Error) 
     1396{ 
     1397    pj_str_t codec_str = str2Pj(codec_id); 
     1398    PJSUA2_CHECK_EXPR( pjsua_codec_set_priority(&codec_str, priority) ); 
     1399} 
     1400 
     1401CodecParam Endpoint::codecGetParam(const string &codec_id) const throw(Error) 
     1402{ 
     1403    pjmedia_codec_param *pj_param = NULL; 
     1404    pj_str_t codec_str = str2Pj(codec_id); 
     1405 
     1406    PJSUA2_CHECK_EXPR( pjsua_codec_get_param(&codec_str, pj_param) ); 
     1407 
     1408    return pj_param; 
     1409} 
     1410 
     1411void Endpoint::codecSetParam(const string &codec_id, 
     1412                             const CodecParam param) throw(Error) 
     1413{ 
     1414    pj_str_t codec_str = str2Pj(codec_id); 
     1415    pjmedia_codec_param *pj_param = (pjmedia_codec_param*)param; 
     1416 
     1417    PJSUA2_CHECK_EXPR( pjsua_codec_set_param(&codec_str, pj_param) ); 
     1418} 
     1419 
     1420void Endpoint::clearCodecInfoList() 
     1421{ 
     1422    pj_enter_critical_section(); 
     1423    for (unsigned i=0;i<codecInfoList.size();++i) { 
     1424        delete codecInfoList[i]; 
     1425    } 
     1426    codecInfoList.clear(); 
     1427    pj_leave_critical_section(); 
     1428} 
  • pjproject/branches/projects/pjsua2/pjsip/src/pjsua2/media.cpp

    r4668 r4669  
    386386    unsigned count; 
    387387 
     388    PJSUA2_CHECK_EXPR( pjsua_enum_aud_devs(pj_info, &count) ); 
     389 
    388390    clearAudioDevList(); 
    389391 
    390     PJSUA2_CHECK_EXPR( pjsua_enum_aud_devs(pj_info, &count) ); 
    391  
     392    pj_enter_critical_section(); 
    392393    for (unsigned i = 0; (i<count && i<MAX_DEV_COUNT) ;++i) { 
    393394        AudioDevInfo *dev_info = new AudioDevInfo; 
     
    395396        audioDevList.push_back(dev_info); 
    396397    } 
     398    pj_leave_critical_section(); 
    397399    return audioDevList; 
    398400} 
     
    691693void AudDevManager::clearAudioDevList() 
    692694{ 
     695    pj_enter_critical_section(); 
    693696    for(unsigned i=0;i<audioDevList.size();++i) { 
    694697        delete audioDevList[i]; 
    695698    } 
    696699    audioDevList.clear(); 
     700    pj_leave_critical_section(); 
    697701} 
    698702 
     
    704708    return is_capture?capture_dev:playback_dev; 
    705709} 
     710 
     711/////////////////////////////////////////////////////////////////////////////// 
     712void CodecInfo::fromPj(const pjsua_codec_info &codec_info) 
     713{ 
     714    codecId = pj2Str(codec_info.codec_id); 
     715    priority = codec_info.priority; 
     716    desc = pj2Str(codec_info.desc); 
     717} 
Note: See TracChangeset for help on using the changeset viewer.