Changeset 5273 for pjproject


Ignore:
Timestamp:
Apr 4, 2016 1:44:10 AM (5 years ago)
Author:
riza
Message:

Re #1908: Implement new API to open speaker only in pjsua/pjsua2.

Location:
pjproject/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/swig/symbols.i

    r5165 r5273  
    166166typedef enum pjsua_create_media_transport_flag {PJSUA_MED_TP_CLOSE_MEMBER = 1} pjsua_create_media_transport_flag; 
    167167 
     168typedef enum pjsua_snd_dev_mode {PJSUA_SND_DEV_SPEAKER_ONLY = 1, PJSUA_SND_DEV_NO_IMMEDIATE_OPEN = 2} pjsua_snd_dev_mode; 
     169 
  • pjproject/trunk/pjsip-apps/src/swig/symbols.lst

    r5165 r5273  
    3434pjsip-ua/sip_inv.h              pjsip_inv_state 
    3535 
    36 pjsua-lib/pjsua.h               pjsua_invalid_id_const_ pjsua_state pjsua_stun_use pjsua_call_hold_type pjsua_acc_id pjsua_destroy_flag pjsua_100rel_use pjsua_sip_timer_use pjsua_ipv6_use pjsua_buddy_status pjsua_call_media_status pjsua_vid_win_id pjsua_call_id pjsua_med_tp_st pjsua_call_vid_strm_op pjsua_vid_req_keyframe_method pjsua_call_flag pjsua_create_media_transport_flag 
     36pjsua-lib/pjsua.h               pjsua_invalid_id_const_ pjsua_state pjsua_stun_use pjsua_call_hold_type pjsua_acc_id pjsua_destroy_flag pjsua_100rel_use pjsua_sip_timer_use pjsua_ipv6_use pjsua_buddy_status pjsua_call_media_status pjsua_vid_win_id pjsua_call_id pjsua_med_tp_st pjsua_call_vid_strm_op pjsua_vid_req_keyframe_method pjsua_call_flag pjsua_create_media_transport_flag pjsua_snd_dev_mode 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r5242 r5273  
    59985998} pjsua_media_transport; 
    59995999 
     6000/** 
     6001 * This enumeration specifies the sound device mode. 
     6002 */ 
     6003typedef enum pjsua_snd_dev_mode 
     6004{ 
     6005    /** 
     6006     * Open sound device without mic (speaker only). 
     6007     */ 
     6008    PJSUA_SND_DEV_SPEAKER_ONLY = 1, 
     6009 
     6010    /** 
     6011     * Do not open sound device, after setting the sound device. 
     6012     */ 
     6013    PJSUA_SND_DEV_NO_IMMEDIATE_OPEN  = 2 
     6014 
     6015} pjsua_snd_dev_mode; 
     6016 
     6017 
     6018/** 
     6019 * This structure specifies the parameters to set the sound device. 
     6020 * Use pjsua_snd_dev_param_default() to initialize this structure with 
     6021 * default values. 
     6022 */ 
     6023typedef struct pjsua_snd_dev_param 
     6024{ 
     6025    /* 
     6026     * Capture dev id. 
     6027     * 
     6028     * Default: PJMEDIA_AUD_DEFAULT_CAPTURE_DEV 
     6029     */ 
     6030    int                 capture_dev; 
     6031 
     6032    /* 
     6033     * Playback dev id. 
     6034     * 
     6035     * Default: PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV 
     6036     */ 
     6037    int                 playback_dev; 
     6038 
     6039    /* 
     6040     * Sound device mode, refer to #pjsua_snd_dev_mode. 
     6041     * 
     6042     * Default: 0 
     6043     */ 
     6044    unsigned            mode; 
     6045 
     6046} pjsua_snd_dev_param; 
     6047 
     6048 
     6049/** 
     6050 * Initialize pjsua_snd_dev_param with default values. 
     6051 * 
     6052 * @param prm           The parameter. 
     6053 */ 
     6054PJ_DECL(void) pjsua_snd_dev_param_default(pjsua_snd_dev_param *prm); 
     6055 
    60006056 
    60016057/** 
     
    63856441                                       int playback_dev); 
    63866442 
     6443/** 
     6444 * Select or change sound device according to the specified param. 
     6445 * 
     6446 * @param snd_param     Sound device param.  
     6447 * 
     6448 * @return              PJ_SUCCESS on success, or the appropriate error code. 
     6449 */ 
     6450PJ_DECL(pj_status_t) pjsua_set_snd_dev2(pjsua_snd_dev_param *snd_param); 
     6451 
    63876452 
    63886453/** 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h

    r5217 r5273  
    479479    pjmedia_port        *null_port; /**< Null port.                     */ 
    480480    pj_bool_t            snd_is_on; /**< Media flow is currently active */ 
     481    unsigned             snd_mode;  /**< Sound device mode.             */ 
    481482 
    482483    /* Video device */ 
  • pjproject/trunk/pjsip/include/pjsua2/media.hpp

    r5165 r5273  
    768768    /** 
    769769     * Select or change capture sound device. Application may call this 
    770      * function at any time to replace current sound device. 
     770     * function at any time to replace current sound device. Calling this  
     771     * method will not change the state of the sound device (opened/closed). 
     772     * Note that this method will override the mode set by setSndDevMode(). 
    771773     * 
    772774     * @param capture_dev       Device ID of the capture device. 
     
    776778    /** 
    777779     * Select or change playback sound device. Application may call this 
    778      * function at any time to replace current sound device. 
     780     * function at any time to replace current sound device. Calling this  
     781     * method will not change the state of the sound device (opened/closed). 
     782     * Note that this method will override the mode set by setSndDevMode(). 
    779783     * 
    780784     * @param playback_dev      Device ID of the playback device. 
     
    806810     */ 
    807811    MediaPort *setNoDev(); 
     812 
     813    /** 
     814     * Set sound device mode. 
     815     *  
     816     * @param mode              The sound device mode, as bitmask combination  
     817     *                          of #pjsua_snd_dev_mode 
     818     * 
     819     */ 
     820    void setSndDevMode(unsigned mode) const throw(Error); 
    808821 
    809822    /** 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_aud.c

    r5205 r5273  
    688688} 
    689689 
     690PJ_DEF(void) pjsua_snd_dev_param_default(pjsua_snd_dev_param *prm) 
     691{ 
     692    pj_bzero(prm, sizeof(*prm)); 
     693    prm->capture_dev = PJMEDIA_AUD_DEFAULT_CAPTURE_DEV; 
     694    prm->playback_dev = PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV; 
     695} 
    690696 
    691697/* 
     
    16971703    pjmedia_port *conf_port; 
    16981704    pj_status_t status; 
     1705    pj_bool_t speaker_only = (pjsua_var.snd_mode & PJSUA_SND_DEV_SPEAKER_ONLY); 
    16991706 
    17001707    PJ_ASSERT_RETURN(param, PJ_EINVAL); 
     
    17251732        param->on_rec_frame = &on_aud_prev_rec_frame; 
    17261733 
    1727     PJ_LOG(4,(THIS_FILE, "Opening sound device %s@%d/%d/%dms", 
     1734    PJ_LOG(4,(THIS_FILE, "Opening sound device (%s) %s@%d/%d/%dms", 
     1735              speaker_only?"speaker only":"speaker + mic", 
    17281736              get_fmt_name(param->base.ext_fmt.id), 
    17291737              param->base.clock_rate, param->base.channel_count, 
     
    17321740    pj_log_push_indent(); 
    17331741 
    1734     status = pjmedia_snd_port_create2( pjsua_var.snd_pool, 
    1735                                        param, &pjsua_var.snd_port); 
     1742    if (speaker_only) { 
     1743        status = pjmedia_snd_port_create_player(pjsua_var.snd_pool, 
     1744                                                -1, 
     1745                                                param->base.clock_rate, 
     1746                                                param->base.channel_count, 
     1747                                                param->base.samples_per_frame, 
     1748                                                param->base.bits_per_sample,  
     1749                                                0, 
     1750                                                &pjsua_var.snd_port); 
     1751 
     1752    } else { 
     1753        status = pjmedia_snd_port_create2(pjsua_var.snd_pool, 
     1754                                          param, &pjsua_var.snd_port); 
     1755    } 
     1756 
    17361757    if (status != PJ_SUCCESS) 
    17371758        goto on_error; 
     
    19211942 
    19221943 
     1944PJ_DEF(pj_status_t) pjsua_set_snd_dev(int capture_dev, 
     1945                                      int playback_dev) 
     1946{ 
     1947    pjsua_snd_dev_param param; 
     1948 
     1949    pjsua_snd_dev_param_default(&param); 
     1950 
     1951    param.capture_dev = capture_dev; 
     1952    param.playback_dev = playback_dev; 
     1953    /* Always open the sound device. */ 
     1954    param.mode = 0; 
     1955 
     1956    return pjsua_set_snd_dev2(&param); 
     1957} 
     1958 
    19231959/* 
    19241960 * Select or change sound device. Application may call this function at 
    19251961 * any time to replace current sound device. 
    19261962 */ 
    1927 PJ_DEF(pj_status_t) pjsua_set_snd_dev( int capture_dev, 
    1928                                        int playback_dev) 
     1963PJ_DEF(pj_status_t) pjsua_set_snd_dev2(pjsua_snd_dev_param *snd_param) 
    19291964{ 
    19301965    unsigned alt_cr_cnt = 1; 
     
    19321967    unsigned i; 
    19331968    pj_status_t status = -1; 
     1969    unsigned orig_snd_dev_mode = pjsua_var.snd_mode; 
     1970    pj_bool_t no_change = (pjsua_var.snd_is_on || (!pjsua_var.snd_is_on && 
     1971                           (snd_param->mode &  
     1972                            PJSUA_SND_DEV_NO_IMMEDIATE_OPEN))); 
    19341973 
    19351974    PJ_LOG(4,(THIS_FILE, "Set sound device: capture=%d, playback=%d", 
    1936               capture_dev, playback_dev)); 
     1975              snd_param->capture_dev, snd_param->playback_dev)); 
    19371976    pj_log_push_indent(); 
    19381977 
    19391978    PJSUA_LOCK(); 
    19401979 
    1941     if (pjsua_var.cap_dev == capture_dev && 
    1942         pjsua_var.play_dev == playback_dev && 
    1943         pjsua_var.snd_is_on && !pjsua_var.no_snd) 
     1980    if (pjsua_var.cap_dev == snd_param->capture_dev && 
     1981        pjsua_var.play_dev == snd_param->playback_dev && 
     1982        pjsua_var.snd_mode == snd_param->mode && 
     1983        !pjsua_var.no_snd && no_change) 
    19441984    { 
    19451985        PJ_LOG(4, (THIS_FILE, "No changes in capture and playback devices")); 
     
    19501990     
    19511991    /* Null-sound */ 
    1952     if (capture_dev==NULL_SND_DEV_ID && playback_dev==NULL_SND_DEV_ID) { 
     1992    if (snd_param->capture_dev == NULL_SND_DEV_ID &&  
     1993        snd_param->playback_dev == NULL_SND_DEV_ID)  
     1994    { 
    19531995        PJSUA_UNLOCK(); 
    19541996        status = pjsua_set_null_snd_dev(); 
    19551997        pj_log_pop_indent(); 
    19561998        return status; 
     1999    } 
     2000 
     2001    pjsua_var.snd_mode = snd_param->mode; 
     2002 
     2003    if (!pjsua_var.no_snd && 
     2004        (snd_param->mode & PJSUA_SND_DEV_NO_IMMEDIATE_OPEN)) 
     2005    { 
     2006        pjsua_var.cap_dev = snd_param->capture_dev; 
     2007        pjsua_var.play_dev = snd_param->playback_dev; 
     2008 
     2009        PJSUA_UNLOCK();  
     2010        pj_log_pop_indent(); 
     2011        return PJ_SUCCESS; 
    19572012    } 
    19582013 
     
    19832038        pjmedia_snd_port_param_default(&param); 
    19842039        param.ec_options = pjsua_var.media_cfg.ec_options; 
    1985         status = create_aud_param(&param.base, capture_dev, playback_dev, 
     2040        status = create_aud_param(&param.base, snd_param->capture_dev,  
     2041                                  snd_param->playback_dev,  
    19862042                                  alt_cr[i], pjsua_var.media_cfg.channel_count, 
    19872043                                  samples_per_frame, 16); 
     
    20092065 
    20102066on_error: 
     2067    pjsua_var.snd_mode = orig_snd_dev_mode; 
    20112068    PJSUA_UNLOCK(); 
    20122069    pj_log_pop_indent(); 
  • pjproject/trunk/pjsip/src/pjsua2/media.cpp

    r5170 r5273  
    680680 
    681681void AudDevManager::setCaptureDev(int capture_dev) const throw(Error) 
    682 { 
    683     int playback_dev = getPlaybackDev(); 
    684  
    685     PJSUA2_CHECK_EXPR( pjsua_set_snd_dev(capture_dev, playback_dev) ); 
     682{     
     683    pjsua_snd_dev_param param; 
     684    pjsua_snd_dev_param_default(&param);     
     685 
     686    param.capture_dev = capture_dev; 
     687    param.playback_dev = getPlaybackDev();     
     688 
     689    param.mode = PJSUA_SND_DEV_NO_IMMEDIATE_OPEN;     
     690 
     691    PJSUA2_CHECK_EXPR( pjsua_set_snd_dev2(&param) ); 
    686692} 
    687693 
    688694void AudDevManager::setPlaybackDev(int playback_dev) const throw(Error) 
    689695{ 
    690     int capture_dev = getCaptureDev(); 
    691  
    692     PJSUA2_CHECK_EXPR( pjsua_set_snd_dev(capture_dev, playback_dev) ); 
     696    pjsua_snd_dev_param param; 
     697    pjsua_snd_dev_param_default(&param);     
     698 
     699    param.capture_dev = getCaptureDev(); 
     700    param.playback_dev = playback_dev; 
     701 
     702    param.mode = PJSUA_SND_DEV_NO_IMMEDIATE_OPEN;     
     703 
     704    PJSUA2_CHECK_EXPR( pjsua_set_snd_dev2(&param) );     
    693705} 
    694706 
     
    719731{ 
    720732    return (MediaPort*)pjsua_set_no_snd_dev(); 
     733} 
     734 
     735void AudDevManager::setSndDevMode(unsigned mode) const throw(Error) 
     736{     
     737    int capture_dev = 0, playback_dev = 0; 
     738    pjsua_snd_dev_param param; 
     739    pj_status_t status = pjsua_get_snd_dev(&capture_dev, &playback_dev);     
     740    if (status != PJ_SUCCESS) { 
     741        PJSUA2_RAISE_ERROR2(status, "AudDevManager::setSndDevMode()");   
     742    } 
     743    pjsua_snd_dev_param_default(&param); 
     744    param.capture_dev = capture_dev; 
     745    param.playback_dev = playback_dev; 
     746    param.mode = mode; 
     747    PJSUA2_CHECK_EXPR( pjsua_set_snd_dev2(&param) ); 
    721748} 
    722749 
Note: See TracChangeset for help on using the changeset viewer.