Changeset 422


Ignore:
Timestamp:
Apr 29, 2006 8:31:09 AM (18 years ago)
Author:
bennylp
Message:

Improve codec handling in pjsua cmd-line options, and add URI to call

Location:
pjproject/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/config.c

    r419 r422  
    2222 
    2323static const char *id = "config.c"; 
    24 const char *PJ_VERSION = "0.5.4.12"; 
     24const char *PJ_VERSION = "0.5.4.13"; 
    2525 
    2626PJ_DEF(void) pj_dump_config(void) 
  • pjproject/trunk/pjsip-apps/src/pjsua/main.c

    r355 r422  
    414414    struct input_result result; 
    415415 
     416 
     417    /* If user specifies URI to call, then call the URI */ 
     418    if (pjsua.uri_to_call.slen) { 
     419        pjsua_make_call( current_acc, pjsua.uri_to_call.ptr, NULL); 
     420    } 
     421 
    416422    keystroke_help(); 
    417423 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r398 r422  
    184184    pjmedia_endpt   *med_endpt;     /**< Media endpoint.                */ 
    185185    unsigned         clock_rate;    /**< Internal clock rate.           */ 
    186     pj_bool_t        has_wb;        /**< Include wideband codecs        */ 
    187     pj_bool_t        has_uwb;       /**< Include ultra-wideband codecs  */ 
    188186    pjmedia_conf    *mconf;         /**< Media conference.              */ 
    189187    pj_bool_t        null_audio;    /**< Null audio flag.               */ 
     
    250248 
    251249    /* PJSUA Calls: */ 
     250    pj_str_t         uri_to_call;   /**< URI to call.                   */ 
    252251    int              max_calls;     /**< Max nb of calls.               */ 
    253252    int              call_cnt;      /**< Number of calls.               */ 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c

    r398 r422  
    10481048                                   call->conf_slot, 0); 
    10491049 
    1050     } else if (pjsua.auto_loop && call->inv->role == PJSIP_ROLE_UAS) { 
     1050    } 
     1051    if (pjsua.auto_loop && call->inv->role == PJSIP_ROLE_UAS) { 
    10511052 
    10521053        pjmedia_conf_connect_port( pjsua.mconf, call->conf_slot,  
    10531054                                   call->conf_slot, 0); 
    10541055 
    1055     } else if (pjsua.auto_conf) { 
    1056  
     1056    } 
     1057    if (pjsua.auto_conf) { 
    10571058        int i; 
    10581059 
     
    10711072        } 
    10721073 
    1073     } else { 
    1074  
    1075         /* Connect new call to the sound device port (port zero) in the 
    1076          * main conference bridge. 
    1077          */ 
     1074    }  
     1075     
     1076    /* Normal operation: if no auto_xx is given, connect new call to  
     1077     * the sound device port (port zero) in the main conference bridge. 
     1078     */ 
     1079    if (pjsua.auto_play == 0 && pjsua.auto_loop == 0 && 
     1080        pjsua.auto_conf == 0) 
     1081    { 
    10781082        pjmedia_conf_connect_port( pjsua.mconf, 0, call->conf_slot, 0); 
    10791083        pjmedia_conf_connect_port( pjsua.mconf, call->conf_slot, 0, 0); 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r412 r422  
    8080#if defined(PJ_DARWINOS) && PJ_DARWINOS!=0 
    8181    pjsua.clock_rate = 44100; 
    82 #else 
    83     pjsua.clock_rate = 8000; 
    8482#endif 
    8583    pjsua.complexity = -1; 
    8684    pjsua.quality = 4; 
    87     pjsua.has_wb = 0; 
    88     pjsua.has_uwb = 0; 
    8985 
    9086 
     
    621617static pj_status_t init_media(void) 
    622618{ 
     619    int i; 
    623620    unsigned options; 
     621    unsigned clock_rate; 
     622    unsigned samples_per_frame; 
     623    pj_str_t codec_id; 
    624624    pj_status_t status; 
    625625 
    626     /* If user doesn't specify any codecs, register all of them. */ 
    627     if (pjsua.codec_cnt == 0) { 
    628  
     626    /* Register all codecs */ 
    629627#if PJMEDIA_HAS_SPEEX_CODEC 
    630         unsigned option = PJMEDIA_SPEEX_NO_WB | PJMEDIA_SPEEX_NO_UWB; 
    631  
    632         /* Register speex. */ 
    633         if (pjsua.has_wb) 
    634             option &= ~PJMEDIA_SPEEX_NO_WB; 
    635         if (pjsua.has_uwb) 
    636             option &= ~PJMEDIA_SPEEX_NO_UWB; 
    637  
    638         status = pjmedia_codec_speex_init(pjsua.med_endpt, option,  
    639                                           pjsua.quality, pjsua.complexity ); 
    640         if (status != PJ_SUCCESS) { 
    641             pjsua_perror(THIS_FILE, "Error initializing Speex codec", 
    642                          status); 
    643             return status; 
    644         } 
    645  
    646         pjsua.codec_arg[pjsua.codec_cnt] = pj_str("speex"); 
    647         pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_speex_deinit; 
    648         pjsua.codec_cnt++; 
     628    /* Register speex. */ 
     629    status = pjmedia_codec_speex_init(pjsua.med_endpt,  
     630                                      PJMEDIA_SPEEX_NO_UWB, 
     631                                      pjsua.quality, pjsua.complexity ); 
     632    if (status != PJ_SUCCESS) { 
     633        pjsua_perror(THIS_FILE, "Error initializing Speex codec", 
     634                     status); 
     635        return status; 
     636    } 
     637 
     638    /* Set "speex/16000/1" to have highest priority */ 
     639    codec_id = pj_str("speex/16000/1"); 
     640    pjmedia_codec_mgr_set_codec_priority(  
     641        pjmedia_endpt_get_codec_mgr(pjsua.med_endpt), 
     642        &codec_id,  
     643        PJMEDIA_CODEC_PRIO_HIGHEST); 
     644 
    649645#endif /* PJMEDIA_HAS_SPEEX_CODEC */ 
    650646 
    651647#if PJMEDIA_HAS_GSM_CODEC 
    652         /* Register GSM */ 
    653         status = pjmedia_codec_gsm_init(pjsua.med_endpt); 
    654         if (status != PJ_SUCCESS) { 
    655             pjsua_perror(THIS_FILE, "Error initializing GSM codec", 
    656                          status); 
    657             return status; 
    658         } 
    659  
    660         pjsua.codec_arg[pjsua.codec_cnt] = pj_str("gsm"); 
    661         pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_gsm_deinit; 
    662         pjsua.codec_cnt++; 
     648    /* Register GSM */ 
     649    status = pjmedia_codec_gsm_init(pjsua.med_endpt); 
     650    if (status != PJ_SUCCESS) { 
     651        pjsua_perror(THIS_FILE, "Error initializing GSM codec", 
     652                     status); 
     653        return status; 
     654    } 
    663655#endif /* PJMEDIA_HAS_GSM_CODEC */ 
    664656 
     657#if PJMEDIA_HAS_G711_CODEC 
     658    /* Register PCMA and PCMU */ 
     659    status = pjmedia_codec_g711_init(pjsua.med_endpt); 
     660    if (status != PJ_SUCCESS) { 
     661        pjsua_perror(THIS_FILE, "Error initializing G711 codec", 
     662                     status); 
     663        return status; 
     664    } 
     665#endif  /* PJMEDIA_HAS_G711_CODEC */ 
     666 
    665667#if PJMEDIA_HAS_L16_CODEC 
    666         /* Register L16 */ 
    667         status = pjmedia_codec_l16_init(pjsua.med_endpt, 0); 
    668         if (status != PJ_SUCCESS) { 
    669             pjsua_perror(THIS_FILE, "Error initializing L16 codec", 
    670                          status); 
    671             return status; 
    672         } 
    673  
    674         pjsua.codec_arg[pjsua.codec_cnt] = pj_str("l16"); 
    675         pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_l16_deinit; 
    676         pjsua.codec_cnt++; 
    677 #endif /* PJMEDIA_HAS_L16_CODEC */ 
    678  
    679  
    680 #if PJMEDIA_HAS_G711_CODEC 
    681         /* Register PCMA and PCMU */ 
    682         status = pjmedia_codec_g711_init(pjsua.med_endpt); 
    683         if (status != PJ_SUCCESS) { 
    684             pjsua_perror(THIS_FILE, "Error initializing G711 codec", 
    685                          status); 
    686             return status; 
    687         } 
    688  
    689         pjsua.codec_arg[pjsua.codec_cnt] = pj_str("pcmu"); 
    690         pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_g711_deinit; 
    691         pjsua.codec_cnt++; 
    692         pjsua.codec_arg[pjsua.codec_cnt] = pj_str("pcma"); 
    693         pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_g711_deinit; 
    694         pjsua.codec_cnt++; 
    695 #endif  /* PJMEDIA_HAS_G711_CODEC */ 
    696  
    697     } else { 
    698  
    699         /* If user specifies the exact codec to be used, then create only 
    700          * those codecs. 
    701          */ 
    702         int i; 
    703  
    704         for (i=0; i<pjsua.codec_cnt; ++i) { 
     668    /* Register L16 family codecs, but disable all */ 
     669    status = pjmedia_codec_l16_init(pjsua.med_endpt, 0); 
     670    if (status != PJ_SUCCESS) { 
     671        pjsua_perror(THIS_FILE, "Error initializing L16 codecs", 
     672                     status); 
     673        return status; 
     674    } 
     675 
     676    /* Disable ALL L16 codecs */ 
     677    codec_id = pj_str("L16"); 
     678    pjmedia_codec_mgr_set_codec_priority(  
     679        pjmedia_endpt_get_codec_mgr(pjsua.med_endpt), 
     680        &codec_id,  
     681        PJMEDIA_CODEC_PRIO_DISABLED); 
     682 
     683#endif  /* PJMEDIA_HAS_L16_CODEC */ 
     684 
     685 
     686    /* If user specifies the exact codec to be used, then disable all codecs 
     687     * and only enable those specific codecs. 
     688     */ 
     689    if (pjsua.codec_cnt != 0) { 
     690        codec_id = pj_str(""); 
     691        pjmedia_codec_mgr_set_codec_priority(  
     692            pjmedia_endpt_get_codec_mgr(pjsua.med_endpt), 
     693            &codec_id,  
     694            PJMEDIA_CODEC_PRIO_DISABLED); 
     695    } 
     696 
    705697         
    706             if (0) { 
    707                 /* Dummy */ 
    708             } 
    709 #if PJMEDIA_HAS_SPEEX_CODEC 
    710             /* Is it speex? */ 
    711             else if (!pj_stricmp2(&pjsua.codec_arg[i], "speex")) { 
    712  
    713                 unsigned option = PJMEDIA_SPEEX_NO_WB | PJMEDIA_SPEEX_NO_UWB; 
    714  
    715                 /* Register speex. */ 
    716                 if (pjsua.has_wb) 
    717                     option &= ~(PJMEDIA_SPEEX_NO_WB); 
    718                 if (pjsua.has_uwb) 
    719                     option &= ~(PJMEDIA_SPEEX_NO_UWB); 
    720  
    721                 status = pjmedia_codec_speex_init(pjsua.med_endpt, option, 
    722                                                   -1, -1); 
    723                 if (status != PJ_SUCCESS) { 
    724                     pjsua_perror(THIS_FILE, "Error initializing Speex codec", 
    725                                  status); 
    726                     return status; 
    727                 } 
    728  
    729                 pjsua.codec_deinit[i] = &pjmedia_codec_speex_deinit; 
    730             } 
    731 #endif  /* PJMEDIA_HAS_SPEEX_CODEC */ 
    732  
    733 #if PJMEDIA_HAS_GSM_CODEC 
    734             /* Is it gsm? */ 
    735             else if (!pj_stricmp2(&pjsua.codec_arg[i], "gsm")) { 
    736  
    737                 status = pjmedia_codec_gsm_init(pjsua.med_endpt); 
    738                 if (status != PJ_SUCCESS) { 
    739                     pjsua_perror(THIS_FILE, "Error initializing GSM codec", 
    740                                  status); 
    741                     return status; 
    742                 } 
    743  
    744                 pjsua.codec_deinit[i] = &pjmedia_codec_gsm_deinit; 
    745  
    746             } 
    747 #endif  /* PJMEDIA_HAS_GSM_CODEC */ 
    748  
    749 #if PJMEDIA_HAS_L16_CODEC 
    750             /* Is it l16? */ 
    751             else if (!pj_stricmp2(&pjsua.codec_arg[i], "l16")) { 
    752  
    753                 status = pjmedia_codec_l16_init(pjsua.med_endpt, 0); 
    754                 if (status != PJ_SUCCESS) { 
    755                     pjsua_perror(THIS_FILE, "Error initializing L16 codec", 
    756                                  status); 
    757                     return status; 
    758                 } 
    759  
    760                 pjsua.codec_deinit[i] = &pjmedia_codec_l16_deinit; 
    761  
    762                 pjsua.clock_rate = 44100; 
    763             } 
    764 #endif  /* PJMEDIA_HAS_L16_CODEC */ 
    765  
    766 #if PJMEDIA_HAS_G711_CODEC 
    767             /* Is it pcma/pcmu? */ 
    768             else if (!pj_stricmp2(&pjsua.codec_arg[i], "pcmu") || 
    769                      !pj_stricmp2(&pjsua.codec_arg[i], "pcma")) 
    770             { 
    771  
    772                 status = pjmedia_codec_g711_init(pjsua.med_endpt); 
    773                 if (status != PJ_SUCCESS) { 
    774                     pjsua_perror(THIS_FILE, "Error initializing G711 codec", 
    775                                  status); 
    776                     return status; 
    777                 } 
    778  
    779                 pjsua.codec_deinit[i] = &pjmedia_codec_g711_deinit; 
    780  
    781             } 
    782 #endif  /* PJMEDIA_HAS_G711_CODEC */ 
    783  
    784             /* Don't know about this codec... */ 
    785             else { 
    786  
    787                 PJ_LOG(1,(THIS_FILE, "Error: unsupported codecs %s", 
    788                           pjsua.codec_arg[i].ptr)); 
    789                 return PJMEDIA_CODEC_EUNSUP; 
    790             } 
    791         } 
    792     } 
     698 
     699    for (i=0; i<pjsua.codec_cnt; ++i) { 
     700        pjmedia_codec_mgr_set_codec_priority(  
     701            pjmedia_endpt_get_codec_mgr(pjsua.med_endpt), 
     702            &pjsua.codec_arg[i],  
     703            PJMEDIA_CODEC_PRIO_NEXT_HIGHER); 
     704    } 
     705 
    793706 
    794707    /* Init options for conference bridge. */ 
     
    798711 
    799712    /* Init conference bridge. */ 
    800  
     713    clock_rate = pjsua.clock_rate ? pjsua.clock_rate : 16000; 
     714    samples_per_frame = clock_rate * 20 / 1000; 
    801715    status = pjmedia_conf_create(pjsua.pool,  
    802716                                 pjsua.max_calls+PJSUA_CONF_MORE_PORTS,  
    803                                  pjsua.clock_rate,  
     717                                 clock_rate,  
    804718                                 1, /* mono */ 
    805                                  pjsua.clock_rate * 20 / 1000, 16,  
     719                                 samples_per_frame,  
     720                                 16,  
    806721                                 options, 
    807722                                 &pjsua.mconf); 
     
    814729 
    815730    /* Add NULL port to the bridge. */ 
    816     status = pjmedia_null_port_create( pjsua.pool, pjsua.clock_rate,  
     731    status = pjmedia_null_port_create( pjsua.pool, clock_rate,  
    817732                                       1, /* mono */ 
    818                                        pjsua.clock_rate * 20 / 1000, 16, 
     733                                       samples_per_frame, 16, 
    819734                                       &pjsua.null_port); 
    820735    pjmedia_conf_add_port( pjsua.mconf, pjsua.pool, pjsua.null_port,  
     
    11281043 
    11291044    /* Shutdown all codecs: */ 
    1130     for (i = pjsua.codec_cnt-1; i >= 0; --i) { 
    1131         (*pjsua.codec_deinit[i])(); 
    1132     } 
     1045#if PJMEDIA_HAS_SPEEX_CODEC 
     1046    pjmedia_codec_speex_deinit(); 
     1047#endif /* PJMEDIA_HAS_SPEEX_CODEC */ 
     1048 
     1049#if PJMEDIA_HAS_GSM_CODEC 
     1050    pjmedia_codec_gsm_deinit(); 
     1051#endif /* PJMEDIA_HAS_GSM_CODEC */ 
     1052 
     1053#if PJMEDIA_HAS_G711_CODEC 
     1054    pjmedia_codec_g711_deinit(); 
     1055#endif  /* PJMEDIA_HAS_G711_CODEC */ 
     1056 
     1057#if PJMEDIA_HAS_L16_CODEC 
     1058    pjmedia_codec_l16_deinit(); 
     1059#endif  /* PJMEDIA_HAS_L16_CODEC */ 
    11331060 
    11341061    /* Destroy media endpoint. */ 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_settings.c

    r412 r422  
    8484    puts  (""); 
    8585    puts  ("Media Options:"); 
    86     puts  ("  --wb                Enable wideband codecs and set clock-rate to 16KHz"); 
    87     puts  ("  --uwb               Enable ultra-wideband codecs and set clock-rate to 32KHz"); 
     86    puts  ("  --add-codec=name    Manually add codec (default is to enable all)"); 
    8887    puts  ("  --clock-rate=N      Override sound device clock rate"); 
    8988    puts  ("  --null-audio        Use NULL audio device"); 
     
    9493    puts  ("  --auto-conf         Automatically put incoming calls to conference"); 
    9594    puts  ("  --rtp-port=N        Base port to try for RTP (default=4000)"); 
    96     puts  ("  --add-codec=name    Specify alternate codec order"); 
    9795    puts  ("  --complexity=N      Specify encoding complexity (0-10, default=none(-1))"); 
    9896    puts  ("  --quality=N         Specify encoding quality (0-10, default=4)"); 
     
    159157    fhnd = fopen(filename, "rt"); 
    160158    if (!fhnd) { 
    161         printf("Unable to open config file %s\n", filename); 
     159        PJ_LOG(1,(THIS_FILE, "Unable to open config file %s", filename)); 
    162160        fflush(stdout); 
    163161        return -1; 
     
    192190 
    193191    if (argc == MAX_ARGS && (i!=*app_argc || !feof(fhnd))) { 
    194         printf("Too many arguments specified in cmd line/config file\n"); 
     192        PJ_LOG(1,(THIS_FILE,  
     193                  "Too many arguments specified in cmd line/config file")); 
    195194        fflush(stdout); 
    196195        fclose(fhnd); 
     
    228227           OPT_AUTO_ANSWER, OPT_AUTO_HANGUP, OPT_AUTO_PLAY, OPT_AUTO_LOOP, 
    229228           OPT_AUTO_CONF, OPT_CLOCK_RATE, 
    230            OPT_PLAY_FILE, OPT_WB, OPT_UWB, OPT_RTP_PORT, OPT_ADD_CODEC, 
     229           OPT_PLAY_FILE, OPT_RTP_PORT, OPT_ADD_CODEC, 
    231230           OPT_COMPLEXITY, OPT_QUALITY, 
    232231           OPT_NEXT_ACCOUNT, OPT_NEXT_CRED, OPT_MAX_CALLS, OPT_UAS_REFRESH, 
     
    240239        { "help",       0, 0, OPT_HELP}, 
    241240        { "version",    0, 0, OPT_VERSION}, 
    242         { "wb",         0, 0, OPT_WB}, 
    243         { "uwb",        0, 0, OPT_UWB}, 
    244241        { "clock-rate", 1, 0, OPT_CLOCK_RATE}, 
    245242        { "null-audio", 0, 0, OPT_NULL_AUDIO}, 
     
    322319            c = pj_strtoul(pj_cstr(&tmp, pj_optarg)); 
    323320            if (c < 0 || c > 6) { 
    324                 printf("Error: expecting integer value 0-6 for --log-level\n"); 
     321                PJ_LOG(1,(THIS_FILE,  
     322                          "Error: expecting integer value 0-6 " 
     323                          "for --log-level")); 
    325324                return PJ_EINVAL; 
    326325            } 
     
    331330            pjsua.app_log_level = pj_strtoul(pj_cstr(&tmp, pj_optarg)); 
    332331            if (pjsua.app_log_level < 0 || pjsua.app_log_level > 6) { 
    333                 printf("Error: expecting integer value 0-6 for --app-log-level\n"); 
     332                PJ_LOG(1,(THIS_FILE,  
     333                          "Error: expecting integer value 0-6 " 
     334                          "for --app-log-level")); 
    334335                return PJ_EINVAL; 
    335336            } 
     
    352353            break; 
    353354 
    354         case OPT_WB: 
    355             pjsua.has_wb = 1; 
    356             break; 
    357  
    358         case OPT_UWB: 
    359             pjsua.has_uwb = 1; 
    360             break; 
    361  
    362355        case OPT_CLOCK_RATE: 
    363356            lval = pj_strtoul(pj_cstr(&tmp, pj_optarg)); 
    364357            if (lval < 8000 || lval > 48000) { 
    365                 printf("Error: expecting value between 8000-48000 for clock rate\n"); 
     358                PJ_LOG(1,(THIS_FILE, "Error: expecting value between " 
     359                                     "8000-48000 for clock rate")); 
    366360                return PJ_EINVAL; 
    367361            } 
     
    372366            lval = pj_strtoul(pj_cstr(&tmp, pj_optarg)); 
    373367            if (lval < 1 || lval > 65535) { 
    374                 printf("Error: expecting integer value for --local-port\n"); 
     368                PJ_LOG(1,(THIS_FILE,  
     369                          "Error: expecting integer value for " 
     370                          "--local-port")); 
    375371                return PJ_EINVAL; 
    376372            } 
     
    380376        case OPT_PROXY:   /* proxy */ 
    381377            if (pjsua_verify_sip_url(pj_optarg) != 0) { 
    382                 printf("Error: invalid SIP URL '%s' in proxy argument\n", pj_optarg); 
     378                PJ_LOG(1,(THIS_FILE,  
     379                          "Error: invalid SIP URL '%s' " 
     380                          "in proxy argument", pj_optarg)); 
    383381                return PJ_EINVAL; 
    384382            } 
     
    388386        case OPT_OUTBOUND_PROXY:   /* outbound proxy */ 
    389387            if (pjsua_verify_sip_url(pj_optarg) != 0) { 
    390                 printf("Error: invalid SIP URL '%s' in outbound proxy argument\n", pj_optarg); 
     388                PJ_LOG(1,(THIS_FILE,  
     389                          "Error: invalid SIP URL '%s' " 
     390                          "in outbound proxy argument", pj_optarg)); 
    391391                return PJ_EINVAL; 
    392392            } 
     
    396396        case OPT_REGISTRAR:   /* registrar */ 
    397397            if (pjsua_verify_sip_url(pj_optarg) != 0) { 
    398                 printf("Error: invalid SIP URL '%s' in registrar argument\n", pj_optarg); 
     398                PJ_LOG(1,(THIS_FILE,  
     399                          "Error: invalid SIP URL '%s' in " 
     400                          "registrar argument", pj_optarg)); 
    399401                return PJ_EINVAL; 
    400402            } 
     
    405407            cur_acc->reg_timeout = pj_strtoul(pj_cstr(&tmp,pj_optarg)); 
    406408            if (cur_acc->reg_timeout < 1 || cur_acc->reg_timeout > 3600) { 
    407                 printf("Error: invalid value for --reg-timeout (expecting 1-3600)\n"); 
     409                PJ_LOG(1,(THIS_FILE,  
     410                          "Error: invalid value for --reg-timeout " 
     411                          "(expecting 1-3600)")); 
    408412                return PJ_EINVAL; 
    409413            } 
     
    412416        case OPT_ID:   /* id */ 
    413417            if (pjsua_verify_sip_url(pj_optarg) != 0) { 
    414                 printf("Error: invalid SIP URL '%s' in local id argument\n", pj_optarg); 
     418                PJ_LOG(1,(THIS_FILE,  
     419                          "Error: invalid SIP URL '%s' " 
     420                          "in local id argument", pj_optarg)); 
    415421                return PJ_EINVAL; 
    416422            } 
     
    421427        case OPT_CONTACT:   /* contact */ 
    422428            if (pjsua_verify_sip_url(pj_optarg) != 0) { 
    423                 printf("Error: invalid SIP URL '%s' in contact argument\n", pj_optarg); 
     429                PJ_LOG(1,(THIS_FILE,  
     430                          "Error: invalid SIP URL '%s' " 
     431                          "in contact argument", pj_optarg)); 
    424432                return PJ_EINVAL; 
    425433            } 
     
    460468                pjsua.stun_port1 = pj_strtoul(pj_cstr(&tmp, p+1)); 
    461469                if (pjsua.stun_port1 < 1 || pjsua.stun_port1 > 65535) { 
    462                     printf("Error: expecting port number with option --use-stun1\n"); 
     470                    PJ_LOG(1,(THIS_FILE,  
     471                              "Error: expecting port number with " 
     472                              "option --use-stun1")); 
    463473                    return PJ_EINVAL; 
    464474                } 
     
    476486                pjsua.stun_port2 = pj_strtoul(pj_cstr(&tmp,p+1)); 
    477487                if (pjsua.stun_port2 < 1 || pjsua.stun_port2 > 65535) { 
    478                     printf("Error: expecting port number with option --use-stun2\n"); 
     488                    PJ_LOG(1,(THIS_FILE,  
     489                              "Error: expecting port number with " 
     490                              "option --use-stun2")); 
    479491                    return PJ_EINVAL; 
    480492                } 
     
    487499        case OPT_ADD_BUDDY: /* Add to buddy list. */ 
    488500            if (pjsua_verify_sip_url(pj_optarg) != 0) { 
    489                 printf("Error: invalid URL '%s' in --add-buddy option\n", pj_optarg); 
     501                PJ_LOG(1,(THIS_FILE,  
     502                          "Error: invalid URL '%s' in " 
     503                          "--add-buddy option", pj_optarg)); 
    490504                return -1; 
    491505            } 
    492506            if (pjsua.buddy_cnt == PJSUA_MAX_BUDDIES) { 
    493                 printf("Error: too many buddies in buddy list.\n"); 
     507                PJ_LOG(1,(THIS_FILE,  
     508                          "Error: too many buddies in buddy list.")); 
    494509                return -1; 
    495510            } 
     
    517532            if (pjsua.start_rtp_port < 1 || pjsua.start_rtp_port > 65535) { 
    518533                PJ_LOG(1,(THIS_FILE, 
    519                           "Error: rtp-port argument value (expecting 1-65535")); 
     534                          "Error: rtp-port argument value " 
     535                          "(expecting 1-65535")); 
    520536                return -1; 
    521537            } 
     
    548564            if (pjsua.auto_answer < 100 || pjsua.auto_answer > 699) { 
    549565                PJ_LOG(1,(THIS_FILE, 
    550                           "Error: invalid code in --auto-answer (expecting 100-699")); 
     566                          "Error: invalid code in --auto-answer " 
     567                          "(expecting 100-699")); 
    551568                return -1; 
    552569            } 
     
    564581            pjsua.uas_refresh = my_atoi(pj_optarg); 
    565582            if (pjsua.uas_refresh < 1) { 
    566                 PJ_LOG(1,(THIS_FILE,"Invalid value for --uas-refresh (must be >0)")); 
     583                PJ_LOG(1,(THIS_FILE, 
     584                          "Invalid value for --uas-refresh (must be >0)")); 
    567585                return -1; 
    568586            } 
     
    572590            pjsua.uas_duration = my_atoi(pj_optarg); 
    573591            if (pjsua.uas_duration < 1) { 
    574                 PJ_LOG(1,(THIS_FILE,"Invalid value for --uas-duration (must be >0)")); 
     592                PJ_LOG(1,(THIS_FILE, 
     593                          "Invalid value for --uas-duration " 
     594                          "(must be >0)")); 
    575595                return -1; 
    576596            } 
     
    580600 
    581601    if (pj_optind != argc) { 
    582         printf("Error: unknown options %s\n", argv[pj_optind]); 
     602        int i; 
     603 
     604        if (pjsua_verify_sip_url(argv[pj_optind]) != PJ_SUCCESS) { 
     605            PJ_LOG(1,(THIS_FILE, "Invalid SIP URI %s", argv[pj_optind])); 
     606            return -1; 
     607        } 
     608        pjsua.uri_to_call = pj_str(argv[pj_optind]); 
     609        pj_optind++; 
     610 
     611        /* Add URI to call to buddy list if it's not already there */ 
     612        for (i=0; i<pjsua.buddy_cnt; ++i) { 
     613            if (pj_stricmp(&pjsua.buddies[i].uri, &pjsua.uri_to_call)==0) 
     614                break; 
     615        } 
     616        if (i == pjsua.buddy_cnt && pjsua.buddy_cnt < PJSUA_MAX_BUDDIES) { 
     617            pjsua.buddies[pjsua.buddy_cnt++].uri = pjsua.uri_to_call; 
     618        } 
     619    } 
     620 
     621    if (pj_optind != argc) { 
     622        PJ_LOG(1,(THIS_FILE, "Error: unknown options %s", argv[pj_optind])); 
    583623        return PJ_EINVAL; 
    584624    } 
    585  
    586     /* Adjust clock rate */ 
    587     if (pjsua.clock_rate == 8000 && pjsua.has_uwb) 
    588         pjsua.clock_rate = 32000; 
    589     else if (pjsua.clock_rate == 8000 && pjsua.has_wb) 
    590         pjsua.clock_rate = 16000; 
    591625 
    592626    return PJ_SUCCESS; 
     
    10481082    } 
    10491083    /* Media clock rate. */ 
    1050     if (pjsua.has_uwb) 
    1051         pj_strcat2(&cfg, "--uwb\n"); 
    1052  
    1053     if (pjsua.has_wb) 
    1054         pj_strcat2(&cfg, "--wb\n"); 
    1055  
    1056     pj_ansi_sprintf(line, "--clock-rate %d\n", 
    1057                     pjsua.clock_rate); 
    1058     pj_strcat2(&cfg, line); 
     1084    if (pjsua.clock_rate) { 
     1085        pj_ansi_sprintf(line, "--clock-rate %d\n", 
     1086                        pjsua.clock_rate); 
     1087        pj_strcat2(&cfg, line); 
     1088    } 
    10591089 
    10601090 
Note: See TracChangeset for help on using the changeset viewer.