[asterisk-commits] mmichelson: branch mmichelson/direct_media r382820 - in /team/mmichelson/dire...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Mar 11 16:52:43 CDT 2013
Author: mmichelson
Date: Mon Mar 11 16:52:39 2013
New Revision: 382820
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382820
Log:
Put code in place for direct media glare mitigation.
A config option, aptly called direct_media_glare_mitigation,
directs us how we can attempt to reduce reinvite glare. We
can either do nothing, not send an initial refresh on outgoing
calls, or not send an initial refresh on incoming calls.
In order to only allow for this to occur once per call, a datastore
is set up on the session during session creation. The datastore is
then removed when a reinvite is prevented from being sent out.
Modified:
team/mmichelson/direct_media/channels/chan_gulp.c
team/mmichelson/direct_media/include/asterisk/res_sip.h
team/mmichelson/direct_media/res/res_sip/sip_configuration.c
Modified: team/mmichelson/direct_media/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/direct_media/channels/chan_gulp.c?view=diff&rev=382820&r1=382819&r2=382820
==============================================================================
--- team/mmichelson/direct_media/channels/chan_gulp.c (original)
+++ team/mmichelson/direct_media/channels/chan_gulp.c Mon Mar 11 16:52:39 2013
@@ -96,6 +96,7 @@
};
/*! \brief SIP session interaction functions */
+static void gulp_session_begin(struct ast_sip_session *session);
static void gulp_session_end(struct ast_sip_session *session);
static int gulp_incoming_request(struct ast_sip_session *session, struct pjsip_rx_data *rdata);
static void gulp_incoming_response(struct ast_sip_session *session, struct pjsip_rx_data *rdata);
@@ -103,6 +104,7 @@
/*! \brief SIP session supplement structure */
static struct ast_sip_session_supplement gulp_supplement = {
.method = "INVITE",
+ .session_begin = gulp_session_begin,
.session_end = gulp_session_end,
.incoming_request = gulp_incoming_request,
.incoming_response = gulp_incoming_response,
@@ -145,6 +147,37 @@
{
RAII_VAR(struct ast_sip_session *, session, data, ao2_cleanup);
return ast_sip_session_refresh(session, NULL, NULL, session->endpoint->direct_media_method);
+}
+
+static struct ast_datastore_info direct_media_mitigation_info = { };
+
+static int direct_media_mitigate_glare(struct ast_sip_session *session)
+{
+ RAII_VAR(struct ast_datastore *, datastore, NULL, ao2_cleanup);
+
+ if (session->endpoint->direct_media_glare_mitigation ==
+ AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_NONE) {
+ return 0;
+ }
+
+ datastore = ast_sip_session_get_datastore(session, "direct_media_mitigation");
+ if (!datastore) {
+ return 0;
+ }
+
+ /* Removing the datastore ensures we won't try to mitigate glare on subsequent reinvites */
+ ast_sip_session_remove_datastore(session, "direct_media_mitigation");
+
+ if ((session->endpoint->direct_media_glare_mitigation ==
+ AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_OUTGOING &&
+ session->inv_session->role == PJSIP_ROLE_UAC) ||
+ (session->endpoint->direct_media_glare_mitigation ==
+ AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_INCOMING &&
+ session->inv_session->role == PJSIP_ROLE_UAS)) {
+ return 1;
+ }
+
+ return 0;
}
/*! \brief Function called by RTP engine to change where the remote party should send media */
@@ -155,10 +188,6 @@
const struct ast_format_cap *cap,
int nat_active)
{
- /* We can figure out whether we need to send the reinvite in this
- * function. We ultimately will push a task in the session's serializer
- * to send the reinvite out.
- */
struct ast_sip_session *session = ast_channel_tech_pvt(chan);
int changed = 0;
@@ -183,11 +212,11 @@
}
}
+ if (direct_media_mitigate_glare(session)) {
+ return 0;
+ }
+
if (changed) {
- /* Queue a reinvite to be sent. We'll care about
- * transaction states and the like once the task
- * comes up
- */
ao2_ref(session, +1);
ast_sip_push_task(session->serializer, send_direct_media_request, session);
}
@@ -856,6 +885,25 @@
return 0;
}
+static void gulp_session_begin(struct ast_sip_session *session)
+{
+ RAII_VAR(struct ast_datastore *, datastore, NULL, ao2_cleanup);
+
+ if (!session->endpoint->direct_media_glare_mitigation ==
+ AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_NONE) {
+ return;
+ }
+
+ datastore = ast_sip_session_alloc_datastore(&direct_media_mitigation_info,
+ "direct_media_glare_mitigation");
+
+ if (!datastore) {
+ return;
+ }
+
+ ast_sip_session_add_datastore(session, datastore);
+}
+
/*! \brief Function called when the session ends */
static void gulp_session_end(struct ast_sip_session *session)
{
Modified: team/mmichelson/direct_media/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/direct_media/include/asterisk/res_sip.h?view=diff&rev=382820&r1=382819&r2=382820
==============================================================================
--- team/mmichelson/direct_media/include/asterisk/res_sip.h (original)
+++ team/mmichelson/direct_media/include/asterisk/res_sip.h Mon Mar 11 16:52:39 2013
@@ -218,6 +218,19 @@
AST_SIP_SESSION_REFRESH_METHOD_INVITE,
/*! Use UPDATE to negotiate direct media */
AST_SIP_SESSION_REFRESH_METHOD_UPDATE,
+};
+
+enum ast_sip_direct_media_glare_mitigation {
+ /*! Take no special action to mitigate reinvite glare */
+ AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_NONE,
+ /*! Do not send an initial direct media session refresh on outgoing call legs
+ * Subsequent session refreshes will be sent no matter the session direction
+ */
+ AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_OUTGOING,
+ /*! Do not send an initial direct media session refresh on incoming call legs
+ * Subsequent session refreshes will be sent no matter the session direction
+ */
+ AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_INCOMING,
};
/*!
@@ -271,6 +284,8 @@
unsigned int direct_media;
/*! When using direct media, which method should be used */
enum ast_sip_session_refresh_method direct_media_method;
+ /*! Take steps to mitigate glare for direct media */
+ enum ast_sip_direct_media_glare_mitigation direct_media_glare_mitigation;
};
/*!
Modified: team/mmichelson/direct_media/res/res_sip/sip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/direct_media/res/res_sip/sip_configuration.c?view=diff&rev=382820&r1=382819&r2=382820
==============================================================================
--- team/mmichelson/direct_media/res/res_sip/sip_configuration.c (original)
+++ team/mmichelson/direct_media/res/res_sip/sip_configuration.c Mon Mar 11 16:52:39 2013
@@ -267,6 +267,25 @@
var->value, var->name, ast_sorcery_object_get_id(endpoint));
return -1;
}
+ return 0;
+}
+
+static int direct_media_glare_mitigation_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
+{
+ struct ast_sip_endpoint *endpoint = obj;
+
+ if (!strcasecmp(var->value, "none")) {
+ endpoint->direct_media_glare_mitigation = AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_NONE;
+ } else if (!strcasecmp(var->value, "outgoing")) {
+ endpoint->direct_media_glare_mitigation = AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_OUTGOING;
+ } else if (!strcasecmp(var->value, "incoming")) {
+ endpoint->direct_media_glare_mitigation = AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_INCOMING;
+ } else {
+ ast_log(LOG_NOTICE, "Unrecognized option value %s for %s on endpoint %s\n",
+ var->value, var->name, ast_sorcery_object_get_id(endpoint));
+ return -1;
+ }
+
return 0;
}
@@ -325,6 +344,7 @@
ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "identify_by", "username,location", ident_handler, NULL, 0, 0);
ast_sorcery_object_field_register(sip_sorcery, "endpoint", "direct_media", "yes", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, direct_media));
ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "direct_media_method", "invite", direct_media_method_handler, NULL, 0, 0);
+ ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "direct_media_glare_mitigation", "none", direct_media_glare_mitigation_handler, NULL, 0, 0);
if (ast_sip_initialize_sorcery_transport(sip_sorcery)) {
ast_log(LOG_ERROR, "Failed to register SIP transport support with sorcery\n");
More information about the asterisk-commits
mailing list