[asterisk-commits] mmichelson: branch mmichelson/direct_media r382512 - in /team/mmichelson/dire...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 6 12:01:58 CST 2013


Author: mmichelson
Date: Wed Mar  6 12:01:54 2013
New Revision: 382512

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382512
Log:
More progress towards direct media calls.

I've taken care of the crash seen during hangup by ensuring
we do not try to apply a negotiated SDP if there is no channel
to apply it to.

There is still a race condition that sometimes causes reinvites
not to get sent on the outbound leg. It happens about one in five
times during a call and likely has something to do with the timing
of when the RTP layer is calling the update_peer glue function.

I think the issue is that the command to send a reinvite is happening
between when the INVITE transaction terminates and when the inv_session
layer actually clears the invite_tsx from itself. This means that we
delay sending the reinvite due to a pending transaction, but we never
get told that the transaction has cleared since there are no more
transaction state changes. Instead, we may have to rely on a signal
from the inv_session layer to indicate that it has cleared its
invite_tsx.


Modified:
    team/mmichelson/direct_media/channels/chan_gulp.c
    team/mmichelson/direct_media/res/res_sip_session.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=382512&r1=382511&r2=382512
==============================================================================
--- team/mmichelson/direct_media/channels/chan_gulp.c (original)
+++ team/mmichelson/direct_media/channels/chan_gulp.c Wed Mar  6 12:01:54 2013
@@ -144,7 +144,8 @@
 {
 	RAII_VAR(struct ast_sip_session *, session, data, ao2_cleanup);
 
-	ast_log(LOG_NOTICE, "Should be calling method to send a reinvite now\n");
+	ast_log(LOG_NOTICE, "Should be calling method to send a reinvite now to %s\n",
+			S_OR(ast_sorcery_object_get_id(session->endpoint), "outbound"));
 
 	return ast_sip_session_send_reinvite(session, NULL);
 }
@@ -194,6 +195,8 @@
 		 */
 		ao2_ref(session, +1);
 		ast_sip_push_task(session->serializer, send_direct_media_reinvite, session);
+	} else {
+		ast_log(LOG_NOTICE, "No change detected. Not doing anathin\n");
 	}
 
 	return 0;
@@ -673,6 +676,9 @@
 			ast_sip_session_send_request(session, packet);
 		}
 	}
+
+	ast_log(LOG_NOTICE, "This is when we're setting the channel NULL for session with endpoint %s\n",
+			S_OR(ast_sorcery_object_get_id(session->endpoint), "outbound"));
 
 	session->channel = NULL;
 	ast_channel_tech_pvt_set(ast, NULL);

Modified: team/mmichelson/direct_media/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/direct_media/res/res_sip_session.c?view=diff&rev=382512&r1=382511&r2=382512
==============================================================================
--- team/mmichelson/direct_media/res/res_sip_session.c (original)
+++ team/mmichelson/direct_media/res/res_sip_session.c Wed Mar  6 12:01:54 2013
@@ -349,14 +349,15 @@
 	return 0;
 }
 
-static void send_delayed_request(struct ast_sip_session *session)
-{
+static int send_delayed_request(void *data)
+{
+	struct ast_sip_session *session = data;
 	struct ast_sip_session_delayed_request *delay;
 
 	delay = AST_LIST_REMOVE_HEAD(&session->delayed_requests, next);
 	if (!delay) {
-		/* No delayed request to send, so just return */
-		return;
+		ao2_ref(session, -1);
+		return 0;
 	}
 
 	ast_log(LOG_NOTICE, "Sending delayed %s message to %s\n", delay->method, ast_sorcery_object_get_id(session->endpoint));
@@ -369,7 +370,19 @@
 		ast_sip_session_send_request(session, tdata);
 	}
 	ast_free(delay);
-	return;
+	ao2_ref(session, -1);
+	return 0;
+}
+
+static void queue_delayed_request(struct ast_sip_session *session)
+{
+	if (AST_LIST_EMPTY(&session->delayed_requests)) {
+		/* No delayed request to send, so just return */
+		return;
+	}
+
+	ao2_ref(session, +1);
+	ast_sip_push_task(session->serializer, send_delayed_request, session);
 }
 
 static int delay_request(struct ast_sip_session *session, const char *method)
@@ -392,13 +405,15 @@
 
 	if (inv_session->state == PJSIP_INV_STATE_DISCONNECTED) {
 		/* Don't try to do anything with a hung-up call */
-		ast_log(LOG_NOTICE, "Not sending because of disconnected state...\n");
+		ast_log(LOG_NOTICE, "Not sending reinvite to %s because of disconnected state...\n",
+				S_OR(ast_sorcery_object_get_id(session->endpoint), "outbound"));
 		return 0;
 	}
 
 	if (inv_session->invite_tsx) {
 		/* We can't send a reinvite yet, so delay it */
-		ast_log(LOG_NOTICE, "Delaying sending reinvite...\n");
+		ast_log(LOG_NOTICE, "Delaying sending reinvite to %s because of outstanding transaction...\n",
+				S_OR(ast_sorcery_object_get_id(session->endpoint), "outbound"));
 		return delay_request(session, "INVITE");
 	}
 
@@ -438,9 +453,11 @@
 	if (inv_session->invite_tsx) {
 		/* We can't send a request yet, so delay it */
 		char method[15];
-		ast_log(LOG_NOTICE, "Delaying sending reinvite...\n");
 		ast_copy_pj_str(method, &tdata->msg->line.req.method.name, sizeof(method));
+		ast_log(LOG_NOTICE, "Delaying sending %s request to %s due to outstanding transaction\n",
+				method, S_OR(ast_sorcery_object_get_id(session->endpoint), "outbound"));
 		delay_request(session, method);
+		return;
 	}
 	handle_outgoing_request(session, tdata);
 	pjsip_inv_send_msg(session->inv_session, tdata);
@@ -536,7 +553,9 @@
 	struct ast_sip_session *session = obj;
 	struct ast_sip_session_supplement *supplement;
 
-	ast_debug(3, "Destroying SIP session\n");
+	ast_debug(3, "Destroying SIP session with endpoint %s\n",
+			S_OR(ast_sorcery_object_get_id(session->endpoint), "outbound"));
+
 	while ((supplement = AST_LIST_REMOVE_HEAD(&session->supplements, next))) {
 		if (supplement->session_destroy) {
 			supplement->session_destroy(session);
@@ -949,7 +968,16 @@
 
 static void session_on_tsx_state(pjsip_transaction *tsx, pjsip_event *event)
 {
-	/* XXX STUB */
+	pjsip_inv_session *inv;
+	pjsip_dialog *dlg;
+	ast_log(LOG_NOTICE, "Just curious if we're getting called back?\n");
+	dlg = pjsip_tsx_get_dlg(tsx);
+	inv = pjsip_dlg_get_inv_session(dlg);
+	if (!inv) {
+		ast_log(LOG_NOTICE, "Huh, no inv_session to be found for this tsx?\n");
+	} else if (tsx == inv->invite_tsx) {
+		ast_log(LOG_NOTICE, "Whoa! TSX matches invite_tsx!\n");
+	}
 }
 
 static void handle_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata)
@@ -1100,11 +1128,6 @@
 	if (inv->state == PJSIP_INV_STATE_DISCONNECTED) {
 		session_end(session);
 	}
-
-	if (inv->state == PJSIP_INV_STATE_CONFIRMED) {
-		/* We may have a delayed request to send */
-		send_delayed_request(session);
-	}
 }
 
 static void session_inv_on_new_session(pjsip_inv_session *inv, pjsip_event *e)
@@ -1114,7 +1137,15 @@
 
 static void session_inv_on_tsx_state_changed(pjsip_inv_session *inv, pjsip_transaction *tsx, pjsip_event *e)
 {
-	/* XXX STUB */
+	if (inv->invite_tsx == tsx && tsx->state == PJSIP_TSX_STATE_TERMINATED) {
+		struct ast_sip_session *session = inv->mod_data[session_module.id];
+		struct ast_sip_endpoint *endpoint = session->endpoint;
+		queue_delayed_request(session);
+		/* XXX This feels wrong being here */
+		if (endpoint->direct_media && session->channel) {
+			ast_queue_control(session->channel, AST_CONTROL_SRCCHANGE);
+		}
+	}
 }
 
 static int add_sdp_streams(void *obj, void *arg, void *data, int flags)
@@ -1199,12 +1230,17 @@
 	struct ast_sip_session *session = inv->mod_data[session_module.id];
 	const pjmedia_sdp_session *local, *remote;
 
+	if (!session->channel) {
+		/* If we don't have a channel. We really don't care about media updates.
+		 * Just ignore
+		 */
+		return;
+	}
+
 	if ((status != PJ_SUCCESS) || (pjmedia_sdp_neg_get_active_local(inv->neg, &local) != PJ_SUCCESS) ||
 		(pjmedia_sdp_neg_get_active_remote(inv->neg, &remote) != PJ_SUCCESS)) {
-		if (session->channel) {
-			ast_channel_hangupcause_set(session->channel, AST_CAUSE_BEARERCAPABILITY_NOTAVAIL);
-			ast_queue_hangup(session->channel);
-		}
+		ast_channel_hangupcause_set(session->channel, AST_CAUSE_BEARERCAPABILITY_NOTAVAIL);
+		ast_queue_hangup(session->channel);
 		return;
 	}
 




More information about the asterisk-commits mailing list