Index: /pjproject/trunk/pjmedia/include/pjmedia/sdp.h
===================================================================
--- /pjproject/trunk/pjmedia/include/pjmedia/sdp.h	(revision 3197)
+++ /pjproject/trunk/pjmedia/include/pjmedia/sdp.h	(revision 3198)
@@ -532,4 +532,16 @@
 
 
+/**
+ * Clone SDP media description and deactivate the new SDP media.
+ *
+ * @param rhs	    The SDP media to clone.
+ *
+ * @return	    New media descrption with deactivated indication.
+ */
+PJ_DECL(pjmedia_sdp_media*) pjmedia_sdp_media_clone_deactivate(
+						pj_pool_t *pool,
+						const pjmedia_sdp_media *rhs);
+
+
 /* **************************************************************************
  * SDP SESSION DESCRIPTION
Index: /pjproject/trunk/pjmedia/src/pjmedia/sdp.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/sdp.c	(revision 3197)
+++ /pjproject/trunk/pjmedia/src/pjmedia/sdp.c	(revision 3198)
@@ -1431,17 +1431,43 @@
 						 pjmedia_sdp_media *m)
 {
-    pjmedia_sdp_attr *attr;
-    static const pj_str_t ID_INACTIVE = { "inactive", 8 };
-
-    if (m->attr_count >= PJMEDIA_MAX_SDP_ATTR)
-	return PJ_ETOOMANY;
-
-    attr = pjmedia_sdp_attr_create(pool, ID_INACTIVE.ptr, NULL);
-    if (NULL == attr)
-	return PJ_ENOMEM;
-
-    pjmedia_sdp_media_add_attr(m, attr);
+    PJ_ASSERT_RETURN(m, PJ_EINVAL);
+    PJ_UNUSED_ARG(pool);
+
+    /* Set port to zero */
     m->desc.port = 0;
 
+    /* And remove attributes */
+    m->attr_count = 0;
+
     return PJ_SUCCESS;
 }
+
+
+PJ_DEF(pjmedia_sdp_media*) pjmedia_sdp_media_clone_deactivate(
+						pj_pool_t *pool,
+						const pjmedia_sdp_media *rhs)
+{
+    unsigned int i;
+    pjmedia_sdp_media *m;
+
+    PJ_ASSERT_RETURN(pool && rhs, NULL);
+
+    m = PJ_POOL_ZALLOC_T(pool, pjmedia_sdp_media);
+    pj_memcpy(m, rhs, sizeof(*m));
+
+    /* Clone the media line only */
+    pj_strdup (pool, &m->desc.media, &rhs->desc.media);
+    pj_strdup (pool, &m->desc.transport, &rhs->desc.transport);
+    for (i=0; i<rhs->desc.fmt_count; ++i)
+	pj_strdup(pool, &m->desc.fmt[i], &rhs->desc.fmt[i]);
+
+    if (rhs->conn) {
+	m->conn = pjmedia_sdp_conn_clone (pool, rhs->conn);
+	PJ_ASSERT_RETURN(m->conn != NULL, NULL);
+    }
+
+    /* And deactivate it */
+    pjmedia_sdp_media_deactivate(pool, m);
+
+    return m;
+}
Index: /pjproject/trunk/pjmedia/src/pjmedia/sdp_cmp.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/sdp_cmp.c	(revision 3197)
+++ /pjproject/trunk/pjmedia/src/pjmedia/sdp_cmp.c	(revision 3198)
@@ -184,4 +184,8 @@
 	return PJMEDIA_SDP_ETPORTNOTEQUAL;
 
+    /* For zeroed port media, stop comparing here */
+    if (sd1->desc.port == 0)
+	return PJ_SUCCESS;
+
     /* Compare number of formats. */
     if (sd1->desc.fmt_count != sd2->desc.fmt_count)
Index: /pjproject/trunk/pjmedia/src/pjmedia/sdp_neg.c
===================================================================
--- /pjproject/trunk/pjmedia/src/pjmedia/sdp_neg.c	(revision 3197)
+++ /pjproject/trunk/pjmedia/src/pjmedia/sdp_neg.c	(revision 3198)
@@ -312,6 +312,5 @@
 	    pjmedia_sdp_media *m;
 
-	    m = pjmedia_sdp_media_clone(pool, om);
-	    m->desc.port = 0;
+	    m = pjmedia_sdp_media_clone_deactivate(pool, om);
 
 	    pj_array_insert(new_offer->media, sizeof(new_offer->media[0]),
@@ -777,7 +776,7 @@
 	
 	/* Remote has rejected our offer. 
-	 * Set our port to zero too in active SDP.
+	 * Deactivate our media too.
 	 */
-	offer->desc.port = 0;
+	pjmedia_sdp_media_deactivate(pool, offer);
 
 	/* Don't need to proceed */
@@ -1012,11 +1011,12 @@
 
 	    /* Generate matching-but-disabled-media for the answer */
-	    am = pjmedia_sdp_media_clone(pool, offer->media[omi]);
-	    am->desc.port = 0;
+	    am = pjmedia_sdp_media_clone_deactivate(pool, offer->media[omi]);
 	    answer->media[answer->media_count++] = am;
 	    ++ami;
 
+	    /* Deactivate our media offer too */
+	    pjmedia_sdp_media_deactivate(pool, offer->media[omi]);
+
 	    /* No answer media to be negotiated */
-	    offer->media[omi]->desc.port = 0;
 	    continue;
 	}
@@ -1027,10 +1027,16 @@
 	/* If media type is mismatched, just disable the media. */
 	if (status == PJMEDIA_SDPNEG_EINVANSMEDIA) {
-	    offer->media[omi]->desc.port = 0;
+	    pjmedia_sdp_media_deactivate(pool, offer->media[omi]);
 	    continue;
 	}
-
-	if (status != PJ_SUCCESS)
+	/* No common format in the answer media. */
+	else if (status == PJMEDIA_SDPNEG_EANSNOMEDIA) {
+	    pjmedia_sdp_media_deactivate(pool, offer->media[omi]);
+	    pjmedia_sdp_media_deactivate(pool, answer->media[ami]);
+	} 
+	/* Return the error code, for other errors. */
+	else if (status != PJ_SUCCESS) {
 	    return status;
+	}
 
 	if (offer->media[omi]->desc.port != 0)
@@ -1065,9 +1071,7 @@
     pj_str_t pt_amr_need_adapt = {NULL, 0};
 
-    /* If offer has zero port, just clone the offer and update direction */
+    /* If offer has zero port, just clone the offer */
     if (offer->desc.port == 0) {
-	answer = pjmedia_sdp_media_clone(pool, offer);
-	remove_all_media_directions(answer);
-	update_media_direction(pool, offer, answer);
+	answer = pjmedia_sdp_media_clone_deactivate(pool, offer);
 	*p_answer = answer;
 	return PJ_SUCCESS;
@@ -1357,6 +1361,4 @@
 	     * Reject the offer by setting the port to zero in the answer.
 	     */
-	    //pjmedia_sdp_attr *a;
-
 	    /* For simplicity in the construction of the answer, we'll
 	     * just clone the media from the offer. Anyway receiver will
@@ -1364,16 +1366,5 @@
 	     * number is zero.
 	     */
-	    am = pjmedia_sdp_media_clone(pool, om);
-	    am->desc.port = 0;
-
-	    // Just set port zero to disable stream without set it to inactive.
-	    /* Remove direction attribute, and replace with inactive */
-	    remove_all_media_directions(am);
-	    //a = pjmedia_sdp_attr_create(pool, "inactive", NULL);
-	    //pjmedia_sdp_media_add_attr(am, a);
-
-	    /* Then update direction */
-	    update_media_direction(pool, om, am);
-
+	    am = pjmedia_sdp_media_clone_deactivate(pool, om);
 	} else {
 	    /* The answer is in am */
@@ -1439,5 +1430,4 @@
 	    neg->active_local_sdp = active;
 	    neg->active_remote_sdp = neg->neg_remote_sdp;
-
 	}
     } else {
Index: /pjproject/trunk/pjmedia/src/test/sdp_neg_test.c
===================================================================
--- /pjproject/trunk/pjmedia/src/test/sdp_neg_test.c	(revision 3197)
+++ /pjproject/trunk/pjmedia/src/test/sdp_neg_test.c	(revision 3198)
@@ -97,5 +97,5 @@
 	    "a=rtpmap:0 PCMU/8000\r\n"
 	    "m=video 0 RTP/AVP 31\r\n"
-	    "a=rtpmap:31 H261/90000\r\n"
+	    //"a=rtpmap:31 H261/90000\r\n"	/* <-- this is not necessary (port 0) */
 	    "m=video 53000 RTP/AVP 32\r\n"
 	    "a=rtpmap:32 MPV/90000\r\n"
@@ -130,10 +130,11 @@
 	    "a=rtpmap:0 PCMU/8000\r\n"
 	    "m=video 0 RTP/AVP 31\r\n"
-	    //"a=rtpmap:31 H261/90000\r\n"	/* <-- this is not necessary */
+	    //"a=rtpmap:31 H261/90000\r\n"	/* <-- this is not necessary (port 0) */
 	    "m=video 53000 RTP/AVP 32\r\n"
 	    "a=rtpmap:32 MPV/90000\r\n"
 	    "m=audio 0 RTP/AVP 110\r\n"
-	    "a=rtpmap:110 telephone-events/8000\r\n"
-	    "a=sendonly\r\n"
+	    /* <-- the following attributes are not necessary (port 0) */
+	    //"a=rtpmap:110 telephone-events/8000\r\n"
+	    //"a=sendonly\r\n"
 	  }
 	}
@@ -556,6 +557,8 @@
 	    "a=rtpmap:0 PCMU/8000\r\n"
 	    "a=rtpmap:8 PCMA/8000\r\n"
-	    "m=video 0 RTP/AVP 31\r\n"
-	    "a=rtpmap:31 H261/90000\r\n"
+	    // By #1088, the formats won't be negotiated when the media has port 0.
+	    //"m=video 0 RTP/AVP 31\r\n"
+	    "m=video 0 RTP/AVP 31 32\r\n"
+	    //"a=rtpmap:31 H261/90000\r\n"  /* <-- this is not necessary (port 0) */
 	  },
 	  {
@@ -590,5 +593,5 @@
 	    "a=rtpmap:0 PCMU/8000\r\n"
 	    "m=video 0 RTP/AVP 31\r\n"
-	    "a=rtpmap:31 H261/90000\r\n"
+	    //"a=rtpmap:31 H261/90000\r\n"  /* <-- this is not necessary (port 0) */
 	  }
 	}
@@ -666,5 +669,5 @@
 	    "a=rtpmap:0 PCMU/8000\r\n"
 	    "m=video 0 RTP/AVP 31\r\n"
-	    "a=rtpmap:31 H261/90000\r\n"
+	    //"a=rtpmap:31 H261/90000\r\n"  /* <-- this is not necessary (port 0) */
 	  }
 	}
@@ -817,5 +820,5 @@
 	    "t=0 0\r\n"
 	    "m=audio 0 RTP/AVP 0\r\n"
-	    "a=rtpmap:0 PCMU/8000\r\n"
+	    //"a=rtpmap:0 PCMU/8000\r\n"	  /* <-- this is not necessary (port 0) */
 	    "m=audio 51372 RTP/AVP 97 101\r\n"
 	    "a=rtpmap:97 iLBC/8000\r\n"
@@ -871,5 +874,5 @@
 	    "t=0 0\r\n"
 	    "m=audio 0 RTP/AVP 0\r\n"
-	    "a=rtpmap:0 PCMU/8000\r\n"
+	    //"a=rtpmap:0 PCMU/8000\r\n"      /* <-- this is not necessary (port 0) */
 	    "m=audio 49170 RTP/AVP 97 101\r\n"
 	    "a=rtpmap:97 iLBC/8000\r\n"
@@ -917,5 +920,5 @@
 	    "a=rtpmap:0 PCMU/8000\r\n"
 	    "m=video 0 RTP/AVP 31\r\n"
-	    "a=rtpmap:31 H261/90000\r\n"
+	    //"a=rtpmap:31 H261/90000\r\n"    /* <-- this is not necessary (port 0) */
 	    "",
 	  }
@@ -963,5 +966,5 @@
 	    "a=rtpmap:0 PCMU/8000\r\n"
 	    "m=video 0 RTP/AVP 31\r\n"
-	    "a=rtpmap:31 H261/90000\r\n"
+	    //"a=rtpmap:31 H261/90000\r\n"    /* <-- this is not necessary (port 0) */
 	    "",
 	  }
@@ -1053,7 +1056,7 @@
 	    "a=rtpmap:0 PCMU/8000\r\n"
 	    "m=audio 0 RTP/AVP 0\r\n"
-	    "a=rtpmap:0 PCMU/8000\r\n"
-	    "m=video 0 RTP/AVP 31\r\n"
-	    "a=rtpmap:31 H261/90000\r\n"
+	    //"a=rtpmap:0 PCMU/8000\r\n"      /* <-- this is not necessary (port 0) */
+	    "m=video 0 RTP/AVP 31\r\n"
+	    //"a=rtpmap:31 H261/90000\r\n"    /* <-- this is not necessary (port 0) */
 	    "",
 	  }
@@ -1231,5 +1234,5 @@
 	    "a=rtpmap:0 PCMU/8000\r\n"
 	    "m=audio 0 RTP/AVP 0\r\n"
-	    "a=rtpmap:0 PCMU/8000\r\n"
+	    //"a=rtpmap:0 PCMU/8000\r\n"      /* <-- this is not necessary (port 0) */
 	    "m=video 5000 RTP/AVP 31\r\n"
 	    "a=rtpmap:31 H261/90000\r\n"
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 3197)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 3198)
@@ -1302,30 +1302,9 @@
 	    const pjmedia_sdp_media *rem_m = rem_sdp->media[i];
 	    pjmedia_sdp_media *m;
-	    const pjmedia_sdp_attr *a;
 
 	    if ((int)i == call->audio_idx)
 		continue;
 
-	    m = PJ_POOL_ZALLOC_T(pool, pjmedia_sdp_media);
-	    pj_strdup(pool, &m->desc.media, &rem_m->desc.media);
-	    pj_strdup(pool, &m->desc.transport, &rem_m->desc.transport);
-	    m->desc.port = 0;
-
-	    /* Add one format, copy from the offer. And copy the corresponding
-	     * rtpmap and fmtp attributes too.
-	     */
-	    m->desc.fmt_count = 1;
-	    pj_strdup(pool, &m->desc.fmt[0], &rem_m->desc.fmt[0]);
-	    if ((a=pjmedia_sdp_attr_find2(rem_m->attr_count, rem_m->attr,
-					  "rtpmap", &m->desc.fmt[0])) != NULL)
-	    {
-		m->attr[m->attr_count++] = pjmedia_sdp_attr_clone(pool, a);
-	    }
-	    if ((a=pjmedia_sdp_attr_find2(rem_m->attr_count, rem_m->attr,
-					  "fmtp", &m->desc.fmt[0])) != NULL)
-	    {
-		m->attr[m->attr_count++] = pjmedia_sdp_attr_clone(pool, a);
-	    }
-
+	    m = pjmedia_sdp_media_clone_deactivate(pool, rem_m);
 	    if (i==sdp->media_count)
 		sdp->media[sdp->media_count++] = m;
