Index: /pjproject/trunk/pjmedia/include/pjmedia/config.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/config.h	(revision 2006)
+++ /pjproject/trunk/pjmedia/include/pjmedia/config.h	(revision 2007)
@@ -84,8 +84,12 @@
 
 /**
- * Specify PortAudio maximum buffering latency, in milliseconds.
- */
-#ifndef PJMEDIA_PASOUND_MAX_LATENCY
-#   define PJMEDIA_PASOUND_MAX_LATENCY	    100
+ * Specify sound device latency default, in milisecond.
+ */
+#ifndef PJMEDIA_SND_DEFAULT_REC_LATENCY
+#   define PJMEDIA_SND_DEFAULT_REC_LATENCY  10
+#endif
+
+#ifndef PJMEDIA_SND_DEFAULT_PLAY_LATENCY
+#   define PJMEDIA_SND_DEFAULT_PLAY_LATENCY 100
 #endif
 
Index: /pjproject/trunk/pjmedia/include/pjmedia/sound.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/sound.h	(revision 2006)
+++ /pjproject/trunk/pjmedia/include/pjmedia/sound.h	(revision 2007)
@@ -152,4 +152,26 @@
  */
 PJ_DECL(const pjmedia_snd_dev_info*) pjmedia_snd_get_dev_info(unsigned index);
+
+
+/**
+ * Set sound device latency, this function must be called before sound device
+ * opened, or otherwise default latency setting will be used, @see
+ * PJMEDIA_SND_DEFAULT_REC_LATENCY & PJMEDIA_SND_DEFAULT_PLAY_LATENCY.
+ *
+ * Choosing latency value is not straightforward, it should accomodate both 
+ * minimum latency and stability. Lower latency tends to cause sound device 
+ * less reliable (producing audio dropouts) on CPU load disturbance. Moreover,
+ * the best latency setting may vary based on many aspects, e.g: sound card, 
+ * CPU, OS, kernel, etc.
+ *
+ * @param input_latency	    The latency of input device, in ms, set to 0
+ *			    for default PJMEDIA_SND_DEFAULT_REC_LATENCY.
+ * @param output_latency    The latency of output device, in ms, set to 0
+ *			    for default PJMEDIA_SND_DEFAULT_PLAY_LATENCY.
+ *
+ * @return		    PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjmedia_snd_set_latency(unsigned input_latency, 
+					     unsigned output_latency);
 
 
Index: /pjproject/trunk/pjmedia/src/pjmedia/dsound.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/dsound.c	(revision 2006)
+++ /pjproject/trunk/pjmedia/src/pjmedia/dsound.c	(revision 2007)
@@ -60,4 +60,8 @@
 static int snd_init_count;
 
+/* Latency settings */
+static unsigned snd_input_latency  = PJMEDIA_SND_DEFAULT_REC_LATENCY;
+static unsigned snd_output_latency = PJMEDIA_SND_DEFAULT_PLAY_LATENCY;
+
 
 /* Individual DirectSound capture/playback stream descriptor */
@@ -987,4 +991,20 @@
 
 
+/*
+ * Set sound latency.
+ */
+PJ_DEF(pj_status_t) pjmedia_snd_set_latency(unsigned input_latency, 
+					    unsigned output_latency)
+{
+    PJ_TODO(APPLY_LATENCY_SETTINGS_ON_DSOUND);
+
+    snd_input_latency  = (input_latency == 0)? 
+			 PJMEDIA_SND_DEFAULT_REC_LATENCY : input_latency;
+    snd_output_latency = (output_latency == 0)? 
+			 PJMEDIA_SND_DEFAULT_PLAY_LATENCY : output_latency;
+
+    return PJ_SUCCESS;
+}
+
 #endif	/* PJMEDIA_SOUND_IMPLEMENTATION */
 
Index: /pjproject/trunk/pjmedia/src/pjmedia/nullsound.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/nullsound.c	(revision 2006)
+++ /pjproject/trunk/pjmedia/src/pjmedia/nullsound.c	(revision 2007)
@@ -182,3 +182,15 @@
 }
 
+/*
+ * Set sound latency.
+ */
+PJ_DEF(pj_status_t) pjmedia_snd_set_latency(unsigned input_latency, 
+					    unsigned output_latency)
+{
+    /* Nothing to do */
+    PJ_UNUSED_ARG(input_latency);
+    PJ_UNUSED_ARG(output_latency);
+    return PJ_SUCCESS;
+}
+
 #endif	/* PJMEDIA_SOUND_IMPLEMENTATION */
Index: /pjproject/trunk/pjmedia/src/pjmedia/pasound.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/pasound.c	(revision 2006)
+++ /pjproject/trunk/pjmedia/src/pjmedia/pasound.c	(revision 2007)
@@ -29,7 +29,9 @@
 #define THIS_FILE	"pasound.c"
 
-#define MAX_LATENCY	(PJMEDIA_PASOUND_MAX_LATENCY / 1000.0)
-
 static int snd_init_count;
+
+/* Latency settings */
+static unsigned snd_input_latency  = PJMEDIA_SND_DEFAULT_REC_LATENCY;
+static unsigned snd_output_latency = PJMEDIA_SND_DEFAULT_PLAY_LATENCY;
 
 static struct snd_mgr
@@ -562,7 +564,5 @@
     inputParam.hostApiSpecificStreamInfo = NULL;
     inputParam.sampleFormat = sampleFormat;
-    inputParam.suggestedLatency = paDevInfo->defaultLowInputLatency;
-    if (inputParam.suggestedLatency > MAX_LATENCY)
-	inputParam.suggestedLatency = MAX_LATENCY;
+    inputParam.suggestedLatency = snd_input_latency / 1000.0;
 
     paHostApiInfo = Pa_GetHostApiInfo(paDevInfo->hostApi);
@@ -664,7 +664,5 @@
     outputParam.hostApiSpecificStreamInfo = NULL;
     outputParam.sampleFormat = sampleFormat;
-    outputParam.suggestedLatency = paDevInfo->defaultLowOutputLatency;
-    if (outputParam.suggestedLatency > MAX_LATENCY)
-	outputParam.suggestedLatency = MAX_LATENCY;
+    outputParam.suggestedLatency = snd_output_latency / 1000.0;
 
     paHostApiInfo = Pa_GetHostApiInfo(paDevInfo->hostApi);
@@ -795,7 +793,5 @@
     inputParam.hostApiSpecificStreamInfo = NULL;
     inputParam.sampleFormat = sampleFormat;
-    inputParam.suggestedLatency = paRecDevInfo->defaultLowInputLatency;
-    if (inputParam.suggestedLatency > MAX_LATENCY)
-	inputParam.suggestedLatency = MAX_LATENCY;
+    inputParam.suggestedLatency = snd_input_latency / 1000.0;
 
     paRecHostApiInfo = Pa_GetHostApiInfo(paRecDevInfo->hostApi);
@@ -806,7 +802,5 @@
     outputParam.hostApiSpecificStreamInfo = NULL;
     outputParam.sampleFormat = sampleFormat;
-    outputParam.suggestedLatency = paPlayDevInfo->defaultLowOutputLatency;
-    if (outputParam.suggestedLatency > MAX_LATENCY)
-	outputParam.suggestedLatency = MAX_LATENCY;
+    outputParam.suggestedLatency = snd_output_latency / 1000.0;
 
     paPlayHostApiInfo = Pa_GetHostApiInfo(paPlayDevInfo->hostApi);
@@ -1013,4 +1007,17 @@
 }
 
+/*
+ * Set sound latency.
+ */
+PJ_DEF(pj_status_t) pjmedia_snd_set_latency(unsigned input_latency, 
+					    unsigned output_latency)
+{
+    snd_input_latency  = (input_latency == 0)? 
+			 PJMEDIA_SND_DEFAULT_REC_LATENCY : input_latency;
+    snd_output_latency = (output_latency == 0)? 
+			 PJMEDIA_SND_DEFAULT_PLAY_LATENCY : output_latency;
+
+    return PJ_SUCCESS;
+}
 
 #endif	/* PJMEDIA_SOUND_IMPLEMENTATION */
Index: /pjproject/trunk/pjmedia/src/pjmedia/rtcp_xr.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/rtcp_xr.c	(revision 2006)
+++ /pjproject/trunk/pjmedia/src/pjmedia/rtcp_xr.c	(revision 2007)
@@ -327,13 +327,11 @@
 	 * is taken to be totally around 30ms + sound device latency.
 	 */
-	est_extra_delay = 30 + 
-#if PJMEDIA_SOUND_IMPLEMENTATION==PJMEDIA_SOUND_PORTAUDIO_SOUND
-			  PJMEDIA_PASOUND_MAX_LATENCY
-#elif PJMEDIA_SOUND_IMPLEMENTATION==PJMEDIA_SOUND_NULL_SOUND
-			  0
-#else
-			  (PJMEDIA_SOUND_BUFFER_COUNT * 15)
+	est_extra_delay = 30;
+
+#if PJMEDIA_SOUND_IMPLEMENTATION!=PJMEDIA_SOUND_NULL_SOUND
+	est_extra_delay += PJMEDIA_SND_DEFAULT_REC_LATENCY + 
+			   PJMEDIA_SND_DEFAULT_PLAY_LATENCY;
 #endif
-			  ;
+
 	sess->stat.rx.voip_mtc.end_sys_delay = (pj_uint16_t)
 				 (sess->stat.rx.voip_mtc.rnd_trip_delay / 2 +
Index: /pjproject/trunk/pjmedia/src/pjmedia/symbian_sound.cpp
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/symbian_sound.cpp	(revision 2006)
+++ /pjproject/trunk/pjmedia/src/pjmedia/symbian_sound.cpp	(revision 2007)
@@ -928,2 +928,14 @@
 }
 
+
+/*
+ * Set sound latency.
+ */
+PJ_DEF(pj_status_t) pjmedia_snd_set_latency(unsigned input_latency, 
+					    unsigned output_latency)
+{
+    /* Nothing to do */
+    PJ_UNUSED_ARG(input_latency);
+    PJ_UNUSED_ARG(output_latency);
+    return PJ_SUCCESS;
+}
Index: /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 2006)
+++ /pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 2007)
@@ -86,4 +86,5 @@
 
     int			    capture_dev, playback_dev;
+    unsigned		    capture_lat, playback_lat;
 } app_config;
 
@@ -195,4 +196,6 @@
     puts  ("  --capture-dev=id    Audio capture device ID (default=-1)");
     puts  ("  --playback-dev=id   Audio playback device ID (default=-1)");
+    puts  ("  --capture-lat=N     Audio capture latency, in ms (default=10)");
+    puts  ("  --playback-lat=N    Audio playback latency, in ms (default=100)");
 
     puts  ("");
@@ -253,4 +256,6 @@
     cfg->capture_dev = PJSUA_INVALID_ID;
     cfg->playback_dev = PJSUA_INVALID_ID;
+    cfg->capture_lat = PJMEDIA_SND_DEFAULT_REC_LATENCY;
+    cfg->playback_lat = PJMEDIA_SND_DEFAULT_PLAY_LATENCY;
 
     for (i=0; i<PJ_ARRAY_SIZE(cfg->acc_cfg); ++i)
@@ -414,4 +419,5 @@
 	   OPT_TLS_NEG_TIMEOUT,
 	   OPT_CAPTURE_DEV, OPT_PLAYBACK_DEV,
+	   OPT_CAPTURE_LAT, OPT_PLAYBACK_LAT,
 	   OPT_AUTO_UPDATE_NAT,OPT_USE_COMPACT_FORM,OPT_DIS_CODEC
     };
@@ -500,4 +506,6 @@
 	{ "capture-dev",    1, 0, OPT_CAPTURE_DEV},
 	{ "playback-dev",   1, 0, OPT_PLAYBACK_DEV},
+	{ "capture-lat",    1, 0, OPT_CAPTURE_LAT},
+	{ "playback-lat",   1, 0, OPT_PLAYBACK_LAT},
 	{ NULL, 0, 0, 0}
     };
@@ -1076,4 +1084,12 @@
 	case OPT_PLAYBACK_DEV:
 	    cfg->playback_dev = atoi(pj_optarg);
+	    break;
+
+	case OPT_CAPTURE_LAT:
+	    cfg->capture_lat = atoi(pj_optarg);
+	    break;
+
+	case OPT_PLAYBACK_LAT:
+	    cfg->playback_lat = atoi(pj_optarg);
 	    break;
 
@@ -1472,4 +1488,14 @@
     if (config->playback_dev != PJSUA_INVALID_ID) {
 	pj_ansi_sprintf(line, "--playback-dev %d\n", config->playback_dev);
+	pj_strcat2(&cfg, line);
+    }
+
+    /* Sound device latency */
+    if (config->capture_lat != PJMEDIA_SND_DEFAULT_REC_LATENCY) {
+	pj_ansi_sprintf(line, "--capture-lat %d\n", config->capture_lat);
+	pj_strcat2(&cfg, line);
+    }
+    if (config->playback_dev != PJMEDIA_SND_DEFAULT_PLAY_LATENCY) {
+	pj_ansi_sprintf(line, "--playback-lat %d\n", config->playback_lat);
 	pj_strcat2(&cfg, line);
     }
@@ -3714,4 +3740,7 @@
 	goto on_error;
 
+    /* Set sound device latency */
+    pjmedia_snd_set_latency(app_config.capture_lat, app_config.playback_lat);
+
     /* Use null sound device? */
 #ifndef STEREO_DEMO
