Index: pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h	(revision 4749)
+++ pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h	(revision 4750)
@@ -636,4 +636,10 @@
 pj_status_t pjsua_media_channel_deinit(pjsua_call_id call_id);
 
+/*
+ * Error message when media operation is requested while another is in progress
+ */
+#define ERR_MEDIA_CHANGING  " because another media operation is in progress"
+
+pj_bool_t   pjsua_call_media_is_changing(pjsua_call *call);
 pj_status_t pjsua_call_media_init(pjsua_call_media *call_med,
                                   pjmedia_type type,
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 4749)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 4750)
@@ -34,5 +34,4 @@
  */
 #define LOCK_CODEC_MAX_RETRY	     5
-
 
 /*
@@ -2393,4 +2392,10 @@
 	goto on_return;
 
+    if (pjsua_call_media_is_changing(call)) {
+	PJ_LOG(1,(THIS_FILE, "Unable to reinvite" ERR_MEDIA_CHANGING));
+	status = PJ_EINVALIDOP;
+	goto on_return;
+    }
+
     if (call->inv->state != PJSIP_INV_STATE_CONFIRMED) {
 	PJ_LOG(3,(THIS_FILE, "Can not re-INVITE call that is not confirmed"));
@@ -2499,4 +2504,10 @@
     if (status != PJ_SUCCESS)
 	goto on_return;
+
+    if (pjsua_call_media_is_changing(call)) {
+	PJ_LOG(1,(THIS_FILE, "Unable to send UPDATE" ERR_MEDIA_CHANGING));
+	status = PJ_EINVALIDOP;
+	goto on_return;
+    }
 
     status = apply_call_setting(call, opt, NULL);
@@ -3879,5 +3890,11 @@
     PJ_LOG(4,(THIS_FILE, "Call %d: received updated media offer",
 	      call->index));
+
     pj_log_push_indent();
+
+    if (pjsua_call_media_is_changing(call)) {
+	PJ_LOG(1,(THIS_FILE, "Unable to process offer" ERR_MEDIA_CHANGING));
+	goto on_return;
+    }
 
     if (pjsua_var.ua_cfg.cb.on_call_rx_offer) {
@@ -3970,4 +3987,9 @@
 
     call = (pjsua_call*) inv->dlg->mod_data[pjsua_var.mod.id];
+    if (pjsua_call_media_is_changing(call)) {
+	*offer = NULL;
+	PJ_LOG(1,(THIS_FILE, "Unable to create offer" ERR_MEDIA_CHANGING));
+	goto on_return;
+    }
 
     /* See if we've put call on hold. */
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 4749)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 4750)
@@ -1303,4 +1303,18 @@
 
     return status;
+}
+
+/* Determine if call's media is being changed, for example when video is being
+ * added. Then we can reject incoming re-INVITE, for example. This is the
+ * solution for https://trac.pjsip.org/repos/ticket/1738
+ */
+pj_bool_t  pjsua_call_media_is_changing(pjsua_call *call)
+{
+    /* The problem in #1738 occurs because we do handle_events() loop while
+     * adding media, which could cause incoming re-INVITE to be processed and
+     * cause havoc. Since the handle_events() loop only happens while adding
+     * media, it is sufficient to only check if "prov > cnt" for now.
+     */
+    return call->med_prov_cnt > call->med_cnt;
 }
 
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c	(revision 4749)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c	(revision 4750)
@@ -1536,4 +1536,9 @@
 	return PJ_ETOOMANY;
 
+    if (pjsua_call_media_is_changing(call)) {
+	PJ_LOG(1,(THIS_FILE, "Unable to add video" ERR_MEDIA_CHANGING));
+	return PJ_EINVALIDOP;
+    }
+
     /* Get active local SDP and clone it */
     status = pjmedia_sdp_neg_get_active_local(call->inv->neg, &current_sdp);
@@ -1636,4 +1641,9 @@
     pjmedia_sdp_session *sdp;
     pj_status_t status;
+
+    if (pjsua_call_media_is_changing(call)) {
+	PJ_LOG(1,(THIS_FILE, "Unable to modify video" ERR_MEDIA_CHANGING));
+	return PJ_EINVALIDOP;
+    }
 
     /* Verify and normalize media index */
