From 2366a9a4ae5efcdadbd90acbd2885d86bd34720d Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Sat, 4 Mar 2006 20:43:52 +0000 Subject: Added Speex for narrowband, wideband, and ultra-wideband!! git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@278 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/src/pjsua-lib/pjsua_core.c | 174 ++++++++++++++++++++++++++++++----- pjsip/src/pjsua-lib/pjsua_settings.c | 10 +- 2 files changed, 160 insertions(+), 24 deletions(-) (limited to 'pjsip/src/pjsua-lib') diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c index e944ea42..1f975142 100644 --- a/pjsip/src/pjsua-lib/pjsua_core.c +++ b/pjsip/src/pjsua-lib/pjsua_core.c @@ -528,18 +528,6 @@ pj_status_t pjsua_init(void) return status; } - /* Init pjmedia-codecs: */ - - status = pjmedia_codec_init(pjsua.med_endpt); - if (status != PJ_SUCCESS) { - pj_caching_pool_destroy(&pjsua.cp); - pjsua_perror(THIS_FILE, - "Media codec initialization has returned error", - status); - return status; - } - - /* Done. */ return PJ_SUCCESS; } @@ -608,14 +596,129 @@ int pjsua_find_account_for_outgoing(const pj_str_t *url) /* - * Start pjsua stack. - * This will start the registration process, if registration is configured. + * Init media. */ -pj_status_t pjsua_start(void) +static pj_status_t init_media(void) { - int i; /* Must be signed */ - pjsip_transport *udp_transport; - pj_status_t status = PJ_SUCCESS; + + pj_status_t status; + + /* If user doesn't specify any codecs, register all of them. */ + if (pjsua.codec_cnt == 0) { + + unsigned option = PJMEDIA_SPEEX_NO_WB | PJMEDIA_SPEEX_NO_UWB; + + /* Register speex. */ + if (pjsua.clock_rate >= 16000) + option &= ~(PJMEDIA_SPEEX_NO_WB); + if (pjsua.clock_rate >= 32000) + 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_arg[pjsua.codec_cnt] = pj_str("speex"); + pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_speex_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; + } + + pjsua.codec_arg[pjsua.codec_cnt] = pj_str("gsm"); + pjsua.codec_deinit[pjsua.codec_cnt] = &pjmedia_codec_gsm_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; + } + + 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++; + + } else { + + /* If user specifies the exact codec to be used, then create only + * those codecs. + */ + int i; + + for (i=0; i= 16000) + option &= ~(PJMEDIA_SPEEX_NO_WB); + if (pjsua.clock_rate >= 32000) + 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; + } + /* 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; + + } + /* 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; + + } + /* 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; + } + } + } /* Init conference bridge. */ @@ -661,6 +764,27 @@ pj_status_t pjsua_start(void) } + return PJ_SUCCESS; +} + + +/* + * Start pjsua stack. + * This will start the registration process, if registration is configured. + */ +pj_status_t pjsua_start(void) +{ + int i; /* Must be signed */ + pjsip_transport *udp_transport; + pj_status_t status = PJ_SUCCESS; + + /* + * Init media subsystem (codecs, conference bridge, et all). + */ + status = init_media(); + if (status != PJ_SUCCESS) + return status; + /* Init sockets (STUN etc): */ for (i=0; i<(int)pjsua.max_calls; ++i) { status = init_sockets(i==0, &pjsua.calls[i].skinfo); @@ -870,7 +994,7 @@ static void busy_sleep(unsigned msec) */ pj_status_t pjsua_destroy(void) { - int i; + int i; /* Must be signed */ /* Signal threads to quit: */ pjsua.quit_flag = 1; @@ -907,14 +1031,20 @@ pj_status_t pjsua_destroy(void) if (pjsua.mconf) pjmedia_conf_destroy(pjsua.mconf); - /* Shutdown pjmedia-codec: */ - pjmedia_codec_deinit(); - /* Destroy sound framework: * (this should be done in pjmedia_shutdown()) */ pj_snd_deinit(); + /* Shutdown all codecs: */ + for (i = pjsua.codec_cnt-1; i >= 0; --i) { + (*pjsua.codec_deinit[i])(); + } + + /* Destroy media endpoint. */ + + pjmedia_endpt_destroy(pjsua.med_endpt); + /* Destroy endpoint. */ pjsip_endpt_destroy(pjsua.endpt); diff --git a/pjsip/src/pjsua-lib/pjsua_settings.c b/pjsip/src/pjsua-lib/pjsua_settings.c index 9e1d3ff8..810d645a 100644 --- a/pjsip/src/pjsua-lib/pjsua_settings.c +++ b/pjsip/src/pjsua-lib/pjsua_settings.c @@ -90,7 +90,8 @@ static void usage(void) puts(" --auto-play Automatically play the file (to incoming calls only)"); 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"); + puts(" --rtp-port=N Base port to try for RTP"); + puts(" --add-codec=name Specify alternate codec order"); puts(""); puts("Buddy List (can be more than one):"); puts(" --add-buddy url Add the specified URL to the buddy list."); @@ -220,7 +221,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_PLAY_FILE, OPT_WB, OPT_UWB, OPT_RTP_PORT, + OPT_PLAY_FILE, OPT_WB, OPT_UWB, OPT_RTP_PORT, OPT_ADD_CODEC, OPT_NEXT_ACCOUNT, OPT_NEXT_CRED, OPT_MAX_CALLS, }; struct option long_options[] = { @@ -255,6 +256,7 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) { "auto-conf", 0, 0, OPT_AUTO_CONF}, { "play-file", 1, 0, OPT_PLAY_FILE}, { "rtp-port", 1, 0, OPT_RTP_PORT}, + { "add-codec", 1, 0, OPT_ADD_CODEC}, { "next-account",0,0, OPT_NEXT_ACCOUNT}, { "next-cred", 0, 0, OPT_NEXT_CRED}, { "max-calls", 1, 0, OPT_MAX_CALLS}, @@ -490,6 +492,10 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) return -1; } + case OPT_ADD_CODEC: + pjsua.codec_arg[pjsua.codec_cnt++] = pj_str(optarg); + break; + case OPT_AUTO_ANSWER: pjsua.auto_answer = my_atoi(optarg); if (pjsua.auto_answer < 100 || pjsua.auto_answer > 699) { -- cgit v1.2.3