Index: /pjproject/trunk/pjmedia/include/pjmedia/jbuf.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/jbuf.h	(revision 2316)
+++ /pjproject/trunk/pjmedia/include/pjmedia/jbuf.h	(revision 2317)
@@ -150,12 +150,14 @@
  *
  * @param jb		The jitter buffer.
- * @param prefetch	The prefetch value to be applied to the jitter
- *			buffer.
+ * @param prefetch	The initial prefetch value to be applied to the
+ *			jitter buffer. Setting this to other than 0 will
+ *			activate prefetch buffering, a jitter buffer feature
+ *			that each time it gets empty, it won't return a 
+ *			normal frame until its size reaches the number
+ *			specified here.
  * @param min_prefetch	The minimum delay that must be applied to each
- *			incoming packets, in number of frames. The
- *			default value is zero.
+ *			incoming packets, in number of frames.
  * @param max_prefetch	The maximum allowable value for prefetch delay,
- *			in number of frames. The default value is equal
- *			to the size of the jitter buffer.
+ *			in number of frames.
  *
  * @return		PJ_SUCCESS on success.
Index: /pjproject/trunk/pjmedia/src/pjmedia/jbuf.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/jbuf.c	(revision 2316)
+++ /pjproject/trunk/pjmedia/src/pjmedia/jbuf.c	(revision 2317)
@@ -33,5 +33,4 @@
 #define SAFE_SHRINKING_DIFF	1
 #define MIN_SHRINK_GAP_MSEC	200
-#define USE_PREFETCH_BUFFERING	0
 
 typedef struct jb_framelist_t
@@ -67,4 +66,5 @@
 					  // (at the beginning of the framelist->flist_buffer operation)
     int		    jb_prefetch_cnt;	  // prefetch counter
+    int		    jb_def_prefetch;	  // Default prefetch
     int		    jb_min_prefetch;	  // Minimum allowable prefetch
     int		    jb_max_prefetch;	  // Maximum allowable prefetch
@@ -79,4 +79,5 @@
 #define JB_STATUS_INITIALIZING	0
 #define JB_STATUS_PROCESSING	1
+#define JB_STATUS_PREFETCHING	2
 
 /* Enabling this would log the jitter buffer state about once per 
@@ -344,5 +345,5 @@
 
     jb->jb_min_prefetch = jb->jb_max_prefetch = 
-	jb->jb_prefetch = prefetch;
+	jb->jb_prefetch = jb->jb_def_prefetch = prefetch;
 
     return PJ_SUCCESS;
@@ -365,5 +366,5 @@
 		     PJ_EINVAL);
 
-    jb->jb_prefetch = prefetch;
+    jb->jb_prefetch = jb->jb_def_prefetch = prefetch;
     jb->jb_min_prefetch = min_prefetch;
     jb->jb_max_prefetch = max_prefetch;
@@ -423,11 +424,11 @@
 	    if (jb->jb_stable_hist > STABLE_HISTORY_LIMIT) {
 		
+		diff = (jb->jb_prefetch - jb->jb_max_hist_level) / 3;
+
+		if (diff < 1)
+		    diff = 1;
+
 		/* Update max_hist_level. */
 		jb->jb_max_hist_level = jb->jb_prefetch;
-
-		diff = (jb->jb_prefetch - jb->jb_max_hist_level) / 3;
-
-		if (diff < 1)
-		    diff = 1;
 
 		jb->jb_prefetch -= diff;
@@ -542,6 +543,21 @@
 	}
 
-	if (jb->jb_prefetch_cnt < jb->jb_prefetch)	
+	if (jb->jb_prefetch_cnt < jb->jb_prefetch) {
 	    jb->jb_prefetch_cnt += seq_diff;
+	    
+	    TRACE__((jb->name.ptr, "PUT prefetch_cnt=%d/%d", 
+		     jb->jb_prefetch_cnt, jb->jb_prefetch));
+
+	    if (jb->jb_status == JB_STATUS_PREFETCHING && 
+		jb->jb_prefetch_cnt >= jb->jb_prefetch)
+	    {
+		int diff, cur_size;
+
+		cur_size = jb_framelist_size(&jb->jb_framelist);
+		jb->jb_status = JB_STATUS_PROCESSING;
+	    }
+	}
+
+
 
 	if (discarded)
@@ -583,11 +599,13 @@
     jbuf_update(jb, JB_OP_GET);
 
-#if USE_PREFETCH_BUFFERING
-
     if (jb_framelist_size(&jb->jb_framelist) == 0) {
 	jb->jb_prefetch_cnt = 0;
-    }
-
-    if ((jb->jb_prefetch_cnt < jb->jb_prefetch)) {
+	if (jb->jb_def_prefetch)
+	    jb->jb_status = JB_STATUS_PREFETCHING;
+    }
+
+    if (jb->jb_status == JB_STATUS_PREFETCHING && 
+	jb->jb_prefetch_cnt < jb->jb_prefetch)
+    {
 	/* Can't return frame because jitter buffer is filling up
 	 * minimum prefetch.
@@ -602,8 +620,8 @@
 	    *size = 0;
 
+	TRACE__((jb->name.ptr, "GET prefetch_cnt=%d/%d",
+		 jb->jb_prefetch_cnt, jb->jb_prefetch));
 	return;
     }
-
-#endif
 
     /* Retrieve a frame from frame list */
Index: /pjproject/trunk/pjmedia/src/pjmedia/stream.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/stream.c	(revision 2316)
+++ /pjproject/trunk/pjmedia/src/pjmedia/stream.c	(revision 2317)
@@ -1670,5 +1670,5 @@
 	jb_max = 500 / stream->codec_param.info.frm_ptime;
 
-    if (info->jb_min_pre >= 0)
+    if (info->jb_min_pre > 0)
 	jb_min_pre = info->jb_min_pre;
     else
@@ -1682,9 +1682,9 @@
 	jb_max_pre = jb_max * 4 / 5;
 
-    if (info->jb_init >= 0)
+    if (info->jb_init > 0)
 	jb_init = info->jb_init;
     else
 	//jb_init = (jb_min_pre + jb_max_pre) / 2;
-	jb_init = jb_min_pre;
+	jb_init = 0;
 
 
