Index: pjproject/trunk/pjmedia/src/test/mips_test.c
===================================================================
--- pjproject/trunk/pjmedia/src/test/mips_test.c	(revision 2191)
+++ pjproject/trunk/pjmedia/src/test/mips_test.c	(revision 2192)
@@ -423,5 +423,5 @@
 	    p = buf+c;
 	    for (i=0; i<PJ_ARRAY_SIZE(ref_signal); ++i) {
-		*p = ref_signal[i] * pct_level / 100;
+		*p = (pj_int16_t)(ref_signal[i] * pct_level / 100);
 		p += channel_count;
 	    }
@@ -533,5 +533,5 @@
 {
     return init_conf_port(1, pool, clock_rate, channel_count, 
-			  samples_per_frame, 0, te);
+			  samples_per_frame, flags, te);
 }
 
@@ -547,5 +547,5 @@
 {
     return init_conf_port(2, pool, clock_rate, channel_count, 
-			  samples_per_frame, 0, te);
+			  samples_per_frame, flags, te);
 }
 
@@ -560,5 +560,5 @@
 {
     return init_conf_port(4, pool, clock_rate, channel_count, 
-			  samples_per_frame, 0, te);
+			  samples_per_frame, flags, te);
 }
 
@@ -573,5 +573,5 @@
 {
     return init_conf_port(8, pool, clock_rate, channel_count, 
-			  samples_per_frame, 0, te);
+			  samples_per_frame, flags, te);
 }
 
@@ -585,6 +585,7 @@
 				      struct test_entry *te)
 {
+    PJ_UNUSED_ARG(flags);
     return init_conf_port(16, pool, clock_rate, channel_count, 
-			  samples_per_frame, 0, te);
+			  samples_per_frame, flags, te);
 }
 
@@ -603,4 +604,7 @@
     unsigned opt = 0;
     pj_status_t status;
+
+    PJ_UNUSED_ARG(flags);
+    PJ_UNUSED_ARG(te);
 
     if (!high_quality)
@@ -736,4 +740,7 @@
     pj_status_t status;
 
+    PJ_UNUSED_ARG(flags);
+    PJ_UNUSED_ARG(te);
+
     codec_id = pj_str((char*)codec);
     cp = PJ_POOL_ZALLOC_T(pool, struct codec_port);
@@ -959,4 +966,7 @@
     unsigned opt = 0;
     pj_status_t status;
+
+    PJ_UNUSED_ARG(flags);
+    PJ_UNUSED_ARG(te);
 
     wp = PJ_POOL_ZALLOC_T(pool, struct wsola_plc_port);
@@ -1131,4 +1141,7 @@
     pj_status_t status;
 
+    PJ_UNUSED_ARG(flags);
+    PJ_UNUSED_ARG(te);
+
     wp = PJ_POOL_ZALLOC_T(pool, struct wsola_discard_port);
     wp->discard_pct = discard_pct;
@@ -1250,4 +1263,7 @@
     pjmedia_port *gen_port, *ec_port;
     pj_status_t status;
+
+    PJ_UNUSED_ARG(flags);
+    PJ_UNUSED_ARG(te);
 
     gen_port = create_gen_port(pool, clock_rate, channel_count, 
@@ -1389,4 +1405,7 @@
     pj_status_t status;
 
+    PJ_UNUSED_ARG(flags);
+    PJ_UNUSED_ARG(te);
+
     status = pjmedia_tonegen_create(pool, clock_rate, channel_count,
 				    samples_per_frame, 16, 
@@ -1396,10 +1415,10 @@
 
     pj_bzero(tones, sizeof(tones));
-    tones[0].freq1 = freq1;
-    tones[0].freq2 = freq2;
+    tones[0].freq1 = (short)freq1;
+    tones[0].freq2 = (short)freq2;
     tones[0].on_msec = 400;
     tones[0].off_msec = 0;
-    tones[1].freq1 = freq1;
-    tones[1].freq2 = freq2;
+    tones[1].freq1 = (short)freq1;
+    tones[1].freq2 = (short)freq2;
     tones[1].on_msec = 400;
     tones[1].off_msec = 100;
@@ -1484,4 +1503,6 @@
     pjmedia_stream_info si;
     pj_status_t status;
+
+    PJ_UNUSED_ARG(flags);
 
     codec_id = pj_str((char*)codec);
@@ -1749,4 +1770,225 @@
 			 clock_rate, channel_count,
 			 samples_per_frame, flags, te);
+}
+
+
+/***************************************************************************/
+/* Delay buffer */
+enum {DELAY_BUF_MAX_DELAY = 80};
+struct delaybuf_port
+{
+    pjmedia_port	 base;
+    pjmedia_delay_buf   *delaybuf;
+    pjmedia_port	*gen_port;
+    int			 drift_pct;
+};
+
+
+static pj_status_t delaybuf_get_frame(struct pjmedia_port *this_port, 
+				      pjmedia_frame *frame)
+{
+    struct delaybuf_port *dp = (struct delaybuf_port*)this_port;
+    pj_status_t status;
+
+    status = pjmedia_delay_buf_get(dp->delaybuf, (pj_int16_t*)frame->buf);
+    pj_assert(status == PJ_SUCCESS);
+
+    /* Additional GET when drift_pct is negative */
+    if (dp->drift_pct < 0) {
+	int rnd;
+	rnd = pj_rand() % 100;
+
+	if (rnd < -dp->drift_pct) {
+	    status = pjmedia_delay_buf_get(dp->delaybuf, (pj_int16_t*)frame->buf);
+	    pj_assert(status == PJ_SUCCESS);
+	}
+    }
+
+    return PJ_SUCCESS;
+}
+
+static pj_status_t delaybuf_put_frame(struct pjmedia_port *this_port, 
+				      const pjmedia_frame *frame)
+{
+    struct delaybuf_port *dp = (struct delaybuf_port*)this_port;
+    pj_status_t status;
+    pjmedia_frame f = *frame;
+
+    status = pjmedia_port_get_frame(dp->gen_port, &f);
+    pj_assert(status == PJ_SUCCESS);
+    status = pjmedia_delay_buf_put(dp->delaybuf, (pj_int16_t*)f.buf);
+    pj_assert(status == PJ_SUCCESS);
+
+    /* Additional PUT when drift_pct is possitive */
+    if (dp->drift_pct > 0) {
+	int rnd;
+	rnd = pj_rand() % 100;
+
+	if (rnd < dp->drift_pct) {
+	    status = pjmedia_port_get_frame(dp->gen_port, &f);
+	    pj_assert(status == PJ_SUCCESS);
+	    status = pjmedia_delay_buf_put(dp->delaybuf, (pj_int16_t*)f.buf);
+	    pj_assert(status == PJ_SUCCESS);
+	}
+    }
+
+    return PJ_SUCCESS;
+}
+
+static pj_status_t delaybuf_on_destroy(struct pjmedia_port *this_port)
+{
+    struct delaybuf_port *dp = (struct delaybuf_port*)this_port;
+    pjmedia_port_destroy(dp->gen_port);
+    pjmedia_delay_buf_destroy(dp->delaybuf);
+    return PJ_SUCCESS;
+}
+
+static pjmedia_port* create_delaybuf(int drift_pct,
+				     pj_pool_t *pool,
+				     unsigned clock_rate,
+				     unsigned channel_count,
+				     unsigned samples_per_frame,
+				     unsigned flags,
+				     struct test_entry *te)
+{
+    struct delaybuf_port *dp;
+    pj_str_t name = pj_str("delaybuf");
+    unsigned opt = 0;
+    pj_status_t status;
+
+    PJ_UNUSED_ARG(flags);
+    PJ_UNUSED_ARG(te);
+
+    dp = PJ_POOL_ZALLOC_T(pool, struct delaybuf_port);
+    dp->drift_pct = drift_pct;
+    dp->base.get_frame = &delaybuf_get_frame;
+    dp->base.put_frame = &delaybuf_put_frame;
+    dp->base.on_destroy = &delaybuf_on_destroy;
+    pjmedia_port_info_init(&dp->base.info, &name, 0x5678, clock_rate, 
+			   channel_count, 16, samples_per_frame);
+
+    status = pjmedia_delay_buf_create(pool, "mips_test", clock_rate, 
+				      samples_per_frame, channel_count, 
+				      DELAY_BUF_MAX_DELAY,
+				      opt, &dp->delaybuf);
+    if (status != PJ_SUCCESS)
+	return NULL;
+
+    dp->gen_port = create_gen_port(pool, clock_rate, channel_count, 
+				   samples_per_frame, 100);
+    if (dp->gen_port == NULL)
+	return NULL;
+
+    return &dp->base;
+}
+
+
+/* Delay buffer without drift */
+static pjmedia_port* delaybuf_0( pj_pool_t *pool,
+				  unsigned clock_rate,
+				  unsigned channel_count,
+				  unsigned samples_per_frame,
+				  unsigned flags,
+				  struct test_entry *te)
+{
+    return create_delaybuf(0, pool, clock_rate, channel_count, 
+			   samples_per_frame, flags, te);
+}
+
+
+/* Delay buffer with 2% drift */
+static pjmedia_port* delaybuf_p2( pj_pool_t *pool,
+				  unsigned clock_rate,
+				  unsigned channel_count,
+				  unsigned samples_per_frame,
+				  unsigned flags,
+				  struct test_entry *te)
+{
+    return create_delaybuf(2, pool, clock_rate, channel_count, 
+			   samples_per_frame, flags, te);
+}
+
+/* Delay buffer with 5% drift */
+static pjmedia_port* delaybuf_p5( pj_pool_t *pool,
+				  unsigned clock_rate,
+				  unsigned channel_count,
+				  unsigned samples_per_frame,
+				  unsigned flags,
+				  struct test_entry *te)
+{
+    return create_delaybuf(5, pool, clock_rate, channel_count, 
+			   samples_per_frame, flags, te);
+}
+
+/* Delay buffer with 10% drift */
+static pjmedia_port* delaybuf_p10(pj_pool_t *pool,
+				  unsigned clock_rate,
+				  unsigned channel_count,
+				  unsigned samples_per_frame,
+				  unsigned flags,
+				  struct test_entry *te)
+{
+    return create_delaybuf(10, pool, clock_rate, channel_count, 
+			   samples_per_frame, flags, te);
+}
+
+/* Delay buffer with 20% drift */
+static pjmedia_port* delaybuf_p20(pj_pool_t *pool,
+				  unsigned clock_rate,
+				  unsigned channel_count,
+				  unsigned samples_per_frame,
+				  unsigned flags,
+				  struct test_entry *te)
+{
+    return create_delaybuf(20, pool, clock_rate, channel_count, 
+			   samples_per_frame, flags, te);
+}
+
+/* Delay buffer with -2% drift */
+static pjmedia_port* delaybuf_n2( pj_pool_t *pool,
+				  unsigned clock_rate,
+				  unsigned channel_count,
+				  unsigned samples_per_frame,
+				  unsigned flags,
+				  struct test_entry *te)
+{
+    return create_delaybuf(-2, pool, clock_rate, channel_count, 
+			   samples_per_frame, flags, te);
+}
+
+/* Delay buffer with -5% drift */
+static pjmedia_port* delaybuf_n5( pj_pool_t *pool,
+				  unsigned clock_rate,
+				  unsigned channel_count,
+				  unsigned samples_per_frame,
+				  unsigned flags,
+				  struct test_entry *te)
+{
+    return create_delaybuf(-5, pool, clock_rate, channel_count, 
+			   samples_per_frame, flags, te);
+}
+
+/* Delay buffer with -10% drift */
+static pjmedia_port* delaybuf_n10(pj_pool_t *pool,
+				  unsigned clock_rate,
+				  unsigned channel_count,
+				  unsigned samples_per_frame,
+				  unsigned flags,
+				  struct test_entry *te)
+{
+    return create_delaybuf(-10, pool, clock_rate, channel_count, 
+			   samples_per_frame, flags, te);
+}
+
+/* Delay buffer with -20% drift */
+static pjmedia_port* delaybuf_n20(pj_pool_t *pool,
+				  unsigned clock_rate,
+				  unsigned channel_count,
+				  unsigned samples_per_frame,
+				  unsigned flags,
+				  struct test_entry *te)
+{
+    return create_delaybuf(-20, pool, clock_rate, channel_count, 
+			   samples_per_frame, flags, te);
 }
 
@@ -1869,4 +2111,13 @@
 	{ "WSOLA discard 20% excess", OP_GET, K8|K16, &wsola_discard_20},
 	{ "WSOLA discard 50% excess", OP_GET, K8|K16, &wsola_discard_50},
+	{ "Delay buffer", OP_GET_PUT, K8|K16, &delaybuf_0},
+	{ "Delay buffer - drift -2%", OP_GET_PUT, K8|K16, &delaybuf_n2},
+	{ "Delay buffer - drift -5%", OP_GET_PUT, K8|K16, &delaybuf_n5},
+	{ "Delay buffer - drift -10%", OP_GET_PUT, K8|K16, &delaybuf_n10},
+	{ "Delay buffer - drift -20%", OP_GET_PUT, K8|K16, &delaybuf_n20},
+	{ "Delay buffer - drift +2%", OP_GET_PUT, K8|K16, &delaybuf_p2},
+	{ "Delay buffer - drift +5%", OP_GET_PUT, K8|K16, &delaybuf_p5},
+	{ "Delay buffer - drift +10%", OP_GET_PUT, K8|K16, &delaybuf_p10},
+	{ "Delay buffer - drift +20%", OP_GET_PUT, K8|K16, &delaybuf_p20},
 	{ "echo canceller 100ms tail len", OP_GET_PUT, K8|K16, &ec_create_100},
 	{ "echo canceller 128ms tail len", OP_GET_PUT, K8|K16, &ec_create_128},
