Index: /pjproject/branches/users/nanang/pjmedia/include/pjmedia/transport.h
===================================================================
--- /pjproject/branches/users/nanang/pjmedia/include/pjmedia/transport.h	(revision 1701)
+++ /pjproject/branches/users/nanang/pjmedia/include/pjmedia/transport.h	(revision 1702)
@@ -255,5 +255,6 @@
 				pj_pool_t *pool,
 				pjmedia_sdp_session *sdp_local,
-				const pjmedia_sdp_session *sdp_remote);
+				const pjmedia_sdp_session *sdp_remote,
+				unsigned media_index);
 
     /**
@@ -471,7 +472,9 @@
 				    pj_pool_t *pool,
 				    pjmedia_sdp_session *sdp_local,
-				    const pjmedia_sdp_session *sdp_remote)
-{
-    return (*tp->op->media_create)(tp, pool, sdp_local, sdp_remote);
+				    const pjmedia_sdp_session *sdp_remote,
+				    unsigned media_index)
+{
+    return (*tp->op->media_create)(tp, pool, sdp_local, sdp_remote, 
+				   media_index);
 }
 
Index: /pjproject/branches/users/nanang/pjmedia/include/pjmedia/transport_srtp.h
===================================================================
--- /pjproject/branches/users/nanang/pjmedia/include/pjmedia/transport_srtp.h	(revision 1701)
+++ /pjproject/branches/users/nanang/pjmedia/include/pjmedia/transport_srtp.h	(revision 1702)
@@ -30,24 +30,100 @@
 PJ_BEGIN_DECL
 
-/**
- * Options that can be specified when creating SRTP transport.
- */
-enum pjmedia_transport_srtp_options
-{
-    /**
-     * This option will make the underlying transport to be closed whenever
-     * the SRTP transport is closed.
-     */
-    PJMEDIA_SRTP_AUTO_CLOSE_UNDERLYING_TRANSPORT = 1
-};
-
-/**
- * SRTP session parameters.
- */
-typedef struct pjmedia_srtp_stream_policy
-{
-    pj_str_t key;	     /**< Key string.		    */
-    pj_str_t crypto_suite;   /**< SRTP parameter for RTP.   */
-} pjmedia_srtp_stream_policy;
+
+/**
+ * Crypto option.
+ */
+typedef enum pjmedia_srtp_crypto_option
+{
+    /** When this flag is specified, encryption will be disabled. */
+    PJMEDIA_SRTP_NO_ENCRYPTION  = 1,
+
+    /** When this flag is specified, authentication will be disabled. */
+    PJMEDIA_SRTP_NO_AUTHENTICATION  = 2
+
+} pjmedia_srtp_crypto_option;
+
+
+/**
+ * This structure describes an individual crypto setting.
+ */
+typedef struct pjmedia_srtp_crypto
+{
+    /** Optional key. If empty, a random key will be autogenerated. */
+    pj_str_t	key;
+
+    /** Crypto name.   */
+    pj_str_t	crypto;
+
+    /* Flags, bitmask from #pjmedia_srtp_crypto_option */
+    unsigned	flags;
+
+} pjmedia_srtp_crypto;
+
+
+/**
+ * This enumeration specifies the behavior of the SRTP transport regarding
+ * media security offer and answer.
+ */
+typedef enum pjmedia_srtp_use
+{
+    /**
+     * When this flag is specified, SRTP will be disabled, and the transport
+     * will reject RTP/SAVP offer.
+     */
+    PJMEDIA_SRTP_DISABLED,
+
+    /**
+     * When this flag is specified, SRTP will be advertised as optional and
+     * incoming SRTP offer will be accepted.
+     */
+    PJMEDIA_SRTP_OPTIONAL,
+
+    /**
+     * When this flag is specified, the transport will require that RTP/SAVP
+     * media shall be used.
+     */
+    PJMEDIA_SRTP_MANDATORY
+
+} pjmedia_srtp_use;
+
+
+/**
+ * Settings to be given when creating SRTP transport. Application should call
+ * #pjmedia_srtp_setting_default() to initialize this structure with its 
+ * default values.
+ */
+typedef struct pjmedia_srtp_setting
+{
+    /**
+     * Specify the usage policy. Default is PJMEDIA_SRTP_OPTIONAL.
+     */
+    pjmedia_srtp_use use;
+
+    /**
+     * Specify whether the SRTP transport should close the member transport 
+     * when it is destroyed. Default: PJ_TRUE.
+     */
+    pj_bool_t			close_member_tp;
+
+    /**
+     * Specify the number of crypto suite settings.
+     */
+    unsigned			crypto_count;
+
+    /**
+     * Specify individual crypto suite setting.
+     */
+    pjmedia_srtp_crypto		crypto[8];
+
+} pjmedia_srtp_setting;
+
+
+/**
+ * Initialize SRTP setting with its default values.
+ *
+ * @param opt	SRTP setting to be initialized.
+ */
+PJ_DECL(void) pjmedia_srtp_setting_default(pjmedia_srtp_setting *opt);
 
 
@@ -55,42 +131,48 @@
  * Create an SRTP media transport.
  *
- * @param endpt		    The media endpoint instance.
- * @param tp		    The actual media transport 
- *			    to send and receive RTP/RTCP packets.
- * @param p_tp_srtp	    Pointer to receive the transport SRTP instance.
- *
- * @return		    PJ_SUCCESS on success.
- */
-PJ_DECL(pj_status_t) pjmedia_transport_srtp_create(pjmedia_endpt *endpt,
-					 pjmedia_transport *tp,
-					 unsigned options,
-					 pjmedia_transport **p_tp_srtp);
-
-/**
- * Initialize and start SRTP session with the given parameters.
- * Please note:
- * 1. pjmedia_transport_srtp_init_session() and 
- *    pjmedia_transport_srtp_deinit_session() is automatic called by 
- *    SRTP pjmedia_transport_media_start() and pjmedia_transport_media_stop(),
- *    application needs to call these functions directly only if the application
- *    is not intended to call SRTP pjmedia_transport_media_start.
- * 2. Even if an RTP stream is only one direction, you might need to provide 
- *    both policies, because it is needed by RTCP, which is usually two 
- *    directions.
- * 3. Key for transmit and receive direction MUST be different, this is
- *    specified by libsrtp.
+ * @param endpt	    The media endpoint instance.
+ * @param tp	    The actual media transport to send and receive 
+ *		    RTP/RTCP packets. This media transport will be
+ *		    kept as member transport of this SRTP instance.
+ * @param opt	    Optional settings. If NULL is given, default
+ *		    settings will be used.
+ * @param p_tp	    Pointer to receive the transport SRTP instance.
+ *
+ * @return	    PJ_SUCCESS on success.
+ */
+PJ_DECL(pj_status_t) pjmedia_transport_srtp_create(
+				       pjmedia_endpt *endpt,
+				       pjmedia_transport *tp,
+				       const pjmedia_srtp_setting *opt,
+				       pjmedia_transport **p_tp);
+
+
+/**
+ * Manually start SRTP session with the given parameters. Application only
+ * needs to call this function when the SRTP transport is used without SDP
+ * offer/answer. When SDP offer/answer framework is used, the SRTP transport
+ * will be started/stopped by #pjmedia_transport_media_start() and 
+ * #pjmedia_transport_media_stop() respectively.
+ *
+ * Please note that even if an RTP stream is only one direction, application
+ * will still need to provide both crypto suites, because it is needed by 
+ * RTCP.
+
+ * If application specifies the crypto keys, the keys for transmit and receive
+ * direction MUST be different.
  *
  * @param srtp	    The SRTP transport.
- * @param prm	    Session parameters.
+ * @param tx	    Crypto suite setting for transmit direction.
+ * @param rx	    Crypto suite setting for receive direction.
  *
  * @return	    PJ_SUCCESS on success.
  */
-PJ_DECL(pj_status_t) pjmedia_transport_srtp_init_session(
-		       pjmedia_transport *srtp,
-		       const pjmedia_srtp_stream_policy *policy_tx,
-		       const pjmedia_srtp_stream_policy *policy_rx);
-
-/**
- * Stop SRTP seession.
+PJ_DECL(pj_status_t) pjmedia_transport_srtp_start(
+					    pjmedia_transport *srtp,
+					    const pjmedia_srtp_crypto *tx,
+					    const pjmedia_srtp_crypto *rx);
+
+/**
+ * Stop SRTP session.
  *
  * @param srtp	    The SRTP media transport.
@@ -98,19 +180,18 @@
  * @return	    PJ_SUCCESS on success.
  *
- * @see pjmedia_transport_srtp_init_session() 
- */
-PJ_DECL(pj_status_t) pjmedia_transport_srtp_deinit_session(
-		       pjmedia_transport *srtp);
-
-
-/**
- * Query real transport of SRTP.
+ * @see #pjmedia_transport_srtp_start() 
+ */
+PJ_DECL(pj_status_t) pjmedia_transport_srtp_stop(pjmedia_transport *srtp);
+
+
+/**
+ * Query member transport of SRTP.
  *
  * @param srtp		    The SRTP media transport.
  *
- * @return		    real media transport.
- */
-PJ_DECL(pjmedia_transport*) pjmedia_transport_srtp_get_real_transport(
-				pjmedia_transport *srtp);
+ * @return		    member media transport.
+ */
+PJ_DECL(pjmedia_transport*) pjmedia_transport_srtp_get_member(
+						    pjmedia_transport *srtp);
 
 
Index: /pjproject/branches/users/nanang/pjmedia/src/pjmedia/transport_ice.c
===================================================================
--- /pjproject/branches/users/nanang/pjmedia/src/pjmedia/transport_ice.c	(revision 1701)
+++ /pjproject/branches/users/nanang/pjmedia/src/pjmedia/transport_ice.c	(revision 1702)
@@ -76,5 +76,6 @@
 				       pj_pool_t *pool,
 				       pjmedia_sdp_session *sdp_local,
-				       const pjmedia_sdp_session *sdp_remote);
+				       const pjmedia_sdp_session *sdp_remote,
+				       unsigned media_index);
 static pj_status_t transport_media_start (pjmedia_transport *tp,
 				       pj_pool_t *pool,
@@ -259,5 +260,6 @@
 				       pj_pool_t *pool,
 				       pjmedia_sdp_session *sdp_local,
-				       const pjmedia_sdp_session *sdp_remote)
+				       const pjmedia_sdp_session *sdp_remote,
+				       unsigned media_index)
 {
     struct transport_ice *tp_ice = (struct transport_ice*)tp;
Index: /pjproject/branches/users/nanang/pjmedia/src/pjmedia/transport_srtp.c
===================================================================
--- /pjproject/branches/users/nanang/pjmedia/src/pjmedia/transport_srtp.c	(revision 1701)
+++ /pjproject/branches/users/nanang/pjmedia/src/pjmedia/transport_srtp.c	(revision 1702)
@@ -78,4 +78,5 @@
     unsigned		 options;   /**< Transport options.	   */
 
+    pjmedia_srtp_setting setting;
     /* SRTP policy */
     pj_bool_t		 session_inited;
@@ -83,6 +84,6 @@
     char		 tx_key[MAX_KEY_LEN];
     char		 rx_key[MAX_KEY_LEN];
-    pjmedia_srtp_stream_policy tx_policy;
-    pjmedia_srtp_stream_policy rx_policy;
+    pjmedia_srtp_stream_crypto tx_policy;
+    pjmedia_srtp_stream_crypto rx_policy;
 
     /* libSRTP contexts */
@@ -245,8 +246,8 @@
  * Initialize and start SRTP session with the given parameters.
  */
-PJ_DEF(pj_status_t) pjmedia_transport_srtp_init_session(
+PJ_DEF(pj_status_t) pjmedia_transport_srtp_start(
 			   pjmedia_transport *srtp, 
-			   const pjmedia_srtp_stream_policy *policy_tx,
-			   const pjmedia_srtp_stream_policy *policy_rx)
+			   const pjmedia_srtp_stream_crypto *policy_tx,
+			   const pjmedia_srtp_stream_crypto *policy_rx)
 {
     transport_srtp  *p_srtp = (transport_srtp*) srtp;
@@ -344,6 +345,5 @@
  * Stop SRTP session.
  */
-PJ_DEF(pj_status_t) pjmedia_transport_srtp_deinit_session(
-					    pjmedia_transport *srtp)
+PJ_DEF(pj_status_t) pjmedia_transport_srtp_stop(pjmedia_transport *srtp)
 {
     transport_srtp *p_srtp = (transport_srtp*) srtp;
@@ -367,6 +367,6 @@
 }
 
-PJ_DEF(pjmedia_transport *) pjmedia_transport_srtp_get_real_transport(
-				    pjmedia_transport *tp)
+PJ_DEF(pjmedia_transport *) pjmedia_transport_srtp_get_member(
+						pjmedia_transport *tp)
 {
     transport_srtp *srtp = (transport_srtp*) tp;
@@ -506,9 +506,9 @@
     pjmedia_transport_detach(tp, NULL);
     
-    if (srtp->options && PJMEDIA_SRTP_AUTO_CLOSE_UNDERLYING_TRANSPORT) {
+    if (srtp->setting.close_member_tp) {
 	pjmedia_transport_close(srtp->real_tp);
     }
 
-    status = pjmedia_transport_srtp_deinit_session(tp);
+    status = pjmedia_transport_srtp_stop(tp);
 
     pj_pool_release(srtp->pool);
@@ -692,5 +692,5 @@
 static pj_status_t parse_attr_crypto(pj_pool_t *pool,
 				     const pjmedia_sdp_attr *attr,
-				     pjmedia_srtp_stream_policy *policy,
+				     pjmedia_srtp_stream_crypto *policy,
 				     int *tag)
 {
@@ -749,6 +749,6 @@
     pjmedia_sdp_media *media_local  = sdp_local->media[media_index];
     pjmedia_sdp_attr *attr;
-    pjmedia_srtp_stream_policy policy_remote;
-    pjmedia_srtp_stream_policy policy_local;
+    pjmedia_srtp_stream_crypto policy_remote;
+    pjmedia_srtp_stream_crypto policy_local;
     pj_status_t status;
     unsigned cs_cnt = sizeof(crypto_suites)/sizeof(crypto_suites[0]);
@@ -970,6 +970,5 @@
 
     /* Got policy_local & policy_remote, let's initalize the SRTP */
-    status = pjmedia_transport_srtp_init_session(tp, 
-						 &policy_local, &policy_remote);
+    status = pjmedia_transport_srtp_start(tp, &policy_local, &policy_remote);
     if (status != PJ_SUCCESS)
 	return status;
@@ -985,5 +984,5 @@
     pj_status_t status;
 
-    status = pjmedia_transport_srtp_deinit_session(tp);
+    status = pjmedia_transport_srtp_stop(tp);
     if (status != PJ_SUCCESS)
 	PJ_LOG(4, (THIS_FILE, "Failed deinit session."));
Index: /pjproject/branches/users/nanang/pjmedia/src/pjmedia/transport_udp.c
===================================================================
--- /pjproject/branches/users/nanang/pjmedia/src/pjmedia/transport_udp.c	(revision 1701)
+++ /pjproject/branches/users/nanang/pjmedia/src/pjmedia/transport_udp.c	(revision 1702)
@@ -122,5 +122,6 @@
 				       pj_pool_t *pool,
 				       pjmedia_sdp_session *sdp_local,
-				       const pjmedia_sdp_session *sdp_remote);
+				       const pjmedia_sdp_session *sdp_remote,
+				       unsigned media_index);
 static pj_status_t transport_media_start (pjmedia_transport *tp,
 				       pj_pool_t *pool,
@@ -741,5 +742,6 @@
 				  pj_pool_t *pool,
 				  pjmedia_sdp_session *sdp_local,
-				  const pjmedia_sdp_session *sdp_remote)
+				  const pjmedia_sdp_session *sdp_remote,
+				  unsigned media_index)
 {
     PJ_UNUSED_ARG(tp);
