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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Apr 18 17:57:40 CDT 2013


Author: kharwell
Date: Thu Apr 18 17:57:36 2013
New Revision: 386045

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=386045
Log:
refactored audio_offer func to remove code overkill - also added codecs to req_caps structure

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_session.c
    team/kharwell/pimp_sip_media_neg/res/res_sip_session.exports.in

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=386045&r1=386044&r2=386045
==============================================================================
--- team/kharwell/pimp_sip_media_neg/channels/chan_gulp.c (original)
+++ team/kharwell/pimp_sip_media_neg/channels/chan_gulp.c Thu Apr 18 17:57:36 2013
@@ -260,75 +260,8 @@
 	.read = gulp_dial_contacts,
 };
 
-struct media_offering {
-	const char *name;
-	int (*get)(struct ast_sip_session *, char *, size_t len);
-	int (*set)(struct ast_sip_session *, const char *);
-
-	AST_LIST_ENTRY(media_offering) next;
-};
-
-AST_RWLIST_HEAD_STATIC(media_offerings, media_offering);
-
-static int register_media_offering(struct media_offering *obj)
-{
-	SCOPED_LOCK(lock, &media_offerings, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
-	AST_RWLIST_INSERT_TAIL(&media_offerings, obj, next);
-	ast_module_ref(ast_module_info->self);
-	return 0;
-}
-
-static void unregister_media_offering(struct media_offering *obj)
-{
-	struct media_offering *i;
-	SCOPED_LOCK(lock, &media_offerings, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
-	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&media_offerings, i, next) {
-		if (obj == i) {
-			AST_RWLIST_REMOVE_CURRENT(next);
-			ast_module_unref(ast_module_info->self);
-			break;
-		}
-	}
-	AST_RWLIST_TRAVERSE_SAFE_END;
-}
-
-static int media_offer_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
-{
-	struct gulp_pvt *pvt = ast_channel_tech_pvt(chan);
-	struct media_offering *i;
-
-	AST_LIST_TRAVERSE(&media_offerings, i, next) {
-		if (!strcmp(data, i->name) && i->get) {
-			return i->get(pvt->session, buf, len);
-		}
-	}
-
-	ast_log(LOG_WARNING, "Function %s: reading given media %s is not supported\n", cmd, data);
-	return 0;
-}
-
-static int media_offer_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
-{
-	struct gulp_pvt *pvt = ast_channel_tech_pvt(chan);
-	struct media_offering *i;
-
-	AST_LIST_TRAVERSE(&media_offerings, i, next) {
-		if (!strcmp(data, i->name) && i->set) {
-			return i->set(pvt->session, value);
-		}
-	}
-
-	ast_log(LOG_WARNING, "Function %s: writing given media %s is not supported\n", cmd, data);
-	return 0;
-}
-
-static struct ast_custom_function media_offer_function = {
-	.name = "MEDIA_OFFER",
-	.read = media_offer_read,
-	.write = media_offer_write
-};
-
-static int media_offer_av_get(struct ast_sip_session *session, char *buf, size_t len, enum ast_format_type media_type)
+static int media_offer_read_av(struct ast_sip_session *session, char *buf,
+			       size_t len, enum ast_format_type media_type)
 {
 	int i, size = 0;
 	struct ast_format fmt;
@@ -339,7 +272,7 @@
 			continue;
 		}
 
-		name = ast_rtp_lookup_mime_subtype2(1, &fmt, 0, 0);
+		name = ast_getformatname(&fmt); /* ast_rtp_lookup_mime_subtype2(1, &fmt, 0, 0); */
 
 		if (ast_strlen_zero(name)) {
 			continue;
@@ -363,7 +296,8 @@
 	return 0;
 }
 
-static int media_offer_av_set(struct ast_sip_session *session, const char *value, enum ast_format_type media_type)
+static int media_offer_write_av(struct ast_sip_session *session, const char *value,
+				enum ast_format_type media_type)
 {
 	int i;
 	struct ast_format fmt;
@@ -373,41 +307,44 @@
 			ast_codec_pref_remove(&session->override_prefs, &fmt);
 		}
 	}
+	ast_format_cap_remove_bytype(session->req_caps, media_type);
+
 	ast_parse_allow_disallow(&session->override_prefs, NULL, value, 1);
-
-	return 0;
-}
-
-static int media_offer_audio_get(struct ast_sip_session *session, char *buf, size_t len)
-{
-	return media_offer_av_get(session, buf, len, AST_FORMAT_TYPE_AUDIO);
-}
-
-static int media_offer_audio_set(struct ast_sip_session *session, const char *value)
-{
-	return media_offer_av_set(session, value, AST_FORMAT_TYPE_AUDIO);
-}
-
-static struct media_offering audio_offering = {
-	.name = "audio",
-	.get = media_offer_audio_get,
-	.set = media_offer_audio_set
-};
-
-static int media_offer_video_get(struct ast_sip_session *session, char *buf, size_t len)
-{
-	return media_offer_av_get(session, buf, len, AST_FORMAT_TYPE_VIDEO);
-}
-
-static int media_offer_video_set(struct ast_sip_session *session, const char *value)
-{
-	return media_offer_av_set(session, value, AST_FORMAT_TYPE_VIDEO);
-}
-
-static struct media_offering video_offering = {
-	.name = "video",
-	.get = media_offer_video_get,
-	.set = media_offer_video_set
+	ast_parse_allow_disallow(NULL, session->req_caps, value, 1);
+
+	return 0;
+}
+
+static int media_offer_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
+{
+	struct gulp_pvt *pvt = ast_channel_tech_pvt(chan);
+
+	if (!strcmp(data, "audio")) {
+		return media_offer_read_av(pvt->session, buf, len, AST_FORMAT_TYPE_AUDIO);
+	} else if (!strcmp(data, "video")) {
+		return media_offer_read_av(pvt->session, buf, len, AST_FORMAT_TYPE_VIDEO);
+	}
+
+	return 0;
+}
+
+static int media_offer_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
+{
+	struct gulp_pvt *pvt = ast_channel_tech_pvt(chan);
+
+	if (!strcmp(data, "audio")) {
+		return media_offer_write_av(pvt->session, value, AST_FORMAT_TYPE_AUDIO);
+	} else if (!strcmp(data, "video")) {
+		return media_offer_write_av(pvt->session, value, AST_FORMAT_TYPE_VIDEO);
+	}
+
+	return 0;
+}
+
+static struct ast_custom_function media_offer_function = {
+	.name = "MEDIA_OFFER",
+	.read = media_offer_read,
+	.write = media_offer_write
 };
 
 /*! \brief Function called by RTP engine to get local audio RTP peer */
@@ -1021,7 +958,7 @@
 static int call(void *data)
 {
 	struct ast_sip_session *session = data;
-	int res = ast_sip_session_send_request_with_sdp(session);
+	int res = ast_sip_session_send_invite(session);
 	ao2_ref(session, -1);
 	return res;
 }
@@ -1487,9 +1424,6 @@
 
 	if (ast_custom_function_register(&media_offer_function)) {
 		ast_log(LOG_WARNING, "Unable to register MEDIA_OFFER dialplan function\n");
-	} else {
-		register_media_offering(&audio_offering);
-		register_media_offering(&video_offering);
 	}
 
 	if (ast_sip_session_register_supplement(&gulp_supplement)) {
@@ -1506,10 +1440,7 @@
 	return 0;
 
 end:
-	unregister_media_offering(&video_offering);
-	unregister_media_offering(&audio_offering);
 	ast_custom_function_unregister(&media_offer_function);
-
 	ast_custom_function_unregister(&gulp_dial_contacts_function);
 	ast_channel_unregister(&gulp_tech);
 	ast_rtp_glue_unregister(&gulp_rtp_glue);
@@ -1526,8 +1457,6 @@
 /*! \brief Unload the Gulp channel from Asterisk */
 static int unload_module(void)
 {
-	unregister_media_offering(&video_offering);
-	unregister_media_offering(&audio_offering);
 	ast_custom_function_unregister(&media_offer_function);
 
 	ast_sip_session_unregister_supplement(&gulp_supplement);

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=386045&r1=386044&r2=386045
==============================================================================
--- 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 Thu Apr 18 17:57:36 2013
@@ -454,15 +454,11 @@
 void ast_sip_session_send_request(struct ast_sip_session *session, pjsip_tx_data *tdata);
 
 /*!
- * \brief Send a SIP request
- *
- * This will first create an sdp to add to the outgoing request and then will
- * send the SIP request specified in tdata and call into any registered
- * supplements' outgoing_request callback.
- *
- * \param session The session to which to send the request
- */
-int ast_sip_session_send_request_with_sdp(struct ast_sip_session *session);
+ * \brief Creates an offer and sends an INVITE request
+ *
+ * \param session Starting session for the INVITE
+ */
+int ast_sip_session_send_invite(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_session.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_media_neg/res/res_sip_session.c?view=diff&rev=386045&r1=386044&r2=386045
==============================================================================
--- team/kharwell/pimp_sip_media_neg/res/res_sip_session.c (original)
+++ team/kharwell/pimp_sip_media_neg/res/res_sip_session.c Thu Apr 18 17:57:36 2013
@@ -787,7 +787,7 @@
 	ast_sip_session_send_request_with_cb(session, tdata, NULL);
 }
 
-int ast_sip_session_send_request_with_sdp(struct ast_sip_session *session)
+int ast_sip_session_send_invite(struct ast_sip_session *session)
 {
 	pjsip_tx_data *tdata;
 	pjmedia_sdp_session *offer;

Modified: team/kharwell/pimp_sip_media_neg/res/res_sip_session.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_media_neg/res/res_sip_session.exports.in?view=diff&rev=386045&r1=386044&r2=386045
==============================================================================
--- team/kharwell/pimp_sip_media_neg/res/res_sip_session.exports.in (original)
+++ team/kharwell/pimp_sip_media_neg/res/res_sip_session.exports.in Thu Apr 18 17:57:36 2013
@@ -12,7 +12,7 @@
 		LINKER_SYMBOL_PREFIXast_sip_session_refresh;
 		LINKER_SYMBOL_PREFIXast_sip_session_send_response;
 		LINKER_SYMBOL_PREFIXast_sip_session_send_request;
-		LINKER_SYMBOL_PREFIXast_sip_session_send_request_with_sdp;
+		LINKER_SYMBOL_PREFIXast_sip_session_send_invite;
 		LINKER_SYMBOL_PREFIXast_sip_session_create_outgoing;
 	local:
 		*;




More information about the asterisk-commits mailing list