Index: pjproject/trunk/pjmedia/src/pjmedia/echo_common.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/echo_common.c	(revision 2728)
+++ pjproject/trunk/pjmedia/src/pjmedia/echo_common.c	(revision 2747)
@@ -20,5 +20,4 @@
 
 #include <pjmedia/echo.h>
-#include <pjmedia/delaybuf.h>
 #include <pjmedia/errno.h>
 #include <pj/assert.h>
@@ -51,6 +50,4 @@
     struct frame     lat_buf;	    /* Frame queue for delayed playback	    */
     struct frame     lat_free;	    /* Free frame list.			    */
-
-    pjmedia_delay_buf	*delay_buf;
 };
 
@@ -147,4 +144,5 @@
     pjmedia_echo_state *ec;
     pj_status_t status;
+    unsigned i;
 
     /* Create new pool and instantiate and init the EC */
@@ -192,30 +190,15 @@
     /* Create latency buffers */
     ptime = samples_per_frame * 1000 / clock_rate;
-    if (latency_ms == 0) {
-	/* Give at least one frame delay to simplify programming */
+    /* Give at least one frame delay to simplify programming */
+    if (latency_ms < ptime) {
 	latency_ms = ptime;
     }
     ec->lat_target_cnt = latency_ms / ptime;
-    if (ec->lat_target_cnt != 0) {
-	unsigned i;
-	for (i=0; i < ec->lat_target_cnt; ++i)  {
-	    struct frame *frm;
-
-	    frm = (struct frame*) pj_pool_alloc(pool, (samples_per_frame<<1) +
-						      sizeof(struct frame));
-	    pj_list_push_back(&ec->lat_free, frm);
-	}
-    } else {
-	ec->lat_ready = PJ_TRUE;
-    }
-
-    /* Create delay buffer to compensate drifts */
-    status = pjmedia_delay_buf_create(ec->pool, ec->obj_name, clock_rate, 
-				      samples_per_frame, channel_count,
-				      (PJMEDIA_SOUND_BUFFER_COUNT+1) * ptime,
-				      0, &ec->delay_buf);
-    if (status != PJ_SUCCESS) {
-	pj_pool_release(pool);
-	return status;
+    for (i=0; i < ec->lat_target_cnt; ++i)  {
+	struct frame *frm;
+
+	frm = (struct frame*) pj_pool_alloc(pool, (samples_per_frame<<1) +
+						  sizeof(struct frame));
+	pj_list_push_back(&ec->lat_free, frm);
     }
 
@@ -241,9 +224,4 @@
     (*echo->op->ec_destroy)(echo->state);
 
-    if (echo->delay_buf) {
-	pjmedia_delay_buf_destroy(echo->delay_buf);
-	echo->delay_buf = NULL;
-    }
-
     pj_pool_release(echo->pool);
     return PJ_SUCCESS;
@@ -263,5 +241,4 @@
     }
     echo->lat_ready = PJ_FALSE;
-    pjmedia_delay_buf_reset(echo->delay_buf);
     echo->op->ec_reset(echo->state);
     return PJ_SUCCESS;
@@ -275,29 +252,24 @@
 					   pj_int16_t *play_frm )
 {
-    if (!echo->lat_ready) {
+    struct frame *frm;
+
+    if (echo->lat_ready) {
+	frm = echo->lat_buf.next;
+	pj_list_erase(frm);
+    } else {
 	/* We've not built enough latency in the buffer, so put this frame
 	 * in the latency buffer list.
 	 */
-	struct frame *frm;
-
+	frm = echo->lat_free.prev;
+	pj_list_erase(frm);
 	if (pj_list_empty(&echo->lat_free)) {
 	    echo->lat_ready = PJ_TRUE;
 	    PJ_LOG(5,(echo->obj_name, "Latency bufferring complete"));
-	    pjmedia_delay_buf_put(echo->delay_buf, play_frm);
-	    return PJ_SUCCESS;
 	}
-	    
-	frm = echo->lat_free.prev;
-	pj_list_erase(frm);
-
-	pjmedia_copy_samples(frm->buf, play_frm, echo->samples_per_frame);
-	pj_list_push_back(&echo->lat_buf, frm);
-
-    } else {
-	/* Latency buffer is ready (full), so we put this frame in the
-	 * delay buffer.
-	 */
-	pjmedia_delay_buf_put(echo->delay_buf, play_frm);
-    }
+    }
+
+    /* Put the incoming frame into the end of latency buffer */
+    pjmedia_copy_samples(frm->buf, play_frm, echo->samples_per_frame);
+    pj_list_push_back(&echo->lat_buf, frm);
 
     return PJ_SUCCESS;
@@ -314,5 +286,5 @@
 {
     struct frame *oldest_frm;
-    pj_status_t status, rc;
+    pj_status_t status;
 
     if (!echo->lat_ready) {
@@ -324,5 +296,4 @@
     /* Retrieve oldest frame from the latency buffer */
     oldest_frm = echo->lat_buf.next;
-    pj_list_erase(oldest_frm);
 
     /* Cancel echo using this reference frame */
@@ -330,14 +301,4 @@
 				 options, NULL);
 
-    /* Move one frame from delay buffer to the latency buffer. */
-    rc = pjmedia_delay_buf_get(echo->delay_buf, oldest_frm->buf);
-    if (rc != PJ_SUCCESS) {
-	/* Ooops.. no frame! */
-	PJ_LOG(5,(echo->obj_name, 
-		  "No frame from delay buffer. This will upset EC later"));
-	pjmedia_zero_samples(oldest_frm->buf, echo->samples_per_frame);
-    }
-    pj_list_push_back(&echo->lat_buf, oldest_frm);
-    
     return status;
 }
