diff options
author | Richard Mudgett <rmudgett@digium.com> | 2011-08-31 18:11:23 +0000 |
---|---|---|
committer | Richard Mudgett <rmudgett@digium.com> | 2011-08-31 18:11:23 +0000 |
commit | 89e79698fd79d5583a15f492aa1ea814033895ed (patch) | |
tree | fa8121def693c8cb428faaca1fc13f5869fe869b /channels | |
parent | dadc749dacbb7b273a490985ebbba11d26160a50 (diff) |
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/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@334115 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels')
-rw-r--r-- | channels/chan_sip.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 46aaca2b7..613bea33d 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -25688,6 +25688,10 @@ static int sip_send_mwi_to_peer(struct sip_peer *peer, int cache_only) /*! \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 @@ static void check_rtp_timeout(struct sip_pvt *dialog, time_t t) 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 @@ static void check_rtp_timeout(struct sip_pvt *dialog, time_t t) */ /* 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. |