Ticket #393: Added configuration to set basic audio frame length to minimize audio latency in pjsua-lib

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@1482 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h
index 062943b..fad7917 100644
--- a/pjsip/include/pjsua-lib/pjsua.h
+++ b/pjsip/include/pjsua-lib/pjsua.h
@@ -1744,7 +1744,7 @@
  * either "sip" or "sips".
  */
 #ifndef PJSUA_SECURE_SCHEME
-#   define PJSUA_SECURE_SCHEME		"sip"
+#   define PJSUA_SECURE_SCHEME		"sips"
 #endif
 
 
@@ -3466,6 +3466,16 @@
     unsigned		clock_rate;
 
     /**
+     * Specify audio frame ptime. The value here will affect the 
+     * samples per frame of both the sound device and the conference
+     * bridge. Specifying lower ptime will normally reduce the
+     * latency.
+     *
+     * Default: 20 (miliseconds)
+     */
+    unsigned		audio_frame_ptime;
+
+    /**
      * Specify maximum number of media ports to be created in the
      * conference bridge. Since all media terminate in the bridge
      * (calls, file player, file recorder, etc), the value must be
@@ -3505,7 +3515,7 @@
     unsigned		quality;
 
     /**
-     * Specify default ptime.
+     * Specify default codec ptime.
      *
      * Default: 0 (codec specific)
      */
diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c
index f34ac36..8061760 100644
--- a/pjsip/src/pjsua-lib/pjsua_core.c
+++ b/pjsip/src/pjsua-lib/pjsua_core.c
@@ -154,6 +154,7 @@
     pj_bzero(cfg, sizeof(*cfg));
 
     cfg->clock_rate = PJSUA_DEFAULT_CLOCK_RATE;
+    cfg->audio_frame_ptime = 10;
     cfg->max_media_ports = 32;
     cfg->has_ioqueue = PJ_TRUE;
     cfg->thread_cnt = 1;
@@ -1880,8 +1881,11 @@
     pj_ansi_strcpy(url, c_url);
 
     p = pjsip_parse_uri(pool, url, len, 0);
-    if (!p || pj_stricmp2(pjsip_uri_get_scheme(p), "sip") != 0)
+    if (!p || (pj_stricmp2(pjsip_uri_get_scheme(p), "sip") != 0 &&
+	       pj_stricmp2(pjsip_uri_get_scheme(p), "sips") != 0))
+    {
 	p = NULL;
+    }
 
     pj_pool_release(pool);
     return p ? 0 : -1;
diff --git a/pjsip/src/pjsua-lib/pjsua_media.c b/pjsip/src/pjsua-lib/pjsua_media.c
index 9b847b3..0f4547b 100644
--- a/pjsip/src/pjsua-lib/pjsua_media.c
+++ b/pjsip/src/pjsua-lib/pjsua_media.c
@@ -22,8 +22,6 @@
 
 #define THIS_FILE		"pjsua_media.c"
 
-#define PTIME		    20
-#define FPS		    (1000/PTIME)
 #define DEFAULT_RTP_PORT    4000
 
 /* Next RTP port to be used */
@@ -155,7 +153,8 @@
      * reference.
      */
     pjsua_var.mconf_cfg.samples_per_frame = pjsua_var.media_cfg.clock_rate * 
-					    PTIME / 1000;
+					    pjsua_var.media_cfg.audio_frame_ptime / 
+					    1000;
     pjsua_var.mconf_cfg.channel_count = 1;
     pjsua_var.mconf_cfg.bits_per_sample = 16;
 
@@ -1648,16 +1647,18 @@
     /* Attempts to open the sound device with different clock rates */
     for (i=0; i<PJ_ARRAY_SIZE(clock_rates); ++i) {
 	char errmsg[PJ_ERR_MSG_SIZE];
+	unsigned fps;
 
 	PJ_LOG(4,(THIS_FILE, 
 		  "pjsua_set_snd_dev(): attempting to open devices "
 		  "@%d Hz", clock_rates[i]));
 
 	/* Create the sound device. Sound port will start immediately. */
+	fps = 1000 / pjsua_var.media_cfg.audio_frame_ptime;
 	status = pjmedia_snd_port_create(pjsua_var.pool, capture_dev,
 					 playback_dev, 
 					 clock_rates[i], 1,
-					 clock_rates[i]/FPS,
+					 clock_rates[i]/fps,
 					 16, 0, &pjsua_var.snd_port);
 
 	if (status == PJ_SUCCESS) {