diff options
-rw-r--r-- | pjlib/src/pj/config.c | 2 | ||||
-rw-r--r-- | pjsip-apps/src/pjsua/main.c | 6 | ||||
-rw-r--r-- | pjsip/include/pjsua-lib/pjsua.h | 3 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_call.c | 20 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_core.c | 245 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_settings.c | 130 |
6 files changed, 186 insertions, 220 deletions
diff --git a/pjlib/src/pj/config.c b/pjlib/src/pj/config.c index 4e77c4b3..7d89f1cc 100644 --- a/pjlib/src/pj/config.c +++ b/pjlib/src/pj/config.c @@ -21,7 +21,7 @@ #include <pj/ioqueue.h> static const char *id = "config.c"; -const char *PJ_VERSION = "0.5.4.12"; +const char *PJ_VERSION = "0.5.4.13"; PJ_DEF(void) pj_dump_config(void) { diff --git a/pjsip-apps/src/pjsua/main.c b/pjsip-apps/src/pjsua/main.c index 3c7e2fdd..97da6f34 100644 --- a/pjsip-apps/src/pjsua/main.c +++ b/pjsip-apps/src/pjsua/main.c @@ -413,6 +413,12 @@ static void ui_console_main(void) char *uri; struct input_result result; + + /* If user specifies URI to call, then call the URI */ + if (pjsua.uri_to_call.slen) { + pjsua_make_call( current_acc, pjsua.uri_to_call.ptr, NULL); + } + keystroke_help(); for (;;) { diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h index dc179cb3..726f8f0c 100644 --- a/pjsip/include/pjsua-lib/pjsua.h +++ b/pjsip/include/pjsua-lib/pjsua.h @@ -183,8 +183,6 @@ struct pjsua int start_rtp_port;/**< Start of RTP port to try. */ pjmedia_endpt *med_endpt; /**< Media endpoint. */ unsigned clock_rate; /**< Internal clock rate. */ - pj_bool_t has_wb; /**< Include wideband codecs */ - pj_bool_t has_uwb; /**< Include ultra-wideband codecs */ pjmedia_conf *mconf; /**< Media conference. */ pj_bool_t null_audio; /**< Null audio flag. */ pj_bool_t no_mic; /**< Disable microphone. */ @@ -249,6 +247,7 @@ struct pjsua /* PJSUA Calls: */ + pj_str_t uri_to_call; /**< URI to call. */ int max_calls; /**< Max nb of calls. */ int call_cnt; /**< Number of calls. */ pjsua_call calls[PJSUA_MAX_CALLS]; /** Calls array. */ diff --git a/pjsip/src/pjsua-lib/pjsua_call.c b/pjsip/src/pjsua-lib/pjsua_call.c index b5e32780..b8fff57f 100644 --- a/pjsip/src/pjsua-lib/pjsua_call.c +++ b/pjsip/src/pjsua-lib/pjsua_call.c @@ -1047,13 +1047,14 @@ static void pjsua_call_on_media_update(pjsip_inv_session *inv, pjmedia_conf_connect_port( pjsua.mconf, pjsua.wav_slot, call->conf_slot, 0); - } else if (pjsua.auto_loop && call->inv->role == PJSIP_ROLE_UAS) { + } + if (pjsua.auto_loop && call->inv->role == PJSIP_ROLE_UAS) { pjmedia_conf_connect_port( pjsua.mconf, call->conf_slot, call->conf_slot, 0); - } else if (pjsua.auto_conf) { - + } + if (pjsua.auto_conf) { int i; pjmedia_conf_connect_port( pjsua.mconf, 0, call->conf_slot, 0); @@ -1070,11 +1071,14 @@ static void pjsua_call_on_media_update(pjsip_inv_session *inv, call->conf_slot, 0); } - } else { - - /* Connect new call to the sound device port (port zero) in the - * main conference bridge. - */ + } + + /* Normal operation: if no auto_xx is given, connect new call to + * the sound device port (port zero) in the main conference bridge. + */ + if (pjsua.auto_play == 0 && pjsua.auto_loop == 0 && + pjsua.auto_conf == 0) + { pjmedia_conf_connect_port( pjsua.mconf, 0, call->conf_slot, 0); pjmedia_conf_connect_port( pjsua.mconf, call->conf_slot, 0, 0); } diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c index 0bfb062c..034262ab 100644 --- a/pjsip/src/pjsua-lib/pjsua_core.c +++ b/pjsip/src/pjsua-lib/pjsua_core.c @@ -79,13 +79,9 @@ void pjsua_default(void) /* Default for media: */ #if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 pjsua.clock_rate = 44100; -#else - pjsua.clock_rate = 8000; #endif pjsua.complexity = -1; pjsua.quality = 4; - pjsua.has_wb = 0; - pjsua.has_uwb = 0; /* Init accounts: */ @@ -620,189 +616,108 @@ int pjsua_find_account_for_outgoing(const pj_str_t *url) */ static pj_status_t init_media(void) { + int i; unsigned options; + unsigned clock_rate; + unsigned samples_per_frame; + pj_str_t codec_id; pj_status_t status; - /* If user doesn't specify any codecs, register all of them. */ - if (pjsua.codec_cnt == 0) { - + /* Register all codecs */ #if PJMEDIA_HAS_SPEEX_CODEC - unsigned option = PJMEDIA_SPEEX_NO_WB | PJMEDIA_SPEEX_NO_UWB; - - /* Register speex. */ - if (pjsua.has_wb) - option &= ~PJMEDIA_SPEEX_NO_WB; - if (pjsua.has_uwb) - option &= ~PJMEDIA_SPEEX_NO_UWB; + /* Register speex. */ + status = pjmedia_codec_speex_init(pjsua.med_endpt, + PJMEDIA_SPEEX_NO_UWB, + pjsua.quality, pjsua.complexity ); + if (status != PJ_SUCCESS) { + pjsua_perror(THIS_FILE, "Error initializing Speex codec", + status); + return status; + } - status = pjmedia_codec_speex_init(pjsua.med_endpt, option, - pjsua.quality, pjsua.complexity ); - if (status != PJ_SUCCESS) { - pjsua_perror(THIS_FILE, "Error initializing Speex codec", - status); - return status; - } + /* Set "speex/16000/1" to have highest priority */ + codec_id = pj_str("speex/16000/1"); + pjmedia_codec_mgr_set_codec_priority( + pjmedia_endpt_get_codec_mgr(pjsua.med_endpt), + &codec_id, + PJMEDIA_CODEC_PRIO_HIGHEST); - pjsua.codec_arg[pjsua.codec_cnt] = pj_str("speex"); - pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_speex_deinit; - pjsua.codec_cnt++; #endif /* PJMEDIA_HAS_SPEEX_CODEC */ #if PJMEDIA_HAS_GSM_CODEC - /* Register GSM */ - status = pjmedia_codec_gsm_init(pjsua.med_endpt); - if (status != PJ_SUCCESS) { - pjsua_perror(THIS_FILE, "Error initializing GSM codec", - status); - return status; - } - - pjsua.codec_arg[pjsua.codec_cnt] = pj_str("gsm"); - pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_gsm_deinit; - pjsua.codec_cnt++; + /* Register GSM */ + status = pjmedia_codec_gsm_init(pjsua.med_endpt); + if (status != PJ_SUCCESS) { + pjsua_perror(THIS_FILE, "Error initializing GSM codec", + status); + return status; + } #endif /* PJMEDIA_HAS_GSM_CODEC */ -#if PJMEDIA_HAS_L16_CODEC - /* Register L16 */ - status = pjmedia_codec_l16_init(pjsua.med_endpt, 0); - if (status != PJ_SUCCESS) { - pjsua_perror(THIS_FILE, "Error initializing L16 codec", - status); - return status; - } - - pjsua.codec_arg[pjsua.codec_cnt] = pj_str("l16"); - pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_l16_deinit; - pjsua.codec_cnt++; -#endif /* PJMEDIA_HAS_L16_CODEC */ - - #if PJMEDIA_HAS_G711_CODEC - /* Register PCMA and PCMU */ - status = pjmedia_codec_g711_init(pjsua.med_endpt); - if (status != PJ_SUCCESS) { - pjsua_perror(THIS_FILE, "Error initializing G711 codec", - status); - return status; - } - - pjsua.codec_arg[pjsua.codec_cnt] = pj_str("pcmu"); - pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_g711_deinit; - pjsua.codec_cnt++; - pjsua.codec_arg[pjsua.codec_cnt] = pj_str("pcma"); - pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_g711_deinit; - pjsua.codec_cnt++; + /* Register PCMA and PCMU */ + status = pjmedia_codec_g711_init(pjsua.med_endpt); + if (status != PJ_SUCCESS) { + pjsua_perror(THIS_FILE, "Error initializing G711 codec", + status); + return status; + } #endif /* PJMEDIA_HAS_G711_CODEC */ - } else { - - /* If user specifies the exact codec to be used, then create only - * those codecs. - */ - int i; - - for (i=0; i<pjsua.codec_cnt; ++i) { - - if (0) { - /* Dummy */ - } -#if PJMEDIA_HAS_SPEEX_CODEC - /* Is it speex? */ - else if (!pj_stricmp2(&pjsua.codec_arg[i], "speex")) { - - unsigned option = PJMEDIA_SPEEX_NO_WB | PJMEDIA_SPEEX_NO_UWB; - - /* Register speex. */ - if (pjsua.has_wb) - option &= ~(PJMEDIA_SPEEX_NO_WB); - if (pjsua.has_uwb) - option &= ~(PJMEDIA_SPEEX_NO_UWB); - - status = pjmedia_codec_speex_init(pjsua.med_endpt, option, - -1, -1); - if (status != PJ_SUCCESS) { - pjsua_perror(THIS_FILE, "Error initializing Speex codec", - status); - return status; - } - - pjsua.codec_deinit[i] = &pjmedia_codec_speex_deinit; - } -#endif /* PJMEDIA_HAS_SPEEX_CODEC */ - -#if PJMEDIA_HAS_GSM_CODEC - /* Is it gsm? */ - else if (!pj_stricmp2(&pjsua.codec_arg[i], "gsm")) { - - status = pjmedia_codec_gsm_init(pjsua.med_endpt); - if (status != PJ_SUCCESS) { - pjsua_perror(THIS_FILE, "Error initializing GSM codec", - status); - return status; - } - - pjsua.codec_deinit[i] = &pjmedia_codec_gsm_deinit; - - } -#endif /* PJMEDIA_HAS_GSM_CODEC */ - #if PJMEDIA_HAS_L16_CODEC - /* Is it l16? */ - else if (!pj_stricmp2(&pjsua.codec_arg[i], "l16")) { - - status = pjmedia_codec_l16_init(pjsua.med_endpt, 0); - if (status != PJ_SUCCESS) { - pjsua_perror(THIS_FILE, "Error initializing L16 codec", - status); - return status; - } + /* Register L16 family codecs, but disable all */ + status = pjmedia_codec_l16_init(pjsua.med_endpt, 0); + if (status != PJ_SUCCESS) { + pjsua_perror(THIS_FILE, "Error initializing L16 codecs", + status); + return status; + } - pjsua.codec_deinit[i] = &pjmedia_codec_l16_deinit; + /* Disable ALL L16 codecs */ + codec_id = pj_str("L16"); + pjmedia_codec_mgr_set_codec_priority( + pjmedia_endpt_get_codec_mgr(pjsua.med_endpt), + &codec_id, + PJMEDIA_CODEC_PRIO_DISABLED); - pjsua.clock_rate = 44100; - } #endif /* PJMEDIA_HAS_L16_CODEC */ -#if PJMEDIA_HAS_G711_CODEC - /* Is it pcma/pcmu? */ - else if (!pj_stricmp2(&pjsua.codec_arg[i], "pcmu") || - !pj_stricmp2(&pjsua.codec_arg[i], "pcma")) - { - - status = pjmedia_codec_g711_init(pjsua.med_endpt); - if (status != PJ_SUCCESS) { - pjsua_perror(THIS_FILE, "Error initializing G711 codec", - status); - return status; - } - - pjsua.codec_deinit[i] = &pjmedia_codec_g711_deinit; - } -#endif /* PJMEDIA_HAS_G711_CODEC */ + /* If user specifies the exact codec to be used, then disable all codecs + * and only enable those specific codecs. + */ + if (pjsua.codec_cnt != 0) { + codec_id = pj_str(""); + pjmedia_codec_mgr_set_codec_priority( + pjmedia_endpt_get_codec_mgr(pjsua.med_endpt), + &codec_id, + PJMEDIA_CODEC_PRIO_DISABLED); + } - /* Don't know about this codec... */ - else { + - PJ_LOG(1,(THIS_FILE, "Error: unsupported codecs %s", - pjsua.codec_arg[i].ptr)); - return PJMEDIA_CODEC_EUNSUP; - } - } + for (i=0; i<pjsua.codec_cnt; ++i) { + pjmedia_codec_mgr_set_codec_priority( + pjmedia_endpt_get_codec_mgr(pjsua.med_endpt), + &pjsua.codec_arg[i], + PJMEDIA_CODEC_PRIO_NEXT_HIGHER); } + /* Init options for conference bridge. */ options = 0; if (pjsua.no_mic) options |= PJMEDIA_CONF_NO_MIC; /* Init conference bridge. */ - + clock_rate = pjsua.clock_rate ? pjsua.clock_rate : 16000; + samples_per_frame = clock_rate * 20 / 1000; status = pjmedia_conf_create(pjsua.pool, pjsua.max_calls+PJSUA_CONF_MORE_PORTS, - pjsua.clock_rate, + clock_rate, 1, /* mono */ - pjsua.clock_rate * 20 / 1000, 16, + samples_per_frame, + 16, options, &pjsua.mconf); if (status != PJ_SUCCESS) { @@ -813,9 +728,9 @@ static pj_status_t init_media(void) } /* Add NULL port to the bridge. */ - status = pjmedia_null_port_create( pjsua.pool, pjsua.clock_rate, + status = pjmedia_null_port_create( pjsua.pool, clock_rate, 1, /* mono */ - pjsua.clock_rate * 20 / 1000, 16, + samples_per_frame, 16, &pjsua.null_port); pjmedia_conf_add_port( pjsua.mconf, pjsua.pool, pjsua.null_port, &pjsua.null_port->info.name, NULL ); @@ -1127,9 +1042,21 @@ pj_status_t pjsua_destroy(void) /* Shutdown all codecs: */ - for (i = pjsua.codec_cnt-1; i >= 0; --i) { - (*pjsua.codec_deinit[i])(); - } +#if PJMEDIA_HAS_SPEEX_CODEC + pjmedia_codec_speex_deinit(); +#endif /* PJMEDIA_HAS_SPEEX_CODEC */ + +#if PJMEDIA_HAS_GSM_CODEC + pjmedia_codec_gsm_deinit(); +#endif /* PJMEDIA_HAS_GSM_CODEC */ + +#if PJMEDIA_HAS_G711_CODEC + pjmedia_codec_g711_deinit(); +#endif /* PJMEDIA_HAS_G711_CODEC */ + +#if PJMEDIA_HAS_L16_CODEC + pjmedia_codec_l16_deinit(); +#endif /* PJMEDIA_HAS_L16_CODEC */ /* Destroy media endpoint. */ diff --git a/pjsip/src/pjsua-lib/pjsua_settings.c b/pjsip/src/pjsua-lib/pjsua_settings.c index d811f288..46d2d945 100644 --- a/pjsip/src/pjsua-lib/pjsua_settings.c +++ b/pjsip/src/pjsua-lib/pjsua_settings.c @@ -83,8 +83,7 @@ static void usage(void) puts (" --use-stun2=host[:port] Resolve local IP with the specified STUN servers"); puts (""); puts ("Media Options:"); - puts (" --wb Enable wideband codecs and set clock-rate to 16KHz"); - puts (" --uwb Enable ultra-wideband codecs and set clock-rate to 32KHz"); + puts (" --add-codec=name Manually add codec (default is to enable all)"); puts (" --clock-rate=N Override sound device clock rate"); puts (" --null-audio Use NULL audio device"); puts (" --no-mic Disable microphone device"); @@ -93,7 +92,6 @@ static void usage(void) puts (" --auto-loop Automatically loop incoming RTP to outgoing RTP"); puts (" --auto-conf Automatically put incoming calls to conference"); puts (" --rtp-port=N Base port to try for RTP (default=4000)"); - puts (" --add-codec=name Specify alternate codec order"); puts (" --complexity=N Specify encoding complexity (0-10, default=none(-1))"); puts (" --quality=N Specify encoding quality (0-10, default=4)"); puts (""); @@ -158,7 +156,7 @@ static int read_config_file(pj_pool_t *pool, const char *filename, /* Open config file. */ fhnd = fopen(filename, "rt"); if (!fhnd) { - printf("Unable to open config file %s\n", filename); + PJ_LOG(1,(THIS_FILE, "Unable to open config file %s", filename)); fflush(stdout); return -1; } @@ -191,7 +189,8 @@ static int read_config_file(pj_pool_t *pool, const char *filename, argv[argc++] = (*app_argv)[i]; if (argc == MAX_ARGS && (i!=*app_argc || !feof(fhnd))) { - printf("Too many arguments specified in cmd line/config file\n"); + PJ_LOG(1,(THIS_FILE, + "Too many arguments specified in cmd line/config file")); fflush(stdout); fclose(fhnd); return -1; @@ -227,7 +226,7 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) OPT_ADD_BUDDY, OPT_OFFER_X_MS_MSG, OPT_NO_PRESENCE, OPT_AUTO_ANSWER, OPT_AUTO_HANGUP, OPT_AUTO_PLAY, OPT_AUTO_LOOP, OPT_AUTO_CONF, OPT_CLOCK_RATE, - OPT_PLAY_FILE, OPT_WB, OPT_UWB, OPT_RTP_PORT, OPT_ADD_CODEC, + OPT_PLAY_FILE, OPT_RTP_PORT, OPT_ADD_CODEC, OPT_COMPLEXITY, OPT_QUALITY, OPT_NEXT_ACCOUNT, OPT_NEXT_CRED, OPT_MAX_CALLS, OPT_UAS_REFRESH, OPT_UAS_DURATION, @@ -239,8 +238,6 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) { "app-log-level",1,0,OPT_APP_LOG_LEVEL}, { "help", 0, 0, OPT_HELP}, { "version", 0, 0, OPT_VERSION}, - { "wb", 0, 0, OPT_WB}, - { "uwb", 0, 0, OPT_UWB}, { "clock-rate", 1, 0, OPT_CLOCK_RATE}, { "null-audio", 0, 0, OPT_NULL_AUDIO}, { "no-mic", 0, 0, OPT_NO_MIC}, @@ -321,7 +318,9 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) case OPT_LOG_LEVEL: c = pj_strtoul(pj_cstr(&tmp, pj_optarg)); if (c < 0 || c > 6) { - printf("Error: expecting integer value 0-6 for --log-level\n"); + PJ_LOG(1,(THIS_FILE, + "Error: expecting integer value 0-6 " + "for --log-level")); return PJ_EINVAL; } pj_log_set_level( c ); @@ -330,7 +329,9 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) case OPT_APP_LOG_LEVEL: pjsua.app_log_level = pj_strtoul(pj_cstr(&tmp, pj_optarg)); if (pjsua.app_log_level < 0 || pjsua.app_log_level > 6) { - printf("Error: expecting integer value 0-6 for --app-log-level\n"); + PJ_LOG(1,(THIS_FILE, + "Error: expecting integer value 0-6 " + "for --app-log-level")); return PJ_EINVAL; } break; @@ -351,18 +352,11 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) pjsua.no_mic = 1; break; - case OPT_WB: - pjsua.has_wb = 1; - break; - - case OPT_UWB: - pjsua.has_uwb = 1; - break; - case OPT_CLOCK_RATE: lval = pj_strtoul(pj_cstr(&tmp, pj_optarg)); if (lval < 8000 || lval > 48000) { - printf("Error: expecting value between 8000-48000 for clock rate\n"); + PJ_LOG(1,(THIS_FILE, "Error: expecting value between " + "8000-48000 for clock rate")); return PJ_EINVAL; } pjsua.clock_rate = (int)lval; @@ -371,7 +365,9 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) case OPT_LOCAL_PORT: /* local-port */ lval = pj_strtoul(pj_cstr(&tmp, pj_optarg)); if (lval < 1 || lval > 65535) { - printf("Error: expecting integer value for --local-port\n"); + PJ_LOG(1,(THIS_FILE, + "Error: expecting integer value for " + "--local-port")); return PJ_EINVAL; } pjsua.sip_port = (pj_uint16_t)lval; @@ -379,7 +375,9 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) case OPT_PROXY: /* proxy */ if (pjsua_verify_sip_url(pj_optarg) != 0) { - printf("Error: invalid SIP URL '%s' in proxy argument\n", pj_optarg); + PJ_LOG(1,(THIS_FILE, + "Error: invalid SIP URL '%s' " + "in proxy argument", pj_optarg)); return PJ_EINVAL; } cur_acc->proxy = pj_str(pj_optarg); @@ -387,7 +385,9 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) case OPT_OUTBOUND_PROXY: /* outbound proxy */ if (pjsua_verify_sip_url(pj_optarg) != 0) { - printf("Error: invalid SIP URL '%s' in outbound proxy argument\n", pj_optarg); + PJ_LOG(1,(THIS_FILE, + "Error: invalid SIP URL '%s' " + "in outbound proxy argument", pj_optarg)); return PJ_EINVAL; } pjsua.outbound_proxy = pj_str(pj_optarg); @@ -395,7 +395,9 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) case OPT_REGISTRAR: /* registrar */ if (pjsua_verify_sip_url(pj_optarg) != 0) { - printf("Error: invalid SIP URL '%s' in registrar argument\n", pj_optarg); + PJ_LOG(1,(THIS_FILE, + "Error: invalid SIP URL '%s' in " + "registrar argument", pj_optarg)); return PJ_EINVAL; } cur_acc->reg_uri = pj_str(pj_optarg); @@ -404,14 +406,18 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) case OPT_REG_TIMEOUT: /* reg-timeout */ cur_acc->reg_timeout = pj_strtoul(pj_cstr(&tmp,pj_optarg)); if (cur_acc->reg_timeout < 1 || cur_acc->reg_timeout > 3600) { - printf("Error: invalid value for --reg-timeout (expecting 1-3600)\n"); + PJ_LOG(1,(THIS_FILE, + "Error: invalid value for --reg-timeout " + "(expecting 1-3600)")); return PJ_EINVAL; } break; case OPT_ID: /* id */ if (pjsua_verify_sip_url(pj_optarg) != 0) { - printf("Error: invalid SIP URL '%s' in local id argument\n", pj_optarg); + PJ_LOG(1,(THIS_FILE, + "Error: invalid SIP URL '%s' " + "in local id argument", pj_optarg)); return PJ_EINVAL; } cur_acc->local_uri = pj_str(pj_optarg); @@ -420,7 +426,9 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) case OPT_CONTACT: /* contact */ if (pjsua_verify_sip_url(pj_optarg) != 0) { - printf("Error: invalid SIP URL '%s' in contact argument\n", pj_optarg); + PJ_LOG(1,(THIS_FILE, + "Error: invalid SIP URL '%s' " + "in contact argument", pj_optarg)); return PJ_EINVAL; } cur_acc->contact_uri = pj_str(pj_optarg); @@ -459,7 +467,9 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) pjsua.stun_srv1 = pj_str(pj_optarg); pjsua.stun_port1 = pj_strtoul(pj_cstr(&tmp, p+1)); if (pjsua.stun_port1 < 1 || pjsua.stun_port1 > 65535) { - printf("Error: expecting port number with option --use-stun1\n"); + PJ_LOG(1,(THIS_FILE, + "Error: expecting port number with " + "option --use-stun1")); return PJ_EINVAL; } } else { @@ -475,7 +485,9 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) pjsua.stun_srv2 = pj_str(pj_optarg); pjsua.stun_port2 = pj_strtoul(pj_cstr(&tmp,p+1)); if (pjsua.stun_port2 < 1 || pjsua.stun_port2 > 65535) { - printf("Error: expecting port number with option --use-stun2\n"); + PJ_LOG(1,(THIS_FILE, + "Error: expecting port number with " + "option --use-stun2")); return PJ_EINVAL; } } else { @@ -486,11 +498,14 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) case OPT_ADD_BUDDY: /* Add to buddy list. */ if (pjsua_verify_sip_url(pj_optarg) != 0) { - printf("Error: invalid URL '%s' in --add-buddy option\n", pj_optarg); + PJ_LOG(1,(THIS_FILE, + "Error: invalid URL '%s' in " + "--add-buddy option", pj_optarg)); return -1; } if (pjsua.buddy_cnt == PJSUA_MAX_BUDDIES) { - printf("Error: too many buddies in buddy list.\n"); + PJ_LOG(1,(THIS_FILE, + "Error: too many buddies in buddy list.")); return -1; } pjsua.buddies[pjsua.buddy_cnt++].uri = pj_str(pj_optarg); @@ -516,7 +531,8 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) pjsua.start_rtp_port = my_atoi(pj_optarg); if (pjsua.start_rtp_port < 1 || pjsua.start_rtp_port > 65535) { PJ_LOG(1,(THIS_FILE, - "Error: rtp-port argument value (expecting 1-65535")); + "Error: rtp-port argument value " + "(expecting 1-65535")); return -1; } break; @@ -547,7 +563,8 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) pjsua.auto_answer = my_atoi(pj_optarg); if (pjsua.auto_answer < 100 || pjsua.auto_answer > 699) { PJ_LOG(1,(THIS_FILE, - "Error: invalid code in --auto-answer (expecting 100-699")); + "Error: invalid code in --auto-answer " + "(expecting 100-699")); return -1; } break; @@ -563,7 +580,8 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) case OPT_UAS_REFRESH: pjsua.uas_refresh = my_atoi(pj_optarg); if (pjsua.uas_refresh < 1) { - PJ_LOG(1,(THIS_FILE,"Invalid value for --uas-refresh (must be >0)")); + PJ_LOG(1,(THIS_FILE, + "Invalid value for --uas-refresh (must be >0)")); return -1; } break; @@ -571,7 +589,9 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) case OPT_UAS_DURATION: pjsua.uas_duration = my_atoi(pj_optarg); if (pjsua.uas_duration < 1) { - PJ_LOG(1,(THIS_FILE,"Invalid value for --uas-duration (must be >0)")); + PJ_LOG(1,(THIS_FILE, + "Invalid value for --uas-duration " + "(must be >0)")); return -1; } break; @@ -579,15 +599,29 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) } if (pj_optind != argc) { - printf("Error: unknown options %s\n", argv[pj_optind]); - return PJ_EINVAL; + int i; + + if (pjsua_verify_sip_url(argv[pj_optind]) != PJ_SUCCESS) { + PJ_LOG(1,(THIS_FILE, "Invalid SIP URI %s", argv[pj_optind])); + return -1; + } + pjsua.uri_to_call = pj_str(argv[pj_optind]); + pj_optind++; + + /* Add URI to call to buddy list if it's not already there */ + for (i=0; i<pjsua.buddy_cnt; ++i) { + if (pj_stricmp(&pjsua.buddies[i].uri, &pjsua.uri_to_call)==0) + break; + } + if (i == pjsua.buddy_cnt && pjsua.buddy_cnt < PJSUA_MAX_BUDDIES) { + pjsua.buddies[pjsua.buddy_cnt++].uri = pjsua.uri_to_call; + } } - /* Adjust clock rate */ - if (pjsua.clock_rate == 8000 && pjsua.has_uwb) - pjsua.clock_rate = 32000; - else if (pjsua.clock_rate == 8000 && pjsua.has_wb) - pjsua.clock_rate = 16000; + if (pj_optind != argc) { + PJ_LOG(1,(THIS_FILE, "Error: unknown options %s", argv[pj_optind])); + return PJ_EINVAL; + } return PJ_SUCCESS; } @@ -1047,15 +1081,11 @@ int pjsua_dump_settings(char *buf, pj_size_t max) pj_strcat2(&cfg, line); } /* Media clock rate. */ - if (pjsua.has_uwb) - pj_strcat2(&cfg, "--uwb\n"); - - if (pjsua.has_wb) - pj_strcat2(&cfg, "--wb\n"); - - pj_ansi_sprintf(line, "--clock-rate %d\n", - pjsua.clock_rate); - pj_strcat2(&cfg, line); + if (pjsua.clock_rate) { + pj_ansi_sprintf(line, "--clock-rate %d\n", + pjsua.clock_rate); + pj_strcat2(&cfg, line); + } /* Encoding quality and complexity */ |