Ignore:
Timestamp:
Feb 5, 2009 10:59:14 AM (15 years ago)
Author:
nanang
Message:
  • Added new API for sound & sound port to create/open sound device with extended setting, to allow opening sound device with non-PCM format and other settings.
  • Updated symbian_ua/ua.cpp to be able to reopen sound device when audio stream session is using non-PCM data/passthrough codec.
  • Updated stream.c to allow it works with non-PCM data.
  • Added PCMU/A frames processing into non-PCM play/record callbacks in symbian_audio_aps.cpp.
  • Added passthrough codec init/deinitialization in pjsua-lib.
  • Added a new pjmedia_frame_ext helper function, pjmedia_frame_ext_pop_subframes, to pop-out/remove some subframes.
  • Other minor updates/fixes.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/aps-direct/pjsip-apps/src/symbian_ua/ua.cpp

    r2394 r2438  
    9191static pjsua_buddy_id g_buddy_id = PJSUA_INVALID_ID; 
    9292 
     93static pj_pool_t *app_pool; 
     94static pjmedia_snd_port *snd_port; 
     95 
    9396 
    9497/* Callback called by the library upon receiving incoming call */ 
     
    130133        if (call_id == g_call_id) 
    131134            g_call_id = PJSUA_INVALID_ID; 
     135        if (snd_port) { 
     136            pjmedia_snd_port_destroy(snd_port); 
     137            snd_port = NULL; 
     138        } 
    132139    } else if (ci.state != PJSIP_INV_STATE_INCOMING) { 
    133140        if (g_call_id == PJSUA_INVALID_ID) 
     
    250257} 
    251258 
     259/* Notification that stream is created. */ 
     260static void on_stream_created(pjsua_call_id call_id,  
     261                              pjmedia_session *sess, 
     262                              unsigned stream_idx,  
     263                              pjmedia_port **p_port) 
     264{ 
     265    pjmedia_port *conf; 
     266    pjmedia_session_info sess_info; 
     267    pjmedia_stream_info *strm_info; 
     268    pjmedia_snd_setting setting; 
     269    unsigned samples_per_frame; 
     270    pj_status_t status; 
     271     
     272    status = pjmedia_session_get_info(sess, &sess_info); 
     273    if (status != PJ_SUCCESS) { 
     274        PJ_LOG(1,(THIS_FILE, "on_stream_created() failed to get session info, " 
     275                             "status=%d", status)); 
     276        return; 
     277    } 
     278     
     279    strm_info = &sess_info.stream_info[stream_idx]; 
     280    if (strm_info->type != PJMEDIA_TYPE_AUDIO) 
     281        return; 
     282 
     283    /* Don't need to reopen sound device when the session doesn't use 
     284     * PCM format.  
     285     */ 
     286    if (strm_info->param->info.format.u32 == 0 || 
     287        strm_info->param->info.format.u32 == PJMEDIA_FOURCC_L16)  
     288    { 
     289        return; 
     290    } 
     291     
     292    pj_bzero(&setting, sizeof(setting)); 
     293    setting.format = strm_info->param->info.format; 
     294    setting.bitrate = strm_info->param->info.avg_bps; 
     295    setting.cng = strm_info->param->setting.cng; 
     296    setting.vad = strm_info->param->setting.vad; 
     297    setting.plc = strm_info->param->setting.plc; 
     298 
     299    /* Reopen sound device. */ 
     300    conf = pjsua_set_no_snd_dev(); 
     301 
     302    samples_per_frame = conf->info.samples_per_frame; 
     303     
     304    status = pjmedia_snd_port_create2(app_pool,  
     305                                      PJMEDIA_DIR_CAPTURE_PLAYBACK, 
     306                                      0, 
     307                                      0, 
     308                                      8000, 
     309                                      1, 
     310                                      samples_per_frame, 
     311                                      16, 
     312                                      &setting, 
     313                                      &snd_port); 
     314    if (status != PJ_SUCCESS) { 
     315        PJ_LOG(1,(THIS_FILE, "on_stream_created() failed to reopen sound " 
     316                             "device, status=%d", status)); 
     317        return; 
     318    } 
     319     
     320    status = pjmedia_snd_port_connect(snd_port, conf); 
     321    if (status != PJ_SUCCESS) { 
     322        PJ_LOG(1,(THIS_FILE, "on_stream_created() failed to connect sound " 
     323                             "device to conference, status=%d", status)); 
     324        return; 
     325    } 
     326} 
    252327 
    253328//#include<e32debug.h> 
     
    290365    } 
    291366 
     367    /* Create pool for application */ 
     368    app_pool = pjsua_pool_create("pjsua-app", 1000, 1000); 
     369     
    292370    /* Init pjsua */ 
    293371    pjsua_config cfg; 
     
    310388    cfg.cb.on_call_replaced = &on_call_replaced; 
    311389    cfg.cb.on_nat_detect = &on_nat_detect; 
     390    cfg.cb.on_stream_created = &on_stream_created; 
    312391     
    313392    if (SIP_PROXY) { 
     
    338417    med_cfg.has_ioqueue = PJ_FALSE; 
    339418    med_cfg.clock_rate = 8000; 
    340 #if defined(PJMEDIA_SYM_SND_USE_APS) && (PJMEDIA_SYM_SND_USE_APS==1) 
    341     med_cfg.audio_frame_ptime = 20; 
    342 #else 
    343419    med_cfg.audio_frame_ptime = 40; 
    344 #endif 
    345420    med_cfg.ec_tail_len = 0; 
    346421    med_cfg.enable_ice = USE_ICE; 
    347     med_cfg.snd_auto_close_time = 5; // wait for 5 seconds idle before sound dev get auto-closed 
     422    med_cfg.snd_auto_close_time = 0; // wait for 0 seconds idle before sound dev get auto-closed 
    348423     
    349424    status = pjsua_init(&cfg, &log_cfg, &med_cfg); 
     
    803878#endif 
    804879         
     880    // Let pjsua destroys app pool, since the pool may still be used by app 
     881    // until pjsua_destroy() finished. 
     882    // e.g: quitting app when there is an active call may cause sound port  
     883    // memory destroyed before sound port itself gets closed/destroyed. 
     884    /* 
     885    // Release application pool 
     886    if (app_pool) { 
     887        pj_pool_release(app_pool); 
     888        app_pool = NULL; 
     889    } 
     890    */ 
     891     
    805892    // Shutdown pjsua 
    806893    pjsua_destroy(); 
Note: See TracChangeset for help on using the changeset viewer.