Index: pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c
===================================================================
--- pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c	(revision 1101)
+++ pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c	(revision 1104)
@@ -70,6 +70,5 @@
  * And these are ICE callbacks.
  */
-static void ice_on_rx_data(pj_ice_st *ice_st,
-			   unsigned comp_id, unsigned cand_id,
+static void ice_on_rx_data(pj_ice_st *ice_st, unsigned comp_id, 
 			   void *pkt, pj_size_t size,
 			   const pj_sockaddr_t *src_addr,
@@ -100,5 +99,4 @@
     pj_ice_st_cb ice_st_cb;
     struct transport_ice *tp_ice;
-    unsigned i;
     pj_status_t status;
 
@@ -111,14 +109,9 @@
 
     /* Create ICE */
-    status = pj_ice_st_create(stun_cfg, name, NULL, &ice_st_cb, &ice_st);
+    status = pj_ice_st_create(stun_cfg, name, comp_cnt, NULL, 
+			      &ice_st_cb, &ice_st);
     if (status != PJ_SUCCESS)
 	return status;
 
-    /* Add components */
-    for (i=0; i<comp_cnt; ++i) {
-	status = pj_ice_st_add_comp(ice_st, i+1);
-	if (status != PJ_SUCCESS) 
-	    goto on_error;
-    }
 
     /* Create transport instance and attach to ICE */
@@ -136,8 +129,4 @@
 
     return PJ_SUCCESS;
-
-on_error:
-    pj_ice_st_destroy(ice_st);
-    return status;
 }
 
@@ -158,5 +147,63 @@
 
 
-PJ_DECL(pj_ice_st*) pjmedia_ice_get_ice_st(pjmedia_transport *tp)
+PJ_DEF(pj_status_t) pjmedia_ice_start_init( pjmedia_transport *tp,
+					    unsigned options,
+					    const pj_sockaddr_in *start_addr,
+					    const pj_sockaddr_in *stun_srv,
+					    const pj_sockaddr_in *turn_srv)
+{
+    struct transport_ice *tp_ice = (struct transport_ice*)tp;
+    unsigned comp_id;
+    pj_status_t status;
+
+    status = pj_ice_st_set_stun_srv(tp_ice->ice_st, stun_srv, turn_srv);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    status = pj_ice_st_create_comp(tp_ice->ice_st, 1, options, start_addr, 
+				   &comp_id);
+    if (status != PJ_SUCCESS)
+	return status;
+
+    if (tp_ice->ice_st->comp_cnt > 1) {
+	pj_sockaddr_in addr;
+
+	pj_memcpy(&addr, &tp_ice->ice_st->comp[0]->local_addr.ipv4,
+		  sizeof(pj_sockaddr_in));
+	if (start_addr)
+	    addr.sin_addr.s_addr = start_addr->sin_addr.s_addr;
+	else
+	    addr.sin_addr.s_addr = 0;
+
+	addr.sin_port = (pj_uint16_t)(pj_ntohs(addr.sin_port)+1);
+	status = pj_ice_st_create_comp(tp_ice->ice_st, 2, options, 
+				       &addr, &comp_id);
+	if (status != PJ_SUCCESS)
+	    return status;
+    }
+    return status;
+}
+
+
+PJ_DEF(pj_status_t) pjmedia_ice_get_init_status(pjmedia_transport *tp)
+{
+    struct transport_ice *tp_ice = (struct transport_ice*)tp;
+    return pj_ice_st_get_comps_status(tp_ice->ice_st);
+}
+
+
+PJ_DEF(pj_status_t) pjmedia_ice_get_comp( pjmedia_transport *tp,
+					  unsigned comp_id,
+					  pj_ice_st_comp *comp)
+{
+    struct transport_ice *tp_ice = (struct transport_ice*)tp;
+    PJ_ASSERT_RETURN(tp && comp_id && comp_id <= tp_ice->ice_st->comp_cnt &&
+		     comp, PJ_EINVAL);
+
+    pj_memcpy(comp, tp_ice->ice_st->comp[comp_id-1], sizeof(pj_ice_st_comp));
+    return PJ_SUCCESS;		    
+}
+
+PJ_DEF(pj_ice_st*) pjmedia_ice_get_ice_st(pjmedia_transport *tp)
 {
     struct transport_ice *tp_ice = (struct transport_ice*)tp;
@@ -416,32 +463,28 @@
 {
     struct transport_ice *tp_ice = (struct transport_ice*)tp;
-    int rel_idx = -1, srflx_idx = -1, host_idx = -1, idx = -1;
-    unsigned i;
+    pj_ice_st *ice_st = tp_ice->ice_st;
+    pj_ice_st_comp *comp;
 
     pj_bzero(info, sizeof(*info));
     info->rtp_sock = info->rtcp_sock = PJ_INVALID_SOCKET;
 
-    for (i=0; i<tp_ice->ice_st->itf_cnt; ++i) {
-	pj_ice_st_interface *itf = tp_ice->ice_st->itfs[i];
-
-	if (itf->type == PJ_ICE_CAND_TYPE_HOST && host_idx == -1)
-	    host_idx = i;
-	else if (itf->type == PJ_ICE_CAND_TYPE_RELAYED && rel_idx == -1)
-	    rel_idx = i;
-	else if (itf->type == PJ_ICE_CAND_TYPE_SRFLX && srflx_idx == -1)
-	    srflx_idx = i;
-    }
-
-    if (idx == -1 && srflx_idx != -1)
-	idx = srflx_idx;
-    else if (idx == -1 && rel_idx != -1)
-	idx = rel_idx;
-    else if (idx == -1 && host_idx != -1)
-	idx = host_idx;
-
-    PJ_ASSERT_RETURN(idx != -1, PJ_EBUG);
-
-    pj_memcpy(&info->rtp_addr_name, &tp_ice->ice_st->itfs[idx]->addr,
+    /* Retrieve address of default candidate for component 1 (RTP) */
+    comp = ice_st->comp[0];
+    pj_assert(comp->default_cand >= 0);
+    info->rtp_sock = comp->sock;
+    pj_memcpy(&info->rtp_addr_name, 
+	      &comp->cand_list[comp->default_cand].addr,
 	      sizeof(pj_sockaddr_in));
+
+    /* Retrieve address of default candidate for component 12(RTCP) */
+    if (ice_st->comp_cnt > 1) {
+	comp = ice_st->comp[1];
+	pj_assert(comp->default_cand >= 0);
+	info->rtp_sock = comp->sock;
+	pj_memcpy(&info->rtp_addr_name, 
+		  &comp->cand_list[comp->default_cand].addr,
+		  sizeof(pj_sockaddr_in));
+    }
+
 
     return PJ_SUCCESS;
@@ -492,11 +535,7 @@
 {
     struct transport_ice *tp_ice = (struct transport_ice*)tp;
-    if (tp_ice->ice_st->ice) {
-	return pj_ice_st_send_data(tp_ice->ice_st, 1, pkt, size);
-    } else {
-	return pj_ice_st_sendto(tp_ice->ice_st, 1, 0,
-				pkt, size, &tp_ice->remote_rtp,
-				sizeof(pj_sockaddr_in));
-    }
+    return pj_ice_st_sendto(tp_ice->ice_st, 1, 
+			    pkt, size, &tp_ice->remote_rtp,
+			    sizeof(pj_sockaddr_in));
 }
 
@@ -506,19 +545,16 @@
 			        pj_size_t size)
 {
-#if 0
-    struct transport_ice *tp_ice = (struct transport_ice*)tp;
-    return pj_ice_st_send_data(tp_ice->ice_st, 1, pkt, size);
-#else
-    PJ_TODO(SUPPORT_RTCP);
-    PJ_UNUSED_ARG(tp);
-    PJ_UNUSED_ARG(pkt);
-    PJ_UNUSED_ARG(size);
-    return PJ_SUCCESS;
-#endif
-}
-
-
-static void ice_on_rx_data(pj_ice_st *ice_st,
-			   unsigned comp_id, unsigned cand_id,
+    struct transport_ice *tp_ice = (struct transport_ice*)tp;
+    if (tp_ice->ice_st->comp_cnt > 1) {
+	return pj_ice_st_sendto(tp_ice->ice_st, 2, 
+				pkt, size, &tp_ice->remote_rtp,
+				sizeof(pj_sockaddr_in));
+    } else {
+	return PJ_SUCCESS;
+    }
+}
+
+
+static void ice_on_rx_data(pj_ice_st *ice_st, unsigned comp_id, 
 			   void *pkt, pj_size_t size,
 			   const pj_sockaddr_t *src_addr,
@@ -532,7 +568,8 @@
 	(*tp_ice->rtcp_cb)(tp_ice->stream, pkt, size);
 
-    PJ_UNUSED_ARG(cand_id);
     PJ_UNUSED_ARG(src_addr);
     PJ_UNUSED_ARG(src_addr_len);
+
+    PJ_TODO(SWITCH_SOURCE_ADDRESS);
 }
 
