Ignore:
Timestamp:
Feb 18, 2009 2:28:49 PM (15 years ago)
Author:
nanang
Message:
  • Added APS-direct sound device management into pjsua-lib (and removed it from apps).
  • Fixed bug in conf_switch.c to always update ts_rx (even if port is not transmitting).
  • Minor updates: 'fmt_id' to 'id', added transmitter_Cnt in conf port info, explicit mapping in Symbian audio APS impl from pjmedia_format_id to Symbian APS fourcc.
File:
1 edited

Legend:

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

    r2456 r2460  
    9292static pjsua_buddy_id g_buddy_id = PJSUA_INVALID_ID; 
    9393 
    94 static pj_pool_t *app_pool; 
    95 static pjmedia_snd_port *g_snd_port; 
    96  
    9794 
    9895/* Callback called by the library upon receiving incoming call */ 
     
    254251} 
    255252 
    256 /* Notification that stream is created. */ 
    257 static void on_stream_created(pjsua_call_id call_id,  
    258                               pjmedia_session *sess, 
    259                               unsigned stream_idx,  
    260                               pjmedia_port **p_port) 
    261 { 
    262     pjmedia_port *conf; 
    263     pjmedia_session_info sess_info; 
    264     pjmedia_stream_info *strm_info; 
    265     pjmedia_snd_setting setting; 
    266     unsigned samples_per_frame; 
    267     pj_status_t status; 
    268      
    269     PJ_UNUSED_ARG(call_id); 
    270     PJ_UNUSED_ARG(p_port); 
    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     /* Init sound device setting based on stream info. */ 
    284     pj_bzero(&setting, sizeof(setting)); 
    285     setting.format = strm_info->param->info.format; 
    286     setting.bitrate = strm_info->param->info.avg_bps; 
    287     setting.cng = strm_info->param->setting.cng; 
    288     setting.vad = strm_info->param->setting.vad; 
    289     setting.plc = strm_info->param->setting.plc; 
    290     if (setting.format.u32 == PJMEDIA_FORMAT_ILBC) { 
    291         unsigned i; 
    292         pjmedia_codec_fmtp *fmtp = &strm_info->param->setting.dec_fmtp; 
    293          
    294         /* Initialize mode. */ 
    295         setting.mode = 30; 
    296          
    297         /* Get mode. */ 
    298         for (i = 0; i < fmtp->cnt; ++i) { 
    299             if (pj_stricmp2(&fmtp->param[i].name, "mode") == 0) { 
    300                 setting.mode = (pj_uint32_t) pj_strtoul(&fmtp->param[i].val); 
    301                 break; 
    302             } 
    303         } 
    304     } 
    305  
    306     samples_per_frame = strm_info->param->info.clock_rate * 
    307                         strm_info->param->info.frm_ptime * 
    308                         strm_info->param->info.channel_cnt / 
    309                         1000; 
    310      
    311     /* Close sound device. */ 
    312     conf = pjsua_set_no_snd_dev(); 
    313      
    314     /* Reset conference attributes. */ 
    315     conf->info.samples_per_frame = samples_per_frame; 
    316     conf->info.clock_rate = strm_info->param->info.clock_rate; 
    317     conf->info.channel_count = strm_info->param->info.channel_cnt; 
    318     conf->info.bits_per_sample = 16; 
    319     conf->info.format = strm_info->param->info.format; 
    320  
    321     /* Reopen sound device. */ 
    322     status = pjmedia_snd_port_create2(app_pool,  
    323                                       PJMEDIA_DIR_CAPTURE_PLAYBACK, 
    324                                       0, 
    325                                       0, 
    326                                       strm_info->param->info.clock_rate, 
    327                                       strm_info->param->info.channel_cnt, 
    328                                       samples_per_frame, 
    329                                       16, 
    330                                       &setting, 
    331                                       &g_snd_port); 
    332     if (status != PJ_SUCCESS) { 
    333         PJ_LOG(1,(THIS_FILE, "on_stream_created() failed to reopen sound " 
    334                              "device, status=%d", status)); 
    335         return; 
    336     } 
    337      
    338     status = pjmedia_snd_port_connect(g_snd_port, conf); 
    339     if (status != PJ_SUCCESS) { 
    340         PJ_LOG(1,(THIS_FILE, "on_stream_created() failed to connect sound " 
    341                              "device to conference, status=%d", status)); 
    342         return; 
    343     } 
    344 } 
    345  
    346 static void on_stream_destroyed(pjsua_call_id call_id, 
    347                                 pjmedia_session *sess,  
    348                                 unsigned stream_idx) 
    349 { 
    350     PJ_UNUSED_ARG(call_id); 
    351     PJ_UNUSED_ARG(sess); 
    352     PJ_UNUSED_ARG(stream_idx); 
    353  
    354     if (g_snd_port) { 
    355         pjmedia_snd_port_destroy(g_snd_port); 
    356         g_snd_port = NULL; 
    357     } 
    358 } 
    359253 
    360254//#include<e32debug.h> 
     
    397291    } 
    398292 
    399     /* Create pool for application */ 
    400     app_pool = pjsua_pool_create("pjsua-app", 1000, 1000); 
    401      
    402293    /* Init pjsua */ 
    403294    pjsua_config cfg; 
     
    420311    cfg.cb.on_call_replaced = &on_call_replaced; 
    421312    cfg.cb.on_nat_detect = &on_nat_detect; 
    422     cfg.cb.on_stream_created = &on_stream_created; 
    423     cfg.cb.on_stream_destroyed = &on_stream_destroyed; 
    424313     
    425314    if (SIP_PROXY) { 
     
    636525#   if PJMEDIA_SOUND_IMPLEMENTATION == PJMEDIA_SOUND_SYMB_APS_SOUND 
    637526    case 't': 
    638         if (g_snd_port) { 
    639             static pj_bool_t act_loudspk = PJ_TRUE; 
    640             pjmedia_snd_stream *strm; 
     527        do { 
     528            static pjmedia_snd_route route = PJMEDIA_SND_ROUTE_LOUDSPEAKER; 
    641529             
    642             strm = pjmedia_snd_port_get_snd_stream(g_snd_port); 
    643             pjmedia_snd_aps_activate_loudspeaker(strm, act_loudspk); 
    644             act_loudspk = !act_loudspk; 
    645         } else { 
    646             PJ_LOG(3,(THIS_FILE, "Sound device is not active.")); 
    647         } 
     530            pjsua_set_snd_route(route); 
     531             
     532            if (route == PJMEDIA_SND_ROUTE_LOUDSPEAKER) 
     533                route = PJMEDIA_SND_ROUTE_EARPIECE; 
     534            else 
     535                route = PJMEDIA_SND_ROUTE_LOUDSPEAKER; 
     536                 
     537        } while(0); 
    648538        break; 
    649539#   endif 
     
    1013903#endif 
    1014904         
    1015     if (g_snd_port) { 
    1016         pjmedia_snd_port_destroy(g_snd_port); 
    1017         g_snd_port = NULL; 
    1018     } 
    1019  
    1020     // Release application pool 
    1021     if (app_pool) { 
    1022         pj_pool_release(app_pool); 
    1023         app_pool = NULL; 
    1024     } 
    1025      
    1026905    // Shutdown pjsua 
    1027906    pjsua_destroy(); 
Note: See TracChangeset for help on using the changeset viewer.