Index: /pjproject/branches/1.x/pjmedia/include/pjmedia/transport_adapter_sample.h
===================================================================
--- /pjproject/branches/1.x/pjmedia/include/pjmedia/transport_adapter_sample.h	(revision 3803)
+++ /pjproject/branches/1.x/pjmedia/include/pjmedia/transport_adapter_sample.h	(revision 3804)
@@ -50,6 +50,8 @@
  * @param name		Optional name to identify this media transport
  *			for logging purposes.
- * @param transport	The underlying media transport to send and receive
- *			RTP/RTCP packets.
+ * @param base_tp	The base/underlying media transport to send and
+ * 			receive RTP/RTCP packets.
+ * @param del_base	Specify whether the base transport should also be
+ * 			destroyed when destroy() is called upon us.
  * @param p_tp		Pointer to receive the media transport instance.
  *
@@ -58,5 +60,6 @@
 PJ_DECL(pj_status_t) pjmedia_tp_adapter_create( pjmedia_endpt *endpt,
 					        const char *name,
-					        pjmedia_transport *transport,
+					        pjmedia_transport *base_tp,
+					        pj_bool_t del_base,
 						pjmedia_transport **p_tp);
 
Index: /pjproject/branches/1.x/pjmedia/src/pjmedia/transport_adapter_sample.c
===================================================================
--- /pjproject/branches/1.x/pjmedia/src/pjmedia/transport_adapter_sample.c	(revision 3803)
+++ /pjproject/branches/1.x/pjmedia/src/pjmedia/transport_adapter_sample.c	(revision 3804)
@@ -95,4 +95,5 @@
 {
     pjmedia_transport	 base;
+    pj_bool_t		 del_base;
 
     pj_pool_t		*pool;
@@ -119,4 +120,5 @@
 					       const char *name,
 					       pjmedia_transport *transport,
+					       pj_bool_t del_base,
 					       pjmedia_transport **p_tp)
 {
@@ -139,4 +141,5 @@
     /* Save the transport as the slave transport */
     adapter->slave_tp = transport;
+    adapter->del_base = del_base;
 
     /* Done */
@@ -422,5 +425,7 @@
 
     /* Close the slave transport */
-    pjmedia_transport_close(adapter->slave_tp);
+    if (adapter->del_base) {
+	pjmedia_transport_close(adapter->slave_tp);
+    }
 
     /* Self destruct.. */
Index: /pjproject/branches/1.x/pjsip-apps/src/pjsua/pjsua_app.c
===================================================================
--- /pjproject/branches/1.x/pjsip-apps/src/pjsua/pjsua_app.c	(revision 3803)
+++ /pjproject/branches/1.x/pjsip-apps/src/pjsua/pjsua_app.c	(revision 3804)
@@ -141,7 +141,4 @@
 #ifdef STEREO_DEMO
 static void stereo_demo();
-#endif
-#ifdef TRANSPORT_ADAPTER_SAMPLE
-static pj_status_t transport_adapter_sample(void);
 #endif
 static pj_status_t create_ipv6_media_transports(void);
@@ -3052,4 +3049,33 @@
 }
 
+#ifdef TRANSPORT_ADAPTER_SAMPLE
+/*
+ * This callback is called when media transport needs to be created.
+ */
+static pjmedia_transport* on_create_media_transport(pjsua_call_id call_id,
+						    unsigned media_idx,
+						    pjmedia_transport *base_tp,
+						    unsigned flags)
+{
+    pjmedia_transport *adapter;
+    pj_status_t status;
+
+    /* Create the adapter */
+    status = pjmedia_tp_adapter_create(pjsua_get_pjmedia_endpt(),
+                                       NULL, base_tp,
+                                       (flags & PJSUA_MED_TP_CLOSE_MEMBER),
+                                       &adapter);
+    if (status != PJ_SUCCESS) {
+	PJ_PERROR(1,(THIS_FILE, status, "Error creating adapter"));
+	return NULL;
+    }
+
+    PJ_LOG(3,(THIS_FILE, "Media transport is created for call %d media %d",
+	      call_id, media_idx));
+
+    return adapter;
+}
+#endif
+
 /*
  * Print buddy list.
@@ -4652,4 +4678,7 @@
     app_config.cfg.cb.on_transport_state = &on_transport_state;
     app_config.cfg.cb.on_ice_transport_error = &on_ice_transport_error;
+#ifdef TRANSPORT_ADAPTER_SAMPLE
+    app_config.cfg.cb.on_create_media_transport = &on_create_media_transport;
+#endif
     app_config.log_cfg.cb = log_cb;
 
@@ -4930,4 +4959,7 @@
     /* Add accounts */
     for (i=0; i<app_config.acc_cnt; ++i) {
+	app_config.acc_cfg[i].reg_retry_interval = 300;
+	app_config.acc_cfg[i].reg_first_retry_interval = 60;
+
 	status = pjsua_acc_add(&app_config.acc_cfg[i], PJ_TRUE, NULL);
 	if (status != PJ_SUCCESS)
@@ -4955,13 +4987,9 @@
 
     /* Add RTP transports */
-#ifdef TRANSPORT_ADAPTER_SAMPLE
-    status = transport_adapter_sample();
-
-#else
     if (app_config.ipv6)
 	status = create_ipv6_media_transports();
     else
 	status = pjsua_media_transports_create(&app_config.rtp_cfg);
-#endif
+
     if (status != PJ_SUCCESS)
 	goto on_error;
@@ -5172,45 +5200,4 @@
 #endif
 
-#ifdef TRANSPORT_ADAPTER_SAMPLE
-static pj_status_t create_transport_adapter(pjmedia_endpt *med_endpt, int port,
-					    pjmedia_transport **p_tp)
-{
-    pjmedia_transport *udp;
-    pj_status_t status;
-
-    /* Create the UDP media transport */
-    status = pjmedia_transport_udp_create(med_endpt, NULL, port, 0, &udp);
-    if (status != PJ_SUCCESS)
-	return status;
-
-    /* Create the adapter */
-    status = pjmedia_tp_adapter_create(med_endpt, NULL, udp, p_tp);
-    if (status != PJ_SUCCESS) {
-	pjmedia_transport_close(udp);
-	return status;
-    }
-
-    return PJ_SUCCESS;
-}
-
-static pj_status_t transport_adapter_sample(void)
-{
-    pjsua_media_transport tp[PJSUA_MAX_CALLS];
-    pj_status_t status;
-    int port = 7000;
-    unsigned i;
-
-    for (i=0; i<app_config.cfg.max_calls; ++i) {
-	status = create_transport_adapter(pjsua_get_pjmedia_endpt(), 
-					  port + i*10,
-					  &tp[i].transport);
-	if (status != PJ_SUCCESS)
-	    return status;
-    }
-
-    return pjsua_media_transports_attach(tp, i, PJ_TRUE);
-}
-#endif
-
 static pj_status_t create_ipv6_media_transports(void)
 {
