Index: pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/simpleua.c
===================================================================
--- pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/simpleua.c	(revision 3459)
+++ pjproject/branches/projects/2.0-dev/pjsip-apps/src/samples/simpleua.c	(revision 3460)
@@ -102,10 +102,11 @@
 static pjsip_inv_session    *g_inv;	    /* Current invite session.	*/
 static pjmedia_stream       *g_med_stream;  /* Call's audio stream.	*/
+static pjmedia_snd_port	    *g_snd_port;    /* Sound device.		*/
+
+#if PJMEDIA_HAS_VIDEO
 static pjmedia_vid_stream   *g_med_vstream; /* Call's video stream.	*/
-static pjmedia_snd_port	    *g_snd_player;  /* Call's sound player	*/
-static pjmedia_snd_port	    *g_snd_rec;	    /* Call's sound recorder.	*/
 static pjmedia_vid_port	    *g_vid_capturer;/* Call's video capturer.	*/
 static pjmedia_vid_port	    *g_vid_renderer;/* Call's video renderer.	*/
-
+#endif	/* PJMEDIA_HAS_VIDEO */
 
 /*
@@ -374,4 +375,5 @@
 
     /* Init video subsystem */
+#if PJMEDIA_HAS_VIDEO
     pool = pjmedia_endpt_create_pool(g_med_endpt, "Video subsystem", 512, 512);
     status = pjmedia_video_format_mgr_create(pool, 64, 0, NULL);
@@ -384,8 +386,11 @@
     PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
 
+#  if PJMEDIA_HAS_FFMPEG_CODEC
     /* Init ffmpeg video codecs */
     status = pjmedia_codec_ffmpeg_init(NULL, &cp.factory);
     PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
-
+#  endif  /* PJMEDIA_HAS_FFMPEG_CODEC */
+
+#endif	/* PJMEDIA_HAS_VIDEO */
     
     /* 
@@ -469,11 +474,9 @@
 
 	/* Get the SDP body to be put in the outgoing INVITE, by asking
-	 * media endpoint to create one for us. The SDP will contain all
-	 * codecs that have been registered to it (in this case, only
-	 * PCMA and PCMU), plus telephony event.
+	 * media endpoint to create one for us.
 	 */
 	status = pjmedia_endpt_create_sdp( g_med_endpt,	    /* the media endpt	*/
 					   dlg->pool,	    /* pool.		*/
-					   MAX_MEDIA_CNT,	    /* # of streams	*/
+					   MAX_MEDIA_CNT,   /* # of streams	*/
 					   g_sock_info,     /* RTP sock info	*/
 					   &local_sdp);	    /* the SDP result	*/
@@ -548,21 +551,26 @@
     dump_pool_usage(THIS_FILE, &cp);
 
-    /* Destroy stream */
-    if (g_med_stream)
-	pjmedia_stream_destroy(g_med_stream);
-    if (g_med_vstream)
-	pjmedia_vid_stream_destroy(g_med_vstream);
-
-    /* Destroy audio ports */
-    if (g_snd_player)
-	pjmedia_snd_port_destroy(g_snd_player);
-    if (g_snd_rec)
-	pjmedia_snd_port_destroy(g_snd_rec);
+    /* Destroy audio ports. Destroy the audio port first
+     * before the stream since the audio port has threads
+     * that get/put frames to the stream.
+     */
+    if (g_snd_port)
+	pjmedia_snd_port_destroy(g_snd_port);
 
     /* Destroy video ports */
+#if PJMEDIA_HAS_VIDEO
     if (g_vid_capturer)
 	pjmedia_vid_port_destroy(g_vid_capturer);
     if (g_vid_renderer)
 	pjmedia_vid_port_destroy(g_vid_renderer);
+#endif
+
+    /* Destroy streams */
+    if (g_med_stream)
+	pjmedia_stream_destroy(g_med_stream);
+#if PJMEDIA_HAS_VIDEO
+    if (g_med_vstream)
+	pjmedia_vid_stream_destroy(g_med_vstream);
+#endif
 
     /* Destroy media transports */
@@ -573,5 +581,7 @@
 
     /* Deinit ffmpeg codec */
+#if PJMEDIA_HAS_FFMPEG_CODEC
     pjmedia_codec_ffmpeg_deinit();
+#endif
 
     /* Deinit pjmedia endpoint */
@@ -846,20 +856,17 @@
     pjmedia_stream_get_port(g_med_stream, &media_port);
 
-
-
-    /* Create a sound Player device and connect the media port to the
-     * sound device.
-     */
-    status = pjmedia_snd_port_create_player( 
-		    inv->pool,				/* pool		    */
-		    -1,					/* sound dev id	    */
-		    PJMEDIA_PIA_SRATE(&media_port->info),/* clock rate	    */
-		    PJMEDIA_PIA_CCNT(&media_port->info),/* channel count    */
-		    PJMEDIA_PIA_SPF(&media_port->info), /* samples per frame*/
-		    PJMEDIA_PIA_BITS(&media_port->info),/* bits per sample  */
-		    0,					/* options	    */
-		    &g_snd_player);
+    /* Create sound port */
+    pjmedia_snd_port_create(inv->pool,
+                            PJMEDIA_AUD_DEFAULT_CAPTURE_DEV,
+                            PJMEDIA_AUD_DEFAULT_PLAYBACK_DEV,
+                            PJMEDIA_PIA_SRATE(&media_port->info),/* clock rate	    */
+                            PJMEDIA_PIA_CCNT(&media_port->info),/* channel count    */
+                            PJMEDIA_PIA_SPF(&media_port->info), /* samples per frame*/
+                            PJMEDIA_PIA_BITS(&media_port->info),/* bits per sample  */
+                            0,
+                            &g_snd_port);
+
     if (status != PJ_SUCCESS) {
-	app_perror( THIS_FILE, "Unable to create sound player", status);
+	app_perror( THIS_FILE, "Unable to create sound port", status);
 	PJ_LOG(3,(THIS_FILE, "%d %d %d %d",
 		    PJMEDIA_PIA_SRATE(&media_port->info),/* clock rate	    */
@@ -871,25 +878,5 @@
     }
 
-    status = pjmedia_snd_port_connect(g_snd_player, media_port);
-
-
-    /* Create a sound recorder device and connect the media port to the
-     * sound device.
-     */
-    status = pjmedia_snd_port_create_rec( 
-		    inv->pool,				/* pool		    */
-		    -1,					/* sound dev id	    */
-		    PJMEDIA_PIA_SRATE(&media_port->info),/* clock rate	    */
-		    PJMEDIA_PIA_CCNT(&media_port->info),/* channel count    */
-		    PJMEDIA_PIA_SPF(&media_port->info), /* samples per frame*/
-		    PJMEDIA_PIA_BITS(&media_port->info),/* bits per sample  */
-		    0,					/* options	    */
-		    &g_snd_rec);
-    if (status != PJ_SUCCESS) {
-	app_perror( THIS_FILE, "Unable to create sound recorder", status);
-	return;
-    }
-
-    status = pjmedia_snd_port_connect(g_snd_rec, media_port);
+    status = pjmedia_snd_port_connect(g_snd_port, media_port);
 
 
@@ -898,7 +885,10 @@
      * the port directly to a renderer/capture video device.
      */
+#if PJMEDIA_HAS_VIDEO
     if (local_sdp->media_count > 1) {
 	pjmedia_vid_stream_info vstream_info;
 	pjmedia_vid_port_param vport_param;
+
+	pjmedia_vid_port_param_default(&vport_param);
 
 	/* Create stream info based on the media video SDP. */
@@ -919,7 +909,7 @@
 	 * media socket that we created earlier.
 	 */
-	status = pjmedia_vid_stream_create(g_med_endpt, inv->dlg->pool,
-					   &vstream_info, g_med_transport[1],
-					   NULL, &g_med_vstream);
+	status = pjmedia_vid_stream_create(g_med_endpt, NULL, &vstream_info,
+	                                   g_med_transport[1], NULL,
+	                                   &g_med_vstream);
 	if (status != PJ_SUCCESS) {
 	    app_perror( THIS_FILE, "Unable to create video stream", status);
@@ -933,5 +923,4 @@
 	    return;
 	}
-
 
 	if (vstream_info.dir & PJMEDIA_DIR_DECODING) {
@@ -945,7 +934,11 @@
 	    }
 
-	    /* Get renderer format from decoding format in stream info */
-	    pjmedia_format_copy(&vport_param.vidparam.fmt, 
-				&vstream_info.codec_param->dec_fmt);
+	    /* Get video stream port for decoding direction */
+	    pjmedia_vid_stream_get_port(g_med_vstream, PJMEDIA_DIR_DECODING,
+					&media_port);
+
+	    /* Set format */
+	    pjmedia_format_copy(&vport_param.vidparam.fmt,
+				&media_port->info.fmt);
 	    vport_param.vidparam.dir = PJMEDIA_DIR_RENDER;
 	    vport_param.active = PJ_TRUE;
@@ -959,8 +952,4 @@
 		return;
 	    }
-
-	    /* Get video stream port for decoding direction */
-	    pjmedia_vid_stream_get_port(g_med_vstream, PJMEDIA_DIR_DECODING,
-					&media_port);
 
 	    /* Connect renderer to media_port */
@@ -985,10 +974,11 @@
 	    }
 
-	    /* Get renderer capturer from encoding format in stream info */
+	    /* Get video stream port for decoding direction */
+	    pjmedia_vid_stream_get_port(g_med_vstream, PJMEDIA_DIR_ENCODING,
+					&media_port);
+
+	    /* Get capturer format from stream info */
 	    pjmedia_format_copy(&vport_param.vidparam.fmt, 
-				&vstream_info.codec_param->enc_fmt);
-
-	    /* Capturer format ID should be copied from decoder format ID? */
-	    vport_param.vidparam.fmt.id = vstream_info.codec_param->dec_fmt.id;
+	                        &media_port->info.fmt);
 	    vport_param.vidparam.dir = PJMEDIA_DIR_CAPTURE;
 	    vport_param.active = PJ_TRUE;
@@ -1003,8 +993,4 @@
 	    }
 
-	    /* Get video stream port for decoding direction */
-	    pjmedia_vid_stream_get_port(g_med_vstream, PJMEDIA_DIR_ENCODING,
-					&media_port);
-
 	    /* Connect capturer to media_port */
 	    status = pjmedia_vid_port_connect(g_vid_capturer, media_port, 
@@ -1035,4 +1021,5 @@
 	}
     }
+#endif	/* PJMEDIA_HAS_VIDEO */
 
     /* Done with media. */
