Index: /pjproject/trunk/pjnath/src/pjnath/ice_session.c
===================================================================
--- /pjproject/trunk/pjnath/src/pjnath/ice_session.c	(revision 3752)
+++ /pjproject/trunk/pjnath/src/pjnath/ice_session.c	(revision 3753)
@@ -1749,4 +1749,5 @@
 	 "Sending connectivity check for check %s", 
 	 dump_check(ice->tmp.txt, sizeof(ice->tmp.txt), clist, check)));
+    pj_log_push_indent();
 
     /* Create request */
@@ -1756,4 +1757,5 @@
     if (status != PJ_SUCCESS) {
 	pjnath_perror(ice->obj_name, "Error creating STUN request", status);
+	pj_log_pop_indent();
 	return status;
     }
@@ -1812,4 +1814,5 @@
 	check->tdata = NULL;
 	pjnath_perror(ice->obj_name, "Error sending STUN request", status);
+	pj_log_pop_indent();
 	return status;
     }
@@ -1817,4 +1820,5 @@
     check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_IN_PROGRESS, 
 	            PJ_SUCCESS);
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 }
@@ -1846,4 +1850,5 @@
 
     LOG5((ice->obj_name, "Starting checklist periodic check"));
+    pj_log_push_indent();
 
     /* Send STUN Binding request for check with highest priority on
@@ -1857,4 +1862,5 @@
 	    if (status != PJ_SUCCESS) {
 		pj_mutex_unlock(ice->mutex);
+		pj_log_pop_indent();
 		return status;
 	    }
@@ -1876,4 +1882,5 @@
 		if (status != PJ_SUCCESS) {
 		    pj_mutex_unlock(ice->mutex);
+		    pj_log_pop_indent();
 		    return status;
 		}
@@ -1897,4 +1904,5 @@
 
     pj_mutex_unlock(ice->mutex);
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 }
@@ -1909,4 +1917,5 @@
 
     LOG4((ice->obj_name, "Starting nominated check.."));
+    pj_log_push_indent();
 
     pj_assert(ice->is_nominating == PJ_FALSE);
@@ -1959,4 +1968,5 @@
 
     ice->is_nominating = PJ_TRUE;
+    pj_log_pop_indent();
 }
 
@@ -2006,4 +2016,5 @@
 
     LOG4((ice->obj_name, "Starting ICE check.."));
+    pj_log_push_indent();
 
     /* If we are using aggressive nomination, set the is_nominating state */
@@ -2033,4 +2044,5 @@
 	pj_assert(!"Unable to find checklist for component 1");
 	pj_mutex_unlock(ice->mutex);
+	pj_log_pop_indent();
 	return PJNATH_EICEINCOMPID;
     }
@@ -2073,6 +2085,8 @@
 	      "Performing delayed triggerred check for component %d",
 	      rcheck->comp_id));
+	pj_log_push_indent();
 	handle_incoming_check(ice, rcheck);
 	rcheck = rcheck->next;
+	pj_log_pop_indent();
     }
     pj_list_init(&ice->early_check);
@@ -2092,4 +2106,5 @@
 
     pj_mutex_unlock(ice->mutex);
+    pj_log_pop_indent();
     return status;
 }
@@ -2194,7 +2209,9 @@
 	    /* Resend request */
 	    LOG4((ice->obj_name, "Resending check because of role conflict"));
+	    pj_log_push_indent();
 	    check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_WAITING, 0);
 	    perform_check(ice, clist, msg_data->data.req.ckid, 
 			  check->nominated || ice->is_nominating);
+	    pj_log_pop_indent();
 	    pj_mutex_unlock(ice->mutex);
 	    return;
@@ -2208,7 +2225,8 @@
 	     (check->nominated ? " (nominated)" : " (not nominated)"),
 	     errmsg));
-
+	pj_log_push_indent();
 	check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_FAILED, status);
 	on_check_complete(ice, check);
+	pj_log_pop_indent();
 	pj_mutex_unlock(ice->mutex);
 	return;
@@ -2231,6 +2249,8 @@
 			&ice->clist, check),
 	     (check->nominated ? " (nominated)" : " (not nominated)")));
+	pj_log_push_indent();
 	check_set_state(ice, check, PJ_ICE_SESS_CHECK_STATE_FAILED, status);
 	on_check_complete(ice, check);
+	pj_log_pop_indent();
 	pj_mutex_unlock(ice->mutex);
 	return;
@@ -2703,5 +2723,7 @@
 
 	    LOG5((ice->obj_name, "Performing triggered check for check %d",i));
+	    pj_log_push_indent();
 	    perform_check(ice, &ice->clist, i, nominate);
+	    pj_log_pop_indent();
 
 	} else if (c->state == PJ_ICE_SESS_CHECK_STATE_IN_PROGRESS) {
@@ -2710,5 +2732,7 @@
 	    LOG5((ice->obj_name, "Triggered check for check %d not performed "
 		  "because it's in progress. Retransmitting", i));
+	    pj_log_push_indent();
 	    pj_stun_session_retransmit_req(comp->stun_sess, c->tdata);
+	    pj_log_pop_indent();
 
 	} else if (c->state == PJ_ICE_SESS_CHECK_STATE_SUCCEEDED) {
@@ -2744,6 +2768,7 @@
 	    LOG5((ice->obj_name, "Triggered check for check %d not performed "
 				"because it's completed", i));
-
+	    pj_log_push_indent();
 	    complete = on_check_complete(ice, c);
+	    pj_log_pop_indent();
 	    if (complete) {
 		return;
@@ -2774,5 +2799,7 @@
 	LOG4((ice->obj_name, "New triggered check added: %d", 
 	     ice->clist.count));
+	pj_log_push_indent();
 	perform_check(ice, &ice->clist, ice->clist.count++, nominate);
+	pj_log_pop_indent();
 
     } else {
@@ -2803,4 +2830,6 @@
     sd = (struct stun_data*) pj_stun_session_get_user_data(sess);
 
+    pj_log_push_indent();
+
     if (msg->hdr.type == PJ_STUN_BINDING_INDICATION) {
 	LOG5((sd->ice->obj_name, "Received Binding Indication keep-alive "
@@ -2811,4 +2840,6 @@
 	      sd->comp_id));
     }
+
+    pj_log_pop_indent();
 
     return PJ_SUCCESS;
Index: /pjproject/trunk/pjnath/src/pjnath/ice_strans.c
===================================================================
--- /pjproject/trunk/pjnath/src/pjnath/ice_strans.c	(revision 3752)
+++ /pjproject/trunk/pjnath/src/pjnath/ice_strans.c	(revision 3753)
@@ -406,4 +406,6 @@
 		      comp_id));
 
+	    pj_log_push_indent();
+
 	    /* Start Binding resolution */
 	    status = pj_stun_sock_start(comp->stun_sock, 
@@ -413,4 +415,5 @@
 	    if (status != PJ_SUCCESS) {
 		///sess_dec_ref(ice_st);
+		pj_log_pop_indent();
 		return status;
 	    }
@@ -420,4 +423,5 @@
 	    if (status != PJ_SUCCESS) {
 		///sess_dec_ref(ice_st);
+		pj_log_pop_indent();
 		return status;
 	    }
@@ -438,4 +442,5 @@
 	    comp->default_cand = cand - comp->cand_list;
 
+	    pj_log_pop_indent();
 	}
 
@@ -537,4 +542,5 @@
 	      "Creating ICE stream transport with %d component(s)",
 	      comp_cnt));
+    pj_log_push_indent();
 
     pj_ice_strans_cfg_copy(pool, &ice_st->cfg, cfg);
@@ -551,4 +557,5 @@
     if (status != PJ_SUCCESS) {
 	destroy_ice_st(ice_st);
+	pj_log_pop_indent();
 	return status;
     }
@@ -571,4 +578,5 @@
 	    pj_lock_release(ice_st->init_lock);
 	    destroy_ice_st(ice_st);
+	    pj_log_pop_indent();
 	    return status;
 	}
@@ -584,4 +592,6 @@
 
     *p_ice_st = ice_st;
+    pj_log_pop_indent();
+
     return PJ_SUCCESS;
 }
@@ -591,4 +601,7 @@
 {
     unsigned i;
+
+    PJ_LOG(5,(ice_st->obj_name, "ICE stream transport destroying.."));
+    pj_log_push_indent();
 
     /* Destroy ICE if we have ICE */
@@ -630,6 +643,9 @@
     }
 
+    PJ_LOG(4,(ice_st->obj_name, "ICE stream transport destroyed"));
+
     /* Done */
     pj_pool_release(ice_st->pool);
+    pj_log_pop_indent();
 }
 
@@ -665,7 +681,10 @@
     pj_strerror(status, errmsg, sizeof(errmsg));
     PJ_LOG(4,(ice_st->obj_name, "%s: %s", title, errmsg));
-
-    if (op==PJ_ICE_STRANS_OP_INIT && ice_st->cb_called)
+    pj_log_push_indent();
+
+    if (op==PJ_ICE_STRANS_OP_INIT && ice_st->cb_called) {
+	pj_log_pop_indent();
 	return;
+    }
 
     ice_st->cb_called = PJ_TRUE;
@@ -673,4 +692,6 @@
     if (ice_st->cb.on_ice_complete)
 	(*ice_st->cb.on_ice_complete)(ice_st, op, status);
+
+    pj_log_pop_indent();
 }
 
@@ -710,6 +731,4 @@
 PJ_DEF(pj_status_t) pj_ice_strans_destroy(pj_ice_strans *ice_st)
 {
-    char obj_name[PJ_MAX_OBJ_NAME];
-
     PJ_ASSERT_RETURN(ice_st, PJ_EINVAL);
 
@@ -721,8 +740,5 @@
     }
     
-    pj_memcpy(obj_name, ice_st->obj_name, PJ_MAX_OBJ_NAME);
     destroy_ice_st(ice_st);
-
-    PJ_LOG(4,(obj_name, "ICE stream transport destroyed"));
     return PJ_SUCCESS;
 }
@@ -1295,7 +1311,8 @@
 					       PJ_ICE_STRANS_STATE_FAILED;
 
+	pj_log_push_indent();
 	(*ice_st->cb.on_ice_complete)(ice_st, PJ_ICE_STRANS_OP_NEGOTIATION, 
 				      status);
-
+	pj_log_pop_indent();
 	
     }
@@ -1616,4 +1633,5 @@
     PJ_LOG(5,(comp->ice_st->obj_name, "TURN client state changed %s --> %s",
 	      pj_turn_state_name(old_state), pj_turn_state_name(new_state)));
+    pj_log_push_indent();
 
     sess_add_ref(comp->ice_st);
@@ -1691,4 +1709,6 @@
 
     sess_dec_ref(comp->ice_st);
-}
-
+
+    pj_log_pop_indent();
+}
+
Index: /pjproject/trunk/pjnath/src/pjnath/stun_session.c
===================================================================
--- /pjproject/trunk/pjnath/src/pjnath/stun_session.c	(revision 3752)
+++ /pjproject/trunk/pjnath/src/pjnath/stun_session.c	(revision 3753)
@@ -865,4 +865,6 @@
     PJ_ASSERT_RETURN(sess && addr_len && server && tdata, PJ_EINVAL);
 
+    pj_log_push_indent();
+
     /* Allocate packet */
     tdata->max_len = PJ_STUN_MAX_PKT_LEN;
@@ -972,4 +974,6 @@
 on_return:
     pj_lock_release(sess->lock);
+
+    pj_log_pop_indent();
 
     /* Check if application has called destroy() in the callback */
@@ -1354,4 +1358,6 @@
     PJ_ASSERT_RETURN(sess && packet && pkt_size, PJ_EINVAL);
 
+    pj_log_push_indent();
+
     /* Lock the session and prevent user from destroying us in the callback */
     pj_atomic_inc(sess->busy);
@@ -1411,4 +1417,6 @@
     pj_lock_release(sess->lock);
 
+    pj_log_pop_indent();
+
     /* If we've received destroy request while we're on the callback,
      * destroy the session now.
Index: /pjproject/trunk/pjnath/src/pjnath/stun_transaction.c
===================================================================
--- /pjproject/trunk/pjnath/src/pjnath/stun_transaction.c	(revision 3752)
+++ /pjproject/trunk/pjnath/src/pjnath/stun_transaction.c	(revision 3753)
@@ -226,4 +226,5 @@
     PJ_LOG(5,(tsx->obj_name, "STUN sending message (transmit count=%d)",
 	      tsx->transmit_count));
+    pj_log_push_indent();
 
     /* Send message */
@@ -239,7 +240,7 @@
 	}
 	stun_perror(tsx, "STUN error sending message", status);
-	return status;
-    }
-
+    }
+
+    pj_log_pop_indent();
     return status;
 }
@@ -322,4 +323,5 @@
 	tsx->retransmit_timer.id = 0;
 	PJ_LOG(4,(tsx->obj_name, "STUN timeout waiting for response"));
+	pj_log_push_indent();
 	if (!tsx->complete) {
 	    tsx->complete = PJ_TRUE;
@@ -329,4 +331,5 @@
 	}
 	/* We might have been destroyed, don't try to access the object */
+	pj_log_pop_indent();
 	return;
     }
Index: /pjproject/trunk/pjsip/src/pjsip-simple/evsub.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip-simple/evsub.c	(revision 3752)
+++ /pjproject/trunk/pjsip/src/pjsip-simple/evsub.c	(revision 3753)
@@ -579,4 +579,5 @@
 	      (int)sub->state_str.slen,
 	      sub->state_str.ptr));
+    pj_log_push_indent();
 
     /* don't call the callback with NULL event, it may crash the app! */
@@ -596,4 +597,6 @@
 	}
     }
+
+    pj_log_pop_indent();
 }
 
@@ -628,4 +631,5 @@
 
 	    PJ_LOG(5,(sub->obj_name, "Refreshing subscription."));
+	    pj_log_push_indent();
 	    status = pjsip_evsub_initiate(sub, NULL, 
 					  sub->expires->ivalue,
@@ -633,4 +637,6 @@
 	    if (status == PJ_SUCCESS)
 		pjsip_evsub_send_request(sub, tdata);
+
+	    pj_log_pop_indent();
 	}
 	break;
@@ -646,8 +652,11 @@
 	    PJ_LOG(5,(sub->obj_name, "Timeout waiting for refresh. "
 				     "Sending NOTIFY to terminate."));
+	    pj_log_push_indent();
 	    status = pjsip_evsub_notify( sub, PJSIP_EVSUB_STATE_TERMINATED, 
 					 NULL, &STR_TIMEOUT, &tdata);
 	    if (status == PJ_SUCCESS)
 		pjsip_evsub_send_request(sub, tdata);
+
+	    pj_log_pop_indent();
 	}
 	break;
@@ -659,6 +668,8 @@
 	    PJ_LOG(5,(sub->obj_name, "Timeout waiting for final NOTIFY. "
 				     "Terminating.."));
+	    pj_log_push_indent();
 	    set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, NULL, 
 		      &timeout);
+	    pj_log_pop_indent();
 	}
 	break;
@@ -673,7 +684,10 @@
 		     "send non-2xx response for previous NOTIFY). "
 		     "Unsubscribing.."));
+	    pj_log_push_indent();
 	    status = pjsip_evsub_initiate( sub, NULL, 0, &tdata);
 	    if (status == PJ_SUCCESS)
 		pjsip_evsub_send_request(sub, tdata);
+
+	    pj_log_pop_indent();
 	}
 	break;
Index: /pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c	(revision 3752)
+++ /pjproject/trunk/pjsip/src/pjsip-ua/sip_inv.c	(revision 3753)
@@ -1917,4 +1917,6 @@
     PJ_ASSERT_RETURN(inv->invite_tsx, PJ_EBUG);
 
+    pj_log_push_indent();
+
     pjsip_dlg_inc_lock(inv->dlg);
 
@@ -1964,4 +1966,5 @@
 on_return:
     pjsip_dlg_dec_lock(inv->dlg);
+    pj_log_pop_indent();
     return status;
 }
@@ -1990,4 +1993,6 @@
     PJ_ASSERT_RETURN(inv->last_answer, PJ_EINVALIDOP);
 
+    pj_log_push_indent();
+
     pjsip_dlg_inc_lock(inv->dlg);
 
@@ -2017,4 +2022,5 @@
 on_return:
     pjsip_dlg_dec_lock(inv->dlg);
+    pj_log_pop_indent();
     return status;
 }
@@ -2052,4 +2058,6 @@
     /* Verify arguments. */
     PJ_ASSERT_RETURN(inv && p_tdata, PJ_EINVAL);
+
+    pj_log_push_indent();
 
     /* Set cause code. */
@@ -2082,4 +2090,5 @@
 		PJ_LOG(4, (inv->obj_name, "Delaying CANCEL since no "
 			   "provisional response is received yet"));
+		pj_log_pop_indent();
 		return PJ_SUCCESS;
 	    }
@@ -2093,6 +2102,8 @@
 					       inv->invite_tsx->last_tx,
 					       &tdata);
-	    if (status != PJ_SUCCESS)
+	    if (status != PJ_SUCCESS) {
+		pj_log_pop_indent();
 		return status;
+	    }
 
 	    /* Set timeout for the INVITE transaction, in case UAS is not
@@ -2126,13 +2137,17 @@
     case PJSIP_INV_STATE_DISCONNECTED:
 	/* No need to do anything. */
+	pj_log_pop_indent();
 	return PJSIP_ESESSIONTERMINATED;
 
     default:
 	pj_assert("!Invalid operation!");
+	pj_log_pop_indent();
 	return PJ_EINVALIDOP;
     }
 
-    if (status != PJ_SUCCESS)
+    if (status != PJ_SUCCESS) {
+	pj_log_pop_indent();
 	return status;
+    }
 
 
@@ -2142,4 +2157,5 @@
     *p_tdata = tdata;
 
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 }
@@ -2364,4 +2380,5 @@
 	return PJ_EINVALIDOP;
 
+    pj_log_push_indent();
 
     pjsip_dlg_inc_lock(inv->dlg);
@@ -2434,4 +2451,5 @@
 on_return:
     pjsip_dlg_dec_lock(inv->dlg);
+    pj_log_pop_indent();
     return status;
 }
@@ -2460,4 +2478,6 @@
     PJ_ASSERT_RETURN(inv->state < PJSIP_INV_STATE_DISCONNECTED,
 		     PJ_EINVALIDOP);
+
+    pj_log_push_indent();
 
     /* Lock dialog. */
@@ -2523,4 +2543,5 @@
     *p_tdata = tdata;
 
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 
@@ -2532,4 +2553,5 @@
     pjsip_dlg_dec_lock(inv->dlg);
 
+    pj_log_pop_indent();
     return status;
 }
@@ -2594,4 +2616,6 @@
     PJ_ASSERT_RETURN(inv && tdata, PJ_EINVAL);
 
+    pj_log_push_indent();
+
     PJ_LOG(5,(inv->obj_name, "Sending %s", 
 	      pjsip_tx_data_get_info(tdata)));
@@ -2608,5 +2632,6 @@
 	    pjsip_tx_data_dec_ref(tdata);
 	    pjsip_dlg_dec_lock(inv->dlg);
-	    return PJ_EINVALIDOP;
+	    status = PJ_EINVALIDOP;
+	    goto on_error;
 	}
 
@@ -2619,6 +2644,7 @@
 	status = pjsip_dlg_send_request(inv->dlg, tdata, mod_inv.mod.id, 
 					tsx_inv_data);
-	if (status != PJ_SUCCESS)
-	    return status;
+	if (status != PJ_SUCCESS) {
+	    goto on_error;
+	}
 
     } else {
@@ -2639,10 +2665,16 @@
 	}
 
-	if (status != PJ_SUCCESS)
-	    return status;
-    }
-
-    /* Done (?) */
+	if (status != PJ_SUCCESS) {
+	    goto on_error;
+	}
+    }
+
+    /* Done */
+    pj_log_pop_indent();
     return PJ_SUCCESS;
+
+on_error:
+    pj_log_pop_indent();
+    return status;
 }
 
Index: /pjproject/trunk/pjsip/src/pjsip/sip_dialog.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip/sip_dialog.c	(revision 3752)
+++ /pjproject/trunk/pjsip/src/pjsip/sip_dialog.c	(revision 3753)
@@ -803,4 +803,6 @@
     PJ_ASSERT_RETURN(dlg && mod, PJ_EINVAL);
 
+    pj_log_push_indent();
+
     pjsip_dlg_inc_lock(dlg);
     ++dlg->sess_count;
@@ -810,4 +812,5 @@
 	      dlg->sess_count, (int)mod->name.slen, mod->name.ptr));
 
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 }
@@ -890,4 +893,6 @@
     PJ_ASSERT_RETURN(dlg, PJ_EINVAL);
 
+    pj_log_push_indent();
+
     PJ_LOG(5,(dlg->obj_name, "Session count dec to %d by %.*s",
 	      dlg->sess_count-1, (int)mod->name.slen, mod->name.ptr));
@@ -897,4 +902,5 @@
     pjsip_dlg_dec_lock(dlg);
 
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 }
@@ -1151,4 +1157,5 @@
 		     PJSIP_ENOTREQUESTMSG);
 
+    pj_log_push_indent();
     PJ_LOG(5,(dlg->obj_name, "Sending %s",
 	      pjsip_tx_data_get_info(tdata)));
@@ -1222,5 +1229,5 @@
     /* Unlock dialog, may destroy dialog. */
     pjsip_dlg_dec_lock(dlg);
-
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 
@@ -1231,5 +1238,5 @@
     /* Whatever happen delete the message. */
     pjsip_tx_data_dec_ref( tdata );
-
+    pj_log_pop_indent();
     return status;
 }
@@ -1409,4 +1416,6 @@
     PJ_ASSERT_RETURN(tsx->mod_data[dlg->ua->id] == dlg, PJ_EINVALIDOP);
 
+    pj_log_push_indent();
+
     PJ_LOG(5,(dlg->obj_name, "Sending %s",
 	      pjsip_tx_data_get_info(tdata)));
@@ -1453,4 +1462,5 @@
 
     pjsip_dlg_dec_lock(dlg);
+    pj_log_pop_indent();
 
     return status;
@@ -1520,4 +1530,5 @@
     PJ_LOG(5,(dlg->obj_name, "Received %s",
 	      pjsip_rx_data_get_info(rdata)));
+    pj_log_push_indent();
 
     /* Lock dialog and increment session. */
@@ -1541,4 +1552,5 @@
 	pjsip_endpt_respond_stateless(dlg->endpt,
 				      rdata, 500, &warn_text, NULL, NULL);
+	pj_log_pop_indent();
 	return;
     }
@@ -1644,4 +1656,5 @@
     /* Unlock dialog and dec session, may destroy dialog. */
     pjsip_dlg_dec_lock(dlg);
+    pj_log_pop_indent();
 }
 
@@ -1740,4 +1753,5 @@
     PJ_LOG(5,(dlg->obj_name, "Received %s",
 	      pjsip_rx_data_get_info(rdata)));
+    pj_log_push_indent();
 
     /* Lock the dialog and inc session. */
@@ -1932,4 +1946,6 @@
     /* Unlock dialog and dec session, may destroy dialog. */
     pjsip_dlg_dec_lock(dlg);
+
+    pj_log_pop_indent();
 }
 
@@ -1945,4 +1961,5 @@
     PJ_LOG(5,(dlg->obj_name, "Transaction %s state changed to %s",
 	      tsx->obj_name, pjsip_tsx_state_str(tsx->state)));
+    pj_log_push_indent();
 
     /* Lock the dialog and increment session. */
@@ -1973,4 +1990,5 @@
     /* Unlock dialog and dec session, may destroy dialog. */
     pjsip_dlg_dec_lock(dlg);
+    pj_log_pop_indent();
 }
 
Index: /pjproject/trunk/pjsip/src/pjsip/sip_endpoint.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip/sip_endpoint.c	(revision 3752)
+++ /pjproject/trunk/pjsip/src/pjsip/sip_endpoint.c	(revision 3753)
@@ -826,4 +826,5 @@
     PJ_LOG(5, (THIS_FILE, "Processing incoming message: %s", 
 	       pjsip_rx_data_get_info(rdata)));
+    pj_log_push_indent();
 
 #if defined(PJSIP_CHECK_VIA_SENT_BY) && PJSIP_CHECK_VIA_SENT_BY != 0
@@ -881,4 +882,5 @@
 				 rdata->pkt_info.src_name, 
 				 rdata->pkt_info.src_port));
+	    pj_log_pop_indent();
 	    return;
 	}
@@ -941,4 +943,6 @@
      */
     pj_bzero(&rdata->endpt_info, sizeof(rdata->endpt_info));
+
+    pj_log_pop_indent();
 }
 
Index: /pjproject/trunk/pjsip/src/pjsip/sip_transaction.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip/sip_transaction.c	(revision 3752)
+++ /pjproject/trunk/pjsip/src/pjsip/sip_transaction.c	(revision 3753)
@@ -1087,4 +1087,5 @@
     PJ_LOG(5,(tsx->obj_name, "%s timer event", 
 	     (entry==&tsx->retransmit_timer ? "Retransmit":"Timeout")));
+    pj_log_push_indent();
 
 
@@ -1095,4 +1096,6 @@
     (*tsx->state_handler)(tsx, &event);
     unlock_tsx(tsx, &lck);
+
+    pj_log_pop_indent();
 }
 
@@ -1114,4 +1117,5 @@
 	       state_str[tsx->state], state_str[state], 
                pjsip_event_str(event_src_type)));
+    pj_log_push_indent();
 
     /* Change state. */
@@ -1192,4 +1196,6 @@
 	tsx_destroy(tsx);
     }
+
+    pj_log_pop_indent();
 }
 
@@ -1325,6 +1331,8 @@
     unlock_tsx(tsx, &lck);
 
+    pj_log_push_indent();
     PJ_LOG(5,(tsx->obj_name, "Transaction created for %s",
 	      pjsip_tx_data_get_info(tdata)));
+    pj_log_pop_indent();
 
     *p_tsx = tsx;
@@ -1467,7 +1475,8 @@
     unlock_tsx(tsx, &lck);
 
-
+    pj_log_push_indent();
     PJ_LOG(5,(tsx->obj_name, "Transaction created for %s",
 	      pjsip_rx_data_get_info(rdata)));
+    pj_log_pop_indent();
 
 
@@ -1537,4 +1546,6 @@
 	return PJ_SUCCESS;
 
+    pj_log_push_indent();
+
     lock_tsx(tsx, &lck);
     tsx_set_status_code(tsx, code, NULL);
@@ -1542,4 +1553,6 @@
     unlock_tsx(tsx, &lck);
 
+    pj_log_pop_indent();
+
     return PJ_SUCCESS;
 }
@@ -1561,4 +1574,6 @@
 
     PJ_LOG(5,(tsx->obj_name, "Request to stop retransmission"));
+
+    pj_log_push_indent();
 
     lock_tsx(tsx, &lck);
@@ -1569,4 +1584,6 @@
     }
     unlock_tsx(tsx, &lck);
+
+    pj_log_pop_indent();
 
     return PJ_SUCCESS;
@@ -1641,4 +1658,5 @@
                              pjsip_tx_data_get_info(tdata),
 			     state_str[tsx->state]));
+    pj_log_push_indent();
 
     PJSIP_EVENT_INIT_TX_MSG(event, tdata);
@@ -1662,4 +1680,6 @@
     }
 
+    pj_log_pop_indent();
+
     return status;
 }
@@ -1679,4 +1699,5 @@
     PJ_LOG(5,(tsx->obj_name, "Incoming %s in state %s", 
 	      pjsip_rx_data_get_info(rdata), state_str[tsx->state]));
+    pj_log_push_indent();
 
     /* Put the transaction in the rdata's mod_data. */
@@ -1690,4 +1711,6 @@
     status = (*tsx->state_handler)(tsx, &event);
     unlock_tsx(tsx, &lck);
+
+    pj_log_pop_indent();
 }
 
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c	(revision 3752)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c	(revision 3753)
@@ -375,6 +375,7 @@
     pjsua_acc *acc;
     unsigned i, id;
-    pj_status_t status;
-
+    pj_status_t status = PJ_SUCCESS;
+
+    PJ_ASSERT_RETURN(cfg, PJ_EINVAL);
     PJ_ASSERT_RETURN(pjsua_var.acc_cnt < PJ_ARRAY_SIZE(pjsua_var.acc),
 		     PJ_ETOOMANY);
@@ -385,8 +386,13 @@
     /* Verify media count */
 #if !defined(PJMEDIA_HAS_VIDEO) || (PJMEDIA_HAS_VIDEO == 0)
+    /* Enable PJMEDIA_HAS_VIDEO in your config_site.h! */
     PJ_ASSERT_RETURN(cfg->max_video_cnt == 0, PJ_EINVAL);
 #endif
     PJ_ASSERT_RETURN(cfg->max_audio_cnt + cfg->max_video_cnt <= 
 		     PJSUA_MAX_CALL_MEDIA, PJ_ETOOMANY);
+
+    PJ_LOG(4,(THIS_FILE, "Adding account: id=%.*s",
+	      (int)cfg->id.slen, cfg->id.ptr));
+    pj_log_push_indent();
 
     PJSUA_LOCK();
@@ -434,6 +440,9 @@
     for (i=0; i<acc->cfg.proxy_cnt; ++i) {
 	status = normalize_route_uri(acc->pool, &acc->cfg.proxy[i]);
-	if (status != PJ_SUCCESS)
+	if (status != PJ_SUCCESS) {
+	    PJSUA_UNLOCK();
+	    pj_log_pop_indent();
 	    return status;
+	}
     }
 
@@ -444,4 +453,5 @@
 	acc->pool = NULL;
 	PJSUA_UNLOCK();
+	pj_log_pop_indent();
 	return status;
     }
@@ -469,4 +479,5 @@
     }
 
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 }
@@ -575,4 +586,7 @@
     PJ_ASSERT_RETURN(pjsua_var.acc[acc_id].valid, PJ_EINVALIDOP);
 
+    PJ_LOG(4,(THIS_FILE, "Deleting account %d..", acc_id));
+    pj_log_push_indent();
+
     PJSUA_LOCK();
 
@@ -625,4 +639,5 @@
     PJ_LOG(4,(THIS_FILE, "Account id %d deleted", acc_id));
 
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 }
@@ -656,4 +671,6 @@
 		     PJSUA_MAX_CALL_MEDIA, PJ_ETOOMANY);
 
+    PJ_LOG(4,(THIS_FILE, "Modifying accunt %d", acc_id));
+    pj_log_push_indent();
 
     PJSUA_LOCK();
@@ -1041,4 +1058,5 @@
 on_return:
     PJSUA_UNLOCK();
+    pj_log_pop_indent();
     return status;
 }
@@ -1056,7 +1074,13 @@
     PJ_ASSERT_RETURN(pjsua_var.acc[acc_id].valid, PJ_EINVALIDOP);
 
+    PJ_LOG(4,(THIS_FILE, "Acc %d: setting online status to %d..",
+	      acc_id, is_online));
+    pj_log_push_indent();
+
     pjsua_var.acc[acc_id].online_status = is_online;
     pj_bzero(&pjsua_var.acc[acc_id].rpid, sizeof(pjrpid_element));
     pjsua_pres_update_acc(acc_id, PJ_FALSE);
+
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 }
@@ -1074,4 +1098,8 @@
     PJ_ASSERT_RETURN(pjsua_var.acc[acc_id].valid, PJ_EINVALIDOP);
 
+    PJ_LOG(4,(THIS_FILE, "Acc %d: setting online status to %d..",
+    	      acc_id, is_online));
+    pj_log_push_indent();
+
     PJSUA_LOCK();
     pjsua_var.acc[acc_id].online_status = is_online;
@@ -1080,4 +1108,6 @@
 
     pjsua_pres_update_acc(acc_id, PJ_TRUE);
+    pj_log_pop_indent();
+
     return PJ_SUCCESS;
 }
@@ -1665,4 +1695,5 @@
 	return;
 
+    pj_log_push_indent();
     PJSUA_LOCK();
 
@@ -1716,4 +1747,5 @@
 	    if (acc_check_nat_addr(acc, param)) {
 		PJSUA_UNLOCK();
+		pj_log_pop_indent();
 		return;
 	    }
@@ -1778,4 +1810,5 @@
     
     PJSUA_UNLOCK();
+    pj_log_pop_indent();
 }
 
@@ -1965,4 +1998,8 @@
     PJ_ASSERT_RETURN(pjsua_var.acc[acc_id].valid, PJ_EINVALIDOP);
 
+    PJ_LOG(4,(THIS_FILE, "Acc %d: setting %sregistration..",
+	      acc_id, (renew? "" : "un")));
+    pj_log_push_indent();
+
     PJSUA_LOCK();
 
@@ -2040,5 +2077,5 @@
 		     status);
     } else {
-	PJ_LOG(3,(THIS_FILE, "%s sent",
+	PJ_LOG(4,(THIS_FILE, "Acc %d: %s sent", acc_id,
 	         (renew? "Registration" : "Unregistration")));
     }
@@ -2046,4 +2083,5 @@
 on_return:
     PJSUA_UNLOCK();
+    pj_log_pop_indent();
     return status;
 }
@@ -2791,4 +2829,8 @@
 	return;
 
+    PJ_LOG(4,(THIS_FILE, "Disconnected notification for transport %s",
+	      tp->obj_name));
+    pj_log_push_indent();
+
     /* Shutdown this transport, to make sure that the transport manager 
      * will create a new transport for reconnection.
@@ -2818,3 +2860,4 @@
 
     PJSUA_UNLOCK();
-}
+    pj_log_pop_indent();
+}
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 3752)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c	(revision 3753)
@@ -343,5 +343,5 @@
 					  pjsua_call_id *p_call_id)
 {
-    pj_pool_t *tmp_pool;
+    pj_pool_t *tmp_pool = NULL;
     pjsip_dialog *dlg = NULL;
     pjmedia_sdp_session *offer;
@@ -362,4 +362,9 @@
     PJ_ASSERT_RETURN(dest_uri, PJ_EINVAL);
 
+    PJ_LOG(4,(THIS_FILE, "Making call with acc #%d to %.*s", acc_id,
+	      (int)dest_uri->slen, dest_uri->ptr));
+
+    pj_log_push_indent();
+
     PJSUA_LOCK();
 
@@ -375,8 +380,6 @@
 
 	status = pjsua_set_snd_dev(pjsua_var.cap_dev, pjsua_var.play_dev);
-	if (status != PJ_SUCCESS) {
-	    PJSUA_UNLOCK();
-	    return status;
-	}
+	if (status != PJ_SUCCESS)
+	    goto on_error;
     }
 
@@ -385,6 +388,6 @@
 	pjsua_perror(THIS_FILE, "Unable to make call because account "
 		     "is not valid", PJ_EINVALIDOP);
-	PJSUA_UNLOCK();
-	return PJ_EINVALIDOP;
+	status = PJ_EINVALIDOP;
+	goto on_error;
     }
 
@@ -394,6 +397,6 @@
     if (call_id == PJSUA_INVALID_ID) {
 	pjsua_perror(THIS_FILE, "Error making call", PJ_ETOOMANY);
-	PJSUA_UNLOCK();
-	return PJ_ETOOMANY;
+	status = PJ_ETOOMANY;
+	goto on_error;
     }
 
@@ -422,12 +425,8 @@
 	    pjsua_perror(THIS_FILE, "Unable to make call", 
 			 PJSIP_EINVALIDREQURI);
-	    pj_pool_release(tmp_pool);
-	    PJSUA_UNLOCK();
-	    return PJSIP_EINVALIDREQURI;
-	}
-    }
-
-    PJ_LOG(4,(THIS_FILE, "Making call with acc #%d to %.*s", acc_id,
-	      (int)dest_uri->slen, dest_uri->ptr));
+	    status = PJSIP_EINVALIDREQURI;
+	    goto on_error;
+	}
+    }
 
     /* Mark call start time. */
@@ -448,7 +447,5 @@
 	    pjsua_perror(THIS_FILE, "Unable to generate Contact header", 
 			 status);
-	    pj_pool_release(tmp_pool);
-	    PJSUA_UNLOCK();
-	    return status;
+	    goto on_error;
 	}
     }
@@ -460,7 +457,5 @@
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Dialog creation failed", status);
-	pj_pool_release(tmp_pool);
-	PJSUA_UNLOCK();
-	return status;
+	goto on_error;
     }
 
@@ -588,4 +583,6 @@
     PJSUA_UNLOCK();
 
+    pj_log_pop_indent();
+
     return PJ_SUCCESS;
 
@@ -606,6 +603,9 @@
     }
 
-    pj_pool_release(tmp_pool);
+    if (tmp_pool)
+	pj_pool_release(tmp_pool);
     PJSUA_UNLOCK();
+
+    pj_log_pop_indent();
     return status;
 }
@@ -669,4 +669,7 @@
     }
 
+    PJ_LOG(4,(THIS_FILE, "Incoming %s", rdata->msg_info.info));
+    pj_log_push_indent();
+
     PJSUA_LOCK();
 
@@ -680,6 +683,5 @@
 	PJ_LOG(2,(THIS_FILE, 
 		  "Unable to accept incoming call (too many calls)"));
-	PJSUA_UNLOCK();
-	return PJ_TRUE;
+	goto on_return;
     }
 
@@ -715,6 +717,5 @@
 	}
 
-	PJSUA_UNLOCK();
-	return PJ_TRUE;
+	goto on_return;
     }
 
@@ -746,6 +747,5 @@
 	    pjsip_endpt_respond(pjsua_var.endpt, NULL, rdata, 
 				st_code, &st_text, NULL, NULL, NULL);
-	    PJSUA_UNLOCK();
-	    return PJ_TRUE;
+	    goto on_return;
 	}
     }
@@ -794,6 +794,5 @@
 	    pjsip_endpt_respond(pjsua_var.endpt, NULL, rdata, 400, 
 				&reason, &hdr_list, NULL, NULL);
-	    PJSUA_UNLOCK();
-	    return PJ_TRUE;
+	    goto on_return;
 	}
 
@@ -805,6 +804,5 @@
 	    pjsip_endpt_respond(pjsua_var.endpt, NULL, rdata, 400, &reason, 
 				NULL, NULL, NULL);
-	    PJSUA_UNLOCK();
-	    return PJ_TRUE;
+	    goto on_return;
 	}
 
@@ -823,6 +821,5 @@
 	pjsip_endpt_respond(pjsua_var.endpt, NULL, rdata,
 			    sip_err_code, NULL, NULL, NULL, NULL);
-	PJSUA_UNLOCK();
-	return PJ_TRUE;
+	goto on_return;
     }
 
@@ -834,6 +831,5 @@
 	pjsip_endpt_respond(pjsua_var.endpt, NULL, rdata,
 			    sip_err_code, NULL, NULL, NULL, NULL);
-	PJSUA_UNLOCK();
-	return PJ_TRUE;
+	goto on_return;
     }
 
@@ -872,6 +868,5 @@
 
 	pjsua_media_channel_deinit(call->index);
-	PJSUA_UNLOCK();
-	return PJ_TRUE;
+	goto on_return;
     } 
 
@@ -889,6 +884,5 @@
 					  NULL, NULL);
 	    pjsua_media_channel_deinit(call->index);
-	    PJSUA_UNLOCK();
-	    return PJ_TRUE;
+	    goto on_return;
 	}
     }
@@ -901,6 +895,5 @@
 				      NULL, NULL);
 	pjsua_media_channel_deinit(call->index);
-	PJSUA_UNLOCK();
-	return PJ_TRUE;
+	goto on_return;
     }
 
@@ -943,6 +936,5 @@
 	 */
 	pjsua_media_channel_deinit(call->index);
-	PJSUA_UNLOCK();
-	return PJ_TRUE;
+	goto on_return;
     }
 
@@ -959,6 +951,5 @@
 	pjsua_media_channel_deinit(call->index);
 
-	PJSUA_UNLOCK();
-	return PJ_TRUE;
+	goto on_return;
     }
 
@@ -1007,6 +998,5 @@
 	}
 	pjsua_media_channel_deinit(call->index);
-	PJSUA_UNLOCK();
-	return PJ_TRUE;
+	goto on_return;
 
     } else {
@@ -1014,6 +1004,5 @@
 	if (status != PJ_SUCCESS) {
 	    pjsua_perror(THIS_FILE, "Unable to send 100 response", status);
-	    PJSUA_UNLOCK();
-	    return PJ_TRUE;
+	    goto on_return;
 	}
     }
@@ -1088,4 +1077,6 @@
 
     /* This INVITE request has been handled. */
+on_return:
+    pj_log_pop_indent();
     PJSUA_UNLOCK();
     return PJ_TRUE;
@@ -1578,5 +1569,5 @@
 {
     pjsua_call *call;
-    pjsip_dialog *dlg;
+    pjsip_dialog *dlg = NULL;
     pjsip_tx_data *tdata;
     pj_status_t status;
@@ -1585,7 +1576,10 @@
 		     PJ_EINVAL);
 
+    PJ_LOG(4,(THIS_FILE, "Answering call %d: code=%d", call_id, code));
+    pj_log_push_indent();
+
     status = acquire_call("pjsua_call_answer()", call_id, &call, &dlg);
     if (status != PJ_SUCCESS)
-	return status;
+	goto on_return;
 
     if (call->res_time.sec == 0)
@@ -1600,6 +1594,5 @@
 	pjsua_perror(THIS_FILE, "Error creating response", 
 		     status);
-	pjsip_dlg_dec_lock(dlg);
-	return status;
+	goto on_return;
     }
 
@@ -1607,8 +1600,6 @@
      * 200/OK and the media failed to start.
      */
-    if (call->inv == NULL) {
-	pjsip_dlg_dec_lock(dlg);
-	return PJSIP_ESESSIONTERMINATED;
-    }
+    if (call->inv == NULL)
+	goto on_return;
 
     /* Add additional headers etc */
@@ -1621,6 +1612,7 @@
 		     status);
 
-    pjsip_dlg_dec_lock(dlg);
-
+on_return:
+    if (dlg) pjsip_dlg_dec_lock(dlg);
+    pj_log_pop_indent();
     return status;
 }
@@ -1637,5 +1629,5 @@
 {
     pjsua_call *call;
-    pjsip_dialog *dlg;
+    pjsip_dialog *dlg = NULL;
     pj_status_t status;
     pjsip_tx_data *tdata;
@@ -1650,7 +1642,10 @@
 		     PJ_EINVAL);
 
+    PJ_LOG(4,(THIS_FILE, "Call %d hanging up: code=%d..", call_id, code));
+    pj_log_push_indent();
+
     status = acquire_call("pjsua_call_hangup()", call_id, &call, &dlg);
     if (status != PJ_SUCCESS)
-	return status;
+	goto on_return;
 
     if (code==0) {
@@ -1668,6 +1663,5 @@
 		     "Failed to create end session message", 
 		     status);
-	pjsip_dlg_dec_lock(dlg);
-	return status;
+	goto on_return;
     }
 
@@ -1676,8 +1670,6 @@
      * with any provisional responses.
      */
-    if (tdata == NULL) {
-	pjsip_dlg_dec_lock(dlg);
-	return PJ_SUCCESS;
-    }
+    if (tdata == NULL)
+	goto on_return;
 
     /* Add additional headers etc */
@@ -1690,6 +1682,5 @@
 		     "Failed to send end session message", 
 		     status);
-	pjsip_dlg_dec_lock(dlg);
-	return status;
+	goto on_return;
     }
 
@@ -1701,7 +1692,8 @@
     }
 
-    pjsip_dlg_dec_lock(dlg);
-
-    return PJ_SUCCESS;
+on_return:
+    if (dlg) pjsip_dlg_dec_lock(dlg);
+    pj_log_pop_indent();
+    return status;
 }
 
@@ -1741,5 +1733,5 @@
     pjmedia_sdp_session *sdp;
     pjsua_call *call;
-    pjsip_dialog *dlg;
+    pjsip_dialog *dlg = NULL;
     pjsip_tx_data *tdata;
     pj_status_t status;
@@ -1748,20 +1740,20 @@
 		     PJ_EINVAL);
 
+    PJ_LOG(4,(THIS_FILE, "Putting call %d on hold", call_id));
+    pj_log_push_indent();
+
     status = acquire_call("pjsua_call_set_hold()", call_id, &call, &dlg);
     if (status != PJ_SUCCESS)
-	return status;
-
+	goto on_return;
 
     if (call->inv->state != PJSIP_INV_STATE_CONFIRMED) {
 	PJ_LOG(3,(THIS_FILE, "Can not hold call that is not confirmed"));
-	pjsip_dlg_dec_lock(dlg);
-	return PJSIP_ESESSIONSTATE;
+	status = PJSIP_ESESSIONSTATE;
+	goto on_return;
     }
 
     status = create_sdp_of_call_hold(call, &sdp);
-    if (status != PJ_SUCCESS) {
-	pjsip_dlg_dec_lock(dlg);
-	return status;
-    }
+    if (status != PJ_SUCCESS)
+	goto on_return;
 
     /* Create re-INVITE with new offer */
@@ -1769,6 +1761,5 @@
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to create re-INVITE", status);
-	pjsip_dlg_dec_lock(dlg);
-	return status;
+	goto on_return;
     }
 
@@ -1780,6 +1771,5 @@
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to send re-INVITE", status);
-	pjsip_dlg_dec_lock(dlg);
-	return status;
+	goto on_return;
     }
 
@@ -1787,7 +1777,8 @@
     call->local_hold = PJ_TRUE;
 
-    pjsip_dlg_dec_lock(dlg);
-
-    return PJ_SUCCESS;
+on_return:
+    if (dlg) pjsip_dlg_dec_lock(dlg);
+    pj_log_pop_indent();
+    return status;
 }
 
@@ -1804,5 +1795,5 @@
     pjsip_tx_data *tdata;
     pjsua_call *call;
-    pjsip_dialog *dlg;
+    pjsip_dialog *dlg = NULL;
     pj_status_t status;
 
@@ -1811,12 +1802,15 @@
 		     PJ_EINVAL);
 
+    PJ_LOG(4,(THIS_FILE, "Sending re-INVITE on call %d", call_id));
+    pj_log_push_indent();
+
     status = acquire_call("pjsua_call_reinvite()", call_id, &call, &dlg);
     if (status != PJ_SUCCESS)
-	return status;
+	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"));
-	pjsip_dlg_dec_lock(dlg);
-	return PJSIP_ESESSIONSTATE;
+	status = PJSIP_ESESSIONSTATE;
+	goto on_return;
     }
 
@@ -1833,6 +1827,5 @@
 	pjsua_perror(THIS_FILE, "Unable to get SDP from media endpoint", 
 		     status);
-	pjsip_dlg_dec_lock(dlg);
-	return status;
+	goto on_return;
     }
 
@@ -1847,6 +1840,5 @@
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to create re-INVITE", status);
-	pjsip_dlg_dec_lock(dlg);
-	return status;
+	goto on_return;
     }
 
@@ -1858,11 +1850,11 @@
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to send re-INVITE", status);
-	pjsip_dlg_dec_lock(dlg);
-	return status;
-    }
-
+	goto on_return;
+    }
+
+on_return:
     pjsip_dlg_dec_lock(dlg);
-
-    return PJ_SUCCESS;
+    pj_log_pop_indent();
+    return status;
 }
 
@@ -1879,5 +1871,5 @@
     pjsip_tx_data *tdata;
     pjsua_call *call;
-    pjsip_dialog *dlg;
+    pjsip_dialog *dlg = NULL;
     pj_status_t status;
 
@@ -1887,7 +1879,10 @@
 		     PJ_EINVAL);
 
+    PJ_LOG(4,(THIS_FILE, "Sending UPDATE on call %d", call_id));
+    pj_log_push_indent();
+
     status = acquire_call("pjsua_call_update()", call_id, &call, &dlg);
     if (status != PJ_SUCCESS)
-	return status;
+	goto on_return;
 
     /* Create SDP */
@@ -1898,6 +1893,5 @@
 	pjsua_perror(THIS_FILE, "Unable to get SDP from media endpoint", 
 		     status);
-	pjsip_dlg_dec_lock(dlg);
-	return status;
+	goto on_return;
     }
 
@@ -1912,6 +1906,5 @@
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to create UPDATE request", status);
-	pjsip_dlg_dec_lock(dlg);
-	return status;
+	goto on_return;
     }
 
@@ -1923,13 +1916,13 @@
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to send UPDATE request", status);
-	pjsip_dlg_dec_lock(dlg);
-	return status;
+	goto on_return;
     }
 
     call->local_hold = PJ_FALSE;
 
-    pjsip_dlg_dec_lock(dlg);
-
-    return PJ_SUCCESS;
+on_return:
+    if (dlg) pjsip_dlg_dec_lock(dlg);
+    pj_log_pop_indent();
+    return status;
 }
 
@@ -1945,5 +1938,5 @@
     pjsip_tx_data *tdata;
     pjsua_call *call;
-    pjsip_dialog *dlg;
+    pjsip_dialog *dlg = NULL;
     pjsip_generic_string_hdr *gs_hdr;
     const pj_str_t str_ref_by = { "Referred-By", 11 };
@@ -1952,11 +1945,14 @@
 
 
-    PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls,
-		     PJ_EINVAL);
+    PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls &&
+                     dest, PJ_EINVAL);
     
+    PJ_LOG(4,(THIS_FILE, "Transfering call %d to %.*s", call_id,
+			 (int)dest->slen, dest->ptr));
+    pj_log_push_indent();
+
     status = acquire_call("pjsua_call_xfer()", call_id, &call, &dlg);
     if (status != PJ_SUCCESS)
-	return status;
-
+	goto on_return;
    
     /* Create xfer client subscription. */
@@ -1967,6 +1963,5 @@
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to create xfer", status);
-	pjsip_dlg_dec_lock(dlg);
-	return status;
+	goto on_return;
     }
 
@@ -1980,6 +1975,5 @@
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to create REFER request", status);
-	pjsip_dlg_dec_lock(dlg);
-	return status;
+	goto on_return;
     }
 
@@ -1997,6 +1991,5 @@
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to send REFER request", status);
-	pjsip_dlg_dec_lock(dlg);
-	return status;
+	goto on_return;
     }
 
@@ -2005,8 +1998,8 @@
      * may want to hold the INVITE, or terminate the invite, or whatever.
      */
-
-    pjsip_dlg_dec_lock(dlg);
-
-    return PJ_SUCCESS;
+on_return:
+    if (dlg) pjsip_dlg_dec_lock(dlg);
+    pj_log_pop_indent();
+    return status;
 
 }
@@ -2036,8 +2029,14 @@
 		     PJ_EINVAL);
     
+    PJ_LOG(4,(THIS_FILE, "Transfering call %d replacing with call %d",
+			 call_id, dest_call_id));
+    pj_log_push_indent();
+
     status = acquire_call("pjsua_call_xfer_replaces()", dest_call_id, 
 			  &dest_call, &dest_dlg);
-    if (status != PJ_SUCCESS)
+    if (status != PJ_SUCCESS) {
+	pj_log_pop_indent();
 	return status;
+    }
         
     /* 
@@ -2046,9 +2045,10 @@
 
     /* Make sure we have sufficient buffer's length */
-    PJ_ASSERT_RETURN( dest_dlg->remote.info_str.slen +
+    PJ_ASSERT_ON_FAIL(dest_dlg->remote.info_str.slen +
 		      dest_dlg->call_id->id.slen +
 		      dest_dlg->remote.info->tag.slen +
 		      dest_dlg->local.info->tag.slen + 32 
-		      < (long)sizeof(str_dest_buf), PJSIP_EURITOOLONG);
+		      < (long)sizeof(str_dest_buf),
+		      { status=PJSIP_EURITOOLONG; goto on_error; });
 
     /* Print URI */
@@ -2059,6 +2059,8 @@
     len = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, uri, 
 		          str_dest_buf+1, sizeof(str_dest_buf)-1);
-    if (len < 0)
-	return PJSIP_EURITOOLONG;
+    if (len < 0) {
+	status = PJSIP_EURITOOLONG;
+	goto on_error;
+    }
 
     str_dest.slen += len;
@@ -2081,6 +2083,6 @@
 			   dest_dlg->local.info->tag.ptr);
 
-    PJ_ASSERT_RETURN(len > 0 && len <= (int)sizeof(str_dest_buf)-str_dest.slen,
-		     PJSIP_EURITOOLONG);
+    PJ_ASSERT_ON_FAIL(len > 0 && len <= (int)sizeof(str_dest_buf)-str_dest.slen,
+		      { status=PJSIP_EURITOOLONG; goto on_error; });
     
     str_dest.ptr = str_dest_buf;
@@ -2089,5 +2091,13 @@
     pjsip_dlg_dec_lock(dest_dlg);
     
-    return pjsua_call_xfer(call_id, &str_dest, msg_data);
+    status = pjsua_call_xfer(call_id, &str_dest, msg_data);
+
+    pj_log_pop_indent();
+    return status;
+
+on_error:
+    if (dest_dlg) pjsip_dlg_dec_lock(dest_dlg);
+    pj_log_pop_indent();
+    return status;
 }
 
@@ -2100,5 +2110,5 @@
 {
     pjsua_call *call;
-    pjsip_dialog *dlg;
+    pjsip_dialog *dlg = NULL;
     pj_status_t status;
 
@@ -2106,12 +2116,16 @@
 		     PJ_EINVAL);
     
+    PJ_LOG(4,(THIS_FILE, "Call %d dialing DTMF %.*s",
+    			 call_id, (int)digits->slen, digits->ptr));
+    pj_log_push_indent();
+
     status = acquire_call("pjsua_call_dial_dtmf()", call_id, &call, &dlg);
     if (status != PJ_SUCCESS)
-	return status;
+	goto on_return;
 
     if (!pjsua_call_has_media(call_id)) {
 	PJ_LOG(3,(THIS_FILE, "Media is not established yet!"));
-	pjsip_dlg_dec_lock(dlg);
-	return PJ_EINVALIDOP;
+	status = PJ_EINVALIDOP;
+	goto on_return;
     }
 
@@ -2119,6 +2133,7 @@
 		call->media[call->audio_idx].strm.a.stream, digits);
 
-    pjsip_dlg_dec_lock(dlg);
-
+on_return:
+    if (dlg) pjsip_dlg_dec_lock(dlg);
+    pj_log_pop_indent();
     return status;
 }
@@ -2135,5 +2150,5 @@
 {
     pjsua_call *call;
-    pjsip_dialog *dlg;
+    pjsip_dialog *dlg = NULL;
     const pj_str_t mime_text_plain = pj_str("text/plain");
     pjsip_media_type ctype;
@@ -2142,11 +2157,14 @@
     pj_status_t status;
 
-
     PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls,
 		     PJ_EINVAL);
 
+    PJ_LOG(4,(THIS_FILE, "Call %d sending %d bytes MESSAGE..",
+        	          call_id, (int)content->slen));
+    pj_log_push_indent();
+
     status = acquire_call("pjsua_call_send_im()", call_id, &call, &dlg);
     if (status != PJ_SUCCESS)
-	return status;
+	goto on_return;
     
     /* Set default media type if none is specified */
@@ -2200,5 +2218,6 @@
 
 on_return:
-    pjsip_dlg_dec_lock(dlg);
+    if (dlg) pjsip_dlg_dec_lock(dlg);
+    pj_log_pop_indent();
     return status;
 }
@@ -2213,5 +2232,5 @@
 {
     pjsua_call *call;
-    pjsip_dialog *dlg;
+    pjsip_dialog *dlg = NULL;
     pjsip_tx_data *tdata;
     pj_status_t status;
@@ -2220,7 +2239,11 @@
 		     PJ_EINVAL);
 
+    PJ_LOG(4,(THIS_FILE, "Call %d sending typing indication..",
+            	          call_id));
+    pj_log_push_indent();
+
     status = acquire_call("pjsua_call_send_typing_ind", call_id, &call, &dlg);
     if (status != PJ_SUCCESS)
-	return status;
+	goto on_return;
 
     /* Create request message. */
@@ -2247,5 +2270,6 @@
 
 on_return:
-    pjsip_dlg_dec_lock(dlg);
+    if (dlg) pjsip_dlg_dec_lock(dlg);
+    pj_log_pop_indent();
     return status;
 }
@@ -2260,5 +2284,5 @@
 {
     pjsua_call *call;
-    pjsip_dialog *dlg;
+    pjsip_dialog *dlg = NULL;
     pjsip_method method;
     pjsip_tx_data *tdata;
@@ -2268,7 +2292,11 @@
 		     PJ_EINVAL);
 
+    PJ_LOG(4,(THIS_FILE, "Call %d sending %.*s request..",
+            	          call_id, (int)method_str->slen, method_str->ptr));
+    pj_log_push_indent();
+
     status = acquire_call("pjsua_call_send_request", call_id, &call, &dlg);
     if (status != PJ_SUCCESS)
-	return status;
+	goto on_return;
 
     /* Init method */
@@ -2293,5 +2321,6 @@
 
 on_return:
-    pjsip_dlg_dec_lock(dlg);
+    if (dlg) pjsip_dlg_dec_lock(dlg);
+    pj_log_pop_indent();
     return status;
 }
@@ -2304,4 +2333,7 @@
 {
     unsigned i;
+
+    PJ_LOG(4,(THIS_FILE, "Hangup all calls.."));
+    pj_log_push_indent();
 
     PJSUA_LOCK();
@@ -2313,4 +2345,5 @@
 
     PJSUA_UNLOCK();
+    pj_log_pop_indent();
 }
 
@@ -2609,5 +2642,5 @@
         return PJ_SUCCESS;
 
-    PJ_LOG(3, (THIS_FILE, "Got answer with multiple codecs, scheduling "
+    PJ_LOG(4, (THIS_FILE, "Got answer with multiple codecs, scheduling "
 			  "updating media session to use only one codec.."));
 
@@ -2635,4 +2668,5 @@
     pjsua_call *call;
 
+    pj_log_push_indent();
     PJSUA_LOCK();
 
@@ -2641,4 +2675,5 @@
     if (!call) {
 	PJSUA_UNLOCK();
+	pj_log_pop_indent();
 	return;
     }
@@ -2797,4 +2832,5 @@
 
     PJSUA_UNLOCK();
+    pj_log_pop_indent();
 }
 
@@ -2905,4 +2941,5 @@
     //const pj_str_t st_update = {"UPDATE", 6};
 
+    pj_log_push_indent();
     PJSUA_LOCK();
 
@@ -2930,6 +2967,5 @@
 	}
 
-	PJSUA_UNLOCK();
-	return;
+	goto on_return;
     }
 
@@ -2942,6 +2978,5 @@
 		     status);
 	//call_disconnect(inv, PJSIP_SC_UNSUPPORTED_MEDIA_TYPE);
-	PJSUA_UNLOCK();
-	return;
+	goto on_return;
     }
 
@@ -2952,6 +2987,5 @@
 		     status);
 	//call_disconnect(inv, PJSIP_SC_UNSUPPORTED_MEDIA_TYPE);
-	PJSUA_UNLOCK();
-	return;
+	goto on_return;
     }
 
@@ -2971,6 +3005,5 @@
 	 */
 	/*pjsua_media_channel_deinit(call->index);*/
-	PJSUA_UNLOCK();
-	return;
+	goto on_return;
     }
 
@@ -2985,6 +3018,7 @@
 	pjsua_var.ua_cfg.cb.on_call_media_state(call->index);
 
-
+on_return:
     PJSUA_UNLOCK();
+    pj_log_pop_indent();
 }
 
@@ -3105,4 +3139,5 @@
     PJ_LOG(4,(THIS_FILE, "Call %d: received updated media offer",
 	      call->index));
+    pj_log_push_indent();
 
     status = pjsua_media_channel_create_sdp(call->index, 
@@ -3111,6 +3146,5 @@
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to create local SDP", status);
-	PJSUA_UNLOCK();
-	return;
+	goto on_return;
     }
 
@@ -3155,9 +3189,10 @@
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to set answer", status);
-	PJSUA_UNLOCK();
-	return;
-    }
-
+	goto on_return;
+    }
+
+on_return:
     PJSUA_UNLOCK();
+    pj_log_pop_indent();
 }
 
@@ -3172,4 +3207,5 @@
     pj_status_t status;
 
+    pj_log_push_indent();
     PJSUA_LOCK();
 
@@ -3193,9 +3229,10 @@
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to create local SDP", status);
-	PJSUA_UNLOCK();
-	return;
-    }
-
+	goto on_return;
+    }
+
+on_return:
     PJSUA_UNLOCK();
+    pj_log_pop_indent();
 }
 
@@ -3209,4 +3246,6 @@
     
     PJ_UNUSED_ARG(event);
+
+    pj_log_push_indent();
 
     /*
@@ -3297,5 +3336,5 @@
 	if (!call || !event || !pjsua_var.ua_cfg.cb.on_call_transfer_status) {
 	    /* Application is not interested with call progress status */
-	    return;
+	    goto on_return;
 	}
 
@@ -3314,5 +3353,5 @@
 		PJ_LOG(2,(THIS_FILE, 
 			  "Warning: received NOTIFY without message body"));
-		return;
+		goto on_return;
 	    }
 
@@ -3324,5 +3363,5 @@
 			  "Warning: received NOTIFY with non message/sipfrag "
 			  "content"));
-		return;
+		goto on_return;
 	    }
 
@@ -3334,5 +3373,5 @@
 			  "Warning: received NOTIFY with invalid "
 			  "message/sipfrag content"));
-		return;
+		goto on_return;
 	    }
 
@@ -3366,4 +3405,7 @@
 	}
     }
+
+on_return:
+    pj_log_pop_indent();
 }
 
@@ -3375,6 +3417,7 @@
 static void xfer_server_on_evsub_state( pjsip_evsub *sub, pjsip_event *event)
 {
-    
     PJ_UNUSED_ARG(event);
+
+    pj_log_push_indent();
 
     /*
@@ -3387,5 +3430,5 @@
 	call = (pjsua_call*) pjsip_evsub_get_mod_data(sub, pjsua_var.mod.id);
 	if (!call)
-	    return;
+	    goto on_return;
 
 	pjsip_evsub_set_mod_data(sub, pjsua_var.mod.id, NULL);
@@ -3394,4 +3437,7 @@
 	PJ_LOG(4,(THIS_FILE, "Xfer server subscription terminated"));
     }
+
+on_return:
+    pj_log_pop_indent();
 }
 
@@ -3420,4 +3466,6 @@
     pjsip_evsub *sub;
 
+    pj_log_push_indent();
+
     existing_call = (pjsua_call*) inv->dlg->mod_data[pjsua_var.mod.id];
 
@@ -3432,5 +3480,5 @@
 	PJ_LOG(4,(THIS_FILE, "Received REFER without Refer-To header!"));
 	pjsip_dlg_respond( inv->dlg, rdata, 400, NULL, NULL, NULL);
-	return;
+	goto on_return;
     }
 
@@ -3463,5 +3511,5 @@
 	/* Application rejects call transfer request */
 	pjsip_dlg_respond( inv->dlg, rdata, code, NULL, NULL, NULL);
-	return;
+	goto on_return;
     }
 
@@ -3485,5 +3533,5 @@
 	    pjsua_perror(THIS_FILE, "Unable to create 2xx response to REFER",
 			 status);
-	    return;
+	    goto on_return;
 	}
 
@@ -3501,5 +3549,5 @@
 	    pjsua_perror(THIS_FILE, "Unable to create 2xx response to REFER",
 			 status);
-	    return;
+	    goto on_return;
 	}
 
@@ -3523,5 +3571,5 @@
 	    pjsua_perror(THIS_FILE, "Unable to create xfer uas", status);
 	    pjsip_dlg_respond( inv->dlg, rdata, 500, NULL, NULL, NULL);
-	    return;
+	    goto on_return;
 	}
 
@@ -3550,5 +3598,5 @@
 	    pjsua_perror(THIS_FILE, "Unable to create NOTIFY to REFER", 
 			 status);
-	    return;
+	    goto on_return;
 	}
 
@@ -3557,5 +3605,5 @@
 	if (status != PJ_SUCCESS) {
 	    pjsua_perror(THIS_FILE, "Unable to send NOTIFY to REFER", status);
-	    return;
+	    goto on_return;
 	}
     }
@@ -3595,5 +3643,5 @@
 		pjsua_perror(THIS_FILE, "Unable to create NOTIFY to REFER", 
 			      status);
-		return;
+		goto on_return;
 	    }
 	    status = pjsip_xfer_send_request(sub, tdata);
@@ -3601,8 +3649,8 @@
 		pjsua_perror(THIS_FILE, "Unable to send NOTIFY to REFER", 
 			      status);
-		return;
+		goto on_return;
 	    }
 	}
-	return;
+	goto on_return;
     }
 
@@ -3618,4 +3666,7 @@
 				 &pjsua_var.calls[new_call]);
     }
+
+on_return:
+    pj_log_pop_indent();
 }
 
@@ -3634,12 +3685,11 @@
     pjsua_call *call;
 
+    pj_log_push_indent();
     PJSUA_LOCK();
 
     call = (pjsua_call*) inv->dlg->mod_data[pjsua_var.mod.id];
 
-    if (call == NULL) {
-	PJSUA_UNLOCK();
-	return;
-    }
+    if (call == NULL)
+	goto on_return;
 
     if (call->inv == NULL) {
@@ -3649,6 +3699,5 @@
 	 * receive another REFER for this call.
 	 */
-	PJSUA_UNLOCK();
-	return;
+	goto on_return;
     }
 
@@ -3695,6 +3744,5 @@
 	    pjsip_dlg_respond( inv->dlg, rdata, PJSIP_SC_NOT_ACCEPTABLE_HERE, 
 			       NULL, &hdr_list, NULL );
-	    PJSUA_UNLOCK();
-	    return;
+	    goto on_return;
 	}
 
@@ -3731,6 +3779,7 @@
     }
 
-
+on_return:
     PJSUA_UNLOCK();
+    pj_log_pop_indent();
 }
 
@@ -3744,4 +3793,5 @@
     pjsip_redirect_op op;
 
+    pj_log_push_indent();
     PJSUA_LOCK();
 
@@ -3758,4 +3808,5 @@
 
     PJSUA_UNLOCK();
+    pj_log_pop_indent();
 
     return op;
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c	(revision 3752)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c	(revision 3753)
@@ -84,5 +84,6 @@
     cfg->decor = PJ_LOG_HAS_SENDER | PJ_LOG_HAS_TIME | 
 		 PJ_LOG_HAS_MICRO_SEC | PJ_LOG_HAS_NEWLINE |
-		 PJ_LOG_HAS_SPACE;
+		 PJ_LOG_HAS_SPACE | PJ_LOG_HAS_THREAD_SWC |
+		 PJ_LOG_HAS_INDENT;
 #if defined(PJ_WIN32) && PJ_WIN32 != 0
     cfg->decor |= PJ_LOG_HAS_COLOR;
@@ -629,4 +630,6 @@
     PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
 
+    pj_log_push_indent();
+
     /* Init random seed */
     init_random_seed();
@@ -660,4 +663,5 @@
 				       &pjsua_var.mutex);
     if (status != PJ_SUCCESS) {
+	pj_log_pop_indent();
 	pjsua_perror(THIS_FILE, "Unable to create mutex", status);
 	return status;
@@ -673,5 +677,5 @@
 
     pjsua_set_state(PJSUA_STATE_CREATED);
-
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 }
@@ -694,4 +698,5 @@
     pj_status_t status;
 
+    pj_log_push_indent();
 
     /* Create default configurations when the config is not supplied */
@@ -711,5 +716,5 @@
 	status = pjsua_reconfigure_logging(log_cfg);
 	if (status != PJ_SUCCESS)
-	    return status;
+	    goto on_error;
     }
 
@@ -735,5 +740,5 @@
 	if (status != PJ_SUCCESS) {
 	    pjsua_perror(THIS_FILE, "Error creating resolver", status);
-	    return status;
+	    goto on_error;
 	}
 
@@ -744,5 +749,5 @@
 	if (status != PJ_SUCCESS) {
 	    pjsua_perror(THIS_FILE, "Error setting nameserver", status);
-	    return status;
+	    goto on_error;
 	}
 
@@ -751,5 +756,5 @@
 	if (status != PJ_SUCCESS) {
 	    pjsua_perror(THIS_FILE, "Error setting DNS resolver", status);
-	    return status;
+	    goto on_error;
 	}
 
@@ -833,5 +838,6 @@
 	    pjsua_perror(THIS_FILE, "Invalid outbound proxy URI",
 			 PJSIP_EINVALIDURI);
-	    return PJSIP_EINVALIDURI;
+	    status = PJSIP_EINVALIDURI;
+	    goto on_error;
 	}
 
@@ -841,5 +847,6 @@
 		!PJSIP_URI_SCHEME_IS_SIP(r->name_addr.uri))
 	    {
-		return PJSIP_EINVALIDSCHEME;
+		status = PJSIP_EINVALIDSCHEME;
+		goto on_error;
 	    }
 	    sip_url = (pjsip_sip_uri*)r->name_addr.uri;
@@ -872,5 +879,5 @@
     if (status != PJ_SUCCESS && status != PJ_EPENDING) {
 	pjsua_perror(THIS_FILE, "Error resolving STUN server", status);
-	return status;
+	goto on_error;
     }
 
@@ -942,9 +949,10 @@
 
     pjsua_set_state(PJSUA_STATE_INIT);
-
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 
 on_error:
     pjsua_destroy();
+    pj_log_pop_indent();
     return status;
 }
@@ -1323,4 +1331,6 @@
 	PJ_LOG(4,(THIS_FILE, "Shutting down..."));
 
+	pj_log_push_indent();
+
 	/* Terminate all calls. */
 	pjsua_call_hangup_all();
@@ -1478,4 +1488,6 @@
 	}
 
+	pj_log_pop_indent();
+
 	/* Shutdown PJLIB */
 	pj_shutdown();
@@ -1524,20 +1536,23 @@
 
     pjsua_set_state(PJSUA_STATE_STARTING);
+    pj_log_push_indent();
 
     status = pjsua_call_subsys_start();
     if (status != PJ_SUCCESS)
-	return status;
+	goto on_return;
 
     status = pjsua_media_subsys_start();
     if (status != PJ_SUCCESS)
-	return status;
+	goto on_return;
 
     status = pjsua_pres_start();
     if (status != PJ_SUCCESS)
-	return status;
+	goto on_return;
 
     pjsua_set_state(PJSUA_STATE_RUNNING);
 
-    return PJ_SUCCESS;
+on_return:
+    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 3752)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c	(revision 3753)
@@ -73,4 +73,6 @@
     PJ_UNUSED_ARG(codec_id);
 
+    pj_log_push_indent();
+
     /* Specify which audio device settings are save-able */
     pjsua_var.aud_svmask = 0xFFFFFFFF;
@@ -111,5 +113,5 @@
 		     "Media stack initialization has returned error", 
 		     status);
-	return status;
+	goto on_error;
     }
 
@@ -138,5 +140,5 @@
 		pjsua_perror(THIS_FILE, "Error querying audio device info",
 			     status);
-		return status;
+		goto on_error;
 	    }
 	    
@@ -175,5 +177,5 @@
     if (status != PJ_SUCCESS) {
 	PJ_PERROR(1,(THIS_FILE, status, "Error registering codecs"));
-	return status;
+	goto on_error;
     }
 
@@ -229,5 +231,5 @@
 	pjsua_perror(THIS_FILE, "Error creating conference bridge", 
 		     status);
-	return status;
+	goto on_error;
     }
 
@@ -251,5 +253,5 @@
 	pjsua_perror(THIS_FILE, "Error initializing SRTP library", 
 		     status);
-	return status;
+	goto on_error;
     }
 #endif
@@ -259,8 +261,13 @@
     status = pjsua_vid_subsys_init();
     if (status != PJ_SUCCESS)
-	return status;
+	goto on_error;
 #endif
 
+    pj_log_pop_indent();
     return PJ_SUCCESS;
+
+on_error:
+    pj_log_pop_indent();
+    return status;
 }
 
@@ -345,4 +352,6 @@
     pj_status_t status;
 
+    pj_log_push_indent();
+
 #if DISABLED_FOR_TICKET_1185
     /* Create media for calls, if none is specified */
@@ -355,6 +364,8 @@
 
 	status = pjsua_media_transports_create(&transport_cfg);
-	if (status != PJ_SUCCESS)
+	if (status != PJ_SUCCESS) {
+	    pj_log_pop_indent();
 	    return status;
+	}
     }
 #endif
@@ -366,6 +377,8 @@
 #if PJMEDIA_HAS_VIDEO
     status = pjsua_vid_subsys_start();
-    if (status != PJ_SUCCESS)
+    if (status != PJ_SUCCESS) {
+	pj_log_pop_indent();
 	return status;
+    }
 #endif
 
@@ -376,4 +389,5 @@
     }
 
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 }
@@ -388,4 +402,5 @@
 
     PJ_LOG(4,(THIS_FILE, "Shutting down media.."));
+    pj_log_push_indent();
 
     close_snd_dev();
@@ -451,4 +466,6 @@
     /* Reset RTP port */
     next_rtp_port = 0;
+
+    pj_log_pop_indent();
 
     return PJ_SUCCESS;
@@ -1364,4 +1381,7 @@
 	return PJ_EBUSY;
 
+    PJ_LOG(4,(THIS_FILE, "Call %d: initializing media..", call_id));
+    pj_log_push_indent();
+
 #if DISABLED_FOR_TICKET_1185
     /* Return error if media transport has not been created yet
@@ -1370,5 +1390,6 @@
     for (i=0; i<call->med_cnt; ++i) {
 	if (call->media[i].tp == NULL) {
-	    return PJ_EBUSY;
+	    status = PJ_EBUSY;
+	    goto on_error;
 	}
     }
@@ -1386,5 +1407,6 @@
 	    if (sip_err_code) *sip_err_code = PJSIP_SC_NOT_ACCEPTABLE_HERE;
 	    pjsua_media_channel_deinit(call_id);
-	    return PJSIP_ERRNO_FROM_SIP_STATUS(PJSIP_SC_NOT_ACCEPTABLE_HERE);
+	    status = PJSIP_ERRNO_FROM_SIP_STATUS(PJSIP_SC_NOT_ACCEPTABLE_HERE);
+	    goto on_error;
 	}
 
@@ -1426,5 +1448,6 @@
 	if (sip_err_code) *sip_err_code = PJSIP_SC_NOT_ACCEPTABLE_HERE;
 	pjsua_media_channel_deinit(call_id);
-	return PJSIP_ERRNO_FROM_SIP_STATUS(PJSIP_SC_NOT_ACCEPTABLE_HERE);
+	status = PJSIP_ERRNO_FROM_SIP_STATUS(PJSIP_SC_NOT_ACCEPTABLE_HERE);
+	goto on_error;
     }
 
@@ -1463,5 +1486,5 @@
 	    if (status != PJ_SUCCESS) {
 		pjsua_media_channel_deinit(call_id);
-		return status;
+		goto on_error;
 	    }
 	} else {
@@ -1501,5 +1524,5 @@
 		if (sip_err_code) *sip_err_code = PJSIP_SC_NOT_ACCEPTABLE;
 		pjsua_media_channel_deinit(call_id);
-		return status;
+		goto on_error;
 	    }
 
@@ -1508,5 +1531,10 @@
     }
 
+    pj_log_pop_indent();
     return PJ_SUCCESS;
+
+on_error:
+    pj_log_pop_indent();
+    return status;
 }
 
@@ -1791,4 +1819,6 @@
     unsigned mi;
 
+    pj_log_push_indent();
+
     for (mi=0; mi<call->med_cnt; ++mi) {
 	pjsua_call_media *call_med = &call->media[mi];
@@ -1839,4 +1869,6 @@
 	call_med->state = PJSUA_CALL_MEDIA_NONE;
     }
+
+    pj_log_pop_indent();
 }
 
@@ -1845,4 +1877,7 @@
     pjsua_call *call = &pjsua_var.calls[call_id];
     unsigned mi;
+
+    PJ_LOG(4,(THIS_FILE, "Call %d: deinitializing media..", call_id));
+    pj_log_push_indent();
 
     stop_media_session(call_id);
@@ -1869,4 +1904,5 @@
 
     check_snd_dev_idle();
+    pj_log_pop_indent();
 
     return PJ_SUCCESS;
@@ -1881,4 +1917,6 @@
 {
     PJ_UNUSED_ARG(strm);
+
+    pj_log_push_indent();
 
     /* For discussions about call mutex protection related to this 
@@ -1892,4 +1930,6 @@
 	pjsua_var.ua_cfg.cb.on_dtmf_digit(call_id, digit);
     }
+
+    pj_log_pop_indent();
 }
 
@@ -1905,9 +1945,12 @@
     unsigned strm_idx = call_med->idx;
     pj_status_t status;
+
+    PJ_LOG(4,(THIS_FILE,"Audio channel update.."));
+    pj_log_push_indent();
     
     status = pjmedia_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_return;
 
     /* Check if no media is active */
@@ -1927,5 +1970,5 @@
 					       remote_sdp, strm_idx);
 	if (status != PJ_SUCCESS)
-	    return status;
+	    goto on_return;
 
 	call_med->tp_st = PJSUA_MED_TP_RUNNING;
@@ -1992,5 +2035,5 @@
 				       &call_med->strm.a.stream);
 	if (status != PJ_SUCCESS) {
-	    return status;
+	    goto on_return;
 	}
 
@@ -1998,5 +2041,5 @@
 	status = pjmedia_stream_start(call_med->strm.a.stream);
 	if (status != PJ_SUCCESS) {
-	    return status;
+	    goto on_return;
 	}
 
@@ -2046,5 +2089,5 @@
 					    &call_med->strm.a.conf_slot);
 	    if (status != PJ_SUCCESS) {
-		return status;
+		goto on_return;
 	    }
 	}
@@ -2093,8 +2136,10 @@
 	if (len > 0)
 	    info_len += len;
-	PJ_LOG(4,(THIS_FILE,"Media updates%s", info));
-    }
-
-    return PJ_SUCCESS;
+	PJ_LOG(4,(THIS_FILE,"Audio updated%s", info));
+    }
+
+on_return:
+    pj_log_pop_indent();
+    return status;
 }
 
@@ -2120,4 +2165,7 @@
     if (pjsua_get_state() != PJSUA_STATE_RUNNING)
 	return PJ_EBUSY;
+
+    PJ_LOG(4,(THIS_FILE, "Call %d: updating media..", call_id));
+    pj_log_push_indent();
 
     /* Destroy existing media session, if any. */
@@ -2183,5 +2231,6 @@
 	    PJ_LOG(1,(THIS_FILE, "Error updating media for call %d: "
 		      "invalid media index %d in SDP", call_id, mi));
-	    return PJMEDIA_SDP_EINSDP;
+	    status = PJMEDIA_SDP_EINSDP;
+	    goto on_error;
 #endif
 	}
@@ -2236,16 +2285,21 @@
 	status = pjmedia_sdp_neg_set_remote_offer(tmp_pool, neg, remote_sdp);
 	if (status != PJ_SUCCESS)
-	    return status;
+	    goto on_error;
 
 	status = pjmedia_sdp_neg_set_local_answer(tmp_pool, neg, local_sdp);
 	if (status != PJ_SUCCESS)
-	    return status;
+	    goto on_error;
 
 	status = pjmedia_sdp_neg_negotiate(tmp_pool, neg, 0);
 	if (status != PJ_SUCCESS)
-	    return status;
-    }
-
+	    goto on_error;
+    }
+
+    pj_log_pop_indent();
     return (got_media? PJ_SUCCESS : PJMEDIA_SDPNEG_ENOMEDIA);
+
+on_error:
+    pj_log_pop_indent();
+    return status;
 }
 
@@ -2358,4 +2412,11 @@
 					pjsua_conf_port_id sink)
 {
+    pj_status_t status = PJ_SUCCESS;
+
+    PJ_LOG(4,(THIS_FILE, "%s connect: %d --> %d",
+	      (pjsua_var.is_mswitch ? "Switch" : "Conf"),
+	      source, sink));
+    pj_log_push_indent();
+
     /* If sound device idle timer is active, cancel it first. */
     PJSUA_LOCK();
@@ -2378,5 +2439,4 @@
 	unsigned peer_id;
 	pj_bool_t need_reopen = PJ_FALSE;
-	pj_status_t status;
 
 	peer_id = (source!=0)? source : sink;
@@ -2420,5 +2480,5 @@
 		    pjsua_perror(THIS_FILE, "Error opening sound device",
 				 status);
-		    return status;
+		    goto on_return;
 		}
 
@@ -2434,5 +2494,5 @@
 		    pjsua_perror(THIS_FILE, "Error opening sound device",
 				 status);
-		    return status;
+		    goto on_return;
 		}
 	    } else {
@@ -2443,5 +2503,5 @@
 		    pjsua_perror(THIS_FILE, "Error opening sound device",
 				 status);
-		    return status;
+		    goto on_return;
 		}
 	    }
@@ -2468,5 +2528,5 @@
 	    if (status != PJ_SUCCESS) {
 		pjsua_perror(THIS_FILE, "Error opening sound device", status);
-		return status;
+		goto on_return;
 	    }
 	} else if (pjsua_var.no_snd && !pjsua_var.snd_is_on) {
@@ -2479,5 +2539,9 @@
     }
 
-    return pjmedia_conf_connect_port(pjsua_var.mconf, source, sink, 0);
+    status = pjmedia_conf_connect_port(pjsua_var.mconf, source, sink, 0);
+
+on_return:
+    pj_log_pop_indent();
+    return status;
 }
 
@@ -2491,7 +2555,13 @@
     pj_status_t status;
 
+    PJ_LOG(4,(THIS_FILE, "%s disconnect: %d -x- %d",
+	      (pjsua_var.is_mswitch ? "Switch" : "Conf"),
+	      source, sink));
+    pj_log_push_indent();
+
     status = pjmedia_conf_disconnect_port(pjsua_var.mconf, source, sink);
     check_snd_dev_idle();
 
+    pj_log_pop_indent();
     return status;
 }
@@ -2559,10 +2629,14 @@
     unsigned slot, file_id;
     char path[PJ_MAXPATH];
-    pj_pool_t *pool;
+    pj_pool_t *pool = NULL;
     pjmedia_port *port;
-    pj_status_t status;
+    pj_status_t status = PJ_SUCCESS;
 
     if (pjsua_var.player_cnt >= PJ_ARRAY_SIZE(pjsua_var.player))
 	return PJ_ETOOMANY;
+
+    PJ_LOG(4,(THIS_FILE, "Creating file player: %.*s..",
+	      (int)filename->slen, filename->ptr));
+    pj_log_push_indent();
 
     PJSUA_LOCK();
@@ -2575,7 +2649,7 @@
     if (file_id == PJ_ARRAY_SIZE(pjsua_var.player)) {
 	/* This is unexpected */
-	PJSUA_UNLOCK();
 	pj_assert(0);
-	return PJ_EBUG;
+	status = PJ_EBUG;
+	goto on_error;
     }
 
@@ -2585,6 +2659,6 @@
     pool = pjsua_pool_create(get_basename(path, filename->slen), 1000, 1000);
     if (!pool) {
-	PJSUA_UNLOCK();
-	return PJ_ENOMEM;
+	status = PJ_ENOMEM;
+	goto on_error;
     }
 
@@ -2596,8 +2670,6 @@
 				    options, 0, &port);
     if (status != PJ_SUCCESS) {
-	PJSUA_UNLOCK();
 	pjsua_perror(THIS_FILE, "Unable to open file for playback", status);
-	pj_pool_release(pool);
-	return status;
+	goto on_error;
     }
 
@@ -2606,9 +2678,7 @@
     if (status != PJ_SUCCESS) {
 	pjmedia_port_destroy(port);
-	PJSUA_UNLOCK();
 	pjsua_perror(THIS_FILE, "Unable to add file to conference bridge", 
 		     status);
-	pj_pool_release(pool);
-	return status;
+	goto on_error;
     }
 
@@ -2623,5 +2693,15 @@
 
     PJSUA_UNLOCK();
+
+    PJ_LOG(4,(THIS_FILE, "Player created, id=%d, slot=%d", file_id, slot));
+
+    pj_log_pop_indent();
     return PJ_SUCCESS;
+
+on_error:
+    PJSUA_UNLOCK();
+    if (pool) pj_pool_release(pool);
+    pj_log_pop_indent();
+    return status;
 }
 
@@ -2638,10 +2718,13 @@
 {
     unsigned slot, file_id, ptime;
-    pj_pool_t *pool;
+    pj_pool_t *pool = NULL;
     pjmedia_port *port;
-    pj_status_t status;
+    pj_status_t status = PJ_SUCCESS;
 
     if (pjsua_var.player_cnt >= PJ_ARRAY_SIZE(pjsua_var.player))
 	return PJ_ETOOMANY;
+
+    PJ_LOG(4,(THIS_FILE, "Creating playlist with %d file(s)..", file_count));
+    pj_log_push_indent();
 
     PJSUA_LOCK();
@@ -2654,7 +2737,7 @@
     if (file_id == PJ_ARRAY_SIZE(pjsua_var.player)) {
 	/* This is unexpected */
-	PJSUA_UNLOCK();
 	pj_assert(0);
-	return PJ_EBUG;
+	status = PJ_EBUG;
+	goto on_error;
     }
 
@@ -2665,6 +2748,6 @@
     pool = pjsua_pool_create("playlist", 1000, 1000);
     if (!pool) {
-	PJSUA_UNLOCK();
-	return PJ_ENOMEM;
+	status = PJ_ENOMEM;
+	goto on_error;
     }
 
@@ -2673,8 +2756,6 @@
 					 ptime, options, 0, &port);
     if (status != PJ_SUCCESS) {
-	PJSUA_UNLOCK();
 	pjsua_perror(THIS_FILE, "Unable to create playlist", status);
-	pj_pool_release(pool);
-	return status;
+	goto on_error;
     }
 
@@ -2683,8 +2764,6 @@
     if (status != PJ_SUCCESS) {
 	pjmedia_port_destroy(port);
-	PJSUA_UNLOCK();
 	pjsua_perror(THIS_FILE, "Unable to add port", status);
-	pj_pool_release(pool);
-	return status;
+	goto on_error;
     }
 
@@ -2699,6 +2778,17 @@
 
     PJSUA_UNLOCK();
+
+    PJ_LOG(4,(THIS_FILE, "Playlist created, id=%d, slot=%d", file_id, slot));
+
+    pj_log_pop_indent();
+
     return PJ_SUCCESS;
 
+on_error:
+    PJSUA_UNLOCK();
+    if (pool) pj_pool_release(pool);
+    pj_log_pop_indent();
+
+    return status;
 }
 
@@ -2752,4 +2842,7 @@
     PJ_ASSERT_RETURN(id>=0&&id<(int)PJ_ARRAY_SIZE(pjsua_var.player), PJ_EINVAL);
     PJ_ASSERT_RETURN(pjsua_var.player[id].port != NULL, PJ_EINVAL);
+
+    PJ_LOG(4,(THIS_FILE, "Destroying player %d..", id));
+    pj_log_push_indent();
 
     PJSUA_LOCK();
@@ -2766,4 +2859,5 @@
 
     PJSUA_UNLOCK();
+    pj_log_pop_indent();
 
     return PJ_SUCCESS;
@@ -2796,7 +2890,7 @@
     pj_str_t ext;
     int file_format;
-    pj_pool_t *pool;
+    pj_pool_t *pool = NULL;
     pjmedia_port *port;
-    pj_status_t status;
+    pj_status_t status = PJ_SUCCESS;
 
     /* Filename must present */
@@ -2809,6 +2903,12 @@
     PJ_ASSERT_RETURN(enc_type == 0, PJ_EINVAL);
 
-    if (pjsua_var.rec_cnt >= PJ_ARRAY_SIZE(pjsua_var.recorder))
+    PJ_LOG(4,(THIS_FILE, "Creating recorder %.*s..",
+	      (int)filename->slen, filename->ptr));
+    pj_log_push_indent();
+
+    if (pjsua_var.rec_cnt >= PJ_ARRAY_SIZE(pjsua_var.recorder)) {
+	pj_log_pop_indent();
 	return PJ_ETOOMANY;
+    }
 
     /* Determine the file format */
@@ -2824,4 +2924,5 @@
 			     "determine file format for %.*s",
 			     (int)filename->slen, filename->ptr));
+	pj_log_pop_indent();
 	return PJ_ENOTSUP;
     }
@@ -2836,7 +2937,7 @@
     if (file_id == PJ_ARRAY_SIZE(pjsua_var.recorder)) {
 	/* This is unexpected */
-	PJSUA_UNLOCK();
 	pj_assert(0);
-	return PJ_EBUG;
+	status = PJ_EBUG;
+	goto on_return;
     }
 
@@ -2846,6 +2947,6 @@
     pool = pjsua_pool_create(get_basename(path, filename->slen), 1000, 1000);
     if (!pool) {
-	PJSUA_UNLOCK();
-	return PJ_ENOMEM;
+	status = PJ_ENOMEM;
+	goto on_return;
     }
 
@@ -2864,8 +2965,6 @@
 
     if (status != PJ_SUCCESS) {
-	PJSUA_UNLOCK();
 	pjsua_perror(THIS_FILE, "Unable to open file for recording", status);
-	pj_pool_release(pool);
-	return status;
+	goto on_return;
     }
 
@@ -2874,7 +2973,5 @@
     if (status != PJ_SUCCESS) {
 	pjmedia_port_destroy(port);
-	PJSUA_UNLOCK();
-	pj_pool_release(pool);
-	return status;
+	goto on_return;
     }
 
@@ -2888,5 +2985,15 @@
 
     PJSUA_UNLOCK();
+
+    PJ_LOG(4,(THIS_FILE, "Recorder created, id=%d, slot=%d", file_id, slot));
+
+    pj_log_pop_indent();
     return PJ_SUCCESS;
+
+on_return:
+    PJSUA_UNLOCK();
+    if (pool) pj_pool_release(pool);
+    pj_log_pop_indent();
+    return status;
 }
 
@@ -2927,4 +3034,7 @@
 		     PJ_EINVAL);
     PJ_ASSERT_RETURN(pjsua_var.recorder[id].port != NULL, PJ_EINVAL);
+
+    PJ_LOG(4,(THIS_FILE, "Destroying recorder %d..", id));
+    pj_log_push_indent();
 
     PJSUA_LOCK();
@@ -2941,4 +3051,5 @@
 
     PJSUA_UNLOCK();
+    pj_log_pop_indent();
 
     return PJ_SUCCESS;
@@ -3148,9 +3259,10 @@
 	      param->base.samples_per_frame / param->base.channel_count *
 	      1000 / param->base.clock_rate));
+    pj_log_push_indent();
 
     status = pjmedia_snd_port_create2( pjsua_var.snd_pool, 
 				       param, &pjsua_var.snd_port);
     if (status != PJ_SUCCESS)
-	return status;
+	goto on_error;
 
     /* Get the port0 of the conference bridge. */
@@ -3189,5 +3301,5 @@
 		       errmsg));
 	    close_snd_dev();
-	    return status;
+	    goto on_error;
 	} 
 	    
@@ -3218,5 +3330,5 @@
 	pjmedia_snd_port_destroy(pjsua_var.snd_port); 	 
 	pjsua_var.snd_port = NULL; 	 
-	return status; 	 
+	goto on_error;
     }
 
@@ -3256,5 +3368,5 @@
 	/* Any error is not major, let it through */
 	status = PJ_SUCCESS;
-    };
+    }
 
     /* If this is the first time the audio device is open, retrieve some
@@ -3267,5 +3379,10 @@
     }
 
+    pj_log_pop_indent();
     return PJ_SUCCESS;
+
+on_error:
+    pj_log_pop_indent();
+    return status;
 }
 
@@ -3274,4 +3391,6 @@
 static void close_snd_dev(void)
 {
+    pj_log_push_indent();
+
     /* Notify app */
     if (pjsua_var.snd_is_on && pjsua_var.ua_cfg.cb.on_snd_dev_operation) {
@@ -3313,4 +3432,6 @@
     pjsua_var.snd_pool = NULL;
     pjsua_var.snd_is_on = PJ_FALSE;
+
+    pj_log_pop_indent();
 }
 
@@ -3328,7 +3449,13 @@
     pj_status_t status = -1;
 
+    PJ_LOG(4,(THIS_FILE, "Set sound device: capture=%d, playback=%d",
+	      capture_dev, playback_dev));
+    pj_log_push_indent();
+
     /* Null-sound */
     if (capture_dev==NULL_SND_DEV_ID && playback_dev==NULL_SND_DEV_ID) {
-	return pjsua_set_null_snd_dev();
+	status = pjsua_set_null_snd_dev();
+	pj_log_pop_indent();
+	return status;
     }
 
@@ -3361,5 +3488,5 @@
 				  samples_per_frame, 16);
 	if (status != PJ_SUCCESS)
-	    return status;
+	    goto on_error;
 
 	/* Open! */
@@ -3372,5 +3499,5 @@
     if (status != PJ_SUCCESS) {
 	pjsua_perror(THIS_FILE, "Unable to open sound device", status);
-	return status;
+	goto on_error;
     }
 
@@ -3378,5 +3505,10 @@
     pjsua_var.snd_is_on = PJ_TRUE;
 
+    pj_log_pop_indent();
     return PJ_SUCCESS;
+
+on_error:
+    pj_log_pop_indent();
+    return status;
 }
 
@@ -3408,4 +3540,8 @@
     pjmedia_port *conf_port;
     pj_status_t status;
+
+    PJ_LOG(4,(THIS_FILE, "Setting null sound device.."));
+    pj_log_push_indent();
+
 
     /* Close existing sound device */
@@ -3435,4 +3571,5 @@
 	pjsua_perror(THIS_FILE, "Unable to create null sound device",
 		     status);
+	pj_log_pop_indent();
 	return status;
     }
@@ -3448,4 +3585,5 @@
     pjsua_var.snd_is_on = PJ_TRUE;
 
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 }
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c	(revision 3752)
+++ /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c	(revision 3753)
@@ -390,4 +390,8 @@
 		     PJ_ETOOMANY);
 
+    PJ_LOG(4,(THIS_FILE, "Adding buddy: %.*s",
+	      (int)cfg->uri.slen, cfg->uri.ptr));
+    pj_log_push_indent();
+
     PJSUA_LOCK();
 
@@ -403,4 +407,5 @@
 	/* This shouldn't happen */
 	pj_assert(!"index < PJ_ARRAY_SIZE(pjsua_var.buddy)");
+	pj_log_pop_indent();
 	return PJ_ETOOMANY;
     }
@@ -432,4 +437,5 @@
 	buddy->pool = NULL;
 	PJSUA_UNLOCK();
+	pj_log_pop_indent();
 	return PJSIP_EINVALIDURI;
     }
@@ -440,4 +446,5 @@
 	buddy->pool = NULL;
 	PJSUA_UNLOCK();
+	pj_log_pop_indent();
 	return PJSIP_EINVALIDSCHEME;
     }
@@ -470,6 +477,9 @@
     PJSUA_UNLOCK();
 
+    PJ_LOG(4,(THIS_FILE, "Buddy %d added.", index));
+
     pjsua_buddy_subscribe_pres(index, cfg->subscribe);
 
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 }
@@ -495,4 +505,7 @@
     if (status != PJ_SUCCESS)
 	return status;
+
+    PJ_LOG(4,(THIS_FILE, "Buddy %d: deleting..", buddy_id));
+    pj_log_push_indent();
 
     /* Unsubscribe presence */
@@ -519,4 +532,5 @@
 
     unlock_buddy(&lck);
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 }
@@ -538,4 +552,7 @@
 	return status;
 
+    PJ_LOG(4,(THIS_FILE, "Buddy %d: unsubscribing presence..", buddy_id));
+    pj_log_push_indent();
+
     lck.buddy->monitor = subscribe;
 
@@ -543,4 +560,5 @@
 
     unlock_buddy(&lck);
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 }
@@ -560,4 +578,7 @@
     if (status != PJ_SUCCESS)
 	return status;
+
+    PJ_LOG(4,(THIS_FILE, "Buddy %d: updating presence..", buddy_id));
+    pj_log_push_indent();
 
     /* Is this an unsubscribe request? */
@@ -565,4 +586,5 @@
 	unsubscribe_buddy_presence(buddy_id);
 	unlock_buddy(&lck);
+	pj_log_pop_indent();
 	return PJ_SUCCESS;
     }
@@ -571,4 +593,5 @@
     if (lck.buddy->sub) {
 	unlock_buddy(&lck);
+	pj_log_pop_indent();
 	return PJ_SUCCESS;
     }
@@ -578,5 +601,5 @@
 
     unlock_buddy(&lck);
-
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 }
@@ -746,4 +769,5 @@
 	PJ_LOG(4,(THIS_FILE, "Server subscription to %s is %s",
 		  uapres->remote, pjsip_evsub_get_state_name(sub)));
+	pj_log_push_indent();
 
 	state = pjsip_evsub_get_state(sub);
@@ -762,4 +786,5 @@
 	    pj_list_erase(uapres);
 	}
+	pj_log_pop_indent();
     }
 
@@ -807,4 +832,5 @@
     PJ_LOG(4,(THIS_FILE, "Creating server subscription, using account %d",
 	      acc_id));
+    pj_log_push_indent();
     
     /* Create suitable Contact header */
@@ -820,4 +846,5 @@
 	    pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 400, NULL,
 					  NULL, NULL);
+	    pj_log_pop_indent();
 	    return PJ_TRUE;
 	}
@@ -834,4 +861,5 @@
 	pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 400, NULL,
 				      NULL, NULL);
+	pj_log_pop_indent();
 	return PJ_TRUE;
     }
@@ -865,4 +893,5 @@
 
 	PJSUA_UNLOCK();
+	pj_log_pop_indent();
 	return PJ_TRUE;
     }
@@ -935,4 +964,5 @@
 	    pjsip_pres_terminate(sub, PJ_FALSE);
 	    PJSUA_UNLOCK();
+	    pj_log_pop_indent();
 	    return PJ_FALSE;
 	}
@@ -953,4 +983,5 @@
 	pjsip_pres_terminate(sub, PJ_FALSE);
 	PJSUA_UNLOCK();
+	pj_log_pop_indent();
 	return PJ_TRUE;
     }
@@ -964,4 +995,5 @@
 	pjsip_pres_terminate(sub, PJ_FALSE);
 	PJSUA_UNLOCK();
+	pj_log_pop_indent();
 	return PJ_FALSE;
     }
@@ -976,5 +1008,5 @@
 
     PJSUA_UNLOCK();
-
+    pj_log_pop_indent();
     return PJ_TRUE;
 }
@@ -1007,4 +1039,8 @@
     PJ_ASSERT_RETURN(pjsua_var.acc[acc_id].valid, PJ_EINVALIDOP);
 
+    PJ_LOG(4,(THIS_FILE, "Acc %d: sending NOTIFY for srv_pres=0x%p..",
+	      acc_id, (int)(long)srv_pres));
+    pj_log_push_indent();
+
     PJSUA_LOCK();
 
@@ -1015,4 +1051,5 @@
 	/* Subscription has been terminated */
 	PJSUA_UNLOCK();
+	pj_log_pop_indent();
 	return PJ_EINVALIDOP;
     }
@@ -1056,4 +1093,5 @@
 	pjsip_pres_terminate(srv_pres->sub, PJ_FALSE);
 	PJSUA_UNLOCK();
+	pj_log_pop_indent();
 	return status;
     }
@@ -1072,5 +1110,5 @@
 
     PJSUA_UNLOCK();
-
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 }
@@ -1132,4 +1170,7 @@
     pj_status_t status;
 
+    PJ_LOG(5,(THIS_FILE, "Acc %d: sending %sPUBLISH..",
+	      acc_id, (active ? "" : "un-")));
+    pj_log_push_indent();
 
     /* Create PUBLISH request */
@@ -1200,4 +1241,5 @@
 
     acc->publish_state = acc->online_status;
+    pj_log_pop_indent();
     return PJ_SUCCESS;
 
@@ -1207,4 +1249,5 @@
 	acc->publish_sess = NULL;
     }
+    pj_log_pop_indent();
     return status;
 }
@@ -1455,4 +1498,5 @@
 		  pjsua_var.buddy[buddy->index].uri.ptr, 
 		  pjsip_evsub_get_state_name(sub)));
+	pj_log_push_indent();
 
 	if (pjsip_evsub_get_state(sub) == PJSIP_EVSUB_STATE_TERMINATED) {
@@ -1574,4 +1618,6 @@
 	    pjsip_evsub_set_mod_data(sub, pjsua_var.mod.id, NULL);
 	}
+
+	pj_log_pop_indent();
     }
 }
@@ -1685,6 +1731,7 @@
     acc = &pjsua_var.acc[acc_id];
 
-    PJ_LOG(4,(THIS_FILE, "Using account %d for buddy %d subscription",
-			 acc_id, buddy_id));
+    PJ_LOG(4,(THIS_FILE, "Buddy %d: subscribing presence,using account %d..",
+	      buddy_id, acc_id));
+    pj_log_push_indent();
 
     /* Generate suitable Contact header unless one is already set in
@@ -1702,4 +1749,5 @@
 		         status);
 	    pj_pool_release(tmp_pool);
+	    pj_log_pop_indent();
 	    return;
 	}
@@ -1716,4 +1764,5 @@
 		     status);
 	if (tmp_pool) pj_pool_release(tmp_pool);
+	pj_log_pop_indent();
 	return;
     }
@@ -1735,4 +1784,5 @@
 	if (buddy->dlg) pjsip_dlg_dec_lock(buddy->dlg);
 	if (tmp_pool) pj_pool_release(tmp_pool);
+	pj_log_pop_indent();
 	return;
     }
@@ -1774,4 +1824,5 @@
 		     status);
 	if (tmp_pool) pj_pool_release(tmp_pool);
+	pj_log_pop_indent();
 	return;
     }
@@ -1789,4 +1840,5 @@
 		     status);
 	if (tmp_pool) pj_pool_release(tmp_pool);
+	pj_log_pop_indent();
 	return;
     }
@@ -1794,4 +1846,5 @@
     pjsip_dlg_dec_lock(buddy->dlg);
     if (tmp_pool) pj_pool_release(tmp_pool);
+    pj_log_pop_indent();
 }
 
@@ -1813,4 +1866,7 @@
 	return;
     }
+
+    PJ_LOG(5,(THIS_FILE, "Buddy %d: unsubscribing..", buddy_id));
+    pj_log_push_indent();
 
     status = pjsip_pres_initiate( buddy->sub, 0, &tdata);
@@ -1826,4 +1882,6 @@
 		     status);
     }
+
+    pj_log_pop_indent();
 }
 
@@ -1915,8 +1973,13 @@
     mwi_info.rdata = rdata;
 
+    PJ_LOG(4,(THIS_FILE, "MWI got NOTIFY.."));
+    pj_log_push_indent();
+
     /* Call callback */
     if (pjsua_var.ua_cfg.cb.on_mwi_info) {
 	(*pjsua_var.ua_cfg.cb.on_mwi_info)(acc->index, &mwi_info);
     }
+
+    pj_log_pop_indent();
 }
 
@@ -1973,4 +2036,7 @@
 
     }
+
+    PJ_LOG(4,(THIS_FILE, "Starting MWI subscription.."));
+    pj_log_push_indent();
 
     /* Generate suitable Contact header unless one is already set in 
@@ -1987,4 +2053,5 @@
 		         status);
 	    pj_pool_release(tmp_pool);
+	    pj_log_pop_indent();
 	    return;
 	}
@@ -2000,4 +2067,5 @@
 	pjsua_perror(THIS_FILE, "Unable to create dialog", status);
 	if (tmp_pool) pj_pool_release(tmp_pool);
+	pj_log_pop_indent();
 	return;
     }
@@ -2015,4 +2083,5 @@
 	if (tmp_pool) pj_pool_release(tmp_pool);
 	if (acc->mwi_dlg) pjsip_dlg_dec_lock(acc->mwi_dlg);
+	pj_log_pop_indent();
 	return;
     }
@@ -2055,4 +2124,5 @@
 		     status);
 	if (tmp_pool) pj_pool_release(tmp_pool);
+	pj_log_pop_indent();
 	return;
     }
@@ -2071,4 +2141,5 @@
 		     status);
 	if (tmp_pool) pj_pool_release(tmp_pool);
+	pj_log_pop_indent();
 	return;
     }
@@ -2077,4 +2148,5 @@
     if (tmp_pool) pj_pool_release(tmp_pool);
 
+    pj_log_pop_indent();
 }
 
@@ -2106,4 +2178,8 @@
     }
 
+    PJ_LOG(4,(THIS_FILE, "Got unsolicited NOTIFY from %s:%d..",
+	      rdata->pkt_info.src_name, rdata->pkt_info.src_port));
+    pj_log_push_indent();
+
     /* Got unsolicited MWI request, respond with 200/OK first */
     pjsip_endpt_respond(pjsua_get_pjsip_endpt(), NULL, rdata, 200, NULL,
@@ -2124,5 +2200,5 @@
     }
 
-    
+    pj_log_pop_indent();
     return PJ_TRUE;
 }
@@ -2254,4 +2330,5 @@
 
     PJ_LOG(4,(THIS_FILE, "Shutting down presence.."));
+    pj_log_push_indent();
 
     if (pjsua_var.pres_timer.id != 0) {
@@ -2276,3 +2353,5 @@
 	    pjsua_pres_update_acc(i, PJ_FALSE);
     }
-}
+
+    pj_log_pop_indent();
+}
Index: /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c	(revision 3752)
+++ /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;
