[svn-commits] rmudgett: trunk r334115 - /trunk/channels/chan_sip.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Aug 31 13:11:28 CDT 2011


Author: rmudgett
Date: Wed Aug 31 13:11:23 2011
New Revision: 334115

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=334115
Log:
Optimize chan_sip.c check_rtp_timeout() function.

* Make check_rtp_timeout() remember the values returned by
ast_rtp_instance_get_timeout(), ast_rtp_instance_get_hold_timeout(), and
ast_rtp_instance_get_keepalive() instead of repeatedly calling them.

(closes issue ASTERISK-18319)
Reported by: Rob Gagnon
Patches:
      issue-18319-trunk-r333066.diff (License #6159) patch uploaded by Rob Gagnon

Review: https://reviewboard.asterisk.org/r/1377/

Modified:
    trunk/channels/chan_sip.c

Modified: trunk/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_sip.c?view=diff&rev=334115&r1=334114&r2=334115
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Wed Aug 31 13:11:23 2011
@@ -25688,6 +25688,10 @@
 /*! \brief helper function for the monitoring thread -- seems to be called with the assumption that the dialog is locked */
 static void check_rtp_timeout(struct sip_pvt *dialog, time_t t)
 {
+	int timeout;
+	int hold_timeout;
+	int keepalive;
+
 	/* If we have no active owner, no need to check timers */
 	if (!dialog->owner) {
 		dialog_unlink_rtpcheck(dialog);
@@ -25710,15 +25714,19 @@
 		return;
 	}
 
+	/* Store these values locally to avoid multiple function calls */
+	timeout = ast_rtp_instance_get_timeout(dialog->rtp);
+	hold_timeout = ast_rtp_instance_get_hold_timeout(dialog->rtp);
+	keepalive = ast_rtp_instance_get_keepalive(dialog->rtp);
+
 	/* If we have no timers set, return now */
-	if (!ast_rtp_instance_get_keepalive(dialog->rtp) && !ast_rtp_instance_get_timeout(dialog->rtp) && !ast_rtp_instance_get_hold_timeout(dialog->rtp)) {
+	if (!keepalive && !timeout && !hold_timeout) {
 		dialog_unlink_rtpcheck(dialog);
 		return;
 	}
 
 	/* Check AUDIO RTP keepalives */
-	if (dialog->lastrtptx && ast_rtp_instance_get_keepalive(dialog->rtp) &&
-		    (t > dialog->lastrtptx + ast_rtp_instance_get_keepalive(dialog->rtp))) {
+	if (dialog->lastrtptx && keepalive && (t > dialog->lastrtptx + keepalive)) {
 		/* Need to send an empty RTP packet */
 		dialog->lastrtptx = time(NULL);
 		ast_rtp_instance_sendcng(dialog->rtp, 0);
@@ -25731,10 +25739,10 @@
 	*/
 
 	/* Check AUDIO RTP timers */
-	if (dialog->lastrtprx && (ast_rtp_instance_get_timeout(dialog->rtp) || ast_rtp_instance_get_hold_timeout(dialog->rtp)) && (t > dialog->lastrtprx + ast_rtp_instance_get_timeout(dialog->rtp))) {
-		if (!ast_test_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD) || (ast_rtp_instance_get_hold_timeout(dialog->rtp) && (t > dialog->lastrtprx + ast_rtp_instance_get_hold_timeout(dialog->rtp)))) {
+	if (dialog->lastrtprx && (timeout || hold_timeout) && (t > dialog->lastrtprx + timeout)) {
+		if (!ast_test_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD) || (hold_timeout && (t > dialog->lastrtprx + hold_timeout))) {
 			/* Needs a hangup */
-			if (ast_rtp_instance_get_timeout(dialog->rtp)) {
+			if (timeout) {
 				if (!dialog->owner || ast_channel_trylock(dialog->owner)) {
 					/*
 					 * Don't block, just try again later.




More information about the svn-commits mailing list