Index: /pjproject/trunk/pjmedia/include/pjmedia/errno.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/errno.h	(revision 139)
+++ /pjproject/trunk/pjmedia/include/pjmedia/errno.h	(revision 140)
@@ -150,27 +150,42 @@
 /**
  * @hideinitializer
+ * No initial local SDP.
+ */
+#define PJMEDIA_SDPNEG_ENOINITIAL   (PJMEDIA_ERRNO_START+41)    /* 220041 */
+/**
+ * @hideinitializer
  * No currently active SDP.
  */
-#define PJMEDIA_SDPNEG_ENOACTIVE    (PJMEDIA_ERRNO_START+41)    /* 220041 */
+#define PJMEDIA_SDPNEG_ENOACTIVE    (PJMEDIA_ERRNO_START+42)    /* 220042 */
+/**
+ * @hideinitializer
+ * No current offer or answer.
+ */
+#define PJMEDIA_SDPNEG_ENONEG	    (PJMEDIA_ERRNO_START+43)    /* 220043 */
 /**
  * @hideinitializer
  * Media count mismatch in offer and answer.
  */
-#define PJMEDIA_SDPNEG_EMISMEDIA    (PJMEDIA_ERRNO_START+42)    /* 220042 */
+#define PJMEDIA_SDPNEG_EMISMEDIA    (PJMEDIA_ERRNO_START+44)    /* 220044 */
 /**
  * @hideinitializer
  * Media type is different in the remote answer.
  */
-#define PJMEDIA_SDPNEG_EINVANSMEDIA (PJMEDIA_ERRNO_START+43)    /* 220043 */
+#define PJMEDIA_SDPNEG_EINVANSMEDIA (PJMEDIA_ERRNO_START+45)    /* 220045 */
 /**
  * @hideinitializer
  * Transport type is different in the remote answer.
  */
-#define PJMEDIA_SDPNEG_EINVANSTP    (PJMEDIA_ERRNO_START+44)    /* 220044 */
+#define PJMEDIA_SDPNEG_EINVANSTP    (PJMEDIA_ERRNO_START+46)    /* 220046 */
 /**
  * @hideinitializer
  * No common media payload is provided in the answer.
  */
-#define PJMEDIA_SDPNEG_EANSNOMEDIA  (PJMEDIA_ERRNO_START+45)    /* 220045 */
+#define PJMEDIA_SDPNEG_EANSNOMEDIA  (PJMEDIA_ERRNO_START+47)    /* 220047 */
+/**
+ * @hideinitializer
+ * No media is active after negotiation.
+ */
+#define PJMEDIA_SDPNEG_ENOMEDIA	    (PJMEDIA_ERRNO_START+48)    /* 220048 */
 
 
Index: /pjproject/trunk/pjmedia/include/pjmedia/sdp_neg.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/sdp_neg.h	(revision 139)
+++ /pjproject/trunk/pjmedia/include/pjmedia/sdp_neg.h	(revision 140)
@@ -40,5 +40,27 @@
 
 /**
- * This enumeration describes SDP negotiation state.
+ * This enumeration describes SDP negotiation state. The negotiator state
+ * is illustrated in the following diagram.
+ * 
+ * <pre>
+ *                                              reinit_local_offer()
+ *                                              modify_local_offer()
+ *     create_w_local_offer()  +-------------+  send_local_offer()
+ *     ----------------------->| LOCAL_OFFER |<-----------------------
+ *    |                        +-------------+                        |
+ *    |                               |                               |
+ *    |           set_remote_answer() |                               |
+ *    |                               V                               |
+ * +--+---+                     +-----------+     negotiate()     +------+
+ * | NULL |                     | WAIT_NEGO |-------------------->| DONE |
+ * +------+                     +-----------+                     +------+
+ *    |                               A                               |
+ *    |            set_local_answer() |                               |
+ *    |                               |                               |
+ *    |                        +--------------+   set_remote_offer()  |
+ *     ----------------------->| REMOTE_OFFER |<----------------------
+ *     create_w_remote_offer() +--------------+
+ *
+ * </pre>
  */
 enum pjmedia_sdp_neg_state
@@ -51,12 +73,19 @@
     /** 
      * This state occurs when SDP negotiator has sent our offer to remote and
-     * it is waiting for answer.
+     * it is waiting for answer. 
      */
     PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER,
+
+    /** 
+     * This state occurs when SDP negotiator has received offer from remote
+     * and currently waiting for local answer.
+     */
+    PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER,
 
     /**
      * This state occurs when an offer (either local or remote) has been 
      * provided with answer. The SDP negotiator is ready to negotiate both
-     * session descriptors.
+     * session descriptors. Application can call #pjmedia_sdp_neg_negotiate()
+     * immediately to begin negotiation process.
      */
     PJMEDIA_SDP_NEG_STATE_WAIT_NEGO,
@@ -69,30 +98,21 @@
 };
 
-/* Negotiator state:
- *
- *                                                 reinit_local_offer()
- *                                                 modify_local_offer()
- *     create_w_local_offer()     +-------------+  tx_local_offer()
- *     /------------------------->| LOCAL_OFFER |<----------------------\
- *    |                           +-------------+                        |
- *    |                                  |                               |
- *    |               rx_remote_answer() |                               |
- *    |                                  V                               |
- * +--+---+                         +-----------+     negotiate()     +------+
- * + NULL |------------------------>| WAIT_NEGO |-------------------->| DONE |
- * +------+ create_w_remote_offer() +-----------+                     +------+
- *                                       A                               |
- *                                       |         rx_remote_offer()     |
- *                                        \-----------------------------/
- */ 
-
 /**
  * Create the SDP negotiator with local offer. The SDP negotiator then
  * will move to PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER state, where it waits
  * until it receives answer from remote. When SDP answer from remote is
- * received, application should call #pjmedia_sdp_neg_rx_remote_answer().
+ * received, application should call #pjmedia_sdp_neg_set_remote_answer().
  *
  * After calling this function, application should send the local SDP offer
- * to remote party and wait for SDP answer.
+ * to remote party using higher layer signaling protocol (e.g. SIP) and 
+ * wait for SDP answer.
+ *
+ * @param pool		Pool to allocate memory. The pool's lifetime needs
+ *			to be valid for the duration of the negotiator.
+ * @param local		The initial local capability.
+ * @param p_neg		Pointer to receive the negotiator instance.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error
+ *			code.
  */
 PJ_DECL(pj_status_t) 
@@ -102,14 +122,33 @@
 
 /**
- * Initialize the SDP negotiator with both local and remote offer. 
- * Application normally calls this function when it receives initial offer
- * from remote. Application must also provide initial local offer when
- * calling this function. After this function is called, the SDP negotiator
- * state will move to PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, and the negotiation
- * function can be called.
+ * Initialize the SDP negotiator with remote offer, and optionally
+ * specify the initial local capability, if known. Application normally 
+ * calls this function when it receives initial offer
+ * from remote. 
+ *
+ * If local media capability is specified, this capability will be set as
+ * initial local capability of the negotiator, and after this function is
+ * called, the SDP negotiator state will move to state
+ * PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, and the negotiation function can be 
+ * called. 
+ *
+ * If local SDP is not specified, the negotiator will not have initial local
+ * capability, and after this function is called the negotiator state will 
+ * move to PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER state. Application MUST supply
+ * local answer later with #pjmedia_sdp_neg_set_local_answer(), before
+ * calling the negotiation function.
+ *
+ * @param pool		Pool to allocate memory. The pool's lifetime needs
+ *			to be valid for the duration of the negotiator.
+ * @param initial	Optional initial local capability.
+ * @param remote	The remote offer.
+ * @param p_neg		Pointer to receive the negotiator instance.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate error
+ *			code.
  */
 PJ_DECL(pj_status_t) 
 pjmedia_sdp_neg_create_w_remote_offer(pj_pool_t *pool,
-				      const pjmedia_sdp_session *local,
+				      const pjmedia_sdp_session *initial,
 				      const pjmedia_sdp_session *remote,
 				      pjmedia_sdp_neg **p_neg);
@@ -117,4 +156,8 @@
 /**
  * Get SDP negotiator state.
+ *
+ * @param neg		The SDP negotiator instance.
+ *
+ * @return		The negotiator state.
  */
 PJ_DECL(pjmedia_sdp_neg_state)
@@ -126,8 +169,13 @@
  * active SDPs. Calling this function will not change the state of the 
  * negotiator.
- */
-PJ_DECL(pj_status_t) 
-pjmedia_sdp_neg_get_local( pjmedia_sdp_neg *neg,
-			   const pjmedia_sdp_session **local);
+ *
+ * @param neg		The SDP negotiator instance.
+ * @param local		Pointer to receive the local active SDP.
+ *
+ * @return		PJ_SUCCESS if local active SDP is present.
+ */
+PJ_DECL(pj_status_t) 
+pjmedia_sdp_neg_get_active_local( pjmedia_sdp_neg *neg,
+				  const pjmedia_sdp_session **local);
 
 /**
@@ -136,9 +184,50 @@
  * active SDPs. Calling this function will not change the state of the 
  * negotiator.
- */
-PJ_DECL(pj_status_t) 
-pjmedia_sdp_neg_get_remote( pjmedia_sdp_neg *neg,
-			    const pjmedia_sdp_session **remote);
-
+ *
+ * @param neg		The SDP negotiator instance.
+ * @param remote	Pointer to receive the remote active SDP.
+ *
+ * @return		PJ_SUCCESS if remote active SDP is present.
+ */
+PJ_DECL(pj_status_t) 
+pjmedia_sdp_neg_get_active_remote( pjmedia_sdp_neg *neg,
+				   const pjmedia_sdp_session **remote);
+
+/**
+ * Get the current remote SDP offer or answer. Application can only 
+ * call this function in state PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER or
+ * PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, or otherwise there won't be remote 
+ * SDP offer/answer. Calling this  function will not change the state 
+ * of the negotiator.
+ *
+ * @param neg		The SDP negotiator instance.
+ * @param remote	Pointer to receive the current remote offer or
+ *			answer.
+ *
+ * @return		PJ_SUCCESS if the negotiator currently has
+ *			remote offer or answer.
+ */
+PJ_DECL(pj_status_t)
+pjmedia_sdp_neg_get_neg_remote( pjmedia_sdp_neg *neg,
+				const pjmedia_sdp_session **remote);
+
+
+/**
+ * Get the current local SDP offer or answer. Application can only 
+ * call this function in state PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER or
+ * PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, or otherwise there won't be local 
+ * SDP offer/answer. Calling this function will not change the state 
+ * of the negotiator.
+ *
+ * @param neg		The SDP negotiator instance.
+ * @param local		Pointer to receive the current local offer or
+ *			answer.
+ *
+ * @return		PJ_SUCCESS if the negotiator currently has
+ *			local offer or answer.
+ */
+PJ_DECL(pj_status_t) 
+pjmedia_sdp_neg_get_neg_local( pjmedia_sdp_neg *neg,
+			       const pjmedia_sdp_session **local);
 
 /**
@@ -148,4 +237,12 @@
  * The negotiator state will move to PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER,
  * where it waits for SDP answer from remote.
+ *
+ * @param pool		Pool to allocate memory. The pool's lifetime needs
+ *			to be valid for the duration of the negotiator.
+ * @param neg		The SDP negotiator instance.
+ * @param local		The new local SDP.
+ *
+ * @return		PJ_SUCCESS on success, or the appropriate
+ *			error code.
  */
 PJ_DECL(pj_status_t) 
@@ -158,5 +255,22 @@
  * SDP negotiator must be in PJMEDIA_SDP_NEG_STATE_WAIT_NEGO state.
  * After calling this function, the negotiator state will move to
- * PJMEDIA_SDP_NEG_STATE_DONE.
+ * PJMEDIA_SDP_NEG_STATE_DONE regardless whether the negotiation has
+ * been successfull or not.
+ *
+ * If the negotiation succeeds (i.e. the return value is PJ_SUCCESS),
+ * the active local and remote SDP will be replaced with the new SDP
+ * from the negotiation process.
+ *
+ * If the negotiation fails, the active local and remote SDP will not
+ * change.
+ *
+ * @param pool		Pool to allocate memory. The pool's lifetime needs
+ *			to be valid for the duration of the negotiator.
+ * @param neg		The SDP negotiator instance.
+ * @param allow_asym	Should be zero.
+ *
+ * @return		PJ_SUCCESS when there is at least one media
+ *			is actuve common in both offer and answer, or 
+ *			failure code when negotiation has failed.
  */
 PJ_DECL(pj_status_t) pjmedia_sdp_neg_negotiate( pj_pool_t *pool,
@@ -170,10 +284,41 @@
  * local SDP to be sent to remote. The negotiator state will then move
  * to PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER, where it waits for SDP answer
- * from remote.
- */
-PJ_DECL(pj_status_t) 
-pjmedia_sdp_neg_tx_local_offer( pj_pool_t *pool,
-			        pjmedia_sdp_neg *neg,
-				const pjmedia_sdp_session **offer);
+ * from remote. When SDP answer has been received from remote, application
+ * must call #pjmedia_sdp_neg_set_remote_answer().
+ *
+ * @param pool		Pool to allocate memory. The pool's lifetime needs
+ *			to be valid for the duration of the negotiator.
+ * @param neg		The SDP negotiator instance.
+ * @param offer		Pointer to receive active local SDP to be
+ *			offered to remote.
+ *
+ * @return		PJ_SUCCESS if local offer can be created.
+ */
+PJ_DECL(pj_status_t) 
+pjmedia_sdp_neg_send_local_offer( pj_pool_t *pool,
+			          pjmedia_sdp_neg *neg,
+				  const pjmedia_sdp_session **offer);
+
+/**
+ * This function can only be called in PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER
+ * state, i.e. after application calls #pjmedia_sdp_neg_send_local_offer()
+ * function. Application calls this function when it receives SDP answer
+ * from remote. After this function is called, the negotiator state will
+ * move to PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, and application can call the
+ * negotiation function #pjmedia_sdp_neg_negotiate().
+ *
+ * @param pool		Pool to allocate memory. The pool's lifetime needs
+ *			to be valid for the duration of the negotiator.
+ * @param neg		The SDP negotiator instance.
+ * @param remote	The remote answer.
+ *
+ * @return		PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) 
+pjmedia_sdp_neg_set_remote_answer( pj_pool_t *pool,
+				   pjmedia_sdp_neg *neg,
+				   const pjmedia_sdp_session *remote);
+
+
 
 /**
@@ -181,24 +326,47 @@
  * Application calls this function when it receives SDP offer from remote.
  * After this function is called, the negotiator state will move to 
- * PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, and application can call the
- * negotiation function #pjmedia_sdp_neg_negotiate().
- */
-PJ_DECL(pj_status_t) 
-pjmedia_sdp_neg_rx_remote_offer( pj_pool_t *pool,
-				 pjmedia_sdp_neg *neg,
-				 const pjmedia_sdp_session *remote);
-
-
-/**
- * This function can only be called in PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER
- * state. Application calls this function when it receives SDP answer
- * from remote. After this function is called, the negotiator state will
+ * PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER, and application MUST call the
+ * #pjmedia_sdp_neg_set_local_answer() to set local answer before it can
+ * call the negotiation function.
+ *
+ * @param pool		Pool to allocate memory. The pool's lifetime needs
+ *			to be valid for the duration of the negotiator.
+ * @param neg		The SDP negotiator instance.
+ * @param remote	The remote offer.
+ *
+ * @return		PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) 
+pjmedia_sdp_neg_set_remote_offer( pj_pool_t *pool,
+				  pjmedia_sdp_neg *neg,
+				  const pjmedia_sdp_session *remote);
+
+
+
+/**
+ * This function can only be called in PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER
+ * state, i.e. after application calls #pjmedia_sdp_neg_set_remote_offer()
+ * function. After this function is called, the negotiator state will
  * move to PJMEDIA_SDP_NEG_STATE_WAIT_NEGO, and application can call the
  * negotiation function #pjmedia_sdp_neg_negotiate().
- */
-PJ_DECL(pj_status_t) 
-pjmedia_sdp_neg_rx_remote_answer( pj_pool_t *pool,
+ *
+ * @param pool		Pool to allocate memory. The pool's lifetime needs
+ *			to be valid for the duration of the negotiator.
+ * @param neg		The SDP negotiator instance.
+ * @param local		Optional local answer. If negotiator has initial
+ *			local capability, application can specify NULL on
+ *			this argument; in this case, the negotiator will
+ *			create answer by by negotiating remote offer with
+ *			initial local capability. If negotiator doesn't have
+ *			initial local capability, application MUST specify
+ *			local answer here.
+ *
+ * @return		PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) 
+pjmedia_sdp_neg_set_local_answer( pj_pool_t *pool,
 				  pjmedia_sdp_neg *neg,
-				  const pjmedia_sdp_session *remote);
+				  const pjmedia_sdp_session *local);
+
 
 
Index: /pjproject/trunk/pjmedia/src/pjmedia/errno.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/errno.c	(revision 139)
+++ /pjproject/trunk/pjmedia/src/pjmedia/errno.c	(revision 140)
@@ -54,9 +54,12 @@
     /* SDP negotiator errors. */
     { PJMEDIA_SDPNEG_EINSTATE,	    "Invalid SDP negotiator state for operation" },
+    { PJMEDIA_SDPNEG_ENOINITIAL,    "No initial local SDP in SDP negotiator" },
     { PJMEDIA_SDPNEG_ENOACTIVE,	    "No active SDP in SDP negotiator" },
+    { PJMEDIA_SDPNEG_ENONEG,	    "No current local/remote offer/answer" },
     { PJMEDIA_SDPNEG_EMISMEDIA,	    "SDP media count mismatch in offer/answer" },
     { PJMEDIA_SDPNEG_EINVANSMEDIA,  "SDP media type mismatch in offer/answer" },
     { PJMEDIA_SDPNEG_EINVANSTP,	    "SDP media transport type mismatch in offer/answer" },
     { PJMEDIA_SDPNEG_EANSNOMEDIA,   "No common SDP media payload in answer" },
+    { PJMEDIA_SDPNEG_ENOMEDIA,	    "No active media stream after negotiation" },
 
     /* SDP comparison results */
Index: /pjproject/trunk/pjmedia/src/pjmedia/sdp.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/sdp.c	(revision 139)
+++ /pjproject/trunk/pjmedia/src/pjmedia/sdp.c	(revision 140)
@@ -1094,4 +1094,5 @@
 {
     unsigned i;
+    const pj_str_t STR_RTPMAP = { "rtpmap", 6 };
 
     CHECK( sdp != NULL, PJ_EINVAL);
@@ -1156,5 +1157,5 @@
 		const pjmedia_sdp_attr *a;
 
-		a = pjmedia_sdp_media_find_attr2(m, "rtpmap", &m->desc.fmt[j]);
+		a = pjmedia_sdp_media_find_attr(m,&STR_RTPMAP,&m->desc.fmt[j]);
 		CHECK( a != NULL, PJMEDIA_SDP_EMISSINGRTPMAP);
 	    }
Index: /pjproject/trunk/pjmedia/src/pjmedia/sdp_neg.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/sdp_neg.c	(revision 139)
+++ /pjproject/trunk/pjmedia/src/pjmedia/sdp_neg.c	(revision 140)
@@ -78,5 +78,5 @@
 PJ_DEF(pj_status_t) 
 pjmedia_sdp_neg_create_w_remote_offer(pj_pool_t *pool,
-				      const pjmedia_sdp_session *local,
+				      const pjmedia_sdp_session *initial,
 				      const pjmedia_sdp_session *remote,
 				      pjmedia_sdp_neg **p_neg)
@@ -86,13 +86,12 @@
 
     /* Check arguments are valid. */
-    PJ_ASSERT_RETURN(pool && local && remote && p_neg, PJ_EINVAL);
+    PJ_ASSERT_RETURN(pool && remote && p_neg, PJ_EINVAL);
 
     *p_neg = NULL;
 
-    /* Validate remote offer and local answer */
+    /* Validate remote offer and initial answer */
     status = pjmedia_sdp_validate(remote);
     if (status != PJ_SUCCESS)
 	return status;
-    PJ_ASSERT_RETURN((status=pjmedia_sdp_validate(local))==PJ_SUCCESS, status);
 
     /* Create and initialize negotiator. */
@@ -100,13 +99,20 @@
     PJ_ASSERT_RETURN(neg != NULL, PJ_ENOMEM);
 
-    neg->state = PJMEDIA_SDP_NEG_STATE_WAIT_NEGO;
-    neg->initial_sdp = pjmedia_sdp_session_clone(pool, local);
-    PJ_ASSERT_RETURN((status=pjmedia_sdp_validate(neg->initial_sdp))==PJ_SUCCESS,
-		     status);
-
-    neg->neg_local_sdp = pjmedia_sdp_session_clone(pool, local);
     neg->neg_remote_sdp = pjmedia_sdp_session_clone(pool, remote);
-    PJ_ASSERT_RETURN((status=pjmedia_sdp_validate(neg->neg_remote_sdp))==PJ_SUCCESS,
-		      status);
+
+    if (initial) {
+	PJ_ASSERT_RETURN((status=pjmedia_sdp_validate(initial))==PJ_SUCCESS, 
+			 status);
+
+	neg->initial_sdp = pjmedia_sdp_session_clone(pool, initial);
+	neg->neg_local_sdp = pjmedia_sdp_session_clone(pool, initial);
+
+	neg->state = PJMEDIA_SDP_NEG_STATE_WAIT_NEGO;
+
+    } else {
+	
+	neg->state = PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER;
+
+    }
 
     *p_neg = neg;
@@ -127,6 +133,6 @@
 
 PJ_DEF(pj_status_t) 
-pjmedia_sdp_neg_get_local( pjmedia_sdp_neg *neg,
-			   const pjmedia_sdp_session **local)
+pjmedia_sdp_neg_get_active_local( pjmedia_sdp_neg *neg,
+				  const pjmedia_sdp_session **local)
 {
     PJ_ASSERT_RETURN(neg && local, PJ_EINVAL);
@@ -139,6 +145,6 @@
 
 PJ_DEF(pj_status_t) 
-pjmedia_sdp_neg_get_remote( pjmedia_sdp_neg *neg,
-			    const pjmedia_sdp_session **remote)
+pjmedia_sdp_neg_get_active_remote( pjmedia_sdp_neg *neg,
+				   const pjmedia_sdp_session **remote)
 {
     PJ_ASSERT_RETURN(neg && remote, PJ_EINVAL);
@@ -146,4 +152,26 @@
 
     *remote = neg->active_remote_sdp;
+    return PJ_SUCCESS;
+}
+
+PJ_DEF(pj_status_t)
+pjmedia_sdp_neg_get_neg_remote( pjmedia_sdp_neg *neg,
+				const pjmedia_sdp_session **remote)
+{
+    PJ_ASSERT_RETURN(neg && remote, PJ_EINVAL);
+    PJ_ASSERT_RETURN(neg->neg_remote_sdp, PJMEDIA_SDPNEG_ENONEG);
+
+    *remote = neg->neg_remote_sdp;
+    return PJ_SUCCESS;
+}
+
+PJ_DEF(pj_status_t) 
+pjmedia_sdp_neg_get_neg_local( pjmedia_sdp_neg *neg,
+			       const pjmedia_sdp_session **local)
+{
+    PJ_ASSERT_RETURN(neg && local, PJ_EINVAL);
+    PJ_ASSERT_RETURN(neg->neg_local_sdp, PJMEDIA_SDPNEG_ENONEG);
+
+    *local = neg->neg_local_sdp;
     return PJ_SUCCESS;
 }
@@ -175,7 +203,7 @@
 
 PJ_DEF(pj_status_t) 
-pjmedia_sdp_neg_tx_local_offer( pj_pool_t *pool,
-				pjmedia_sdp_neg *neg,
-				const pjmedia_sdp_session **offer)
+pjmedia_sdp_neg_send_local_offer( pj_pool_t *pool,
+				  pjmedia_sdp_neg *neg,
+				  const pjmedia_sdp_session **offer)
 {
     /* Check arguments are valid. */
@@ -211,7 +239,30 @@
 
 PJ_DEF(pj_status_t) 
-pjmedia_sdp_neg_rx_remote_offer( pj_pool_t *pool,
-				 pjmedia_sdp_neg *neg,
-				 const pjmedia_sdp_session *remote)
+pjmedia_sdp_neg_set_remote_answer( pj_pool_t *pool,
+				   pjmedia_sdp_neg *neg,
+				   const pjmedia_sdp_session *remote)
+{
+    /* Check arguments are valid. */
+    PJ_ASSERT_RETURN(pool && neg && remote, PJ_EINVAL);
+
+    /* Can only do this in STATE_LOCAL_OFFER.
+     * If we haven't provided local offer, then rx_remote_offer() should
+     * be called instead of this function.
+     */
+    PJ_ASSERT_RETURN(neg->state == PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER, 
+		     PJMEDIA_SDPNEG_EINSTATE);
+
+    /* We're ready to negotiate. */
+    neg->state = PJMEDIA_SDP_NEG_STATE_WAIT_NEGO;
+    neg->has_remote_answer = 1;
+    neg->neg_remote_sdp = pjmedia_sdp_session_clone(pool, remote);
+ 
+    return PJ_SUCCESS;
+}
+
+PJ_DEF(pj_status_t) 
+pjmedia_sdp_neg_set_remote_offer( pj_pool_t *pool,
+				  pjmedia_sdp_neg *neg,
+				  const pjmedia_sdp_session *remote)
 {
     /* Check arguments are valid. */
@@ -225,6 +276,6 @@
 		     PJMEDIA_SDPNEG_EINSTATE);
 
-    /* We're ready to negotiate. */
-    neg->state = PJMEDIA_SDP_NEG_STATE_WAIT_NEGO;
+    /* State now is STATE_REMOTE_OFFER. */
+    neg->state = PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER;
     neg->neg_remote_sdp = pjmedia_sdp_session_clone(pool, remote);
 
@@ -233,23 +284,27 @@
 
 PJ_DEF(pj_status_t) 
-pjmedia_sdp_neg_rx_remote_answer( pj_pool_t *pool,
+pjmedia_sdp_neg_set_local_answer( pj_pool_t *pool,
 				  pjmedia_sdp_neg *neg,
-				  const pjmedia_sdp_session *remote)
+				  const pjmedia_sdp_session *local)
 {
     /* Check arguments are valid. */
-    PJ_ASSERT_RETURN(pool && neg && remote, PJ_EINVAL);
-
-    /* Can only do this in STATE_LOCAL_OFFER.
-     * If we haven't provided local offer, then rx_remote_offer() should
+    PJ_ASSERT_RETURN(pool && neg && local, PJ_EINVAL);
+
+    /* Can only do this in STATE_REMOTE_OFFER.
+     * If we already provide local offer, then rx_remote_answer() should
      * be called instead of this function.
      */
-    PJ_ASSERT_RETURN(neg->state == PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER, 
+    PJ_ASSERT_RETURN(neg->state == PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER, 
 		     PJMEDIA_SDPNEG_EINSTATE);
 
-    /* We're ready to negotiate. */
+    /* State now is STATE_WAIT_NEGO. */
     neg->state = PJMEDIA_SDP_NEG_STATE_WAIT_NEGO;
-    neg->has_remote_answer = 1;
-    neg->neg_remote_sdp = pjmedia_sdp_session_clone(pool, remote);
- 
+    if (local)
+	neg->neg_local_sdp = pjmedia_sdp_session_clone(pool, local);
+    else {
+	PJ_ASSERT_RETURN(neg->initial_sdp, PJMEDIA_SDPNEG_ENOINITIAL);
+	neg->neg_local_sdp = pjmedia_sdp_session_clone(pool, neg->initial_sdp);
+    }
+
     return PJ_SUCCESS;
 }
@@ -464,4 +519,5 @@
 {
     unsigned mi;
+    pj_bool_t has_active = PJ_FALSE;
     pj_status_t status;
 
@@ -479,8 +535,12 @@
 	if (status != PJ_SUCCESS)
 	    return status;
+
+	if (offer->media[mi]->desc.port != 0)
+	    has_active = PJ_TRUE;
     }
 
     *p_active = offer;
-    return PJ_SUCCESS;
+
+    return has_active ? PJ_SUCCESS : PJMEDIA_SDPNEG_ENOMEDIA;
 }
 
@@ -675,4 +735,5 @@
 {
     pj_status_t status;
+    pj_bool_t has_active = PJ_FALSE;
     pjmedia_sdp_session *answer;
     char media_used[PJSDP_MAX_MEDIA];
@@ -749,8 +810,13 @@
 	/* Add the media answer */
 	answer->media[answer->media_count++] = am;
+
+	/* Check if this media is active.*/
+	if (am->desc.port != 0)
+	    has_active = PJ_TRUE;
     }
 
     *p_answer = answer;
-    return PJ_SUCCESS;
+
+    return has_active ? PJ_SUCCESS : PJMEDIA_SDPNEG_ENOMEDIA;
 }
 
@@ -785,5 +851,5 @@
 	pjmedia_sdp_session *answer;
 
-	status = create_answer(pool, neg->initial_sdp, neg->neg_remote_sdp,
+	status = create_answer(pool, neg->neg_local_sdp, neg->neg_remote_sdp,
 			       &answer);
 	if (status == PJ_SUCCESS) {
