Index: /pjproject/trunk/pjmedia/src/pjmedia/wav_player.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/wav_player.c	(revision 3404)
+++ /pjproject/trunk/pjmedia/src/pjmedia/wav_player.c	(revision 3405)
@@ -68,4 +68,6 @@
     pj_off_t	     fsize;
     unsigned	     start_data;
+    unsigned         data_len;
+    unsigned         data_left;
     pj_off_t	     fpos;
     pj_oshandle_t    fd;
@@ -106,5 +108,7 @@
 static pj_status_t fill_buffer(struct file_reader_port *fport)
 {
-    pj_ssize_t size_left = fport->bufsize;
+    pj_size_t data_left = fport->data_left;
+    pj_ssize_t bufsize = (fport->bufsize > data_left) ? data_left : fport->bufsize;
+    pj_ssize_t size_left = bufsize;
     unsigned size_to_read;
     pj_ssize_t size;
@@ -118,5 +122,6 @@
 	size = size_to_read = size_left;
 	status = pj_file_read(fport->fd, 
-			      &fport->buf[fport->bufsize-size_left], 
+			      //&fport->buf[fport->bufsize-size_left], 
+			      &fport->buf[bufsize-size_left], 
 			      &size);
 	if (status != PJ_SUCCESS)
@@ -128,4 +133,5 @@
 
 	size_left -= size;
+        fport->data_left -= size;
 	fport->fpos += size;
 
@@ -133,16 +139,29 @@
 	 * encountered EOF. Rewind the file.
 	 */
-	if (size < (pj_ssize_t)size_to_read) {
-	    fport->eof = PJ_TRUE;
-	    fport->eofpos = fport->buf + fport->bufsize - size_left;
-	    
-	    if (fport->options & PJMEDIA_FILE_NO_LOOP) {
-		/* Zero remaining buffer */
-		pj_bzero(fport->eofpos, size_left);
-	    }
+        if (size < (pj_ssize_t)size_to_read || fport->data_left <= 0) {
+            fport->eof = PJ_TRUE;
+            //fport->eofpos = fport->buf + fport->bufsize - size_left;
+            fport->eofpos = fport->buf + bufsize - size_left;
+
+            if (fport->options & PJMEDIA_FILE_NO_LOOP) {
+                /* Zero remaining buffer */
+                if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_PCM) {
+                    pj_bzero(fport->eofpos, size_left +
+                             (fport->bufsize - data_left));
+                } else if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ULAW) {
+                    int val = pjmedia_linear2ulaw(0);
+                    pj_memset(fport->eofpos, val, size_left +
+                              (fport->bufsize - data_left));
+                } else if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ALAW) {
+                    int val = pjmedia_linear2alaw(0);
+                    pj_memset(fport->eofpos, val, size_left +
+                              (fport->bufsize - data_left));
+                }
+            }
 
 	    /* Rewind file */
 	    fport->fpos = fport->start_data;
 	    pj_file_setpos( fport->fd, fport->fpos, PJ_SEEK_SET);
+            fport->data_left = fport->data_len;
 	}
     }
@@ -313,10 +332,14 @@
     status = pj_file_getpos(fport->fd, &pos);
     fport->start_data = (unsigned)pos;
-
-    /* Validate length. */
+	fport->data_len = wave_hdr.data_hdr.len;
+	fport->data_left = wave_hdr.data_hdr.len;
+
+    /* Validate length. This is unnecessary since we only play data chunks. */
+    /*
     if (wave_hdr.data_hdr.len != fport->fsize - fport->start_data) {
 	pj_file_close(fport->fd);
 	return PJMEDIA_EWAVEUNSUPP;
     }
+    */
     if (wave_hdr.data_hdr.len < ptime * wave_hdr.fmt_hdr.sample_rate *
 				wave_hdr.fmt_hdr.nchan / 1000)
@@ -592,5 +615,17 @@
 	if (fport->eof && (fport->options & PJMEDIA_FILE_NO_LOOP)) {
 	    fport->readpos += endread;
-	    pj_bzero((char*)frame->buf + endread, frame_size - endread);
+
+            if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_PCM) {
+                pj_bzero((char*)frame->buf + endread, frame_size - endread);
+            } else if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ULAW) {
+                int val = pjmedia_linear2ulaw(0);
+                pj_memset((char*)frame->buf + endread, val,
+                          frame_size - endread);
+            } else if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ALAW) {
+                int val = pjmedia_linear2alaw(0);
+                pj_memset((char*)frame->buf + endread, val,
+                          frame_size - endread);
+            }
+
 	    return PJ_SUCCESS;
 	}
