Index: /pjproject/trunk/pjmedia/docs/doxygen.cfg
===================================================================
--- /pjproject/trunk/pjmedia/docs/doxygen.cfg	(revision 530)
+++ /pjproject/trunk/pjmedia/docs/doxygen.cfg	(revision 531)
@@ -346,5 +346,5 @@
 # with spaces.
 
-INPUT                  =  include
+INPUT                  =  include ../pjsip-apps/src/samples
 
 # If the value of the INPUT tag contains directories, you can use the 
@@ -355,5 +355,5 @@
 # *.h++ *.idl *.odl
 
-FILE_PATTERNS          = *.h
+FILE_PATTERNS          = *.h *.c
 
 # The RECURSIVE tag can be used to turn specify whether or not subdirectories 
@@ -384,5 +384,5 @@
 # the \include command).
 
-EXAMPLE_PATH           = 
+EXAMPLE_PATH           = ../pjsip-apps/src/samples
 
 # If the value of the EXAMPLE_PATH tag contains directories, you can use the 
Index: /pjproject/trunk/pjmedia/include/pjmedia-codec.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia-codec.h	(revision 530)
+++ /pjproject/trunk/pjmedia/include/pjmedia-codec.h	(revision 531)
@@ -20,4 +20,9 @@
 #define __PJMEDIA_CODEC_PJMEDIA_CODEC_H__
 
+/**
+ * @file pjmedia-codec.h
+ * @brief Include all codecs API in PJMEDIA-CODEC
+ */
+
 #include <pjmedia-codec/l16.h>
 #include <pjmedia-codec/gsm.h>
Index: /pjproject/trunk/pjmedia/include/pjmedia-codec/gsm.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia-codec/gsm.h	(revision 530)
+++ /pjproject/trunk/pjmedia/include/pjmedia-codec/gsm.h	(revision 531)
@@ -28,5 +28,5 @@
 
 /**
- * @defgroup PJMED_GSM GSM 06.10
+ * @defgroup PJMED_GSM GSM 06.10 Codec
  * @ingroup PJMEDIA_CODEC
  * @brief Implementation of GSM FR based on GSM 06.10 library
Index: /pjproject/trunk/pjmedia/include/pjmedia-codec/l16.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia-codec/l16.h	(revision 530)
+++ /pjproject/trunk/pjmedia/include/pjmedia-codec/l16.h	(revision 531)
@@ -24,5 +24,5 @@
 
 /**
- * @defgroup PJMED_L16 L16 Family
+ * @defgroup PJMED_L16 L16 Codec Family
  * @ingroup PJMEDIA_CODEC
  * @brief 16bit linear codecs (useful for debugging)
Index: /pjproject/trunk/pjmedia/include/pjmedia-codec/speex.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia-codec/speex.h	(revision 530)
+++ /pjproject/trunk/pjmedia/include/pjmedia-codec/speex.h	(revision 531)
@@ -28,5 +28,5 @@
 
 /**
- * @defgroup PJMED_SPEEX Speex
+ * @defgroup PJMED_SPEEX Speex Codec Family
  * @ingroup PJMEDIA_CODEC
  * @brief Implementation of Speex codecs (narrow/wide/ultrawide-band).
Index: /pjproject/trunk/pjmedia/include/pjmedia/doxygen.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/doxygen.h	(revision 530)
+++ /pjproject/trunk/pjmedia/include/pjmedia/doxygen.h	(revision 531)
@@ -62,7 +62,61 @@
  *
  * \n
+ * @section main_page_get_start_sec Getting Started
+ *
+ * For those who likes to just get start coding, the @ref getting_started_pjmedia
+ * may be a good place to start.
+ *
+ * The @ref page_pjmedia_samples page describes some examples that are available
+ * in the source tree.
+ *
+ *
+ * \n
  * @section pjmedia_lic Copying and Acknowledgements
  *
- * Please see @ref lic_stuffs page for the details.
+ * PJMEDIA and PJMEDIA-CODEC contains various parts obtained from other
+ * places, and each of these would have their own licensing terms.
+ * Please see @ref lic_stuffs page for details.
+ *
+ */
+
+/**
+ * @page pjmed_keywords_page Features Index
+ * @section pjmed_keywords Features Index
+ *
+ * <b>PJMEDIA features</b>, in no particular order (click to go to the relevant
+ * documentation): 
+ * @ref lic_stuffs "Open Source media stack", 
+ * @ref PJMEDIA_CLOCK, 
+ * @ref PJMEDIA_CODEC,
+ * @ref enc_dec_codec,
+ * @ref plc_codec, 
+ * @ref PJMEDIA_CONF, 
+ * @ref PJMED_G711 "G711/G.711 (PCMA/PCMU) codec with PLC",
+ * @ref PJMED_GSM "GSM codec with PLC", 
+ * @ref PJMED_L16 "linear codecs (multiple clockrate, stereo support, etc)",
+ * @ref PJMED_SPEEX "Speex codec (narrowband, wideband, ultra-wideband)",
+ * @ref PJMED_JBUF "portable, adaptive jitter buffer with PLC support",
+ * @ref PJMEDIA_MASTER_PORT, 
+ * @ref PJMEDIA_NULL_PORT,
+ * @ref PJMED_PLC, 
+ * @ref PJMEDIA_PORT_CONCEPT, 
+ * @ref PJMEDIA_PORT_CLOCK,
+ * @ref PJMEDIA_RESAMPLE "high quality resampling/sampling rate conversion",
+ * @ref PJMEDIA_RESAMPLE_PORT, 
+ * @ref PJMED_RTCP "small footprint, portable RTCP with media quality statistics",
+ * @ref PJMED_RTP "very small footprint, modular, DSP ready RTP implementation", 
+ * @ref PJMEDIA_SDP "modular, small footprint, open source SDP implementation", 
+ * @ref PJMEDIA_SDP_NEG "modular SDP negotiation/negotiator abstraction",
+ * @ref PJMED_SES "media session abstraction",
+ * @ref PJMEDIA_SILENCEDET,
+ * @ref PJMED_SND "portable audio/sound hardware/device abstraction for Linux, Unix, Windows, DirectSound, WinCE, Windows Mobile, MacOS X, etc.", 
+ * @ref PJMED_SND_PORT,
+ * @ref PJMEDIA_SPLITCOMB, 
+ * @ref PJMED_STRM "remote stream", 
+ * @ref PJMEDIA_TRANSPORT_H "custom media transport abstraction",
+ * @ref PJMEDIA_TRANSPORT_UDP, 
+ * @ref PJMEDIA_FILE_PLAY "WAV/WAVE file playback", 
+ * @ref PJMEDIA_FILE_REC "WAV/WAVE file recording/capture",
+ * @ref PJMEDIA_WAVE "portable WAV/WAVE header manipulation"
  */
 
@@ -326,3 +380,140 @@
  */
 
+
+/**
+ @page getting_started_pjmedia Getting Started with PJMEDIA
+ 
+ @section getstart_init_setup_build Setting-up the Build System
+
+ @subsection subsec_build_pjmedia Building PJMEDIA and PJMEDIA-CODEC
+
+ The PJMEDIA and PJMEDIA-CODEC libraries are normally bundled in PJPROJECT
+ source tarball, and they are located in <tt><b>pjmedia</b></tt> sub-directory
+ tree.
+
+ Please follow the instructions in <tt><b>INSTALL.txt</b></tt> in the root
+ PJPROJECT directory to build all projects, including PJMEDIA and PJMEDIA-CODEC.
+
+ @subsection subsec_config_build Setting Up the Build Environment
+
+ In your project, you will need to configure the following.
+ - Add <tt><b>$pjproject/pjmedia/include</b></tt> in the search path for
+   include files.
+ - Add <tt><b>$pjproject/pjmedia/lib</b></tt> in the search path for
+   library files.
+ - Add PJMEDIA and PJMEDIA static libraries in the link command.
+
+ @subsection subsec_inc_pjmedia Include PJMEDIA and PJMEDIA-CODEC in Source Files
+
+ To include all features from PJMEDIA and PJMEDIA-CODEC, use the following:
+
+ \code
+   #include <pjlib.h>
+   #include <pjmedia.h>
+   #include <pjmedia-codec.h>
+ \endcode
+
+ Alternatively, you may include only specific parts of the library (for example
+ to speed up compilation by just a fraction), for example:
+
+ \code
+   #include <pjmedia/conference.h>
+   #include <pjmedia/jbuf.h>
+   #include <pjmedia-codec/speex.h>
+ \endcode
+
+  Note that you need to give <b>"pjmedia/"</b> and <b>"pjmedia-codec/"</b> 
+  prefix to include specific files.
+
+
+ @section getstart_using Using PJMEDIA
+
+  I wish I could explain more, but for now, please have a look at the 
+  @ref page_pjmedia_samples page on some examples.
+ */
+
+/**
+  @page page_pjmedia_samples PJMEDIA and PJMEDIA-CODEC Examples
+
+  @section pjmedia_samples_sec PJMEDIA and PJMEDIA-CODEC Examples
+
+  Please find below some PJMEDIA related examples that may help in giving
+  some more info:
+
+  - @ref page_pjmedia_samples_level_c\n
+    This is a good place to start learning about @ref PJMEDIA_PORT_CONCEPT,
+    as it shows that @ref PJMEDIA_PORT_CONCEPT are only "passive" objects
+    with <tt>get_frame()</tt> and <tt>put_frame()</tt> interface, and
+    someone has to call these to retrieve/store media frames.
+
+  - @ref page_pjmedia_samples_playfile_c\n
+    This example shows that when application connects a media port (in this
+    case a @ref PJMEDIA_FILE_PLAY) to @ref PJMED_SND_PORT, media will flow
+    automatically since the @ref PJMED_SND_PORT provides @ref PJMEDIA_PORT_CLOCK.
+
+  - @ref page_pjmedia_samples_recfile_c\n
+    Demonstrates how to capture audio from microphone to WAV file.
+
+  - @ref page_pjmedia_samples_playsine_c\n
+    Demonstrates how to create a custom @ref PJMEDIA_PORT_CONCEPT (in this
+    case a sine wave generator) and integrate it to PJMEDIA.
+
+  - @ref page_pjmedia_samples_confsample_c\n
+    This demonstrates how to use the @ref PJMEDIA_CONF. The sample program can 
+    open multiple WAV files, and instruct the conference bridge to mix the
+    signal before playing it to the sound device.
+
+  - @ref page_pjmedia_samples_confbench_c\n
+    I use this to benchmark/optimize the conference bridge algorithm, but
+    readers may find the source useful.
+
+  - @ref page_pjmedia_samples_resampleplay_c\n
+    Demonstrates how to use @ref PJMEDIA_RESAMPLE_PORT to change the
+    sampling rate of a media port (in this case, a @ref PJMEDIA_FILE_PLAY).
+
+  - @ref page_pjmedia_samples_sndtest_c\n
+    This program performs some tests to the sound device to get some
+    quality parameters (such as sound jitter and clock drifts).\n
+    Screenshots on WinXP: \image html sndtest.jpg "sndtest screenshot on WinXP"
+
+  - @ref page_pjmedia_samples_streamutil_c\n
+    This example mainly demonstrates how to stream media (in this case a
+    @ref PJMEDIA_FILE_PLAY) to remote peer using RTP.
+
+  - @ref page_pjmedia_samples_siprtp_c\n
+    This is a useful program (integrated with PJSIP) to actively measure 
+    the network quality/impairment parameters by making one or more SIP 
+    calls (or receiving one or more SIP calls) and display the network
+    impairment of each stream direction at the end of the call.
+    The program is able to measure network quality parameters such as
+    jitter, packet lost/reorder/duplicate, round trip time, etc.\n
+    Note that the remote peer MUST support RTCP so that network quality
+    of each direction can be calculated. Using siprtp for both endpoints
+    is recommended.\n
+    Screenshots on WinXP: \image html siprtp.jpg "siprtp screenshot on WinXP"
+
+ */
+
+/**
+ * \page page_pjmedia_samples_siprtp_c Samples: Using SIP and Custom RTP/RTCP to Monitor Quality
+ *
+ * This source is an example to demonstrate using SIP and RTP/RTCP framework
+ * to measure the network quality/impairment from the SIP call. This
+ * program can be used to make calls or to receive calls from other
+ * SIP endpoint (or other siprtp program), and to display the media
+ * quality statistics at the end of the call.
+ *
+ * Note that the remote peer must support RTCP.
+ *
+ * The layout of the program has been designed so that custom reporting
+ * can be generated instead of plain human readable text.
+ *
+ * The source code of the file is pjsip-apps/src/samples/siprtp.c
+ *
+ * Screenshots on WinXP: \image html siprtp.jpg
+ *
+ * \includelineno siprtp.c
+ */
+
 #endif /* __PJMEDIA_DOXYGEN_H__ */
+
Index: /pjproject/trunk/pjmedia/include/pjmedia/plc.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/plc.h	(revision 530)
+++ /pjproject/trunk/pjmedia/include/pjmedia/plc.h	(revision 531)
@@ -28,5 +28,5 @@
 
 /**
- * @defgroup PJMED_PLC Packet Lost Concealment
+ * @defgroup PJMED_PLC Packet Lost Concealment (PLC)
  * @ingroup PJMEDIA_FRAME_OP
  * @{
Index: /pjproject/trunk/pjmedia/include/pjmedia/rtp.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/rtp.h	(revision 530)
+++ /pjproject/trunk/pjmedia/include/pjmedia/rtp.h	(revision 531)
@@ -38,5 +38,6 @@
  * The RTP module is designed to be dependent only to PJLIB, it does not depend
  * on any other parts of PJMEDIA library. The RTP module does not even depend
- * on any transports (sockets), to promote even more use.
+ * on any transports (sockets), to promote even more use, such as in DSP
+ * development (where transport may be handled by different processor).
  *
  * An RTCP implementation is available, in separate module. Please see 
Index: /pjproject/trunk/pjmedia/include/pjmedia/sdp_neg.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/sdp_neg.h	(revision 530)
+++ /pjproject/trunk/pjmedia/include/pjmedia/sdp_neg.h	(revision 531)
@@ -26,6 +26,7 @@
  */
 /**
- * @defgroup PJMEDIA_SDP_NEG SDP Negotiator
+ * @defgroup PJMEDIA_SDP_NEG SDP Negotiation
  * @ingroup PJMEDIA_SESSION
+ * @brief Abstraction to perform SDP negotiation
  * @{
  *
Index: /pjproject/trunk/pjmedia/include/pjmedia/sound.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/sound.h	(revision 530)
+++ /pjproject/trunk/pjmedia/include/pjmedia/sound.h	(revision 531)
@@ -31,5 +31,5 @@
 
 /**
- * @defgroup PJMED_SND Sound Hardware Abstraction
+ * @defgroup PJMED_SND Portable Sound Hardware Abstraction
  * @ingroup PJMED_SND_PORT
  * @brief PJMEDIA abstraction for sound device hardware
Index: /pjproject/trunk/pjmedia/include/pjmedia/splitcomb.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/splitcomb.h	(revision 530)
+++ /pjproject/trunk/pjmedia/include/pjmedia/splitcomb.h	(revision 531)
@@ -19,4 +19,23 @@
 #ifndef __PJMEDIA_SPLITCOMB_H__
 #define __PJMEDIA_SPLITCOMB_H__
+
+
+/**
+ * @file splitcomb.h
+ * @brief Media channel splitter/combiner port.
+ */
+#include <pjmedia/types.h>
+
+
+/**
+ * @addtogroup PJMEDIA_SPLITCOMB Media channel splitter/combiner
+ * @ingroup PJMEDIA_PORT
+ * @brief Split and combine media channels in media streams
+ * @{
+ * This section describes media port to split and combine media
+ * channels in the stream.
+ */
+
+PJ_BEGIN_DECL
 
 
@@ -108,4 +127,9 @@
 
 
+PJ_END_DECL
+
+/**
+ * @}
+ */
 
 #endif	/* __PJMEDIA_SPLITCOMB_H__ */
Index: /pjproject/trunk/pjmedia/include/pjmedia/wav_port.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/wav_port.h	(revision 530)
+++ /pjproject/trunk/pjmedia/include/pjmedia/wav_port.h	(revision 531)
@@ -32,5 +32,5 @@
 
 /**
- * @defgroup PJMEDIA_FILE_PLAY File Player
+ * @defgroup PJMEDIA_FILE_PLAY WAV File Player
  * @ingroup PJMEDIA_PORT
  * @brief WAV File Player
@@ -78,14 +78,48 @@
 
 /**
- * Set the play position of WAV player.
+ * Set the file play position of WAV player.
  *
  * @param port		The file player port.
- * @param samples	Sample position (zero as start of file).
+ * @param offset	Playback position in bytes, relative to the start of
+ *			the payload.
  *
  * @return		PJ_SUCCESS on success.
  */
 PJ_DECL(pj_status_t) pjmedia_wav_player_port_set_pos( pjmedia_port *port,
-						      pj_uint32_t samples );
-
+						      pj_uint32_t offset );
+
+
+/**
+ * Get the file play position of WAV player.
+ *
+ * @param port		The file player port.
+ *
+ * @return		PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_ssize_t) pjmedia_wav_player_port_get_pos( pjmedia_port *port );
+
+
+/**
+ * Register a callback to be called when the file reading has reached the
+ * end of file. If the file is set to play repeatedly, then the callback
+ * will be called multiple times. Note that only one callback can be 
+ * registered for each file port.
+ *
+ * @param port		The file player port.
+ * @param user_data	User data to be specified in the callback. Note that
+ *			this overwrites the user data previously set when
+ *			the file port is created.
+ * @param cb		Callback to be called. If the callback returns non-
+ *			PJ_SUCCESS, the playback will stop. Note that if
+ *			application destroys the file port in the callback,
+ *			it must return non-PJ_SUCCESS here.
+ *
+ * @return		PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) 
+pjmedia_wav_player_set_eof_cb( pjmedia_port *port,
+			       void *user_data,
+			       pj_status_t (*cb)(pjmedia_port *port,
+						 void *usr_data));
 
 /**
@@ -115,11 +149,11 @@
  * @param bits_per_sample   Number of bits per sample (eg 16).
  * @param flags		    Port creation flags (must be 0 at present).
- * @param buff_size	Buffer size to be allocated. If the value is zero or
- *			negative, the port will use default buffer size (which
- *			is about 4KB).
- * @param user_data	User data to be associated with the file writer port.
- * @param p_port	Pointer to receive the file port instance.
- *
- * @return		PJ_SUCCESS on success.
+ * @param buff_size	    Buffer size to be allocated. If the value is 
+ *			    zero or negative, the port will use default buffer
+ *			    size (which is about 4KB).
+ * @param user_data	    User data to be associated with the file port.
+ * @param p_port	    Pointer to receive the file port instance.
+ *
+ * @return		    PJ_SUCCESS on success.
  */
 PJ_DECL(pj_status_t) pjmedia_wav_writer_port_create(pj_pool_t *pool,
@@ -135,4 +169,42 @@
 
 
+/**
+ * Get current writing position. Note that this does not necessarily match
+ * the size written to the file, since the WAV writer employs some internal
+ * buffering. Also the value reported here only indicates the payload size
+ * (it does not include the size of the WAV header),
+ *
+ * @param port		The file writer port.
+ *
+ * @return		Positive value to indicate the position (in bytes), 
+ *			or negative value containing the error code.
+ */
+PJ_DECL(pj_ssize_t) pjmedia_wav_writer_port_get_pos( pjmedia_port *port );
+
+
+/**
+ * Register the callback to be called when the file writing has reached
+ * certain size. Application can use this callback, for example, to limit
+ * the size of the output file.
+ *
+ * @param port		The file writer port.
+ * @param pos		The file position on which the callback will be called.
+ * @param user_data	User data to be specified in the callback. Note that
+ *			this overwrites the user data previously set when
+ *			the file port is created.
+ * @param cb		Callback to be called. If the callback returns non-
+ *			PJ_SUCCESS, the writing will stop. Note that if 
+ *			application destroys the port in the callback, it must
+ *			return non-PJ_SUCCESS here.
+ *
+ * @return		PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) 
+pjmedia_wav_writer_port_set_cb( pjmedia_port *port,
+				pj_size_t pos,
+				void *user_data,
+				pj_status_t (*cb)(pjmedia_port *port,
+						  void *usr_data));
+
 
 /**
Index: /pjproject/trunk/pjmedia/src/pjmedia/conference.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/conference.c	(revision 530)
+++ /pjproject/trunk/pjmedia/src/pjmedia/conference.c	(revision 531)
@@ -1056,5 +1056,5 @@
 		   count));
 
-	status = (cport->port->get_frame)(cport->port, &f);
+	status = pjmedia_port_get_frame(cport->port, &f);
 
 	*type = f.type;
@@ -1461,4 +1461,8 @@
 		continue;
 	    }
+
+	    /* Check that the port is not removed when we call get_frame() */
+	    if (conf->ports[i] == NULL)
+		continue;
 	}
 
Index: /pjproject/trunk/pjmedia/src/pjmedia/wav_player.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/wav_player.c	(revision 530)
+++ /pjproject/trunk/pjmedia/src/pjmedia/wav_player.c	(revision 531)
@@ -31,5 +31,5 @@
 
 
-#define SIGNATURE	    ('F'<<24|'P'<<16|'L'<<8|'Y')
+#define SIGNATURE	    PJMEDIA_PORT_SIGNATURE('F', 'P', 'l', 'y')
 #define BYTES_PER_SAMPLE    2
 
@@ -66,4 +66,5 @@
     pj_oshandle_t    fd;
 
+    pj_status_t	   (*cb)(pjmedia_port*, void*);
 };
 
@@ -117,7 +118,7 @@
     pj_status_t status;
 
-    if (fport->eof) {
+    /* Can't read file if EOF and loop flag is disabled */
+    if (fport->eof)
 	return PJ_EEOF;
-    }
 
     while (size_left > 0) {
@@ -142,4 +143,25 @@
 	 */
 	if (size < (pj_ssize_t)size_to_read) {
+	    /* Call callback, if any. */
+	    if (fport->cb) {
+		PJ_LOG(5,(THIS_FILE, 
+			  "File port %.*s EOF, calling callback",
+			  (int)fport->base.info.name.slen,
+			  fport->base.info.name.ptr));
+
+		fport->eof = PJ_TRUE;
+		status = (*fport->cb)(&fport->base, fport->base.user_data);
+		if (status != PJ_SUCCESS) {
+		    /* This will crash if file port is destroyed in the 
+		     * callback, that's why we set the eof flag before
+		     * calling the callback:
+		     fport->eof = PJ_TRUE;
+		    */
+		    return status;
+		}
+		
+		fport->eof = PJ_FALSE;
+	    }
+
 	    if (fport->options & PJMEDIA_FILE_NO_LOOP) {
 		PJ_LOG(5,(THIS_FILE, "File port %.*s EOF, stopping..",
@@ -336,21 +358,77 @@
  */
 PJ_DEF(pj_status_t) pjmedia_wav_player_port_set_pos(pjmedia_port *port,
-						    pj_uint32_t samples )
+						    pj_uint32_t bytes )
 {
     struct file_port *fport;
 
-    PJ_ASSERT_RETURN(port, PJ_EINVAL);
+    /* Sanity check */
+    PJ_ASSERT_RETURN(port, -PJ_EINVAL);
+
+    /* Check that this is really a player port */
+    PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, -PJ_EINVALIDOP);
+
 
     fport = (struct file_port*) port;
 
-    PJ_ASSERT_RETURN(samples*BYTES_PER_SAMPLE < fport->fsize -
-		      sizeof(pjmedia_wave_hdr), PJ_EINVAL);
-
-    fport->fpos = sizeof(struct pjmedia_wave_hdr) + 
-		    samples * BYTES_PER_SAMPLE;
+    PJ_ASSERT_RETURN(bytes < fport->fsize - sizeof(pjmedia_wave_hdr), 
+		     PJ_EINVAL);
+
+    fport->fpos = sizeof(struct pjmedia_wave_hdr) + bytes;
     pj_file_setpos( fport->fd, fport->fpos, PJ_SEEK_SET);
 
     fport->eof = PJ_FALSE;
     return fill_buffer(fport);
+}
+
+
+/*
+ * Get the file play position of WAV player.
+ */
+PJ_DEF(pj_ssize_t) pjmedia_wav_player_port_get_pos( pjmedia_port *port )
+{
+    struct file_port *fport;
+    pj_size_t payload_pos;
+
+    /* Sanity check */
+    PJ_ASSERT_RETURN(port, -PJ_EINVAL);
+
+    /* Check that this is really a player port */
+    PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, -PJ_EINVALIDOP);
+
+    fport = (struct file_port*) port;
+
+    payload_pos = (pj_size_t)(fport->fpos - sizeof(pjmedia_wave_hdr));
+    if (payload_pos >= fport->bufsize)
+	return payload_pos - fport->bufsize + (fport->readpos - fport->buf);
+    else
+	return (fport->readpos - fport->buf) % payload_pos;
+}
+
+
+
+/*
+ * Register a callback to be called when the file reading has reached the
+ * end of file.
+ */
+PJ_DEF(pj_status_t) 
+pjmedia_wav_player_set_eof_cb( pjmedia_port *port,
+			       void *user_data,
+			       pj_status_t (*cb)(pjmedia_port *port,
+						 void *usr_data))
+{
+    struct file_port *fport;
+
+    /* Sanity check */
+    PJ_ASSERT_RETURN(port, -PJ_EINVAL);
+
+    /* Check that this is really a player port */
+    PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, -PJ_EINVALIDOP);
+
+    fport = (struct file_port*) port;
+
+    fport->base.user_data = user_data;
+    fport->cb = cb;
+
+    return PJ_SUCCESS;
 }
 
Index: /pjproject/trunk/pjmedia/src/pjmedia/wav_writer.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/wav_writer.c	(revision 530)
+++ /pjproject/trunk/pjmedia/src/pjmedia/wav_writer.c	(revision 531)
@@ -29,5 +29,5 @@
 
 #define THIS_FILE	    "wav_writer.c"
-#define SIGNATURE	    ('F'<<24|'W'<<16|'R'<<8|'T')
+#define SIGNATURE	    PJMEDIA_PORT_SIGNATURE('F', 'W', 'R', 'T')
 #define BYTES_PER_SAMPLE    2
 
@@ -39,6 +39,10 @@
     char	    *buf;
     char	    *writepos;
+    pj_size_t	     total;
 
     pj_oshandle_t    fd;
+
+    pj_size_t	     cb_size;
+    pj_status_t	   (*cb)(pjmedia_port*, void*);
 };
 
@@ -178,4 +182,52 @@
 
 
+
+/*
+ * Get current writing position. 
+ */
+PJ_DEF(pj_ssize_t) pjmedia_wav_writer_port_get_pos( pjmedia_port *port )
+{
+    struct file_port *fport;
+
+    /* Sanity check */
+    PJ_ASSERT_RETURN(port, -PJ_EINVAL);
+
+    /* Check that this is really a writer port */
+    PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, -PJ_EINVALIDOP);
+
+    fport = (struct file_port*) port;
+
+    return fport->total;
+}
+
+
+/*
+ * Register callback.
+ */
+PJ_DEF(pj_status_t) 
+pjmedia_wav_writer_port_set_cb( pjmedia_port *port,
+				pj_size_t pos,
+				void *user_data,
+			        pj_status_t (*cb)(pjmedia_port *port,
+						  void *usr_data))
+{
+    struct file_port *fport;
+
+    /* Sanity check */
+    PJ_ASSERT_RETURN(port && cb, PJ_EINVAL);
+
+    /* Check that this is really a writer port */
+    PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, PJ_EINVALIDOP);
+
+    fport = (struct file_port*) port;
+
+    fport->cb_size = pos;
+    fport->base.user_data = user_data;
+    fport->cb = cb;
+
+    return PJ_SUCCESS;
+}
+
+
 #if defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN!=0
     static void swap_samples(pj_int16_t *samples, unsigned count)
@@ -235,4 +287,17 @@
     fport->writepos += frame->size;
 
+    /* Increment total written, and check if we need to call callback */
+    fport->total += frame->size;
+    if (fport->cb && fport->total >= fport->cb_size) {
+	pj_status_t (*cb)(pjmedia_port*, void*);
+	pj_status_t status;
+
+	cb = fport->cb;
+	fport->cb = NULL;
+
+	status = (*cb)(this_port, this_port->user_data);
+	return status;
+    }
+
     return PJ_SUCCESS;
 }
Index: /pjproject/trunk/pjsip-apps/src/samples/confbench.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/samples/confbench.c	(revision 530)
+++ /pjproject/trunk/pjsip-apps/src/samples/confbench.c	(revision 531)
@@ -18,8 +18,16 @@
  */
 
-/*
+
+/**
+ * \page page_pjmedia_samples_confbench_c Samples: Benchmarking Conference Bridge
+ *
  * Benchmarking pjmedia (conference bridge+resample). For my use only,
  * and it only works in Win32.
+ *
+ * This file is pjsip-apps/src/samples/confbench.c
+ *
+ * \includelineno confbench.c
  */
+
 
 #include <pjmedia.h>
@@ -39,6 +47,6 @@
  *     the port.
  */
-#define TEST_SET	    SMALL_SET
-#define HAS_RESAMPLE	    1
+#define TEST_SET	    LARGE_SET
+#define HAS_RESAMPLE	    0
 
 
@@ -266,5 +274,8 @@
     }
 
+    printf("Resampling is %s\n", (HAS_RESAMPLE?"active":"disabled"));
+
     /* Create Null ports */
+    printf("Creating %d null ports..\n", NULL_COUNT);
     for (i=0; i<NULL_COUNT; ++i) {
 	status = pjmedia_null_port_create(pool, CLOCK_RATE, 1, SAMPLES_PER_FRAME*2, 16, &nulls[i]);
@@ -276,4 +287,5 @@
 
     /* Create sine ports. */
+    printf("Creating %d sine generator ports..\n", SINE_COUNT);
     for (i=0; i<SINE_COUNT; ++i) {
 	unsigned j, slot;
@@ -305,4 +317,5 @@
 
     /* Create idle ports */
+    printf("Creating %d idle ports..\n", IDLE_COUNT);
     for (i=0; i<IDLE_COUNT; ++i) {
 	pjmedia_port *dummy;
Index: /pjproject/trunk/pjsip-apps/src/samples/confsample.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/samples/confsample.c	(revision 530)
+++ /pjproject/trunk/pjsip-apps/src/samples/confsample.c	(revision 531)
@@ -26,4 +26,16 @@
 
 #include "util.h"
+
+/**
+ * \page page_pjmedia_samples_confsample_c Samples: Using Conference Bridge
+ *
+ * Sample to mix multiple files in the conference bridge and play the
+ * result to sound device.
+ *
+ * This file is pjsip-apps/src/samples/confsample.c
+ *
+ * \includelineno confsample.c
+ */
+
 
 /* For logging purpose. */
Index: /pjproject/trunk/pjsip-apps/src/samples/level.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/samples/level.c	(revision 530)
+++ /pjproject/trunk/pjsip-apps/src/samples/level.c	(revision 531)
@@ -17,4 +17,17 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
  */
+
+
+/**
+ * \page page_pjmedia_samples_level_c Samples: Reading from WAV File
+ *
+ * This is a very simple example to use the @ref PJMEDIA_FILE_PLAY, to
+ * directly read the samples from the file.
+ *
+ * This file is pjsip-apps/src/samples/level.c
+ *
+ * \includelineno level.c
+ */
+
 
 static const char *desc = 
Index: /pjproject/trunk/pjsip-apps/src/samples/playfile.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/samples/playfile.c	(revision 530)
+++ /pjproject/trunk/pjsip-apps/src/samples/playfile.c	(revision 531)
@@ -25,4 +25,20 @@
 
 #include "util.h"
+
+
+/**
+ * \page page_pjmedia_samples_playfile_c Samples: Playing WAV File to Sound Device
+ *
+ * This is a very simple example to use the @ref PJMEDIA_FILE_PLAY and
+ * @ref PJMED_SND_PORT. In this example, we open both the file and sound
+ * device, and connect the two of them, and voila! Sound will be playing
+ * the contents of the file.
+ *
+ * @see page_pjmedia_samples_recfile_c
+ *
+ * This file is pjsip-apps/src/samples/playfile.c
+ *
+ * \includelineno playfile.c
+ */
 
 
Index: /pjproject/trunk/pjsip-apps/src/samples/playsine.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/samples/playsine.c	(revision 530)
+++ /pjproject/trunk/pjsip-apps/src/samples/playsine.c	(revision 531)
@@ -16,4 +16,16 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
+ */
+
+
+/**
+ * \page page_pjmedia_samples_playsine_c Samples: Using Custom Ports (Sine Wave Generator)
+ *
+ * This example demonstrate how to create a custom media port (in this case, a
+ * sine wave generator) and connect it to the sound device.
+ *
+ * This file is pjsip-apps/src/samples/playsine.c
+ *
+ * \includelineno playsine.c
  */
 
Index: /pjproject/trunk/pjsip-apps/src/samples/recfile.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/samples/recfile.c	(revision 530)
+++ /pjproject/trunk/pjsip-apps/src/samples/recfile.c	(revision 531)
@@ -18,4 +18,16 @@
  */
 
+/**
+ * \page page_pjmedia_samples_recfile_c Samples: Capturing Audio to WAV File
+ *
+ * In this example, we capture audio from the sound device and save it to
+ * WAVE file.
+ *
+ * @see page_pjmedia_samples_playfile_c
+ *
+ * This file is pjsip-apps/src/samples/recfile.c
+ *
+ * \includelineno recfile.c
+ */
 
 #include <pjmedia.h>
@@ -26,4 +38,5 @@
 /* For logging purpose. */
 #define THIS_FILE   "recfile.c"
+
 
 /* Configs */
Index: /pjproject/trunk/pjsip-apps/src/samples/resampleplay.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/samples/resampleplay.c	(revision 530)
+++ /pjproject/trunk/pjsip-apps/src/samples/resampleplay.c	(revision 531)
@@ -17,4 +17,16 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
  */
+
+/**
+ * \page page_pjmedia_samples_resampleplay_c Samples: Using Resample Port
+ *
+ * This example demonstrates how to use @ref PJMEDIA_RESAMPLE_PORT to
+ * change the sampling rate of the media streams.
+ *
+ * This file is pjsip-apps/src/samples/resampleplay.c
+ *
+ * \includelineno resampleplay.c
+ */
+
 #include <pjmedia.h>
 #include <pjlib-util.h>
Index: /pjproject/trunk/pjsip-apps/src/samples/siprtp.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/samples/siprtp.c	(revision 530)
+++ /pjproject/trunk/pjsip-apps/src/samples/siprtp.c	(revision 531)
@@ -17,4 +17,5 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
  */
+
 
 
Index: /pjproject/trunk/pjsip-apps/src/samples/sipstateless.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/samples/sipstateless.c	(revision 530)
+++ /pjproject/trunk/pjsip-apps/src/samples/sipstateless.c	(revision 531)
@@ -104,18 +104,11 @@
     /* Create global endpoint: */
     {
-	const pj_str_t *hostname;
-	const char *endpt_name;
-
 	/* Endpoint MUST be assigned a globally unique name.
-	 * The name will be used as the hostname in Warning header.
+	 * Ideally we should put hostname or public IP address, but
+	 * we'll just use an arbitrary name here.
 	 */
 
-	/* For this implementation, we'll use hostname for simplicity */
-	hostname = pj_gethostname();
-	endpt_name = hostname->ptr;
-
 	/* Create the endpoint: */
-
-	status = pjsip_endpt_create(&cp.factory, endpt_name, 
+	status = pjsip_endpt_create(&cp.factory, "sipstateless", 
 				    &sip_endpt);
 	PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
Index: /pjproject/trunk/pjsip-apps/src/samples/sndtest.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/samples/sndtest.c	(revision 530)
+++ /pjproject/trunk/pjsip-apps/src/samples/sndtest.c	(revision 531)
@@ -17,4 +17,19 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
  */
+
+/**
+ * \page page_pjmedia_samples_sndtest_c Samples: Sound Card Benchmark
+ *
+ * This example can be used to benchmark the quality of the sound card
+ * installed in the system. At the end of the test, it will report
+ * the jitter and clock drifts of the device.
+ *
+ * This file is pjsip-apps/src/samples/sndtest.c
+ *
+ * Screenshots on WinXP: \image html sndtest.jpg
+ *
+ * \includelineno sndtest.c
+ */
+
 
 #include <pjmedia.h>
Index: /pjproject/trunk/pjsip-apps/src/samples/streamutil.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/samples/streamutil.c	(revision 530)
+++ /pjproject/trunk/pjsip-apps/src/samples/streamutil.c	(revision 531)
@@ -16,4 +16,16 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
+ */
+
+
+/**
+ * \page page_pjmedia_samples_streamutil_c Samples: Remote Streaming
+ *
+ * This example mainly demonstrates how to stream media file to remote
+ * peer using RTP.
+ *
+ * This file is pjsip-apps/src/samples/streamutil.c
+ *
+ * \includelineno streamutil.c
  */
 
Index: /pjproject/trunk/pjsip/docs/doxygen.cfg
===================================================================
--- /pjproject/trunk/pjsip/docs/doxygen.cfg	(revision 530)
+++ /pjproject/trunk/pjsip/docs/doxygen.cfg	(revision 531)
@@ -385,5 +385,5 @@
 # the \include command).
 
-EXAMPLE_PATH           = 
+EXAMPLE_PATH           = ../pjsip-apps/src/samples ../pjsip-apps/src/pjsua
 
 # If the value of the EXAMPLE_PATH tag contains directories, you can use the 
@@ -405,5 +405,5 @@
 # the \image command).
 
-IMAGE_PATH             = 
+IMAGE_PATH             = docs ../pjmedia/docs
 
 # The INPUT_FILTER tag can be used to specify a program that doxygen should 
Index: /pjproject/trunk/pjsip/docs/doxygen.h
===================================================================
--- /pjproject/trunk/pjsip/docs/doxygen.h	(revision 530)
+++ /pjproject/trunk/pjsip/docs/doxygen.h	(revision 531)
@@ -182,2 +182,95 @@
 
 
+/**
+ @page page_pjsip_samples PJSIP Samples
+
+ I wish I could write more samples, but for now here are some samples or
+ working applications that are available from the source tree:
+
+  - @ref page_pjsip_sample_sipstateless_c\n
+    This is about the simplest SIP application with PJSIP, all it does is
+    respond all incoming requests with 501 (Not Implemented) response
+    statelessly.
+
+  - @ref page_pjsip_sample_simple_ua_c\n
+    This is a very simple SIP User Agent application that only use PJSIP
+    (without PJSIP-UA). It's able to make and receive call, and play
+    media to the sound device.
+    
+  - @ref page_pjsip_samples_pjsua\n
+    This is the reference implementation for PJSIP and PJMEDIA.
+    PJSUA is a console based application, designed to be simple enough
+    to be readble, but powerful enough to demonstrate all features
+    available in PJSIP and PJMEDIA.\n
+    Screenshot on WinXP: \image html pjsua.jpg "pjsua on WinXP"
+
+  - @ref page_pjmedia_samples_siprtp_c\n
+    This is a useful program (integrated with PJSIP) to actively measure 
+    the network quality/impairment parameters by making one or more SIP 
+    calls (or receiving one or more SIP calls) and display the network
+    impairment of each stream direction at the end of the call.
+    The program is able to measure network quality parameters such as
+    jitter, packet lost/reorder/duplicate, round trip time, etc.\n
+    Note that the remote peer MUST support RTCP so that network quality
+    of each direction can be calculated. Using siprtp for both endpoints
+    is recommended.\n
+    Screenshots on WinXP: \image html siprtp.jpg "siprtp screenshot on WinXP"
+
+ */
+
+/**
+ * \page page_pjsip_samples_pjsua PJSUA
+ *
+ * This is the reference implementation for PJSIP and PJMEDIA.
+ * PJSUA is a console based application, designed to be simple enough
+ * to be readble, but powerful enough to demonstrate all features
+ * available in PJSIP and PJMEDIA.
+ *
+ * This file is pjsip-apps/src/pjsua/pjsua_app.c
+ *
+ * Screenshot on WinXP: \image html pjsua.jpg "pjsua on WinXP"
+ *
+ * \includelineno pjsua_app.c
+ */
+
+/**
+ * \page page_pjsip_sample_simple_ua_c Samples: Simple UA
+ *
+ * This is a very simple SIP User Agent application that only use PJSIP
+ * (without PJSIP-UA). It's able to make and receive call, and play
+ * media to the sound device.
+ *
+ * \includelineno simpleua.c
+ */
+
+/**
+ * \page page_pjsip_sample_sipstateless_c Samples: Stateless SIP Endpoint
+ *
+ * This is about the simplest SIP application with PJSIP, all it does is
+ * respond all incoming requests with 501 (Not Implemented) response
+ * statelessly.
+ *
+ * \includelineno sipstateless.c
+ */
+
+/**
+ * \page page_pjmedia_samples_siprtp_c Samples: Using SIP and Custom RTP/RTCP to Monitor Quality
+ *
+ * This source is an example to demonstrate using SIP and RTP/RTCP framework
+ * to measure the network quality/impairment from the SIP call. This
+ * program can be used to make calls or to receive calls from other
+ * SIP endpoint (or other siprtp program), and to display the media
+ * quality statistics at the end of the call.
+ *
+ * Note that the remote peer must support RTCP.
+ *
+ * The layout of the program has been designed so that custom reporting
+ * can be generated instead of plain human readable text.
+ *
+ * The source code of the file is pjsip-apps/src/samples/siprtp.c
+ *
+ * Screenshots on WinXP: \image html siprtp.jpg
+ *
+ * \includelineno siprtp.c
+ */
+
