diff options
-rw-r--r-- | pjsip-apps/src/samples/confsample.c | 70 | ||||
-rw-r--r-- | pjsip/include/pjsua-lib/pjsua.h | 2 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_core.c | 18 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_settings.c | 33 |
4 files changed, 80 insertions, 43 deletions
diff --git a/pjsip-apps/src/samples/confsample.c b/pjsip-apps/src/samples/confsample.c index 11746e4b..514bd028 100644 --- a/pjsip-apps/src/samples/confsample.c +++ b/pjsip-apps/src/samples/confsample.c @@ -19,34 +19,33 @@ #include <pjmedia.h> -/* - * FILE: - * - * confsample.c - * - * PURPOSE: - * - * Demonstrate how to use conference bridge. - * - * USAGE: - * - * confsample [file1.wav] [file2.wav] ... - * - * where: - * fileN.wav are optional WAV files to be connected to the conference - * bridge. The WAV files MUST have single channel (mono) and 16 bit PCM - * samples. It can have arbitrary sampling rate. - * - * DESCRIPTION: - * - * Here we create a conference bridge, with at least one port (port zero - * is always created for the sound device). - * - * If WAV files are specified, the WAV file player ports will be connected - * to slot starting from number one in the bridge. The WAV files can have - * arbitrary sampling rate; the bridge will convert it to its clock rate. - * However, the files MUST have a single audio channel only (i.e. mono). - */ +static const char *desc = + " FILE: \n" + " \n" + " confsample.c \n" + " \n" + " PURPOSE: \n" + " \n" + " Demonstrate how to use conference bridge. \n" + " \n" + " USAGE: \n" + " \n" + " confsample [file1.wav] [file2.wav] ... \n" + " \n" + " where: \n" + " fileN.wav are optional WAV files to be connected to the conference \n" + " bridge. The WAV files MUST have single channel (mono) and 16 bit PCM \n" + " samples. It can have arbitrary sampling rate. \n" + " \n" + " DESCRIPTION: \n" + " \n" + " Here we create a conference bridge, with at least one port (port zero \n" + " is always created for the sound device). \n" + " \n" + " If WAV files are specified, the WAV file player ports will be connected \n" + " to slot starting from number one in the bridge. The WAV files can have \n" + " arbitrary sampling rate; the bridge will convert it to its clock rate. \n" + " However, the files MUST have a single audio channel only (i.e. mono). \n"; #include <pjmedia.h> #include <pjlib.h> @@ -58,6 +57,13 @@ /* For logging purpose. */ #define THIS_FILE "confsample.c" +/* Constants */ +#define CLOCK_RATE 44100 +#define NSAMPLES (CLOCK_RATE * 20 / 1000) +#define NCHANNELS 1 +#define NBITS 16 + + /* * Prototypes: */ @@ -173,10 +179,10 @@ int main(int argc, char *argv[]) */ status = pjmedia_conf_create( pool, /* pool to use */ port_count,/* number of ports */ - 16000, /* sampling rate */ - 1, /* # of channels. */ - 320, /* samples per frame */ - 16, /* bits per sample */ + CLOCK_RATE,/* sampling rate */ + NCHANNELS,/* # of channels. */ + NSAMPLES, /* samples per frame */ + NBITS, /* bits per sample */ 0, /* options */ &conf /* result */ ); diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h index 5a39c9ed..c5594f4c 100644 --- a/pjsip/include/pjsua-lib/pjsua.h +++ b/pjsip/include/pjsua-lib/pjsua.h @@ -180,6 +180,8 @@ 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. */ diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c index 1dd4ca08..fdf66c8f 100644 --- a/pjsip/src/pjsua-lib/pjsua_core.c +++ b/pjsip/src/pjsua-lib/pjsua_core.c @@ -77,9 +77,15 @@ void pjsua_default(void) pjsua.stun_port1 = pjsua.stun_port2 = 0; /* 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: */ @@ -621,10 +627,10 @@ static pj_status_t init_media(void) 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); + 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, pjsua.quality, pjsua.complexity ); @@ -689,9 +695,9 @@ static pj_status_t init_media(void) unsigned option = PJMEDIA_SPEEX_NO_WB | PJMEDIA_SPEEX_NO_UWB; /* Register speex. */ - if (pjsua.clock_rate >= 16000) + if (pjsua.has_wb) option &= ~(PJMEDIA_SPEEX_NO_WB); - if (pjsua.clock_rate >= 32000) + if (pjsua.has_uwb) option &= ~(PJMEDIA_SPEEX_NO_UWB); status = pjmedia_codec_speex_init(pjsua.med_endpt, option, diff --git a/pjsip/src/pjsua-lib/pjsua_settings.c b/pjsip/src/pjsua-lib/pjsua_settings.c index a5013bfe..b4d52e53 100644 --- a/pjsip/src/pjsua-lib/pjsua_settings.c +++ b/pjsip/src/pjsua-lib/pjsua_settings.c @@ -86,6 +86,7 @@ static void usage(void) 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 (" --clock-rate=N Override sound device clock rate"); puts (" --null-audio Use NULL audio device"); puts (" --no-mic Disable microphone device"); puts (" --play-file=file Play WAV file in conference bridge"); @@ -226,7 +227,7 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) OPT_USE_STUN1, OPT_USE_STUN2, 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_AUTO_CONF, OPT_CLOCK_RATE, OPT_PLAY_FILE, OPT_WB, OPT_UWB, OPT_RTP_PORT, OPT_ADD_CODEC, OPT_COMPLEXITY, OPT_QUALITY, OPT_NEXT_ACCOUNT, OPT_NEXT_CRED, OPT_MAX_CALLS, OPT_UAS_REFRESH, @@ -241,6 +242,7 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) { "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}, { "local-port", 1, 0, OPT_LOCAL_PORT}, @@ -351,11 +353,20 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) break; case OPT_WB: - pjsua.clock_rate = 16000; + pjsua.has_wb = 1; break; case OPT_UWB: - pjsua.clock_rate = 32000; + 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"); + return PJ_EINVAL; + } + pjsua.clock_rate = (int)lval; break; case OPT_LOCAL_PORT: /* local-port */ @@ -573,6 +584,12 @@ pj_status_t pjsua_parse_args(int argc, char *argv[]) return PJ_EINVAL; } + /* 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; + return PJ_SUCCESS; } @@ -905,11 +922,17 @@ int pjsua_dump_settings(char *buf, pj_size_t max) pj_strcat2(&cfg, line); } /* Media clock rate. */ - if (pjsua.clock_rate >= 32000) + if (pjsua.has_uwb) pj_strcat2(&cfg, "--uwb\n"); - else if (pjsua.clock_rate >= 16000) + + if (pjsua.has_wb) pj_strcat2(&cfg, "--wb\n"); + pj_ansi_sprintf(line, "--clock-rate %d\n", + pjsua.clock_rate); + pj_strcat2(&cfg, line); + + /* Encoding quality and complexity */ pj_ansi_sprintf(line, "--quality %d\n", pjsua.quality); |