Ignore:
Timestamp:
Jun 1, 2006 12:28:44 PM (18 years ago)
Author:
bennylp
Message:

Initial work on pjsua ActiveX component

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r482 r487  
    5252 
    5353    cfg->thread_cnt = 1; 
     54    cfg->media_has_ioqueue = 1; 
     55    cfg->media_thread_cnt = 1; 
    5456    cfg->udp_port = 5060; 
    5557    cfg->start_rtp_port = 4000; 
     
    247249} 
    248250 
     251/** 
     252 * Poll pjsua. 
     253 */ 
     254PJ_DECL(int) pjsua_handle_events(unsigned msec_timeout) 
     255{ 
     256    unsigned count = 0; 
     257    pj_time_val tv; 
     258    pj_status_t status; 
     259 
     260    tv.sec = 0; 
     261    tv.msec = msec_timeout; 
     262    pj_time_val_normalize(&tv); 
     263 
     264    status = pjsip_endpt_handle_events2(pjsua.endpt, &tv, &count); 
     265    if (status != PJ_SUCCESS) 
     266        return -status; 
     267 
     268    return count; 
     269} 
    249270 
    250271 
     
    505526    /* Must create media endpoint too */ 
    506527    status = pjmedia_endpt_create(&pjsua.cp.factory,  
    507                                   pjsip_endpt_get_ioqueue(pjsua.endpt), 0, 
     528                                  pjsua.config.media_has_ioqueue? NULL : 
     529                                       pjsip_endpt_get_ioqueue(pjsua.endpt),  
     530                                  pjsua.config.media_thread_cnt, 
    508531                                  &pjsua.med_endpt); 
    509532    if (status != PJ_SUCCESS) { 
     
    755778 
    756779 
     780/***************************************************************************** 
     781 * Console application custom logging: 
     782 */ 
     783 
     784 
     785static void log_writer(int level, const char *buffer, int len) 
     786{ 
     787    /* Write to both stdout and file. */ 
     788 
     789    if (level <= (int)pjsua.config.app_log_level) 
     790        pj_log_write(level, buffer, len); 
     791 
     792    if (pjsua.log_file) { 
     793        fwrite(buffer, len, 1, pjsua.log_file); 
     794        fflush(pjsua.log_file); 
     795    } 
     796} 
     797 
     798 
     799static pj_status_t logging_init() 
     800{ 
     801    /* Redirect log function to ours */ 
     802 
     803    pj_log_set_log_func( &log_writer ); 
     804 
     805    /* If output log file is desired, create the file: */ 
     806 
     807    if (pjsua.config.log_filename.slen) { 
     808        pjsua.log_file = fopen(pjsua.config.log_filename.ptr, "wt"); 
     809        if (pjsua.log_file == NULL) { 
     810            PJ_LOG(1,(THIS_FILE, "Unable to open log file %s",  
     811                      pjsua.config.log_filename.ptr));    
     812            return -1; 
     813        } 
     814    } 
     815 
     816    return PJ_SUCCESS; 
     817} 
     818 
     819 
     820static void logging_shutdown(void) 
     821{ 
     822    /* Close logging file, if any: */ 
     823 
     824    if (pjsua.log_file) { 
     825        fclose(pjsua.log_file); 
     826        pjsua.log_file = NULL; 
     827    } 
     828} 
     829 
     830 
    757831/* 
    758832 * Initialize pjsua application. 
     
    807881    pj_log_set_level(pjsua.config.log_level); 
    808882    pj_log_set_decor(pjsua.config.log_decor); 
     883 
     884    status = logging_init(); 
     885    if (status != PJ_SUCCESS) 
     886        goto on_error; 
    809887 
    810888 
     
    854932        } 
    855933        status = pjmedia_transport_udp_attach(pjsua.med_endpt, NULL, 
    856                                               &pjsua.calls[i].skinfo, 
     934                                              &pjsua.calls[i].skinfo, 0, 
    857935                                              &pjsua.calls[i].med_tp); 
    858936    } 
     
    13691447 * Get conference port associated with player. 
    13701448 */ 
    1371 PJ_DEF(unsigned) pjsua_player_get_conf_port(pjsua_player_id id) 
     1449PJ_DEF(int) pjsua_player_get_conf_port(pjsua_player_id id) 
    13721450{ 
    13731451    PJ_ASSERT_RETURN(id>=0 && id < PJ_ARRAY_SIZE(pjsua.player), PJ_EINVAL); 
     
    14531531 * Get conference port associated with recorder. 
    14541532 */ 
    1455 PJ_DEF(unsigned) pjsua_recorder_get_conf_port(pjsua_recorder_id id) 
     1533PJ_DEF(int) pjsua_recorder_get_conf_port(pjsua_recorder_id id) 
    14561534{ 
    14571535    PJ_ASSERT_RETURN(id>=0 && id < PJ_ARRAY_SIZE(pjsua.recorder), PJ_EINVAL); 
     
    15211599    /* Signal threads to quit: */ 
    15221600    pjsua.quit_flag = 1; 
    1523  
    1524     /* Terminate all calls. */ 
    1525     pjsua_call_hangup_all(); 
    1526  
    1527     /* Terminate all presence subscriptions. */ 
    1528     pjsua_pres_shutdown(); 
    1529  
    1530     /* Unregister, if required: */ 
    1531     for (i=0; i<(int)pjsua.config.acc_cnt; ++i) { 
    1532         if (pjsua.acc[i].regc) { 
    1533             pjsua_acc_set_registration(i, PJ_FALSE); 
    1534         } 
    1535     } 
    15361601 
    15371602    /* Wait worker threads to quit: */ 
     
    15451610    } 
    15461611 
    1547  
    1548     /* Wait for some time to allow unregistration to complete: */ 
     1612     
    15491613    if (pjsua.endpt) { 
     1614        /* Terminate all calls. */ 
     1615        pjsua_call_hangup_all(); 
     1616 
     1617        /* Terminate all presence subscriptions. */ 
     1618        pjsua_pres_shutdown(); 
     1619 
     1620        /* Unregister, if required: */ 
     1621        for (i=0; i<(int)pjsua.config.acc_cnt; ++i) { 
     1622            if (pjsua.acc[i].regc) { 
     1623                pjsua_acc_set_registration(i, PJ_FALSE); 
     1624            } 
     1625        } 
     1626 
     1627        /* Wait for some time to allow unregistration to complete: */ 
    15501628        PJ_LOG(4,(THIS_FILE, "Shutting down...")); 
    15511629        busy_sleep(1000); 
     
    16301708 
    16311709 
     1710    PJ_LOG(4,(THIS_FILE, "PJSUA destroyed...")); 
     1711 
     1712    /* End logging */ 
     1713    logging_shutdown(); 
     1714 
    16321715    /* Done. */ 
    16331716 
Note: See TracChangeset for help on using the changeset viewer.