Index: pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/codec.h
===================================================================
--- pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/codec.h	(revision 2456)
+++ pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/codec.h	(revision 2457)
@@ -276,5 +276,5 @@
        pj_uint8_t  pcm_bits_per_sample;	/**< Bits/sample in the PCM side    */
        pj_uint8_t  pt;			/**< Payload type.		    */
-       pjmedia_format format;		/**< Source format, it's format of
+       pjmedia_format_id fmt_id;	/**< Source format, it's format of
 					     encoder input and decoder 
 					     output.			    */
Index: pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/sound.h
===================================================================
--- pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/sound.h	(revision 2456)
+++ pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/sound.h	(revision 2457)
@@ -93,4 +93,20 @@
 } pjmedia_snd_stream_info;
 
+/**
+ * Audio routing destination.
+ */
+typedef enum pjmedia_snd_route
+{
+    /** Route to default destination */
+    PJMEDIA_SND_ROUTE_DEFAULT,
+
+    /** Route to loudspeaker */
+    PJMEDIA_SND_ROUTE_LOUDSPEAKER,
+
+    /** Route to earpiece */
+    PJMEDIA_SND_ROUTE_EARPIECE,
+
+} pjmedia_snd_route;
+
 
 /** 
@@ -100,11 +116,7 @@
 {
     pjmedia_format	format;	  /**< Format.			    */ 
-    pj_uint32_t		bitrate;  /**< Bitrate (bps).		    */
-    pj_uint32_t		mode;	  /**< Mode, e.g: iLBC format has
-				       20ms or 30ms frame size.	    */
     pj_bool_t		plc;	  /**< PLC enabled/disabled.	    */
-    pj_bool_t		vad;	  /**< VAD enabled/disabled.	    */
     pj_bool_t		cng;	  /**< CNG enabled/disabled.	    */
-    pj_bool_t		loudspk;  /**< Audio routed to loudspeaker. */
+    pjmedia_snd_route	route;	  /**< Audio routing.		    */
 } pjmedia_snd_setting;
 
Index: pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/types.h
===================================================================
--- pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/types.h	(revision 2456)
+++ pjproject/branches/projects/aps-direct/pjmedia/include/pjmedia/types.h	(revision 2457)
@@ -179,27 +179,40 @@
 } pjmedia_sock_info;
 
-/**
- * Declaration of format.
- */
-typedef union pjmedia_format {
-   pj_uint32_t  u32;
-   char         c[4];
+
+/**
+ * Macro for packing format.
+ */
+#define PJMEDIA_FORMAT_PACK(C1, C2, C3, C4) ( C4<<24 | C3<<16 | C2<<8 | C1 )
+
+/**
+ * Format identifier definition.
+ */
+typedef enum pjmedia_format_id
+{
+    PJMEDIA_FORMAT_L16	    = 0,
+    PJMEDIA_FORMAT_PCMA	    = PJMEDIA_FORMAT_PACK('A', 'L', 'A', 'W'),
+    PJMEDIA_FORMAT_PCMU	    = PJMEDIA_FORMAT_PACK('u', 'L', 'A', 'W'),
+    PJMEDIA_FORMAT_AMR	    = PJMEDIA_FORMAT_PACK(' ', 'A', 'M', 'R'),
+    PJMEDIA_FORMAT_G729	    = PJMEDIA_FORMAT_PACK('G', '7', '2', '9'),
+    PJMEDIA_FORMAT_ILBC	    = PJMEDIA_FORMAT_PACK('I', 'L', 'B', 'C')
+} pjmedia_format_id;
+
+
+/**
+ * Media format information.
+ */
+typedef struct pjmedia_format
+{
+    /** Format ID */
+    pjmedia_format_id	fmt_id;
+
+    /** Bitrate. */
+    pj_uint32_t		bitrate;
+
+    /** Flag to indicate whether VAD is enabled */
+    pj_bool_t		vad;
+
 } pjmedia_format;
 
-
-/**
- * Macro for packing format.
- */
-#define PJMEDIA_FORMAT_PACK(C1, C2, C3, C4) ( C4<<24 | C3<<16 | C2<<8 | C1 )
-
-/**
- * Format identifier definitions.
- */
-#define PJMEDIA_FORMAT_L16	0
-#define PJMEDIA_FORMAT_PCMA	PJMEDIA_FORMAT_PACK('A', 'L', 'A', 'W')
-#define PJMEDIA_FORMAT_PCMU	PJMEDIA_FORMAT_PACK('u', 'L', 'A', 'W')
-#define PJMEDIA_FORMAT_AMR	PJMEDIA_FORMAT_PACK(' ', 'A', 'M', 'R')
-#define PJMEDIA_FORMAT_G729	PJMEDIA_FORMAT_PACK('G', '7', '2', '9')
-#define PJMEDIA_FORMAT_ILBC	PJMEDIA_FORMAT_PACK('I', 'L', 'B', 'C')
 
 
Index: pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia-codec/passthrough.c
===================================================================
--- pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia-codec/passthrough.c	(revision 2456)
+++ pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia-codec/passthrough.c	(revision 2457)
@@ -156,5 +156,5 @@
     const char	    *name;		/* Codec name.			    */
     pj_uint8_t	     pt;		/* Payload type.		    */
-    pjmedia_format   format;		/* Source format.		    */
+    pjmedia_format_id fmt_id;		/* Source format.		    */
     unsigned	     clock_rate;	/* Codec's clock rate.		    */
     unsigned	     channel_count;	/* Codec's channel count.	    */
@@ -173,5 +173,5 @@
 {
 #   if PJMEDIA_HAS_PASSTHROUGH_CODEC_AMR
-    {1, "AMR",	    PJMEDIA_RTP_PT_AMR,       {PJMEDIA_FORMAT_AMR},
+    {1, "AMR",	    PJMEDIA_RTP_PT_AMR,       PJMEDIA_FORMAT_AMR,
 		    8000, 1, 160, 
 		    7400, 12200, 2, 1, 1,
@@ -182,5 +182,5 @@
 
 #   if PJMEDIA_HAS_PASSTHROUGH_CODEC_G729
-    {1, "G729",	    PJMEDIA_RTP_PT_G729,      {PJMEDIA_FORMAT_G729},
+    {1, "G729",	    PJMEDIA_RTP_PT_G729,      PJMEDIA_FORMAT_G729,
 		    8000, 1,  80,
 		    8000, 8000, 2, 1, 1
@@ -189,5 +189,5 @@
 
 #   if PJMEDIA_HAS_PASSTHROUGH_CODEC_ILBC
-    {1, "iLBC",	    PJMEDIA_RTP_PT_ILBC,      {PJMEDIA_FORMAT_ILBC},
+    {1, "iLBC",	    PJMEDIA_RTP_PT_ILBC,      PJMEDIA_FORMAT_ILBC,
 		    8000, 1,  240,
 		    13333, 15200, 1, 1, 1,
@@ -198,5 +198,5 @@
 
 #   if PJMEDIA_HAS_PASSTHROUGH_CODEC_PCMU
-    {1, "PCMU",	    PJMEDIA_RTP_PT_PCMU,      {PJMEDIA_FORMAT_PCMU},
+    {1, "PCMU",	    PJMEDIA_RTP_PT_PCMU,      PJMEDIA_FORMAT_PCMU,
 		    8000, 1,  80,
 		    64000, 64000, 2, 1, 1
@@ -205,5 +205,5 @@
 
 #   if PJMEDIA_HAS_PASSTHROUGH_CODEC_PCMA
-    {1, "PCMA",	    PJMEDIA_RTP_PT_PCMA,      {PJMEDIA_FORMAT_PCMA},
+    {1, "PCMA",	    PJMEDIA_RTP_PT_PCMA,      PJMEDIA_FORMAT_PCMA,
 		    8000, 1,  80,
 		    64000, 64000, 2, 1, 1
@@ -450,5 +450,5 @@
 				    codec_desc[i].channel_count / 
 				    codec_desc[i].clock_rate);
-	    attr->info.format = codec_desc[i].format;
+	    attr->info.fmt_id = codec_desc[i].fmt_id;
 
 	    /* Default flags. */
Index: pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/conf_switch.c
===================================================================
--- pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/conf_switch.c	(revision 2456)
+++ pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/conf_switch.c	(revision 2457)
@@ -589,5 +589,5 @@
 
     /* Source and sink format must match. */
-    if (src_port->info->format.u32 != dst_port->info->format.u32) {
+    if (src_port->info->format.fmt_id != dst_port->info->format.fmt_id) {
 	pj_mutex_unlock(conf->mutex);
 	return PJMEDIA_ENOTCOMPATIBLE;
@@ -952,5 +952,5 @@
 
     /* Level adjustment is applicable only for ports that work with raw PCM. */
-    PJ_ASSERT_RETURN(conf_port->info->format.u32 == PJMEDIA_FORMAT_L16,
+    PJ_ASSERT_RETURN(conf_port->info->format.fmt_id == PJMEDIA_FORMAT_L16,
 		     PJ_EIGNORED);
 
@@ -986,5 +986,5 @@
 
     /* Level adjustment is applicable only for ports that work with raw PCM. */
-    PJ_ASSERT_RETURN(conf_port->info->format.u32 == PJMEDIA_FORMAT_L16,
+    PJ_ASSERT_RETURN(conf_port->info->format.fmt_id == PJMEDIA_FORMAT_L16,
 		     PJ_EIGNORED);
 
@@ -1111,5 +1111,5 @@
 	/* Check port format. */
 	if (cport_dst->port &&
-	    cport_dst->port->info.format.u32 == PJMEDIA_FORMAT_L16)
+	    cport_dst->port->info.format.fmt_id == PJMEDIA_FORMAT_L16)
 	{
 	    /* When there is already some samples in listener's TX buffer, 
Index: pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/sound_port.c
===================================================================
--- pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/sound_port.c	(revision 2456)
+++ pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/sound_port.c	(revision 2457)
@@ -290,5 +290,5 @@
 	unsigned i, size_decoded;
 
-	switch (snd_port->setting.format.u32) {
+	switch (snd_port->setting.format.fmt_id) {
 	case PJMEDIA_FORMAT_PCMA:
 	    decoder = &pjmedia_alaw_decode;
@@ -299,5 +299,5 @@
 	default:
 	    PJ_LOG(1,(THIS_FILE, "Unsupported format %d", 
-		      snd_port->setting.format.u32));
+		      snd_port->setting.format.fmt_id));
 	    goto no_frame;
 	}
@@ -392,5 +392,5 @@
     fx->base.timestamp.u32.lo = timestamp;
 
-    switch (snd_port->setting.format.u32) {
+    switch (snd_port->setting.format.fmt_id) {
     case PJMEDIA_FORMAT_PCMA:
 	encoder = &pjmedia_alaw_encode;
@@ -401,5 +401,5 @@
     default:
 	PJ_LOG(1,(THIS_FILE, "Unsupported format %d", 
-		  snd_port->setting.format.u32));
+		  snd_port->setting.format.fmt_id));
 	return PJ_SUCCESS;
     }
@@ -435,5 +435,5 @@
 		     PJ_EBUG);
 
-    if (snd_port->setting.format.u32 == PJMEDIA_FORMAT_L16) {
+    if (snd_port->setting.format.fmt_id == PJMEDIA_FORMAT_L16) {
 	snd_rec_cb = &rec_cb;
 	snd_play_cb = &play_cb;
@@ -716,5 +716,5 @@
 #if !defined(PJMEDIA_SND_SUPPORT_OPEN2) || PJMEDIA_SND_SUPPORT_OPEN2==0
     /* For devices that doesn't support open2(), enable simulation */
-    if (snd_port->setting.format.u32 != PJMEDIA_FORMAT_L16) {
+    if (snd_port->setting.format.fmt_id != PJMEDIA_FORMAT_L16) {
 	snd_port->frm_buf_size = sizeof(pjmedia_frame_ext) + 
 				 (samples_per_frame << 1) +
Index: pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/stream.c
===================================================================
--- pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/stream.c	(revision 2456)
+++ pjproject/branches/projects/aps-direct/pjmedia/src/pjmedia/stream.c	(revision 2457)
@@ -868,5 +868,5 @@
     } else if (frame->type == PJMEDIA_FRAME_TYPE_AUDIO &&
 	       frame->buf == NULL &&
-	       stream->port.info.format.u32 == PJMEDIA_FORMAT_L16 &&
+	       stream->port.info.format.fmt_id == PJMEDIA_FORMAT_L16 &&
 	       (stream->dir & PJMEDIA_DIR_ENCODING) &&
 	       stream->codec_param.info.frm_ptime *
@@ -1606,7 +1606,9 @@
     stream->port.info.clock_rate = info->fmt.clock_rate;
     stream->port.info.channel_count = info->fmt.channel_cnt;
-    stream->port.info.format = info->param->info.format;
+    stream->port.info.format.fmt_id = info->param->info.fmt_id;
+    stream->port.info.format.bitrate = info->param->info.avg_bps;
+    stream->port.info.format.vad = (info->param->setting.vad != 0);
     stream->port.port_data.pdata = stream;
-    if (stream->port.info.format.u32 == PJMEDIA_FORMAT_L16) {
+    if (stream->port.info.format.fmt_id == PJMEDIA_FORMAT_L16) {
 	stream->port.put_frame = &put_frame;
 	stream->port.get_frame = &get_frame;
Index: pjproject/branches/projects/aps-direct/pjsip-apps/src/pjsua/pjsua_app.c
===================================================================
--- pjproject/branches/projects/aps-direct/pjsip-apps/src/pjsua/pjsua_app.c	(revision 2456)
+++ pjproject/branches/projects/aps-direct/pjsip-apps/src/pjsua/pjsua_app.c	(revision 2457)
@@ -2434,4 +2434,5 @@
     pjmedia_port *conf;
     pjmedia_session_info sess_info;
+    pjmedia_port *port;
     pjmedia_stream_info *strm_info;
     pjmedia_snd_setting setting;
@@ -2446,10 +2447,10 @@
     strm_info = &sess_info.stream_info[stream_idx];
 
+    pjmedia_session_get_port(sess, stream_idx, &port);
+
     /* Init sound device setting based on stream info. */
     pj_bzero(&setting, sizeof(setting));
-    setting.format = strm_info->param->info.format;
-    setting.bitrate = strm_info->param->info.avg_bps;
+    setting.format = port->info.format;
     setting.cng = strm_info->param->setting.cng;
-    setting.vad = strm_info->param->setting.vad;
     setting.plc = strm_info->param->setting.plc;
 
