[asterisk-commits] kharwell: branch kharwell/pimp_sip_media_neg r385276 - in /team/kharwell/pimp...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Apr 10 17:47:59 CDT 2013


Author: kharwell
Date: Wed Apr 10 17:47:55 2013
New Revision: 385276

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385276
Log:
refactored sdp handling code to use offers from dialplan

Modified:
    team/kharwell/pimp_sip_media_neg/channels/chan_gulp.c
    team/kharwell/pimp_sip_media_neg/include/asterisk/res_sip_session.h
    team/kharwell/pimp_sip_media_neg/res/res_sip_sdp_rtp.c
    team/kharwell/pimp_sip_media_neg/res/res_sip_session.c

Modified: team/kharwell/pimp_sip_media_neg/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_media_neg/channels/chan_gulp.c?view=diff&rev=385276&r1=385275&r2=385276
==============================================================================
--- team/kharwell/pimp_sip_media_neg/channels/chan_gulp.c (original)
+++ team/kharwell/pimp_sip_media_neg/channels/chan_gulp.c Wed Apr 10 17:47:55 2013
@@ -295,7 +295,7 @@
 	struct gulp_pvt *pvt = ast_channel_tech_pvt(chan);
 	struct media_offering *i;
 
-	if (!pvt->session->outgoing_caps) {
+	if (!pvt->session->offer_caps) {
 		return 0;
 	}
 
@@ -314,8 +314,8 @@
 	struct gulp_pvt *pvt = ast_channel_tech_pvt(chan);
 	struct media_offering *i;
 
-	if (!pvt->session->outgoing_caps) {
-		pvt->session->outgoing_caps = ast_format_cap_alloc_nolock();
+	if (!pvt->session->offer_caps) {
+		pvt->session->offer_caps = ast_format_cap_alloc_nolock();
 	}
 
 	AST_LIST_TRAVERSE(&media_offerings, i, next) {
@@ -340,8 +340,8 @@
 	const char *name;
 	int size = 0;
 
-	ast_format_cap_iter_start(session->outgoing_caps);
-	while (!ast_format_cap_iter_next(session->outgoing_caps, &fmt)) {
+	ast_format_cap_iter_start(session->offer_caps);
+	while (!ast_format_cap_iter_next(session->offer_caps, &fmt)) {
 		if (AST_FORMAT_GET_TYPE(fmt.id) != media_type) {
 			continue;
 		}
@@ -362,7 +362,7 @@
 		strncat(buf, name, size);
 		strncat(buf, ",", 1);
 	}
-	ast_format_cap_iter_end(session->outgoing_caps);
+	ast_format_cap_iter_end(session->offer_caps);
 	
 	if (size) {
 		/* remove the extra comma */
@@ -373,8 +373,8 @@
 
 static int media_offer_av_set(struct ast_sip_session *session, const char *value, enum ast_format_type media_type)
 {
-	ast_format_cap_remove_bytype(session->outgoing_caps, media_type);
-	ast_parse_allow_disallow(NULL, session->outgoing_caps, value, 1);
+	ast_format_cap_remove_bytype(session->offer_caps, media_type);
+	ast_parse_allow_disallow(NULL, session->offer_caps, value, 1);
 
 	return 0;
 }
@@ -1022,16 +1022,9 @@
 static int call(void *data)
 {
 	struct ast_sip_session *session = data;
-	pjsip_tx_data *packet;
-
-	if (pjsip_inv_invite(session->inv_session, &packet) != PJ_SUCCESS) {
-		return -1;
-	}
-
-	ast_sip_session_send_request_with_sdp(session, packet);
-
+	int res = ast_sip_session_send_request_with_sdp(session);
 	ao2_ref(session, -1);
-	return 0;
+	return res;
 }
 
 /*! \brief Function called by core to actually start calling a remote party */

Modified: team/kharwell/pimp_sip_media_neg/include/asterisk/res_sip_session.h
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_media_neg/include/asterisk/res_sip_session.h?view=diff&rev=385276&r1=385275&r2=385276
==============================================================================
--- team/kharwell/pimp_sip_media_neg/include/asterisk/res_sip_session.h (original)
+++ team/kharwell/pimp_sip_media_neg/include/asterisk/res_sip_session.h Wed Apr 10 17:47:55 2013
@@ -99,8 +99,8 @@
 	struct ast_format_cap *direct_media_cap;
 	/* Requested capabilities */
 	struct ast_format_cap *req_caps;
-	/* Capabilities set by dialplan for an outgoing request */
-	struct ast_format_cap *outgoing_caps;
+	/* Capabilities offered by dialplan for an outgoing request */
+	struct ast_format_cap *offer_caps;
 };
 
 typedef int (*ast_sip_session_request_creation_cb)(struct ast_sip_session *session, pjsip_tx_data *tdata);
@@ -445,9 +445,8 @@
  * supplements' outgoing_request callback.
  *
  * \param session The session to which to send the request
- * \param tdata The request to send
- */
-void ast_sip_session_send_request_with_sdp(struct ast_sip_session *session, pjsip_tx_data *tdata);
+ */
+int ast_sip_session_send_request_with_sdp(struct ast_sip_session *session);
 
 /*!
  * \brief Send a SIP request and get called back when a response is received

Modified: team/kharwell/pimp_sip_media_neg/res/res_sip_sdp_rtp.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_media_neg/res/res_sip_sdp_rtp.c?view=diff&rev=385276&r1=385275&r2=385276
==============================================================================
--- team/kharwell/pimp_sip_media_neg/res/res_sip_sdp_rtp.c (original)
+++ team/kharwell/pimp_sip_media_neg/res/res_sip_sdp_rtp.c Wed Apr 10 17:47:55 2013
@@ -286,6 +286,78 @@
 	return attr;
 }
 
+/*! \brief Generates an attribute based up on the given ast format */
+static int generate_attr(pj_pool_t *pool, pjmedia_sdp_media *media, enum ast_format_type media_type,
+			 struct ast_rtp_codecs *codecs, struct ast_format *fmt, int *min_packet_size)
+{
+	int rtp_code;
+	pjmedia_sdp_attr *attr;
+
+	if ((rtp_code = ast_rtp_codecs_payload_code(codecs, 1, fmt, 0)) == -1) {
+		return -1;
+	}
+
+	if (!(attr = generate_rtpmap_attr(media, pool, rtp_code, 1, fmt, 0))) {
+		return 0;
+	}
+
+	media->attr[media->attr_count++] = attr;
+
+	if ((attr = generate_fmtp_attr(pool, fmt, rtp_code))) {
+		media->attr[media->attr_count++] = attr;
+	}
+
+	if (&codecs->pref && media_type != AST_FORMAT_TYPE_VIDEO) {
+		struct ast_format_list list = ast_codec_pref_getsize(&codecs->pref, fmt);
+		if (list.cur_ms && ((list.cur_ms < *min_packet_size) || !*min_packet_size)) {
+			*min_packet_size = list.cur_ms;
+		}
+	}
+	return 0;
+}
+
+/*! \brief Converts the given capabilities to media attributes */
+static int caps_to_attrs(pj_pool_t *pool, pjmedia_sdp_media *media, enum ast_format_type media_type,
+			 struct ast_rtp_codecs *codecs, struct ast_format_cap *caps,
+			 int *min_packet_size, struct ast_sip_session *session)
+{
+	int i;
+	struct ast_format fmt;
+	struct ast_format compat_fmt;
+
+	for (i = 0; ast_codec_pref_index(&session->endpoint->prefs, i, &fmt); ++i) {
+		if ((AST_FORMAT_GET_TYPE(fmt.id) != media_type) ||
+		    (!ast_format_cap_get_compatible_format(caps, &fmt, &compat_fmt))) {
+			continue;
+		}
+
+		if (generate_attr(pool, media, media_type, codecs, &compat_fmt, min_packet_size)) {
+			return -1;
+		}
+	}
+	return 0;
+}
+
+/*! \brief Converts offered capabilities to media attributes */
+static int offer_caps_to_attrs(pj_pool_t *pool, pjmedia_sdp_media *media, enum ast_format_type media_type,
+			       struct ast_rtp_codecs *codecs, struct ast_format_cap *caps, int *min_packet_size)
+{
+	int res = 0;
+	struct ast_format fmt;
+	ast_format_cap_iter_start(caps);
+	while (!ast_format_cap_iter_next(caps, &fmt)) {
+		if (AST_FORMAT_GET_TYPE(fmt.id) != media_type) {
+			continue;
+		}
+
+		if ((res = generate_attr(pool, media, media_type, codecs, &fmt, min_packet_size))) {
+			break;
+		}
+	}
+	ast_format_cap_iter_end(caps);
+	return res;
+}
+
 /*! \brief Function which adds ICE attributes to a media stream */
 static void add_ice_to_stream(struct ast_sip_session *session, struct ast_sip_session_media *session_media, pj_pool_t *pool, pjmedia_sdp_media *media)
 {
@@ -504,23 +576,21 @@
 	pjmedia_sdp_attr *attr;
 	int index = 0, min_packet_size = 0, noncodec = (session->endpoint->dtmf == AST_SIP_DTMF_RFC_4733) ? AST_RTP_DTMF : 0;
 	int rtp_code;
-	struct ast_format format;
-	struct ast_format compat_format;
 	RAII_VAR(struct ast_format_cap *, caps, NULL, ast_format_cap_destroy);
 	enum ast_format_type media_type = stream_to_media_type(session_media->stream_type);
 
 	int direct_media_enabled = !ast_sockaddr_isnull(&session_media->direct_media_addr) &&
 		!ast_format_cap_is_empty(session->direct_media_cap);
 
-	int use_outgoing_caps = !ast_format_cap_is_empty(session->outgoing_caps);
-
-	/* if ((use_outgoing_caps && !ast_format_cap_has_type(session->outgoing_caps, media_type)) || */
-	/*     (!use_outgoing_caps && !ast_format_cap_has_type(session->endpoint->codecs, media_type))) { */
+	int use_offer_caps = !ast_format_cap_is_empty(session->offer_caps);
+
+	if ((use_offer_caps && !ast_format_cap_has_type(session->offer_caps, media_type)) ||
+	    (!use_offer_caps && !ast_format_cap_has_type(session->endpoint->codecs, media_type))) {
+		/* If no type formats are configured don't add a stream */
+		return 0;
+	/* if (!ast_format_cap_has_type(session->endpoint->codecs, media_type)) { */
 	/* 	/\* If no type formats are configured don't add a stream *\/ */
 	/* 	return 0; */
-	if (!ast_format_cap_has_type(session->endpoint->codecs, media_type)) {
-		/* If no type formats are configured don't add a stream */
-		return 0;
 	} else if (!session_media->rtp && create_rtp(session, session_media, session->endpoint->rtp_ipv6)) {
 		return -1;
 	}
@@ -563,46 +633,23 @@
 		return -1;
 	}
 
-	if (use_outgoing_caps) {
-		ast_format_cap_copy(caps, session->outgoing_caps);
- 	} else if (direct_media_enabled) {
-		ast_format_cap_joint_copy(session->endpoint->codecs, session->direct_media_cap, caps);
-	} else if (ast_format_cap_is_empty(session->req_caps)) {
-		ast_format_cap_copy(caps, session->endpoint->codecs);
+	if (use_offer_caps) {
+		if (offer_caps_to_attrs(pool, media, media_type, ast_rtp_instance_get_codecs(session_media->rtp),
+					session->offer_caps, &min_packet_size)) {
+			return -1;
+		}
 	} else {
-		ast_format_cap_joint_copy(session->endpoint->codecs, session->req_caps, caps);
-	}
-
-	for (index = 0; ast_codec_pref_index(&session->endpoint->prefs, index, &format); ++index) {
-		struct ast_codec_pref *pref = &ast_rtp_instance_get_codecs(session_media->rtp)->pref;
-
-		if (AST_FORMAT_GET_TYPE(format.id) != media_type) {
-			continue;
-		}
-
-		if (!ast_format_cap_get_compatible_format(caps, &format, &compat_format)) {
-			continue;
-		}
-
-		if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(session_media->rtp), 1, &compat_format, 0)) == -1) {
+		if (direct_media_enabled) {
+			ast_format_cap_joint_copy(session->endpoint->codecs, session->direct_media_cap, caps);
+		} else if (ast_format_cap_is_empty(session->req_caps)) {
+			ast_format_cap_copy(caps, session->endpoint->codecs);
+		} else {
+			ast_format_cap_joint_copy(session->endpoint->codecs, session->req_caps, caps);
+		}
+
+		if (caps_to_attrs(pool, media, media_type, ast_rtp_instance_get_codecs(session_media->rtp),
+				  caps, &min_packet_size, session)) {
 			return -1;
-		}
-
-		if (!(attr = generate_rtpmap_attr(media, pool, rtp_code, 1, &compat_format, 0))) {
-			continue;
-		}
-
-		media->attr[media->attr_count++] = attr;
-
-		if ((attr = generate_fmtp_attr(pool, &compat_format, rtp_code))) {
-			media->attr[media->attr_count++] = attr;
-		}
-
-		if (pref && media_type != AST_FORMAT_TYPE_VIDEO) {
-			struct ast_format_list fmt = ast_codec_pref_getsize(pref, &compat_format);
-			if (fmt.cur_ms && ((fmt.cur_ms < min_packet_size) || !min_packet_size)) {
-				min_packet_size = fmt.cur_ms;
-			}
 		}
 	}
 

Modified: team/kharwell/pimp_sip_media_neg/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_media_neg/res/res_sip_session.c?view=diff&rev=385276&r1=385275&r2=385276
==============================================================================
--- team/kharwell/pimp_sip_media_neg/res/res_sip_session.c (original)
+++ team/kharwell/pimp_sip_media_neg/res/res_sip_session.c Wed Apr 10 17:47:55 2013
@@ -773,16 +773,22 @@
 	ast_sip_session_send_request_with_cb(session, tdata, NULL);
 }
 
-void ast_sip_session_send_request_with_sdp(struct ast_sip_session *session, pjsip_tx_data *tdata)
-{
-	pjmedia_sdp_session *offer = create_local_sdp(session->inv_session, session, NULL);
-
-	if (offer) {
-		pjsip_inv_set_local_sdp(session->inv_session, offer);
-		ast_sip_session_send_request(session, tdata);
-	} else {
+int ast_sip_session_send_request_with_sdp(struct ast_sip_session *session)
+{
+	pjsip_tx_data *tdata;
+	pjmedia_sdp_session *offer;
+
+	if (!(offer = create_local_sdp(session->inv_session, session, NULL))) {
 		pjsip_inv_terminate(session->inv_session, 500, PJ_FALSE);
-	}
+		return -1;
+	}
+
+	pjsip_inv_set_local_sdp(session->inv_session, offer);
+	if (pjsip_inv_invite(session->inv_session, &tdata) != PJ_SUCCESS) {
+		return -1;
+	}
+	ast_sip_session_send_request(session, tdata);
+	return 0;
 }
 
 /*!
@@ -884,7 +890,7 @@
 	}
 	ao2_cleanup(session->endpoint);
 	ast_format_cap_destroy(session->req_caps);
-	ast_format_cap_destroy(session->outgoing_caps);
+	ast_format_cap_destroy(session->offer_caps);
 }
 
 static int add_supplements(struct ast_sip_session *session)




More information about the asterisk-commits mailing list