[asterisk-commits] mmichelson: branch group/pimp_my_sip r379476 - in /team/group/pimp_my_sip: in...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jan 18 15:12:16 CST 2013


Author: mmichelson
Date: Fri Jan 18 15:12:12 2013
New Revision: 379476

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=379476
Log:
Add SDP answer to outgoing calls.

This should allow for media streams to be added to outbound
SDPs, at least for those answering an SDP offer. Outbound SDP
offers have still not been addressed.


Modified:
    team/group/pimp_my_sip/include/asterisk/res_sip_session.h
    team/group/pimp_my_sip/res/res_sip_sdp_audio.c
    team/group/pimp_my_sip/res/res_sip_session.c

Modified: team/group/pimp_my_sip/include/asterisk/res_sip_session.h
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/include/asterisk/res_sip_session.h?view=diff&rev=379476&r1=379475&r2=379476
==============================================================================
--- team/group/pimp_my_sip/include/asterisk/res_sip_session.h (original)
+++ team/group/pimp_my_sip/include/asterisk/res_sip_session.h Fri Jan 18 15:12:12 2013
@@ -112,12 +112,11 @@
      * \retval <0 There was an error encountered. No further operation will take place and the current negotiation will be abandoned.
      * \retval >0 The stream was handled by this handler. No further handler of this stream type will be called.
      */
-    int (*handle_incoming_sdp_stream)(struct ast_sip_session *session, struct pjmedia_sdp_session *sdp, struct pjmedia_sdp_media *stream);
+    int (*handle_incoming_sdp_stream)(struct ast_sip_session *session, const struct pjmedia_sdp_session *sdp, struct pjmedia_sdp_media *stream);
     /*!
      * \brief Create an SDP media stream and add it to the outgoing SDP offer or answer
      * \param session The session for which media is being added
 	 * \param sdp The entire SDP as currently built
-     * \param[out] stream The stream to be added to the SDP
      * \retval 0 This handler has no stream to add. If there are other registered handlers for this stream type, they will be called.
      * \retval <0 There was an error encountered. No further operation will take place and the current SDP negotiation will be abandoned.
      * \retval >0 The handler has a stream to be added to the SDP. No further handler of this stream type will be called.

Modified: team/group/pimp_my_sip/res/res_sip_sdp_audio.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip_sdp_audio.c?view=diff&rev=379476&r1=379475&r2=379476
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_sdp_audio.c (original)
+++ team/group/pimp_my_sip/res/res_sip_sdp_audio.c Fri Jan 18 15:12:12 2013
@@ -54,7 +54,7 @@
 static struct ast_sched_context *sched;
 
 /*! \brief Forward declarations for SDP handler functions */
-static int audio_handle_incoming_sdp_stream(struct ast_sip_session *session, struct pjmedia_sdp_session *sdp, struct pjmedia_sdp_media *stream);
+static int audio_handle_incoming_sdp_stream(struct ast_sip_session *session, const struct pjmedia_sdp_session *sdp, struct pjmedia_sdp_media *stream);
 static int audio_create_outgoing_sdp_stream(struct ast_sip_session *session, struct pjmedia_sdp_session *sdp);
 
 /*! \brief SDP handler for 'audio' media stream */
@@ -87,7 +87,7 @@
 }
 
 /*! \brief Function which handles an incoming 'audio' stream */
-static int audio_handle_incoming_sdp_stream(struct ast_sip_session *session, struct pjmedia_sdp_session *sdp, struct pjmedia_sdp_media *stream)
+static int audio_handle_incoming_sdp_stream(struct ast_sip_session *session, const struct pjmedia_sdp_session *sdp, struct pjmedia_sdp_media *stream)
 {
 	int res = 1, addrs_cnt, format, othercapability = 0;
 	char host[NI_MAXHOST];

Modified: team/group/pimp_my_sip/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip_session.c?view=diff&rev=379476&r1=379475&r2=379476
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_session.c (original)
+++ team/group/pimp_my_sip/res/res_sip_session.c Fri Jan 18 15:12:12 2013
@@ -136,38 +136,28 @@
 	ao2_callback_data(sdp_handlers, OBJ_KEY | OBJ_UNLINK | OBJ_NODATA, remove_handler, (void *)stream_type, handler);
 }
 
-static int handle_sdp(struct ast_sip_session *session, pjsip_rx_data *rdata)
-{
-	/*XXX STUB
-	 * This function will need to first check if there is an SDP. If so,
-	 * then it will iterate over the streams and pass them off to the appropriate
-	 * SDP handlers.
-	 */
+static int handle_incoming_sdp(struct ast_sip_session *session, const pjmedia_sdp_session *sdp)
+{
 	int i;
-	pjsip_rdata_sdp_info *sdp_info = pjsip_rdata_get_sdp_info(rdata);
-	if (!sdp_info || sdp_info->sdp_err) {
-		return -1;
-	}
-	if (!sdp_info->sdp) {
-		/* No SDP is not an error. It just means we have to create the SDP offer when we send our SIP response */
-		ast_debug(1, "No SDP detected in incoming INVITE from %s\n", session->endpoint->name);
-		return 0;
-	}
-	for (i = 0; i < sdp_info->sdp->media_count; ++i) {
+	for (i = 0; i < sdp->media_count; ++i) {
 		/* See if there are registered handlers for this media stream type */
-		pj_str_t media;
+		char media[20];
+		size_t chars_to_copy;
 		struct ast_sip_session_sdp_handler *handler;
 		RAII_VAR(struct sdp_handler_list *, handler_list, NULL, ao2_cleanup);
 
 		/* We need a null-terminated version of the media string */
-		pj_strdup_with_null(rdata->tp_info.pool, &media, &sdp_info->sdp->media[i]->desc.media);
-		handler_list = ao2_find(sdp_handlers, pj_strbuf(&media), OBJ_KEY);
+		chars_to_copy = MIN(sizeof(media)-1, pj_strlen(&sdp->media[i]->desc.media));
+		memcpy(media, pj_strbuf(&sdp->media[i]->desc.media), chars_to_copy);
+		media[chars_to_copy] = '\0';
+
+		handler_list = ao2_find(sdp_handlers, media, OBJ_KEY);
 		if (!handler_list) {
-			ast_debug(1, "No registered SDP handlers for media type '%s'\n", pj_strbuf(&media));
+			ast_debug(1, "No registered SDP handlers for media type '%s'\n", media);
 			continue;
 		}
 		AST_LIST_TRAVERSE(&handler_list->list, handler, next) {
-			int res = handler->handle_incoming_sdp_stream(session, sdp_info->sdp, sdp_info->sdp->media[i]);
+			int res = handler->handle_incoming_sdp_stream(session, sdp, sdp->media[i]);
 			if (res < 0) {
 				/* Catastrophic failure. Abort! */
 				return -1;
@@ -619,15 +609,6 @@
 		if (!supplement->method || !strcmp(supplement->method, "INVITE")) {
 			supplement->incoming_request(session, rdata);
 		}
-	}
-	if (handle_sdp(session, rdata)) {
-		/* Dangit. After all that, we have to reject the call */
-		if (pjsip_inv_end_session(inv_session, 488, NULL, &tdata) == PJ_SUCCESS) {
-			ast_sip_session_send_response(session, tdata);
-		} else {
-			pjsip_inv_terminate(inv_session, 488, PJ_FALSE);
-		}
-		return;
 	}
 }
 
@@ -692,9 +673,47 @@
 	/* XXX STUB */
 }
 
+static int add_sdp_streams(void *obj, void *arg, void *data, int flags)
+{
+	pjmedia_sdp_session *answer = arg;
+	struct sdp_handler_list *handler_list = obj;
+	struct ast_sip_session_sdp_handler *handler;
+	struct ast_sip_session *session = data;
+
+	AST_LIST_TRAVERSE(&handler_list->list, handler, next) {
+		int res = handler->create_outgoing_sdp_stream(session, answer);
+		if (res < 0) {
+			/* Catastrophic failure. Completely stop processing */
+			return CMP_STOP;
+		} else if (res > 0) {
+			/* This stream type has been handled. Move on to the next type */
+			return 0;
+		}
+	}
+	return 0;
+}
+
 static void session_inv_on_rx_offer(pjsip_inv_session *inv, const pjmedia_sdp_session *offer)
 {
-	/* XXX STUB */
+	struct ast_sip_session *session = inv->mod_data[session_module.id];
+	pjmedia_sdp_session *answer;
+	if (handle_incoming_sdp(session, offer)) {
+		return;
+	}
+	answer = PJ_POOL_ZALLOC_T(inv->pool, pjmedia_sdp_session);
+	answer->origin.version = answer->origin.id = (pj_uint32_t)(ast_random());
+	pj_strdup2(inv->dlg->pool, &answer->origin.user, "Asterisk");
+	/* XXX Hardcoded origin net stuff for now. Replace with transport
+	 * stuff later
+	 */
+	pj_strdup2(inv->dlg->pool, &answer->origin.net_type, "IN");
+	pj_strdup2(inv->dlg->pool, &answer->origin.addr_type, "IP4");
+	pj_strdup2(inv->dlg->pool, &answer->origin.addr, "127.0.0.1");
+	answer->name = answer->origin.user;
+	/* Now let the handlers add streams of various types */
+	ao2_callback_data(sdp_handlers, 0, add_sdp_streams, answer, session);
+
+	pjsip_inv_set_sdp_answer(inv, answer);
 }
 
 static void session_inv_on_create_offer(pjsip_inv_session *inv, pjmedia_sdp_session **p_offer)




More information about the asterisk-commits mailing list