Index: pjproject/trunk/pjsip-apps/src/samples/confsample.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/samples/confsample.c	(revision 352)
+++ pjproject/trunk/pjsip-apps/src/samples/confsample.c	(revision 361)
@@ -19,4 +19,19 @@
 
 #include <pjmedia.h>
+#include <pjlib-util.h>	/* pj_getopt */
+#include <pjlib.h>
+
+#include <stdlib.h>	/* atoi() */
+#include <stdio.h>
+
+#include "util.h"
+
+/* For logging purpose. */
+#define THIS_FILE   "confsample.c"
+
+
+/* Shall we put recorder in the conference */
+#define RECORDER    1
+
 
 static const char *desc = 
@@ -31,7 +46,9 @@
  " USAGE:								    \n"
  "									    \n"
- "  confsample [file1.wav] [file2.wav] ...				    \n"
- "									    \n"
- " where:								    \n"
+ "  confsample [options] [file1.wav] [file2.wav] ...			    \n"
+ "									    \n"
+ " options:								    \n"
+ SND_USAGE
+ "									    \n"
  "  fileN.wav are optional WAV files to be connected to the conference      \n"
  "  bridge. The WAV files MUST have single channel (mono) and 16 bit PCM    \n"
@@ -46,21 +63,6 @@
  "  to slot starting from number one in the bridge. The WAV files can have  \n"
  "  arbitrary sampling rate; the bridge will convert it to its clock rate.  \n"
- "  However, the files MUST have a single audio channel only (i.e. mono).   \n";
-
-#include <pjmedia.h>
-#include <pjlib.h>
-
-#include <stdlib.h>	/* atoi() */
-#include <stdio.h>
-
-
-/* For logging purpose. */
-#define THIS_FILE   "confsample.c"
-
-/* Constants */
-#define CLOCK_RATE	44100
-#define NSAMPLES	(CLOCK_RATE * 20 / 1000)
-#define NCHANNELS	1
-#define NBITS		16
+ "  However, the files MUST have a single audio channel only (i.e. mono).  \n";
+
 
  
@@ -74,17 +76,4 @@
 /* Display VU meter */
 static void monitor_level(pjmedia_conf *conf, int slot, int dir, int dur);
-
-
-/* Util to display the error message for the specified error code  */
-static int app_perror( const char *sender, const char *title, 
-		       pj_status_t status)
-{
-    char errmsg[PJ_ERR_MSG_SIZE];
-
-    pj_strerror(status, errmsg, sizeof(errmsg));
-
-    printf("%s: %s [code=%d]\n", title, errmsg, status);
-    return 1;
-}
 
 
@@ -124,4 +113,10 @@
 int main(int argc, char *argv[])
 {
+    int dev_id = -1;
+    int clock_rate = CLOCK_RATE;
+    int channel_count = NCHANNELS;
+    int samples_per_frame = NSAMPLES;
+    int bits_per_sample = NBITS;
+
     pj_caching_pool cp;
     pjmedia_endpt *med_endpt;
@@ -131,14 +126,8 @@
     int i, port_count, file_count;
     pjmedia_port **file_port;	/* Array of file ports */
+    pjmedia_port *rec_port = NULL;  /* Wav writer port */
 
     char tmp[10];
     pj_status_t status;
-
-
-    /* Just in case user needs help */
-    if (argc > 1 && (*argv[1]=='-' || *argv[1]=='/' || *argv[1]=='?')) {
-	usage();
-	return 1;
-    }
 
 
@@ -146,4 +135,12 @@
     status = pj_init();
     PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
+
+    /* Get command line options. */
+    if (get_snd_options(THIS_FILE, argc, argv, &dev_id, &clock_rate,
+			&channel_count, &samples_per_frame, &bits_per_sample))
+    {
+	usage();
+	return 1;
+    }
 
     /* Must create a pool factory before we can allocate any memory. */
@@ -166,6 +163,6 @@
 
 
-    file_count = argc-1;
-    port_count = file_count + 1;
+    file_count = argc - pj_optind;
+    port_count = file_count + 1 + RECORDER;
 
     /* Create the conference bridge. 
@@ -175,8 +172,8 @@
     status = pjmedia_conf_create( pool,	    /* pool to use	    */
 				  port_count,/* number of ports	    */
-				  CLOCK_RATE,/* sampling rate	    */
-				  NCHANNELS,/* # of channels.	    */
-				  NSAMPLES, /* samples per frame    */
-				  NBITS,    /* bits per sample	    */
+				  clock_rate,
+				  channel_count,
+				  samples_per_frame,
+				  bits_per_sample,
 				  0,	    /* options		    */
 				  &conf	    /* result		    */
@@ -187,4 +184,18 @@
     }
 
+#if RECORDER
+    status = pjmedia_file_writer_port_create( pool, "confrecord.wav",
+					      clock_rate, channel_count,
+					      samples_per_frame, 
+					      bits_per_sample, 0, 0, NULL,
+					      &rec_port);
+    if (status != PJ_SUCCESS) {
+	app_perror(THIS_FILE, "Unable to create WAV writer", status);
+	return 1;
+    }
+
+    pjmedia_conf_add_port(conf, pool, rec_port, NULL, NULL);
+#endif
+
 
     /* Create file ports. */
@@ -194,14 +205,15 @@
 
 	/* Load the WAV file to file port. */
-	status = pjmedia_file_player_port_create( pool,	    /* pool.	    */
-						  argv[i+1],/* filename	    */
-						  0,	    /* flags	    */
-						  0,	    /* buf size	    */
-						  NULL,	    /* user data    */
-						  &file_port[i]	/* result   */
-						  );
+	status = pjmedia_file_player_port_create( 
+			pool,		    /* pool.	    */
+			argv[i+pj_optind],  /* filename	    */
+			0,		    /* flags	    */
+			0,		    /* buf size	    */
+			NULL,		    /* user data    */
+			&file_port[i]	    /* result	    */
+			);
 	if (status != PJ_SUCCESS) {
 	    char title[80];
-	    pj_ansi_sprintf(title, "Unable to use %s", argv[i+1]);
+	    pj_ansi_sprintf(title, "Unable to use %s", argv[i+pj_optind]);
 	    app_perror(THIS_FILE, title, status);
 	    usage();
@@ -214,5 +226,5 @@
 					file_port[i],	/* port to connect  */
 					NULL,		/* Use port's name  */
-					NULL		/* ptr to receive slot # */
+					NULL		/* ptr for slot #   */
 					);
 	if (status != PJ_SUCCESS) {
@@ -229,4 +241,7 @@
      */
 
+
+    /* Dump memory usage */
+    dump_pool_usage(THIS_FILE, &cp);
 
     /* Sleep to allow log messages to flush */
@@ -421,4 +436,8 @@
     }
 
+    /* Destroy recorder port */
+    if (rec_port)
+	pjmedia_port_destroy(rec_port);
+
     /* Release application pool */
     pj_pool_release( pool );
@@ -484,4 +503,5 @@
 		   "  Name                    : %.*s\n"
 		   "  Sampling rate           : %d Hz\n"
+		   "  Samples per frame       : %d\n"
 		   "  Frame time              : %d ms\n"
 		   "  Signal level adjustment : tx=%d, rx=%d\n"
@@ -492,4 +512,5 @@
 		   port_info->name.ptr,
 		   port_info->clock_rate,
+		   port_info->samples_per_frame,
 		   port_info->samples_per_frame*1000/port_info->clock_rate,
 		   port_info->tx_adj_level,
