Ignore:
Timestamp:
Feb 13, 2009 11:53:12 AM (15 years ago)
Author:
bennylp
Message:

Added APS-Direct emulation to sound port and pjsua_app.c, also fixed miscellaneous compilation warnings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/aps-direct/pjsip-apps/src/pjsua/pjsua_app.c

    r2408 r2452  
    24022402} 
    24032403 
     2404#ifdef PJSUA_SIMULATE_APS_DIRECT 
     2405/* To simulate APS direct, add these to config_site.h: 
     2406#define PJSUA_SIMULATE_APS_DIRECT 
     2407#ifdef PJSUA_SIMULATE_APS_DIRECT 
     2408    #define PJMEDIA_CONF_USE_SWITCH_BOARD       1 
     2409    #define PJMEDIA_HAS_PASSTHROUGH_CODECS      1 
     2410 
     2411    #define PJMEDIA_HAS_L16_CODEC               0 
     2412    #define PJMEDIA_HAS_GSM_CODEC               0 
     2413    #define PJMEDIA_HAS_SPEEX_CODEC             0 
     2414    #define PJMEDIA_HAS_ILBC_CODEC              0 
     2415    #define PJMEDIA_HAS_G722_CODEC              0 
     2416    #define PJMEDIA_HAS_INTEL_IPP               0 
     2417 
     2418    #define PJMEDIA_HAS_PASSTHROUGH_CODEC_AMR   0 
     2419    #define PJMEDIA_HAS_PASSTHROUGH_CODEC_G729  0 
     2420    #define PJMEDIA_HAS_PASSTHROUGH_CODEC_ILBC  0 
     2421#endif 
     2422*/ 
     2423 
     2424/* Global sound port. */ 
     2425static pjmedia_snd_port *g_snd_port; 
     2426 
     2427 
     2428/* Reopen sound device on on_stream_created() pjsua callback. */ 
     2429static void on_call_stream_created(pjsua_call_id call_id,  
     2430                                   pjmedia_session *sess, 
     2431                                   unsigned stream_idx,  
     2432                                   pjmedia_port **p_port) 
     2433{ 
     2434    pjmedia_port *conf; 
     2435    pjmedia_session_info sess_info; 
     2436    pjmedia_stream_info *strm_info; 
     2437    pjmedia_snd_setting setting; 
     2438    unsigned samples_per_frame; 
     2439    pj_status_t status; 
     2440 
     2441    PJ_UNUSED_ARG(call_id); 
     2442    PJ_UNUSED_ARG(p_port); 
     2443 
     2444    /* Get active format for this stream, based on SDP negotiation result. */     
     2445    pjmedia_session_get_info(sess, &sess_info); 
     2446    strm_info = &sess_info.stream_info[stream_idx]; 
     2447 
     2448    /* Init sound device setting based on stream info. */ 
     2449    pj_bzero(&setting, sizeof(setting)); 
     2450    setting.format = strm_info->param->info.format; 
     2451    setting.bitrate = strm_info->param->info.avg_bps; 
     2452    setting.cng = strm_info->param->setting.cng; 
     2453    setting.vad = strm_info->param->setting.vad; 
     2454    setting.plc = strm_info->param->setting.plc; 
     2455 
     2456    /* Close sound device and get the conference port. */ 
     2457    conf = pjsua_set_no_snd_dev(); 
     2458     
     2459    samples_per_frame = strm_info->param->info.clock_rate * 
     2460                        strm_info->param->info.frm_ptime * 
     2461                        strm_info->param->setting.frm_per_pkt * 
     2462                        strm_info->param->info.channel_cnt / 
     2463                        1000; 
     2464 
     2465    /* Reset conference port attributes. */ 
     2466    conf->info.samples_per_frame = samples_per_frame; 
     2467    conf->info.clock_rate = 8000; 
     2468    conf->info.channel_count = 1; 
     2469    conf->info.bits_per_sample = 16; 
     2470 
     2471    /* Reopen sound device. */ 
     2472    status = pjmedia_snd_port_create2(app_config.pool,  
     2473                                      PJMEDIA_DIR_CAPTURE_PLAYBACK, 
     2474                                      -1, 
     2475                                      -1, 
     2476                                      8000, 
     2477                                      1, 
     2478                                      samples_per_frame, 
     2479                                      16, 
     2480                                      &setting, 
     2481                                      &g_snd_port); 
     2482    if (status != PJ_SUCCESS) { 
     2483        pjsua_perror(THIS_FILE, "Error opening sound device", status); 
     2484        return; 
     2485    } 
     2486 
     2487    /* Connect sound to conference port. */ 
     2488    pjmedia_snd_port_connect(g_snd_port, conf); 
     2489} 
     2490 
     2491static void on_call_stream_destroyed(pjsua_call_id call_id, 
     2492                                     pjmedia_session *sess,  
     2493                                     unsigned stream_idx) 
     2494{ 
     2495    PJ_UNUSED_ARG(call_id); 
     2496    PJ_UNUSED_ARG(sess); 
     2497    PJ_UNUSED_ARG(stream_idx); 
     2498 
     2499    if (g_snd_port) { 
     2500        pjmedia_snd_port_destroy(g_snd_port); 
     2501        g_snd_port = NULL; 
     2502    } 
     2503} 
     2504 
     2505#endif 
     2506 
    24042507/* 
    24052508 * DTMF callback. 
     
    40474150    app_config.cfg.cb.on_call_state = &on_call_state; 
    40484151    app_config.cfg.cb.on_call_media_state = &on_call_media_state; 
     4152#ifdef PJSUA_SIMULATE_APS_DIRECT 
     4153    app_config.cfg.cb.on_stream_created = &on_call_stream_created; 
     4154    app_config.cfg.cb.on_stream_destroyed = &on_call_stream_destroyed; 
     4155#endif 
    40494156    app_config.cfg.cb.on_incoming_call = &on_incoming_call; 
    40504157    app_config.cfg.cb.on_call_tsx_state = &on_call_tsx_state; 
Note: See TracChangeset for help on using the changeset viewer.