Index: pjproject/trunk/pjmedia/src/pjmedia/event.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/event.c	(revision 3777)
+++ pjproject/trunk/pjmedia/src/pjmedia/event.c	(revision 3778)
@@ -73,7 +73,12 @@
                                              pjmedia_event_subscription *esub)
 {
+    char epub_name[5];
+
     PJ_ASSERT_RETURN(epub && esub && esub->cb, PJ_EINVAL);
     /* Must not currently subscribe to anything */
     PJ_ASSERT_RETURN(esub->subscribe_to == NULL, PJ_EINVALIDOP);
+
+    TRACE_((THIS_FILE, "Subscription to publisher %s",
+		       pjmedia_fourcc_name(epub->sig, epub_name)));
 
     pj_list_push_back(&epub->subscription_list, esub);
@@ -85,5 +90,11 @@
 {
     PJ_ASSERT_RETURN(esub, PJ_EINVAL);
+
     if (esub->subscribe_to) {
+	char epub_name[5];
+	TRACE_((THIS_FILE, "Unsubscription to publisher %s",
+			   pjmedia_fourcc_name(esub->subscribe_to->sig,
+					       epub_name)));
+
 	PJ_ASSERT_RETURN(
 	    pj_list_find_node(&esub->subscribe_to->subscription_list,
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 3777)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 3778)
@@ -2039,5 +2039,5 @@
 
 on_return:
-    pjsip_dlg_dec_lock(dlg);
+    if (dlg) pjsip_dlg_dec_lock(dlg);
     pj_log_pop_indent();
     return status;
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 3777)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 3778)
@@ -1340,9 +1340,4 @@
 #endif
 
-    pjmedia_event_subscription_init(&call_med->esub_rend, &call_media_on_event,
-                                    call_med);
-    pjmedia_event_subscription_init(&call_med->esub_cap, &call_media_on_event,
-                                    call_med);
-
 on_error:
     if (status != PJ_SUCCESS && call_med->tp) {
@@ -1403,4 +1398,10 @@
 		call_med->strm.v.cap_dev = info.id;
 	    }
+
+	    /* Init event subscribtion */
+	    pjmedia_event_subscription_init(&call_med->esub_rend, &call_media_on_event,
+					    call_med);
+	    pjmedia_event_subscription_init(&call_med->esub_cap, &call_media_on_event,
+					    call_med);
 	}
 #endif
Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c	(revision 3777)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c	(revision 3778)
@@ -24,5 +24,5 @@
 #if PJSUA_HAS_VIDEO
 
-#define ENABLE_EVENT	    	0
+#define ENABLE_EVENT	    	1
 #define VID_TEE_MAX_PORT    	(PJSUA_MAX_CALLS + 1)
 
@@ -972,13 +972,11 @@
     pj_log_push_indent();
 
-    /* Unsubscribe events */
-    pjmedia_event_unsubscribe(&call_med->esub_rend);
-    pjmedia_event_unsubscribe(&call_med->esub_cap);
-
     if (call_med->strm.v.cap_win_id != PJSUA_INVALID_ID) {
 	pjmedia_port *media_port;
-	pjsua_vid_win *w =
-		    &pjsua_var.win[call_med->strm.v.cap_win_id];
+	pjsua_vid_win *w = &pjsua_var.win[call_med->strm.v.cap_win_id];
 	pj_status_t status;
+
+	/* Stop the capture before detaching stream and unsubscribing event */
+	pjmedia_vid_port_stop(w->vp_cap);
 
 	/* Disconnect video stream from capture device */
@@ -987,9 +985,13 @@
 					     &media_port);
 	if (status == PJ_SUCCESS) {
-	    /* Video tee is not threadsafe, so stop the capture first */
-	    pjmedia_vid_port_stop(w->vp_cap);
 	    pjmedia_vid_tee_remove_dst_port(w->tee, media_port);
+	}
+
+        /* Unsubscribe event */
+	pjmedia_event_unsubscribe(&call_med->esub_cap);
+
+	/* Re-start capture again, if it is used by other stream */
+	if (w->ref_cnt > 1)
 	    pjmedia_vid_port_start(w->vp_cap);
-	}
 
 	dec_vid_win(call_med->strm.v.cap_win_id);
@@ -998,4 +1000,10 @@
 
     if (call_med->strm.v.rdr_win_id != PJSUA_INVALID_ID) {
+	pjsua_vid_win *w = &pjsua_var.win[call_med->strm.v.rdr_win_id];
+
+	/* Stop the render before unsubscribing event */
+	pjmedia_vid_port_stop(w->vp_rend);
+	pjmedia_event_unsubscribe(&call_med->esub_rend);
+
 	dec_vid_win(call_med->strm.v.rdr_win_id);
 	call_med->strm.v.rdr_win_id = PJSUA_INVALID_ID;
@@ -1840,10 +1848,4 @@
 
     if (w->vp_rend) {
-#if ENABLE_EVENT
-	pjmedia_event_subscribe(
-		pjmedia_vid_port_get_event_publisher(w->vp_rend),
-		&call_med->esub_cap);
-#endif
-
 	/* Start renderer */
 	status = pjmedia_vid_port_start(new_w->vp_rend);
@@ -1851,4 +1853,10 @@
 	    goto on_error;
     }
+
+#if ENABLE_EVENT
+    pjmedia_event_subscribe(
+	    pjmedia_vid_port_get_event_publisher(new_w->vp_cap),
+	    &call_med->esub_cap);
+#endif
 
     /* Start capturer */
