Index: /pjproject/trunk/pjmedia/include/pjmedia/stream.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/stream.h	(revision 289)
+++ /pjproject/trunk/pjmedia/include/pjmedia/stream.h	(revision 290)
@@ -71,5 +71,6 @@
     pjmedia_sock_info	sock_info;  /**< Media transport (RTP/RTCP sockets) */
     pj_sockaddr_in	rem_addr;   /**< Remote RTP address		    */
-    pjmedia_codec_info	fmt;	    /**< Codec format info.		    */
+    pjmedia_codec_info	fmt;	    /**< Incoming codec format info.	    */
+    unsigned		tx_pt;	    /**< Outgoing codec paylaod type.	    */
     int		        tx_event_pt;/**< Outgoing pt for telephone-events.  */
     int			rx_event_pt;/**< Incoming pt for telephone-events.  */
Index: /pjproject/trunk/pjmedia/src/pjmedia/session.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/session.c	(revision 289)
+++ /pjproject/trunk/pjmedia/src/pjmedia/session.c	(revision 290)
@@ -96,5 +96,5 @@
 
 	si->type = PJMEDIA_TYPE_UNKNOWN;
-
+	return PJMEDIA_EINVALIMEDIATYPE;
     }
 
@@ -142,8 +142,11 @@
 
     /* And codec must be numeric! */
-    if (!pj_isdigit(*local_m->desc.fmt[0].ptr))
+    if (!pj_isdigit(*local_m->desc.fmt[0].ptr) || 
+	!pj_isdigit(*rem_m->desc.fmt[0].ptr))
+    {
 	return PJMEDIA_EINVALIDPT;
-
-    /* Get the payload number. */
+    }
+
+    /* Get the payload number for receive channel. */
     pt = pj_strtoul(&local_m->desc.fmt[0]);
 
@@ -162,6 +165,8 @@
 	    return status;
 
+	/* For static payload type, pt's are symetric */
+	si->tx_pt = pt;
+
     } else {
-
 	attr = pjmedia_sdp_media_find_attr(local_m, &ID_RTPMAP, 
 					   &local_m->desc.fmt[0]);
@@ -179,5 +184,40 @@
 	pj_strdup(pool, &si->fmt.encoding_name, &rtpmap->enc_name);
 	si->fmt.sample_rate = rtpmap->clock_rate;
-    }
+
+	/* Determine payload type for outgoing channel, by finding
+	 * dynamic payload type in remote SDP that matches the answer.
+	 */
+	si->tx_pt = 0xFFFF;
+	for (i=0; i<rem_m->desc.fmt_count; ++i) {
+	    unsigned rpt;
+	    pjmedia_sdp_attr *r_attr;
+	    pjmedia_sdp_rtpmap r_rtpmap;
+
+	    rpt = pj_strtoul(&rem_m->desc.fmt[i]);
+	    if (rpt < 96)
+		continue;
+
+	    r_attr = pjmedia_sdp_media_find_attr(rem_m, &ID_RTPMAP,
+						 &rem_m->desc.fmt[i]);
+	    if (!r_attr)
+		continue;
+
+	    if (pjmedia_sdp_attr_get_rtpmap(attr, &r_rtpmap) != PJ_SUCCESS)
+		continue;
+
+	    if (!pj_stricmp(&rtpmap->enc_name, &r_rtpmap.enc_name) &&
+		rtpmap->clock_rate == r_rtpmap.clock_rate)
+	    {
+		/* Found matched codec. */
+		si->tx_pt = rpt;
+		break;
+	    }
+	}
+
+	if (si->tx_pt == 0xFFFF)
+	    return PJMEDIA_EMISSINGRTPMAP;
+    }
+
+  
 
     /* Get local DTMF payload type */
Index: /pjproject/trunk/pjmedia/src/pjmedia/stream.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/stream.c	(revision 289)
+++ /pjproject/trunk/pjmedia/src/pjmedia/stream.c	(revision 290)
@@ -132,5 +132,5 @@
 
     pj_strerror(status, errmsg, sizeof(errmsg));
-    PJ_LOG(3,(sender, "%s: %s [err:%d]", title, errmsg, status));
+    PJ_LOG(4,(sender, "%s: %s [err:%d]", title, errmsg, status));
 }
 
@@ -510,5 +510,8 @@
 	    status != PJMEDIA_RTP_ESESSRESTART) 
 	{
-	    TRACE_((THIS_FILE, "RTP session_update error", status));
+	    TRACE_((THIS_FILE, "RTP session_update error (details follows)", 
+		    status));
+	    PJ_LOG(4,(THIS_FILE,"RTP packet detail: pt=%d, seq=%d",
+		      hdr->pt, pj_ntohs(hdr->seq)));
 	    continue;
 	}
@@ -558,4 +561,5 @@
 				   pjmedia_stream *stream,
 				   pjmedia_dir dir,
+				   unsigned pt,
 				   const pjmedia_stream_info *param,
 				   const pjmedia_codec_param *codec_param,
@@ -575,5 +579,5 @@
     channel->dir = dir;
     channel->paused = 1;
-    channel->pt = param->fmt.pt;
+    channel->pt = pt;
 
     /* Allocate buffer for incoming packet. */
@@ -609,6 +613,5 @@
     /* Create RTP and RTCP sessions: */
 
-    status = pjmedia_rtp_session_init(&channel->rtp, param->fmt.pt, 
-				 param->ssrc);
+    status = pjmedia_rtp_session_init(&channel->rtp, pt, param->ssrc);
     if (status != PJ_SUCCESS)
 	return status;
@@ -749,6 +752,6 @@
     /* Create decoder channel: */
 
-    status = create_channel( pool, stream, PJMEDIA_DIR_DECODING, info,
-			     &codec_param, &stream->dec);
+    status = create_channel( pool, stream, PJMEDIA_DIR_DECODING, 
+			     info->fmt.pt, info, &codec_param, &stream->dec);
     if (status != PJ_SUCCESS)
 	goto err_cleanup;
@@ -757,6 +760,6 @@
     /* Create encoder channel: */
 
-    status = create_channel( pool, stream, PJMEDIA_DIR_ENCODING, info,
-			     &codec_param, &stream->enc);
+    status = create_channel( pool, stream, PJMEDIA_DIR_ENCODING, 
+			     info->tx_pt, info, &codec_param, &stream->enc);
     if (status != PJ_SUCCESS)
 	goto err_cleanup;
