Index: pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c	(revision 3737)
+++ pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c	(revision 3753)
@@ -37,9 +37,12 @@
     pj_status_t status;
 
+    PJ_LOG(4,(THIS_FILE, "Initializing video subsystem.."));
+    pj_log_push_indent();
+
     status = pjmedia_video_format_mgr_create(pjsua_var.pool, 64, 0, NULL);
     if (status != PJ_SUCCESS) {
 	PJ_PERROR(1,(THIS_FILE, status,
 		     "Error creating PJMEDIA video format manager"));
-	return status;
+	goto on_error;
     }
 
@@ -48,5 +51,5 @@
 	PJ_PERROR(1,(THIS_FILE, status,
 		     "Error creating PJMEDIA converter manager"));
-	return status;
+	goto on_error;
     }
 
@@ -55,5 +58,5 @@
 	PJ_PERROR(1,(THIS_FILE, status,
 		     "Error creating PJMEDIA video codec manager"));
-	return status;
+	goto on_error;
     }
 
@@ -62,5 +65,5 @@
 	PJ_PERROR(1,(THIS_FILE, status,
 		     "Error creating PJMEDIA video subsystem"));
-	return status;
+	goto on_error;
     }
 
@@ -70,5 +73,5 @@
 	PJ_PERROR(1,(THIS_FILE, status,
 		     "Error initializing ffmpeg library"));
-	return status;
+	goto on_error;
     }
 #endif
@@ -77,10 +80,17 @@
 	if (pjsua_var.win[i].pool == NULL) {
 	    pjsua_var.win[i].pool = pjsua_pool_create("win%p", 512, 512);
-	    if (pjsua_var.win[i].pool == NULL)
-		return PJ_ENOMEM;
+	    if (pjsua_var.win[i].pool == NULL) {
+		status = PJ_ENOMEM;
+		goto on_error;
+	    }
 	}
     }
 
+    pj_log_pop_indent();
     return PJ_SUCCESS;
+
+on_error:
+    pj_log_pop_indent();
+    return status;
 }
 
@@ -93,4 +103,7 @@
 {
     unsigned i;
+
+    PJ_LOG(4,(THIS_FILE, "Destroying video subsystem.."));
+    pj_log_push_indent();
 
     for (i=0; i<PJSUA_MAX_VID_WINS; ++i) {
@@ -108,4 +121,5 @@
 #endif
 
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 }
@@ -343,4 +357,8 @@
     pj_status_t status;
     unsigned i;
+
+    PJ_LOG(4,(THIS_FILE, "Creating window, type=%d, cap_dev=%d, rend_dev=%d",
+	      type, cap_id, rend_id));
+    pj_log_push_indent();
 
     /* If type is preview, check if it exists already */
@@ -361,4 +379,6 @@
 	    /* Done */
 	    *id = wid;
+	    PJ_LOG(4,(THIS_FILE, "Window already exist: %d", wid));
+	    pj_log_pop_indent();
 	    return PJ_SUCCESS;
 	}
@@ -374,6 +394,8 @@
 	}
     }
-    if (i == PJSUA_MAX_VID_WINS)
+    if (i == PJSUA_MAX_VID_WINS) {
+	pj_log_pop_indent();
 	return PJ_ETOOMANY;
+    }
 
     /* Initialize window */
@@ -449,8 +471,11 @@
     *id = wid;
 
+    PJ_LOG(4,(THIS_FILE, "Window %d created", wid));
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 
 on_error:
     free_vid_win(wid);
+    pj_log_pop_indent();
     return status;
 }
@@ -461,4 +486,7 @@
     pjsua_vid_win *w = &pjsua_var.win[wid];
     
+    PJ_LOG(4,(THIS_FILE, "Window %d: destroying..", wid));
+    pj_log_push_indent();
+
     if (w->vp_cap) {
 	pjmedia_vid_port_stop(w->vp_cap);
@@ -474,4 +502,6 @@
     }
     pjsua_vid_win_reset(wid);
+
+    pj_log_pop_indent();
 }
 
@@ -514,8 +544,11 @@
     pj_status_t status;
     
+    PJ_LOG(4,(THIS_FILE, "Video channel update.."));
+    pj_log_push_indent();
+
     status = pjmedia_vid_stream_info_from_sdp(si, tmp_pool, pjsua_var.med_endpt,
 					      local_sdp, remote_sdp, strm_idx);
     if (status != PJ_SUCCESS)
-	return status;
+	goto on_error;
 
     /* Check if no media is active */
@@ -535,5 +568,5 @@
 					       remote_sdp, strm_idx);
 	if (status != PJ_SUCCESS)
-	    return status;
+	    goto on_error;
 
 	call_med->tp_st = PJSUA_MED_TP_RUNNING;
@@ -592,5 +625,5 @@
 					      &dev_info);
 	    if (status != PJ_SUCCESS)
-		return status;
+		goto on_error;
 
 	    /* Find matched format ID */
@@ -617,10 +650,10 @@
 					   &call_med->strm.v.stream);
 	if (status != PJ_SUCCESS)
-	    return status;
+	    goto on_error;
 
 	/* Start stream */
 	status = pjmedia_vid_stream_start(call_med->strm.v.stream);
 	if (status != PJ_SUCCESS)
-	    return status;
+	    goto on_error;
 
 	/* Setup decoding direction */
@@ -630,9 +663,14 @@
 	    pjsua_vid_win *w;
 
+	    PJ_LOG(4,(THIS_FILE, "Setting up RX.."));
+	    pj_log_push_indent();
+
 	    status = pjmedia_vid_stream_get_port(call_med->strm.v.stream,
 						 PJMEDIA_DIR_DECODING,
 						 &media_port);
-	    if (status != PJ_SUCCESS)
-		return status;
+	    if (status != PJ_SUCCESS) {
+		pj_log_pop_indent();
+		goto on_error;
+	    }
 
 	    /* Create stream video window */
@@ -644,6 +682,8 @@
 				    acc->cfg.vid_in_auto_show,
 				    &wid);
-	    if (status != PJ_SUCCESS)
-		return status;
+	    if (status != PJ_SUCCESS) {
+		pj_log_pop_indent();
+		goto on_error;
+	    }
 
 	    w = &pjsua_var.win[wid];
@@ -659,15 +699,20 @@
 	    status = pjmedia_vid_port_connect(w->vp_rend, media_port,
 					      PJ_FALSE);
-	    if (status != PJ_SUCCESS)
-		return status;
+	    if (status != PJ_SUCCESS) {
+		pj_log_pop_indent();
+		goto on_error;
+	    }
 
 	    /* Start renderer */
 	    status = pjmedia_vid_port_start(w->vp_rend);
-	    if (status != PJ_SUCCESS)
-		return status;
+	    if (status != PJ_SUCCESS) {
+		pj_log_pop_indent();
+		goto on_error;
+	    }
 
 	    /* Done */
 	    inc_vid_win(wid);
 	    call_med->strm.v.rdr_win_id = wid;
+	    pj_log_pop_indent();
 	}
 
@@ -678,9 +723,14 @@
 	    pjsua_vid_win_id wid;
 
+	    PJ_LOG(4,(THIS_FILE, "Setting up TX.."));
+	    pj_log_push_indent();
+
 	    status = pjmedia_vid_stream_get_port(call_med->strm.v.stream,
 						 PJMEDIA_DIR_ENCODING,
 						 &media_port);
-	    if (status != PJ_SUCCESS)
-		return status;
+	    if (status != PJ_SUCCESS) {
+		pj_log_pop_indent();
+		goto on_error;
+	    }
 
 	    /* Create preview video window */
@@ -693,6 +743,8 @@
 				    PJ_FALSE,
 				    &wid);
-	    if (status != PJ_SUCCESS)
-		return status;
+	    if (status != PJ_SUCCESS) {
+		pj_log_pop_indent();
+		goto on_error;
+	    }
 
 	    w = &pjsua_var.win[wid];
@@ -705,20 +757,27 @@
 	    /* Connect stream to capturer (via video window tee) */
 	    status = pjmedia_vid_tee_add_dst_port2(w->tee, 0, media_port);
-	    if (status != PJ_SUCCESS)
-		return status;
+	    if (status != PJ_SUCCESS) {
+		pj_log_pop_indent();
+		goto on_error;
+	    }
 
 	    /* Start renderer */
 	    status = pjmedia_vid_port_start(w->vp_rend);
-	    if (status != PJ_SUCCESS)
-		return status;
+	    if (status != PJ_SUCCESS) {
+		pj_log_pop_indent();
+		goto on_error;
+	    }
 
 	    /* Start capturer */
 	    status = pjmedia_vid_port_start(w->vp_cap);
-	    if (status != PJ_SUCCESS)
-		return status;
+	    if (status != PJ_SUCCESS) {
+		pj_log_pop_indent();
+		goto on_error;
+	    }
 
 	    /* Done */
 	    inc_vid_win(wid);
 	    call_med->strm.v.cap_win_id = wid;
+	    pj_log_pop_indent();
 	}
 
@@ -766,5 +825,5 @@
 	if (len > 0)
 	    info_len += len;
-	PJ_LOG(4,(THIS_FILE,"Media updates%s", info));
+	PJ_LOG(4,(THIS_FILE,"Video updated%s", info));
     }
 
@@ -773,8 +832,13 @@
 					  PJMEDIA_DIR_ENCODING);
 	if (status != PJ_SUCCESS)
-	    return status;
-    }
-
+	    goto on_error;
+    }
+
+    pj_log_pop_indent();
     return PJ_SUCCESS;
+
+on_error:
+    pj_log_pop_indent();
+    return status;
 }
 
@@ -790,4 +854,7 @@
     if (!strm)
 	return;
+
+    PJ_LOG(4,(THIS_FILE, "Stopping video stream.."));
+    pj_log_push_indent();
 
     /* Unsubscribe events */
@@ -832,4 +899,6 @@
     pjmedia_vid_stream_destroy(strm);
     call_med->strm.v.stream = NULL;
+
+    pj_log_pop_indent();
 }
 
@@ -847,10 +916,14 @@
     pj_status_t status;
 
-    PJSUA_LOCK();
-
     if (!prm) {
 	pjsua_vid_preview_param_default(&default_param);
 	prm = &default_param;
     }
+
+    PJ_LOG(4,(THIS_FILE, "Starting preview for cap_dev=%d, show=%d",
+	      id, prm->show));
+    pj_log_push_indent();
+
+    PJSUA_LOCK();
 
     rend_id = prm->rend_id;
@@ -860,4 +933,5 @@
     if (status != PJ_SUCCESS) {
 	PJSUA_UNLOCK();
+	pj_log_pop_indent();
 	return status;
     }
@@ -869,4 +943,5 @@
     if (status != PJ_SUCCESS) {
 	PJSUA_UNLOCK();
+	pj_log_pop_indent();
 	return status;
     }
@@ -876,4 +951,5 @@
     if (status != PJ_SUCCESS) {
 	PJSUA_UNLOCK();
+	pj_log_pop_indent();
 	return status;
     }
@@ -882,4 +958,5 @@
 
     PJSUA_UNLOCK();
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 }
@@ -891,4 +968,7 @@
 {
     pjsua_vid_win_id wid = PJSUA_INVALID_ID;
+
+    PJ_LOG(4,(THIS_FILE, "Stopping preview for cap_dev=%d", id));
+    pj_log_push_indent();
 
     PJSUA_LOCK();
@@ -896,4 +976,5 @@
     if (wid == PJSUA_INVALID_ID) {
 	PJSUA_UNLOCK();
+	pj_log_pop_indent();
 	return PJ_ENOTFOUND;
     }
@@ -902,4 +983,5 @@
 
     PJSUA_UNLOCK();
+    pj_log_pop_indent();
 
     return PJ_SUCCESS;
@@ -1580,4 +1662,8 @@
 		     PJ_EINVAL);
     PJ_ASSERT_RETURN(op != PJSUA_CALL_VID_STRM_NO_OP, PJ_EINVAL);
+
+    PJ_LOG(4,(THIS_FILE, "Call %d: set video stream, op=%d",
+	      call_id, op));
+    pj_log_push_indent();
 
     PJSUA_LOCK();
@@ -1636,4 +1722,5 @@
 
     PJSUA_UNLOCK();
+    pj_log_pop_indent();
 
     return status;
