diff options
author | Joshua Colp <jcolp@digium.com> | 2015-07-18 13:16:10 -0300 |
---|---|---|
committer | Joshua Colp <jcolp@digium.com> | 2015-07-24 12:43:02 -0300 |
commit | 27497217912a82ca243a9d5e9acfbbb597faf323 (patch) | |
tree | a461e85b877c4879eadae0f84024fb26735c630b /res/res_pjsip_sdp_rtp.c | |
parent | 1997b6f677f314f685ece102af9a70ed17fe63b5 (diff) |
pjsip: Add rtp_timeout and rtp_timeout_hold endpoint options.
This change adds support for the 'rtp_timeout' and 'rtp_timeout_hold'
endpoint options. These allow the channel to be hung up if RTP
is not received from the remote endpoint for a specified number of
seconds.
ASTERISK-25259 #close
Change-Id: I3f39daaa7da2596b5022737b77799d16204175b9
Diffstat (limited to 'res/res_pjsip_sdp_rtp.c')
-rw-r--r-- | res/res_pjsip_sdp_rtp.c | 64 |
1 files changed, 57 insertions, 7 deletions
diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c index 100224c10..4071ad76a 100644 --- a/res/res_pjsip_sdp_rtp.c +++ b/res/res_pjsip_sdp_rtp.c @@ -115,10 +115,6 @@ static int send_keepalive(const void *data) time_t interval; int send_keepalive; - if (!rtp) { - return 0; - } - keepalive = ast_rtp_instance_get_keepalive(rtp); if (!ast_sockaddr_isnull(&session_media->direct_media_addr)) { @@ -140,6 +136,37 @@ static int send_keepalive(const void *data) return (keepalive - interval) * 1000; } +/*! \brief Check whether RTP is being received or not */ +static int rtp_check_timeout(const void *data) +{ + struct ast_sip_session_media *session_media = (struct ast_sip_session_media *)data; + struct ast_rtp_instance *rtp = session_media->rtp; + int elapsed; + struct ast_channel *chan; + + if (!rtp) { + return 0; + } + + elapsed = time(NULL) - ast_rtp_instance_get_last_rx(rtp); + if (elapsed < ast_rtp_instance_get_timeout(rtp)) { + return (ast_rtp_instance_get_timeout(rtp) - elapsed) * 1000; + } + + chan = ast_channel_get_by_name(ast_rtp_instance_get_channel_id(rtp)); + if (!chan) { + return 0; + } + + ast_log(LOG_NOTICE, "Disconnecting channel '%s' for lack of RTP activity in %d seconds\n", + ast_channel_name(chan), elapsed); + + ast_softhangup(chan, AST_SOFTHANGUP_DEV); + ast_channel_unref(chan); + + return 0; +} + /*! \brief Internal function which creates an RTP instance */ static int create_rtp(struct ast_sip_session *session, struct ast_sip_session_media *session_media, unsigned int ipv6) { @@ -174,6 +201,8 @@ static int create_rtp(struct ast_sip_session *session, struct ast_sip_session_me session->endpoint->media.cos_video, "SIP RTP Video"); } + ast_rtp_instance_set_last_rx(session_media->rtp, time(NULL)); + return 0; } @@ -1271,6 +1300,28 @@ static int apply_negotiated_sdp_stream(struct ast_sip_session *session, struct a session_media, 1); } + /* As the channel lock is not held during this process the scheduled item won't block if + * it is hanging up the channel at the same point we are applying this negotiated SDP. + */ + AST_SCHED_DEL(sched, session_media->timeout_sched_id); + + /* Due to the fact that we only ever have one scheduled timeout item for when we are both + * off hold and on hold we don't need to store the two timeouts differently on the RTP + * instance itself. + */ + ast_rtp_instance_set_timeout(session_media->rtp, 0); + if (session->endpoint->media.rtp.timeout && !session_media->held) { + ast_rtp_instance_set_timeout(session_media->rtp, session->endpoint->media.rtp.timeout); + } else if (session->endpoint->media.rtp.timeout_hold && session_media->held) { + ast_rtp_instance_set_timeout(session_media->rtp, session->endpoint->media.rtp.timeout_hold); + } + + if (ast_rtp_instance_get_timeout(session_media->rtp)) { + session_media->timeout_sched_id = ast_sched_add_variable(sched, + ast_rtp_instance_get_timeout(session_media->rtp) * 1000, rtp_check_timeout, + session_media, 1); + } + return 1; } @@ -1300,9 +1351,8 @@ static void change_outgoing_sdp_stream_media_address(pjsip_tx_data *tdata, struc static void stream_destroy(struct ast_sip_session_media *session_media) { if (session_media->rtp) { - if (session_media->keepalive_sched_id != -1) { - AST_SCHED_DEL(sched, session_media->keepalive_sched_id); - } + AST_SCHED_DEL(sched, session_media->keepalive_sched_id); + AST_SCHED_DEL(sched, session_media->timeout_sched_id); ast_rtp_instance_stop(session_media->rtp); ast_rtp_instance_destroy(session_media->rtp); } |