[asterisk-commits] kmoore: branch kmoore/pimp_sip_srtp r386533 - in /team/kmoore/pimp_sip_srtp: ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Apr 25 13:06:37 CDT 2013


Author: kmoore
Date: Thu Apr 25 13:06:34 2013
New Revision: 386533

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=386533
Log:
Avoid memory overhead of SRTP crypto structure when possible

Modified:
    team/kmoore/pimp_sip_srtp/configs/res_sip.conf.sample
    team/kmoore/pimp_sip_srtp/include/asterisk/res_sip_session.h
    team/kmoore/pimp_sip_srtp/res/res_sip_sdp_rtp.c
    team/kmoore/pimp_sip_srtp/res/res_sip_session.c

Modified: team/kmoore/pimp_sip_srtp/configs/res_sip.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pimp_sip_srtp/configs/res_sip.conf.sample?view=diff&rev=386533&r1=386532&r2=386533
==============================================================================
--- team/kmoore/pimp_sip_srtp/configs/res_sip.conf.sample (original)
+++ team/kmoore/pimp_sip_srtp/configs/res_sip.conf.sample Thu Apr 25 13:06:34 2013
@@ -23,3 +23,4 @@
 ;rtp_symmetric=yes        ; Enable symmetric RTP support
 ;use_ptime=yes            ; Whether to use the ptime value received from the endpoint or not
 ;media_encryption=no      ; Options for media encryption are deny, no, and sdes
+;use_avpf=no              ; Whether to force usage of AVPF transport for this endpoint

Modified: team/kmoore/pimp_sip_srtp/include/asterisk/res_sip_session.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pimp_sip_srtp/include/asterisk/res_sip_session.h?view=diff&rev=386533&r1=386532&r2=386533
==============================================================================
--- team/kmoore/pimp_sip_srtp/include/asterisk/res_sip_session.h (original)
+++ team/kmoore/pimp_sip_srtp/include/asterisk/res_sip_session.h Thu Apr 25 13:06:34 2013
@@ -57,7 +57,7 @@
 	/*! \brief SDP handler that setup the RTP */
 	struct ast_sip_session_sdp_handler *handler;
 	/*! \brief Holds SRTP information */
-	struct ast_sdp_srtp srtp;
+	struct ast_sdp_srtp *srtp;
 	/*! \brief Stream is on hold */
 	unsigned int held:1;
 	/*! \brief Stream type this session media handles */

Modified: team/kmoore/pimp_sip_srtp/res/res_sip_sdp_rtp.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pimp_sip_srtp/res/res_sip_sdp_rtp.c?view=diff&rev=386533&r1=386532&r2=386533
==============================================================================
--- team/kmoore/pimp_sip_srtp/res/res_sip_sdp_rtp.c (original)
+++ team/kmoore/pimp_sip_srtp/res/res_sip_sdp_rtp.c Thu Apr 25 13:06:34 2013
@@ -545,7 +545,21 @@
 		return -1;
 	}
 
-	if (ast_sdp_crypto_process(session_media->rtp, &session_media->srtp, crypto_str)) {
+	if (!session_media->srtp) {
+		session_media->srtp = ast_sdp_srtp_alloc();
+		if (!session_media->srtp) {
+			return -1;
+		}
+	}
+
+	if (!session_media->srtp->crypto) {
+		session_media->srtp->crypto = ast_sdp_crypto_setup();
+		if (!session_media->srtp->crypto) {
+			return -1;
+		}
+	}
+
+	if (ast_sdp_crypto_process(session_media->rtp, session_media->srtp, crypto_str)) {
 		return -1;
 	}
 
@@ -593,15 +607,24 @@
 	return set_caps(session, session_media, stream);
 }
 
-static int add_crypto_to_stream(struct ast_sip_session_media *session_media,
+static int add_crypto_to_stream(struct ast_sip_session *session,
+	struct ast_sip_session_media *session_media,
 	pj_pool_t *pool, pjmedia_sdp_media *media)
 {
 	pj_str_t stmp;
 	pjmedia_sdp_attr *attr;
-	const char *crypto_attribute = ast_sdp_srtp_get_attrib(&session_media->srtp,
+	const char *crypto_attribute;
+
+	if (!session_media->srtp && session->endpoint->media_encryption != AST_SIP_MEDIA_ENCRYPT_DENY) {
+		session_media->srtp = ast_sdp_srtp_alloc();
+		if (!session_media->srtp) {
+			return -1;
+		}
+	}
+
+	crypto_attribute = ast_sdp_srtp_get_attrib(session_media->srtp,
 		0 /* DTLS can not be enabled for res_sip */,
 		0 /* don't prefer 32byte tag length */);
-
 	if (!crypto_attribute) {
 		/* No crypto attribute to add */
 		return -1;
@@ -650,7 +673,7 @@
 		return -1;
 	}
 
-	crypto_res = add_crypto_to_stream(session_media, pool, media);
+	crypto_res = add_crypto_to_stream(session, session_media, pool, media);
 
 	media->desc.media = pj_str(session_media->stream_type);
 	media->desc.transport = pj_str(ast_sdp_get_rtp_profile(

Modified: team/kmoore/pimp_sip_srtp/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pimp_sip_srtp/res/res_sip_session.c?view=diff&rev=386533&r1=386532&r2=386533
==============================================================================
--- team/kmoore/pimp_sip_srtp/res/res_sip_session.c (original)
+++ team/kmoore/pimp_sip_srtp/res/res_sip_session.c Thu Apr 25 13:06:34 2013
@@ -881,8 +881,8 @@
 	if (session_media->handler) {
 		session_media->handler->stream_destroy(session_media);
 	}
-	if (session_media->srtp.crypto) {
-		ast_sdp_crypto_destroy(session_media->srtp.crypto);
+	if (session_media->srtp) {
+		ast_sdp_srtp_destroy(session_media->srtp);
 	}
 }
 
@@ -932,15 +932,10 @@
 static int add_session_media(void *obj, void *arg, int flags)
 {
 	struct sdp_handler_list *handler_list = obj;
-	struct ast_sip_session * session = arg;
+	struct ast_sip_session *session = arg;
 	RAII_VAR(struct ast_sip_session_media *, session_media, NULL, ao2_cleanup);
 	session_media = ao2_alloc(sizeof(*session_media) + strlen(handler_list->stream_type), session_media_dtor);
 	if (!session_media) {
-		return CMP_STOP;
-	}
-
-	session_media->srtp.crypto = ast_sdp_crypto_setup();
-	if (!session_media->srtp.crypto) {
 		return CMP_STOP;
 	}
 




More information about the asterisk-commits mailing list