Index: pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/config.h
===================================================================
--- pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/config.h	(revision 2470)
+++ pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/config.h	(revision 2471)
@@ -292,5 +292,5 @@
  */
 #ifndef PJMEDIA_FILE_PORT_BUFSIZE
-#   define PJMEDIA_FILE_PORT_BUFSIZE    4000
+#   define PJMEDIA_FILE_PORT_BUFSIZE		4000
 #endif
 
Index: pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/types.h
===================================================================
--- pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/types.h	(revision 2470)
+++ pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/types.h	(revision 2471)
@@ -186,14 +186,53 @@
 
 /**
- * Format identifier definition.
+ * This enumeration describes format ID. 
  */
 typedef enum pjmedia_format_id
 {
+    /**
+     * 16bit linear
+     */
     PJMEDIA_FORMAT_L16	    = 0,
+    
+    /**
+     * Alias for PJMEDIA_FORMAT_L16
+     */
+    PJMEDIA_FORMAT_PCM	    = PJMEDIA_FORMAT_L16,
+
+    /**
+     * G.711 ALAW
+     */
     PJMEDIA_FORMAT_PCMA	    = PJMEDIA_FORMAT_PACK('A', 'L', 'A', 'W'),
+
+    /**
+     * Alias for PJMEDIA_FORMAT_PCMA
+     */
+    PJMEDIA_FORMAT_ALAW	    = PJMEDIA_FORMAT_PCMA,
+
+    /**
+     * G.711 ULAW
+     */
     PJMEDIA_FORMAT_PCMU	    = PJMEDIA_FORMAT_PACK('u', 'L', 'A', 'W'),
+
+    /**
+     * Aliaw for PJMEDIA_FORMAT_PCMU
+     */
+    PJMEDIA_FORMAT_ULAW	    = PJMEDIA_FORMAT_PCMU,
+
+    /**
+     * AMR narrowband
+     */
     PJMEDIA_FORMAT_AMR	    = PJMEDIA_FORMAT_PACK(' ', 'A', 'M', 'R'),
+
+    /**
+     * ITU G.729
+     */
     PJMEDIA_FORMAT_G729	    = PJMEDIA_FORMAT_PACK('G', '7', '2', '9'),
+
+    /**
+     * Internet Low Bit-Rate Codec (ILBC)
+     */
     PJMEDIA_FORMAT_ILBC	    = PJMEDIA_FORMAT_PACK('I', 'L', 'B', 'C')
+
 } pjmedia_format_id;
 
Index: pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia-audiodev/wmme_dev.c
===================================================================
--- pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia-audiodev/wmme_dev.c	(revision 2470)
+++ pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia-audiodev/wmme_dev.c	(revision 2471)
@@ -45,6 +45,4 @@
 
 #define THIS_FILE			"wmme_dev.c"
-#define BITS_PER_SAMPLE			16
-#define BYTES_PER_SAMPLE		(BITS_PER_SAMPLE/8)
 
 
@@ -103,4 +101,6 @@
 
     void    		*buffer;	    /**< Temp. frame buffer.   */
+    pjmedia_format_id	 fmt_id;	    /**< Frame format	       */
+    pj_uint8_t		 silence_char;	    /**< Silence pattern       */
     unsigned             clock_rate;        /**< Clock rate.           */
     unsigned		 bytes_per_frame;   /**< Bytes per frame       */
@@ -456,4 +456,5 @@
     pj_bzero(wfx, sizeof(PCMWAVEFORMAT)); 
     if (prm->ext_fmt.id == PJMEDIA_FORMAT_L16) {
+	enum { BYTES_PER_SAMPLE = 2 };
 	wfx->wFormatTag = WAVE_FORMAT_PCM; 
 	wfx->nChannels = (pj_uint16_t)prm->channel_count;
@@ -463,5 +464,5 @@
 	wfx->nAvgBytesPerSec = prm->clock_rate * prm->channel_count * 
 			       BYTES_PER_SAMPLE;
-	wfx->wBitsPerSample = BITS_PER_SAMPLE;
+	wfx->wBitsPerSample = 16;
 
 	return PJ_SUCCESS;
@@ -495,4 +496,15 @@
 }
 
+/* Get format name */
+static const char *get_fmt_name(pj_uint32_t id)
+{
+    static char name[8];
+
+    if (id == PJMEDIA_FORMAT_L16)
+	return "l16";
+    pj_memcpy(name, &id, 4);
+    name[4] = '\0';
+    return name;
+}
 
 /* Internal: create WMME player device. */
@@ -527,7 +539,5 @@
     ptime = prm->samples_per_frame * 1000 / 
 	    (prm->clock_rate * prm->channel_count);
-    ptime = prm->samples_per_frame * 1000 / 
-	    (prm->clock_rate * prm->channel_count);
-    parent->bytes_per_frame = wfx.nAvgBytesPerSec / ptime;
+    parent->bytes_per_frame = wfx.nAvgBytesPerSec * ptime / 1000;
 
     /*
@@ -575,7 +585,9 @@
     /* Done setting up play device. */
     PJ_LOG(5, (THIS_FILE, 
-	       " WaveAPI Sound player \"%s\" initialized (clock_rate=%d, "
+	       " WaveAPI Sound player \"%s\" initialized ("
+	       "format=%s, clock_rate=%d, "
 	       "channel_count=%d, samples_per_frame=%d (%dms))",
 	       wf->dev_info[prm->play_id].info.name,
+	       get_fmt_name(prm->ext_fmt.id),
 	       prm->clock_rate, prm->channel_count, prm->samples_per_frame,
 	       prm->samples_per_frame * 1000 / prm->clock_rate));
@@ -613,5 +625,5 @@
     ptime = prm->samples_per_frame * 1000 / 
 	    (prm->clock_rate * prm->channel_count);
-    parent->bytes_per_frame = wfx.nAvgBytesPerSec / ptime;
+    parent->bytes_per_frame = wfx.nAvgBytesPerSec * ptime / 1000;
 
     /*
@@ -653,7 +665,9 @@
     /* Done setting up play device. */
     PJ_LOG(5,(THIS_FILE, 
-	" WaveAPI Sound recorder \"%s\" initialized (clock_rate=%d, "
+	" WaveAPI Sound recorder \"%s\" initialized "
+	"(format=%s, clock_rate=%d, "
 	"channel_count=%d, samples_per_frame=%d (%dms))",
 	wf->dev_info[prm->rec_id].info.name,
+	get_fmt_name(prm->ext_fmt.id),
 	prm->clock_rate, prm->channel_count, prm->samples_per_frame,
 	prm->samples_per_frame * 1000 / prm->clock_rate));
@@ -670,4 +684,7 @@
     unsigned eventCount;
     pj_status_t status = PJ_SUCCESS;
+    static unsigned rec_cnt, play_cnt;
+
+    rec_cnt = play_cnt = 0;
 
     eventCount = 0;
@@ -701,4 +718,11 @@
 	pjmedia_dir signalled_dir;
 
+	/* Swap */
+	if (eventCount==3) {
+	    HANDLE hTemp = events[2];
+	    events[2] = events[1];
+	    events[1] = hTemp;
+	}
+
 	rc = WaitForMultipleObjects(eventCount, events, FALSE, INFINITE);
 	if (rc < WAIT_OBJECT_0 || rc >= WAIT_OBJECT_0 + eventCount)
@@ -739,10 +763,10 @@
 		void *buffer = wmme_strm->WaveHdr[wmme_strm->dwBufIdx].lpData;
 		pjmedia_frame pcm_frame, *frame;
-		pj_bool_t has_frame = PJ_FALSE;
+		MMRESULT mr = MMSYSERR_NOERROR;
 
 		//PJ_LOG(5,(THIS_FILE, "Finished writing buffer %d", 
 		//	  wmme_strm->dwBufIdx));
 
-		if (strm->xfrm == NULL) {
+		if (strm->fmt_id == PJMEDIA_FORMAT_L16) {
 		    /* PCM mode */
 		    frame = &pcm_frame;
@@ -765,4 +789,5 @@
 
 		/* Get frame from application. */
+		PJ_LOG(5,(THIS_FILE, "xxx %u play_cb", play_cnt++));
 		status = (*strm->play_cb)(strm->user_data, frame);
 
@@ -770,13 +795,12 @@
 		    break;
 
-		if (strm->xfrm == NULL) {
+		if (strm->fmt_id == PJMEDIA_FORMAT_L16) {
 		    /* PCM mode */
 		    if (frame->type == PJMEDIA_FRAME_TYPE_NONE) {
 			pj_bzero(buffer, strm->bytes_per_frame);
-			has_frame = PJ_TRUE;
 		    } else if (frame->type == PJMEDIA_FRAME_TYPE_EXTENDED) {
 			pj_assert(!"Frame type not supported");
 		    } else if (frame->type == PJMEDIA_FRAME_TYPE_AUDIO) {
-			has_frame = PJ_TRUE;
+			/* Nothing to do */
 		    } else {
 			pj_assert(!"Frame type not supported");
@@ -785,5 +809,6 @@
 		    /* Codec mode */
 		    if (frame->type == PJMEDIA_FRAME_TYPE_NONE) {
-			/* Not supported */
+			pj_memset(buffer, strm->silence_char, 
+				  strm->bytes_per_frame);
 		    } else if (frame->type == PJMEDIA_FRAME_TYPE_EXTENDED) {
 			unsigned sz;
@@ -791,5 +816,9 @@
 							    buffer,
 							    strm->bytes_per_frame);
-			pj_assert(sz == strm->bytes_per_frame);
+			if (sz < strm->bytes_per_frame) {
+			    pj_memset((char*)buffer+sz,
+				      strm->silence_char,
+				      strm->bytes_per_frame - sz);
+			}
 		    } else {
 			pj_assert(!"Frame type not supported");
@@ -798,14 +827,10 @@
 
 		/* Write to the device. */
-		if (has_frame) {
-		    MMRESULT mr = MMSYSERR_NOERROR;
-
-		    mr = waveOutWrite(wmme_strm->hWave.Out, 
-				      &(wmme_strm->WaveHdr[wmme_strm->dwBufIdx]),
-				      sizeof(WAVEHDR));
-		    if (mr != MMSYSERR_NOERROR) {
-			status = CONVERT_MM_ERROR(mr);
-			break;
-		    }
+		mr = waveOutWrite(wmme_strm->hWave.Out, 
+				  &(wmme_strm->WaveHdr[wmme_strm->dwBufIdx]),
+				  sizeof(WAVEHDR));
+		if (mr != MMSYSERR_NOERROR) {
+		    status = CONVERT_MM_ERROR(mr);
+		    break;
 		}
 
@@ -864,5 +889,5 @@
 		*/
 	    
-		if (strm->xfrm == NULL) {
+		if (strm->fmt_id == PJMEDIA_FORMAT_L16) {
 		    /* PCM mode */
 		    if (cap_len < strm->bytes_per_frame)
@@ -909,4 +934,5 @@
 
 		/* Call callback */
+		PJ_LOG(5,(THIS_FILE, "xxx %u rec_cb", rec_cnt++));
 		status = (*strm->rec_cb)(strm->user_data, frame);
 		if (status != PJ_SUCCESS)
@@ -938,8 +964,20 @@
     pj_pool_t *pool;
     struct wmme_stream *strm;
+    pj_uint8_t silence_char;
     pj_status_t status;
 
-    /* Can only support 16bits per sample */
-    PJ_ASSERT_RETURN(param->bits_per_sample == BITS_PER_SAMPLE, PJ_EINVAL);
+    switch (param->ext_fmt.id) {
+    case PJMEDIA_FORMAT_L16:
+	silence_char = '\0';
+	break;
+    case PJMEDIA_FORMAT_ALAW:
+	silence_char = (pj_uint8_t)'\xd5';
+	break;
+    case PJMEDIA_FORMAT_ULAW:
+	silence_char = (pj_uint8_t)'\xff';
+	break;
+    default:
+	return PJMEDIA_EAUD_BADFORMAT;
+    }
 
     /* Create and Initialize stream descriptor */
@@ -955,14 +993,10 @@
     strm->play_cb = play_cb;
     strm->user_data = user_data;
+    strm->fmt_id = param->ext_fmt.id;
+    strm->silence_char = silence_char;
     strm->clock_rate = param->clock_rate;
     strm->samples_per_frame = param->samples_per_frame;
     strm->bits_per_sample = param->bits_per_sample;
     strm->channel_count = param->channel_count;
-    strm->buffer = pj_pool_alloc(pool, 
-				 param->samples_per_frame * BYTES_PER_SAMPLE);
-    if (!strm->buffer) {
-	pj_pool_release(pool);
-	return PJ_ENOMEM;
-    }
 
     /* Create player stream */
@@ -1014,11 +1048,15 @@
     }
 
+    strm->buffer = pj_pool_alloc(pool, strm->bytes_per_frame);
+    if (!strm->buffer) {
+	pj_pool_release(pool);
+	return PJ_ENOMEM;
+    }
+
     /* If format is extended, must create buffer for the extended frame. */
-    if (param->ext_fmt.id != PJMEDIA_FORMAT_L16) {
-	unsigned ptime = param->samples_per_frame * 1000 /
-			 (param->clock_rate * param->channel_count);
+    if (strm->fmt_id != PJMEDIA_FORMAT_L16) {
 	strm->xfrm_size = sizeof(pjmedia_frame_ext) + 
 			  32 * sizeof(pjmedia_frame_ext_subframe) +
-			  (8000 * ptime / 1000) + 4;
+			  strm->bytes_per_frame + 4;
 	strm->xfrm = (pjmedia_frame_ext*)
 		     pj_pool_alloc(pool, strm->xfrm_size);
Index: pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/conf_switch.c
===================================================================
--- pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/conf_switch.c	(revision 2470)
+++ pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/conf_switch.c	(revision 2471)
@@ -1293,5 +1293,5 @@
 
     /* Return sound playback frame. */
-    do {
+    {
 	struct conf_port *this_cport = conf->ports[this_port->port_data.ldata];
 	pjmedia_frame *f_src = (pjmedia_frame*) this_cport->tx_buf;
@@ -1355,5 +1355,5 @@
 	    f_src_->subframe_cnt = 0;
 	}
-    } while (0);
+    }
 
     /* Unlock mutex */
